mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-02 08:47:57 +00:00
Static array debug info. Temporary dynamic array debug info (pointer to data, no len/cap info provided yet).
This commit is contained in:
41
src/ir.cpp
41
src/ir.cpp
@@ -585,6 +585,7 @@ struct irDebugInfo {
|
||||
Array<irDebugInfo *> param_types;
|
||||
} ProcType; // TODO(lachsinc): Unused?
|
||||
struct {
|
||||
// TODO(lachsinc): Do derived types even need scope/file/line etc. info?
|
||||
irDebugEncoding tag;
|
||||
String name;
|
||||
irDebugInfo * scope;
|
||||
@@ -606,6 +607,7 @@ struct irDebugInfo {
|
||||
i32 size;
|
||||
i32 align;
|
||||
Array<irDebugInfo *> elements;
|
||||
i32 array_count; // TODO(lach): We could define a new !DISubrange and place ptr to it inside above elements array instead.
|
||||
} CompositeType;
|
||||
struct {
|
||||
String name;
|
||||
@@ -1752,6 +1754,45 @@ irDebugInfo *ir_add_debug_info_type(irModule *module, irDebugInfo *scope, Entity
|
||||
return di;
|
||||
}
|
||||
|
||||
// TODO(lachsinc): Not sure if correct.. Also cleanup
|
||||
// NOTE(lachsinc): For now dynamic arrays are just a pointer to their data.
|
||||
// We could get fancy and use a composite type along with
|
||||
// DW_TAG_class_type / template debug stuff eventually.
|
||||
if (is_type_dynamic_array(type)) {
|
||||
irDebugInfo *di = ir_alloc_debug_info(irDebugInfo_DerivedType);
|
||||
|
||||
auto elem_type = type->DynamicArray.elem;
|
||||
|
||||
di->DerivedType.name = str_lit("dynamic_array_todo");
|
||||
di->DerivedType.tag = irDebugBasicEncoding_pointer_type;
|
||||
di->DerivedType.scope = scope;
|
||||
di->DerivedType.file = file;
|
||||
di->DerivedType.pos = e->token.pos;
|
||||
di->DerivedType.base_type = ir_add_debug_info_type(module, scope, e, elem_type, file);
|
||||
di->DerivedType.size = 64; // TODO(lachsinc): HACK
|
||||
di->DerivedType.align = 0; // TODO(lachsinc): HACK
|
||||
|
||||
GB_ASSERT(base->kind != Type_Named);
|
||||
map_set(&module->debug_info, hash_type(type), di);
|
||||
|
||||
return di;
|
||||
}
|
||||
|
||||
if (is_type_array(type)) {
|
||||
|
||||
irDebugInfo *di = ir_alloc_debug_info(irDebugInfo_CompositeType);
|
||||
di->CompositeType.size = 8*cast(i32)type_size_of(type); // TODO(lachsinc): Confirm correct array sizing. llvm expects size in bits!
|
||||
di->CompositeType.align = 8*cast(i32)type_align_of(type);
|
||||
di->CompositeType.base_type = ir_add_debug_info_type(module, scope, e, type->Array.elem, file);
|
||||
di->CompositeType.tag = irDebugBasicEncoding_array_type;
|
||||
di->CompositeType.array_count = (i32)type->Array.count;
|
||||
|
||||
GB_ASSERT(base->kind != Type_Named);
|
||||
map_set(&module->debug_info, hash_type(type), di);
|
||||
|
||||
return di;
|
||||
}
|
||||
|
||||
//
|
||||
// TODO(lachsinc): HACK For now any remaining types interpreted as a rawptr.
|
||||
//
|
||||
|
||||
@@ -2034,13 +2034,16 @@ void print_llvm_ir(irGen *ir) {
|
||||
"name: \"%.*s\""
|
||||
", baseType: !%d"
|
||||
", size: %d"
|
||||
", align: %d"
|
||||
", tag: ",
|
||||
LIT(di->DerivedType.name),
|
||||
di->DerivedType.base_type->id,
|
||||
di->DerivedType.size,
|
||||
di->DerivedType.align);
|
||||
ir_print_debug_encoding(f, irDebugInfo_DerivedType, di->DerivedType.tag);
|
||||
if (di->DerivedType.align > 0) {
|
||||
ir_fprintf(f, ", align: %d",
|
||||
di->DerivedType.align);
|
||||
}
|
||||
if (di->DerivedType.offset > 0) {
|
||||
ir_fprintf(f, ", offset: %d",
|
||||
di->DerivedType.offset);
|
||||
@@ -2048,35 +2051,50 @@ void print_llvm_ir(irGen *ir) {
|
||||
ir_write_byte(f, ')');
|
||||
break;
|
||||
case irDebugInfo_CompositeType: {
|
||||
ir_fprintf(f, "!DICompositeType("
|
||||
"name: \"%.*s\""
|
||||
", scope: !%d"
|
||||
", file: !%d"
|
||||
", line: %td"
|
||||
", size: %d"
|
||||
", align: %d"
|
||||
", tag: ",
|
||||
LIT(di->CompositeType.name),
|
||||
di->CompositeType.scope->id,
|
||||
di->CompositeType.file->id,
|
||||
di->CompositeType.pos.line,
|
||||
di->CompositeType.size,
|
||||
di->CompositeType.align);
|
||||
ir_print_debug_encoding(f, irDebugInfo_CompositeType, di->CompositeType.tag);
|
||||
if (di->CompositeType.base_type) {
|
||||
GB_ASSERT(di->CompositeType.tag == irDebugBasicEncoding_enumeration_type);
|
||||
ir_fprintf(f, ", baseType: !%d", di->CompositeType.base_type->id);
|
||||
}
|
||||
if (di->CompositeType.elements.count > 0) {
|
||||
ir_write_str_lit(f, ", elements: !{");
|
||||
for_array(element_index, di->CompositeType.elements) {
|
||||
ir_fprintf(f, "%s!%d",
|
||||
element_index > 0 ? ", " : "",
|
||||
di->CompositeType.elements[element_index]->id);
|
||||
if (di->CompositeType.tag == irDebugBasicEncoding_array_type) {
|
||||
GB_ASSERT(di->CompositeType.base_type);
|
||||
ir_fprintf(f, "!DICompositeType("
|
||||
"tag: DW_TAG_array_type"
|
||||
", size: %d"
|
||||
", align: %d"
|
||||
", baseType: !%d"
|
||||
", elements: !{!DISubrange(count: %d)}"
|
||||
")",
|
||||
di->CompositeType.size,
|
||||
di->CompositeType.align,
|
||||
di->CompositeType.base_type->id,
|
||||
di->CompositeType.array_count);
|
||||
} else {
|
||||
ir_fprintf(f, "!DICompositeType("
|
||||
"name: \"%.*s\""
|
||||
", scope: !%d"
|
||||
", file: !%d"
|
||||
", line: %td"
|
||||
", size: %d"
|
||||
", align: %d"
|
||||
", tag: ",
|
||||
LIT(di->CompositeType.name),
|
||||
di->CompositeType.scope->id,
|
||||
di->CompositeType.file->id,
|
||||
di->CompositeType.pos.line,
|
||||
di->CompositeType.size,
|
||||
di->CompositeType.align);
|
||||
ir_print_debug_encoding(f, irDebugInfo_CompositeType, di->CompositeType.tag);
|
||||
if (di->CompositeType.base_type) {
|
||||
GB_ASSERT(di->CompositeType.tag == irDebugBasicEncoding_enumeration_type);
|
||||
ir_fprintf(f, ", baseType: !%d", di->CompositeType.base_type->id);
|
||||
}
|
||||
ir_write_byte(f, '}');
|
||||
if (di->CompositeType.elements.count > 0) {
|
||||
ir_write_str_lit(f, ", elements: !{");
|
||||
for_array(element_index, di->CompositeType.elements) {
|
||||
ir_fprintf(f, "%s!%d",
|
||||
element_index > 0 ? ", " : "",
|
||||
di->CompositeType.elements[element_index]->id);
|
||||
}
|
||||
ir_write_byte(f, '}');
|
||||
}
|
||||
ir_write_byte(f, ')');
|
||||
}
|
||||
ir_write_byte(f, ')');
|
||||
break;
|
||||
}
|
||||
case irDebugInfo_Enumerator: {
|
||||
|
||||
Reference in New Issue
Block a user