Support one hardcoded import

This commit is contained in:
2025-07-10 00:43:17 +02:00
parent 181b19eefe
commit 34abb6b4f5
18 changed files with 396 additions and 312 deletions

View File

@ -29,16 +29,14 @@ along with GCC; see the file COPYING3. If not see
#include "stringpool.h"
#include "diagnostic.h"
#include "realmpfr.h"
#include "stor-layout.h"
#include "varasm.h"
#include "fold-const.h"
#include "langhooks.h"
namespace elna::gcc
{
generic_visitor::generic_visitor(std::shared_ptr<symbol_table> symbol_table,
std::shared_ptr<boot::symbol_table> info_table)
: symbols(symbol_table), info_table(info_table)
generic_visitor::generic_visitor(std::shared_ptr<symbol_table> symbol_table, elna::boot::symbol_bag bag)
: bag(bag), symbols(symbol_table)
{
}
@ -321,7 +319,7 @@ namespace elna::gcc
DECL_STRUCT_FUNCTION(fndecl)->language = ggc_cleared_alloc<language_function>();
enter_scope();
this->info_table = this->info_table->lookup(definition->identifier.identifier)->is_procedure()->symbols;
this->bag.enter(this->bag.lookup(definition->identifier.identifier)->is_procedure()->symbols);
tree argument_chain = DECL_ARGUMENTS(fndecl);
for (; argument_chain != NULL_TREE; argument_chain = TREE_CHAIN(argument_chain))
@ -339,7 +337,7 @@ namespace elna::gcc
visit_statements(definition->body.value().body());
tree mapping = leave_scope();
this->info_table = this->info_table->scope();
this->bag.leave();
BLOCK_SUPERCONTEXT(BIND_EXPR_BLOCK(mapping)) = fndecl;
DECL_INITIAL(fndecl) = BIND_EXPR_BLOCK(mapping);
@ -746,7 +744,7 @@ namespace elna::gcc
void generic_visitor::visit(boot::variable_declaration *declaration)
{
this->current_expression = get_inner_alias(
this->info_table->lookup(declaration->identifier.identifier)->is_variable()->symbol,
this->bag.lookup(declaration->identifier.identifier)->is_variable()->symbol,
this->symbols);
location_t declaration_location = get_location(&declaration->position());

View File

@ -62,63 +62,62 @@ static bool elna_langhook_init(void)
return true;
}
static void elna_parse_file(const char *filename)
using dependency_state = elna::boot::dependency_state<std::shared_ptr<elna::gcc::symbol_table>>;
static elna::boot::dependency elna_parse_file(dependency_state& state, const char *filename)
{
std::ifstream file{ filename, std::ios::in };
auto module_table = std::make_shared<elna::boot::symbol_table>(state.globals);
std::ifstream entry_point{ filename, std::ios::in };
if (!file)
if (!entry_point)
{
fatal_error(UNKNOWN_LOCATION, "cannot open filename %s: %m", filename);
fatal_error(UNKNOWN_LOCATION, "Cannot open filename %s: %m", filename);
}
elna::boot::dependency_graph outcome = elna::boot::read_sources(file, filename);
std::shared_ptr<elna::boot::symbol_table> info_table = elna::boot::builtin_symbol_table();
std::shared_ptr<elna::gcc::symbol_table> symbol_table = elna::gcc::builtin_symbol_table();
linemap_add(line_table, LC_ENTER, 0, filename, 1);
elna::boot::dependency outcome = elna::boot::read_sources(entry_point, filename);
if (outcome.has_errors())
{
elna::gcc::report_errors(outcome.errors());
}
else
elna::boot::symbol_bag outcome_bag = elna::boot::symbol_bag{ std::move(outcome.unresolved), module_table };
for (const auto& sub_tree : outcome.tree->imports)
{
for (const std::unique_ptr<elna::boot::program>& module_tree : outcome.modules)
std::filesystem::path sub_path = "source" / elna::boot::build_path(sub_tree->segments);
if (state.cache.find(sub_path) == state.cache.end())
{
elna::boot::declaration_visitor declaration_visitor(filename);
declaration_visitor.visit(module_tree.get());
if (declaration_visitor.errors().empty())
{
elna::boot::name_analysis_visitor name_analysis_visitor(filename, info_table,
std::move(declaration_visitor.unresolved));
name_analysis_visitor.visit(module_tree.get());
if (name_analysis_visitor.errors().empty())
{
elna::gcc::rewrite_symbol_table(info_table, symbol_table);
elna::gcc::generic_visitor generic_visitor{ symbol_table, info_table };
generic_visitor.visit(module_tree.get());
}
else
{
elna::gcc::report_errors(name_analysis_visitor.errors());
}
}
else
{
elna::gcc::report_errors(declaration_visitor.errors());
}
elna_parse_file(state, state.allocate_path(sub_path));
}
outcome_bag.add_import(state.cache.find(sub_path)->second);
}
elna::boot::name_analysis_visitor name_analysis_visitor(filename, outcome_bag);
outcome.tree->accept(&name_analysis_visitor);
if (name_analysis_visitor.has_errors())
{
elna::gcc::report_errors(name_analysis_visitor.errors());
}
state.cache.insert({ filename, outcome_bag });
elna::gcc::rewrite_symbol_table(module_table, state.custom);
linemap_add(line_table, LC_LEAVE, 0, NULL, 0);
return outcome;
}
static void elna_langhook_parse_file(void)
{
dependency_state state{ elna::gcc::builtin_symbol_table() };
for (unsigned int i = 0; i < num_in_fnames; i++)
{
elna_parse_file(in_fnames[i]);
elna::boot::dependency outcome = elna_parse_file(state, in_fnames[i]);
linemap_add(line_table, LC_ENTER, 0, in_fnames[i], 1);
elna::gcc::generic_visitor generic_visitor{ state.custom, state.cache.find(in_fnames[i])->second };
outcome.tree->accept(&generic_visitor);
linemap_add(line_table, LC_LEAVE, 0, NULL, 0);
}
}