Skip to content

Commit

Permalink
Use instruction metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Jun 2, 2020
1 parent f428497 commit 63ea7b0
Showing 1 changed file with 1 addition and 35 deletions.
36 changes: 1 addition & 35 deletions lib/fizzy/parser_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,45 +618,11 @@ parser_result<Code> parse_expr(
case Instr::i64_store16:
case Instr::i64_store32:
{
size_t width = 0;
switch (instr)
{
case Instr::i32_load8_s:
case Instr::i32_load8_u:
case Instr::i64_load8_s:
case Instr::i64_load8_u:
case Instr::i32_store8:
case Instr::i64_store8:
width = 8;
break;
case Instr::i32_load16_s:
case Instr::i32_load16_u:
case Instr::i64_load16_s:
case Instr::i64_load16_u:
case Instr::i32_store16:
case Instr::i64_store16:
width = 16;
break;
case Instr::i32_load:
case Instr::i32_store:
case Instr::i64_load32_s:
case Instr::i64_load32_u:
case Instr::i64_store32:
width = 32;
break;
case Instr::i64_load:
case Instr::i64_store:
width = 64;
break;
default:
break;
}

// alignment
uint32_t align;
std::tie(align, pos) = leb128u_decode<uint32_t>(pos, end);
// NOTE: align > 4 is the hard limit (64 / 8) >> 1, and checking it to avoid overflows
if ((align > 4) || ((1 << align) > (width / 8)))
if ((align > 4) || ((1 << align) > metrics.memory_width))
throw validation_error{"alignment cannot exceed operand size"};

// offset
Expand Down

0 comments on commit 63ea7b0

Please sign in to comment.