This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::string toString(bool b) | |
{ | |
return b ? "true" : "false"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std::string foo{ "foo" }; | |
const auto bar{ 20. }; | |
const auto baz{ 6 }; | |
logger.info("Foo: {}, bar: {}, baz: {}", foo, bar, baz); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <regex> | |
template<size_t ...values> | |
struct values_container | |
{}; | |
namespace details | |
{ | |
template <typename value_type, typename Is> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main: | |
mov eax, 610 | |
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "string.hpp" | |
#include "execute.hpp" | |
using code = decltype( | |
"mov ebp , esp " | |
"push eax " // declare four variables | |
"push eax " | |
"push eax " | |
"push eax " | |
"mov DWORD PTR [ ebp + 8 ] , 0 " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename stack_type, typename flags_type, typename registers_state_type> | |
struct machine_state | |
{ | |
using stack_t = stack_type; | |
using flags_t = flags_type; | |
using registers_state_t = registers_state_type; | |
static constexpr to_flags<flags_t> flags{}; | |
static constexpr to_register_state <registers_state_t> reg_state{}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename code> | |
struct prepare_and_execute | |
{ | |
using tokens = tokenize<code>; | |
using extract_labels_result = extract_labels<tokens>; | |
using tokens_without_labels = typename extract_labels_result::tokens; | |
using labels_metadata = typename extract_labels_result::labels; | |
using tokens_after_labels_substitution = substutite_labels<tokens_without_labels, labels_metadata>; | |
using opcodes = assemble<tokens_after_labels_substitution>; | |
using machine_state = startup_machine_state; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename state_t, size_t ip, size_t ...rest_of_opcodes> | |
struct ex_instruction<state_t, inst::to_size<inst::id_t::JGE>, ip, rest_of_opcodes...> | |
{ | |
using state = to_machine_state<state_t>; | |
static constexpr auto flags_v = typename state::flags_t{}; | |
static constexpr bool should_jmp = ((static_cast<int>(flags_v.SF) ^ static_cast<int>(flags_v.OF)) == 0); | |
using final_regs_state = std::conditional_t< | |
should_jmp, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename state_t, size_t reg1, size_t val, size_t ...rest_of_opcodes> | |
struct ex_instruction<state_t, inst::to_size<inst::id_t::MOV_REG_VAL>, reg1, val, rest_of_opcodes...> | |
{ | |
using state = to_machine_state<state_t>; | |
using new_regs_state = set_reg<typename state::registers_state_t, regs::to_id<reg1>, static_cast<uint32_t>(val)>; | |
using final_regs_state = adjust_eip<new_regs_state, inst::id_t::MOV_REG_VAL>; | |
using next_machine_state = machine_state<typename state::stack_t, typename state::flags_t, final_regs_state>; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename state, size_t ...opcodes> | |
struct ex_instruction; |