Allow exporting global external variables

This commit is contained in:
2025-08-24 16:54:48 +02:00
parent fd3729ba16
commit c95466622a
7 changed files with 56 additions and 52 deletions

View File

@@ -57,8 +57,6 @@ namespace elna::gcc
tree identifier = get_identifier(name);
tree type_declaration = build_decl(UNKNOWN_LOCATION, TYPE_DECL, identifier, type);
TREE_PUBLIC(type_declaration) = 1;
symbol_table->enter(name, type_declaration);
return type_declaration;
@@ -82,24 +80,6 @@ namespace elna::gcc
return symbol_table;
}
tree build_type_declaration(const std::string& identifier, tree type)
{
tree definition_tree = build_decl(UNKNOWN_LOCATION, TYPE_DECL,
get_identifier(identifier.c_str()), type);
TREE_PUBLIC(definition_tree) = 1;
if (is_unique_type(type))
{
TYPE_NAME(type) = DECL_NAME(definition_tree);
TYPE_STUB_DECL(type) = definition_tree;
}
else
{
TYPE_NAME(type) = definition_tree;
}
return definition_tree;
}
tree build_composite_type(const std::vector<boot::type_field>& fields, tree composite_type_node,
std::shared_ptr<symbol_table> symbols)
{
@@ -178,7 +158,7 @@ namespace elna::gcc
}
else if (auto reference = type.get<boot::alias_type>())
{
return handle_symbol(reference->name, reference, symbols);
return TREE_TYPE(handle_symbol(reference->name, reference, symbols));
}
return error_mark_node;
}
@@ -190,13 +170,21 @@ namespace elna::gcc
if (looked_up == NULL_TREE)
{
looked_up = get_inner_alias(reference->reference, symbols);
tree type_tree = get_inner_alias(reference->reference, symbols);
looked_up = build_decl(UNKNOWN_LOCATION, TYPE_DECL,
get_identifier(symbol_name.c_str()), type_tree);
symbols->enter(symbol_name, build_type_declaration(symbol_name, looked_up));
}
else
{
looked_up = TREE_TYPE(looked_up);
TREE_PUBLIC(looked_up) = 1;
if (is_unique_type(type_tree))
{
TYPE_NAME(type_tree) = DECL_NAME(looked_up);
TYPE_STUB_DECL(type_tree) = looked_up;
}
else
{
TYPE_NAME(type_tree) = looked_up;
}
symbols->enter(symbol_name, looked_up);
}
return looked_up;
}
@@ -236,6 +224,7 @@ namespace elna::gcc
DECL_ARGUMENTS(fndecl) = argument_chain;
TREE_ADDRESSABLE(fndecl) = 1;
DECL_EXTERNAL(fndecl) = info.is_extern();
TREE_PUBLIC(fndecl) = info.exported;
}
tree declare_variable(const std::string& name, const boot::variable_info& info,
@@ -246,23 +235,31 @@ namespace elna::gcc
TREE_ADDRESSABLE(declaration_tree) = 1;
DECL_EXTERNAL(declaration_tree) = info.is_extern;
TREE_PUBLIC(declaration_tree) = info.exported;
symbols->enter(name, declaration_tree);
return declaration_tree;
}
void declare_type(const std::string& name, const boot::type_info& info, std::shared_ptr<symbol_table> symbols)
{
// The top level symbol table has basic (builtin) types in it which are not aliases.
if (auto alias_type = info.symbol.get<boot::alias_type>())
{
tree type_declaration = handle_symbol(name, alias_type, symbols);
TREE_PUBLIC(type_declaration) = info.exported;
}
}
void rewrite_symbol_table(std::shared_ptr<boot::symbol_table> info_table, std::shared_ptr<symbol_table> symbols)
{
for (auto& [symbol_name, symbol_info] : *info_table)
{
if (auto type_info = symbol_info->is_type())
{
// The top level symbol table has basic (builtin) types in it which are not aliases.
if (auto alias_type = type_info->symbol.get<boot::alias_type>())
{
handle_symbol(symbol_name, alias_type, symbols);
}
declare_type(symbol_name, *type_info, symbols);
}
else if (auto variable_info = symbol_info->is_variable())
{