authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-15 18:05:46-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-04-15 18:05:46-04:00
log3b8a85c94182f5600d5bec27b4061803869b4fe8
tree73cb0f562a778c58ff3e3fff7b6544b6ad4dd414
parent5cb18e9c6f5ee49541579ba3e45d9de4fcec8bcb
parenta0d2185199e7723aabc38cacd83d6a140f12e01d
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #2281 from shritesh/wasm_module

Support wasm module imports

2 files changed, 9 insertions(+), 8 deletions(-)

src/codegen.cpp+8
...@@ -495,6 +495,14 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) {...@@ -495,6 +495,14 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) {
495 auto entry = g->exported_symbol_names.maybe_get(symbol_name);495 auto entry = g->exported_symbol_names.maybe_get(symbol_name);
496 if (entry == nullptr) {496 if (entry == nullptr) {
497 fn_table_entry->llvm_value = LLVMAddFunction(g->module, buf_ptr(symbol_name), fn_llvm_type);497 fn_table_entry->llvm_value = LLVMAddFunction(g->module, buf_ptr(symbol_name), fn_llvm_type);
498
499 if (target_is_wasm(g->zig_target)) {
500 assert(fn_table_entry->proto_node->type == NodeTypeFnProto);
501 AstNodeFnProto *fn_proto = &fn_table_entry->proto_node->data.fn_proto;
502 if (fn_proto-> is_extern && fn_proto->lib_name != nullptr ) {
503 addLLVMFnAttrStr(fn_table_entry->llvm_value, "wasm-import-module", buf_ptr(fn_proto->lib_name));
504 }
505 }
498 } else {506 } else {
499 assert(entry->value->id == TldIdFn);507 assert(entry->value->id == TldIdFn);
500 TldFn *tld_fn = reinterpret_cast<TldFn *>(entry->value);508 TldFn *tld_fn = reinterpret_cast<TldFn *>(entry->value);
src/ir.cpp+1-8
...@@ -15828,13 +15828,6 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,...@@ -15828,13 +15828,6 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,
15828 ira->codegen->reported_bad_link_libc_error = true;15828 ira->codegen->reported_bad_link_libc_error = true;
15829 }15829 }
1583015830
15831 bool is_wasi = buf_eql_str(lib_name, "wasi");
15832 if (is_wasi && ira->codegen->zig_target->os != OsWASI) {
15833 ir_add_error_node(ira, source_node,
15834 buf_sprintf("linking against wasi library"));
15835 ira->codegen->reported_bad_link_libc_error = true;
15836 }
15837
15838 LinkLib *link_lib = add_link_lib(ira->codegen, lib_name);15831 LinkLib *link_lib = add_link_lib(ira->codegen, lib_name);
15839 for (size_t i = 0; i < link_lib->symbols.length; i += 1) {15832 for (size_t i = 0; i < link_lib->symbols.length; i += 1) {
15840 Buf *existing_symbol_name = link_lib->symbols.at(i);15833 Buf *existing_symbol_name = link_lib->symbols.at(i);
...@@ -15843,7 +15836,7 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,...@@ -15843,7 +15836,7 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,
15843 }15836 }
15844 }15837 }
1584515838
15846 if (!is_libc && !is_wasi && !ira->codegen->have_pic && !ira->codegen->reported_bad_link_libc_error) {15839 if (!is_libc && !target_is_wasm(ira->codegen->zig_target) && !ira->codegen->have_pic && !ira->codegen->reported_bad_link_libc_error) {
15847 ErrorMsg *msg = ir_add_error_node(ira, source_node,15840 ErrorMsg *msg = ir_add_error_node(ira, source_node,
15848 buf_sprintf("dependency on dynamic library '%s' requires enabling Position Independent Code",15841 buf_sprintf("dependency on dynamic library '%s' requires enabling Position Independent Code",
15849 buf_ptr(lib_name)));15842 buf_ptr(lib_name)));