summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/asm2wasm.h1
-rw-r--r--src/asmjs/shared-constants.cpp35
-rw-r--r--src/asmjs/shared-constants.h35
-rw-r--r--src/parsing.h5
-rw-r--r--src/shared-constants.h56
-rw-r--r--src/shell-interface.h1
-rw-r--r--src/wasm-binary.h22
-rw-r--r--src/wasm-linker.cpp7
-rw-r--r--src/wasm-s-parser.h3
-rw-r--r--src/wasm.cpp55
11 files changed, 132 insertions, 90 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a384660da..9fc9cd95e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -150,7 +150,7 @@ SET(wasm_dis_SOURCES
)
ADD_EXECUTABLE(wasm-dis
${wasm_dis_SOURCES})
-TARGET_LINK_LIBRARIES(wasm-dis passes support)
+TARGET_LINK_LIBRARIES(wasm-dis passes support asmjs)
SET_PROPERTY(TARGET wasm-dis PROPERTY CXX_STANDARD 11)
SET_PROPERTY(TARGET wasm-dis PROPERTY CXX_STANDARD_REQUIRED ON)
INSTALL(TARGETS wasm-dis DESTINATION bin)
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index c4cc766aa..2233a10ae 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -25,6 +25,7 @@
#include "wasm.h"
#include "emscripten-optimizer/optimizer.h"
#include "mixed_arena.h"
+#include "shared-constants.h"
#include "asmjs/shared-constants.h"
#include "asm_v_wasm.h"
#include "passes/passes.h"
diff --git a/src/asmjs/shared-constants.cpp b/src/asmjs/shared-constants.cpp
index bc1c0fa3d..b2321a209 100644
--- a/src/asmjs/shared-constants.cpp
+++ b/src/asmjs/shared-constants.cpp
@@ -47,35 +47,9 @@ cashew::IString GLOBAL("global"),
SQRT("sqrt"),
I32_TEMP("asm2wasm_i32_temp"),
DEBUGGER("debugger"),
- GROW_WASM_MEMORY("__growWasmMemory"),
- NEW_SIZE("newSize"),
- MODULE("module"),
- START("start"),
- FUNC("func"),
- PARAM("param"),
- RESULT("result"),
- MEMORY("memory"),
- SEGMENT("segment"),
- EXPORT("export"),
- IMPORT("import"),
- TABLE("table"),
- LOCAL("local"),
- TYPE("type"),
- CALL("call"),
- CALL_IMPORT("call_import"),
- CALL_INDIRECT("call_indirect"),
- BLOCK("block"),
- BR_IF("br_if"),
- THEN("then"),
- ELSE("else"),
- NEG_INFINITY("-infinity"),
- NEG_NAN("-nan"),
- CASE("case"),
- BR("br"),
USE_ASM("use asm"),
BUFFER("buffer"),
ENV("env"),
- FAKE_RETURN("fake_return_waka123"),
MATH_IMUL("Math_imul"),
MATH_CLZ32("Math_clz32"),
MATH_CTZ32("Math_ctz32"),
@@ -87,13 +61,6 @@ cashew::IString GLOBAL("global"),
MATH_NEAREST("Math_NEAREST"),
MATH_SQRT("Math_sqrt"),
MATH_MIN("Math_max"),
- MATH_MAX("Math_min"),
- ASSERT_RETURN("assert_return"),
- ASSERT_TRAP("assert_trap"),
- ASSERT_INVALID("assert_invalid"),
- SPECTEST("spectest"),
- PRINT("print"),
- INVOKE("invoke"),
- EXIT("exit");
+ MATH_MAX("Math_min");
}
diff --git a/src/asmjs/shared-constants.h b/src/asmjs/shared-constants.h
index 2f6c608ba..fb32340ab 100644
--- a/src/asmjs/shared-constants.h
+++ b/src/asmjs/shared-constants.h
@@ -50,35 +50,9 @@ extern cashew::IString GLOBAL,
SQRT,
I32_TEMP,
DEBUGGER,
- GROW_WASM_MEMORY,
- NEW_SIZE,
- MODULE,
- START,
- FUNC,
- PARAM,
- RESULT,
- MEMORY,
- SEGMENT,
- EXPORT,
- IMPORT,
- TABLE,
- LOCAL,
- TYPE,
- CALL,
- CALL_IMPORT,
- CALL_INDIRECT,
- BLOCK,
- BR_IF,
- THEN,
- ELSE,
- NEG_INFINITY,
- NEG_NAN,
- CASE,
- BR,
USE_ASM,
BUFFER,
ENV,
- FAKE_RETURN,
MATH_IMUL,
MATH_CLZ32,
MATH_CTZ32,
@@ -90,14 +64,7 @@ extern cashew::IString GLOBAL,
MATH_NEAREST,
MATH_SQRT,
MATH_MIN,
- MATH_MAX,
- ASSERT_RETURN,
- ASSERT_TRAP,
- ASSERT_INVALID,
- SPECTEST,
- PRINT,
- INVOKE,
- EXIT;
+ MATH_MAX;
}
diff --git a/src/parsing.h b/src/parsing.h
index 6745ad7cd..f5df77bad 100644
--- a/src/parsing.h
+++ b/src/parsing.h
@@ -21,6 +21,7 @@
#include <sstream>
#include <string>
+#include "shared-constants.h"
#include "asmjs/shared-constants.h"
#include "mixed_arena.h"
#include "support/utilities.h"
@@ -34,7 +35,7 @@ inline Expression* parseConst(cashew::IString s, WasmType type, MixedArena& allo
auto ret = allocator.alloc<Const>();
ret->type = type;
if (isWasmTypeFloat(type)) {
- if (s == INFINITY_) {
+ if (s == _INFINITY) {
switch (type) {
case f32: ret->value = Literal(std::numeric_limits<float>::infinity()); break;
case f64: ret->value = Literal(std::numeric_limits<double>::infinity()); break;
@@ -52,7 +53,7 @@ inline Expression* parseConst(cashew::IString s, WasmType type, MixedArena& allo
//std::cerr << "make constant " << str << " ==> " << ret->value << '\n';
return ret;
}
- if (s == NAN_) {
+ if (s == _NAN) {
switch (type) {
case f32: ret->value = Literal(float(std::nan(""))); break;
case f64: ret->value = Literal(double(std::nan(""))); break;
diff --git a/src/shared-constants.h b/src/shared-constants.h
new file mode 100644
index 000000000..fb94ff11b
--- /dev/null
+++ b/src/shared-constants.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2016 WebAssembly Community Group participants
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace wasm {
+
+extern Name GROW_WASM_MEMORY,
+ NEW_SIZE,
+ MODULE,
+ START,
+ FUNC,
+ PARAM,
+ RESULT,
+ MEMORY,
+ SEGMENT,
+ EXPORT,
+ IMPORT,
+ TABLE,
+ LOCAL,
+ TYPE,
+ CALL,
+ CALL_IMPORT,
+ CALL_INDIRECT,
+ BLOCK,
+ BR_IF,
+ THEN,
+ ELSE,
+ _NAN,
+ _INFINITY,
+ NEG_INFINITY,
+ NEG_NAN,
+ CASE,
+ BR,
+ FAKE_RETURN,
+ ASSERT_RETURN,
+ ASSERT_TRAP,
+ ASSERT_INVALID,
+ SPECTEST,
+ PRINT,
+ INVOKE,
+ EXIT;
+
+} // namespace wasm
+
diff --git a/src/shell-interface.h b/src/shell-interface.h
index 62fc2432a..f6c12e8ca 100644
--- a/src/shell-interface.h
+++ b/src/shell-interface.h
@@ -21,6 +21,7 @@
#ifndef wasm_shell_interface_h
#define wasm_shell_interface_h
+#include "shared-constants.h"
#include "asmjs/shared-constants.h"
#include "wasm.h"
#include "wasm-interpreter.h"
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index 5cb56f770..a76bf7fa5 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -238,16 +238,16 @@ enum Meta {
};
namespace Section {
- auto Memory = "memory";
- auto Signatures = "type";
- auto ImportTable = "import";
- auto FunctionSignatures = "function";
- auto Functions = "code";
- auto ExportTable = "export";
- auto DataSegments = "data";
- auto FunctionTable = "table";
- auto Names = "name";
- auto Start = "start";
+ extern const char* Memory;
+ extern const char* Signatures;
+ extern const char* ImportTable;
+ extern const char* FunctionSignatures;
+ extern const char* Functions;
+ extern const char* ExportTable;
+ extern const char* DataSegments;
+ extern const char* FunctionTable;
+ extern const char* Names;
+ extern const char* Start;
};
enum FunctionEntry {
@@ -445,7 +445,7 @@ enum TypeForms {
} // namespace BinaryConsts
-int8_t binaryWasmType(WasmType type) {
+inline int8_t binaryWasmType(WasmType type) {
switch (type) {
case none: return 0;
case i32: return 1;
diff --git a/src/wasm-linker.cpp b/src/wasm-linker.cpp
index e89c324b4..eb7f9e00d 100644
--- a/src/wasm-linker.cpp
+++ b/src/wasm-linker.cpp
@@ -25,13 +25,6 @@
using namespace wasm;
cashew::IString EMSCRIPTEN_ASM_CONST("emscripten_asm_const");
-namespace wasm {
-// These are defined (not just declared) in shared-constants.h, so we can't just
-// include that header. TODO: Move the definitions into a cpp file.
-extern cashew::IString ENV;
-extern cashew::IString MEMORY;
-}
-
void Linker::placeStackPointer(Address stackAllocation) {
// ensure this is the first allocation
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index 0893a5bba..b31b727b7 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -28,6 +28,7 @@
#include "wasm.h"
#include "wasm-binary.h"
+#include "shared-constants.h"
#include "asmjs/shared-constants.h"
#include "mixed_arena.h"
#include "parsing.h"
@@ -41,7 +42,7 @@ using namespace cashew;
// Globals
-int unhex(char c) {
+inline int unhex(char c) {
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
diff --git a/src/wasm.cpp b/src/wasm.cpp
index dd06a8d14..6732f9ca4 100644
--- a/src/wasm.cpp
+++ b/src/wasm.cpp
@@ -20,9 +20,64 @@
namespace wasm {
+// shared constants
+
Name WASM("wasm"),
RETURN_FLOW("*return:)*");
+namespace BinaryConsts {
+namespace Section {
+ const char* Memory = "memory";
+ const char* Signatures = "type";
+ const char* ImportTable = "import";
+ const char* FunctionSignatures = "function";
+ const char* Functions = "code";
+ const char* ExportTable = "export";
+ const char* DataSegments = "data";
+ const char* FunctionTable = "table";
+ const char* Names = "name";
+ const char* Start = "start";
+};
+};
+
+Name GROW_WASM_MEMORY("__growWasmMemory"),
+ NEW_SIZE("newSize"),
+ MODULE("module"),
+ START("start"),
+ FUNC("func"),
+ PARAM("param"),
+ RESULT("result"),
+ MEMORY("memory"),
+ SEGMENT("segment"),
+ EXPORT("export"),
+ IMPORT("import"),
+ TABLE("table"),
+ LOCAL("local"),
+ TYPE("type"),
+ CALL("call"),
+ CALL_IMPORT("call_import"),
+ CALL_INDIRECT("call_indirect"),
+ BLOCK("block"),
+ BR_IF("br_if"),
+ THEN("then"),
+ ELSE("else"),
+ _NAN("NaN"),
+ _INFINITY("Infinity"),
+ NEG_INFINITY("-infinity"),
+ NEG_NAN("-nan"),
+ CASE("case"),
+ BR("br"),
+ FAKE_RETURN("fake_return_waka123"),
+ ASSERT_RETURN("assert_return"),
+ ASSERT_TRAP("assert_trap"),
+ ASSERT_INVALID("assert_invalid"),
+ SPECTEST("spectest"),
+ PRINT("print"),
+ INVOKE("invoke"),
+ EXIT("exit");
+
+// core AST type checking
+
struct TypeSeeker : public PostWalker<TypeSeeker, Visitor<TypeSeeker>> {
Expression* target; // look for this one
Name targetName;