Browse Source

Fix WASM foreign import names

gingerBill 5 years ago
parent
commit
15c4077806
2 changed files with 13 additions and 11 deletions
  1. 5 4
      src/llvm_backend.cpp
  2. 8 7
      src/parser.cpp

+ 5 - 4
src/llvm_backend.cpp

@@ -2045,10 +2045,7 @@ lbProcedure *lb_create_procedure(lbModule *m, Entity *entity) {
 
 
 		if (build_context.metrics.os == TargetOs_js) {
 		if (build_context.metrics.os == TargetOs_js) {
 			char const *export_name = alloc_cstring(heap_allocator(), p->name);
 			char const *export_name = alloc_cstring(heap_allocator(), p->name);
-			LLVMAddTargetDependentFunctionAttr(p->value, "export", export_name);
-			LLVMAddTargetDependentFunctionAttr(p->value, "export-name", export_name);
 			LLVMAddTargetDependentFunctionAttr(p->value, "wasm-export-name", export_name);
 			LLVMAddTargetDependentFunctionAttr(p->value, "wasm-export-name", export_name);
-			LLVMAddTargetDependentFunctionAttr(p->value, "wasm-exported", nullptr);
 		}
 		}
 	}
 	}
 	if (p->is_foreign) {
 	if (p->is_foreign) {
@@ -2056,7 +2053,11 @@ lbProcedure *lb_create_procedure(lbModule *m, Entity *entity) {
 			char const *import_name = alloc_cstring(heap_allocator(), p->name);
 			char const *import_name = alloc_cstring(heap_allocator(), p->name);
 			char const *module_name = "env";
 			char const *module_name = "env";
 			if (entity->Procedure.foreign_library != nullptr) {
 			if (entity->Procedure.foreign_library != nullptr) {
-				module_name = alloc_cstring(heap_allocator(), entity->Procedure.foreign_library->token.string);
+				Entity *foreign_library = entity->Procedure.foreign_library;
+				GB_ASSERT(foreign_library->kind == Entity_LibraryName);
+				if (foreign_library->LibraryName.paths.count > 0)  {
+					module_name = alloc_cstring(heap_allocator(), foreign_library->LibraryName.paths[0]);
+				}
 			}
 			}
 			LLVMAddTargetDependentFunctionAttr(p->value, "wasm-import-name",   import_name);
 			LLVMAddTargetDependentFunctionAttr(p->value, "wasm-import-name",   import_name);
 			LLVMAddTargetDependentFunctionAttr(p->value, "wasm-import-module", module_name);
 			LLVMAddTargetDependentFunctionAttr(p->value, "wasm-import-module", module_name);

+ 8 - 7
src/parser.cpp

@@ -4736,14 +4736,15 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Array<Ast *>
 			for_array(fp_idx, fl->filepaths) {
 			for_array(fp_idx, fl->filepaths) {
 				String file_str = fl->filepaths[fp_idx].string;
 				String file_str = fl->filepaths[fp_idx].string;
 				String fullpath = file_str;
 				String fullpath = file_str;
-
-				String foreign_path = {};
-				bool ok = determine_path_from_string(&p->file_decl_mutex, node, base_dir, file_str, &foreign_path);
-				if (!ok) {
-					decls[i] = ast_bad_decl(f, fl->filepaths[fp_idx], fl->filepaths[fl->filepaths.count-1]);
-					goto end;
+				if (build_context.metrics.os != TargetOs_js) {
+					String foreign_path = {};
+					bool ok = determine_path_from_string(&p->file_decl_mutex, node, base_dir, file_str, &foreign_path);
+					if (!ok) {
+						decls[i] = ast_bad_decl(f, fl->filepaths[fp_idx], fl->filepaths[fl->filepaths.count-1]);
+						goto end;
+					}
+					fullpath = foreign_path;
 				}
 				}
-				fullpath = foreign_path;
 				array_add(&fl->fullpaths, fullpath);
 				array_add(&fl->fullpaths, fullpath);
 			}
 			}
 			if (fl->fullpaths.count == 0) {
 			if (fl->fullpaths.count == 0) {