Skip to content

Commit 303f24f

Browse files
committed
[MERGE #5879 @Cellule] Update WebAssembly spec test suite
Merge pull request #5879 from Cellule:users/micfer/wasm_spec - Updated Wabt version to support new text format syntax - Made fixes to wabtapi.cc to reflect new way of propagating errors - Updated WasmSpec tests using commit 76d26bbc70c51729536243bbd7c64241a6d993d3 (subsequent commit uses a new breaking text format that isn't supported by wabt yet) - Updated jsapi harness to reflect new way of importing scripts and triggering tests
2 parents 720e289 + eebe200 commit 303f24f

File tree

314 files changed

+55450
-44126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

314 files changed

+55450
-44126
lines changed

lib/Runtime/Library/WabtInterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Js::Var WabtInterface::EntryConvertWast2Wasm(RecyclableObject* function, CallInf
173173
}
174174
return result;
175175
}
176-
catch (ChakraWabt::Error& e)
176+
catch (ChakraWabt::WabtAPIError& e)
177177
{
178178
JavascriptError::ThrowTypeErrorVar(scriptContext, WABTERR_WabtError, NarrowStringToWide(&context, e.message));
179179
}

lib/wabt/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
/fuzz-out
44
/emscripten
55
*.pyc
6-
6+
.idea/
7+
/cmake-build-debug/
78
.gitmodules
89
/test
910
/tests

lib/wabt/CMakeLists.txt

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -84,48 +84,41 @@ set(WAST_LEXER_GEN_CC src/prebuilt/wast-lexer-gen.cc)
8484
add_custom_target(everything)
8585

8686
add_library(libwabt OBJECT
87-
src/token.cc
88-
src/opcode.cc
89-
src/error-handler.cc
90-
src/hash-util.cc
91-
src/filenames.cc
92-
src/string-view.cc
93-
src/ir.cc
94-
src/expr-visitor.cc
95-
src/lexer-source.cc
96-
src/lexer-source-line-finder.cc
97-
src/wast-parser-lexer-shared.cc
98-
${WAST_LEXER_GEN_CC}
99-
src/wast-parser.cc
100-
src/type-checker.cc
101-
src/validator.cc
102-
87+
chakra/wabtapi.cc
88+
src/apply-names.cc
89+
src/binary.cc
10390
src/binary-reader.cc
91+
src/binary-reader-ir.cc
10492
src/binary-reader-logging.cc
10593
src/binary-writer.cc
10694
src/binary-writer-spec.cc
107-
src/binary-reader-ir.cc
10895
src/binding-hash.cc
109-
src/wat-writer.cc
110-
src/interp.cc
111-
src/binary-reader-interp.cc
112-
src/apply-names.cc
113-
src/generate-names.cc
114-
src/resolve-names.cc
115-
116-
src/binary.cc
11796
src/color.cc
11897
src/common.cc
11998
src/config.cc
99+
src/error-formatter.cc
100+
src/expr-visitor.cc
120101
src/feature.cc
102+
src/filenames.cc
103+
src/generate-names.cc
104+
src/hash-util.cc
105+
src/ir.cc
121106
src/leb128.cc
107+
src/lexer-source.cc
108+
src/lexer-source-line-finder.cc
122109
src/literal.cc
110+
src/opcode.cc
111+
src/opcode-code-table.c
123112
src/option-parser.cc
113+
src/resolve-names.cc
124114
src/stream.cc
115+
src/string-view.cc
116+
src/token.cc
125117
src/tracing.cc
118+
src/type-checker.cc
126119
src/utf8.cc
127-
128-
chakra/wabtapi.cc
129-
130-
120+
src/validator.cc
121+
src/wast-parser.cc
122+
src/wat-writer.cc
123+
${WAST_LEXER_GEN_CC}
131124
)

