MXVM 1.8.1
Virtual Machine, Compiler, and Pascal Frontend
Loading...
Searching...
No Matches
mxvm::Program Class Reference

Complete MXVM program: instruction interpreter and native x64 code generator. More...

#include <icode.hpp>

Inheritance diagram for mxvm::Program:

Public Member Functions

 Program ()
 Default constructor — initializes execution state (pc, flags, etc.).
 ~Program ()
 Destructor — frees any heap-allocated variables.
 Program (Program &&other) noexcept
 Move constructor — transfers all execution state and child objects.
Program & operator= (Program &&other) noexcept
 Move-assignment operator.
void add_standard ()
 Register standard library runtime functions.
void stop ()
 Halt the interpreter loop.
int exec ()
 Execute the program via the interpreter.
void print (std::ostream &out)
 Print all instructions and data to an output stream.
void post (std::ostream &out)
 Generate native data section (variable declarations) into the output stream.
int getExitCode () const
 Get the program's exit code after execution.
std::string getPlatformSymbolName (const std::string &name)
 Mangle a symbol name with the platform prefix (e.g. _name for Darwin).
void generateCode (const Platform &platform, bool obj, std::ostream &out)
 Generate native x64 assembly for the entire program.
void memoryDump (std::ostream &out)
 Dump all variable values to a stream for debugging.
void setArgs (const std::vector< std::string > &argv)
 Set the command-line arguments available to the program.
void setObject (bool obj)
 Mark this program as an object (no main entry point).
bool validateNames (Validator &v)
 Validate all variable and label names against the Validator.
void flatten (Program *program)
 Flatten child object programs into the root instruction stream.
void flatten_inc (Program *root, Instruction &i)
 Rewrite object-qualified operand references in a single instruction.
void flatten_label (Program *root, int64_t offset, const std::string &label, bool func)
 Copy a label from a child object into the root label map with an address offset.
void flatten_external (Program *root, const std::string &e, RuntimeFunction &r)
 Copy an external function binding from a child object into the root.
std::string getMangledName (const std::string &var)
 Mangle a variable name with its owning object prefix.
std::string getMangledName (const Operand &op)
 Mangle an operand's variable reference with its object prefix.
Program * getObjectByName (const std::string &name)
 Look up a child object program by name.
bool isFunctionValid (const std::string &label)
 Check whether a label exists and is marked as a function entry.
size_t x64_reserve_call_area (std::ostream &out, size_t spill_bytes)
 Reserve stack space for a Win64 call frame including spill area.
void x64_release_call_area (std::ostream &out, size_t frame)
 Release a Win64 call frame previously reserved.
void x64_direct_stack_adjust (std::ostream &out, int64_t bytes)
 Emit a direct stack pointer adjustment.
System V ABI (Linux/macOS) x86-64 code generation
void generateFunctionCall (std::ostream &out, const std::string &name, std::vector< Operand > &op)
 Generate a System V ABI function call with operands as arguments.
void generateInvokeCall (std::ostream &out, std::vector< Operand > &op)
 Generate a dynamic invoke call (runtime-resolved external function).
void generateInstruction (std::ostream &out, const Instruction &i)
 Dispatch a single instruction to its System V code generator.
int generateLoadVar (std::ostream &out, int reg, const Operand &op)
 Load a variable or constant into a numbered register.
int generateLoadVar (std::ostream &out, VarType type, std::string reg, const Operand &op)
 Load a variable or constant into a named register.
std::string getRegisterByIndex (int index, VarType type)
 Get the register name for a given index and variable type.
void gen_print (std::ostream &out, const Instruction &i)
void gen_arth (std::ostream &out, std::string arth, const Instruction &i)
void gen_exit (std::ostream &out, const Instruction &i)
void gen_mov (std::ostream &out, const Instruction &i)
void gen_jmp (std::ostream &out, const Instruction &i)
void gen_cmp (std::ostream &out, const Instruction &i)
void gen_alloc (std::ostream &out, const Instruction &i)
void gen_realloc (std::ostream &out, const Instruction &i)
 Generate System V x86-64 assembly for the REALLOC instruction (dynamic array resize).
void gen_free (std::ostream &out, const Instruction &i)
void gen_load (std::ostream &out, const Instruction &i)
void gen_store (std::ostream &out, const Instruction &i)
void gen_ret (std::ostream &out, const Instruction &i)
void gen_call (std::ostream &out, const Instruction &i)
void gen_done (std::ostream &out, const Instruction &i)
void gen_bitop (std::ostream &out, const std::string &opc, const Instruction &i)
void gen_not (std::ostream &out, const Instruction &i)
void gen_push (std::ostream &out, const Instruction &i)
 Emit x86-64 PUSH for a variable or constant.
void gen_pop (std::ostream &out, const Instruction &i)
 Emit x86-64 POP into a variable.
void gen_stack_load (std::ostream &out, const Instruction &i)
void gen_stack_store (std::ostream &out, const Instruction &i)
void gen_stack_sub (std::ostream &out, const Instruction &i)
void gen_getline (std::ostream &out, const Instruction &i)
void gen_to_int (std::ostream &out, const Instruction &i)
void gen_to_float (std::ostream &out, const Instruction &i)
void gen_invoke (std::ostream &out, const Instruction &i)
void gen_return (std::ostream &out, const Instruction &i)
void gen_neg (std::ostream &out, const Instruction &i)
void gen_lea (std::ostream &out, const Instruction &i)
void gen_fcmp (std::ostream &out, const Instruction &i)
void gen_jae (std::ostream &out, const Instruction &i)
void gen_jbe (std::ostream &out, const Instruction &i)
void gen_jc (std::ostream &out, const Instruction &i)
void gen_jnc (std::ostream &out, const Instruction &i)
void gen_jp (std::ostream &out, const Instruction &i)
void gen_jnp (std::ostream &out, const Instruction &i)
void gen_jo (std::ostream &out, const Instruction &i)
void gen_jno (std::ostream &out, const Instruction &i)
void gen_js (std::ostream &out, const Instruction &i)
void gen_jns (std::ostream &out, const Instruction &i)
void gen_add (std::ostream &out, const Instruction &i)
void gen_sub (std::ostream &out, const Instruction &i)
void gen_mul (std::ostream &out, const Instruction &i)
void gen_div (std::ostream &out, const Instruction &i)
void gen_mod (std::ostream &out, const Instruction &i)
std::string gen_optimize (const std::string &code, const Platform &platform)
 Peephole optimizer for generated assembly.
std::string optimize_darwin (const std::string &code)
 Darwin-specific assembly optimizations.
std::string optimize_core (const std::string &code)
 Platform-independent peephole optimizations.
Interpreter execution methods
void exec_mov (const Instruction &instr)
void exec_add (const Instruction &instr)
void exec_sub (const Instruction &instr)
void exec_mul (const Instruction &instr)
void exec_div (const Instruction &instr)
void exec_cmp (const Instruction &instr)
void exec_jmp (const Instruction &instr)
void exec_load (const Instruction &instr)
void exec_store (const Instruction &instr)
 Execute a STORE instruction — write a value into a pointer at a given offset.
void exec_or (const Instruction &instr)
void exec_and (const Instruction &instr)
void exec_xor (const Instruction &instr)
void exec_not (const Instruction &instr)
void exec_mod (const Instruction &instr)
void exec_je (const Instruction &instr)
void exec_jne (const Instruction &instr)
void exec_jl (const Instruction &instr)
void exec_jle (const Instruction &instr)
void exec_jg (const Instruction &instr)
void exec_jge (const Instruction &instr)
void exec_jz (const Instruction &instr)
void exec_jnz (const Instruction &instr)
void exec_ja (const Instruction &instr)
void exec_jb (const Instruction &instr)
void exec_print (const Instruction &instr)
void exec_string_print (const Instruction &instr)
void exec_exit (const Instruction &instr)
void exec_alloc (const Instruction &instr)
void exec_free (const Instruction &instr)
void exec_getline (const Instruction &instr)
void exec_push (const Instruction &instr)
 Execute a PUSH instruction — save a variable or constant onto the VM stack.
void exec_pop (const Instruction &instr)
 Execute a POP instruction — restore a value from the VM stack into a variable.
void exec_stack_load (const Instruction &instr)
void exec_stack_store (const Instruction &instr)
void exec_stack_sub (const Instruction &instr)
void exec_call (const Instruction &instr)
void exec_ret (const Instruction &instr)
void exec_done (const Instruction &instr)
void exec_to_int (const Instruction &instr)
void exec_to_float (const Instruction &instr)
void exec_invoke (const Instruction &instr)
void exec_return (const Instruction &instr)
void exec_lea (const Instruction &instr)
void exec_neg (const Instruction &instr)
void exec_realloc (const Instruction &instr)
 Execute the REALLOC instruction in the interpreter.
void exec_fcmp (const Instruction &instr)
void exec_jae (const Instruction &instr)
void exec_jbe (const Instruction &instr)
void exec_jc (const Instruction &instr)
void exec_jnc (const Instruction &instr)
void exec_jp (const Instruction &instr)
void exec_jnp (const Instruction &instr)
void exec_jo (const Instruction &instr)
void exec_jno (const Instruction &instr)
void exec_js (const Instruction &instr)
void exec_jns (const Instruction &instr)
Interpreter helper methods
Variable & getVariable (const std::string &name)
 Look up a variable by name, searching local scope then global.
bool isVariable (const std::string &name)
 Check whether a variable exists in local or global scope.
void setVariableFromString (Variable &var, const std::string &value)
 Set a variable's value from a string representation, coercing types.
void addVariables (Variable &dest, Variable &src1, Variable &src2)
 Add two variables and store the result in dest.
void subVariables (Variable &dest, Variable &src1, Variable &src2)
 Subtract src2 from src1 and store the result in dest.
void mulVariables (Variable &dest, Variable &src1, Variable &src2)
 Multiply two variables and store the result in dest.
void divVariables (Variable &dest, Variable &src1, Variable &src2)
 Divide src1 by src2 and store the result in dest.
std::string printFormatted (const std::string &format, const std::vector< Variable * > &args, bool output=true)
 Format and optionally print a printf-style format string with variable arguments.
void setVariableFromConstant (Variable &var, const std::string &value)
 Set a variable's value from a constant string (integer, float, or string literal).
Variable createTempVariable (VarType type, const std::string &value)
 Create a temporary unnamed variable with the given type and value.
bool isConstant (const std::string &value)
 Check whether a string represents a compile-time constant (number or quoted string).
Variable variableFromOperand (const Operand &op)
 Resolve an Operand to its corresponding Variable.
Public Member Functions inherited from mxvm::Base
 Base ()=default
 Base (Base &&other) noexcept
 Move constructor.
 ~Base ()=default
Base & operator= (Base &&other) noexcept
 Move-assignment operator.
void setMainBase (Base *b)
 Set the root program base pointer (used for global variable lookup).
void add_instruction (const Instruction &i)
 Append an instruction to the instruction stream.
