Skip to content

Commit

Permalink
Attempt at removing virtual in the interpreter by using a templated i…
Browse files Browse the repository at this point in the history
…nterpreter function

This way the concolic and concrete engines can continue to run at full speed without virtual function calls for every instruction.
  • Loading branch information
MaartenS11 committed Jan 6, 2025
1 parent 2222a37 commit 4cf34fc
Show file tree
Hide file tree
Showing 7 changed files with 421 additions and 393 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ option(BUILD_ESP "Build for esp" OFF)
option(BUILD_EMULATOR "Build for emulator" OFF)
option(BUILD_UNITTEST "Build for testing" OFF)

include_directories(/usr/include/z3)

if (ESP_PLATFORM)
set(BUILD_ESP ON)
endif ()
Expand Down Expand Up @@ -95,7 +97,8 @@ if (BUILD_UNITTEST)
src/Debug/debugger.cpp
src/Edward/proxy.cpp
src/Edward/proxy_supervisor.cpp
src/Edward/RFC.cpp)
src/Edward/RFC.cpp
src/Interpreter/interp_loop.h)

# Use C++11
set(CMAKE_CXX_STANDARD 11)
Expand Down
5 changes: 5 additions & 0 deletions src/Interpreter/concolic_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "../Utils/macros.h"
#include "../Utils/util.h"
#include "interp_loop.h"

// TODO: Try reuse code from the concrete interpreter
Block *ConcolicInterpreter::pop_block(Module *m) {
Expand Down Expand Up @@ -789,4 +790,8 @@ bool ConcolicInterpreter::i_instr_conversion(Module *m, uint8_t opcode) {

return true;
}

bool ConcolicInterpreter::interpret(Module *m, bool waiting) {
return interp<ConcolicInterpreter>(m , waiting);
}
#endif
57 changes: 29 additions & 28 deletions src/Interpreter/concolic_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,39 @@

class ConcolicInterpreter : public Interpreter {
public:
Block *pop_block(Module *m) override;
void setup_call(Module *m, uint32_t fidx) override;
Block *pop_block(Module *m);
void setup_call(Module *m, uint32_t fidx);

static z3::expr encode_as_symbolic(Module *m, StackValue *stack_value);

private:
void load(Module *m, uint32_t offset, uint32_t addr, int size,
uint8_t value_type, bool sign_extend) override;
uint8_t value_type, bool sign_extend);
void store(Module *m, uint32_t offset, uint32_t addr, int value_sp,
int size) override;
int size);

bool i_instr_if(Module *m, uint8_t *block_ptr) override;
bool i_instr_br_if(Module *m) override;
bool i_instr_select(Module *m) override;
bool i_instr_get_local(Module *m) override;
bool i_instr_set_local(Module *m) override;
bool i_instr_tee_local(Module *m) override;
bool i_instr_get_global(Module *m) override;
bool i_instr_set_global(Module *m) override;
bool i_instr_current_memory(Module *m) override;
bool i_instr_const(Module *m, uint8_t opcode) override;
bool i_instr_unary_u32(Module *m, uint8_t opcode) override;
bool i_instr_math_u32(Module *m, uint8_t opcode) override;
bool i_instr_math_u64(Module *m, uint8_t opcode) override;
bool i_instr_math_f32(Module *m, uint8_t opcode) override;
bool i_instr_math_f64(Module *m, uint8_t opcode) override;
bool i_instr_unary_i32(Module *m, uint8_t opcode) override;
bool i_instr_unary_i64(Module *m, uint8_t opcode) override;
bool i_instr_unary_floating(Module *m, uint8_t opcode) override;
bool i_instr_binary_i32(Module *m, uint8_t opcode) override;
bool i_instr_binary_i64(Module *m, uint8_t opcode) override;
bool i_instr_binary_f32(Module *m, uint8_t opcode) override;
bool i_instr_binary_f64(Module *m, uint8_t opcode) override;
bool i_instr_conversion(Module *m, uint8_t opcode) override;
bool i_instr_if(Module *m, uint8_t *block_ptr);
bool i_instr_br_if(Module *m);
bool i_instr_select(Module *m);
bool i_instr_get_local(Module *m);
bool i_instr_set_local(Module *m);
bool i_instr_tee_local(Module *m);
bool i_instr_get_global(Module *m);
bool i_instr_set_global(Module *m);
bool i_instr_current_memory(Module *m);
bool i_instr_const(Module *m, uint8_t opcode);
bool i_instr_unary_u32(Module *m, uint8_t opcode);
bool i_instr_math_u32(Module *m, uint8_t opcode);
bool i_instr_math_u64(Module *m, uint8_t opcode);
bool i_instr_math_f32(Module *m, uint8_t opcode);
bool i_instr_math_f64(Module *m, uint8_t opcode);
bool i_instr_unary_i32(Module *m, uint8_t opcode);
bool i_instr_unary_i64(Module *m, uint8_t opcode);
bool i_instr_unary_floating(Module *m, uint8_t opcode);
bool i_instr_binary_i32(Module *m, uint8_t opcode);
bool i_instr_binary_i64(Module *m, uint8_t opcode);
bool i_instr_binary_f32(Module *m, uint8_t opcode);
bool i_instr_binary_f64(Module *m, uint8_t opcode);
bool i_instr_conversion(Module *m, uint8_t opcode);

bool interpret(Module *m, bool waiting) override;
};
Loading

0 comments on commit 4cf34fc

Please sign in to comment.