diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-08-18 17:56:01 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-07 09:55:02 -0700 |
commit | a10ca64dc04bdba4fbf4a468604c0c88f62a4a8d (patch) | |
tree | 2c9477cc46b0d335e36287303019bbf20e6b014b /src | |
parent | 793863a5d0e2f864f46dac86baa8e12c63b5b004 (diff) | |
download | binaryen-a10ca64dc04bdba4fbf4a468604c0c88f62a4a8d.tar.gz binaryen-a10ca64dc04bdba4fbf4a468604c0c88f62a4a8d.tar.bz2 binaryen-a10ca64dc04bdba4fbf4a468604c0c88f62a4a8d.zip |
import type for globals
Diffstat (limited to 'src')
-rw-r--r-- | src/asm2wasm.h | 12 | ||||
-rw-r--r-- | src/binaryen-c.cpp | 2 | ||||
-rw-r--r-- | src/passes/Print.cpp | 8 | ||||
-rw-r--r-- | src/passes/RemoveImports.cpp | 2 | ||||
-rw-r--r-- | src/wasm-binary.h | 12 | ||||
-rw-r--r-- | src/wasm-linker.cpp | 4 | ||||
-rw-r--r-- | src/wasm-s-parser.h | 6 | ||||
-rw-r--r-- | src/wasm-validator.h | 10 | ||||
-rw-r--r-- | src/wasm.h | 5 |
9 files changed, 36 insertions, 25 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 10ad769ac..48c52080d 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -738,10 +738,10 @@ void Asm2WasmBuilder::processAsm(Ref ast) { // special math builtins FunctionType* builtin = getBuiltinFunctionType(import->module, import->base); if (builtin) { - import->type = builtin; + import->functionType = builtin; continue; } - import->type = ensureFunctionType(getSig(importedFunctionTypes[name].get()), &wasm); + import->functionType = ensureFunctionType(getSig(importedFunctionTypes[name].get()), &wasm); } else if (import->module != ASM2WASM) { // special-case the special module // never actually used toErase.push_back(name); @@ -1087,7 +1087,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { import->name = F64_REM; import->module = ASM2WASM; import->base = F64_REM; - import->type = ensureFunctionType("ddd", &wasm); + import->functionType = ensureFunctionType("ddd", &wasm); import->kind = Import::Function; wasm.addImport(import); } @@ -1113,7 +1113,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { import->name = call->target; import->module = ASM2WASM; import->base = call->target; - import->type = ensureFunctionType("iii", &wasm); + import->functionType = ensureFunctionType("iii", &wasm); import->kind = Import::Function; wasm.addImport(import); } @@ -1152,7 +1152,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { import->name = DEBUGGER; import->module = ASM2WASM; import->base = DEBUGGER; - import->type = ensureFunctionType("v", &wasm); + import->functionType = ensureFunctionType("v", &wasm); import->kind = Import::Function; wasm.addImport(import); } @@ -1265,7 +1265,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { import->name = F64_TO_INT; import->module = ASM2WASM; import->base = F64_TO_INT; - import->type = ensureFunctionType("id", &wasm); + import->functionType = ensureFunctionType("id", &wasm); import->kind = Import::Function; wasm.addImport(import); } diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index ac64b188d..3ce24bdbd 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -717,7 +717,7 @@ BinaryenImportRef BinaryenAddImport(BinaryenModuleRef module, const char* intern ret->name = internalName; ret->module = externalModuleName; ret->base = externalBaseName; - ret->type = (FunctionType*)type; + ret->functionType = (FunctionType*)type; ret->kind = Import::Function; wasm->addImport(ret); return ret; diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index e9e70c1b0..3e5339932 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -544,7 +544,13 @@ struct PrintSExpression : public Visitor<PrintSExpression> { printName(curr->name) << ' '; printText(o, curr->module.str) << ' '; printText(o, curr->base.str); - if (curr->type) visitFunctionType(curr->type); + switch (curr->kind) { + case Export::Function: if (curr->functionType) visitFunctionType(curr->functionType); break; + case Export::Table: break; + case Export::Memory: break; + case Export::Global: o << printWasmType(curr->globalType); break; + default: WASM_UNREACHABLE(); + } o << ')'; } void visitExport(Export *curr) { diff --git a/src/passes/RemoveImports.cpp b/src/passes/RemoveImports.cpp index 0b3f50049..19d6c3eb1 100644 --- a/src/passes/RemoveImports.cpp +++ b/src/passes/RemoveImports.cpp @@ -37,7 +37,7 @@ struct RemoveImports : public WalkerPass<PostWalker<RemoveImports, Visitor<Remov } void visitCallImport(CallImport *curr) { - WasmType type = module->getImport(curr->target)->type->result; + WasmType type = module->getImport(curr->target)->functionType->result; if (type == none) { replaceCurrent(allocator->alloc<Nop>()); } else { diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 0949e324b..4db728fd6 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -574,10 +574,10 @@ public: if (debug) std::cerr << "write one" << std::endl; o << U32LEB(import->kind); switch (import->kind) { - case Export::Function: o << U32LEB(getFunctionTypeIndex(import->type->name)); + case Export::Function: o << U32LEB(getFunctionTypeIndex(import->functionType->name)); case Export::Table: break; case Export::Memory: break; - case Export::Global: break; + case Export::Global: o << binaryWasmType(import->globalType);break; default: WASM_UNREACHABLE(); } writeInlineString(import->module.str); @@ -1504,13 +1504,13 @@ public: case Export::Function: { auto index = getU32LEB(); assert(index < wasm.functionTypes.size()); - curr->type = wasm.getFunctionType(index); - assert(curr->type->name.is()); + curr->functionType = wasm.getFunctionType(index); + assert(curr->functionType->name.is()); break; } case Export::Table: break; case Export::Memory: break; - case Export::Global: break; + case Export::Global: curr->globalType = getWasmType(); break; default: WASM_UNREACHABLE(); } curr->module = getInlineString(); @@ -1932,7 +1932,7 @@ public: WASM_UNUSED(arity); auto import = wasm.getImport(getU32LEB()); curr->target = import->name; - auto type = import->type; + auto type = import->functionType; assert(type); auto num = type->params.size(); assert(num == arity); diff --git a/src/wasm-linker.cpp b/src/wasm-linker.cpp index 1631e17a9..04deddf4a 100644 --- a/src/wasm-linker.cpp +++ b/src/wasm-linker.cpp @@ -49,7 +49,7 @@ void Linker::ensureImport(Name target, std::string signature) { auto import = new Import; import->name = import->base = target; import->module = ENV; - import->type = ensureFunctionType(signature, &out.wasm); + import->functionType = ensureFunctionType(signature, &out.wasm); import->kind = Import::Function; out.wasm.addImport(import); } @@ -339,7 +339,7 @@ void Linker::emscriptenGlue(std::ostream& o) { auto import = new Import; import->name = import->base = curr->target; import->module = ENV; - import->type = ensureFunctionType(getSig(curr), &parent->out.wasm); + import->functionType = ensureFunctionType(getSig(curr), &parent->out.wasm); import->kind = Import::Function; parent->out.wasm.addImport(import); } diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 17185a925..50d566baf 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -1216,7 +1216,7 @@ private: auto ret = allocator.alloc<CallImport>(); ret->target = s[1]->str(); Import* import = wasm.getImport(ret->target); - ret->type = import->type->result; + ret->type = import->functionType->result; parseCallOperands(s, 2, s.size(), ret); return ret; } @@ -1481,7 +1481,9 @@ private: type->result = stringToWasmType(result[1]->str()); } } - im->type = ensureFunctionType(getSig(type.get()), &wasm); + im->functionType = ensureFunctionType(getSig(type.get()), &wasm); + } else if (im->kind == Import::Global) { + im->globalType = stringToWasmType(s[i]->str()); } wasm.addImport(im.release()); } diff --git a/src/wasm-validator.h b/src/wasm-validator.h index 77bf6d3e9..92ae24688 100644 --- a/src/wasm-validator.h +++ b/src/wasm-validator.h @@ -167,7 +167,7 @@ public: void visitCallImport(CallImport *curr) { auto* import = getModule()->checkImport(curr->target); if (!shouldBeTrue(!!import, curr, "call_import target must exist")) return; - auto* type = import->type; + auto* type = import->functionType; if (!shouldBeTrue(curr->operands.size() == type->params.size(), curr, "call param number must match")) return; for (size_t i = 0; i < curr->operands.size(); i++) { if (!shouldBeEqualOrFirstIsUnreachable(curr->operands[i]->type, type->params[i], curr, "call param types must match")) { @@ -314,9 +314,11 @@ public: void visitImport(Import* curr) { if (!validateWebConstraints) return; - shouldBeUnequal(curr->type->result, i64, curr->name, "Imported function must not have i64 return type"); - for (WasmType param : curr->type->params) { - shouldBeUnequal(param, i64, curr->name, "Imported function must not have i64 parameters"); + if (curr->kind == Import::Function) { + shouldBeUnequal(curr->functionType->result, i64, curr->name, "Imported function must not have i64 return type"); + for (WasmType param : curr->functionType->params) { + shouldBeUnequal(param, i64, curr->name, "Imported function must not have i64 parameters"); + } } } diff --git a/src/wasm.h b/src/wasm.h index f26cf05a9..a2f6a74db 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -1437,11 +1437,12 @@ public: Global = 3, }; - Import() : type(nullptr) {} + Import() : functionType(nullptr), globalType(none) {} Name name, module, base; // name = module.base Kind kind; - FunctionType* type; // for Function imports + FunctionType* functionType; // for Function imports + WasmType globalType; // for Global imports }; class Export { |