summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt10
-rw-r--r--appveyor.yml10
-rw-r--r--src/binary-reader-objdump.cc16
-rw-r--r--src/config.h.in31
-rw-r--r--src/interpreter.cc4
-rw-r--r--src/tools/wasm-interp.cc15
-rw-r--r--test/interp/binary.txt28
-rw-r--r--test/interp/cast.txt4
-rw-r--r--test/interp/convert.txt20
-rw-r--r--test/interp/load.txt4
-rw-r--r--test/interp/select.txt8
-rw-r--r--test/interp/unary.txt32
-rwxr-xr-xtest/run-wasm-link.py8
-rw-r--r--test/spec/float_exprs.txt20
-rw-r--r--test/spec/imports.txt12
15 files changed, 135 insertions, 87 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0a9d2089..55847445 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -257,6 +257,8 @@ if (NOT EMSCRIPTEN)
target_link_libraries(${name} libwabt)
set_property(TARGET ${name} PROPERTY CXX_STANDARD 11)
set_property(TARGET ${name} PROPERTY CXX_STANDARD_REQUIRED ON)
+ list(APPEND WABT_EXECUTABLES ${name})
+ set(WABT_EXECUTABLES ${WABT_EXECUTABLES} PARENT_SCOPE)
endfunction()
# wast2wasm
@@ -343,16 +345,12 @@ if (NOT EMSCRIPTEN)
set(RUN_TESTS_PY ${WABT_SOURCE_DIR}/test/run-tests.py)
add_custom_target(run-tests
COMMAND ${PYTHON_EXECUTABLE} ${RUN_TESTS_PY} --bindir ${CMAKE_BINARY_DIR}
- DEPENDS wast2wasm wasm2wast wasm-interp
+ DEPENDS ${WABT_EXECUTABLES}
WORKING_DIRECTORY ${WABT_SOURCE_DIR}
)
# install
- install(
- TARGETS wast2wasm wasm2wast wasm-interp wasmopcodecnt wasmdump wast-desugar
- wasm-link
- DESTINATION bin
- )
+ install(TARGETS ${WABT_EXECUTABLES} DESTINATION bin)
else ()
# emscripten stuff
diff --git a/appveyor.yml b/appveyor.yml
index 63f1533d..f56b56af 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -3,6 +3,9 @@
init:
- set PATH=C:\Python27\Scripts;%PATH% # while python's bin is already in PATH, but pip.exe in Scripts\ dir isn't
- set PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%
+ # Python doesn't seem to be able to import files from the current script's
+ # directory on Windows.
+ - set PYTHONPATH=%APPVEYOR_BUILD_FOLDER%\test
install:
- git submodule update --init
@@ -28,8 +31,9 @@ environment:
EXE_DIR: '%CONFIG%'
build_script:
- - cmake . -DCMAKE_BUILD_TYPE=%CONFIG% -G "%GENERATOR%"
- - cmake --build . --config %CONFIG% -- %JOBS_FLAG%%JOBS%
+ - cmake . -DCMAKE_BUILD_TYPE=%CONFIG% -DCMAKE_INSTALL_PREFIX=%APPVEYOR_BUILD_FOLDER% -G "%GENERATOR%"
+ - cmake --build . --config %CONFIG% --target install -- %JOBS_FLAG%%JOBS%
test_script:
- - cmd: '%EXE_DIR%\wabt-unittests.exe'
+ - "%APPVEYOR_BUILD_FOLDER%\\bin\\wabt-unittests"
+ - python test\run-tests.py -v --bindir %APPVEYOR_BUILD_FOLDER%\bin
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc
index c6698289..3e117728 100644
--- a/src/binary-reader-objdump.cc
+++ b/src/binary-reader-objdump.cc
@@ -21,6 +21,7 @@
#include <string.h>
#include <stdio.h>
+#include <algorithm>
#include <vector>
#include "binary-reader-nop.h"
@@ -327,11 +328,18 @@ Result BinaryReaderObjdump::OnCount(uint32_t count) {
Result BinaryReaderObjdump::BeginModule(uint32_t version) {
if (options->print_header) {
- const char* basename = strrchr(options->infile, '/');
- if (basename)
- basename++;
- else
+ const char* last_slash = strrchr(options->infile, '/');
+ const char* last_backslash = strrchr(options->infile, '\\');
+ const char* basename;
+ if (last_slash && last_backslash) {
+ basename = std::max(last_slash, last_backslash) + 1;
+ } else if (last_slash) {
+ basename = last_slash + 1;
+ } else if (last_backslash) {
+ basename = last_backslash + 1;
+ } else {
basename = options->infile;
+ }
printf("%s:\tfile format wasm %#08x\n", basename, version);
header_printed = true;
}
diff --git a/src/config.h.in b/src/config.h.in
index 453e7985..052aae88 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -265,4 +265,35 @@ typedef int ssize_t;
#endif
#endif
+#if COMPILER_IS_MSVC && defined(_M_X64)
+// MSVC on x64 generates uint64 -> float conversions but doesn't do
+// round-to-nearest-ties-to-even, which is required by WebAssembly.
+#include <emmintrin.h>
+__inline double wabt_convert_uint64_to_double(unsigned __int64 x) {
+ __m128d result = _mm_setzero_pd();
+ if (x & 0x8000000000000000ULL) {
+ result = _mm_cvtsi64_sd(result, (x >> 1) | (x & 1));
+ result = _mm_add_sd(result, result);
+ } else {
+ result = _mm_cvtsi64_sd(result, x);
+ }
+ return _mm_cvtsd_f64(result);
+}
+
+__inline float wabt_convert_uint64_to_float(unsigned __int64 x) {
+ __m128 result = _mm_setzero_ps();
+ if (x & 0x8000000000000000ULL) {
+ result = _mm_cvtsi64_ss(result, (x >> 1) | (x & 1));
+ result = _mm_add_ss(result, result);
+ } else {
+ result = _mm_cvtsi64_ss(result, x);
+ }
+ return _mm_cvtss_f32(result);
+}
+
+#else
+#define wabt_convert_uint64_to_double(x) static_cast<double>(x)
+#define wabt_convert_uint64_to_float(x) static_cast<float>(x)
+#endif
+
#endif /* WABT_CONFIG_H_ */
diff --git a/src/interpreter.cc b/src/interpreter.cc
index bb1e6a9c..1e12d4a8 100644
--- a/src/interpreter.cc
+++ b/src/interpreter.cc
@@ -1558,7 +1558,7 @@ InterpreterResult run_interpreter(InterpreterThread* thread,
case InterpreterOpcode::F32ConvertUI64: {
VALUE_TYPE_I64 value = POP_I64();
- PUSH_F32(BITCAST_FROM_F32(static_cast<float>(value)));
+ PUSH_F32(BITCAST_FROM_F32(wabt_convert_uint64_to_float(value)));
break;
}
@@ -1610,7 +1610,7 @@ InterpreterResult run_interpreter(InterpreterThread* thread,
case InterpreterOpcode::F64ConvertUI64: {
VALUE_TYPE_I64 value = POP_I64();
- PUSH_F64(BITCAST_FROM_F64(static_cast<double>(value)));
+ PUSH_F64(BITCAST_FROM_F64(wabt_convert_uint64_to_double(value)));
break;
}
diff --git a/src/tools/wasm-interp.cc b/src/tools/wasm-interp.cc
index 924c6b20..643fc3fa 100644
--- a/src/tools/wasm-interp.cc
+++ b/src/tools/wasm-interp.cc
@@ -19,6 +19,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <algorithm>
#include <vector>
#include "binary-reader.h"
@@ -179,19 +180,23 @@ static void parse_options(int argc, char** argv) {
}
static StringSlice get_dirname(const char* s) {
- /* strip everything after and including the last slash, e.g.:
+ /* strip everything after and including the last slash (or backslash), e.g.:
*
* s = "foo/bar/baz", => "foo/bar"
* s = "/usr/local/include/stdio.h", => "/usr/local/include"
* s = "foo.bar", => ""
+ * s = "some\windows\directory", => "some\windows"
*/
const char* last_slash = strrchr(s, '/');
- if (last_slash == nullptr)
+ const char* last_backslash = strrchr(s, '\\');
+ if (!last_slash)
last_slash = s;
+ if (!last_backslash)
+ last_backslash = s;
StringSlice result;
result.start = s;
- result.length = last_slash - s;
+ result.length = std::max(last_slash, last_backslash) - s;
return result;
}
@@ -213,14 +218,14 @@ static void sprint_typed_value(char* buffer,
case Type::F32: {
float value;
memcpy(&value, &tv->value.f32_bits, sizeof(float));
- snprintf(buffer, size, "f32:%g", value);
+ snprintf(buffer, size, "f32:%f", value);
break;
}
case Type::F64: {
double value;
memcpy(&value, &tv->value.f64_bits, sizeof(double));
- snprintf(buffer, size, "f64:%g", value);
+ snprintf(buffer, size, "f64:%f", value);
break;
}
diff --git a/test/interp/binary.txt b/test/interp/binary.txt
index 0193e79a..0cf8c37a 100644
--- a/test/interp/binary.txt
+++ b/test/interp/binary.txt
@@ -215,18 +215,18 @@ i64_shr_u() => i64:2305843009213693939
i64_shr_s() => i64:18446744073709551603
i64_rotl() => i64:18446744073709550823
i64_rotr() => i64:11529215046068469747
-f32_add() => f32:5
-f32_sub() => f32:-9995.5
-f32_mul() => f32:-8487.19
-f32_div() => f32:-5e+08
-f32_min() => f32:0
-f32_max() => f32:0
-f32_copysign() => f32:0
-f64_add() => f64:1.11111e+09
-f64_sub() => f64:1.234e+59
-f64_mul() => f64:-1.51797e+13
-f64_div() => f64:1e+150
-f64_min() => f64:0
-f64_max() => f64:0
-f64_copysign() => f64:0
+f32_add() => f32:5.000000
+f32_sub() => f32:-9995.500000
+f32_mul() => f32:-8487.187500
+f32_div() => f32:-500000000.000000
+f32_min() => f32:0.000000
+f32_max() => f32:0.000000
+f32_copysign() => f32:0.000000
+f64_add() => f64:1111111110.000000
+f64_sub() => f64:123400000000000007812762268812638756607430593436581896388608.000000
+f64_mul() => f64:-15179717820000.000000
+f64_div() => f64:99999999999999998083559617243737459057312001403031879309116481015410011220367858297629826861622
+f64_min() => f64:0.000000
+f64_max() => f64:0.000000
+f64_copysign() => f64:0.000000
;;; STDOUT ;;)
diff --git a/test/interp/cast.txt b/test/interp/cast.txt
index fec8a013..423f09b9 100644
--- a/test/interp/cast.txt
+++ b/test/interp/cast.txt
@@ -16,8 +16,8 @@
f64.const 1.375e10
i64.reinterpret/f64))
(;; STDOUT ;;;
-f32_reinterpret_i32() => f32:4.5
+f32_reinterpret_i32() => f32:4.500000
i32_reinterpret_f32() => i32:3227516928
-f64_reinterpret_i64() => f64:125.125
+f64_reinterpret_i64() => f64:125.125000
i64_reinterpret_f64() => i64:4758506566875873280
;;; STDOUT ;;)
diff --git a/test/interp/convert.txt b/test/interp/convert.txt
index 6b913089..49d59843 100644
--- a/test/interp/convert.txt
+++ b/test/interp/convert.txt
@@ -93,14 +93,14 @@ i64_trunc_s_f32() => i32:1
i64_trunc_u_f32() => i32:1
i64_trunc_s_f64() => i32:1
i64_trunc_u_f64() => i32:1
-f32_convert_s_i32() => f32:-1
-f32_convert_u_i32() => f32:4.29497e+09
-f32_demote_f64() => f32:1.23457e+07
-f32_convert_s_i64() => f32:0
-f32_convert_u_i64() => f32:0
-f64_convert_s_i32() => f64:-1
-f64_convert_u_i32() => f64:4.29497e+09
-f64_demote_f32() => f64:1.23457e+07
-f64_convert_s_i64() => f64:0
-f64_convert_u_i64() => f64:0
+f32_convert_s_i32() => f32:-1.000000
+f32_convert_u_i32() => f32:4294967296.000000
+f32_demote_f64() => f32:12345679.000000
+f32_convert_s_i64() => f32:0.000000
+f32_convert_u_i64() => f32:0.000000
+f64_convert_s_i32() => f64:-1.000000
+f64_convert_u_i32() => f64:4294967295.000000
+f64_demote_f32() => f64:12345679.000000
+f64_convert_s_i64() => f64:0.000000
+f64_convert_u_i64() => f64:0.000000
;;; STDOUT ;;)
diff --git a/test/interp/load.txt b/test/interp/load.txt
index e0922914..50a2dadb 100644
--- a/test/interp/load.txt
+++ b/test/interp/load.txt
@@ -68,6 +68,6 @@ i64_load() => i64:18446744073709551615
i64_load8_u() => i64:255
i64_load16_u() => i64:65535
i64_load32_u() => i64:4294967295
-f32_load() => f32:25.75
-f64_load() => f64:1023.88
+f32_load() => f32:25.750000
+f64_load() => f64:1023.875000
;;; STDOUT ;;)
diff --git a/test/interp/select.txt b/test/interp/select.txt
index 2a51a5e2..45dc4bd9 100644
--- a/test/interp/select.txt
+++ b/test/interp/select.txt
@@ -50,8 +50,8 @@ test_i32_l() => i32:2
test_i32_r() => i32:1
test_i64_l() => i64:2
test_i64_r() => i64:1
-test_f32_l() => f32:2
-test_f32_r() => f32:1
-test_f64_l() => f64:2
-test_f64_r() => f64:1
+test_f32_l() => f32:2.000000
+test_f32_r() => f32:1.000000
+test_f64_l() => f64:2.000000
+test_f64_r() => f64:1.000000
;;; STDOUT ;;)
diff --git a/test/interp/unary.txt b/test/interp/unary.txt
index 601ee751..d6300cf5 100644
--- a/test/interp/unary.txt
+++ b/test/interp/unary.txt
@@ -114,22 +114,22 @@ i64_eqz_0() => i32:1
i64_clz() => i64:56
i64_ctz() => i64:7
i64_popcnt() => i64:1
-f32_neg() => f32:-100
-f32_abs() => f32:100
+f32_neg() => f32:-100.000000
+f32_abs() => f32:100.000000
f32_sqrt_neg_is_nan() => i32:1
-f32_sqrt_100() => f32:10
-f32_ceil() => f32:-0
-f32_floor() => f32:-1
-f32_trunc() => f32:-0
-f32_nearest_lo() => f32:1
-f32_nearest_hi() => f32:2
-f64_neg() => f64:-100
-f64_abs() => f64:100
+f32_sqrt_100() => f32:10.000000
+f32_ceil() => f32:-0.000000
+f32_floor() => f32:-1.000000
+f32_trunc() => f32:-0.000000
+f32_nearest_lo() => f32:1.000000
+f32_nearest_hi() => f32:2.000000
+f64_neg() => f64:-100.000000
+f64_abs() => f64:100.000000
f64_sqrt_neg_is_nan() => i32:1
-f64_sqrt_100() => f64:10
-f64_ceil() => f64:-0
-f64_floor() => f64:-1
-f64_trunc() => f64:-0
-f64_nearest_lo() => f64:1
-f64_nearest_hi() => f64:2
+f64_sqrt_100() => f64:10.000000
+f64_ceil() => f64:-0.000000
+f64_floor() => f64:-1.000000
+f64_trunc() => f64:-0.000000
+f64_nearest_lo() => f64:1.000000
+f64_nearest_hi() => f64:2.000000
;;; STDOUT ;;)
diff --git a/test/run-wasm-link.py b/test/run-wasm-link.py
index 39b4d675..83d4d787 100755
--- a/test/run-wasm-link.py
+++ b/test/run-wasm-link.py
@@ -95,13 +95,15 @@ def main(args):
output = os.path.join(out_dir, 'linked.wasm')
if options.incremental:
- partialy_linked = output + '.partial'
+ partially_linked = output + '.partial'
for i, f in enumerate(wasm_files):
if i == 0:
wasm_link.RunWithArgs('-o', output, f)
else:
- os.rename(output, partialy_linked)
- wasm_link.RunWithArgs('-r', '-o', output, partialy_linked, f)
+ if os.path.exists(partially_linked):
+ os.remove(partially_linked)
+ os.rename(output, partially_linked)
+ wasm_link.RunWithArgs('-r', '-o', output, partially_linked, f)
#wasmdump.RunWithArgs('-d', '-h', output)
wasmdump.RunWithArgs('-d', '-x', '-r', '-h', output)
else:
diff --git a/test/spec/float_exprs.txt b/test/spec/float_exprs.txt
index 3d19912d..04c8579b 100644
--- a/test/spec/float_exprs.txt
+++ b/test/spec/float_exprs.txt
@@ -1,15 +1,15 @@
;;; TOOL: run-interp-spec
;;; STDIN_FILE: third_party/testsuite/float_exprs.wast
(;; STDOUT ;;;
-init(i32:0, f32:15.1) =>
-init(i32:4, f32:15.2) =>
-init(i32:8, f32:15.3) =>
-init(i32:12, f32:15.4) =>
-run(i32:16, f32:3) =>
-init(i32:0, f64:15.1) =>
-init(i32:8, f64:15.2) =>
-init(i32:16, f64:15.3) =>
-init(i32:24, f64:15.4) =>
-run(i32:32, f64:3) =>
+init(i32:0, f32:15.100000) =>
+init(i32:4, f32:15.200000) =>
+init(i32:8, f32:15.300000) =>
+init(i32:12, f32:15.400000) =>
+run(i32:16, f32:3.000000) =>
+init(i32:0, f64:15.100000) =>
+init(i32:8, f64:15.200000) =>
+init(i32:16, f64:15.300000) =>
+init(i32:24, f64:15.400000) =>
+run(i32:32, f64:3.000000) =>
724/724 tests passed.
;;; STDOUT ;;)
diff --git a/test/spec/imports.txt b/test/spec/imports.txt
index 95065729..77b4dea9 100644
--- a/test/spec/imports.txt
+++ b/test/spec/imports.txt
@@ -2,15 +2,15 @@
;;; STDIN_FILE: third_party/testsuite/imports.wast
(;; STDOUT ;;;
called host spectest.print(i32:13) =>
-called host spectest.print(i32:14, f32:42) =>
+called host spectest.print(i32:14, f32:42.000000) =>
called host spectest.print(i32:13) =>
called host spectest.print(i32:13) =>
-called host spectest.print(f32:13) =>
+called host spectest.print(f32:13.000000) =>
called host spectest.print(i32:13) =>
-called host spectest.print(f64:25, f64:53) =>
-called host spectest.print(f64:24) =>
-called host spectest.print(f64:24) =>
-called host spectest.print(f64:24) =>
+called host spectest.print(f64:25.000000, f64:53.000000) =>
+called host spectest.print(f64:24.000000) =>
+called host spectest.print(f64:24.000000) =>
+called host spectest.print(f64:24.000000) =>
out/third_party/testsuite/imports.wast:89: assert_unlinkable passed:
error: unknown module field "unknown"
error: @0x00000020: OnImport callback failed