diff --git a/reid-llvm-lib/src/compile.rs b/reid-llvm-lib/src/compile.rs index c6f7d1e..ed194d7 100644 --- a/reid-llvm-lib/src/compile.rs +++ b/reid-llvm-lib/src/compile.rs @@ -2,7 +2,10 @@ //! LLIR ([`Context`]) into LLVM IR. This module is the only one that interfaces //! with the LLVM API. -use std::{collections::HashMap, ptr::null_mut}; +use std::{ + collections::HashMap, + ptr::{null, null_mut}, +}; use llvm_sys::{ LLVMIntPredicate, LLVMLinkage, LLVMValueKind, @@ -475,6 +478,23 @@ impl DebugTypeHolder { subprogram.flags.as_llvm(), ) } + DebugTypeData::Pointer(ptr) => LLVMDIBuilderCreatePointerType( + debug.builder, + *debug.types.get(&ptr.pointee).unwrap(), + ptr.size_bits, + 0, + 0, + into_cstring(ptr.name.clone()).as_ptr(), + ptr.name.len(), + ), + DebugTypeData::Array(array) => LLVMDIBuilderCreateArrayType( + debug.builder, + array.size_bits, + array.align_bits, + *debug.types.get(&array.element_type).unwrap(), + Vec::new().as_mut_ptr(), + 0, + ), } } } diff --git a/reid-llvm-lib/src/debug.rs b/reid-llvm-lib/src/debug.rs index 98d406a..4af8932 100644 --- a/reid-llvm-lib/src/debug.rs +++ b/reid-llvm-lib/src/debug.rs @@ -9,9 +9,9 @@ use crate::{ CmpPredicate, Instr, InstructionData, TerminatorKind, builder::*, debug_information::{ - DebugBasicType, DebugLocation, DebugLocationValue, DebugMetadataHolder, DebugMetadataValue, - DebugProgramValue, DebugScopeValue, DebugSubprogramType, DebugTypeData, DebugTypeHolder, - DebugTypeValue, + DebugArrayType, DebugBasicType, DebugLocation, DebugLocationValue, DebugMetadataHolder, + DebugMetadataValue, DebugPointerType, DebugProgramValue, DebugScopeValue, + DebugSubprogramType, DebugTypeData, DebugTypeHolder, DebugTypeValue, }, }; @@ -237,8 +237,12 @@ impl Debug for DebugTypeHolder { impl Debug for DebugTypeData { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Basic(basic) => Debug::fmt(basic, f), - Self::Subprogram(subprogram) => Debug::fmt(subprogram, f), + DebugTypeData::Basic(ty) => Debug::fmt(ty, f), + DebugTypeData::Subprogram(ty) => Debug::fmt(ty, f), + DebugTypeData::Basic(ty) => Debug::fmt(ty, f), + DebugTypeData::Subprogram(ty) => Debug::fmt(ty, f), + DebugTypeData::Pointer(ty) => Debug::fmt(ty, f), + DebugTypeData::Array(ty) => Debug::fmt(ty, f), } } } @@ -257,12 +261,30 @@ impl Debug for DebugBasicType { impl Debug for DebugSubprogramType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_tuple("Subprogram") - .field(&self.params) + .field(&self.parameters) .field(&self.flags) .finish() } } +impl Debug for DebugPointerType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_tuple(&format!("Pointer<{:?}>({})", self.pointee, self.name)) + .field(&self.size_bits) + .finish() + } +} + +impl Debug for DebugArrayType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct(&format!("Array<{:?}>", self.element_type)) + .field("size_bits", &self.size_bits) + .field("align_bits", &self.align_bits) + .field("subscripts", &self.subscripts) + .finish() + } +} + impl Debug for DebugMetadataValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "Meta[{}]", self.0) diff --git a/reid-llvm-lib/src/debug_information.rs b/reid-llvm-lib/src/debug_information.rs index 633637b..4379a6f 100644 --- a/reid-llvm-lib/src/debug_information.rs +++ b/reid-llvm-lib/src/debug_information.rs @@ -257,7 +257,9 @@ pub struct DwarfFlags; #[derive(Clone)] pub enum DebugTypeData { Basic(DebugBasicType), - Subprogram(DebugSubprogramTypeData), + Subprogram(DebugSubprogramType), + Pointer(DebugPointerType), + Array(DebugArrayType), } #[derive(Clone)] @@ -273,11 +275,10 @@ pub struct DebugBasicType { #[derive(Clone)] pub struct DebugArrayType { - pub length: u64, - /// Alignment + pub size_bits: u64, pub align_bits: u32, - pub array_type: DebugTypeValue, - pub elements: Vec, + pub element_type: DebugTypeValue, + pub subscripts: Vec, } #[derive(Clone)] @@ -285,25 +286,11 @@ pub struct DebugPointerType { pub name: String, pub pointee: DebugTypeValue, pub size_bits: u64, - pub align_bits: u64, } #[derive(Clone)] -pub struct DebugStructType { - location: DebugLocationValue, - pub size_bits: u64, - pub align_bits: u64, - pub flags: DwarfFlags, -} - -#[derive(Debug, Clone)] -pub struct DebugSubprogramTypeData { - pub parameters: Vec, - pub flags: DwarfFlags, -} - pub struct DebugSubprogramType { - pub params: Vec, + pub parameters: Vec, pub flags: DwarfFlags, } diff --git a/reid/src/codegen.rs b/reid/src/codegen.rs index b970a55..687f202 100644 --- a/reid/src/codegen.rs +++ b/reid/src/codegen.rs @@ -6,7 +6,7 @@ use reid_lib::{ debug_information::{ DebugBasicType, DebugFileData, DebugInformation, DebugLocalVariable, DebugLocation, DebugMetadata, DebugMetadataValue, DebugParamVariable, DebugProgramValue, DebugRecordKind, - DebugScopeValue, DebugSubprogramData, DebugSubprogramOptionals, DebugSubprogramTypeData, + DebugScopeValue, DebugSubprogramData, DebugSubprogramOptionals, DebugSubprogramType, DebugTypeData, DebugTypeValue, DwarfEncoding, DwarfFlags, InstructionDebugRecordData, }, Block, CmpPredicate, ConstValue, Context, CustomTypeKind, Function, FunctionFlags, Instr, @@ -307,11 +307,10 @@ impl mir::Module { .return_type .get_debug_type(&debug_types, &debug); - let debug_ty = - debug.debug_type(DebugTypeData::Subprogram(DebugSubprogramTypeData { - parameters: vec![*fn_param_ty], - flags: DwarfFlags, - })); + let debug_ty = debug.debug_type(DebugTypeData::Subprogram(DebugSubprogramType { + parameters: vec![*fn_param_ty], + flags: DwarfFlags, + })); let subprogram = debug.subprogram(DebugSubprogramData { name: mir_function.name.clone(),