Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ControlFlow Class Reference

#include <control_flow.hpp>

Public Member Functions

 ControlFlow (std::vector< std::vector< FuzzInstruction > > &instruction_blocks)
 
 ~ControlFlow ()
 
void process_cfg_instruction (CFGInstruction instruction)
 
std::vector< uint8_t > build_bytecode (const ReturnOptions &return_options)
 build the bytecode, finalizing the current block with return
 

Private Member Functions

void process_insert_simple_instruction_block (InsertSimpleInstructionBlock instruction)
 add instructions to the current block from the instruction block at the given index taken modulo length of the instruction blocks vector
 
void process_jump_to_new_block (JumpToNewBlock instruction)
 terminates the current block with a jump and creates a new block
 
void process_jump_if_to_new_block (JumpIfToNewBlock instruction)
 terminates the current block with a jump if and creates two new blocks, sets the first as the then block and the second as the else block, changes the current block to the then block
 
void process_jump_to_block (JumpToBlock instruction)
 terminates the current block with a jump to the block, which does not create a loop in the graph (defined by get_reachable_blocks) and switches the current block to the first block defined by get_non_terminated_blocks
 
void process_jump_if_to_block (JumpIfToBlock instruction)
 terminates the current block with a jumpi and jump instructions to the blocks, which does not create a loop in the graph (defined by get_reachable_blocks) and switches the current block to the first block defined by get_non_terminated_blocks
 
void process_finalize_with_return (FinalizeWithReturn instruction)
 terminates the current block with Return and switches to the first non-terminated block
 
void process_switch_to_non_terminated_block (SwitchToNonTerminatedBlock instruction)
 switches to the non-terminated block with the chosen index
 
void process_insert_internal_call (InsertInternalCall instruction)
 inserts INTERNALCALL instruction to the current block creates a new block and sets it as the current block
 
std::vector< ProgramBlock * > get_non_terminated_blocks ()
 get the list of non-terminated blocks
 
std::vector< ProgramBlock * > get_reachable_blocks (ProgramBlock *block)
 get the list of blocks which are can be reached from the given block without creating a loop in the graph Also filters out blocks with different caller
 

Static Private Member Functions

static std::vector< ProgramBlock * > dfs_traverse (ProgramBlock *start_block, bool reverse=false)
 traverse the control flow graph using DFS
 

Private Attributes

ProgramBlockcurrent_block
 
ProgramBlockstart_block
 the entry block of the program
 
std::vector< std::vector< FuzzInstruction > > * instruction_blocks
 

Detailed Description

Definition at line 126 of file control_flow.hpp.

Constructor & Destructor Documentation

◆ ControlFlow()

ControlFlow::ControlFlow ( std::vector< std::vector< FuzzInstruction > > &  instruction_blocks)
inline

Definition at line 188 of file control_flow.hpp.

◆ ~ControlFlow()

ControlFlow::~ControlFlow ( )
inline

Definition at line 194 of file control_flow.hpp.

Member Function Documentation

◆ build_bytecode()

std::vector< uint8_t > ControlFlow::build_bytecode ( const ReturnOptions return_options)

build the bytecode, finalizing the current block with return

Definition at line 283 of file control_flow.cpp.

◆ dfs_traverse()

std::vector< ProgramBlock * > ControlFlow::dfs_traverse ( ProgramBlock start_block,
bool  reverse = false 
)
staticprivate

traverse the control flow graph using DFS

Parameters
start_blockthe start block
reversewhether to traverse in reverse order. If true, the traversal will go to the predecessors of the current block, otherwise to the successors.
Returns
the list of blocks in the order of traversal

Definition at line 3 of file control_flow.cpp.

◆ get_non_terminated_blocks()

std::vector< ProgramBlock * > ControlFlow::get_non_terminated_blocks ( )
private

get the list of non-terminated blocks

Definition at line 173 of file control_flow.cpp.

◆ get_reachable_blocks()

std::vector< ProgramBlock * > ControlFlow::get_reachable_blocks ( ProgramBlock block)
private

get the list of blocks which are can be reached from the given block without creating a loop in the graph Also filters out blocks with different caller

Definition at line 183 of file control_flow.cpp.

◆ process_cfg_instruction()

void ControlFlow::process_cfg_instruction ( CFGInstruction  instruction)

Definition at line 205 of file control_flow.cpp.

◆ process_finalize_with_return()

void ControlFlow::process_finalize_with_return ( FinalizeWithReturn  instruction)
private

terminates the current block with Return and switches to the first non-terminated block

Note
if the current block has caller, it inserts INTERNALRETURN only and switches to the caller
Parameters
instructionthe instruction to process

Definition at line 129 of file control_flow.cpp.

◆ process_insert_internal_call()

void ControlFlow::process_insert_internal_call ( InsertInternalCall  instruction)
private

inserts INTERNALCALL instruction to the current block creates a new block and sets it as the current block

Parameters
instructionthe instruction to process

Definition at line 157 of file control_flow.cpp.

◆ process_insert_simple_instruction_block()

void ControlFlow::process_insert_simple_instruction_block ( InsertSimpleInstructionBlock  instruction)
private

add instructions to the current block from the instruction block at the given index taken modulo length of the instruction blocks vector

Definition at line 32 of file control_flow.cpp.

◆ process_jump_if_to_block()

void ControlFlow::process_jump_if_to_block ( JumpIfToBlock  instruction)
private

terminates the current block with a jumpi and jump instructions to the blocks, which does not create a loop in the graph (defined by get_reachable_blocks) and switches the current block to the first block defined by get_non_terminated_blocks

Parameters
instructionthe instruction to process

Definition at line 107 of file control_flow.cpp.

◆ process_jump_if_to_new_block()

void ControlFlow::process_jump_if_to_new_block ( JumpIfToNewBlock  instruction)
private

terminates the current block with a jump if and creates two new blocks, sets the first as the then block and the second as the else block, changes the current block to the then block

Parameters
instructionthe instruction to process

Definition at line 64 of file control_flow.cpp.

◆ process_jump_to_block()

void ControlFlow::process_jump_to_block ( JumpToBlock  instruction)
private

terminates the current block with a jump to the block, which does not create a loop in the graph (defined by get_reachable_blocks) and switches the current block to the first block defined by get_non_terminated_blocks

Parameters
instructionthe instruction to process

Definition at line 88 of file control_flow.cpp.

◆ process_jump_to_new_block()

void ControlFlow::process_jump_to_new_block ( JumpToNewBlock  instruction)
private

terminates the current block with a jump and creates a new block

Parameters
instructionthe instruction to process

Definition at line 46 of file control_flow.cpp.

◆ process_switch_to_non_terminated_block()

void ControlFlow::process_switch_to_non_terminated_block ( SwitchToNonTerminatedBlock  instruction)
private

switches to the non-terminated block with the chosen index

Parameters
instructionthe instruction to process

Definition at line 148 of file control_flow.cpp.

Member Data Documentation

◆ current_block

ProgramBlock* ControlFlow::current_block
private

Definition at line 128 of file control_flow.hpp.

◆ instruction_blocks

std::vector<std::vector<FuzzInstruction> >* ControlFlow::instruction_blocks
private

Definition at line 131 of file control_flow.hpp.

◆ start_block

ProgramBlock* ControlFlow::start_block
private

the entry block of the program

Definition at line 130 of file control_flow.hpp.


The documentation for this class was generated from the following files: