Replace main_fndecl with current_function_decl
This commit is contained in:
@ -123,10 +123,11 @@ namespace gcc
|
||||
build_pointer_type(build_pointer_type(char_type_node))
|
||||
};
|
||||
tree declaration_type = build_function_type_array(integer_type_node, 2, parameter_types.data());
|
||||
this->main_fndecl = build_fn_decl("main", declaration_type);
|
||||
tree fndecl = build_fn_decl("main", declaration_type);
|
||||
current_function_decl = fndecl;
|
||||
tree resdecl = build_decl(UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, integer_type_node);
|
||||
DECL_CONTEXT(resdecl) = this->main_fndecl;
|
||||
DECL_RESULT(this->main_fndecl) = resdecl;
|
||||
DECL_CONTEXT(resdecl) = fndecl;
|
||||
DECL_RESULT(fndecl) = resdecl;
|
||||
|
||||
enter_scope();
|
||||
|
||||
@ -136,33 +137,33 @@ namespace gcc
|
||||
std::string argument_name = i == 0 ? "count" : "parameters";
|
||||
tree argc_declaration_tree = build_decl(UNKNOWN_LOCATION, PARM_DECL,
|
||||
get_identifier(argument_name.c_str()), parameter_types[i]);
|
||||
DECL_CONTEXT(argc_declaration_tree) = this->main_fndecl;
|
||||
DECL_CONTEXT(argc_declaration_tree) = fndecl;
|
||||
DECL_ARG_TYPE(argc_declaration_tree) = parameter_types[i];
|
||||
this->symbol_map->enter(argument_name, argc_declaration_tree);
|
||||
argument_chain.append(argc_declaration_tree);
|
||||
}
|
||||
DECL_ARGUMENTS(this->main_fndecl) = argument_chain.head();
|
||||
DECL_ARGUMENTS(fndecl) = argument_chain.head();
|
||||
|
||||
for (boot::statement *const body_statement : program->body)
|
||||
{
|
||||
body_statement->accept(this);
|
||||
}
|
||||
tree set_result = build2(INIT_EXPR, void_type_node, DECL_RESULT(main_fndecl),
|
||||
tree set_result = build2(INIT_EXPR, void_type_node, DECL_RESULT(fndecl),
|
||||
build_int_cst_type(integer_type_node, 0));
|
||||
tree return_stmt = build1(RETURN_EXPR, void_type_node, set_result);
|
||||
this->scope.front().append_statement(return_stmt);
|
||||
tree_symbol_mapping mapping = leave_scope();
|
||||
|
||||
BLOCK_SUPERCONTEXT(mapping.block()) = this->main_fndecl;
|
||||
DECL_INITIAL(this->main_fndecl) = mapping.block();
|
||||
DECL_SAVED_TREE(this->main_fndecl) = mapping.bind_expression();
|
||||
BLOCK_SUPERCONTEXT(mapping.block()) = fndecl;
|
||||
DECL_INITIAL(fndecl) = mapping.block();
|
||||
DECL_SAVED_TREE(fndecl) = mapping.bind_expression();
|
||||
|
||||
DECL_EXTERNAL(this->main_fndecl) = 0;
|
||||
DECL_PRESERVE_P(this->main_fndecl) = 1;
|
||||
DECL_EXTERNAL(fndecl) = 0;
|
||||
DECL_PRESERVE_P(fndecl) = 1;
|
||||
|
||||
gimplify_function_tree(this->main_fndecl);
|
||||
|
||||
cgraph_node::finalize_function(this->main_fndecl, true);
|
||||
current_function_decl = NULL_TREE;
|
||||
gimplify_function_tree(fndecl);
|
||||
cgraph_node::finalize_function(fndecl, true);
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::procedure_definition *definition)
|
||||
@ -178,14 +179,15 @@ namespace gcc
|
||||
: build_type(*definition->return_type());
|
||||
tree declaration_type = build_function_type_array(return_type,
|
||||
definition->parameters.size(), parameter_types.data());
|
||||
this->main_fndecl = build_fn_decl(definition->identifier.c_str(), declaration_type);
|
||||
this->symbol_map->enter(definition->identifier, this->main_fndecl);
|
||||
tree fndecl = build_fn_decl(definition->identifier.c_str(), declaration_type);
|
||||
this->symbol_map->enter(definition->identifier, fndecl);
|
||||
|
||||
if (definition->body() != nullptr)
|
||||
{
|
||||
current_function_decl = fndecl;
|
||||
tree resdecl = build_decl(UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, return_type);
|
||||
DECL_CONTEXT(resdecl) = this->main_fndecl;
|
||||
DECL_RESULT(this->main_fndecl) = resdecl;
|
||||
DECL_CONTEXT(resdecl) = fndecl;
|
||||
DECL_RESULT(fndecl) = resdecl;
|
||||
|
||||
enter_scope();
|
||||
}
|
||||
@ -196,7 +198,7 @@ namespace gcc
|
||||
|
||||
tree declaration_tree = build_decl(get_location(¶meter->position()), PARM_DECL,
|
||||
get_identifier(parameter->identifier.c_str()), parameter_types[i]);
|
||||
DECL_CONTEXT(declaration_tree) = this->main_fndecl;
|
||||
DECL_CONTEXT(declaration_tree) = fndecl;
|
||||
DECL_ARG_TYPE(declaration_tree) = parameter_types[i];
|
||||
|
||||
if (definition->body() != nullptr)
|
||||
@ -205,28 +207,28 @@ namespace gcc
|
||||
}
|
||||
argument_chain.append(declaration_tree);
|
||||
}
|
||||
DECL_ARGUMENTS(this->main_fndecl) = argument_chain.head();
|
||||
TREE_PUBLIC(this->main_fndecl) = definition->exported;
|
||||
DECL_ARGUMENTS(fndecl) = argument_chain.head();
|
||||
TREE_PUBLIC(fndecl) = definition->exported;
|
||||
|
||||
if (definition->body() != nullptr)
|
||||
{
|
||||
definition->body()->accept(this);
|
||||
tree_symbol_mapping mapping = leave_scope();
|
||||
|
||||
BLOCK_SUPERCONTEXT(mapping.block()) = this->main_fndecl;
|
||||
DECL_INITIAL(this->main_fndecl) = mapping.block();
|
||||
DECL_SAVED_TREE(this->main_fndecl) = mapping.bind_expression();
|
||||
BLOCK_SUPERCONTEXT(mapping.block()) = fndecl;
|
||||
DECL_INITIAL(fndecl) = mapping.block();
|
||||
DECL_SAVED_TREE(fndecl) = mapping.bind_expression();
|
||||
|
||||
DECL_EXTERNAL(this->main_fndecl) = 0;
|
||||
DECL_PRESERVE_P(this->main_fndecl) = 1;
|
||||
DECL_EXTERNAL(fndecl) = 0;
|
||||
DECL_PRESERVE_P(fndecl) = 1;
|
||||
|
||||
gimplify_function_tree(this->main_fndecl);
|
||||
|
||||
cgraph_node::finalize_function(this->main_fndecl, true);
|
||||
current_function_decl = NULL_TREE;
|
||||
gimplify_function_tree(fndecl);
|
||||
cgraph_node::finalize_function(fndecl, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
DECL_EXTERNAL(this->main_fndecl) = 1;
|
||||
DECL_EXTERNAL(fndecl) = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -633,7 +635,7 @@ namespace gcc
|
||||
error_at(declaration_location, "variable '%s' already declared in this scope",
|
||||
declaration->identifier.c_str());
|
||||
}
|
||||
else if (this->main_fndecl == NULL_TREE)
|
||||
else if (current_function_decl == NULL_TREE)
|
||||
{
|
||||
TREE_STATIC(declaration_tree) = 1;
|
||||
varpool_node::get_create(declaration_tree);
|
||||
@ -641,7 +643,7 @@ namespace gcc
|
||||
}
|
||||
else
|
||||
{
|
||||
DECL_CONTEXT(declaration_tree) = this->main_fndecl;
|
||||
DECL_CONTEXT(declaration_tree) = current_function_decl;
|
||||
this->scope.front().variables.append(declaration_tree);
|
||||
|
||||
auto declaration_statement = build1_loc(declaration_location, DECL_EXPR,
|
||||
@ -822,7 +824,7 @@ namespace gcc
|
||||
auto label_decl = build_decl(loc,
|
||||
LABEL_DECL, get_identifier(name), void_type_node);
|
||||
|
||||
DECL_CONTEXT(label_decl) = this->main_fndecl;
|
||||
DECL_CONTEXT(label_decl) = current_function_decl;
|
||||
|
||||
return label_decl;
|
||||
}
|
||||
@ -898,7 +900,7 @@ namespace gcc
|
||||
}
|
||||
return_expression->accept(this);
|
||||
|
||||
tree set_result = build2(INIT_EXPR, void_type_node, DECL_RESULT(main_fndecl),
|
||||
tree set_result = build2(INIT_EXPR, void_type_node, DECL_RESULT(current_function_decl),
|
||||
this->current_expression);
|
||||
tree return_stmt = build1(RETURN_EXPR, void_type_node, set_result);
|
||||
this->scope.front().append_statement(return_stmt);
|
||||
|
60
gcc/elna1.cc
60
gcc/elna1.cc
@ -19,17 +19,11 @@ along with GCC; see the file COPYING3. If not see
|
||||
#include "system.h"
|
||||
#include "coretypes.h"
|
||||
#include "target.h"
|
||||
#include "tree.h"
|
||||
#include "tree-iterator.h"
|
||||
#include "gimple-expr.h"
|
||||
#include "diagnostic.h"
|
||||
#include "opts.h"
|
||||
#include "fold-const.h"
|
||||
#include "stor-layout.h"
|
||||
#include "debug.h"
|
||||
#include "langhooks.h"
|
||||
#include "langhooks-def.h"
|
||||
#include "common/common-target.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <elna/boot/driver.h>
|
||||
@ -52,14 +46,6 @@ struct GTY (()) lang_decl
|
||||
char dummy;
|
||||
};
|
||||
|
||||
/* Language-dependent contents of an identifier. This must include a
|
||||
tree_identifier. */
|
||||
|
||||
struct GTY (()) lang_identifier
|
||||
{
|
||||
struct tree_identifier common;
|
||||
};
|
||||
|
||||
/* The resulting tree type. */
|
||||
|
||||
union GTY ((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
|
||||
@ -68,7 +54,6 @@ union GTY ((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
|
||||
"(&%h.generic)) : NULL"))) lang_tree_node
|
||||
{
|
||||
union tree_node GTY ((tag ("0"), desc ("tree_node_structure (&%h)"))) generic;
|
||||
struct lang_identifier GTY ((tag ("1"))) identifier;
|
||||
};
|
||||
|
||||
/* We don't use language_function. */
|
||||
@ -83,9 +68,6 @@ struct GTY (()) language_function
|
||||
static bool elna_langhook_init(void)
|
||||
{
|
||||
build_common_tree_nodes(false);
|
||||
|
||||
void_list_node = build_tree_list(NULL_TREE, void_type_node);
|
||||
|
||||
build_common_builtin_nodes();
|
||||
|
||||
return true;
|
||||
@ -198,36 +180,18 @@ static tree elna_langhook_type_for_mode(enum machine_mode mode, int unsignedp)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static tree elna_langhook_type_for_size(unsigned int bits ATTRIBUTE_UNUSED,
|
||||
int unsignedp ATTRIBUTE_UNUSED)
|
||||
static bool global_bindings_p(void)
|
||||
{
|
||||
gcc_unreachable();
|
||||
return current_function_decl == NULL_TREE;
|
||||
}
|
||||
|
||||
/* Record a builtin function. We just ignore builtin functions. */
|
||||
|
||||
static tree elna_langhook_builtin_function(tree decl)
|
||||
static tree pushdecl(tree decl)
|
||||
{
|
||||
return decl;
|
||||
}
|
||||
|
||||
static bool elna_langhook_global_bindings_p(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static tree elna_langhook_pushdecl(tree decl ATTRIBUTE_UNUSED)
|
||||
{
|
||||
gcc_unreachable();
|
||||
}
|
||||
|
||||
static tree elna_langhook_getdecls(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#undef LANG_HOOKS_NAME
|
||||
#define LANG_HOOKS_NAME "Elna"
|
||||
#define LANG_HOOKS_NAME "GNU Elna"
|
||||
|
||||
#undef LANG_HOOKS_INIT
|
||||
#define LANG_HOOKS_INIT elna_langhook_init
|
||||
@ -238,20 +202,14 @@ static tree elna_langhook_getdecls(void)
|
||||
#undef LANG_HOOKS_TYPE_FOR_MODE
|
||||
#define LANG_HOOKS_TYPE_FOR_MODE elna_langhook_type_for_mode
|
||||
|
||||
#undef LANG_HOOKS_TYPE_FOR_SIZE
|
||||
#define LANG_HOOKS_TYPE_FOR_SIZE elna_langhook_type_for_size
|
||||
|
||||
#undef LANG_HOOKS_BUILTIN_FUNCTION
|
||||
#define LANG_HOOKS_BUILTIN_FUNCTION elna_langhook_builtin_function
|
||||
|
||||
#undef LANG_HOOKS_GLOBAL_BINDINGS_P
|
||||
#define LANG_HOOKS_GLOBAL_BINDINGS_P elna_langhook_global_bindings_p
|
||||
|
||||
#undef LANG_HOOKS_PUSHDECL
|
||||
#define LANG_HOOKS_PUSHDECL elna_langhook_pushdecl
|
||||
#define LANG_HOOKS_BUILTIN_FUNCTION pushdecl
|
||||
|
||||
#undef LANG_HOOKS_GETDECLS
|
||||
#define LANG_HOOKS_GETDECLS elna_langhook_getdecls
|
||||
#define LANG_HOOKS_GETDECLS hook_tree_void_null
|
||||
|
||||
#undef LANG_HOOKS_IDENTIFIER_SIZE
|
||||
#define LANG_HOOKS_IDENTIFIER_SIZE sizeof(struct tree_identifier)
|
||||
|
||||
struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
|
||||
|
||||
|
Reference in New Issue
Block a user