V-Gears 0
Free Final Fantasy VII engine.
Instruction Class Referenceabstract

Structure for representing an instruction. More...

#include <Instruction.h>

Inheritance diagram for Instruction:
Collaboration diagram for Instruction:

Public Member Functions

virtual std::ostream & Print (std::ostream &output) const
 Print the instruction to a stream. More...
 
virtual bool IsJump () const
 Checks if the instruction is a jump of some sort. More...
 
virtual bool IsCondJump () const
 Checks if the instruction is a conditional jump. More...
 
virtual bool IsUncondJump () const
 Checks if the instruction is an unconditional jump. More...
 
virtual bool IsStackOp () const
 Checks if the instruction is a stack operation. More...
 
virtual bool IsFuncCall () const
 Checks if the instruction is a call to a script function. More...
 
virtual bool IsReturn () const
 Checks if the instruction is a return statement. More...
 
virtual bool IsKernelCall () const
 Checks if the instruction is a call to a kernel function. More...
 
virtual bool IsLoad () const
 Checks if the instruction is a load operation. More...
 
virtual bool IsStore () const
 Checks if the instruction is a store operation. More...
 
virtual uint32 GetDestAddress () const
 Returns the destination address of a jump instruction. More...
 
virtual void ProcessInst (Function &function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen)=0
 Process an instruction for code generation. More...
 
uint32 GetOpcode () const
 Retrieves the instruction opcode. More...
 
void SetOpcode (uint32 opcode)
 Sets the instruction opcode. More...
 
uint32 GetAddress () const
 Retrieves the instruction address. More...
 
void SetAddress (uint32 address)
 Sets the instruction address. More...
 
std::string GetName () const
 Retrieves the instruction name (the opcode name). More...
 
void SetName (std::string name)
 
int16 GetStackChange () const
 Checks how much the instruction changes the stack pointer. More...
 
void SetStackChange (int16 stack_change)
 Defines how much the instruction changes the stack pointer. More...
 
std::vector< ValuePtrGetParams () const
 Retrieves the list of instruction parameters. More...
 
ValuePtr GetParam (uint32 index) const
 Retrieves a instruction parameter. More...
 
void SetParams (std::vector< ValuePtr > params)
 Sets the instructions parameters. More...
 
void AddParam (ValuePtr value)
 Adds a parameter to the instructions. More...
 
std::string GetCodeGenData () const
 Retrieves metadata for code generation. More...
 
void SetCodeGenData (std::string code_gen_data)
 Sets metadata for code generation. More...
 
bool LabelRequired () const
 Checks if the instruction requires a label. More...
 
void SetLabelRequired (bool required)
 Indicates if the instruction needs a label. More...
 

Static Public Attributes

