From 069c6cac3f42ec7a2428062b0e8c481b755534ad Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 5 Dec 2020 20:47:50 +0000 Subject: [PATCH] Add package name and source code location to `Type_Info_Named` --- core/runtime/core.odin | 7 ++++++- src/ir.cpp | 15 +++++++++++++++ src/llvm_backend.cpp | 23 ++++++++++++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/core/runtime/core.odin b/core/runtime/core.odin index 0dfef269c..2a744a241 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -55,7 +55,12 @@ Type_Info_Struct_Soa_Kind :: enum u8 { } // Variant Types -Type_Info_Named :: struct {name: string, base: ^Type_Info}; +Type_Info_Named :: struct { + name: string, + base: ^Type_Info, + pkg: string, + loc: Source_Code_Location, +}; Type_Info_Integer :: struct {signed: bool, endianness: Platform_Endianness}; Type_Info_Rune :: struct {}; Type_Info_Float :: struct {endianness: Platform_Endianness}; diff --git a/src/ir.cpp b/src/ir.cpp index 1e364c7ba..e46eb27fb 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -12172,6 +12172,21 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), name); ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 1), gtip); + + if (t->Named.type_name->pkg) { + irValue *name = ir_const_string(proc->module, t->Named.type_name->pkg->name); + ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 2), name); + } + + String proc_name = {}; + if (t->Named.type_name->parent_proc_decl) { + DeclInfo *decl = t->Named.type_name->parent_proc_decl; + if (decl->entity && decl->entity->kind == Entity_Procedure) { + proc_name = decl->entity->token.string; + } + } + irValue *loc = ir_emit_source_code_location(proc, proc_name, t->Named.type_name->token.pos); + ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 3), loc); break; } diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 213c05a52..d92108044 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -11973,9 +11973,30 @@ void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info da switch (t->kind) { case Type_Named: { tag = lb_const_ptr_cast(m, variant_ptr, t_type_info_named_ptr); - LLVMValueRef vals[2] = { + + LLVMValueRef pkg_name = nullptr; + if (t->Named.type_name->pkg) { + pkg_name = lb_const_string(m, t->Named.type_name->pkg->name).value; + } else { + pkg_name = LLVMConstNull(lb_type(m, t_string)); + } + + String proc_name = {}; + if (t->Named.type_name->parent_proc_decl) { + DeclInfo *decl = t->Named.type_name->parent_proc_decl; + if (decl->entity && decl->entity->kind == Entity_Procedure) { + proc_name = decl->entity->token.string; + } + } + TokenPos pos = t->Named.type_name->token.pos; + + lbValue loc = lb_emit_source_code_location(p, proc_name, pos); + + LLVMValueRef vals[4] = { lb_const_string(p->module, t->Named.type_name->token.string).value, lb_get_type_info_ptr(m, t->Named.base).value, + pkg_name, + loc.value }; lbValue res = {};