mirror of
https://github.com/edg-l/edlang.git
synced 2024-11-09 09:38:24 +00:00
fix: debug type names
This commit is contained in:
parent
54f148b4ef
commit
dd7b949a44
|
@ -411,7 +411,7 @@ fn compile_fn(ctx: &ModuleCompileCtx, fn_id: DefId) -> Result<(), BuilderError>
|
||||||
"",
|
"",
|
||||||
)?;
|
)?;
|
||||||
local_ty = match local_ty.kind {
|
local_ty = match local_ty.kind {
|
||||||
ir::TypeKind::Struct(id) => {
|
ir::TypeKind::Struct(id, _) => {
|
||||||
let strc = ctx.ctx.program.structs.get(&id).unwrap();
|
let strc = ctx.ctx.program.structs.get(&id).unwrap();
|
||||||
strc.variants[*field_idx].ty.clone()
|
strc.variants[*field_idx].ty.clone()
|
||||||
}
|
}
|
||||||
|
@ -1065,7 +1065,7 @@ fn compile_load_place<'ctx>(
|
||||||
}
|
}
|
||||||
ir::PlaceElem::Field { field_idx } => {
|
ir::PlaceElem::Field { field_idx } => {
|
||||||
local_ty = match local_ty.kind {
|
local_ty = match local_ty.kind {
|
||||||
ir::TypeKind::Struct(id) => {
|
ir::TypeKind::Struct(id, _) => {
|
||||||
let struct_body = ctx.ctx.program.structs.get(&id).unwrap();
|
let struct_body = ctx.ctx.program.structs.get(&id).unwrap();
|
||||||
let ty = struct_body.variants[*field_idx].ty.clone();
|
let ty = struct_body.variants[*field_idx].ty.clone();
|
||||||
let field_name = struct_body.variants[*field_idx].name.clone();
|
let field_name = struct_body.variants[*field_idx].name.clone();
|
||||||
|
@ -1235,7 +1235,7 @@ fn compile_basic_type<'ctx>(
|
||||||
.ptr_sized_int_type(&ctx.target_data, None)
|
.ptr_sized_int_type(&ctx.target_data, None)
|
||||||
.ptr_type(AddressSpace::default())
|
.ptr_type(AddressSpace::default())
|
||||||
.as_basic_type_enum(),
|
.as_basic_type_enum(),
|
||||||
ir::TypeKind::Struct(id) => {
|
ir::TypeKind::Struct(id, _) => {
|
||||||
let body = ctx.ctx.program.structs.get(id).unwrap();
|
let body = ctx.ctx.program.structs.get(id).unwrap();
|
||||||
|
|
||||||
let mut fields = Vec::new();
|
let mut fields = Vec::new();
|
||||||
|
@ -1263,91 +1263,93 @@ fn compile_debug_type<'ctx>(ctx: &ModuleCompileCtx<'ctx, '_>, ty: &ir::TypeInfo)
|
||||||
// https://dwarfstd.org/doc/DWARF5.pdf#section.7.8
|
// https://dwarfstd.org/doc/DWARF5.pdf#section.7.8
|
||||||
|
|
||||||
// https://github.com/GaloisInc/dwarf-tools/blob/master/src/DWARF/DW/TAG.hs
|
// https://github.com/GaloisInc/dwarf-tools/blob/master/src/DWARF/DW/TAG.hs
|
||||||
|
let name = ty.kind.to_string();
|
||||||
|
let name = &name;
|
||||||
match &ty.kind {
|
match &ty.kind {
|
||||||
ir::TypeKind::Unit => todo!(),
|
ir::TypeKind::Unit => todo!(),
|
||||||
ir::TypeKind::Bool => ctx
|
ir::TypeKind::Bool => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_basic_type("bool", 1, 0x2, LLVMDIFlagPublic)
|
.create_basic_type(name, 1, 0x2, LLVMDIFlagPublic)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_type(),
|
.as_type(),
|
||||||
ir::TypeKind::Char => ctx
|
ir::TypeKind::Char => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_basic_type("char", 8, 0x6, LLVMDIFlagPublic)
|
.create_basic_type(name, 8, 0x6, LLVMDIFlagPublic)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_type(),
|
.as_type(),
|
||||||
ir::TypeKind::Int(ty) => match ty {
|
ir::TypeKind::Int(ty) => match ty {
|
||||||
ir::IntTy::I128 => ctx
|
ir::IntTy::I128 => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_basic_type("i128", 128, 0x5, LLVMDIFlagPublic)
|
.create_basic_type(name, 128, 0x5, LLVMDIFlagPublic)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_type(),
|
.as_type(),
|
||||||
ir::IntTy::I64 => ctx
|
ir::IntTy::I64 => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_basic_type("i64", 64, 0x5, LLVMDIFlagPublic)
|
.create_basic_type(name, 64, 0x5, LLVMDIFlagPublic)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_type(),
|
.as_type(),
|
||||||
ir::IntTy::I32 => ctx
|
ir::IntTy::I32 => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_basic_type("i32", 32, 0x5, LLVMDIFlagPublic)
|
.create_basic_type(name, 32, 0x5, LLVMDIFlagPublic)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_type(),
|
.as_type(),
|
||||||
ir::IntTy::I16 => ctx
|
ir::IntTy::I16 => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_basic_type("i16", 16, 0x5, LLVMDIFlagPublic)
|
.create_basic_type(name, 16, 0x5, LLVMDIFlagPublic)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_type(),
|
.as_type(),
|
||||||
ir::IntTy::I8 => ctx
|
ir::IntTy::I8 => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_basic_type("i8", 8, 0x5, LLVMDIFlagPublic)
|
.create_basic_type(name, 8, 0x5, LLVMDIFlagPublic)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_type(),
|
.as_type(),
|
||||||
ir::IntTy::Isize => ctx
|
ir::IntTy::Isize => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_basic_type("isize", 64, 0x5, LLVMDIFlagPublic)
|
.create_basic_type(name, 64, 0x5, LLVMDIFlagPublic)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_type(),
|
.as_type(),
|
||||||
},
|
},
|
||||||
ir::TypeKind::Uint(ty) => match ty {
|
ir::TypeKind::Uint(ty) => match ty {
|
||||||
ir::UintTy::U128 => ctx
|
ir::UintTy::U128 => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_basic_type("u128", 128, 0x7, LLVMDIFlagPublic)
|
.create_basic_type(name, 128, 0x7, LLVMDIFlagPublic)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_type(),
|
.as_type(),
|
||||||
ir::UintTy::U64 => ctx
|
ir::UintTy::U64 => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_basic_type("u64", 64, 0x7, LLVMDIFlagPublic)
|
.create_basic_type(name, 64, 0x7, LLVMDIFlagPublic)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_type(),
|
.as_type(),
|
||||||
ir::UintTy::U32 => ctx
|
ir::UintTy::U32 => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_basic_type("u32", 32, 0x7, LLVMDIFlagPublic)
|
.create_basic_type(name, 32, 0x7, LLVMDIFlagPublic)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_type(),
|
.as_type(),
|
||||||
ir::UintTy::U16 => ctx
|
ir::UintTy::U16 => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_basic_type("u16", 16, 0x7, LLVMDIFlagPublic)
|
.create_basic_type(name, 16, 0x7, LLVMDIFlagPublic)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_type(),
|
.as_type(),
|
||||||
ir::UintTy::U8 => ctx
|
ir::UintTy::U8 => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_basic_type("u8", 8, 0x7, LLVMDIFlagPublic)
|
.create_basic_type(name, 8, 0x7, LLVMDIFlagPublic)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_type(),
|
.as_type(),
|
||||||
ir::UintTy::Usize => ctx
|
ir::UintTy::Usize => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_basic_type("usize", 64, 0x7, LLVMDIFlagPublic)
|
.create_basic_type(name, 64, 0x7, LLVMDIFlagPublic)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_type(),
|
.as_type(),
|
||||||
},
|
},
|
||||||
ir::TypeKind::Float(ty) => match ty {
|
ir::TypeKind::Float(ty) => match ty {
|
||||||
ir::FloatTy::F32 => ctx
|
ir::FloatTy::F32 => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_basic_type("f32", 32, 4, LLVMDIFlagPublic)
|
.create_basic_type(name, 32, 4, LLVMDIFlagPublic)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_type(),
|
.as_type(),
|
||||||
ir::FloatTy::F64 => ctx
|
ir::FloatTy::F64 => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_basic_type("f64", 64, 4, LLVMDIFlagPublic)
|
.create_basic_type(name, 64, 4, LLVMDIFlagPublic)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_type(),
|
.as_type(),
|
||||||
},
|
},
|
||||||
|
@ -1357,7 +1359,7 @@ fn compile_debug_type<'ctx>(ctx: &ModuleCompileCtx<'ctx, '_>, ty: &ir::TypeInfo)
|
||||||
ir::TypeKind::Ptr(_is_mut, pointee) => ctx
|
ir::TypeKind::Ptr(_is_mut, pointee) => ctx
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_pointer_type(
|
.create_pointer_type(
|
||||||
&format!("*{:?}", pointee.kind),
|
name,
|
||||||
compile_debug_type(ctx, pointee),
|
compile_debug_type(ctx, pointee),
|
||||||
(ctx.target_data.get_pointer_byte_size(None) * 8).into(),
|
(ctx.target_data.get_pointer_byte_size(None) * 8).into(),
|
||||||
ctx.target_data.get_pointer_byte_size(None),
|
ctx.target_data.get_pointer_byte_size(None),
|
||||||
|
@ -1368,7 +1370,7 @@ fn compile_debug_type<'ctx>(ctx: &ModuleCompileCtx<'ctx, '_>, ty: &ir::TypeInfo)
|
||||||
.di_builder
|
.di_builder
|
||||||
.create_reference_type(compile_debug_type(ctx, inner), 0x10)
|
.create_reference_type(compile_debug_type(ctx, inner), 0x10)
|
||||||
.as_type(),
|
.as_type(),
|
||||||
ir::TypeKind::Struct(id) => {
|
ir::TypeKind::Struct(id, _) => {
|
||||||
let body = ctx.ctx.program.structs.get(id).unwrap();
|
let body = ctx.ctx.program.structs.get(id).unwrap();
|
||||||
|
|
||||||
let mut fields = Vec::new();
|
let mut fields = Vec::new();
|
||||||
|
|
|
@ -239,7 +239,8 @@ pub enum TypeKind {
|
||||||
Str,
|
Str,
|
||||||
Ptr(bool, Box<TypeInfo>),
|
Ptr(bool, Box<TypeInfo>),
|
||||||
Ref(bool, Box<TypeInfo>),
|
Ref(bool, Box<TypeInfo>),
|
||||||
Struct(DefId), // todo, add generics
|
// name for print purposes
|
||||||
|
Struct(DefId, String), // todo, add generics
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TypeKind {
|
impl TypeKind {
|
||||||
|
@ -276,7 +277,7 @@ impl TypeKind {
|
||||||
TypeKind::FnDef(_, _) => unreachable!(),
|
TypeKind::FnDef(_, _) => unreachable!(),
|
||||||
TypeKind::Ptr(_, _pointee) => todo!(),
|
TypeKind::Ptr(_, _pointee) => todo!(),
|
||||||
TypeKind::Ref(_, inner) => inner.kind.get_falsy_value(),
|
TypeKind::Ref(_, inner) => inner.kind.get_falsy_value(),
|
||||||
TypeKind::Struct(_) => todo!(),
|
TypeKind::Struct(_, _name) => todo!(),
|
||||||
TypeKind::Str => todo!(),
|
TypeKind::Str => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -320,7 +321,7 @@ impl fmt::Display for TypeKind {
|
||||||
|
|
||||||
write!(f, "&{word} {}", inner.kind)
|
write!(f, "&{word} {}", inner.kind)
|
||||||
}
|
}
|
||||||
TypeKind::Struct(_) => todo!(),
|
TypeKind::Struct(_, name) => write!(f, "{}", name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -560,7 +560,7 @@ fn find_expr_type(builder: &mut BodyBuilder, info: &ast::Expression) -> Option<T
|
||||||
.structs
|
.structs
|
||||||
.get(&info.name.name.name)
|
.get(&info.name.name.name)
|
||||||
.expect("struct not found");
|
.expect("struct not found");
|
||||||
ir::TypeKind::Struct(id)
|
ir::TypeKind::Struct(id, info.name.name.name.clone())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -663,7 +663,7 @@ fn lower_expr(
|
||||||
.get(&info.name.name.name)
|
.get(&info.name.name.name)
|
||||||
.expect("struct not found");
|
.expect("struct not found");
|
||||||
let struct_body = builder.ctx.body.structs.get(&id).unwrap().clone();
|
let struct_body = builder.ctx.body.structs.get(&id).unwrap().clone();
|
||||||
let ty = TypeKind::Struct(id);
|
let ty = TypeKind::Struct(id, struct_body.name.clone());
|
||||||
let struct_local = builder.add_local(Local::temp(ty.clone()));
|
let struct_local = builder.add_local(Local::temp(ty.clone()));
|
||||||
|
|
||||||
let place = Place {
|
let place = Place {
|
||||||
|
@ -1114,7 +1114,7 @@ fn lower_path(
|
||||||
ty = inner.kind;
|
ty = inner.kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let TypeKind::Struct(id) = ty {
|
if let TypeKind::Struct(id, _name) = ty {
|
||||||
let struct_body = builder.ctx.body.structs.get(&id).unwrap();
|
let struct_body = builder.ctx.body.structs.get(&id).unwrap();
|
||||||
let idx = *struct_body.name_to_idx.get(&name.name).unwrap();
|
let idx = *struct_body.name_to_idx.get(&name.name).unwrap();
|
||||||
projection.push(PlaceElem::Field { field_idx: idx });
|
projection.push(PlaceElem::Field { field_idx: idx });
|
||||||
|
@ -1204,7 +1204,7 @@ pub fn lower_type(
|
||||||
let struct_body = ctx.body.structs.get(struct_id).unwrap();
|
let struct_body = ctx.body.structs.get(struct_id).unwrap();
|
||||||
ir::TypeInfo {
|
ir::TypeInfo {
|
||||||
span: Some(struct_body.span),
|
span: Some(struct_body.span),
|
||||||
kind: TypeKind::Struct(*struct_id),
|
kind: TypeKind::Struct(*struct_id, struct_body.name.clone()),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(LoweringError::UnrecognizedType {
|
Err(LoweringError::UnrecognizedType {
|
||||||
|
|
Loading…
Reference in a new issue