source: liacs/coco/assignment4/CodeGenerator.h@ 242

Last change on this file since 242 was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

File size: 1.8 KB
Line 
1/*
2 * CodeGenerator.h - Declaration of the CodeGenerator class
3 *
4 * Part of the assignment of the Compiler Construction course
5 * LIACS, Leiden University
6 */
7
8#ifndef _CODEGENERATOR_H_
9#define _CODEGENERATOR_H_
10
11#include <cstdio>
12#include "SymbolTable.h"
13#include "IntermediateCode.h"
14#include "StackFrameManager.h"
15#include "RegisterManager.h"
16// This class handles the assembly code generation. Extend it to your own
17// needs.
18class CodeGenerator {
19public:
20 // Constructor
21 CodeGenerator();
22
23 // Destructor
24 ~CodeGenerator();
25
26 // Dump generated output
27 void Dump(FILE * out);
28
29 // Generates a header
30 void GenerateHeader(FILE * out);
31
32 // Generates the declarations for the global variables
33 void GenerateGlobalDecls(FILE * out, SymbolTable * symtab);
34
35 // Takes an IntermediateCode object and emits MIPS assembly instructions
36 void GenerateCode(FILE * out, SymbolTable * symtab, IntermediateCode * inputCode);
37
38 // Generates a trailer
39 void GenerateTrailer(FILE * out);
40
41private:
42 MOperand *IOperand2MOperand(IOperand *opnd);
43 MStatement *BinaryArithmetic(MOperator opcode, IStatement *stmt,
44 const char * comment = "Binary Arithmetic");
45 MStatement *BranchInstruction(MOperator opcode, IStatement *stmt,
46 bool swap = false, const char * comment = "Branch Instruction Int");
47 MStatement *BranchInstructionReal(MOperator opcode, IStatement *stmt,
48 bool swap = false, const char * comment = "Branch Instruction Real");
49 MStatement *UnaryArithmetic(MOperator opcode, IStatement *stmt,
50 const char * comment = "UnaryArithmetic");
51 MStatement *StackPointerChange(int offset, const char * comment = NULL);
52
53
54 // The current stack frame:
55 AssemblerCode mCode;
56 StackFrameManager currentFrame;
57 RegisterManager rManager;
58};
59
60#endif
Note: See TracBrowser for help on using the repository browser.