lib/wabt/README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build Status](https://travis-ci.org/WebAssembly/wabt.svg?branch=master)](https://travis-ci.org/WebAssembly/wabt) [![Windows status](https://ci.appveyor.com/api/projects/status/79hqj5l0qggw645d/branch/master?svg=true)](https://ci.appveyor.com/project/WebAssembly/wabt/branch/master)
1+
[![Build Status](https://travis-ci.org/WebAssembly/wabt.svg?branch=master)](https://travis-ci.org/WebAssembly/wabt) [![Windows status](https://ci.appveyor.com/api/projects/status/8vl5jwtk5ch6r84t/branch/master?svg=true)](https://ci.appveyor.com/project/WebAssembly/wabt/branch/master)
22

33
# WABT: The WebAssembly Binary Toolkit
44

@@ -24,9 +24,9 @@ target; instead they aim for full fidelity and compliance with the spec (e.g.
2424

2525
Wabt has been compiled to JavaScript via emscripten. Some of the functionality is available in the following demos:
2626

27-
- [index](https://cdn.rawgit.com/WebAssembly/wabt/aae5a4b7/demo/index.html)
28-
- [wat2wasm](https://cdn.rawgit.com/WebAssembly/wabt/aae5a4b7/demo/wat2wasm/)
29-
- [wasm2wat](https://cdn.rawgit.com/WebAssembly/wabt/aae5a4b7/demo/wasm2wat/)
27+
- [index](https://webassembly.github.io/wabt/demo/)
28+
- [wat2wasm](https://webassembly.github.io/wabt/demo/wat2wasm/)
29+
- [wasm2wat](https://webassembly.github.io/wabt/demo/wasm2wat/)
3030

3131
## Cloning
3232

@@ -53,6 +53,10 @@ $ make
5353
This will build the default version of the tools: a debug build using the Clang
5454
compiler.
5555

56+
**NOTE**: Under the hood, this uses make to run CMake, which then calls make again.
57+
On some systems, this doesn't build properly. If you see these errors, you can build
58+
using CMake directly as described below.
59+
5660
There are many make targets available for other configurations as well. They
5761
are generated from every combination of a compiler, build type and
5862
configuration.
@@ -71,6 +75,8 @@ $ make clang-debug-lsan
7175
$ make gcc-debug-no-re2c
7276
```
7377

78+
### Building using CMake directly
79+
7480
You can also run CMake yourself, the normal way:
7581

7682
```console
@@ -149,13 +155,13 @@ $ out/wat2wasm spec-test.wast -v
149155
$ out/wast2json spec-test.wast -o spec-test.json
150156
```
151157

152-
You can use `-h` to get additional help:
158+
You can use `--help` to get additional help:
153159

154160
```console
155-
$ out/wat2wasm -h
161+
$ out/wat2wasm --help
156162
```
157163

158-
Or try the [online demo](https://cdn.rawgit.com/WebAssembly/wabt/aae5a4b7/demo/wat2wasm/).
164+
Or try the [online demo](https://webassembly.github.io/wabt/demo/wat2wasm/).
159165

160166
## Running wasm2wat
161167

@@ -169,13 +175,13 @@ $ out/wasm2wat test.wasm -o test.wat
169175
$ out/wasm2wat test.wasm -o test.wat
170176
```
171177

172-
You can use `-h` to get additional help:
178+
You can use `--help` to get additional help:
173179

174180
```console
175-
$ out/wasm2wat -h
181+
$ out/wasm2wat --help
176182
```
177183

178-
Or try the [online demo](https://cdn.rawgit.com/WebAssembly/wabt/aae5a4b7/demo/wasm2wat/).
184+
Or try the [online demo](https://webassembly.github.io/wabt/demo/wasm2wat/).
179185

180186
## Running wasm-interp
181187

@@ -199,10 +205,10 @@ $ out/wasm-interp test.json --spec
199205
$ out/wasm-interp test.wasm -V 100 --run-all-exports
200206
```
201207

202-
You can use `-h` to get additional help:
208+
You can use `--help` to get additional help:
203209

204210
```console
205-
$ out/wasm-interp -h
211+
$ out/wasm-interp --help
206212
```
207213

208214
## Running wasm2c

lib/wabt/chakra/wabtapi.cc

Lines changed: 52 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#include "src/wast-lexer.h"
1111
#include "src/resolve-names.h"
1212
#include "src/binary-writer.h"
13-
#include "src/error-handler.h"
13+
#include "src/error.h"
14+
#include "src/error-formatter.h"
1415
#include "src/ir.h"
1516
#include "src/cast.h"
1617
#include "src/validator.h"
@@ -19,46 +20,40 @@
1920
using namespace wabt;
2021
using namespace ChakraWabt;
2122

22-
class MyErrorHandler : public ErrorHandler
23+
void CheckResult(
24+
Result result,
25+
Errors* errors,
26+
WastLexer* lexer,
27+
const char* errorMessage
28+
)
2329
{
24-
public:
25-
MyErrorHandler() : ErrorHandler(Location::Type::Text) {}
26-
27-
virtual bool OnError(ErrorLevel level, const Location& loc, const std::string& error, const std::string& source_line, size_t source_line_column_offset) override
30+
if (!Succeeded(result))
2831
{
29-
int colStart = loc.first_column - 1 - (int)source_line_column_offset;
30-
int sourceErrorLength = (loc.last_column - loc.first_column) - 2;
31-
if (sourceErrorLength < 0)
32+
if (errors && errors->size() > 0)
3233
{
33-
// -2 probably overflowed
34-
sourceErrorLength = 0;
34+
std::string message = FormatErrorsToString(
35+
*errors,
36+
Location::Type::Text,
37+
lexer->MakeLineFinder().get(),
38+
wabt::Color(),
39+
errorMessage,
40+
PrintHeader::Once,
41+
256
42+
);
43+
char buf[4096];
44+
wabt_snprintf(buf, 4096, "Wast Parsing %s", message.c_str());
45+
throw WabtAPIError(buf);
3546
}
36-
char buf[4096];
37-
wabt_snprintf(buf, 4096, "Wast Parsing %s:%u:%u:\n%s\n%s\n%*s^%*s^",
38-
GetErrorLevelName(level),
39-
loc.line,
40-
loc.first_column,
41-
error.c_str(),
42-
source_line.c_str(),
43-
colStart, "",
44-
sourceErrorLength, "");
45-
throw Error(buf);
47+
throw WabtAPIError(errorMessage);
4648
}
47-
48-
virtual size_t source_line_max_length() const override
49-
{
50-
return 256;
51-
}
52-
53-
};
49+
}
5450

5551
namespace ChakraWabt
5652
{
5753
struct Context
5854
{
5955
ChakraContext* chakra;
6056
WastLexer* lexer;
61-
MyErrorHandler* errorHandler;
6257
};
6358
}
6459

@@ -91,7 +86,7 @@ uint TruncSizeT(size_t value)
9186
{
9287
if (value > 0xffffffff)
9388
{
94-
throw Error("Out of Memory");
89+
throw WabtAPIError("Out of Memory");
9590
}
9691
return (uint)value;
9792
}
@@ -101,7 +96,7 @@ void set_property(Context* ctx, Js::Var obj, PropertyId id, Js::Var value, const
10196
bool success = ctx->chakra->spec->setProperty(obj, id, value, ctx->chakra->user_data);
10297
if (!success)
10398
{
104-
throw Error(messageIfFailed);
99+
throw WabtAPIError(messageIfFailed);
105100
}
106101
}
107102

@@ -166,7 +161,7 @@ void write_command_type(Context* ctx, CommandType type, Js::Var cmdObj)
166161
uint i = (uint)type;
167162
if (i > (uint)CommandType::Last)
168163
{
169-
throw Error("invalid command type");
164+
throw WabtAPIError("invalid command type");
170165
}
171166
write_string(ctx, cmdObj, PropertyIds::type, s_command_names[i]);
172167
}
@@ -203,7 +198,7 @@ Js::Var create_const_vector(Context* ctx, const ConstVector& consts)
203198
break;
204199
default:
205200
assert(0);
206-
throw Error("invalid constant type");
201+
throw WabtAPIError("invalid constant type");
207202
}
208203
write_string(ctx, constDescriptor, PropertyIds::value, buf);
209204
}
@@ -287,19 +282,21 @@ Js::Var create_module(Context* ctx, const Module* module, bool validate = true)
287282
{
288283
if (!module)
289284
{
290-
throw Error("No module found");
285+
throw WabtAPIError("No module found");
291286
}
292287
if (validate)
293288
{
294289
ValidateOptions options(GetWabtFeatures(*ctx->chakra));
295-
ValidateModule(ctx->lexer, module, ctx->errorHandler, &options);
290+
Errors errors;
291+
Result result = ValidateModule(module, &errors, options);
292+
CheckResult(result, &errors, ctx->lexer, "Failed to validate module");
296293
}
297294
MemoryStream stream;
298295
WriteBinaryOptions s_write_binary_options;
299-
Result result = WriteBinaryModule(&stream, module, &s_write_binary_options);
296+
Result result = WriteBinaryModule(&stream, module, s_write_binary_options);
300297
if (!Succeeded(result))
301298
{
302-
throw Error("Error while writing module");
299+
throw WabtAPIError("Error while writing module");
303300
}
304301
const uint8_t* data = stream.output_buffer().data.data();
305302
const size_t size = stream.output_buffer().size();
@@ -469,25 +466,17 @@ Js::Var write_commands(Context* ctx, Script* script)
469466

470467
void Validate(const ChakraContext& ctx, bool isSpec)
471468
{
472-
if (!ctx.createBuffer) throw Error("Missing createBuffer");
469+
if (!ctx.createBuffer) throw WabtAPIError("Missing createBuffer");
473470
if (isSpec)
474471
{
475-
if (!ctx.spec) throw Error("Missing Spec context");
476-
if (!ctx.spec->setProperty) throw Error("Missing spec->setProperty");
477-
if (!ctx.spec->int32ToVar) throw Error("Missing spec->int32ToVar");
478-
if (!ctx.spec->int64ToVar) throw Error("Missing spec->int64ToVar");
479-
if (!ctx.spec->stringToVar) throw Error("Missing spec->stringToVar");
480-
if (!ctx.spec->createObject) throw Error("Missing spec->createObject");
481-
if (!ctx.spec->createArray) throw Error("Missing spec->createArray");
482-
if (!ctx.spec->push) throw Error("Missing spec->push");
483-
}
484-
}
485-
486-
void CheckResult(Result result, const char* errorMessage)
487-
{
488-
if (!Succeeded(result))
489-
{
490-
throw Error(errorMessage);
472+
if (!ctx.spec) throw WabtAPIError("Missing Spec context");
473+
if (!ctx.spec->setProperty) throw WabtAPIError("Missing spec->setProperty");
474+
if (!ctx.spec->int32ToVar) throw WabtAPIError("Missing spec->int32ToVar");
475+
if (!ctx.spec->int64ToVar) throw WabtAPIError("Missing spec->int64ToVar");
476+
if (!ctx.spec->stringToVar) throw WabtAPIError("Missing spec->stringToVar");
477+
if (!ctx.spec->createObject) throw WabtAPIError("Missing spec->createObject");
478+
if (!ctx.spec->createArray) throw WabtAPIError("Missing spec->createArray");
479+
if (!ctx.spec->push) throw WabtAPIError("Missing spec->push");
491480
}
492481
}
493482

@@ -497,32 +486,31 @@ Js::Var ChakraWabt::ConvertWast2Wasm(ChakraContext& chakraCtx, char* buffer, uin
497486

498487
std::unique_ptr<WastLexer> lexer = WastLexer::CreateBufferLexer("", buffer, (size_t)bufferSize);
499488

500-
MyErrorHandler s_error_handler;
501489
WastParseOptions options(GetWabtFeatures(chakraCtx));
502490
Context ctx;
503491
ctx.chakra = &chakraCtx;
504-
ctx.errorHandler = &s_error_handler;
505492
ctx.lexer = lexer.get();
493+
Errors errors;
506494

507495
if (isSpecText)
508496
{
509497
std::unique_ptr<Script> script;
510-
Result result = ParseWastScript(lexer.get(), &script, &s_error_handler, &options);
511-
CheckResult(result, "Invalid wast script");
498+
Result result = ParseWastScript(lexer.get(), &script, &errors, &options);
499+
CheckResult(result, &errors, lexer.get(), "Invalid wast script");
512500

513-
result = ResolveNamesScript(lexer.get(), script.get(), &s_error_handler);
514-
CheckResult(result, "Unable to resolve script's names");
501+
result = ResolveNamesScript(script.get(), &errors);
502+
CheckResult(result, &errors, lexer.get(), "Unable to resolve script's names");
515503

516504
return write_commands(&ctx, script.get());
517505
}
518506
else
519507
{
520508
std::unique_ptr<Module> module;
521-
Result result = ParseWatModule(lexer.get(), &module, &s_error_handler, &options);
522-
CheckResult(result, "Invalid wat script");
509+
Result result = ParseWatModule(lexer.get(), &module, &errors, &options);
510+
CheckResult(result, &errors, lexer.get(), "Invalid wat script");
523511

524-
result = ResolveNamesModule(lexer.get(), module.get(), &s_error_handler);
525-
CheckResult(result, "Unable to resolve module's names");
512+
result = ResolveNamesModule(module.get(), &errors);
513+
CheckResult(result, &errors, lexer.get(), "Unable to resolve module's names");
526514

527515
return create_module(&ctx, module.get());
528516
}

0 commit comments

Comments
 (0)