void add_label (const std::string &name, uint64_t address, bool f)
 Register a label at the given instruction address.
void add_variable (const std::string &name, const Variable &v)
 Declare a local variable in the symbol table.
void add_global (const std::string &objname, const std::string &name, const Variable &v)
 Declare a global variable scoped to an object.
void add_extern (const std::string &mod, const std::string &name, bool module)
 Register an external function import.
void add_runtime_extern (const std::string &mod_name, const std::string &mod, const std::string &func_name, const std::string &name)
 Register and resolve a runtime-loaded external function.
void add_filename (const std::string &fname)
 Record a source filename for debug/error reporting.
void add_allocated (const std::string &name, Variable &v)
 Track a heap-allocated variable for cleanup.
void add_object (const std::string &name, Program *prog)
 Register a child object program.

Static Public Member Functions

static std::string escapeNewLines (const std::string &text)
 Escape newline characters in a string literal for assembly output.

Public Attributes

std::string name
std::string filename
std::vector< std::unique_ptr< Program > > objects
bool object = false
Stack stack
Operand result
 return value operand from last invoke
Program * parent = nullptr
 parent program (for object programs)
Platform platform
bool last_call_returns_owned = false
VarType last_call_ret_type = VarType::VAR_INTEGER
Public Attributes inherited from mxvm::Base
std::string name
std::vector< Instruction > inc
 instruction stream
std::unordered_map< std::string, Variable > vars
 variable symbol table
std::unordered_map< std::string, std::pair< uint64_t, bool > > labels
 label -> (address, is_function)
std::vector< ExternalFunction > external
 declared external function imports
std::unordered_map< std::string, RuntimeFunction > external_functions
 resolved runtime function bindings
std::string assembly_code
 generated assembly output for objects

Private Types

enum  LastCmpType { CMP_NONE , CMP_INTEGER , CMP_FLOAT }
 Tracks type of last comparison for conditional jumps. More...

Private Attributes

size_t pc
 program counter
bool running
 interpreter running flag
int exitCode = 0
bool zero_flag = false
 comparison zero flag
bool less_flag = false
 comparison less-than flag
bool greater_flag = false
 comparison greater-than flag
bool carry_flag = false
 comparison carry flag
int xmm_offset = 0
 current XMM register allocation offset
std::vector< std::string > args
bool main_function
 true if this program has a main entry point
bool object_external = false
LastCmpType last_cmp_type = CMP_NONE
bool last_call_returns_owned_ptr = false
 tracks ownership of last call's return value

Friends

class Parser

Win64 ABI x86-64 code generation

std::unordered_map< std::string, std::string > x64_reg_vars
 Win64 variable-to-register mapping.
std::vector< std::string > x64_reg_save_order
void x64_emit_iob_func (std::ostream &out, int index, const std::string &dstReg)
 Emit an integer-or-byte function argument load for Win64 ABI.
std::string x64_getRegisterByIndex (int index, VarType type)
 Get the Win64 register name for a given index and variable type.
int x64_generateLoadVar (std::ostream &out, int r, const Operand &op)
 Load a variable or constant into a numbered Win64 register.
int x64_generateLoadVar (std::ostream &out, VarType type, std::string reg, const Operand &op)
 Load a variable or constant into a named Win64 register.
void x64_generateFunctionCall (std::ostream &out, const std::string &name, std::vector< Operand > &args)
 Generate a Win64 ABI function call with operands as arguments.
void x64_generateInvokeCall (std::ostream &out, std::vector< Operand > &op)
 Generate a Win64 dynamic invoke call.
void x64_generateCode (const Platform &platform, bool obj, std::ostream &out)
 Top-level Win64 code generation entry point.
void x64_generateInstruction (std::ostream &out, const Instruction &i)
 Dispatch a single instruction to its Win64 code generator.
void x64_gen_done (std::ostream &out, const Instruction &i)
void x64_gen_ret (std::ostream &out, const Instruction &i)
void x64_gen_return (std::ostream &out, const Instruction &i)
void x64_gen_neg (std::ostream &out, const Instruction &i)
void x64_gen_invoke (std::ostream &out, const Instruction &i)
void x64_gen_call (std::ostream &out, const Instruction &i)
void x64_gen_alloc (std::ostream &out, const Instruction &i)
void x64_gen_realloc (std::ostream &out, const Instruction &i)
 Generate Win64 x86-64 assembly for the REALLOC instruction (dynamic array resize).
void x64_gen_free (std::ostream &out, const Instruction &i)
void x64_gen_load (std::ostream &out, const Instruction &i)
void x64_gen_store (std::ostream &out, const Instruction &i)
void x64_gen_to_int (std::ostream &out, const Instruction &i)
void x64_gen_to_float (std::ostream &out, const Instruction &i)
void x64_gen_div (std::ostream &out, const Instruction &i)
void x64_gen_mod (std::ostream &out, const Instruction &i)
void x64_gen_getline (std::ostream &out, const Instruction &i)
void x64_gen_bitop (std::ostream &out, const std::string &opc, const Instruction &i)
void x64_gen_not (std::ostream &out, const Instruction &i)
void x64_gen_push (std::ostream &out, const Instruction &i)
void x64_gen_pop (std::ostream &out, const Instruction &i)
void x64_gen_stack_load (std::ostream &out, const Instruction &i)
void x64_gen_stack_store (std::ostream &out, const Instruction &i)
void x64_gen_stack_sub (std::ostream &out, const Instruction &i)
void x64_gen_print (std::ostream &out, const Instruction &i)
void x64_gen_jmp (std::ostream &out, const Instruction &i)
void x64_gen_cmp (std::ostream &out, const Instruction &i)
void x64_gen_mov (std::ostream &out, const Instruction &i)
void x64_gen_arth (std::ostream &out, std::string arth, const Instruction &i)
void x64_gen_exit (std::ostream &out, const Instruction &i)
void x64_gen_lea (std::ostream &out, const Instruction &i)
void x64_gen_fcmp (std::ostream &out, const Instruction &i)
void x64_gen_jae (std::ostream &out, const Instruction &i)
void x64_gen_jbe (std::ostream &out, const Instruction &i)
void x64_gen_jc (std::ostream &out, const Instruction &i)
void x64_gen_jnc (std::ostream &out, const Instruction &i)
void x64_gen_jp (std::ostream &out, const Instruction &i)
void x64_gen_jnp (std::ostream &out, const Instruction &i)
void x64_gen_jo (std::ostream &out, const Instruction &i)
void x64_gen_jno (std::ostream &out, const Instruction &i)
void x64_gen_js (std::ostream &out, const Instruction &i)
void x64_gen_jns (std::ostream &out, const Instruction &i)
void x64_analyzeRegAlloc (bool uses_std_module)
 Analyze variable usage and assign Win64 callee-saved registers.
void x64_emitFlushRegs (std::ostream &out)
 Write all register-allocated variables back to memory.
void x64_emitReloadRegs (std::ostream &out)
 Reload register-allocated variables from memory.
void x64_emitSaveRegs (std::ostream &out)
 Save callee-saved registers at function prologue.
void x64_emitRestoreRegs (std::ostream &out)
 Restore callee-saved registers at function epilogue.
void x64_emitStoreVar (std::ostream &out, const std::string &srcReg, const Operand &dest)
 Store a register value into a variable (register-allocated or memory).
void x64_emitStoreVarImm (std::ostream &out, const std::string &imm, const Operand &dest)
 Store an immediate value into a variable.
void x64_emitLoadVar (std::ostream &out, const std::string &dstReg, const Operand &src)
 Load a variable into a destination register.

System V ABI register allocation

std::unordered_map< std::string, std::string > sysv_reg_vars
 SysV variable-to-register mapping.
std::vector< std::string > sysv_reg_save_order
void sysv_analyzeRegAlloc (bool uses_std_module)
 Analyze variable usage and assign System V callee-saved registers.
void sysv_emitFlushRegs (std::ostream &out)
 Write all register-allocated variables back to memory.
void sysv_emitReloadRegs (std::ostream &out)
 Reload register-allocated variables from memory.
void sysv_emitSaveRegs (std::ostream &out)
 Save callee-saved registers at function prologue.
void sysv_emitRestoreRegs (std::ostream &out)
 Restore callee-saved registers at function epilogue.
void sysv_emitStoreVar (std::ostream &out, const std::string &srcReg, const Operand &dest)
 Store a register value into a variable (register-allocated or memory).
void sysv_emitStoreVarImm (std::ostream &out, const std::string &imm, const Operand &dest)
 Store an immediate value into a variable.
void sysv_emitLoadVar (std::ostream &out, const std::string &dstReg, const Operand &src)
 Load a variable into a destination register.

Additional Inherited Members

Static Public Attributes inherited from mxvm::Base
static Base * base = nullptr
 pointer to the main program base
static std::string root_name
static std::vector< std::string > filenames
static std::unordered_map< std::string, Variable > allocated
 heap-allocated variables
static std::unordered_map< std::string, Program * > object_map
 object name -> Program mapping

Detailed Description

Complete MXVM program: instruction interpreter and native x64 code generator.

Extends Base with execution state (program counter, flags, stack) for interpretation, and a full set of code generation methods targeting x86-64 assembly (System V ABI for Linux/macOS, Win64 ABI for Windows).

Definition at line 212 of file icode.hpp.

Member Enumeration Documentation

◆ LastCmpType

Tracks type of last comparison for conditional jumps.

Enumerator
CMP_NONE 
CMP_INTEGER 
CMP_FLOAT 

Definition at line 412 of file icode.hpp.

Constructor & Destructor Documentation

◆ Program() [1/2]

mxvm::Program::Program ( )

Default constructor — initializes execution state (pc, flags, etc.).

Definition at line 96 of file icode.cpp.

References mxvm::Base::add_extern(), pc, and running.

Referenced by Program(), flatten(), flatten_external(), flatten_inc(), flatten_label(), getObjectByName(), isFunctionValid(), memoryDump(), and operator=().

◆ ~Program()

mxvm::Program::~Program ( )

Destructor — frees any heap-allocated variables.

Definition at line 144 of file icode.cpp.

References Col(), mxvm::debug_mode, mxvm::RuntimeFunction::handles, name, mx::Color::RED, and mxvm::Base::vars.

◆ Program() [2/2]

mxvm::Program::Program ( Program && other)
inlinenoexcept

Move constructor — transfers all execution state and child objects.

Definition at line 221 of file icode.hpp.

References Program(), name, pc, and mxvm::Base::vars.

Member Function Documentation

◆ add_standard()

void mxvm::Program::add_standard ( )

Register standard library runtime functions.

Definition at line 107 of file icode.cpp.

References mxvm::Base::add_variable(), name, and mxvm::Variable::setExtern().

Referenced by exec(), generateCode(), and x64_generateCode().

◆ addVariables()

void mxvm::Program::addVariables ( Variable & dest,
Variable & src1,
Variable & src2 )

Add two variables and store the result in dest.

Parameters
destDestination variable
src1First operand
src2Second operand

