diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-07-09 17:24:42 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-07-09 17:24:42 +0200 |
| commit | 36440faa345bf842c348711325312c2b02e4cc23 (patch) | |
| tree | a7ec54ad2f948efc556f3a74b59064321ae581c9 /gcc | |
| parent | 8d8e771af944796eba10cfa9568d284daaab93a1 (diff) | |
| download | elna-36440faa345bf842c348711325312c2b02e4cc23.tar.gz | |
Merge program and unit AST types
Diffstat (limited to 'gcc')
| -rw-r--r-- | gcc/gcc/elna-generic.cc | 97 |
1 files changed, 47 insertions, 50 deletions
diff --git a/gcc/gcc/elna-generic.cc b/gcc/gcc/elna-generic.cc index eb30b4d..a3d022d 100644 --- a/gcc/gcc/elna-generic.cc +++ b/gcc/gcc/elna-generic.cc @@ -235,56 +235,6 @@ namespace elna::gcc } } - void generic_visitor::visit(boot::program *program) - { - visit(static_cast<boot::unit *>(program)); - - tree declaration_type = build_function_type_list(elna_int_type_node, - elna_int_type_node, - build_global_pointer_type(build_global_pointer_type(elna_char_type_node)), - NULL_TREE); - tree fndecl = build_fn_decl("main", declaration_type); - - tree resdecl = build_decl(UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, integer_type_node); - DECL_CONTEXT(resdecl) = fndecl; - DECL_RESULT(fndecl) = resdecl; - - push_struct_function(fndecl, false); - DECL_STRUCT_FUNCTION(fndecl)->language = ggc_cleared_alloc<language_function>(); - - enter_scope(); - - tree parameter_type = TYPE_ARG_TYPES(declaration_type); - for (const char *argument_name : std::array<const char *, 2>{ "count", "parameters" }) - { - tree declaration_tree = build_decl(UNKNOWN_LOCATION, PARM_DECL, - get_identifier(argument_name), TREE_VALUE(parameter_type)); - DECL_CONTEXT(declaration_tree) = fndecl; - DECL_ARG_TYPE(declaration_tree) = TREE_VALUE(parameter_type); - - this->symbols->enter(argument_name, declaration_tree); - DECL_ARGUMENTS(fndecl) = chainon(DECL_ARGUMENTS(fndecl), declaration_tree); - parameter_type = TREE_CHAIN(parameter_type); - } - visit_statements(program->body); - 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); - append_statement(return_stmt); - tree mapping = leave_scope(); - - BLOCK_SUPERCONTEXT(BIND_EXPR_BLOCK(mapping)) = fndecl; - DECL_INITIAL(fndecl) = BIND_EXPR_BLOCK(mapping); - DECL_SAVED_TREE(fndecl) = mapping; - - DECL_EXTERNAL(fndecl) = 0; - DECL_PRESERVE_P(fndecl) = 1; - - pop_cfun(); - gimplify_function_tree(fndecl); - cgraph_node::finalize_function(fndecl, true); - } - void generic_visitor::visit(boot::unit *unit) { for (boot::import_declaration *const declaration : unit->imports) @@ -303,6 +253,53 @@ namespace elna::gcc { procedure->accept(this); } + if (unit->body.has_value()) + { + tree declaration_type = build_function_type_list(elna_int_type_node, + elna_int_type_node, + build_global_pointer_type(build_global_pointer_type(elna_char_type_node)), + NULL_TREE); + tree fndecl = build_fn_decl("main", declaration_type); + + tree resdecl = build_decl(UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, integer_type_node); + DECL_CONTEXT(resdecl) = fndecl; + DECL_RESULT(fndecl) = resdecl; + + push_struct_function(fndecl, false); + DECL_STRUCT_FUNCTION(fndecl)->language = ggc_cleared_alloc<language_function>(); + + enter_scope(); + + tree parameter_type = TYPE_ARG_TYPES(declaration_type); + for (const char *argument_name : std::array<const char *, 2>{ "count", "parameters" }) + { + tree declaration_tree = build_decl(UNKNOWN_LOCATION, PARM_DECL, + get_identifier(argument_name), TREE_VALUE(parameter_type)); + DECL_CONTEXT(declaration_tree) = fndecl; + DECL_ARG_TYPE(declaration_tree) = TREE_VALUE(parameter_type); + + this->symbols->enter(argument_name, declaration_tree); + DECL_ARGUMENTS(fndecl) = chainon(DECL_ARGUMENTS(fndecl), declaration_tree); + parameter_type = TREE_CHAIN(parameter_type); + } + visit_statements(unit->body.value()); + 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); + append_statement(return_stmt); + tree mapping = leave_scope(); + + BLOCK_SUPERCONTEXT(BIND_EXPR_BLOCK(mapping)) = fndecl; + DECL_INITIAL(fndecl) = BIND_EXPR_BLOCK(mapping); + DECL_SAVED_TREE(fndecl) = mapping; + + DECL_EXTERNAL(fndecl) = 0; + DECL_PRESERVE_P(fndecl) = 1; + + pop_cfun(); + gimplify_function_tree(fndecl); + cgraph_node::finalize_function(fndecl, true); + } } void generic_visitor::visit(boot::procedure_declaration *definition) |
