Add array and pointer-types to lib
This commit is contained in:
parent
d64cf750b1
commit
98169af415
@ -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,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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<DebugTypeValue>,
|
||||
pub element_type: DebugTypeValue,
|
||||
pub subscripts: Vec<DebugTypeValue>,
|
||||
}
|
||||
|
||||
#[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<DebugTypeValue>,
|
||||
pub flags: DwarfFlags,
|
||||
}
|
||||
|
||||
pub struct DebugSubprogramType {
|
||||
pub params: Vec<DebugProgramValue>,
|
||||
pub parameters: Vec<DebugTypeValue>,
|
||||
pub flags: DwarfFlags,
|
||||
}
|
||||
|
||||
|
@ -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(),
|
||||
|
Loading…
Reference in New Issue
Block a user