Definition at line 787 of file icode_exec.cpp.

References mxvm::Base::base, mxvm::Variable_Value::float_value, mxvm::Variable_Value::int_value, mxvm::Variable_Value::owns, mxvm::Variable_Value::ptr_value, mxvm::Variable::type, mxvm::Variable_Value::type, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, mxvm::VAR_POINTER, and mxvm::Variable::var_value.

Referenced by exec_add().

◆ createTempVariable()

Variable mxvm::Program::createTempVariable ( VarType type,
const std::string & value )

◆ divVariables()

void mxvm::Program::divVariables ( Variable & dest,
Variable & src1,
Variable & src2 )

◆ escapeNewLines()

std::string mxvm::Program::escapeNewLines ( const std::string & text)
static

Escape newline characters in a string literal for assembly output.

Parameters
textRaw string
Returns
Escaped string

Definition at line 296 of file icode.cpp.

References result.

Referenced by generateCode(), memoryDump(), mxvm::Parser::printObjectHTML(), and x64_generateCode().

◆ exec()

◆ exec_add()

◆ exec_alloc()

◆ exec_and()

◆ exec_call()

void mxvm::Program::exec_call ( const Instruction & instr)

Definition at line 1759 of file icode_exec.cpp.

References mxvm::Base::labels, mxvm::Operand::op, mxvm::Instruction::op1, pc, and stack.

Referenced by exec().

◆ exec_cmp()

◆ exec_div()

◆ exec_done()

void mxvm::Program::exec_done ( const Instruction & instr)

Definition at line 1783 of file icode_exec.cpp.

References exitCode, and stop().

Referenced by exec().

◆ exec_exit()

void mxvm::Program::exec_exit ( const Instruction & instr)

◆ exec_fcmp()

◆ exec_free()

◆ exec_getline()

◆ exec_invoke()

◆ exec_ja()

void mxvm::Program::exec_ja ( const Instruction & instr)

Definition at line 1384 of file icode_exec.cpp.

References exec_jmp(), greater_flag, and pc.

Referenced by exec().

◆ exec_jae()

void mxvm::Program::exec_jae ( const Instruction & instr)

Definition at line 2180 of file icode_exec.cpp.

References exec_jmp(), greater_flag, pc, and zero_flag.

Referenced by exec().

◆ exec_jb()

void mxvm::Program::exec_jb ( const Instruction & instr)

Definition at line 1391 of file icode_exec.cpp.

References exec_jmp(), less_flag, and pc.

Referenced by exec().

◆ exec_jbe()

void mxvm::Program::exec_jbe ( const Instruction & instr)

Definition at line 2187 of file icode_exec.cpp.

References exec_jmp(), less_flag, pc, and zero_flag.

Referenced by exec().

◆ exec_jc()

void mxvm::Program::exec_jc ( const Instruction & instr)

Definition at line 2194 of file icode_exec.cpp.

References carry_flag, exec_jmp(), and pc.

Referenced by exec().

◆ exec_je()

void mxvm::Program::exec_je ( const Instruction & instr)

Definition at line 1328 of file icode_exec.cpp.

References exec_jmp(), pc, and zero_flag.

Referenced by exec().

◆ exec_jg()

void mxvm::Program::exec_jg ( const Instruction & instr)

Definition at line 1356 of file icode_exec.cpp.

References exec_jmp(), greater_flag, and pc.

Referenced by exec().

◆ exec_jge()

void mxvm::Program::exec_jge ( const Instruction & instr)

Definition at line 1363 of file icode_exec.cpp.

References exec_jmp(), greater_flag, pc, and zero_flag.

Referenced by exec().

◆ exec_jl()

void mxvm::Program::exec_jl ( const Instruction & instr)

Definition at line 1342 of file icode_exec.cpp.

References exec_jmp(), less_flag, and pc.

Referenced by exec().

◆ exec_jle()

void mxvm::Program::exec_jle ( const Instruction & instr)

Definition at line 1349 of file icode_exec.cpp.

References exec_jmp(), less_flag, pc, and zero_flag.

Referenced by exec().

◆ exec_jmp()

◆ exec_jnc()

void mxvm::Program::exec_jnc ( const Instruction & instr)

Definition at line 2201 of file icode_exec.cpp.

References carry_flag, exec_jmp(), and pc.

Referenced by exec().

◆ exec_jne()

void mxvm::Program::exec_jne ( const Instruction & instr)

Definition at line 1335 of file icode_exec.cpp.

References exec_jmp(), pc, and zero_flag.

Referenced by exec().

◆ exec_jno()

void mxvm::Program::exec_jno ( const Instruction & instr)

Definition at line 2220 of file icode_exec.cpp.

References exec_jmp().

Referenced by exec().

◆ exec_jnp()

void mxvm::Program::exec_jnp ( const Instruction & instr)

Definition at line 2212 of file icode_exec.cpp.

References exec_jmp().

Referenced by exec().

◆ exec_jns()

void mxvm::Program::exec_jns ( const Instruction & instr)

Definition at line 2228 of file icode_exec.cpp.

References exec_jmp().

Referenced by exec().

◆ exec_jnz()

void mxvm::Program::exec_jnz ( const Instruction & instr)

Definition at line 1377 of file icode_exec.cpp.

References exec_jmp(), pc, and zero_flag.

Referenced by exec().

◆ exec_jo()

void mxvm::Program::exec_jo ( const Instruction & instr)

Definition at line 2216 of file icode_exec.cpp.

References pc.

Referenced by exec().

◆ exec_jp()

void mxvm::Program::exec_jp ( const Instruction & instr)

Definition at line 2208 of file icode_exec.cpp.

References pc.

Referenced by exec().

◆ exec_js()

void mxvm::Program::exec_js ( const Instruction & instr)

Definition at line 2224 of file icode_exec.cpp.

References pc.

Referenced by exec().

◆ exec_jz()

void mxvm::Program::exec_jz ( const Instruction & instr)

Definition at line 1370 of file icode_exec.cpp.

References exec_jmp(), pc, and zero_flag.

Referenced by exec().

◆ exec_lea()

◆ exec_load()

◆ exec_mod()

◆ exec_mov()

◆ exec_mul()

◆ exec_neg()

◆ exec_not()

◆ exec_or()

◆ exec_pop()

void mxvm::Program::exec_pop ( const Instruction & instr)

Execute a POP instruction — restore a value from the VM stack into a variable.

Matches the pushed type via std::holds_alternative and writes back into the correct union member. Float variables are restored from std::get<double> to preserve IEEE 754 representation.

Parameters
instrInstruction whose op1 is the destination variable.

Definition at line 1621 of file icode_exec.cpp.

References mxvm::Variable_Value::float_value, getVariable(), mxvm::Variable_Value::int_value, isVariable(), mxvm::Operand::op, mxvm::Instruction::op1, mxvm::Variable_Value::ptr_value, stack, mxvm::Variable_Value::str_value, mxvm::Variable::type, mxvm::Variable_Value::type, mxvm::VAR_BYTE, mxvm::VAR_EXTERN, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, mxvm::VAR_POINTER, mxvm::VAR_STRING, and mxvm::Variable::var_value.

Referenced by exec().

◆ exec_print()

◆ exec_push()

void mxvm::Program::exec_push ( const Instruction & instr)

Execute a PUSH instruction — save a variable or constant onto the VM stack.

Handles integer/byte, pointer/extern, float, and string variable types. Float variables are pushed as native doubles so that POP can restore them correctly using std::get<double>.

Parameters
instrInstruction whose op1 is the value to push.

Definition at line 1588 of file icode_exec.cpp.

References mxvm::Variable_Value::float_value, getVariable(), mxvm::Variable_Value::int_value, isVariable(), mxvm::Operand::op, mxvm::Instruction::op1, mxvm::Variable_Value::ptr_value, stack, mxvm::Variable_Value::str_value, mxvm::Variable_Value::type, mxvm::VAR_BYTE, mxvm::VAR_EXTERN, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, mxvm::VAR_POINTER, mxvm::VAR_STRING, and mxvm::Variable::var_value.

Referenced by exec().

◆ exec_realloc()

void mxvm::Program::exec_realloc ( const Instruction & instr)

Execute the REALLOC instruction in the interpreter.

Execute the REALLOC instruction.

Resizes the memory block pointed to by the destination variable. Operands: dest (pointer var), elemSize, count. Zero-initialises any newly allocated bytes beyond the old allocation. A count of zero frees the block.

Resizes the heap block of a pointer variable using C realloc(). Operands: op1 = destination ptr variable, op2 = element size, op3 = new element count. Zero-fills newly allocated bytes. A count of zero frees the block.

Definition at line 1910 of file icode_exec.cpp.

References getVariable(), mxvm::Variable_Value::int_value, isVariable(), mxvm::Operand::op, mxvm::Instruction::op1, mxvm::Instruction::op2, mxvm::Instruction::op3, mxvm::Variable_Value::owns, mxvm::Variable_Value::ptr_count, mxvm::Variable_Value::ptr_size, mxvm::Variable_Value::ptr_value, mxvm::Variable::type, mxvm::Variable_Value::type, mxvm::VAR_POINTER, and mxvm::Variable::var_value.

Referenced by exec().

◆ exec_ret()

void mxvm::Program::exec_ret ( const Instruction & instr)

Definition at line 1772 of file icode_exec.cpp.

References pc, and stack.

Referenced by exec().

◆ exec_return()

◆ exec_stack_load()

◆ exec_stack_store()

◆ exec_stack_sub()

void mxvm::Program::exec_stack_sub ( const Instruction & instr)

◆ exec_store()

void mxvm::Program::exec_store ( const Instruction & instr)

Execute a STORE instruction — write a value into a pointer at a given offset.

Supports integer, float, pointer, byte, and string source types. For constants the full 8-byte integer representation is always stored, regardless of the stride operand, to prevent partial-write corruption when storing values larger than one byte.

Parameters
instrInstruction with op1 = source, op2 = destination pointer, op3 = index, vop[0] = stride.

Definition at line 1008 of file icode_exec.cpp.

References mxvm::Base::base, mxvm::Variable_Value::float_value, getVariable(), mxvm::Variable_Value::int_value, isVariable(), mxvm::Operand::op, mxvm::Instruction::op1, mxvm::Instruction::op2, mxvm::Instruction::op3, mxvm::OP_CONSTANT, mxvm::Variable_Value::owns, mxvm::Variable_Value::ptr_count, mxvm::Variable_Value::ptr_size, mxvm::Variable_Value::ptr_value, mxvm::Variable_Value::str_value, mxvm::Operand::type, mxvm::Variable::type, mxvm::VAR_BYTE, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, mxvm::Variable::var_name, mxvm::VAR_POINTER, mxvm::VAR_STRING, mxvm::Variable::var_value, and mxvm::Instruction::vop.

Referenced by exec().

◆ exec_string_print()

◆ exec_sub()

◆ exec_to_float()

◆ exec_to_int()

◆ exec_xor()

◆ flatten()

