Skip to content

Commit

Permalink
[cpp] codegen : debug info stuff. still NYI
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed May 19, 2024
1 parent a25c3f1 commit 42f3bd9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions cpp/src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ namespace code
struct object_debug_info
{
llvm::DICompileUnit* cu;
llvm::DIFile* file;
std::vector<llvm::DIScope*> scopes = {};
void push_scope(llvm::DIScope* scope)
{
this->scopes.push_back(scope);
}

void pop_scope()
{
diag::assert_that(this->scopes.size(), error_code::ice, "pop_scope invoked but we're apparantly at the top-level");
}
void emit_null_location() const
{
builder->SetCurrentDebugLocation(llvm::DebugLoc());
}
void emit_location(const ast::node& node) const
{
llvm::DIScope* scope = this->cu;
if(this->scopes.size())
{
scope = this->scopes.back();
}
builder->SetCurrentDebugLocation(llvm::DILocation::get(scope->getContext(), node.meta.line, node.meta.column, scope));
}
} debug_info;

void static_initialise()
Expand Down Expand Up @@ -209,6 +233,7 @@ namespace code
{
debug = std::make_unique<llvm::DIBuilder>(*program);
debug_info.cu = debug->createCompileUnit(llvm::dwarf::DW_LANG_C, debug->createFile(module_name.c_str(), "."), "Psy Compiler", /*optimised*/ false, "", 0);
debug_info.file = debug->createFile(debug_info.cu->getFilename(), debug_info.cu->getDirectory());
}

// todo: codegen logic goes here.
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/psyc_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int main(int argc, char** argv)
code::state codegen;
for(const auto& [input_file, semantic_output] : semal.analysed_input_files)
{
codegen.codegend_input_files[input_file] = code::generate(parse.parsed_input_files[input_file], semantic_output, input_file.stem().string());
codegen.codegend_input_files[input_file] = code::generate(parse.parsed_input_files[input_file], semantic_output, input_file.string());
if(args.should_dump_ir)
{
std::cout << "==========================\n";
Expand Down

0 comments on commit 42f3bd9

Please sign in to comment.