Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bytecode_builder.cpp
Go to the documentation of this file.
2
4
6
9
11{
12 const auto serialized = instruction.serialize();
13 bytecode.insert(bytecode.end(), serialized.begin(), serialized.end());
14 return *this;
15}
16
18{
19 bytecode.insert(bytecode.end(), bytes.begin(), bytes.end());
20 return *this;
21}
22
23std::vector<uint8_t> encode_to_bytecode(const std::vector<Instruction>& instructions)
24{
26 for (const auto& instruction : instructions) {
28 }
29 return builder.build();
30}
31
33{
34 const auto& wire_format = simulation::testonly::get_instruction_wire_formats().at(opcode);
35 const auto& operand_sizes = simulation::testonly::get_operand_type_sizes();
36
37 // The serialized instruction starts with the 1-byte opcode, followed by the operands laid
38 // out in wire-format order (the addressing-mode byte is the first INDIRECT operand).
39 size_t offset = 1;
40 for (const auto& operand_type : wire_format) {
41 if (operand_type == OperandType::TAG) {
42 return offset;
43 }
44 offset += operand_sizes.at(operand_type);
45 }
46 BB_ASSERT(false, "Wire format for opcode has no TAG operand");
47 return offset;
48}
49
50} // namespace bb::avm2::testing
#define BB_ASSERT(expression,...)
Definition assert.hpp:70
std::vector< uint8_t > build() const
BytecodeBuilder & add(const simulation::Instruction &instruction)
BytecodeBuilder & add_raw(std::span< const uint8_t > bytes)
AluTraceBuilder builder
Definition alu.test.cpp:124
ssize_t offset
Definition engine.cpp:62
Instruction instruction
const std::unordered_map< OperandType, uint32_t > & get_operand_type_sizes()
const std::unordered_map< WireOpCode, std::vector< OperandType > > & get_instruction_wire_formats()
size_t tag_byte_offset(WireOpCode opcode)
std::vector< uint8_t > encode_to_bytecode(const std::vector< Instruction > &instructions)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13