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);
|
||||
|
Reference in New Issue
Block a user