diff --git a/Makefile b/Makefile index 6c323ca..d7291c3 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ clean: rm -f $(BIN) $(SRC:.reid=.o) $(SRC:.reid=.asm) $(SRC:.reid=.ll) $(BIN): $(SRC:.reid=.o) - $(LD) -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/crt1.o -lc $(LDFLAGS) $< -o$@ + $(LD) -O0 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/crt1.o -lc $(LDFLAGS) $< -o$@ .SUFFIXES: .o .reid .reid.o: diff --git a/reid-llvm-lib/src/compile.rs b/reid-llvm-lib/src/compile.rs index 5fb9d62..db0d6cd 100644 --- a/reid-llvm-lib/src/compile.rs +++ b/reid-llvm-lib/src/compile.rs @@ -432,7 +432,18 @@ impl DebugMetadataHolder { param.always_preserve as i32, param.flags.as_llvm(), ), - DebugMetadata::LocalVar(debug_local_variable) => todo!(), + DebugMetadata::LocalVar(var) => LLVMDIBuilderCreateAutoVariable( + debug.builder, + *debug.programs.get(&self.program).unwrap(), + into_cstring(var.name.clone()).as_ptr(), + var.name.len(), + debug.file_ref, + var.location.line, + *debug.types.get(&var.ty).unwrap(), + var.always_preserve as i32, + var.flags.as_llvm(), + var.alignment, + ), } } } diff --git a/reid-llvm-lib/src/debug_information.rs b/reid-llvm-lib/src/debug_information.rs index 3f5b3f6..e469323 100644 --- a/reid-llvm-lib/src/debug_information.rs +++ b/reid-llvm-lib/src/debug_information.rs @@ -229,9 +229,10 @@ pub struct DebugParamVariable { pub struct DebugLocalVariable { pub name: String, pub location: DebugLocation, - pub ty: DebugMetadataValue, + pub ty: DebugTypeValue, pub always_preserve: bool, pub alignment: u32, + pub flags: DwarfFlags, } impl Default for DebugSubprogramOptionals { diff --git a/reid/src/codegen.rs b/reid/src/codegen.rs index 2da7fc8..4d0169a 100644 --- a/reid/src/codegen.rs +++ b/reid/src/codegen.rs @@ -4,8 +4,8 @@ use reid_lib::{ builder::{InstructionValue, TypeValue}, compile::CompiledModule, debug_information::{ - DebugBasicType, DebugFileData, DebugInformation, DebugLocation, DebugMetadata, - DebugMetadataValue, DebugParamVariable, DebugProgramValue, DebugScopeValue, + DebugBasicType, DebugFileData, DebugInformation, DebugLocalVariable, DebugLocation, + DebugMetadata, DebugMetadataValue, DebugParamVariable, DebugProgramValue, DebugScopeValue, DebugSubprogramData, DebugSubprogramOptionals, DebugSubprogramTypeData, DebugTypeData, DebugTypeValue, DwarfEncoding, DwarfFlags, }, @@ -440,6 +440,20 @@ impl mir::Statement { ty.get_type(scope.type_values, scope.types), ), ); + if let Some(debug) = &scope.debug { + let location = self.1.into_debug(scope.tokens).unwrap(); + debug.info.metadata( + &debug.scope, + DebugMetadata::LocalVar(DebugLocalVariable { + name: name.clone(), + location, + ty: scope.debug_const_tys.get(&TypeKind::U32).unwrap().clone(), + always_preserve: true, + alignment: 32, + flags: DwarfFlags, + }), + ); + } None } mir::StmtKind::Set(lhs, rhs) => {