Skip to content

Commit

Permalink
Try using bytes instead of vector<uint8_t>
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Oct 23, 2020
1 parent d3f0e65 commit f365586
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions lib/fizzy/parser_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ inline void store(uint8_t* dst, T value) noexcept
}

template <typename T>
inline void push(std::vector<uint8_t>& b, T value)
inline void push(bytes& b, T value)
{
uint8_t storage[sizeof(T)];
store(storage, value);
Expand Down Expand Up @@ -198,8 +198,7 @@ inline void update_branch_stack(const ControlFrame& current_frame, const Control
drop_operand(current_frame, operand_stack, from_valtype(*branch_frame_type));
}

void push_branch_immediates(
const ControlFrame& branch_frame, int stack_height, std::vector<uint8_t>& instructions)
void push_branch_immediates(const ControlFrame& branch_frame, int stack_height, bytes& instructions)
{
// How many stack items to drop when taking the branch.
const auto stack_drop = stack_height - branch_frame.parent_stack_height;
Expand Down Expand Up @@ -872,7 +871,7 @@ parser_result<Code> parse_expr(const uint8_t* pos, const uint8_t* end, FuncIdx f
break;
}
}
code.instructions.emplace_back(opcode);
code.instructions.push_back(opcode);
}
assert(control_stack.empty());
return {code, pos};
Expand Down
2 changes: 1 addition & 1 deletion lib/fizzy/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ struct Code

// The instructions bytecode without immediate values.
// https://webassembly.github.io/spec/core/binary/instructions.html
std::vector<uint8_t> instructions;
bytes instructions;
};

/// The reference to the `code` in the wasm binary.
Expand Down
4 changes: 2 additions & 2 deletions test/unittests/execute_death_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ TEST(execute_death, malformed_instruction_opcode)
constexpr uint8_t malformed_opcode = 6;

Code code;
code.instructions.emplace_back(malformed_opcode);
code.instructions.emplace_back(static_cast<uint8_t>(Instr::end));
code.instructions.push_back(malformed_opcode);
code.instructions.push_back(static_cast<uint8_t>(Instr::end));

auto module = std::make_unique<Module>();
module->typesec.emplace_back(FuncType{});
Expand Down

0 comments on commit f365586

Please sign in to comment.