void mxvm::Program::flatten ( Program * program)

Flatten child object programs into the root instruction stream.

Parameters
programRoot program to merge into

Definition at line 102 of file icode_exec.cpp.

References Program(), mxvm::Base::external_functions, flatten_external(), flatten_inc(), flatten_label(), mxvm::Base::inc, mxvm::Base::labels, and objects.

◆ flatten_external()

void mxvm::Program::flatten_external ( Program * root,
const std::string & e,
RuntimeFunction & r )

Copy an external function binding from a child object into the root.

Parameters
rootRoot program
eExternal function name
rResolved RuntimeFunction binding

Definition at line 96 of file icode_exec.cpp.

References Program(), and mxvm::Base::external_functions.

Referenced by flatten().

◆ flatten_inc()

void mxvm::Program::flatten_inc ( Program * root,
Instruction & i )

Rewrite object-qualified operand references in a single instruction.

Parameters
rootRoot program owning the merged instruction stream
iInstruction to rewrite (modified in place)

Definition at line 27 of file icode_exec.cpp.

References Program(), mxvm::Base::add_instruction(), CALL, mxvm::Instruction::instruction, JA, JB, JE, JG, JGE, JL, JLE, JMP, JNE, JNZ, JZ, mxvm::Base::labels, name, mxvm::Instruction::op1, mxvm::Instruction::op2, mxvm::Instruction::op3, mxvm::OP_VARIABLE, mxvm::Base::vars, and mxvm::Instruction::vop.

Referenced by flatten().

◆ flatten_label()

void mxvm::Program::flatten_label ( Program * root,
int64_t offset,
const std::string & label,
bool func )

Copy a label from a child object into the root label map with an address offset.

Parameters
rootRoot program
offsetInstruction index offset
labelLabel name
functrue if the label is a function entry

Definition at line 87 of file icode_exec.cpp.

References Program(), mxvm::Base::add_label(), and name.

Referenced by flatten().

◆ gen_add()

void mxvm::Program::gen_add ( std::ostream & out,
const Instruction & i )

◆ gen_alloc()

◆ gen_arth()

◆ gen_bitop()

void mxvm::Program::gen_bitop ( std::ostream & out,
const std::string & opc,
const Instruction & i )

◆ gen_call()

◆ gen_cmp()

◆ gen_div()

◆ gen_done()

void mxvm::Program::gen_done ( std::ostream & out,
const Instruction & i )

◆ gen_exit()

void mxvm::Program::gen_exit ( std::ostream & out,
const Instruction & i )

◆ gen_fcmp()

void mxvm::Program::gen_fcmp ( std::ostream & out,
const Instruction & i )

◆ gen_free()

◆ gen_getline()

◆ gen_invoke()

void mxvm::Program::gen_invoke ( std::ostream & out,
const Instruction & i )

◆ gen_jae()

void mxvm::Program::gen_jae ( std::ostream & out,
const Instruction & i )

Definition at line 1804 of file icode_gen.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by generateInstruction().

◆ gen_jbe()

void mxvm::Program::gen_jbe ( std::ostream & out,
const Instruction & i )

Definition at line 1808 of file icode_gen.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by generateInstruction().

◆ gen_jc()

void mxvm::Program::gen_jc ( std::ostream & out,
const Instruction & i )

Definition at line 1812 of file icode_gen.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by generateInstruction().

◆ gen_jmp()

void mxvm::Program::gen_jmp ( std::ostream & out,
const Instruction & i )

◆ gen_jnc()

void mxvm::Program::gen_jnc ( std::ostream & out,
const Instruction & i )

Definition at line 1816 of file icode_gen.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by generateInstruction().

◆ gen_jno()

void mxvm::Program::gen_jno ( std::ostream & out,
const Instruction & i )

Definition at line 1832 of file icode_gen.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by generateInstruction().

◆ gen_jnp()

void mxvm::Program::gen_jnp ( std::ostream & out,
const Instruction & i )

Definition at line 1824 of file icode_gen.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by generateInstruction().

◆ gen_jns()

void mxvm::Program::gen_jns ( std::ostream & out,
const Instruction & i )

Definition at line 1840 of file icode_gen.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by generateInstruction().

◆ gen_jo()

void mxvm::Program::gen_jo ( std::ostream & out,
const Instruction & i )

Definition at line 1828 of file icode_gen.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by generateInstruction().

◆ gen_jp()

void mxvm::Program::gen_jp ( std::ostream & out,
const Instruction & i )

Definition at line 1820 of file icode_gen.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by generateInstruction().

◆ gen_js()

void mxvm::Program::gen_js ( std::ostream & out,
const Instruction & i )

Definition at line 1836 of file icode_gen.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by generateInstruction().

◆ gen_lea()

void mxvm::Program::gen_lea ( std::ostream & out,
const Instruction & i )

◆ gen_load()

◆ gen_mod()

◆ gen_mov()

◆ gen_mul()

void mxvm::Program::gen_mul ( std::ostream & out,
const Instruction & i )

References platform.

◆ gen_neg()

void mxvm::Program::gen_neg ( std::ostream & out,
const Instruction & i )

◆ gen_not()

void mxvm::Program::gen_not ( std::ostream & out,
const Instruction & i )

◆ gen_optimize()

std::string mxvm::Program::gen_optimize ( const std::string & code,
const Platform & platform )

Peephole optimizer for generated assembly.

Apply peephole optimizations to generated assembly

Parameters
codeRaw assembly text
platformTarget platform (affects optimization rules)
Returns
Optimized assembly text

Definition at line 496 of file icode_opt.cpp.

References mxvm::DARWIN, mxvm::join_lines(), mxvm::opt_core_lines(), mxvm::opt_darwin_lines(), mxvm::opt_linux_lines(), mxvm::opt_x64_windows_lines(), mxvm::WINX64, and mxvm::x64_opt_core_lines().

◆ gen_pop()

void mxvm::Program::gen_pop ( std::ostream & out,
const Instruction & i )

Emit x86-64 POP into a variable.

Handles integer (popq + store), pointer/extern (popq + movq), and float variables. Floating-point values are popped via movsd (rsp), xmm0; addq $8, rsp; movsd xmm0, var(rip) mirroring the SSE push sequence in gen_push().

Parameters
outAssembly output stream.
iInstruction whose op1 is the destination variable.

Definition at line 1400 of file icode_gen.cpp.

References getMangledName(), getVariable(), isVariable(), mxvm::Operand::op, mxvm::Instruction::op1, sysv_emitStoreVar(), mxvm::Variable::type, mxvm::VAR_EXTERN, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, and mxvm::VAR_POINTER.

Referenced by generateInstruction().

◆ gen_print()

◆ gen_push()

void mxvm::Program::gen_push ( std::ostream & out,
const Instruction & i )

Emit x86-64 PUSH for a variable or constant.

Handles integer/pointer (pushq), string (lea+pushq), and float variables. Floating-point values are pushed via movsd var(rip), xmm0; subq $8, rsp; movsd xmm0, (rsp) since x86 PUSH cannot operate directly on XMM registers.

Parameters
outAssembly output stream.
iInstruction whose op1 is the value to push.

Definition at line 1365 of file icode_gen.cpp.

References getMangledName(), getVariable(), isVariable(), mxvm::Operand::op, mxvm::Instruction::op1, mxvm::OP_CONSTANT, sysv_emitLoadVar(), mxvm::Operand::type, mxvm::Variable::type, mxvm::VAR_EXTERN, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, mxvm::VAR_POINTER, and mxvm::VAR_STRING.

Referenced by generateInstruction().

◆ gen_realloc()

void mxvm::Program::gen_realloc ( std::ostream & out,
const Instruction & i )

Generate System V x86-64 assembly for the REALLOC instruction (dynamic array resize).

Generate System V x86-64 native code for REALLOC.

Computes total = count * elemSize, calls C realloc() with the existing pointer and new size, and stores the result back. Stack is 16-byte aligned around the call. Registers are flushed/reloaded via sysv_emitFlushRegs / sysv_emitReloadRegs.

Definition at line 715 of file icode_gen.cpp.

References mxvm::error_label_count, getMangledName(), getPlatformSymbolName(), getVariable(), isVariable(), mxvm::Operand::op, mxvm::Instruction::op1, mxvm::Instruction::op2, mxvm::Instruction::op3, mxvm::Variable_Value::owns, sysv_emitFlushRegs(), sysv_emitLoadVar(), sysv_emitReloadRegs(), mxvm::Variable::type, mxvm::VAR_POINTER, and mxvm::Variable::var_value.

Referenced by generateInstruction().

◆ gen_ret()

void mxvm::Program::gen_ret ( std::ostream & out,
const Instruction & i )

◆ gen_return()

◆ gen_stack_load()

void mxvm::Program::gen_stack_load ( std::ostream & out,
const Instruction & i )

◆ gen_stack_store()

void mxvm::Program::gen_stack_store ( std::ostream & out,
const Instruction & i )

◆ gen_stack_sub()

void mxvm::Program::gen_stack_sub ( std::ostream & out,
const Instruction & i )

◆ gen_store()

◆ gen_sub()

void mxvm::Program::gen_sub ( std::ostream & out,
const Instruction & i )

◆ gen_to_float()

◆ gen_to_int()

◆ generateCode()

void mxvm::Program::generateCode ( const Platform & platform,
bool obj,
std::ostream & out )

◆ generateFunctionCall()

void mxvm::Program::generateFunctionCall ( std::ostream & out,
const std::string & name,
std::vector< Operand > & op )

Generate a System V ABI function call with operands as arguments.

Parameters
outAssembly output stream
nameCallee function name
opOperand list to pass as arguments

Definition at line 610 of file icode_gen.cpp.

References args, generateLoadVar(), getPlatformSymbolName(), name, mxvm::VAR_INTEGER, and xmm_offset.

Referenced by gen_exit(), and generateInvokeCall().

◆ generateInstruction()

◆ generateInvokeCall()

void mxvm::Program::generateInvokeCall ( std::ostream & out,
std::vector< Operand > & op )

Generate a dynamic invoke call (runtime-resolved external function).

Parameters
outAssembly output stream
opOperand list: first is the function name, rest are arguments

Definition at line 591 of file icode_gen.cpp.

References args, generateFunctionCall(), mxvm::isFunctionReturningOwnedPtr(), last_call_returns_owned_ptr, and name.

Referenced by gen_invoke().

◆ generateLoadVar() [1/2]

int mxvm::Program::generateLoadVar ( std::ostream & out,
int reg,
const Operand & op )

Load a variable or constant into a numbered register.

Parameters
outAssembly output stream
regRegister index (0-based)
opOperand to load
Returns
1 if the operand was a constant, 0 if variable

Definition at line 1460 of file icode_gen.cpp.

References getMangledName(), getPlatformSymbolName(), getRegisterByIndex(), getVariable(), isVariable(), mxvm::Operand::op, mxvm::OP_CONSTANT, mxvm::OP_VARIABLE, sysv_reg_vars, mxvm::Operand::type, mxvm::Variable::type, mxvm::VAR_BYTE, mxvm::VAR_EXTERN, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, mxvm::VAR_POINTER, and mxvm::VAR_STRING.

