20#include <boost/format.hpp>
21#include <boost/intrusive_ptr.hpp>
43typedef boost::intrusive_ptr<Instruction>
InstPtr;
127 return inst->
Print(output);
136 virtual std::ostream&
Print(std::ostream &output)
const;
143 virtual bool IsJump()
const;
199 virtual bool IsLoad()
const;
264 void SetName(std::string name);
302 void SetParams(std::vector<ValuePtr> params);
void SetOutputStackEffect(bool value)
Changes whether or not to output the stack effect for an instruction.
Definition: Instruction.cpp:22
InstVec::iterator InstIterator
Type representing an iterator over InstPtrs.
Definition: Instruction.h:387
boost::intrusive_ptr< Instruction > InstPtr
Pointer to an Instruction.
Definition: Instruction.h:43
InstVec::const_iterator ConstInstIterator
Type representing a const_iterator over InstPtrs.
Definition: Instruction.h:392
std::vector< InstPtr > InstVec
Type representing a vector of InstPtrs.
Definition: Instruction.h:382
boost::intrusive_ptr< Value > ValuePtr
Pointer to a Value.
Definition: Value.h:93
Base class for code generators.
Definition: CodeGenerator.h:58
Base class for engines.
Definition: Engine.h:34
Structure for representing an instruction.
Definition: Instruction.h:50
std::string code_gen_data_
String containing metadata for code generation.
Definition: Instruction.h:371
friend std::ostream & operator<<(std::ostream &output, const Instruction *inst)
Operator overload to output an Instruction to a stream.
Definition: Instruction.h:126
virtual void ProcessInst(Function &function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen)=0
Process an instruction for code generation.
uint32 GetAddress() const
Retrieves the instruction address.
Definition: Instruction.cpp:85
virtual bool IsStore() const
Checks if the instruction is a store operation.
Definition: Instruction.cpp:77
static int INST_TYPE_JUMP
Unconditional jump.
Definition: Instruction.h:82
virtual uint32 GetDestAddress() const
Returns the destination address of a jump instruction.
Definition: Instruction.cpp:79
static int INST_TYPE_CALL
Regular function call.
Definition: Instruction.h:67
static int INST_TYPE_UNARY_OP_PRE
Unary operation (e.g.
Definition: Instruction.h:112
static int INST_TYPE_STACK
Stack allocation or deallocation (altering stack pointer).
Definition: Instruction.h:102
virtual bool IsJump() const
Checks if the instruction is a jump of some sort.
Definition: Instruction.cpp:61
virtual bool IsUncondJump() const
Checks if the instruction is an unconditional jump.
Definition: Instruction.cpp:65
std::string name_
The instruction name (opcode name).
Definition: Instruction.h:354
int16 GetStackChange() const
Checks how much the instruction changes the stack pointer.
Definition: Instruction.cpp:93
static int INST_TYPE_COND_JUMP
Conditional jump.
Definition: Instruction.h:72
static int INST_TYPE_LOAD
Load value from memory.
Definition: Instruction.h:92
uint32 GetOpcode() const
Retrieves the instruction opcode.
Definition: Instruction.cpp:81
void SetAddress(uint32 address)
Sets the instruction address.
Definition: Instruction.cpp:87
bool LabelRequired() const
Checks if the instruction requires a label.
Definition: Instruction.cpp:112
std::string GetName() const
Retrieves the instruction name (the opcode name).
Definition: Instruction.cpp:89
static int INST_TYPE_UNARY_OP_POST
Unary operation with operator placed after the operator.
Definition: Instruction.h:117
virtual bool IsFuncCall() const
Checks if the instruction is a call to a script function.
Definition: Instruction.cpp:69
std::string GetCodeGenData() const
Retrieves metadata for code generation.
Definition: Instruction.cpp:108
virtual bool IsKernelCall() const
Checks if the instruction is a call to a kernel function.
Definition: Instruction.cpp:73
static int INST_TYPE_BOOL_NEGATE
Boolean negation.
Definition: Instruction.h:62
virtual bool IsCondJump() const
Checks if the instruction is a conditional jump.
Definition: Instruction.cpp:63
static int INST_TYPE_STORE
Store value in memory.
Definition: Instruction.h:107
std::vector< ValuePtr > params_
Array of parameters used for the instruction.
Definition: Instruction.h:364
virtual bool IsLoad() const
Checks if the instruction is a load operation.
Definition: Instruction.cpp:75
int16 stack_change_
How much this instruction changes the stack pointer by.
Definition: Instruction.h:359
void SetStackChange(int16 stack_change)
Defines how much the instruction changes the stack pointer.
Definition: Instruction.cpp:95
ValuePtr GetParam(uint32 index) const
Retrieves a instruction parameter.
Definition: Instruction.cpp:99
uint32 opcode_
The instruction opcode.
Definition: Instruction.h:344
void SetCodeGenData(std::string code_gen_data)
Sets metadata for code generation.
Definition: Instruction.cpp:110
void SetParams(std::vector< ValuePtr > params)
Sets the instructions parameters.
Definition: Instruction.cpp:104
void AddParam(ValuePtr value)
Adds a parameter to the instructions.
Definition: Instruction.cpp:106
static int INST_TYPE_RETURN
Return from regular function call.
Definition: Instruction.h:97
void SetLabelRequired(bool required)
Indicates if the instruction needs a label.
Definition: Instruction.cpp:114
virtual bool IsReturn() const
Checks if the instruction is a return statement.
Definition: Instruction.cpp:71
uint32 address_
The instruction address.
Definition: Instruction.h:349
void SetName(std::string name)
Definition: Instruction.cpp:91
static int INST_TYPE_BINARY_OP
Binary operation (e.g.
Definition: Instruction.h:57
bool label_required_
Indicates if a label is required.
Definition: Instruction.h:376
std::vector< ValuePtr > GetParams() const
Retrieves the list of instruction parameters.
Definition: Instruction.cpp:97
static int INST_TYPE_DUP
Instruction duplicates the most recent stack entry.
Definition: Instruction.h:77
void SetOpcode(uint32 opcode)
Sets the instruction opcode.
Definition: Instruction.cpp:83
static int INST_TYPE_KERNEL_CALL
Kernel functions.
Definition: Instruction.h:87
virtual std::ostream & Print(std::ostream &output) const
Print the instruction to a stream.
Definition: Instruction.cpp:50
virtual bool IsStackOp() const
Checks if the instruction is a stack operation.
Definition: Instruction.cpp:67
Provides a base implementation of reference counting.
Definition: RefCounted.h:28
unsigned int uint32
Definition: scummsys.h:435
signed short int16
Definition: scummsys.h:434
Structure representing a function.
Definition: Function.h:26