From 3f4b6b22dce11b538baf61705c1787e6e013af04 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 3 Jun 2018 17:55:13 +0100 Subject: [PATCH] Change our IR name mangling rules --- build.bat | 2 +- examples/demo/demo.odin | 6 +----- src/ir.cpp | 23 ++++++++++++++++------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/build.bat b/build.bat index 32e67af1e..fc1d2c881 100644 --- a/build.bat +++ b/build.bat @@ -17,7 +17,7 @@ if %release_mode% EQU 0 ( rem Debug set compiler_warnings= ^ -W4 -WX ^ -wd4100 -wd4101 -wd4127 -wd4189 ^ - -wd4201 -wd4204 -wd4244 ^ + -wd4201 -wd4204 ^ -wd4456 -wd4457 ^ -wd4512 diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin index fbb6da8c5..d4f1725ce 100644 --- a/examples/demo/demo.odin +++ b/examples/demo/demo.odin @@ -739,7 +739,7 @@ deprecated_attribute :: proc() { } main :: proc() { - when false { + when true { general_stuff(); union_type(); parametric_polymorphism(); @@ -753,8 +753,4 @@ main :: proc() { cstring_example(); deprecated_attribute(); } - - x := f32(-123); - fmt.println(abs(x)); } - diff --git a/src/ir.cpp b/src/ir.cpp index b62c39888..4843f7453 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -6147,7 +6147,7 @@ irValue *ir_build_cond(irProcedure *proc, AstNode *cond, irBlock *true_block, ir return v; } -void ir_build_poly_proc(irProcedure *proc, AstNodeProcLit *pd, Entity *e) { +void ir_build_nested_proc(irProcedure *proc, AstNodeProcLit *pd, Entity *e) { GB_ASSERT(pd->body != nullptr); if (ir_min_dep_entity(proc->module, e) == false) { @@ -6165,8 +6165,13 @@ void ir_build_poly_proc(irProcedure *proc, AstNodeProcLit *pd, Entity *e) { isize name_len = proc->name.len + 1 + pd_name.len + 1 + 10 + 1; u8 *name_text = gb_alloc_array(proc->module->allocator, u8, name_len); - i32 guid = cast(i32)proc->children.count; - name_len = gb_snprintf(cast(char *)name_text, name_len, "%.*s.%.*s-%d", LIT(proc->name), LIT(pd_name), guid); + + if (is_type_polymorphic(e->type)) { + i32 guid = cast(i32)proc->children.count; + name_len = gb_snprintf(cast(char *)name_text, name_len, "%.*s.%.*s-%d", LIT(proc->name), LIT(pd_name), guid); + } else { + name_len = gb_snprintf(cast(char *)name_text, name_len, "%.*s.%.*s", LIT(proc->name), LIT(pd_name)); + } String name = make_string(name_text, name_len-1); @@ -6221,8 +6226,12 @@ void ir_build_constant_value_decl(irProcedure *proc, AstNodeValueDecl *vd) { irModule *m = proc->module; isize name_len = proc->name.len + 1 + ts_name.len + 1 + 10 + 1; u8 *name_text = gb_alloc_array(m->allocator, u8, name_len); - i32 guid = cast(i32)m->members.entries.count; - name_len = gb_snprintf(cast(char *)name_text, name_len, "%.*s.%.*s-%d", LIT(proc->name), LIT(ts_name), guid); + if (is_type_polymorphic(e->type)) { + i32 guid = cast(i32)m->members.entries.count; + name_len = gb_snprintf(cast(char *)name_text, name_len, "%.*s.%.*s-%d", LIT(proc->name), LIT(ts_name), guid); + } else { + name_len = gb_snprintf(cast(char *)name_text, name_len, "%.*s.%.*s", LIT(proc->name), LIT(ts_name)); + } String name = make_string(name_text, name_len-1); irValue *value = ir_value_type_name(m->allocator, name, e->type); @@ -6242,10 +6251,10 @@ void ir_build_constant_value_decl(irProcedure *proc, AstNodeValueDecl *vd) { continue; } DeclInfo *d = decl_info_of_entity(e); - ir_build_poly_proc(proc, &d->proc_lit->ProcLit, e); + ir_build_nested_proc(proc, &d->proc_lit->ProcLit, e); } } else { - ir_build_poly_proc(proc, pl, e); + ir_build_nested_proc(proc, pl, e); } } else {