Referenced by gen_arth(), gen_bitop(), gen_cmp(), gen_div(), gen_fcmp(), gen_mod(), gen_neg(), gen_not(), gen_print(), gen_stack_load(), gen_stack_store(), and generateFunctionCall().

◆ generateLoadVar() [2/2]

int mxvm::Program::generateLoadVar ( std::ostream & out,
VarType type,
std::string reg,
const Operand & op )

Load a variable or constant into a named register.

Parameters
outAssembly output stream
typeExpected variable type
regTarget register name (e.g. "rax")
opOperand to load
Returns
1 if the operand was a constant, 0 if variable

Definition at line 1507 of file icode_gen.cpp.

References getMangledName(), getPlatformSymbolName(), getVariable(), isVariable(), mxvm::Operand::op, mxvm::OP_CONSTANT, mxvm::OP_VARIABLE, sysv_reg_vars, mxvm::Operand::type, mxvm::Variable::type, mxvm::VAR_BYTE, mxvm::VAR_EXTERN, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, mxvm::VAR_POINTER, and mxvm::VAR_STRING.

◆ getExitCode()

int mxvm::Program::getExitCode ( ) const
inline

Get the program's exit code after execution.

Returns
Exit code (0 on success)

Definition at line 305 of file icode.hpp.

References exitCode.

Referenced by exec().

◆ getMangledName() [1/2]

std::string mxvm::Program::getMangledName ( const Operand & op)

Mangle an operand's variable reference with its object prefix.

Parameters
opOperand containing the variable reference
Returns
Object-qualified name

Definition at line 55 of file icode.cpp.

References mxvm::Base::base, mxvm::DARWIN, getMangledName(), mxvm::Operand::label, mxvm::Base::labels, name, mxvm::Operand::object, mxvm::Operand::op, and platform.

◆ getMangledName() [2/2]

◆ getObjectByName()

Program * mxvm::Program::getObjectByName ( const std::string & name)

Look up a child object program by name.

Parameters
nameObject identifier
Returns
Pointer to the Program, or nullptr if not found

Definition at line 285 of file icode.cpp.

References Program(), name, and objects.

◆ getPlatformSymbolName()

std::string mxvm::Program::getPlatformSymbolName ( const std::string & name)

Mangle a symbol name with the platform prefix (e.g. _name for Darwin).

Parameters
nameOriginal symbol name
Returns
Platform-adjusted symbol name

Definition at line 14 of file icode_gen.cpp.

References mxvm::DARWIN, name, and platform.

Referenced by gen_alloc(), gen_call(), gen_done(), gen_exit(), gen_free(), gen_getline(), gen_mov(), gen_print(), gen_realloc(), gen_to_float(), gen_to_int(), generateCode(), generateFunctionCall(), generateLoadVar(), and generateLoadVar().

◆ getRegisterByIndex()

std::string mxvm::Program::getRegisterByIndex ( int index,
VarType type )

Get the register name for a given index and variable type.

Parameters
indexRegister index
typeVariable type (determines integer vs. XMM register)
Returns
Register name string

Definition at line 1634 of file icode_gen.cpp.

References mxvm::VAR_BYTE, mxvm::VAR_EXTERN, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, mxvm::VAR_POINTER, mxvm::VAR_STRING, and xmm_offset.

Referenced by generateLoadVar().

◆ getVariable()

Variable & mxvm::Program::getVariable ( const std::string & name)

Look up a variable by name, searching local scope then global.

Parameters
nameVariable identifier
Returns
Reference to the Variable
Exceptions
mx::Exceptionif the variable is not found

Definition at line 681 of file icode_exec.cpp.

References mxvm::Base::base, name, mxvm::Base::object_map, pos(), and mxvm::Base::vars.

Referenced by exec_add(), exec_alloc(), exec_and(), exec_cmp(), exec_div(), exec_exit(), exec_fcmp(), exec_free(), exec_getline(), exec_invoke(), exec_lea(), exec_load(), exec_mod(), exec_mov(), exec_mul(), exec_neg(), exec_not(), exec_or(), exec_pop(), exec_print(), exec_push(), exec_realloc(), exec_return(), exec_stack_load(), exec_stack_store(), exec_stack_sub(), exec_store(), exec_string_print(), exec_sub(), exec_to_float(), exec_to_int(), exec_xor(), gen_alloc(), gen_arth(), gen_bitop(), gen_call(), gen_cmp(), gen_div(), gen_free(), gen_getline(), gen_lea(), gen_load(), gen_mod(), gen_mov(), gen_neg(), gen_not(), gen_pop(), gen_print(), gen_push(), gen_realloc(), gen_ret(), gen_return(), gen_stack_load(), gen_stack_store(), gen_store(), gen_to_float(), gen_to_int(), generateCode(), generateLoadVar(), generateLoadVar(), getMangledName(), getStringFromVar(), mxvm_io_fclose(), mxvm_io_feof(), mxvm_io_fopen(), mxvm_io_fprintf(), mxvm_io_fputs(), mxvm_io_fread(), mxvm_io_fseek(), mxvm_io_fsize(), mxvm_io_fwrite(), mxvm_io_mxvm_fgets(), mxvm_io_rand_number(), mxvm_sdl_blit_surface(), mxvm_sdl_clear(), mxvm_sdl_create_render_target(), mxvm_sdl_create_renderer(), mxvm_sdl_create_rgb_surface(), mxvm_sdl_create_texture(), mxvm_sdl_create_window(), mxvm_sdl_delay(), mxvm_sdl_destroy_render_target(), mxvm_sdl_destroy_renderer(), mxvm_sdl_destroy_texture(), mxvm_sdl_destroy_window(), mxvm_sdl_draw_line(), mxvm_sdl_draw_point(), mxvm_sdl_draw_rect(), mxvm_sdl_draw_text(), mxvm_sdl_fill_rect(), mxvm_sdl_free_surface(), mxvm_sdl_free_wav(), mxvm_sdl_get_keyboard_state(), mxvm_sdl_get_mouse_state(), mxvm_sdl_get_relative_mouse_state(), mxvm_sdl_get_renderer_output_size(), mxvm_sdl_get_window_size(), mxvm_sdl_is_key_pressed(), mxvm_sdl_load_font(), mxvm_sdl_load_texture(), mxvm_sdl_load_texture_color_key(), mxvm_sdl_load_texture_color_key_rgb(), mxvm_sdl_load_wav(), mxvm_sdl_lock_texture(), mxvm_sdl_open_audio(), mxvm_sdl_pause_audio(), mxvm_sdl_present(), mxvm_sdl_present_scaled(), mxvm_sdl_present_stretched(), mxvm_sdl_queue_audio(), mxvm_sdl_render_texture(), mxvm_sdl_set_clipboard_text(), mxvm_sdl_set_draw_color(), mxvm_sdl_set_render_target(), mxvm_sdl_set_window_fullscreen(), mxvm_sdl_set_window_icon(), mxvm_sdl_set_window_position(), mxvm_sdl_set_window_title(), mxvm_sdl_show_cursor(), mxvm_sdl_unlock_texture(), mxvm_sdl_update_texture(), mxvm_std_abs(), mxvm_std_acos(), mxvm_std_argv(), mxvm_std_asin(), mxvm_std_atan(), mxvm_std_atan2(), mxvm_std_atof(), mxvm_std_atoi(), mxvm_std_calloc(), mxvm_std_ceil(), mxvm_std_cos(), mxvm_std_cosh(), mxvm_std_exit(), mxvm_std_exp(), mxvm_std_exp2(), mxvm_std_fabs(), mxvm_std_float_to_int(), mxvm_std_floor(), mxvm_std_fmod(), mxvm_std_hypot(), mxvm_std_int_to_float(), mxvm_std_isalpha(), mxvm_std_isdigit(), mxvm_std_isspace(), mxvm_std_log(), mxvm_std_log10(), mxvm_std_log2(), mxvm_std_malloc(), mxvm_std_memcmp(), mxvm_std_memcpy(), mxvm_std_memmove(), mxvm_std_memset(), mxvm_std_pow(), mxvm_std_release(), mxvm_std_round(), mxvm_std_set_program_args(), mxvm_std_sin(), mxvm_std_sinh(), mxvm_std_sqrt(), mxvm_std_srand(), mxvm_std_system(), mxvm_std_tan(), mxvm_std_tanh(), mxvm_std_tolower(), mxvm_std_toupper(), mxvm_std_trunc(), mxvm_string_copy(), mxvm_string_delete(), mxvm_string_insert(), mxvm_string_inttostr(), mxvm_string_snprintf(), mxvm_string_strat(), mxvm_string_strcmp(), mxvm_string_strfind(), mxvm_string_strlen(), mxvm_string_strncat(), mxvm_string_strncpy(), mxvm_string_substr(), sysv_analyzeRegAlloc(), variableFromOperand(), x64_analyzeRegAlloc(), x64_gen_alloc(), x64_gen_arth(), x64_gen_bitop(), x64_gen_call(), x64_gen_cmp(), x64_gen_div(), x64_gen_free(), x64_gen_getline(), x64_gen_lea(), x64_gen_load(), x64_gen_mod(), x64_gen_mov(), x64_gen_neg(), x64_gen_not(), x64_gen_pop(), x64_gen_push(), x64_gen_realloc(), x64_gen_ret(), x64_gen_return(), x64_gen_store(), x64_generateCode(), x64_generateFunctionCall(), x64_generateLoadVar(), and x64_generateLoadVar().

◆ isConstant()

bool mxvm::Program::isConstant ( const std::string & value)

Check whether a string represents a compile-time constant (number or quoted string).

Parameters
valueString to test
Returns
true if it is a constant

◆ isFunctionValid()

bool mxvm::Program::isFunctionValid ( const std::string & label)

Check whether a label exists and is marked as a function entry.

Parameters
labelLabel name to check
Returns
true if the label is a valid function

Definition at line 175 of file icode.cpp.

References Program(), mxvm::Base::labels, and mxvm::Base::object_map.

Referenced by gen_call(), and x64_gen_call().

◆ isVariable()

bool mxvm::Program::isVariable ( const std::string & name)

Check whether a variable exists in local or global scope.

Parameters
nameVariable identifier
Returns
true if the variable is declared

Definition at line 724 of file icode_exec.cpp.

References mxvm::Base::base, name, mxvm::Base::object_map, and mxvm::Base::vars.

