mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-29 01:14:40 +00:00
Add various debug location stuff.
This commit is contained in:
22
src/ir.cpp
22
src/ir.cpp
@@ -28,6 +28,7 @@ struct irModule {
|
||||
irDebugInfo * debug_compile_unit;
|
||||
irDebugInfo * debug_all_enums; // TODO(lachsinc): Move into irDebugInfo_CompileUnit
|
||||
irDebugInfo * debug_all_globals; // TODO(lachsinc): Move into irDebugInfo_CompileUnit
|
||||
irDebugInfo * curr_debug_loc; // TODO(lachsinc): Temporary, remove me.
|
||||
Array<irDebugInfo *> debug_location_stack;
|
||||
|
||||
|
||||
@@ -807,6 +808,8 @@ Array<irValue *> *ir_value_referrers(irValue *v) {
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
void ir_module_add_value (irModule *m, Entity *e, irValue *v);
|
||||
void ir_module_push_debug_location(irModule *m, Ast *node, irDebugInfo *scope);
|
||||
void ir_module_pop_debug_location (irModule *m);
|
||||
void ir_emit_zero_init (irProcedure *p, irValue *address, Ast *expr);
|
||||
irValue *ir_emit_comment (irProcedure *p, String text);
|
||||
irValue *ir_emit_store (irProcedure *p, irValue *address, irValue *value);
|
||||
@@ -1508,6 +1511,12 @@ irValue *ir_add_param(irProcedure *proc, Entity *e, Ast *expr, Type *abi_type) {
|
||||
irValue *v = ir_value_param(proc, e, abi_type);
|
||||
irValueParam *p = &v->Param;
|
||||
|
||||
// TODO(lachsinc): Correct? Params we want or dont want debug info output ??
|
||||
// if so we should save/restore stack or something.
|
||||
GB_ASSERT_NOT_NULL(proc->debug_scope);
|
||||
ir_module_push_debug_location(proc->module, e->identifier, proc->debug_scope);
|
||||
defer (ir_module_pop_debug_location(proc->module)); // TODO(lachsinc): does this happen after return value calculated ??
|
||||
|
||||
switch (p->kind) {
|
||||
case irParamPass_Value: {
|
||||
irValue *l = ir_add_local(proc, e, expr, false);
|
||||
@@ -7016,7 +7025,9 @@ void ir_build_stmt(irProcedure *proc, Ast *node) {
|
||||
proc->module->stmt_state_flags = out;
|
||||
}
|
||||
|
||||
ir_module_push_debug_location(proc->module, node, proc->debug_scope);
|
||||
ir_build_stmt_internal(proc, node);
|
||||
ir_module_pop_debug_location(proc->module);
|
||||
|
||||
proc->module->stmt_state_flags = prev_stmt_state_flags;
|
||||
}
|
||||
@@ -8078,6 +8089,11 @@ void ir_begin_procedure_body(irProcedure *proc) {
|
||||
}
|
||||
}
|
||||
|
||||
if (proc->entity) { // TODO(lachsinc): Necessary ??
|
||||
GB_ASSERT_NOT_NULL(proc->debug_scope);
|
||||
ir_module_push_debug_location(proc->module, proc->entity->identifier, proc->debug_scope);
|
||||
}
|
||||
|
||||
proc->decl_block = ir_new_block(proc, proc->type_expr, "decls");
|
||||
ir_start_block(proc, proc->decl_block);
|
||||
proc->entry_block = ir_new_block(proc, proc->type_expr, "entry");
|
||||
@@ -8205,6 +8221,10 @@ void ir_end_procedure_body(irProcedure *proc) {
|
||||
proc->curr_block = nullptr;
|
||||
|
||||
ir_number_proc_registers(proc);
|
||||
|
||||
if (proc->entity) {
|
||||
ir_module_pop_debug_location(proc->module);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8328,6 +8348,8 @@ void ir_module_push_debug_location(irModule *m, Ast *node, irDebugInfo *scope) {
|
||||
// TODO(lachsinc): Assert the stack is empty when we finish ir gen process ??
|
||||
GB_ASSERT_NOT_NULL(node);
|
||||
irDebugInfo *debug_location = ir_add_debug_info_location(m, node, scope);
|
||||
// TODO(lachsinc): Ensure validity? if not valid we should push a nullptr on to ensure
|
||||
// calls to pop are safe.
|
||||
array_add(&m->debug_location_stack, debug_location);
|
||||
}
|
||||
|
||||
|
||||
@@ -1550,7 +1550,6 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
|
||||
|
||||
irInstrDebugDeclare *dd = &instr->DebugDeclare;
|
||||
Type *vt = ir_type(dd->value);
|
||||
irDebugInfo *di = dd->scope;
|
||||
Entity *e = dd->entity;
|
||||
String name = e->token.string;
|
||||
TokenPos pos = e->token.pos;
|
||||
@@ -1565,8 +1564,8 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
|
||||
ir_write_byte(f, ' ');
|
||||
ir_print_value(f, m, dd->value, vt);
|
||||
ir_fprintf(f, ", metadata !%d", local_var_di->id);
|
||||
ir_write_str_lit(f, ", metadata !DIExpression())");
|
||||
ir_fprintf(f, ", !dbg !DILocation(line: %td, column: %td, scope: !%d)", pos.line, pos.column, di->id);
|
||||
ir_write_str_lit(f, ", metadata !DIExpression())");
|
||||
ir_print_debug_location(f, m, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user