Add proper procedure type support (return types and param proc signature)

This commit is contained in:
lachsinc
2018-09-18 21:28:28 +10:00
parent 3772ea6ae1
commit 7dcad45e0d
2 changed files with 43 additions and 16 deletions
+30 -8
View File
@@ -566,7 +566,7 @@ struct irDebugInfo {
String name; String name;
irDebugInfo * file; irDebugInfo * file;
TokenPos pos; TokenPos pos;
Array<irDebugInfo *> return_types; Array<irDebugInfo *> types; // !{return, return, param, param, param.. etc.}
// TODO(lachsinc): variables / retainedNodes ? // TODO(lachsinc): variables / retainedNodes ?
} Proc; } Proc;
struct { struct {
@@ -1794,19 +1794,41 @@ irDebugInfo *ir_add_debug_info_proc(irProcedure *proc, Entity *entity, String na
di->Proc.file = file; di->Proc.file = file;
di->Proc.pos = entity->token.pos; di->Proc.pos = entity->token.pos;
isize return_count = proc->type->Proc.result_count; isize result_count = proc->type->Proc.result_count;
array_init(&di->Proc.return_types, ir_allocator(), 0, return_count); // TODO(lachsinc): ir_allocator() safe to use? isize param_count = proc->type->Proc.param_count;
if (return_count >= 1) { array_init(&di->Proc.types, ir_allocator(), 0, gb_max(result_count, 1) + param_count); // TODO(lachsinc): ir_allocator() safe to use?
TypeTuple *tuple = &proc->type->Proc.results->Tuple;
for_array(i, tuple->variables) { // Result/return types
Entity *e = tuple->variables[i]; if (result_count >= 1) {
TypeTuple *results_tuple = &proc->type->Proc.results->Tuple;
for_array(i, results_tuple->variables) {
Entity *e = results_tuple->variables[i];
if (e->kind != Entity_Variable) { if (e->kind != Entity_Variable) {
continue; // TODO(lachsinc): Confirm correct? continue; // TODO(lachsinc): Confirm correct?
} }
irDebugInfo *type_di = ir_add_debug_info_type(proc->module, di, e, e->type, file); irDebugInfo *type_di = ir_add_debug_info_type(proc->module, di, e, e->type, file);
GB_ASSERT_NOT_NULL(type_di); GB_ASSERT_NOT_NULL(type_di);
array_add(&di->Proc.return_types, type_di); array_add(&di->Proc.types, type_di);
}
} else {
// llvm expects "!{null}" for a function without return type, use nullptr to represent it.
// TODO(lachsinc): Is there a specific "void" type we should refer to?
array_add(&di->Proc.types, (irDebugInfo*)nullptr);
}
// Param types
if (param_count >= 1) {
TypeTuple *params_tuple = &proc->type->Proc.params->Tuple;
for_array(i, params_tuple->variables) {
Entity *e = params_tuple->variables[i];
if (e->kind != Entity_Variable) {
continue; // TODO(lachsinc): Confirm correct?
}
// TODO(lach): Could technically be a local?
irDebugInfo *type_di = ir_add_debug_info_type(proc->module, di, e, e->type, file);
GB_ASSERT_NOT_NULL(type_di);
array_add(&di->Proc.types, type_di);
} }
} }
+13 -8
View File
@@ -1982,16 +1982,21 @@ void print_llvm_ir(irGen *ir) {
di->Proc.pos.line, di->Proc.pos.line,
di->Proc.pos.line, // NOTE(lachsinc): Assume scopeLine always same as line. di->Proc.pos.line, // NOTE(lachsinc): Assume scopeLine always same as line.
m->debug_compile_unit->id); m->debug_compile_unit->id);
if (di->Proc.return_types.count == 0) { if (di->Proc.types.count > 0) {
ir_fprintf(f, "null})"); for_array(type_index, di->Proc.types) {
} else { if (type_index > 0) {
for_array(return_type_index, di->Proc.return_types) { ir_write_byte(f, ',');
ir_fprintf(f, "%s!%d", }
return_type_index > 0 ? ", " : "", if (di->Proc.types[type_index]) {
di->Proc.return_types[return_type_index]->id); ir_fprintf(f, "!%d", di->Proc.types[type_index]->id);
} else {
ir_write_str_lit(f, "null");
}
} }
ir_write_str_lit(f, "})"); } else {
ir_write_str_lit(f, "null");
} }
ir_write_str_lit(f, "})"); // !DISubroutineTypes close
ir_write_byte(f, ')'); ir_write_byte(f, ')');
break; break;
case irDebugInfo_LocalVariable: { case irDebugInfo_LocalVariable: {