Referenced by exec_add(), exec_alloc(), exec_and(), exec_cmp(), exec_div(), exec_exit(), exec_fcmp(), exec_free(), exec_getline(), exec_invoke(), exec_lea(), exec_load(), exec_mod(), exec_mov(), exec_mul(), exec_neg(), exec_not(), exec_or(), exec_pop(), exec_print(), exec_push(), exec_realloc(), exec_return(), exec_stack_load(), exec_stack_store(), exec_stack_sub(), exec_store(), exec_string_print(), exec_sub(), exec_to_float(), exec_to_int(), exec_xor(), gen_alloc(), gen_arth(), gen_bitop(), gen_call(), gen_cmp(), gen_div(), gen_free(), gen_getline(), gen_lea(), gen_load(), gen_mod(), gen_mov(), gen_neg(), gen_not(), gen_pop(), gen_print(), gen_push(), gen_realloc(), gen_ret(), gen_return(), gen_stack_load(), gen_stack_store(), gen_stack_sub(), gen_store(), gen_to_float(), gen_to_int(), generateCode(), generateLoadVar(), generateLoadVar(), getMangledName(), getStringFromVar(), mxvm_io_fclose(), mxvm_io_feof(), mxvm_io_fopen(), mxvm_io_fprintf(), mxvm_io_fputs(), mxvm_io_fread(), mxvm_io_fseek(), mxvm_io_fsize(), mxvm_io_fwrite(), mxvm_io_mxvm_fgets(), mxvm_io_rand_number(), mxvm_sdl_blit_surface(), mxvm_sdl_clear(), mxvm_sdl_create_render_target(), mxvm_sdl_create_renderer(), mxvm_sdl_create_rgb_surface(), mxvm_sdl_create_texture(), mxvm_sdl_create_window(), mxvm_sdl_delay(), mxvm_sdl_destroy_render_target(), mxvm_sdl_destroy_renderer(), mxvm_sdl_destroy_texture(), mxvm_sdl_destroy_window(), mxvm_sdl_draw_line(), mxvm_sdl_draw_point(), mxvm_sdl_draw_rect(), mxvm_sdl_draw_text(), mxvm_sdl_fill_rect(), mxvm_sdl_free_surface(), mxvm_sdl_free_wav(), mxvm_sdl_get_keyboard_state(), mxvm_sdl_get_mouse_state(), mxvm_sdl_get_relative_mouse_state(), mxvm_sdl_get_renderer_output_size(), mxvm_sdl_get_window_size(), mxvm_sdl_is_key_pressed(), mxvm_sdl_load_font(), mxvm_sdl_load_texture(), mxvm_sdl_load_texture_color_key(), mxvm_sdl_load_texture_color_key_rgb(), mxvm_sdl_load_wav(), mxvm_sdl_lock_texture(), mxvm_sdl_open_audio(), mxvm_sdl_pause_audio(), mxvm_sdl_present(), mxvm_sdl_present_scaled(), mxvm_sdl_present_stretched(), mxvm_sdl_queue_audio(), mxvm_sdl_render_texture(), mxvm_sdl_set_clipboard_text(), mxvm_sdl_set_draw_color(), mxvm_sdl_set_render_target(), mxvm_sdl_set_window_fullscreen(), mxvm_sdl_set_window_icon(), mxvm_sdl_set_window_position(), mxvm_sdl_set_window_title(), mxvm_sdl_show_cursor(), mxvm_sdl_unlock_texture(), mxvm_sdl_update_texture(), mxvm_std_abs(), mxvm_std_acos(), mxvm_std_argv(), mxvm_std_asin(), mxvm_std_atan(), mxvm_std_atan2(), mxvm_std_atof(), mxvm_std_atoi(), mxvm_std_calloc(), mxvm_std_ceil(), mxvm_std_cos(), mxvm_std_cosh(), mxvm_std_exit(), mxvm_std_exp(), mxvm_std_exp2(), mxvm_std_fabs(), mxvm_std_float_to_int(), mxvm_std_floor(), mxvm_std_fmod(), mxvm_std_hypot(), mxvm_std_int_to_float(), mxvm_std_isalpha(), mxvm_std_isdigit(), mxvm_std_isspace(), mxvm_std_log(), mxvm_std_log10(), mxvm_std_log2(), mxvm_std_malloc(), mxvm_std_memcmp(), mxvm_std_memcpy(), mxvm_std_memmove(), mxvm_std_memset(), mxvm_std_pow(), mxvm_std_release(), mxvm_std_round(), mxvm_std_set_program_args(), mxvm_std_sin(), mxvm_std_sinh(), mxvm_std_sqrt(), mxvm_std_srand(), mxvm_std_system(), mxvm_std_tan(), mxvm_std_tanh(), mxvm_std_tolower(), mxvm_std_toupper(), mxvm_std_trunc(), mxvm_string_snprintf(), mxvm_string_strat(), mxvm_string_strcmp(), mxvm_string_strfind(), mxvm_string_strlen(), mxvm_string_strncat(), mxvm_string_strncpy(), mxvm_string_substr(), sysv_analyzeRegAlloc(), variableFromOperand(), x64_analyzeRegAlloc(), x64_gen_alloc(), x64_gen_arth(), x64_gen_bitop(), x64_gen_call(), x64_gen_cmp(), x64_gen_div(), x64_gen_free(), x64_gen_getline(), x64_gen_lea(), x64_gen_load(), x64_gen_mod(), x64_gen_mov(), x64_gen_neg(), x64_gen_not(), x64_gen_pop(), x64_gen_push(), x64_gen_realloc(), x64_gen_ret(), x64_gen_return(), x64_gen_stack_load(), x64_gen_stack_store(), x64_gen_stack_sub(), x64_gen_store(), x64_gen_to_float(), x64_generateCode(), x64_generateFunctionCall(), x64_generateLoadVar(), and x64_generateLoadVar().

◆ memoryDump()

void mxvm::Program::memoryDump ( std::ostream & out)

Dump all variable values to a stream for debugging.

Parameters
outDestination stream

Definition at line 316 of file icode.cpp.

References Program(), escapeNewLines(), mxvm::Base::labels, name, objects, mxvm::VAR_ARRAY, mxvm::VAR_BYTE, mxvm::VAR_EXTERN, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, mxvm::VAR_LABEL, mxvm::VAR_POINTER, mxvm::VAR_STRING, and mxvm::Base::vars.

◆ mulVariables()

void mxvm::Program::mulVariables ( Variable & dest,
Variable & src1,
Variable & src2 )

◆ operator=()

Program & mxvm::Program::operator= ( Program && other)
inlinenoexcept

◆ optimize_core()

std::string mxvm::Program::optimize_core ( const std::string & code)

Platform-independent peephole optimizations.

Parameters
codeAssembly text
Returns
Optimized assembly text

References args, name, and platform.

◆ optimize_darwin()

std::string mxvm::Program::optimize_darwin ( const std::string & code)

Darwin-specific assembly optimizations.

Parameters
codeAssembly text
Returns
Optimized assembly text

◆ post()

void mxvm::Program::post ( std::ostream & out)

Generate native data section (variable declarations) into the output stream.

Parameters
outDestination stream

Definition at line 2093 of file icode_exec.cpp.

References stack.

◆ print()

void mxvm::Program::print ( std::ostream & out)

Print all instructions and data to an output stream.

Parameters
outDestination stream

Definition at line 2013 of file icode_exec.cpp.

References mxvm::Base::inc, and IncType.

◆ printFormatted()

std::string mxvm::Program::printFormatted ( const std::string & format,
const std::vector< Variable * > & args,
bool output = true )

Format and optionally print a printf-style format string with variable arguments.

Parameters
formatFormat string with % specifiers
argsVariables corresponding to format specifiers
outputtrue to print, false to only return the string
Returns
The formatted string

Definition at line 1501 of file icode_exec.cpp.

References args, mxvm::Variable_Value::float_value, mxvm::Variable_Value::int_value, mxvm::Variable_Value::ptr_value, mxvm::Variable_Value::str_value, mxvm::Variable::type, mxvm::Variable_Value::type, mxvm::VAR_BYTE, mxvm::VAR_EXTERN, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, mxvm::VAR_POINTER, mxvm::VAR_STRING, and mxvm::Variable::var_value.

Referenced by exec_print(), and mxvm_io_fprintf().

◆ setArgs()

void mxvm::Program::setArgs ( const std::vector< std::string > & argv)

Set the command-line arguments available to the program.

Parameters
argvArgument vector

Definition at line 128 of file icode.cpp.

References args, and argv().

◆ setObject()

void mxvm::Program::setObject ( bool obj)

Mark this program as an object (no main entry point).

Parameters
objtrue for object mode, false for stand-alone program

Definition at line 132 of file icode.cpp.

◆ setVariableFromConstant()

void mxvm::Program::setVariableFromConstant ( Variable & var,
const std::string & value )

Set a variable's value from a constant string (integer, float, or string literal).

Parameters
varVariable to modify
valueConstant string to parse

Definition at line 1991 of file icode_exec.cpp.

References mxvm::Variable_Value::float_value, mxvm::Variable_Value::int_value, mxvm::Variable_Value::owns, mxvm::Variable_Value::ptr_value, mxvm::Variable_Value::str_value, mxvm::Variable::type, mxvm::Variable_Value::type, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, mxvm::VAR_POINTER, mxvm::VAR_STRING, and mxvm::Variable::var_value.

Referenced by exec_mov().

◆ setVariableFromString()

void mxvm::Program::setVariableFromString ( Variable & var,
const std::string & value )

Set a variable's value from a string representation, coercing types.

Parameters
varVariable to modify
valueString to parse

Definition at line 771 of file icode_exec.cpp.

References mxvm::Variable_Value::float_value, mxvm::Variable_Value::int_value, mxvm::Variable_Value::str_value, mxvm::Variable::type, mxvm::Variable_Value::type, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, mxvm::VAR_STRING, and mxvm::Variable::var_value.

◆ stop()

void mxvm::Program::stop ( )

Halt the interpreter loop.

Definition at line 23 of file icode_exec.cpp.

References running.

Referenced by exec_done(), and exec_exit().

◆ subVariables()

◆ sysv_analyzeRegAlloc()

void mxvm::Program::sysv_analyzeRegAlloc ( bool uses_std_module)

Analyze variable usage and assign System V callee-saved registers.

Parameters
uses_std_moduletrue if the program uses the std module

Definition at line 24 of file icode_gen.cpp.

References getVariable(), mxvm::Base::inc, mxvm::Variable::is_global, isVariable(), sysv_reg_save_order, sysv_reg_vars, mxvm::Variable::type, and mxvm::VAR_INTEGER.

Referenced by generateCode().

◆ sysv_emitFlushRegs()

void mxvm::Program::sysv_emitFlushRegs ( std::ostream & out)

Write all register-allocated variables back to memory.

Definition at line 67 of file icode_gen.cpp.

References getMangledName(), and sysv_reg_vars.

Referenced by gen_call(), gen_done(), gen_load(), gen_realloc(), gen_ret(), and gen_store().

◆ sysv_emitLoadVar()

void mxvm::Program::sysv_emitLoadVar ( std::ostream & out,
const std::string & dstReg,
const Operand & src )

Load a variable into a destination register.

Parameters
outAssembly output stream
dstRegDestination register name
srcSource operand

Definition at line 110 of file icode_gen.cpp.

References getMangledName(), mxvm::Operand::op, and sysv_reg_vars.

Referenced by gen_alloc(), gen_call(), gen_load(), gen_mov(), gen_push(), gen_realloc(), gen_ret(), gen_stack_store(), gen_stack_sub(), and gen_store().

◆ sysv_emitReloadRegs()

void mxvm::Program::sysv_emitReloadRegs ( std::ostream & out)

Reload register-allocated variables from memory.

Definition at line 73 of file icode_gen.cpp.

References getMangledName(), and sysv_reg_vars.

Referenced by gen_call(), gen_realloc(), gen_store(), and generateCode().

◆ sysv_emitRestoreRegs()

void mxvm::Program::sysv_emitRestoreRegs ( std::ostream & out)

Restore callee-saved registers at function epilogue.

Definition at line 85 of file icode_gen.cpp.

References sysv_reg_save_order.

Referenced by gen_done(), and gen_ret().

◆ sysv_emitSaveRegs()

void mxvm::Program::sysv_emitSaveRegs ( std::ostream & out)

Save callee-saved registers at function prologue.

Definition at line 79 of file icode_gen.cpp.

References sysv_reg_save_order.

Referenced by generateCode().

◆ sysv_emitStoreVar()

void mxvm::Program::sysv_emitStoreVar ( std::ostream & out,
const std::string & srcReg,
const Operand & dest )

Store a register value into a variable (register-allocated or memory).

Parameters
outAssembly output stream
srcRegSource register name
destDestination operand

Definition at line 91 of file icode_gen.cpp.

References getMangledName(), mxvm::Operand::op, and sysv_reg_vars.

Referenced by gen_arth(), gen_bitop(), gen_div(), gen_load(), gen_mod(), gen_mov(), gen_neg(), gen_not(), gen_pop(), gen_return(), gen_stack_load(), gen_to_int(), and generateCode().

◆ sysv_emitStoreVarImm()

void mxvm::Program::sysv_emitStoreVarImm ( std::ostream & out,
const std::string & imm,
const Operand & dest )

Store an immediate value into a variable.

Parameters
outAssembly output stream
immImmediate value string
destDestination operand

Definition at line 101 of file icode_gen.cpp.

References getMangledName(), mxvm::Operand::op, and sysv_reg_vars.

Referenced by gen_mov().

◆ validateNames()

bool mxvm::Program::validateNames ( Validator & v)

Validate all variable and label names against the Validator.

Parameters
vValidator reference
Returns
true if all names pass validation

Definition at line 754 of file icode_exec.cpp.

References objects, mxvm::Validator::var_names, and mxvm::Base::vars.

◆ variableFromOperand()

Variable mxvm::Program::variableFromOperand ( const Operand & op)

Resolve an Operand to its corresponding Variable.

Parameters
opOperand to resolve
Returns
The Variable (looked up or created as a temporary for constants)

Definition at line 2123 of file icode_exec.cpp.

References createTempVariable(), getVariable(), isVariable(), mxvm::Operand::op, mxvm::OP_CONSTANT, mxvm::Operand::type, and mxvm::VAR_INTEGER.

Referenced by mxvm_io_fread(), mxvm_io_fseek(), and mxvm_io_fwrite().

◆ x64_analyzeRegAlloc()

void mxvm::Program::x64_analyzeRegAlloc ( bool uses_std_module)

Analyze variable usage and assign Win64 callee-saved registers.

Parameters
uses_std_moduletrue if the program uses the std module (affects register choices)

Definition at line 39 of file icode_gen_x64.cpp.

References getVariable(), mxvm::Base::inc, mxvm::Variable::is_global, mxvm::is_stdio_name(), isVariable(), mxvm::Variable::type, mxvm::VAR_INTEGER, x64_reg_save_order, and x64_reg_vars.

Referenced by x64_generateCode().

◆ x64_direct_stack_adjust()

void mxvm::Program::x64_direct_stack_adjust ( std::ostream & out,
int64_t bytes )

Emit a direct stack pointer adjustment.

Parameters
outAssembly output stream
bytesPositive = allocate, negative = deallocate

◆ x64_emit_iob_func()

void mxvm::Program::x64_emit_iob_func ( std::ostream & out,
int index,
const std::string & dstReg )

Emit an integer-or-byte function argument load for Win64 ABI.

Parameters
outAssembly output stream
indexArgument index (determines register)
dstRegDestination register name

Definition at line 151 of file icode_gen_x64.cpp.

References x64_release_call_area(), and x64_reserve_call_area().

Referenced by x64_generateLoadVar(), and x64_generateLoadVar().

◆ x64_emitFlushRegs()

void mxvm::Program::x64_emitFlushRegs ( std::ostream & out)

Write all register-allocated variables back to memory.

Definition at line 80 of file icode_gen_x64.cpp.

References getMangledName(), and x64_reg_vars.

Referenced by x64_gen_call(), x64_gen_done(), x64_gen_load(), x64_gen_realloc(), x64_gen_ret(), and x64_gen_store().

◆ x64_emitLoadVar()

void mxvm::Program::x64_emitLoadVar ( std::ostream & out,
const std::string & dstReg,
const Operand & src )

Load a variable into a destination register.

Parameters
outAssembly output stream
dstRegDestination register name
srcSource operand

Definition at line 125 of file icode_gen_x64.cpp.

References getMangledName(), mxvm::Operand::op, and x64_reg_vars.

Referenced by x64_gen_alloc(), x64_gen_call(), x64_gen_load(), x64_gen_mov(), x64_gen_push(), x64_gen_realloc(), x64_gen_ret(), x64_gen_stack_store(), x64_gen_stack_sub(), and x64_gen_store().

◆ x64_emitReloadRegs()

void mxvm::Program::x64_emitReloadRegs ( std::ostream & out)

Reload register-allocated variables from memory.

Definition at line 86 of file icode_gen_x64.cpp.

References getMangledName(), and x64_reg_vars.

Referenced by x64_gen_call(), x64_gen_realloc(), x64_gen_store(), and x64_generateCode().

◆ x64_emitRestoreRegs()

void mxvm::Program::x64_emitRestoreRegs ( std::ostream & out)

Restore callee-saved registers at function epilogue.

Definition at line 99 of file icode_gen_x64.cpp.

References x64_reg_save_order, and mxvm::x64_sp_mod16.

Referenced by x64_gen_done(), and x64_gen_ret().

◆ x64_emitSaveRegs()

void mxvm::Program::x64_emitSaveRegs ( std::ostream & out)

Save callee-saved registers at function prologue.

Definition at line 92 of file icode_gen_x64.cpp.

References x64_reg_save_order, and mxvm::x64_sp_mod16.

Referenced by x64_generateCode().

◆ x64_emitStoreVar()

void mxvm::Program::x64_emitStoreVar ( std::ostream & out,
const std::string & srcReg,
const Operand & dest )

Store a register value into a variable (register-allocated or memory).

Parameters
outAssembly output stream
srcRegSource register name
destDestination operand

Definition at line 106 of file icode_gen_x64.cpp.

References getMangledName(), mxvm::Operand::op, and x64_reg_vars.

Referenced by x64_gen_arth(), x64_gen_bitop(), x64_gen_div(), x64_gen_load(), x64_gen_mod(), x64_gen_mov(), x64_gen_neg(), x64_gen_not(), x64_gen_pop(), x64_gen_return(), x64_gen_stack_load(), x64_gen_to_int(), and x64_generateCode().

◆ x64_emitStoreVarImm()

void mxvm::Program::x64_emitStoreVarImm ( std::ostream & out,
const std::string & imm,
const Operand & dest )

Store an immediate value into a variable.

Parameters
outAssembly output stream
immImmediate value string
destDestination operand

Definition at line 116 of file icode_gen_x64.cpp.

References getMangledName(), mxvm::Operand::op, and x64_reg_vars.

Referenced by x64_gen_mov().

◆ x64_gen_alloc()

◆ x64_gen_arth()

◆ x64_gen_bitop()

void mxvm::Program::x64_gen_bitop ( std::ostream & out,
const std::string & opc,
const Instruction & i )

◆ x64_gen_call()

◆ x64_gen_cmp()

◆ x64_gen_div()

◆ x64_gen_done()

void mxvm::Program::x64_gen_done ( std::ostream & out,
const Instruction & i )

◆ x64_gen_exit()

void mxvm::Program::x64_gen_exit ( std::ostream & out,
const Instruction & i )

◆ x64_gen_fcmp()

void mxvm::Program::x64_gen_fcmp ( std::ostream & out,
const Instruction & i )

◆ x64_gen_free()

◆ x64_gen_getline()

◆ x64_gen_invoke()

void mxvm::Program::x64_gen_invoke ( std::ostream & out,
const Instruction & i )

◆ x64_gen_jae()

void mxvm::Program::x64_gen_jae ( std::ostream & out,
const Instruction & i )

Definition at line 1699 of file icode_gen_x64.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by x64_generateInstruction().

◆ x64_gen_jbe()

void mxvm::Program::x64_gen_jbe ( std::ostream & out,
const Instruction & i )

Definition at line 1703 of file icode_gen_x64.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by x64_generateInstruction().

◆ x64_gen_jc()

void mxvm::Program::x64_gen_jc ( std::ostream & out,
const Instruction & i )

Definition at line 1707 of file icode_gen_x64.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by x64_generateInstruction().

◆ x64_gen_jmp()

void mxvm::Program::x64_gen_jmp ( std::ostream & out,
const Instruction & i )

◆ x64_gen_jnc()

void mxvm::Program::x64_gen_jnc ( std::ostream & out,
const Instruction & i )

Definition at line 1711 of file icode_gen_x64.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by x64_generateInstruction().

◆ x64_gen_jno()

void mxvm::Program::x64_gen_jno ( std::ostream & out,
const Instruction & i )

Definition at line 1727 of file icode_gen_x64.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by x64_generateInstruction().

◆ x64_gen_jnp()

void mxvm::Program::x64_gen_jnp ( std::ostream & out,
const Instruction & i )

Definition at line 1719 of file icode_gen_x64.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by x64_generateInstruction().

◆ x64_gen_jns()

void mxvm::Program::x64_gen_jns ( std::ostream & out,
const Instruction & i )

Definition at line 1735 of file icode_gen_x64.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by x64_generateInstruction().

◆ x64_gen_jo()

void mxvm::Program::x64_gen_jo ( std::ostream & out,
const Instruction & i )

Definition at line 1723 of file icode_gen_x64.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by x64_generateInstruction().

◆ x64_gen_jp()

void mxvm::Program::x64_gen_jp ( std::ostream & out,
const Instruction & i )

Definition at line 1715 of file icode_gen_x64.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by x64_generateInstruction().

◆ x64_gen_js()

void mxvm::Program::x64_gen_js ( std::ostream & out,
const Instruction & i )

Definition at line 1731 of file icode_gen_x64.cpp.

References mxvm::Operand::op, and mxvm::Instruction::op1.

Referenced by x64_generateInstruction().

