Make debug information work

This commit is contained in:
Sofia 2025-07-18 19:37:32 +03:00
parent b169e67ca4
commit 92f12e90eb
3 changed files with 32 additions and 20 deletions

View File

@ -8,7 +8,7 @@ use std::{
};
use llvm_sys::{
LLVMIntPredicate, LLVMLinkage,
LLVMIntPredicate, LLVMLinkage, LLVMValueKind,
analysis::LLVMVerifyModule,
core::*,
debuginfo::*,
@ -813,16 +813,24 @@ impl InstructionHolder {
};
if let Some(location) = &self.data.location {
unsafe {
// LLVMInstructionSetDebugLoc(
// val,
// *module
// .debug
// .as_ref()
// .unwrap()
// .locations
// .get(&location)
// .unwrap(),
// );
match LLVMGetValueKind(val) {
LLVMValueKind::LLVMInstructionValueKind
| LLVMValueKind::LLVMMemoryDefValueKind
| LLVMValueKind::LLVMMemoryUseValueKind
| LLVMValueKind::LLVMMemoryPhiValueKind => {
LLVMInstructionSetDebugLoc(
val,
*module
.debug
.as_ref()
.unwrap()
.locations
.get(&location)
.unwrap(),
);
}
_ => {}
}
}
}
LLVMValue {

View File

@ -364,7 +364,13 @@ impl mir::Block {
state: &State,
) -> Option<InstructionValue> {
for stmt in &self.statements {
stmt.codegen(&mut scope, state);
stmt.codegen(&mut scope, state).map(|s| {
if let Some(debug) = &scope.debug {
let location = stmt.1.into_debug(scope.tokens).unwrap();
let loc_val = debug.info.location(&debug.scope, location);
s.with_location(&mut scope.block, loc_val);
}
});
}
if let Some((kind, expr)) = &self.return_expression {
@ -484,10 +490,7 @@ impl mir::Expression {
_ => panic!("Found an unknown-mutable variable!"),
})
}
mir::ExprKind::Literal(lit) => Some(
lit.as_const(&mut scope.block)
.maybe_location(&mut scope.block, location),
),
mir::ExprKind::Literal(lit) => Some(lit.as_const(&mut scope.block)),
mir::ExprKind::BinOp(binop, lhs_exp, rhs_exp) => {
lhs_exp
.return_type()
@ -667,6 +670,7 @@ impl mir::Expression {
Some(struct_ptr)
}
}
.map(|i| i.maybe_location(&mut scope.block, location))
}
}

View File

@ -95,10 +95,10 @@ impl<'map> Pass for LinkerPass<'map> {
modules.insert(module.name.clone(), Rc::new(RefCell::new((module, tokens))));
}
// modules.insert(
// "std".to_owned(),
// Rc::new(RefCell::new(compile_std(&mut self.module_map))),
// );
modules.insert(
"std".to_owned(),
Rc::new(RefCell::new(compile_std(&mut self.module_map))),
);
let mut modules_to_process: Vec<Rc<RefCell<(Module, Vec<FullToken>)>>> =
modules.values().cloned().collect();