Add debug information to everything (for now)
This commit is contained in:
parent
e1d014bcc2
commit
e75c38ad85
@ -756,11 +756,14 @@ impl InstructionHolder {
|
|||||||
module.values.get(&ptr).unwrap().value_ref,
|
module.values.get(&ptr).unwrap().value_ref,
|
||||||
c"load".as_ptr(),
|
c"load".as_ptr(),
|
||||||
),
|
),
|
||||||
Store(ptr, val) => LLVMBuildStore(
|
Store(ptr, val) => {
|
||||||
module.builder_ref,
|
let store = LLVMBuildStore(
|
||||||
module.values.get(&val).unwrap().value_ref,
|
module.builder_ref,
|
||||||
module.values.get(&ptr).unwrap().value_ref,
|
module.values.get(&val).unwrap().value_ref,
|
||||||
),
|
module.values.get(&ptr).unwrap().value_ref,
|
||||||
|
);
|
||||||
|
store
|
||||||
|
}
|
||||||
ArrayAlloca(ty, len) => {
|
ArrayAlloca(ty, len) => {
|
||||||
let array_len = ConstValue::U16(*len as u16).as_llvm(module);
|
let array_len = ConstValue::U16(*len as u16).as_llvm(module);
|
||||||
LLVMBuildArrayAlloca(
|
LLVMBuildArrayAlloca(
|
||||||
@ -810,6 +813,7 @@ impl InstructionHolder {
|
|||||||
};
|
};
|
||||||
if let Some(location) = &self.data.location {
|
if let Some(location) = &self.data.location {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
// dbg!(&self.data.kind, LLVMGetValueKind(val));
|
||||||
match LLVMGetValueKind(val) {
|
match LLVMGetValueKind(val) {
|
||||||
LLVMValueKind::LLVMInstructionValueKind
|
LLVMValueKind::LLVMInstructionValueKind
|
||||||
| LLVMValueKind::LLVMMemoryDefValueKind
|
| LLVMValueKind::LLVMMemoryDefValueKind
|
||||||
|
@ -394,6 +394,12 @@ impl mir::Statement {
|
|||||||
scope: &mut Scope<'ctx, 'a>,
|
scope: &mut Scope<'ctx, 'a>,
|
||||||
state: &State,
|
state: &State,
|
||||||
) -> Option<InstructionValue> {
|
) -> Option<InstructionValue> {
|
||||||
|
let location = self.1.into_debug(scope.tokens).unwrap();
|
||||||
|
let location = scope
|
||||||
|
.debug
|
||||||
|
.as_ref()
|
||||||
|
.map(|d| d.info.location(&d.scope, location));
|
||||||
|
|
||||||
match &self.0 {
|
match &self.0 {
|
||||||
mir::StmtKind::Let(NamedVariableRef(ty, name, _), mutable, expression) => {
|
mir::StmtKind::Let(NamedVariableRef(ty, name, _), mutable, expression) => {
|
||||||
let value = expression.codegen(scope, &state).unwrap();
|
let value = expression.codegen(scope, &state).unwrap();
|
||||||
@ -420,8 +426,13 @@ impl mir::Statement {
|
|||||||
name.clone(),
|
name.clone(),
|
||||||
ty.get_type(scope.type_values, scope.types),
|
ty.get_type(scope.type_values, scope.types),
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap()
|
||||||
scope.block.build(Instr::Store(alloca, value)).unwrap();
|
.maybe_location(&mut scope.block, location);
|
||||||
|
scope
|
||||||
|
.block
|
||||||
|
.build(Instr::Store(alloca, value))
|
||||||
|
.unwrap()
|
||||||
|
.maybe_location(&mut scope.block, location);
|
||||||
alloca
|
alloca
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
@ -442,7 +453,8 @@ impl mir::Statement {
|
|||||||
scope
|
scope
|
||||||
.block
|
.block
|
||||||
.build(Instr::Store(lhs_value, rhs_value))
|
.build(Instr::Store(lhs_value, rhs_value))
|
||||||
.unwrap(),
|
.unwrap()
|
||||||
|
.maybe_location(&mut scope.block, location),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
mir::StmtKind::Import(_) => todo!(),
|
mir::StmtKind::Import(_) => todo!(),
|
||||||
@ -567,7 +579,8 @@ impl mir::Expression {
|
|||||||
let mut ptr = scope
|
let mut ptr = scope
|
||||||
.block
|
.block
|
||||||
.build(Instr::GetElemPtr(array, vec![idx]))
|
.build(Instr::GetElemPtr(array, vec![idx]))
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
.maybe_location(&mut scope.block, location);
|
||||||
|
|
||||||
if state.should_load {
|
if state.should_load {
|
||||||
ptr = scope
|
ptr = scope
|
||||||
@ -576,7 +589,8 @@ impl mir::Expression {
|
|||||||
ptr,
|
ptr,
|
||||||
val_t.get_type(scope.type_values, scope.types),
|
val_t.get_type(scope.type_values, scope.types),
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
.maybe_location(&mut scope.block, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(ptr)
|
Some(ptr)
|
||||||
@ -598,7 +612,8 @@ impl mir::Expression {
|
|||||||
instr_t.get_type(scope.type_values, scope.types),
|
instr_t.get_type(scope.type_values, scope.types),
|
||||||
instr_list.len() as u32,
|
instr_list.len() as u32,
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
.maybe_location(&mut scope.block, location);
|
||||||
|
|
||||||
for (index, instr) in instr_list.iter().enumerate() {
|
for (index, instr) in instr_list.iter().enumerate() {
|
||||||
let index_expr = scope
|
let index_expr = scope
|
||||||
@ -608,8 +623,13 @@ impl mir::Expression {
|
|||||||
let ptr = scope
|
let ptr = scope
|
||||||
.block
|
.block
|
||||||
.build(Instr::GetElemPtr(array, vec![index_expr]))
|
.build(Instr::GetElemPtr(array, vec![index_expr]))
|
||||||
.unwrap();
|
.unwrap()
|
||||||
scope.block.build(Instr::Store(ptr, *instr)).unwrap();
|
.maybe_location(&mut scope.block, location);
|
||||||
|
scope
|
||||||
|
.block
|
||||||
|
.build(Instr::Store(ptr, *instr))
|
||||||
|
.unwrap()
|
||||||
|
.maybe_location(&mut scope.block, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(array)
|
Some(array)
|
||||||
@ -634,7 +654,8 @@ impl mir::Expression {
|
|||||||
let mut value = scope
|
let mut value = scope
|
||||||
.block
|
.block
|
||||||
.build(Instr::GetStructElemPtr(struct_val, idx as u32))
|
.build(Instr::GetStructElemPtr(struct_val, idx as u32))
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
.maybe_location(&mut scope.block, location);
|
||||||
|
|
||||||
if state.should_load {
|
if state.should_load {
|
||||||
value = scope
|
value = scope
|
||||||
@ -655,15 +676,21 @@ impl mir::Expression {
|
|||||||
name.clone(),
|
name.clone(),
|
||||||
Type::CustomType(*scope.type_values.get(name)?),
|
Type::CustomType(*scope.type_values.get(name)?),
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
.maybe_location(&mut scope.block, location);
|
||||||
|
|
||||||
for (i, (_, exp)) in items.iter().enumerate() {
|
for (i, (_, exp)) in items.iter().enumerate() {
|
||||||
let elem_ptr = scope
|
let elem_ptr = scope
|
||||||
.block
|
.block
|
||||||
.build(Instr::GetStructElemPtr(struct_ptr, i as u32))
|
.build(Instr::GetStructElemPtr(struct_ptr, i as u32))
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
.maybe_location(&mut scope.block, location);
|
||||||
if let Some(val) = exp.codegen(scope, state) {
|
if let Some(val) = exp.codegen(scope, state) {
|
||||||
scope.block.build(Instr::Store(elem_ptr, val)).unwrap();
|
scope
|
||||||
|
.block
|
||||||
|
.build(Instr::Store(elem_ptr, val))
|
||||||
|
.unwrap()
|
||||||
|
.maybe_location(&mut scope.block, location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user