@@ -78,7 +78,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
78
78
std::unique_ptr<OutputBuffer> ReleaseOutputBuffer ();
79
79
80
80
// Implement BinaryReader.
81
- bool OnError (const char * message) override ;
81
+ bool OnError (ErrorLevel, const char * message) override ;
82
82
83
83
wabt::Result EndModule () override ;
84
84
@@ -155,7 +155,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
155
155
uint32_t alignment_log2,
156
156
Address offset) override ;
157
157
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 ;
159
159
wabt::Result OnBrExpr (Index depth) override ;
160
160
wabt::Result OnBrIfExpr (Index depth) override ;
161
161
wabt::Result OnBrTableExpr (Index num_targets,
@@ -165,7 +165,6 @@ class BinaryReaderInterp : public BinaryReaderNop {
165
165
wabt::Result OnCallIndirectExpr (Index sig_index) override ;
166
166
wabt::Result OnCompareExpr (wabt::Opcode opcode) override ;
167
167
wabt::Result OnConvertExpr (wabt::Opcode opcode) override ;
168
- wabt::Result OnCurrentMemoryExpr () override ;
169
168
wabt::Result OnDropExpr () override ;
170
169
wabt::Result OnElseExpr () override ;
171
170
wabt::Result OnEndExpr () override ;
@@ -174,14 +173,15 @@ class BinaryReaderInterp : public BinaryReaderNop {
174
173
wabt::Result OnV128ConstExpr (v128 value_bits) override ;
175
174
wabt::Result OnGetGlobalExpr (Index global_index) override ;
176
175
wabt::Result OnGetLocalExpr (Index local_index) override ;
177
- wabt::Result OnGrowMemoryExpr () override ;
178
176
wabt::Result OnI32ConstExpr (uint32_t value) override ;
179
177
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 ;
181
179
wabt::Result OnLoadExpr (wabt::Opcode opcode,
182
180
uint32_t alignment_log2,
183
181
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 ;
185
185
wabt::Result OnNopExpr () override ;
186
186
wabt::Result OnReturnExpr () override ;
187
187
wabt::Result OnSelectExpr () override ;
@@ -222,10 +222,13 @@ class BinaryReaderInterp : public BinaryReaderNop {
222
222
void PushLabel (IstreamOffset offset, IstreamOffset fixup_offset);
223
223
void PopLabel ();
224
224
225
- bool HandleError (Offset offset, const char * message);
225
+ bool HandleError (ErrorLevel, Offset offset, const char * message);
226
226
void PrintError (const char * format, ...);
227
227
228
228
Index TranslateSigIndexToEnv (Index sig_index);
229
+ void GetBlockSignature (Type sig_type,
230
+ TypeVector* out_param_types,
231
+ TypeVector* out_result_types);
229
232
FuncSignature* GetSignatureByModuleIndex (Index sig_index);
230
233
Index TranslateFuncIndexToEnv (Index func_index);
231
234
Index TranslateModuleFuncIndexToDefined (Index func_index);
@@ -248,7 +251,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
248
251
wabt::Result EmitI64 (uint64_t value);
249
252
wabt::Result EmitV128 (v128 value);
250
253
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);
252
255
wabt::Result AppendFixup (IstreamOffsetVectorVector* fixups_vector,
253
256
Index index);
254
257
wabt::Result EmitBrOffset (Index depth, IstreamOffset offset);
@@ -340,21 +343,36 @@ Label* BinaryReaderInterp::TopLabel() {
340
343
return GetLabel (0 );
341
344
}
342
345
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);
345
350
}
346
351
347
352
void WABT_PRINTF_FORMAT (2 , 3 ) BinaryReaderInterp::PrintError(const char * format,
348
353
...) {
349
354
WABT_SNPRINTF_ALLOCA (buffer, length, format);
350
- HandleError (kInvalidOffset , buffer);
355
+ HandleError (ErrorLevel::Error, kInvalidOffset , buffer);
351
356
}
352
357
353
358
Index BinaryReaderInterp::TranslateSigIndexToEnv (Index sig_index) {
354
359
assert (sig_index < sig_index_mapping_.size ());
355
360
return sig_index_mapping_[sig_index];
356
361
}
357
362
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
+
358
376
FuncSignature* BinaryReaderInterp::GetSignatureByModuleIndex (Index sig_index) {
359
377
return env_->GetFuncSignature (TranslateSigIndexToEnv (sig_index));
360
378
}
@@ -440,16 +458,16 @@ wabt::Result BinaryReaderInterp::EmitI32At(IstreamOffset offset,
440
458
return EmitDataAt (offset, &value, sizeof (value));
441
459
}
442
460
443
- wabt::Result BinaryReaderInterp::EmitDropKeep (uint32_t drop, uint8_t keep) {
461
+ wabt::Result BinaryReaderInterp::EmitDropKeep (uint32_t drop, uint32_t keep) {
444
462
assert (drop != UINT32_MAX);
445
- assert (keep <= 1 );
463
+ assert (keep != UINT32_MAX );
446
464
if (drop > 0 ) {
447
465
if (drop == 1 && keep == 0 ) {
448
466
CHECK_RESULT (EmitOpcode (Opcode::Drop));
449
467
} else {
450
468
CHECK_RESULT (EmitOpcode (Opcode::InterpDropKeep));
451
469
CHECK_RESULT (EmitI32 (drop));
452
- CHECK_RESULT (EmitI8 (keep));
470
+ CHECK_RESULT (EmitI32 (keep));
453
471
}
454
472
}
455
473
return wabt::Result::Ok;
@@ -482,8 +500,7 @@ wabt::Result BinaryReaderInterp::GetBrDropKeepCount(Index depth,
482
500
Index* out_keep_count) {
483
501
TypeChecker::Label* label;
484
502
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 ();
487
504
if (typechecker_.IsUnreachable ()) {
488
505
*out_drop_count = 0 ;
489
506
} else {
@@ -516,7 +533,7 @@ wabt::Result BinaryReaderInterp::EmitBrTableOffset(Index depth) {
516
533
CHECK_RESULT (GetBrDropKeepCount (depth, &drop_count, &keep_count));
517
534
CHECK_RESULT (EmitBrOffset (depth, GetLabel (depth)->offset ));
518
535
CHECK_RESULT (EmitI32 (drop_count));
519
- CHECK_RESULT (EmitI8 (keep_count));
536
+ CHECK_RESULT (EmitI32 (keep_count));
520
537
return wabt::Result::Ok;
521
538
}
522
539
@@ -545,8 +562,8 @@ wabt::Result BinaryReaderInterp::EmitFuncOffset(DefinedFunc* func,
545
562
return wabt::Result::Ok;
546
563
}
547
564
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);
550
567
}
551
568
552
569
wabt::Result BinaryReaderInterp::OnTypeCount (Index count) {
@@ -1101,7 +1118,7 @@ wabt::Result BinaryReaderInterp::BeginFunctionBody(Index index) {
1101
1118
for (Type param_type : sig->param_types )
1102
1119
func->param_and_local_types .push_back (param_type);
1103
1120
1104
- CHECK_RESULT (typechecker_.BeginFunction (& sig->result_types ));
1121
+ CHECK_RESULT (typechecker_.BeginFunction (sig->result_types ));
1105
1122
1106
1123
/* push implicit func label (equivalent to return) */
1107
1124
PushLabel (kInvalidIstreamOffset , kInvalidIstreamOffset );
@@ -1251,23 +1268,26 @@ wabt::Result BinaryReaderInterp::OnBinaryExpr(wabt::Opcode opcode) {
1251
1268
return wabt::Result::Ok;
1252
1269
}
1253
1270
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, ¶m_types, &result_types);
1274
+ CHECK_RESULT (typechecker_.OnBlock (param_types, result_types));
1257
1275
PushLabel (kInvalidIstreamOffset , kInvalidIstreamOffset );
1258
1276
return wabt::Result::Ok;
1259
1277
}
1260
1278
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, ¶m_types, &result_types);
1282
+ CHECK_RESULT (typechecker_.OnLoop (param_types, result_types));
1264
1283
PushLabel (GetIstreamOffset (), kInvalidIstreamOffset );
1265
1284
return wabt::Result::Ok;
1266
1285
}
1267
1286
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, ¶m_types, &result_types);
1290
+ CHECK_RESULT (typechecker_.OnIf (param_types, result_types));
1271
1291
CHECK_RESULT (EmitOpcode (Opcode::InterpBrUnless));
1272
1292
IstreamOffset fixup_offset = GetIstreamOffset ();
1273
1293
CHECK_RESULT (EmitI32 (kInvalidIstreamOffset ));
@@ -1347,7 +1367,7 @@ wabt::Result BinaryReaderInterp::OnBrTableExpr(Index num_targets,
1347
1367
wabt::Result BinaryReaderInterp::OnCallExpr (Index func_index) {
1348
1368
Func* func = GetFuncByModuleIndex (func_index);
1349
1369
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 ));
1351
1371
1352
1372
if (func->is_host ) {
1353
1373
CHECK_RESULT (EmitOpcode (Opcode::InterpCallHost));
@@ -1367,7 +1387,7 @@ wabt::Result BinaryReaderInterp::OnCallIndirectExpr(Index sig_index) {
1367
1387
}
1368
1388
FuncSignature* sig = GetSignatureByModuleIndex (sig_index);
1369
1389
CHECK_RESULT (
1370
- typechecker_.OnCallIndirect (& sig->param_types , & sig->result_types ));
1390
+ typechecker_.OnCallIndirect (sig->param_types , sig->result_types ));
1371
1391
1372
1392
CHECK_RESULT (EmitOpcode (Opcode::CallIndirect));
1373
1393
CHECK_RESULT (EmitI32 (module_->table_index ));
@@ -1483,14 +1503,6 @@ wabt::Result BinaryReaderInterp::OnTeeLocalExpr(Index local_index) {
1483
1503
return wabt::Result::Ok;
1484
1504
}
1485
1505
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
-
1494
1506
wabt::Result BinaryReaderInterp::OnLoadExpr (wabt::Opcode opcode,
1495
1507
uint32_t alignment_log2,
1496
1508
Address offset) {
@@ -1515,10 +1527,18 @@ wabt::Result BinaryReaderInterp::OnStoreExpr(wabt::Opcode opcode,
1515
1527
return wabt::Result::Ok;
1516
1528
}
1517
1529
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));
1522
1542
CHECK_RESULT (EmitI32 (module_->memory_index ));
1523
1543
return wabt::Result::Ok;
1524
1544
}
0 commit comments