Browse Source

Correct SysV ABI for `-> (f32, bool)`

gingerBill 4 years ago
parent
commit
ff6fdc7812
2 changed files with 26 additions and 6 deletions
  1. 5 0
      src/llvm_abi.cpp
  2. 21 6
      src/llvm_backend.cpp

+ 5 - 0
src/llvm_abi.cpp

@@ -549,6 +549,11 @@ namespace lbAbiAmd64SysV {
 		} else if (oldv == RegClass_Memory || newv == RegClass_Memory) {
 			return;
 		} else if (oldv == RegClass_Int || newv	== RegClass_Int) {
+			if (oldv == RegClass_SSEFv || oldv == RegClass_SSEFs) {
+				oldv = RegClass_Int;
+			} else if (newv == RegClass_SSEFv || newv == RegClass_SSEFs) {
+				oldv = RegClass_Int;
+			}
 			return;
 		} else if (oldv == RegClass_X87 || oldv == RegClass_X87Up || oldv == RegClass_ComplexX87 ||
 		           newv == RegClass_X87 || newv == RegClass_X87Up || newv == RegClass_ComplexX87) {

+ 21 - 6
src/llvm_backend.cpp

@@ -5794,9 +5794,15 @@ lbValue lb_find_value_from_entity(lbModule *m, Entity *e) {
 
 	if (USE_SEPARTE_MODULES) {
 		lbModule *other_module = lb_pkg_module(m->gen, e->pkg);
+
+		// TODO(bill): correct this logic
 		bool is_external = other_module != m;
 		if (!is_external) {
-			other_module = e->code_gen_module;
+			if (e->code_gen_module != nullptr) {
+				other_module = e->code_gen_module;
+			} else {
+				other_module = nullptr;
+			}
 			is_external = other_module != m;
 		}
 
@@ -5806,8 +5812,20 @@ lbValue lb_find_value_from_entity(lbModule *m, Entity *e) {
 			lbValue g = {};
 			g.value = LLVMAddGlobal(m->mod, lb_type(m, e->type), alloc_cstring(permanent_allocator(), name));
 			g.type = alloc_type_pointer(e->type);
+			lb_add_entity(m, e, g);
+			lb_add_member(m, name, g);
+
 			LLVMSetLinkage(g.value, LLVMExternalLinkage);
 
+			// if (other_module != nullptr) {
+			// 	lbValue *other_found = string_map_get(&other_module->members, name);
+			// 	if (other_found) {
+			// 		lbValue other_g = *other_found;
+			// 	}
+			// }
+
+			// LLVMSetLinkage(other_g.value, LLVMExternalLinkage);
+
 			if (e->Variable.thread_local_model != "") {
 				LLVMSetThreadLocal(g.value, true);
 
@@ -5827,8 +5845,7 @@ lbValue lb_find_value_from_entity(lbModule *m, Entity *e) {
 				LLVMSetThreadLocalMode(g.value, mode);
 			}
 
-			lb_add_entity(m, e, g);
-			lb_add_member(m, name, g);
+
 			return g;
 		}
 	}
@@ -14713,9 +14730,7 @@ void lb_generate_code(lbGenerator *gen) {
 		if (is_export) {
 			LLVMSetLinkage(g.value, LLVMDLLExportLinkage);
 			LLVMSetDLLStorageClass(g.value, LLVMDLLExportStorageClass);
-		}
-
-		if (e->flags & EntityFlag_Static) {
+		} else {
 			// LLVMSetLinkage(g.value, LLVMInternalLinkage);
 		}