Skip to content

Commit 277ab1e

Browse files
committed
Update wabt sources
1 parent 6d2cd72 commit 277ab1e

Some content is hidden

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

51 files changed

+10220
-9876
lines changed

lib/wabt/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
same "printed page" as the copyright notice for easier
188188
identification within third-party archives.
189189

190-
Copyright 2015 the repository authors, see AUTHORS file.
190+
Copyright [yyyy] [name of copyright owner]
191191

192192
Licensed under the Apache License, Version 2.0 (the "License");
193193
you may not use this file except in compliance with the License.

lib/wabt/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ You can use `-h` to get additional help:
205205
$ out/wasm-interp -h
206206
```
207207

208+
## Running wasm2c
209+
210+
See [wasm2c.md](wasm2c/README.md)
211+
208212
## Running the test suite
209213

210214
See [test/README.md](test/README.md).

lib/wabt/chakra/wabtapi.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MyErrorHandler : public ErrorHandler
2424
public:
2525
MyErrorHandler() : ErrorHandler(Location::Type::Text) {}
2626

27-
virtual bool OnError(const Location& loc, const std::string& error, const std::string& source_line, size_t source_line_column_offset) override
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
2828
{
2929
int colStart = loc.first_column - 1 - (int)source_line_column_offset;
3030
int sourceErrorLength = (loc.last_column - loc.first_column) - 2;
@@ -34,7 +34,8 @@ class MyErrorHandler : public ErrorHandler
3434
sourceErrorLength = 0;
3535
}
3636
char buf[4096];
37-
wabt_snprintf(buf, 4096, "Wast Parsing error:%u:%u:\n%s\n%s\n%*s^%*s^",
37+
wabt_snprintf(buf, 4096, "Wast Parsing %s:%u:%u:\n%s\n%s\n%*s^%*s^",
38+
GetErrorLevelName(level),
3839
loc.line,
3940
loc.first_column,
4041
error.c_str(),

lib/wabt/chakra/windows/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#define HAVE_STRCASECMP 0
3939

4040
/* Whether ENABLE_VIRTUAL_TERMINAL_PROCESSING is defined by windows.h */
41-
#define HAVE_WIN32_VT100 0
41+
#define HAVE_WIN32_VT100 1
4242

4343
#define COMPILER_IS_CLANG 0
4444
#define COMPILER_IS_GNU 0

lib/wabt/src/binary-reader-interp.cc

Lines changed: 63 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
7878
std::unique_ptr<OutputBuffer> ReleaseOutputBuffer();
7979

8080
// Implement BinaryReader.
81-
bool OnError(const char* message) override;
81+
bool OnError(ErrorLevel, const char* message) override;
8282

8383
wabt::Result EndModule() override;
8484

@@ -155,7 +155,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
155155
uint32_t alignment_log2,
156156
Address offset) override;
157157
wabt::Result OnBinaryExpr(wabt::Opcode opcode) override;
158-
wabt::Result OnBlockExpr(Index num_types, Type* sig_types) override;
158+
wabt::Result OnBlockExpr(Type sig_type) override;
159159
wabt::Result OnBrExpr(Index depth) override;
160160
wabt::Result OnBrIfExpr(Index depth) override;
161161
wabt::Result OnBrTableExpr(Index num_targets,
@@ -165,7 +165,6 @@ class BinaryReaderInterp : public BinaryReaderNop {
165165
wabt::Result OnCallIndirectExpr(Index sig_index) override;
166166
wabt::Result OnCompareExpr(wabt::Opcode opcode) override;
167167
wabt::Result OnConvertExpr(wabt::Opcode opcode) override;
168-
wabt::Result OnCurrentMemoryExpr() override;
169168
wabt::Result OnDropExpr() override;
170169
wabt::Result OnElseExpr() override;
171170
wabt::Result OnEndExpr() override;
@@ -174,14 +173,15 @@ class BinaryReaderInterp : public BinaryReaderNop {
174173
wabt::Result OnV128ConstExpr(v128 value_bits) override;
175174
wabt::Result OnGetGlobalExpr(Index global_index) override;
176175
wabt::Result OnGetLocalExpr(Index local_index) override;
177-
wabt::Result OnGrowMemoryExpr() override;
178176
wabt::Result OnI32ConstExpr(uint32_t value) override;
179177
wabt::Result OnI64ConstExpr(uint64_t value) override;
180-
wabt::Result OnIfExpr(Index num_types, Type* sig_types) override;
178+
wabt::Result OnIfExpr(Type sig_type) override;
181179
wabt::Result OnLoadExpr(wabt::Opcode opcode,
182180
uint32_t alignment_log2,
183181
Address offset) override;
184-
wabt::Result OnLoopExpr(Index num_types, Type* sig_types) override;
182+
wabt::Result OnLoopExpr(Type sig_type) override;
183+
wabt::Result OnMemoryGrowExpr() override;
184+
wabt::Result OnMemorySizeExpr() override;
185185
wabt::Result OnNopExpr() override;
186186
wabt::Result OnReturnExpr() override;
187187
wabt::Result OnSelectExpr() override;
@@ -222,10 +222,13 @@ class BinaryReaderInterp : public BinaryReaderNop {
222222
void PushLabel(IstreamOffset offset, IstreamOffset fixup_offset);
223223
void PopLabel();
224224

225-
bool HandleError(Offset offset, const char* message);
225+
bool HandleError(ErrorLevel, Offset offset, const char* message);
226226
void PrintError(const char* format, ...);
227227

228228
Index TranslateSigIndexToEnv(Index sig_index);
229+
void GetBlockSignature(Type sig_type,
230+
TypeVector* out_param_types,
231+
TypeVector* out_result_types);
229232
FuncSignature* GetSignatureByModuleIndex(Index sig_index);
230233
Index TranslateFuncIndexToEnv(Index func_index);
231234
Index TranslateModuleFuncIndexToDefined(Index func_index);
@@ -248,7 +251,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
248251
wabt::Result EmitI64(uint64_t value);
249252
wabt::Result EmitV128(v128 value);
250253
wabt::Result EmitI32At(IstreamOffset offset, uint32_t value);
251-
wabt::Result EmitDropKeep(uint32_t drop, uint8_t keep);
254+
wabt::Result EmitDropKeep(uint32_t drop, uint32_t keep);
252255
wabt::Result AppendFixup(IstreamOffsetVectorVector* fixups_vector,
253256
Index index);
254257
wabt::Result EmitBrOffset(Index depth, IstreamOffset offset);
@@ -340,21 +343,36 @@ Label* BinaryReaderInterp::TopLabel() {
340343
return GetLabel(0);
341344
}
342345

343-
bool BinaryReaderInterp::HandleError(Offset offset, const char* message) {
344-
return error_handler_->OnError(offset, message);
346+
bool BinaryReaderInterp::HandleError(ErrorLevel error_level,
347+
Offset offset,
348+
const char* message) {
349+
return error_handler_->OnError(error_level, offset, message);
345350
}
346351

347352
void WABT_PRINTF_FORMAT(2, 3) BinaryReaderInterp::PrintError(const char* format,
348353
...) {
349354
WABT_SNPRINTF_ALLOCA(buffer, length, format);
350-
HandleError(kInvalidOffset, buffer);
355+
HandleError(ErrorLevel::Error, kInvalidOffset, buffer);
351356
}
352357

353358
Index BinaryReaderInterp::TranslateSigIndexToEnv(Index sig_index) {
354359
assert(sig_index < sig_index_mapping_.size());
355360
return sig_index_mapping_[sig_index];
356361
}
357362

363+
void BinaryReaderInterp::GetBlockSignature(Type sig_type,
364+
TypeVector* out_param_types,
365+
TypeVector* out_result_types) {
366+
if (IsTypeIndex(sig_type)) {
367+
FuncSignature* func_sig = GetSignatureByModuleIndex(GetTypeIndex(sig_type));
368+
*out_param_types = func_sig->param_types;
369+
*out_result_types = func_sig->result_types;
370+
} else {
371+
out_param_types->clear();
372+
*out_result_types = GetInlineTypeVector(sig_type);
373+
}
374+
}
375+
358376
FuncSignature* BinaryReaderInterp::GetSignatureByModuleIndex(Index sig_index) {
359377
return env_->GetFuncSignature(TranslateSigIndexToEnv(sig_index));
360378
}
@@ -440,16 +458,16 @@ wabt::Result BinaryReaderInterp::EmitI32At(IstreamOffset offset,
440458
return EmitDataAt(offset, &value, sizeof(value));
441459
}
442460

443-
wabt::Result BinaryReaderInterp::EmitDropKeep(uint32_t drop, uint8_t keep) {
461+
wabt::Result BinaryReaderInterp::EmitDropKeep(uint32_t drop, uint32_t keep) {
444462
assert(drop != UINT32_MAX);
445-
assert(keep <= 1);
463+
assert(keep != UINT32_MAX);
446464
if (drop > 0) {
447465
if (drop == 1 && keep == 0) {
448466
CHECK_RESULT(EmitOpcode(Opcode::Drop));
449467
} else {
450468
CHECK_RESULT(EmitOpcode(Opcode::InterpDropKeep));
451469
CHECK_RESULT(EmitI32(drop));
452-
CHECK_RESULT(EmitI8(keep));
470+
CHECK_RESULT(EmitI32(keep));
453471
}
454472
}
455473
return wabt::Result::Ok;
@@ -482,8 +500,7 @@ wabt::Result BinaryReaderInterp::GetBrDropKeepCount(Index depth,
482500
Index* out_keep_count) {
483501
TypeChecker::Label* label;
484502
CHECK_RESULT(typechecker_.GetLabel(depth, &label));
485-
*out_keep_count =
486-
label->label_type != LabelType::Loop ? label->sig.size() : 0;
503+
*out_keep_count = label->br_types().size();
487504
if (typechecker_.IsUnreachable()) {
488505
*out_drop_count = 0;
489506
} else {
@@ -516,7 +533,7 @@ wabt::Result BinaryReaderInterp::EmitBrTableOffset(Index depth) {
516533
CHECK_RESULT(GetBrDropKeepCount(depth, &drop_count, &keep_count));
517534
CHECK_RESULT(EmitBrOffset(depth, GetLabel(depth)->offset));
518535
CHECK_RESULT(EmitI32(drop_count));
519-
CHECK_RESULT(EmitI8(keep_count));
536+
CHECK_RESULT(EmitI32(keep_count));
520537
return wabt::Result::Ok;
521538
}
522539

@@ -545,8 +562,8 @@ wabt::Result BinaryReaderInterp::EmitFuncOffset(DefinedFunc* func,
545562
return wabt::Result::Ok;
546563
}
547564

548-
bool BinaryReaderInterp::OnError(const char* message) {
549-
return HandleError(state->offset, message);
565+
bool BinaryReaderInterp::OnError(ErrorLevel error_level, const char* message) {
566+
return HandleError(error_level, state->offset, message);
550567
}
551568

552569
wabt::Result BinaryReaderInterp::OnTypeCount(Index count) {
@@ -1101,7 +1118,7 @@ wabt::Result BinaryReaderInterp::BeginFunctionBody(Index index) {
11011118
for (Type param_type : sig->param_types)
11021119
func->param_and_local_types.push_back(param_type);
11031120

1104-
CHECK_RESULT(typechecker_.BeginFunction(&sig->result_types));
1121+
CHECK_RESULT(typechecker_.BeginFunction(sig->result_types));
11051122

11061123
/* push implicit func label (equivalent to return) */
11071124
PushLabel(kInvalidIstreamOffset, kInvalidIstreamOffset);
@@ -1251,23 +1268,26 @@ wabt::Result BinaryReaderInterp::OnBinaryExpr(wabt::Opcode opcode) {
12511268
return wabt::Result::Ok;
12521269
}
12531270

1254-
wabt::Result BinaryReaderInterp::OnBlockExpr(Index num_types, Type* sig_types) {
1255-
TypeVector sig(sig_types, sig_types + num_types);
1256-
CHECK_RESULT(typechecker_.OnBlock(&sig));
1271+
wabt::Result BinaryReaderInterp::OnBlockExpr(Type sig_type) {
1272+
TypeVector param_types, result_types;
1273+
GetBlockSignature(sig_type, &param_types, &result_types);
1274+
CHECK_RESULT(typechecker_.OnBlock(param_types, result_types));
12571275
PushLabel(kInvalidIstreamOffset, kInvalidIstreamOffset);
12581276
return wabt::Result::Ok;
12591277
}
12601278

1261-
wabt::Result BinaryReaderInterp::OnLoopExpr(Index num_types, Type* sig_types) {
1262-
TypeVector sig(sig_types, sig_types + num_types);
1263-
CHECK_RESULT(typechecker_.OnLoop(&sig));
1279+
wabt::Result BinaryReaderInterp::OnLoopExpr(Type sig_type) {
1280+
TypeVector param_types, result_types;
1281+
GetBlockSignature(sig_type, &param_types, &result_types);
1282+
CHECK_RESULT(typechecker_.OnLoop(param_types, result_types));
12641283
PushLabel(GetIstreamOffset(), kInvalidIstreamOffset);
12651284
return wabt::Result::Ok;
12661285
}
12671286

1268-
wabt::Result BinaryReaderInterp::OnIfExpr(Index num_types, Type* sig_types) {
1269-
TypeVector sig(sig_types, sig_types + num_types);
1270-
CHECK_RESULT(typechecker_.OnIf(&sig));
1287+
wabt::Result BinaryReaderInterp::OnIfExpr(Type sig_type) {
1288+
TypeVector param_types, result_types;
1289+
GetBlockSignature(sig_type, &param_types, &result_types);
1290+
CHECK_RESULT(typechecker_.OnIf(param_types, result_types));
12711291
CHECK_RESULT(EmitOpcode(Opcode::InterpBrUnless));
12721292
IstreamOffset fixup_offset = GetIstreamOffset();
12731293
CHECK_RESULT(EmitI32(kInvalidIstreamOffset));
@@ -1347,7 +1367,7 @@ wabt::Result BinaryReaderInterp::OnBrTableExpr(Index num_targets,
13471367
wabt::Result BinaryReaderInterp::OnCallExpr(Index func_index) {
13481368
Func* func = GetFuncByModuleIndex(func_index);
13491369
FuncSignature* sig = env_->GetFuncSignature(func->sig_index);
1350-
CHECK_RESULT(typechecker_.OnCall(&sig->param_types, &sig->result_types));
1370+
CHECK_RESULT(typechecker_.OnCall(sig->param_types, sig->result_types));
13511371

13521372
if (func->is_host) {
13531373
CHECK_RESULT(EmitOpcode(Opcode::InterpCallHost));
@@ -1367,7 +1387,7 @@ wabt::Result BinaryReaderInterp::OnCallIndirectExpr(Index sig_index) {
13671387
}
13681388
FuncSignature* sig = GetSignatureByModuleIndex(sig_index);
13691389
CHECK_RESULT(
1370-
typechecker_.OnCallIndirect(&sig->param_types, &sig->result_types));
1390+
typechecker_.OnCallIndirect(sig->param_types, sig->result_types));
13711391

13721392
CHECK_RESULT(EmitOpcode(Opcode::CallIndirect));
13731393
CHECK_RESULT(EmitI32(module_->table_index));
@@ -1483,14 +1503,6 @@ wabt::Result BinaryReaderInterp::OnTeeLocalExpr(Index local_index) {
14831503
return wabt::Result::Ok;
14841504
}
14851505

1486-
wabt::Result BinaryReaderInterp::OnGrowMemoryExpr() {
1487-
CHECK_RESULT(CheckHasMemory(wabt::Opcode::GrowMemory));
1488-
CHECK_RESULT(typechecker_.OnGrowMemory());
1489-
CHECK_RESULT(EmitOpcode(Opcode::GrowMemory));
1490-
CHECK_RESULT(EmitI32(module_->memory_index));
1491-
return wabt::Result::Ok;
1492-
}
1493-
14941506
wabt::Result BinaryReaderInterp::OnLoadExpr(wabt::Opcode opcode,
14951507
uint32_t alignment_log2,
14961508
Address offset) {
@@ -1515,10 +1527,18 @@ wabt::Result BinaryReaderInterp::OnStoreExpr(wabt::Opcode opcode,
15151527
return wabt::Result::Ok;
15161528
}
15171529

1518-
wabt::Result BinaryReaderInterp::OnCurrentMemoryExpr() {
1519-
CHECK_RESULT(CheckHasMemory(wabt::Opcode::CurrentMemory));
1520-
CHECK_RESULT(typechecker_.OnCurrentMemory());
1521-
CHECK_RESULT(EmitOpcode(Opcode::CurrentMemory));
1530+
wabt::Result BinaryReaderInterp::OnMemoryGrowExpr() {
1531+
CHECK_RESULT(CheckHasMemory(wabt::Opcode::MemoryGrow));
1532+
CHECK_RESULT(typechecker_.OnMemoryGrow());
1533+
CHECK_RESULT(EmitOpcode(Opcode::MemoryGrow));
1534+
CHECK_RESULT(EmitI32(module_->memory_index));
1535+
return wabt::Result::Ok;
1536+
}
1537+
1538+
wabt::Result BinaryReaderInterp::OnMemorySizeExpr() {
1539+
CHECK_RESULT(CheckHasMemory(wabt::Opcode::MemorySize));
1540+
CHECK_RESULT(typechecker_.OnMemorySize());
1541+
CHECK_RESULT(EmitOpcode(Opcode::MemorySize));
15221542
CHECK_RESULT(EmitI32(module_->memory_index));
15231543
return wabt::Result::Ok;
15241544
}

0 commit comments

Comments
 (0)