Skip to content

Commit

Permalink
Store filename in the Debug information
Browse files Browse the repository at this point in the history
  • Loading branch information
Thirumalai-Shaktivel committed Nov 2, 2022
1 parent 157e517 commit ebd5168
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/bin/lpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ int emit_llvm(const std::string &infile,
// ASR -> LLVM
LFortran::PythonCompiler fe(compiler_options);
LFortran::Result<std::unique_ptr<LFortran::LLVMModule>>
res = fe.get_llvm3(*asr, pass_manager, diagnostics);
res = fe.get_llvm3(*asr, pass_manager, diagnostics, infile);
std::cerr << diagnostics.render(input, lm, compiler_options);
if (!res.ok) {
LFORTRAN_ASSERT(diagnostics.has_error())
Expand Down Expand Up @@ -628,7 +628,7 @@ int compile_python_to_object_file(
std::unique_ptr<LFortran::LLVMModule> m;
auto asr_to_llvm_start = std::chrono::high_resolution_clock::now();
LFortran::Result<std::unique_ptr<LFortran::LLVMModule>>
res = fe.get_llvm3(*asr, pass_manager, diagnostics);
res = fe.get_llvm3(*asr, pass_manager, diagnostics, infile);
auto asr_to_llvm_end = std::chrono::high_resolution_clock::now();
times.push_back(std::make_pair("ASR to LLVM", std::chrono::duration<double, std::milli>(asr_to_llvm_end - asr_to_llvm_start).count()));
std::cerr << diagnostics.render(input, lm, compiler_options);
Expand Down
13 changes: 9 additions & 4 deletions src/libasr/codegen/asr_to_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
std::unique_ptr<llvm::IRBuilder<>> builder;
Platform platform;
bool emit_debug_info;
std::string infile;
bool emit_debug_line_column;
Allocator &al;

Expand Down Expand Up @@ -240,12 +241,14 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
llvm::DIFile *debug_Unit;

ASRToLLVMVisitor(Allocator &al, llvm::LLVMContext &context, Platform platform,
bool emit_debug_info, diag::Diagnostics &diagnostics) :
bool emit_debug_info, std::string infile, bool emit_debug_line_column,
diag::Diagnostics &diagnostics) :
diag{diagnostics},
context(context),
builder(std::make_unique<llvm::IRBuilder<>>(context)),
platform{platform},
emit_debug_info{emit_debug_info},
infile{infile},
emit_debug_line_column{emit_debug_line_column},
al{al},
prototype_only(false),
Expand Down Expand Up @@ -1160,7 +1163,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
if (emit_debug_info) {
DBuilder = std::make_unique<llvm::DIBuilder>(*module);
debug_CU = DBuilder->createCompileUnit(
llvm::dwarf::DW_LANG_C, DBuilder->createFile("xxexpr.py", "/yy/"),
llvm::dwarf::DW_LANG_C, DBuilder->createFile(infile, "."),
"LPython Compiler", false, "", 0);
}

Expand Down Expand Up @@ -6369,12 +6372,14 @@ Result<std::unique_ptr<LLVMModule>> asr_to_llvm(ASR::TranslationUnit_t &asr,
diag::Diagnostics &diagnostics,
llvm::LLVMContext &context, Allocator &al,
LCompilers::PassManager& pass_manager,
CompilerOptions &co, const std::string &run_fn)
CompilerOptions &co, const std::string &run_fn,
const std::string &infile)
{
#if LLVM_VERSION_MAJOR >= 15
context.setOpaquePointers(false);
#endif
ASRToLLVMVisitor v(al, context, co.platform, co.emit_debug_info, diagnostics);
ASRToLLVMVisitor v(al, context, co.platform, co.emit_debug_info, infile,
co.emit_debug_line_column, diagnostics);
LCompilers::PassOptions pass_options;
pass_options.run_fun = run_fn;
pass_options.always_run = false;
Expand Down
3 changes: 2 additions & 1 deletion src/libasr/codegen/asr_to_llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace LFortran {
llvm::LLVMContext &context, Allocator &al,
LCompilers::PassManager& pass_manager,
CompilerOptions &co,
const std::string &run_fn);
const std::string &run_fn,
const std::string &infile);

} // namespace LFortran

Expand Down
6 changes: 3 additions & 3 deletions src/lpython/python_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ PythonCompiler::~PythonCompiler() = default;
Result<std::unique_ptr<LLVMModule>> PythonCompiler::get_llvm3(
#ifdef HAVE_LFORTRAN_LLVM
ASR::TranslationUnit_t &asr, LCompilers::PassManager& lpm,
diag::Diagnostics &diagnostics
diag::Diagnostics &diagnostics, const std::string &infile
#else
ASR::TranslationUnit_t &/*asr*/, LCompilers::PassManager&/*lpm*/,
diag::Diagnostics &/*diagnostics*/
diag::Diagnostics &/*diagnostics*/,const std::string &/*infile*/
#endif
)
{
Expand All @@ -55,7 +55,7 @@ Result<std::unique_ptr<LLVMModule>> PythonCompiler::get_llvm3(
Result<std::unique_ptr<LFortran::LLVMModule>> res
= asr_to_llvm(asr, diagnostics,
e->get_context(), al, lpm, compiler_options,
run_fn);
run_fn, infile);
if (res.ok) {
m = std::move(res.result);
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/lpython/python_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class PythonCompiler
};

Result<std::unique_ptr<LLVMModule>> get_llvm3(ASR::TranslationUnit_t &asr,
LCompilers::PassManager& lpm, diag::Diagnostics &diagnostics);
LCompilers::PassManager& lpm, diag::Diagnostics &diagnostics,
const std::string &infile);

private:
Allocator al;
Expand Down

0 comments on commit ebd5168

Please sign in to comment.