![]() |
V-Gears 0
Free Final Fantasy VII engine.
|
The code generator. More...
#include <FieldCodeGenerator.h>
Public Types | |
enum struct | ValueType : int { Integer = 0 , Float = 1 } |
Type of data. More... | |
Public Member Functions | |
FieldCodeGenerator (Engine *engine, const InstVec &insts, std::ostream &output, FieldScriptFormatter &formatter) | |
Constructor. More... | |
virtual void | Generate (InstVec &insts, const Graph &graph) override |
Generates the script from the instructions. More... | |
virtual void | AddOutputLine (std::string line, bool unindent_before=false, bool indent_after=false) override |
Adds a line to the script. More... | |
float | GetScaleFactor () const |
Retrieves the engine scale factor. More... | |
FieldScriptFormatter & | GetFormatter () |
Retrieves the formatter. More... | |
![]() | |
CodeGenerator (Engine *engine, std::ostream &output, ARGUMENT_ORDER bin_order, ARGUMENT_ORDER call_order) | |
Constructor. More... | |
virtual | ~CodeGenerator () |
Destructor. More... | |
LuaLanguage & | GetLanguage () |
Retrieves the target language. More... | |
void | WriteFunctionCall (std::string function_name, std::string param_format, const std::vector< ValuePtr > ¶ms) |
Writes a function call. More... | |
virtual void | Generate (InstVec &insts, const Graph &graph) |
Generates code from the provided graph and outputs it to stdout. More... | |
virtual void | AddOutputLine (std::string line, bool unindent_before=false, bool indent_after=false) |
Adds a line of code to the current group. More... | |
void | WriteTodo (std::string class_name, std::string instruction) |
Writes a comment line indicating an unimplemented opcode. More... | |
void | WriteAssignment (ValuePtr dst, ValuePtr src) |
Generate an assignment statement. More... | |
void | AddArg (ValuePtr arg) |
Add an argument to the argument list. More... | |
virtual void | ProcessSpecialMetadata (const InstPtr inst, char c, int pos) |
Process a single character of metadata. More... | |
virtual ValueList | GetArgList () |
Retrieves the argument list. More... | |
virtual ARGUMENT_ORDER | GetBinaryOrder () |
Retrieves the order of operands for binary operations. More... | |
Static Public Member Functions | |
static const std::string | FormatInstructionNotImplemented (const std::string &entity, uint32 address, uint32 opcode) |
Generates code for an unimplemented instruction. More... | |
static const std::string | FormatInstructionNotImplemented (const std::string &entity, uint32 address, const Instruction &instruction) |
Generates code for an unimplemented instruction. More... | |
static const std::string | FormatBool (uint32 value) |
Formats a value as a boolean. More... | |
static const std::string | FormatInvertedBool (uint32 value) |
Formats a value as a boolean. More... | |
template<typename TValue > | |
static const std::string | FormatValueOrVariable (FieldScriptFormatter &formatter, uint32 bank, TValue value_or_address, ValueType type=ValueType::Integer, float scale=1.0f) |
Formats a data access for a map script. More... | |
Protected Member Functions | |
virtual std::string | ConstructFuncSignature (const Function &function) override |
Constructs the function signature. More... | |
virtual void | OnEndFunction (const Function &function) override |
Finalizes a function. More... | |
virtual void | OnBeforeStartFunction (const Function &function) override |
Adds lines to the script before a function. More... | |
virtual void | OnStartFunction (const Function &function) override |
Initializes a function. More... | |
virtual bool | OutputOnlyRequiredLabels () const override |
Checks if only required labels are to be written. More... | |
![]() | |
void | ProcessInst (Function &function, InstVec &insts, const InstPtr inst) |
Processes an instruction. More... | |
void | ProcessUncondJumpInst (Function &function, InstVec &insts, const InstPtr inst) |
Processes an unconditional jump instruction. More... | |
void | ProcessCondJumpInst (const InstPtr inst) |
Processes a conditional jump instruction. More... | |
std::string | IndentString (std::string s) |
Indents a string according to the current indentation level. More... | |
virtual std::string | ConstructFuncSignature (const Function &function) |
Construct the signature for a function. More... | |
virtual void | OnBeforeStartFunction (const Function &function) |
Adds lines to the script before a function. More... | |
virtual void | OnEndFunction (const Function &function) |
Adds lines to the script at the end a function. More... | |
virtual void | OnStartFunction (const Function &function) |
Adds lines to the script before a function instructions. More... | |
virtual bool | OutputOnlyRequiredLabels () const |
Checks if only required labels are to be written. More... | |
void | GeneratePass (InstVec &insts, const Graph &graph) |
Generates a pass. More... | |
Private Attributes | |
const InstVec & | insts_ |
The list of instructions in the function to generate. More... | |
std::vector< CodeLine > | lines_ |
Generated lines. More... | |
FieldScriptFormatter & | formatter_ |
The formatter. More... | |
Additional Inherited Members | |
![]() | |
bool | is_label_pass_ = true |
Indicates if a label is being processed. More... | |
GroupPtr | cur_group_ |
The group currently being processed. More... | |
Engine * | engine_ |
The engine used for teh script. More... | |
std::ostream & | output_ |
The stream to output the code to. More... | |
ValueStack | stack_ |
The stack currently being processed. More... | |
uint | indent_level_ |
Current indentation level. More... | |
GraphVertex | cur_vertex_ |
Graph vertex currently being processed. More... | |
std::unique_ptr< LuaLanguage > | target_lang_ |
The target language. More... | |
The code generator.
Generates code for a field map function.
|
strong |
|
inline |
Constructor.
[in] | engine | The engine. |
[in] | insts | The list of instructions to parse. |
[out] | output | The generated script. |
[in] | formatter | The code formatter. |
|
overridevirtual |
Adds a line to the script.
[in] | line | The line to add. |
[in] | unindent_before | If true, the current script indentation will be moved back one position before the line. |
[in] | indent_after | If true, the current script indentation will be moved forward one position after the line. |
Reimplemented from CodeGenerator.
|
overrideprotectedvirtual |
Constructs the function signature.
The function signature is the LUA function declaration, and it looks like this:
function_name = function(self)
[in] | function | The function to construct the signature for. |
Reimplemented from CodeGenerator.
|
static |
Formats a value as a boolean.
[in] | value | The value to format. |
|
static |
Generates code for an unimplemented instruction.
The code will actually be a comment, indicating where the function call must have been.
[in] | entity | The entity name. |
[in] | address | The address of the instruction. |
[in] | instruction | The unimplemented instruction. |
|
static |
Generates code for an unimplemented instruction.
The code will actually be a comment, indicating where the function call must have been.
[in] | entity | The entity name. |
[in] | address | The address of the instruction. |
[in] | opcode | The opcode not implemented. |
|
static |
Formats a value as a boolean.
[in] | value | The value to format. |
|
inlinestatic |
Formats a data access for a map script.
If possible, it will look for friendly names for variables.
[in] | formatter | Formatter to look up variable friendly names. |
[in] | bank | The memory bank to use. |
[in] | value_or_address | The value or memory address to use. When bank is 0, it will be considered as a value. When bank is non 0, it will be considered an address of the bank. |
[in] | type | Data type to use. Used only when getting a value, not a bank address. |
[in] | scale | Scale to scale values to. Used only when using float values, unused when type is integer or when using a bank address. |
Generates the script from the instructions.
[in] | insts | The list of instructions. |
[in] | graph | Code graph, unused. |
Reimplemented from CodeGenerator.
FieldScriptFormatter & FieldCodeGenerator::GetFormatter | ( | ) |
Retrieves the formatter.
float FieldCodeGenerator::GetScaleFactor | ( | ) | const |
Retrieves the engine scale factor.
|
overrideprotectedvirtual |
Adds lines to the script before a function.
If the function is the first in a class, it initializes the class and, if the function belongs to a character, creates the class variable for the character. If the function has a comment associated, it will also be added before the function.
[in] | function | The function about to start. |
Reimplemented from CodeGenerator.
|
overrideprotectedvirtual |
Finalizes a function.
It appends an "end" to finalize the function. If the function is the last of a class, it also closes the class braces.
[in] | function | The function to end. |
Reimplemented from CodeGenerator.
|
overrideprotectedvirtual |
Initializes a function.
It adds a comment with the function opcodes.
[in] | function | The function to start. |
Reimplemented from CodeGenerator.
|
overrideprotectedvirtual |
Checks if only required labels are to be written.
Reimplemented from CodeGenerator.
|
private |
The formatter.
|
private |
The list of instructions in the function to generate.
|
private |
Generated lines.