diff options
Diffstat (limited to 'src/s2wasm.h')
-rw-r--r-- | src/s2wasm.h | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h index 2228ae900..d24f5ef46 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -88,6 +88,11 @@ class S2WasmBuilder { } } + void skipToEOL() { + s = strchr(s, '\n'); + assert(s); + } + bool skipComma() { skipWhitespace(); if (*s != ',') return false; @@ -397,10 +402,11 @@ class S2WasmBuilder { else if (match("weak") || match("hidden") || match("protected") || match("internal")) getStr(); // contents are in the content that follows else if (match("imports")) skipImports(); else if (match("data")) {} - else if (match("ident")) {} + else if (match("ident")) skipToEOL(); else if (match("section")) parseToplevelSection(); - else if (match("align") || match("p2align")) s = strchr(s, '\n'); + else if (match("align") || match("p2align")) skipToEOL(); else if (match("globl")) parseGlobl(); + else if (match("functype")) parseFuncType(); else abort_on("process"); } } @@ -423,11 +429,11 @@ class S2WasmBuilder { void parseInitializer() { // Ignore the rest of the .section line - s = strchr(s, '\n'); + skipToEOL(); skipWhitespace(); // The section may start with .p2align if (match(".p2align")) { - s = strchr(s, '\n'); + skipToEOL(); skipWhitespace(); } mustMatch(".int32"); @@ -480,6 +486,22 @@ class S2WasmBuilder { skipWhitespace(); } + void parseFuncType() { + auto decl = make_unique<FunctionType>(); + Name name = getCommaSeparated(); + skipComma(); + if(match("void")) { + decl->result = none; + } else { + decl->result = getType(); + } + while (*s && skipComma()) decl->params.push_back(getType()); + + FunctionType *ty = wasm->checkFunctionType(getSig(decl.get())); + if (!ty) ty = decl.release(); + linkerObj->addExternType(name, ty); + } + bool parseVersionMin() { if (match("watchos_version_min") || match("tvos_version_min") || match("ios_version_min") || match("macosx_version_min")) { s = strchr(s, '\n'); |