Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,22 +250,10 @@ int predict_block_size(ProgramBlock* block)
case TerminatorType::JUMP:
return bytecode_length + JMP_SIZE; // finalized with jump
case TerminatorType::JUMP_IF: {
// if boolean condition is not set adding SET_8 instruction to the bytecode
// if boolean condition is not set add SET instruction to the bytecode
if (!block->get_terminating_condition_value().has_value()) {
for (uint16_t address = 0; address < 65535; address++) {
// if the memory address is already in use, we skip it
if (block->is_memory_address_set(address)) {
continue;
}
auto set_16_instruction =
SET_16_Instruction{ .value_tag = bb::avm2::MemoryTag::U1,
.result_address =
AddressRef{ .address = address, .mode = AddressingMode::Direct },
.value = 0 };
block->process_instruction(set_16_instruction);
bytecode_length = static_cast<int>(create_bytecode(block->get_instructions()).size());
break;
}
block->process_write_terminating_condition_value();
bytecode_length = static_cast<int>(create_bytecode(block->get_instructions()).size());
}
return bytecode_length + JMP_IF_SIZE + JMP_SIZE; // finalized with jumpi
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,15 @@ std::optional<uint16_t> ProgramBlock::get_terminating_condition_value()
return condition_addr;
}

void ProgramBlock::process_write_terminating_condition_value()
{
uint16_t value = condition_offset_index % 2;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

process_set_16_instruction(SET_16_Instruction{
.value_tag = bb::avm2::MemoryTag::U1,
.result_address = AddressRef{ .address = condition_offset_index, .mode = AddressingMode::Direct },
.value = value });
}

bool ProgramBlock::is_memory_address_set(uint16_t address)
{
return memory_manager.is_memory_address_set(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class ProgramBlock {
void insert_internal_call(ProgramBlock* target_block);

std::optional<uint16_t> get_terminating_condition_value();
void process_write_terminating_condition_value();
std::vector<bb::avm2::simulation::Instruction> get_instructions();

bool is_memory_address_set(uint16_t address);
Expand Down
Loading