/* * CodeGenerator.h - Declaration of the CodeGenerator class * * Part of the assignment of the Compiler Construction course * LIACS, Leiden University */ #ifndef _CODEGENERATOR_H_ #define _CODEGENERATOR_H_ #include #include "SymbolTable.h" #include "IntermediateCode.h" #include "StackFrameManager.h" #include "RegisterManager.h" // This class handles the assembly code generation. Extend it to your own // needs. class CodeGenerator { public: // Constructor CodeGenerator(); // Destructor ~CodeGenerator(); // Dump generated output void Dump(FILE * out); // Generates a header void GenerateHeader(FILE * out); // Generates the declarations for the global variables void GenerateGlobalDecls(FILE * out, SymbolTable * symtab); // Takes an IntermediateCode object and emits MIPS assembly instructions void GenerateCode(FILE * out, SymbolTable * symtab, IntermediateCode * inputCode); // Generates a trailer void GenerateTrailer(FILE * out); private: MOperand *IOperand2MOperand(IOperand *opnd); MStatement *BinaryArithmetic(MOperator opcode, IStatement *stmt, const char * comment = "Binary Arithmetic"); MStatement *BranchInstruction(MOperator opcode, IStatement *stmt, bool swap = false, const char * comment = "Branch Instruction Int"); MStatement *BranchInstructionReal(MOperator opcode, IStatement *stmt, bool swap = false, const char * comment = "Branch Instruction Real"); MStatement *UnaryArithmetic(MOperator opcode, IStatement *stmt, const char * comment = "UnaryArithmetic"); MStatement *StackPointerChange(int offset, const char * comment = NULL); // The current stack frame: AssemblerCode mCode; StackFrameManager currentFrame; RegisterManager rManager; }; #endif