static int INST_TYPE_BINARY_OP
 Binary operation (e.g. More...
 
static int INST_TYPE_BOOL_NEGATE
 Boolean negation. More...
 
static int INST_TYPE_CALL
 Regular function call. More...
 
static int INST_TYPE_COND_JUMP
 Conditional jump. More...
 
static int INST_TYPE_DUP
 Instruction duplicates the most recent stack entry. More...
 
static int INST_TYPE_JUMP
 Unconditional jump. More...
 
static int INST_TYPE_KERNEL_CALL
 Kernel functions. More...
 
static int INST_TYPE_LOAD
 Load value from memory. More...
 
static int INST_TYPE_RETURN
 Return from regular function call. More...
 
static int INST_TYPE_STACK
 Stack allocation or deallocation (altering stack pointer). More...
 
static int INST_TYPE_STORE
 Store value in memory. More...
 
static int INST_TYPE_UNARY_OP_PRE
 Unary operation (e.g. More...
 
static int INST_TYPE_UNARY_OP_POST
 Unary operation with operator placed after the operator. More...
 

Protected Attributes

uint32 opcode_
 The instruction opcode. More...
 
uint32 address_
 The instruction address. More...
 
std::string name_
 The instruction name (opcode name). More...
 
int16 stack_change_
 How much this instruction changes the stack pointer by. More...
 
std::vector< ValuePtrparams_
 Array of parameters used for the instruction. More...
 
std::string code_gen_data_
 String containing metadata for code generation. More...
 
bool label_required_ = false
 Indicates if a label is required. More...
 

Friends

std::ostream & operator<< (std::ostream &output, const Instruction *inst)
 Operator overload to output an Instruction to a stream. More...
 

Additional Inherited Members

- Protected Member Functions inherited from RefCounted
 RefCounted ()
 
virtual ~RefCounted ()
 

Detailed Description

Structure for representing an instruction.

Member Function Documentation

◆ AddParam()

void Instruction::AddParam ( ValuePtr  value)

Adds a parameter to the instructions.

Parameters
[in]valueThe parameter to add.

◆ GetAddress()

uint32 Instruction::GetAddress ( ) const

Retrieves the instruction address.

Returns
The address.

◆ GetCodeGenData()

std::string Instruction::GetCodeGenData ( ) const

Retrieves metadata for code generation.

See the extended documentation for details.

Returns
Code generator metadata.

◆ GetDestAddress()

uint32 Instruction::GetDestAddress ( ) const
virtual

Returns the destination address of a jump instruction.

Returns
Destination address of a jump instruction.
Exceptions
WrongTypeExceptionif instruction is not a jump.

Reimplemented in FieldUncondJumpInstruction, WorldCondJumpInstruction, WorldUncondJumpInstruction, and FieldCondJumpInstruction.

◆ GetName()

std::string Instruction::GetName ( ) const

Retrieves the instruction name (the opcode name).

Returns
The name.

◆ GetOpcode()

uint32 Instruction::GetOpcode ( ) const

Retrieves the instruction opcode.

Returns
The opcode.

◆ GetParam()

ValuePtr Instruction::GetParam ( uint32  index) const

Retrieves a instruction parameter.

Parameters
[in]indexIndex of the parameter to retrieve.
Returns
The parameter at the specified index, or nullptr if there is not that many parameters.

◆ GetParams()

std::vector< ValuePtr > Instruction::GetParams ( ) const

Retrieves the list of instruction parameters.

Returns
The list of parameters.

◆ GetStackChange()

int16 Instruction::GetStackChange ( ) const

Checks how much the instruction changes the stack pointer.

Returns
The stack pointer change, in bytes.

◆ IsCondJump()

bool Instruction::IsCondJump ( ) const
virtual

Checks if the instruction is a conditional jump.

Returns
True if the instruction is a conditional jump, false otherwise.

Reimplemented in CondJumpInstruction.

◆ IsFuncCall()

bool Instruction::IsFuncCall ( ) const
virtual

Checks if the instruction is a call to a script function.

Returns
True if the instruction is a script function call, false otherwise.

Reimplemented in FieldUncondJumpInstruction, CallInstruction, and WorldUncondJumpInstruction.

◆ IsJump()

bool Instruction::IsJump ( ) const
virtual

Checks if the instruction is a jump of some sort.

Returns
True if the instruction is a jump, otherwise false.

◆ IsKernelCall()

bool Instruction::IsKernelCall ( ) const
virtual

Checks if the instruction is a call to a kernel function.

Returns
True if the instruction is a kernel function call, false otherwise.

Reimplemented in KernelCallInstruction.

◆ IsLoad()

bool Instruction::IsLoad ( ) const
virtual

Checks if the instruction is a load operation.

Returns
True if the instruction is a load operation, false otherwise.

Reimplemented in LoadInstruction.

◆ IsReturn()

bool Instruction::IsReturn ( ) const
virtual

Checks if the instruction is a return statement.

Returns
True if the instruction is a return statement, false otherwise.

Reimplemented in ReturnInstruction.

◆ IsStackOp()

bool Instruction::IsStackOp ( ) const
virtual

Checks if the instruction is a stack operation.

Returns
True if the instruction is a stack operation, false otherwise.

Reimplemented in StackInstruction.

◆ IsStore()

bool Instruction::IsStore ( ) const
virtual

Checks if the instruction is a store operation.

Returns
True if the instruction is a store operation, false otherwise.

Reimplemented in StoreInstruction.

◆ IsUncondJump()

bool Instruction::IsUncondJump ( ) const
virtual

Checks if the instruction is an unconditional jump.

Returns
True if the instruction is an unconditional jump, false otherwise.

Reimplemented in FieldUncondJumpInstruction, WorldUncondJumpInstruction, and UncondJumpInstruction.

◆ LabelRequired()

bool Instruction::LabelRequired ( ) const

Checks if the instruction requires a label.

◆ Print()

std::ostream & Instruction::Print ( std::ostream &  output) const
virtual

Print the instruction to a stream.

Parameters
[out]outputThe stream to write to.
Returns
The stream used for output.

Reimplemented in FieldCondJumpInstruction, FieldUncondJumpInstruction, WorldCondJumpInstruction, and WorldUncondJumpInstruction.

◆ ProcessInst()

◆ SetAddress()

void Instruction::SetAddress ( uint32  address)

Sets the instruction address.

Parameters
[in]addressThe address.

◆ SetCodeGenData()

void Instruction::SetCodeGenData ( std::string  code_gen_data)

Sets metadata for code generation.

See the extended documentation for details.

Parameters
[in]code_gen_dataCode generator metadata.

◆ SetLabelRequired()

void Instruction::SetLabelRequired ( bool  required)

Indicates if the instruction needs a label.

◆ SetName()

void Instruction::SetName ( std::string  name)

◆ SetOpcode()

void Instruction::SetOpcode ( uint32  opcode)

Sets the instruction opcode.

Parameters
[in]opcodeThe opcode.

◆ SetParams()

void Instruction::SetParams ( std::vector< ValuePtr params)

Sets the instructions parameters.

Parameters
[in]paramsThe list of instruction parameters.

◆ SetStackChange()

void Instruction::SetStackChange ( int16  stack_change)

Defines how much the instruction changes the stack pointer.

Parameters
[in]stack_changeBytes the instruction changes the stack pointer by.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  output,
const Instruction inst 
)
friend

Operator overload to output an Instruction to a stream.

Parameters
[out]outputThe stream to output to.
[in]instThe Instruction to output.
Returns
The stream used for output.

Member Data Documentation

◆ address_

uint32 Instruction::address_
protected

The instruction address.

◆ code_gen_data_

std::string Instruction::code_gen_data_
protected

String containing metadata for code generation.

See the extended documentation for details.

◆ INST_TYPE_BINARY_OP

int Instruction::INST_TYPE_BINARY_OP
static

Binary operation (e.g.

+, &&, etc.), including comparisons.

◆ INST_TYPE_BOOL_NEGATE

int Instruction::INST_TYPE_BOOL_NEGATE
static

Boolean negation.

◆ INST_TYPE_CALL

int Instruction::INST_TYPE_CALL
static

Regular function call.

◆ INST_TYPE_COND_JUMP

int Instruction::INST_TYPE_COND_JUMP
static

Conditional jump.

◆ INST_TYPE_DUP

int Instruction::INST_TYPE_DUP
static

Instruction duplicates the most recent stack entry.

◆ INST_TYPE_JUMP

int Instruction::INST_TYPE_JUMP
static

Unconditional jump.

◆ INST_TYPE_KERNEL_CALL

int Instruction::INST_TYPE_KERNEL_CALL
static

Kernel functions.

◆ INST_TYPE_LOAD

int Instruction::INST_TYPE_LOAD
static

Load value from memory.

◆ INST_TYPE_RETURN

int Instruction::INST_TYPE_RETURN
static

Return from regular function call.

◆ INST_TYPE_STACK

int Instruction::INST_TYPE_STACK
static

Stack allocation or deallocation (altering stack pointer).

◆ INST_TYPE_STORE

int Instruction::INST_TYPE_STORE
static

Store value in memory.

◆ INST_TYPE_UNARY_OP_POST

int Instruction::INST_TYPE_UNARY_OP_POST
static

Unary operation with operator placed after the operator.

◆ INST_TYPE_UNARY_OP_PRE

int Instruction::INST_TYPE_UNARY_OP_PRE
static

Unary operation (e.g.

!) with operator placed before the operator.

◆ label_required_

bool Instruction::label_required_ = false
protected

Indicates if a label is required.

◆ name_

std::string Instruction::name_
protected

The instruction name (opcode name).

◆ opcode_

uint32 Instruction::opcode_
protected

The instruction opcode.

◆ params_

std::vector<ValuePtr> Instruction::params_
protected

Array of parameters used for the instruction.

◆ stack_change_

int16 Instruction::stack_change_
protected

How much this instruction changes the stack pointer by.


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