Browse Source

Change our IR name mangling rules

gingerBill 7 years ago
parent
commit
3f4b6b22dc
3 changed files with 18 additions and 13 deletions
  1. 1 1
      build.bat
  2. 1 5
      examples/demo/demo.odin
  3. 16 7
      src/ir.cpp

+ 1 - 1
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
 

+ 1 - 5
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));
 }
-

+ 16 - 7
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 {