![]() |
V-Gears 0
Free Final Fantasy VII engine.
|
Base class for code generators. More...
#include <CodeGenerator.h>
Public Member Functions | |
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... | |
Protected Member Functions | |
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... | |
Protected Attributes | |
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... | |
Private Member Functions | |
void | Process (Function &function, InstVec &insts, GraphVertex vertex) |
Processes a GraphVertex. More... | |
Private Attributes | |
Graph | graph_ |
The annotated graph of the script. More... | |
const ARGUMENT_ORDER | bin_order_ |
Order of operands for binary operations. More... | |
const ARGUMENT_ORDER | call_order_ |
Order of operands for call arguments. More... | |
ValueList | arg_list_ |
Lists of arguments to be built when processing function calls. More... | |
Base class for code generators.
This is to be overriden by each engine.
CodeGenerator::CodeGenerator | ( | Engine * | engine, |
std::ostream & | output, | ||
ARGUMENT_ORDER | bin_order, | ||
ARGUMENT_ORDER | call_order | ||
) |
Constructor.
[in] | engine | The engine used for the script. |
[out] | output | The stream to output the code to. |
[in] | bin_order | Order of arguments for binary operators. |
[in] | call_order | Order of arguments for function calls. |
|
virtual |
Destructor.
Does nothing.
void CodeGenerator::AddArg | ( | ValuePtr | arg | ) |
Add an argument to the argument list.
[in] | arg | The argument to add. |
|
virtual |
Adds a line of code to the current group.
[in] | line | The line to add. |
[in] | unindent_before | Whether or not to remove an indentation level before the line. Defaults to false. |
[in] | indent_after | Whether or not to add an indentation level after the line. Defaults to false. |
Reimplemented in FieldCodeGenerator.
|
protectedvirtual |
Construct the signature for a function.
[in] | function | Reference to the function to construct the signature for. |
Reimplemented in WorldCodeGenerator, and FieldCodeGenerator.
Generates code from the provided graph and outputs it to stdout.
[in] | insts | The list of instructions. |
[in] | graph | The annotated graph of the script. |
Reimplemented in FieldCodeGenerator.
Generates a pass.
[in] | insts | The list of instructions. |
[in] | graph | The code graph. |
|
virtual |
Retrieves the argument list.
|
virtual |
Retrieves the order of operands for binary operations.
LuaLanguage & CodeGenerator::GetLanguage | ( | ) |
Retrieves the target language.
|
protected |
Indents a string according to the current indentation level.
[in] | s | The string to indent. |
|
protectedvirtual |
Adds lines to the script before a function.
Called before writing a function start. For this base class, it does nothing.
[in] | function | The function about to start. |
Reimplemented in FieldCodeGenerator.
|
protectedvirtual |
Adds lines to the script at the end a function.
Called after writing a function. For this base class, it adds a closing bracer "}".
[in] | function | The function about to end. |
Reimplemented in FieldCodeGenerator.
|
protectedvirtual |
Adds lines to the script before a function instructions.
Called after writing a function start. For this base class, it does nothing.
[in] | function | The function starting. |
Reimplemented in FieldCodeGenerator.
|
protectedvirtual |
Checks if only required labels are to be written.
Reimplemented in FieldCodeGenerator.
|
private |
Processes a GraphVertex.
[in] | function | The function to process. |
[in] | insts | The list of instructions. |
[in] | vertex | The vertex to process. |
|
protected |
Processes a conditional jump instruction.
Called by {
[in] | inst | The instruction to process. |
|
protected |
Processes an instruction.
Called by {
[in] | function | The function the instruction is is. |
[in] | inst | The instruction to process. |
[in] | insts | Every instruction in the function. |
|
virtual |
Process a single character of metadata.
[in] | inst | The instruction being processed. Unused. |
[in] | c | The character signifying the action to be taken. The only valid one is 'p'. |
[in] | pos | The position at which c occurred in the metadata. Unused. |
Reimplemented in WorldCodeGenerator.
|
protected |
Processes an unconditional jump instruction.
Called by {
[in] | function | The function the instruction is is. |
[in] | inst | The instruction to process. |
[in] | insts | Every instruction in the function. |
Generate an assignment statement.
[in] | dst | The variable being assigned to. |
[in] | src | The value being assigned. |
void CodeGenerator::WriteFunctionCall | ( | std::string | function_name, |
std::string | param_format, | ||
const std::vector< ValuePtr > & | params | ||
) |
Writes a function call.
[in] | function_name | The name of the function. |
[in] | param_format | Characters indicating the parameter format. 'b' for boolean parameters, 'n' for integers (treated as unsigned) or 'f' for floats. |
[in] | params | The list of parameters. |
void CodeGenerator::WriteTodo | ( | std::string | class_name, |
std::string | instruction | ||
) |
Writes a comment line indicating an unimplemented opcode.
[in] | class_name | The class where the instruction is. Unused. |
[in] | instruction | The unimplemented instruction. |
|
private |
Lists of arguments to be built when processing function calls.
|
private |
Order of operands for binary operations.
|
private |
Order of operands for call arguments.
|
protected |
The group currently being processed.
|
protected |
Graph vertex currently being processed.
|
protected |
The engine used for teh script.
|
private |
The annotated graph of the script.
|
protected |
Current indentation level.
|
protected |
Indicates if a label is being processed.
|
protected |
The stream to output the code to.
|
protected |
The stack currently being processed.
|
protected |
The target language.