◆ x64_gen_lea()

void mxvm::Program::x64_gen_lea ( std::ostream & out,
const Instruction & i )

◆ x64_gen_load()

◆ x64_gen_mod()

◆ x64_gen_mov()

◆ x64_gen_neg()

◆ x64_gen_not()

void mxvm::Program::x64_gen_not ( std::ostream & out,
const Instruction & i )

◆ x64_gen_pop()

◆ x64_gen_print()

void mxvm::Program::x64_gen_print ( std::ostream & out,
const Instruction & i )

◆ x64_gen_push()

◆ x64_gen_realloc()

void mxvm::Program::x64_gen_realloc ( std::ostream & out,
const Instruction & i )

Generate Win64 x86-64 assembly for the REALLOC instruction (dynamic array resize).

Generate Win64 x86-64 native code for REALLOC.

Uses the Win64 calling convention (rcx = ptr, rdx = size) for the C realloc() call. Shadow space is reserved. Registers are flushed/reloaded around the call.

Definition at line 804 of file icode_gen_x64.cpp.

References mxvm::error_label_count, getMangledName(), getVariable(), isVariable(), mxvm::Operand::op, mxvm::Instruction::op1, mxvm::Instruction::op2, mxvm::Instruction::op3, mxvm::Variable_Value::owns, mxvm::Variable::type, mxvm::VAR_POINTER, mxvm::Variable::var_value, x64_emitFlushRegs(), x64_emitLoadVar(), x64_emitReloadRegs(), x64_release_call_area(), and x64_reserve_call_area().

Referenced by x64_generateInstruction().

◆ x64_gen_ret()

void mxvm::Program::x64_gen_ret ( std::ostream & out,
const Instruction & i )

◆ x64_gen_return()

void mxvm::Program::x64_gen_return ( std::ostream & out,
const Instruction & i )

◆ x64_gen_stack_load()

void mxvm::Program::x64_gen_stack_load ( std::ostream & out,
const Instruction & i )

◆ x64_gen_stack_store()

void mxvm::Program::x64_gen_stack_store ( std::ostream & out,
const Instruction & i )

◆ x64_gen_stack_sub()

void mxvm::Program::x64_gen_stack_sub ( std::ostream & out,
const Instruction & i )

◆ x64_gen_store()

◆ x64_gen_to_float()

void mxvm::Program::x64_gen_to_float ( std::ostream & out,
const Instruction & i )

◆ x64_gen_to_int()

void mxvm::Program::x64_gen_to_int ( std::ostream & out,
const Instruction & i )

◆ x64_generateCode()

◆ x64_generateFunctionCall()

void mxvm::Program::x64_generateFunctionCall ( std::ostream & out,
const std::string & name,
std::vector< Operand > & args )

Generate a Win64 ABI function call with operands as arguments.

Parameters
outAssembly output stream
nameCallee function name
argsArgument operand list

Definition at line 257 of file icode_gen_x64.cpp.

References args, getVariable(), isVariable(), name, mxvm::Variable::type, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, x64_generateLoadVar(), x64_release_call_area(), x64_reserve_call_area(), and xmm_offset.

Referenced by x64_gen_exit(), x64_gen_print(), and x64_generateInvokeCall().

◆ x64_generateInstruction()

◆ x64_generateInvokeCall()

void mxvm::Program::x64_generateInvokeCall ( std::ostream & out,
std::vector< Operand > & op )

Generate a Win64 dynamic invoke call.

Parameters
outAssembly output stream
opOperand list

Definition at line 296 of file icode_gen_x64.cpp.

References mxvm::isFunctionReturningOwnedPtr(), last_call_returns_owned_ptr, and x64_generateFunctionCall().

Referenced by x64_gen_invoke().

◆ x64_generateLoadVar() [1/2]

int mxvm::Program::x64_generateLoadVar ( std::ostream & out,
int r,
const Operand & op )

◆ x64_generateLoadVar() [2/2]

int mxvm::Program::x64_generateLoadVar ( std::ostream & out,
VarType type,
std::string reg,
const Operand & op )

Load a variable or constant into a named Win64 register.

Parameters
outAssembly output stream
typeExpected variable type
regTarget register name
opOperand to load
Returns
1 if the operand was a constant, 0 if variable

Definition at line 160 of file icode_gen_x64.cpp.

References getMangledName(), getVariable(), mxvm::is_stdio_name(), isVariable(), mxvm::Operand::op, mxvm::OP_CONSTANT, mxvm::stdio_index(), mxvm::Operand::type, mxvm::Variable::type, mxvm::VAR_BYTE, mxvm::VAR_EXTERN, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, mxvm::VAR_POINTER, mxvm::VAR_STRING, x64_emit_iob_func(), and x64_reg_vars.

◆ x64_getRegisterByIndex()

std::string mxvm::Program::x64_getRegisterByIndex ( int index,
VarType type )

Get the Win64 register name for a given index and variable type.

Parameters
indexRegister index
typeVariable type (determines integer vs. XMM register)
Returns
Register name string

Definition at line 20 of file icode_gen_x64.cpp.

References mxvm::VAR_FLOAT.

Referenced by x64_generateLoadVar().

◆ x64_release_call_area()

void mxvm::Program::x64_release_call_area ( std::ostream & out,
size_t frame )

Release a Win64 call frame previously reserved.

Parameters
outAssembly output stream
frameFrame size to release

Definition at line 147 of file icode_gen_x64.cpp.

References mxvm::x64_sp_mod16.

Referenced by x64_emit_iob_func(), x64_gen_alloc(), x64_gen_call(), x64_gen_done(), x64_gen_exit(), x64_gen_free(), x64_gen_getline(), x64_gen_realloc(), x64_gen_to_int(), x64_generateCode(), and x64_generateFunctionCall().

◆ x64_reserve_call_area()

size_t mxvm::Program::x64_reserve_call_area ( std::ostream & out,
size_t spill_bytes )

Reserve stack space for a Win64 call frame including spill area.

Parameters
outAssembly output stream
spill_bytesAdditional spill bytes needed
Returns
Total frame size allocated (for matching release)

Definition at line 135 of file icode_gen_x64.cpp.

References mxvm::x64_sp_mod16.

Referenced by x64_emit_iob_func(), x64_gen_alloc(), x64_gen_call(), x64_gen_done(), x64_gen_exit(), x64_gen_free(), x64_gen_getline(), x64_gen_realloc(), x64_gen_to_int(), x64_generateCode(), and x64_generateFunctionCall().

◆ Parser

friend class Parser
friend

Definition at line 214 of file icode.hpp.

References Parser.

Referenced by Parser.

Member Data Documentation

◆ args

◆ carry_flag

bool mxvm::Program::carry_flag = false
private

comparison carry flag

Definition at line 405 of file icode.hpp.

Referenced by exec_jc(), exec_jnc(), and operator=().

◆ exitCode

int mxvm::Program::exitCode = 0
private

Definition at line 401 of file icode.hpp.

Referenced by exec_done(), exec_exit(), getExitCode(), and operator=().

◆ filename

std::string mxvm::Program::filename

Definition at line 307 of file icode.hpp.

Referenced by operator=().

◆ greater_flag

bool mxvm::Program::greater_flag = false
private

comparison greater-than flag

Definition at line 404 of file icode.hpp.

Referenced by exec_cmp(), exec_fcmp(), exec_ja(), exec_jae(), exec_jg(), exec_jge(), and operator=().

◆ last_call_ret_type

VarType mxvm::Program::last_call_ret_type = VarType::VAR_INTEGER

Definition at line 881 of file icode.hpp.

◆ last_call_returns_owned

bool mxvm::Program::last_call_returns_owned = false

Definition at line 880 of file icode.hpp.

◆ last_call_returns_owned_ptr

bool mxvm::Program::last_call_returns_owned_ptr = false
private

tracks ownership of last call's return value

Definition at line 418 of file icode.hpp.

Referenced by gen_return(), generateInvokeCall(), x64_gen_return(), and x64_generateInvokeCall().

◆ last_cmp_type

LastCmpType mxvm::Program::last_cmp_type = CMP_NONE
private

◆ less_flag

bool mxvm::Program::less_flag = false
private

comparison less-than flag

Definition at line 403 of file icode.hpp.

Referenced by exec_cmp(), exec_fcmp(), exec_jb(), exec_jbe(), exec_jl(), exec_jle(), and operator=().

◆ main_function

bool mxvm::Program::main_function
private

true if this program has a main entry point

Definition at line 408 of file icode.hpp.

Referenced by operator=().

◆ name

◆ object

bool mxvm::Program::object = false

Definition at line 341 of file icode.hpp.

◆ object_external

bool mxvm::Program::object_external = false
private

Definition at line 409 of file icode.hpp.

Referenced by operator=().

◆ objects

std::vector<std::unique_ptr<Program> > mxvm::Program::objects

Definition at line 340 of file icode.hpp.

Referenced by flatten(), getObjectByName(), memoryDump(), operator=(), and validateNames().

◆ parent

Program* mxvm::Program::parent = nullptr

parent program (for object programs)

Definition at line 860 of file icode.hpp.

Referenced by operator=().

◆ pc

◆ platform

Platform mxvm::Program::platform

◆ result

Operand mxvm::Program::result

return value operand from last invoke

Definition at line 859 of file icode.hpp.

Referenced by escapeNewLines(), exec_invoke(), exec_return(), and operator=().

◆ running

bool mxvm::Program::running
private

interpreter running flag

Definition at line 400 of file icode.hpp.

Referenced by Program(), exec(), operator=(), and stop().

◆ stack

Stack mxvm::Program::stack

◆ sysv_reg_save_order

std::vector<std::string> mxvm::Program::sysv_reg_save_order

Definition at line 678 of file icode.hpp.

Referenced by sysv_analyzeRegAlloc(), sysv_emitRestoreRegs(), and sysv_emitSaveRegs().

◆ sysv_reg_vars

std::unordered_map<std::string, std::string> mxvm::Program::sysv_reg_vars

◆ x64_reg_save_order

std::vector<std::string> mxvm::Program::x64_reg_save_order

Definition at line 634 of file icode.hpp.

Referenced by x64_analyzeRegAlloc(), x64_emitRestoreRegs(), and x64_emitSaveRegs().

◆ x64_reg_vars

std::unordered_map<std::string, std::string> mxvm::Program::x64_reg_vars

◆ xmm_offset

int mxvm::Program::xmm_offset = 0
private

current XMM register allocation offset

Definition at line 406 of file icode.hpp.

Referenced by gen_print(), generateFunctionCall(), getRegisterByIndex(), operator=(), x64_gen_print(), and x64_generateFunctionCall().

◆ zero_flag

bool mxvm::Program::zero_flag = false
private

comparison zero flag

Definition at line 402 of file icode.hpp.

Referenced by exec_cmp(), exec_fcmp(), exec_jae(), exec_jbe(), exec_je(), exec_jge(), exec_jle(), exec_jne(), exec_jnz(), exec_jz(), and operator=().


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