Decaf Compiler
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions
p4-codegen.c File Reference

Compiler phase 4: code generation. More...

#include "p4-codegen.h"

Classes

struct  CodeGenData
 State/data for the code generator visitor. More...
 

Macros

#define DATA   ((CodeGenData*)visitor->data)
 Macro for more convenient access to the error list inside a visitor data structure.
 

Typedefs

typedef struct CodeGenData CodeGenData
 State/data for the code generator visitor.
 

Functions

CodeGenDataCodeGenData_new (void)
 Allocate memory for code gen data.
 
void CodeGenData_free (CodeGenData *data)
 Deallocate memory for code gen data.
 
Operand var_base (ASTNode *node, Symbol *variable)
 Fills a register with the base address of a variable.
 
Operand var_offset (ASTNode *node, Symbol *variable)
 Calculates the offset of a scalar variable reference and fills a register with that offset.
 
InsnListgenerate_code (ASTNode *tree)
 Convert an AST into linear ILOC code.
 

Detailed Description

Compiler phase 4: code generation.

Function Documentation

◆ CodeGenData_free()

void CodeGenData_free ( CodeGenData data)

Deallocate memory for code gen data.

Parameters
dataPointer to the structure to be deallocated

◆ CodeGenData_new()

CodeGenData * CodeGenData_new ( void  )

Allocate memory for code gen data.

Returns
Pointer to allocated structure

◆ generate_code()

InsnList * generate_code ( ASTNode tree)

Convert an AST into linear ILOC code.

Parameters
treeRoot of AST
Returns
List of ILOC instructions

◆ var_base()

Operand var_base ( ASTNode node,
Symbol variable 
)

Fills a register with the base address of a variable.

Parameters
nodeAST node to emit code into (if needed)
variableDesired variable
Returns
Virtual register that contains the base address

◆ var_offset()

Operand var_offset ( ASTNode node,
Symbol variable 
)

Calculates the offset of a scalar variable reference and fills a register with that offset.

Parameters
nodeAST node to emit code into (if needed)
variableDesired variable
Returns
Virtual register that contains the base address