diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-08-18 15:53:45 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-07 09:55:02 -0700 |
commit | 793863a5d0e2f864f46dac86baa8e12c63b5b004 (patch) | |
tree | 4415cc69c33f8ca5e1fcac451dcfd77c38803f81 /src/wasm-s-parser.h | |
parent | 2e2e0241a10c0eccb89365c1b50217d6d0d3a386 (diff) | |
download | binaryen-793863a5d0e2f864f46dac86baa8e12c63b5b004.tar.gz binaryen-793863a5d0e2f864f46dac86baa8e12c63b5b004.tar.bz2 binaryen-793863a5d0e2f864f46dac86baa8e12c63b5b004.zip |
import kinds
Diffstat (limited to 'src/wasm-s-parser.h')
-rw-r--r-- | src/wasm-s-parser.h | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index b6270217b..17185a925 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -1440,33 +1440,49 @@ private: im->name = Name::fromInt(importCounter); } importCounter++; + if (!s[i]->quoted()) { + if (s[i]->str() == MEMORY) { + im->kind = Import::Memory; + } else if (s[2]->str() == TABLE) { + im->kind = Import::Table; + } else if (s[2]->str() == GLOBAL) { + im->kind = Import::Table; + } else { + WASM_UNREACHABLE(); + } + i++; + } else { + im->kind = Import::Function; + } im->module = s[i++]->str(); if (!s[i]->isStr()) throw ParseException("no name for import"); im->base = s[i++]->str(); - std::unique_ptr<FunctionType> type = make_unique<FunctionType>(); - if (s.size() > i) { - Element& params = *s[i]; - IString id = params[0]->str(); - if (id == PARAM) { - for (size_t i = 1; i < params.size(); i++) { - type->params.push_back(stringToWasmType(params[i]->str())); + if (im->kind == Import::Function) { + std::unique_ptr<FunctionType> type = make_unique<FunctionType>(); + if (s.size() > i) { + Element& params = *s[i]; + IString id = params[0]->str(); + if (id == PARAM) { + for (size_t i = 1; i < params.size(); i++) { + type->params.push_back(stringToWasmType(params[i]->str())); + } + } else if (id == RESULT) { + type->result = stringToWasmType(params[1]->str()); + } else if (id == TYPE) { + IString name = params[1]->str(); + if (!wasm.checkFunctionType(name)) throw ParseException("bad function type for import"); + *type = *wasm.getFunctionType(name); + } else { + throw ParseException("bad import element"); + } + if (s.size() > i+1) { + Element& result = *s[i+1]; + assert(result[0]->str() == RESULT); + type->result = stringToWasmType(result[1]->str()); } - } else if (id == RESULT) { - type->result = stringToWasmType(params[1]->str()); - } else if (id == TYPE) { - IString name = params[1]->str(); - if (!wasm.checkFunctionType(name)) throw ParseException("bad function type for import"); - *type = *wasm.getFunctionType(name); - } else { - throw ParseException("bad import element"); - } - if (s.size() > i+1) { - Element& result = *s[i+1]; - assert(result[0]->str() == RESULT); - type->result = stringToWasmType(result[1]->str()); } + im->type = ensureFunctionType(getSig(type.get()), &wasm); } - im->type = ensureFunctionType(getSig(type.get()), &wasm); wasm.addImport(im.release()); } |