source: liacs/coco/assignment3/ICGenerator.h@ 144

Last change on this file since 144 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: 2.5 KB
Line 
1/*
2 * ICGenerator.h - Declaration of the ICGenerator class
3 *
4 * Part of the assignment of the Compiler Construction course
5 * LIACS, Leiden University
6 */
7
8#ifndef _ICGENERATOR_H_
9#define _ICGENERATOR_H_
10
11#include "debug.h"
12#include "SyntaxTree.h"
13#include "SymbolTable.h"
14#include "types.h"
15#include "IntermediateCode.h"
16#include "IOperand.h"
17
18
19// This class handles the intermediate code generation. Extend it to your own
20// needs.
21class ICGenerator {
22 public:
23 // Constructor
24 ICGenerator();
25
26 // Destructor
27 ~ICGenerator();
28
29 // Preprocesses the syntax tree; this method is called before
30 // GenerateIntermediateCode() if optimizations are enabled
31 void Preprocess (SyntaxTree * tree, SymbolTable * symtab);
32
33 // Takes a SyntaxTree and converts it into an IntermediateCode structure
34 IntermediateCode * GenerateIntermediateCode (SyntaxTree * inputTree, SymbolTable * symtab);
35
36 // Postprocesses the intermediate code; this method is called after
37 // GenerateIntermediateCode() if optimizations are enabled
38 void Postprocess (IntermediateCode * code, SymbolTable * symtab);
39
40 private:
41 // Generates a temporary symbol
42 Symbol * GenerateTempVar(ReturnType type);
43
44 // Generates a Symbol for a label
45 Symbol * GenerateLabel();
46
47 // Goes recursively through the syntax tree while appending intermediate code
48 // Returns a new IOperand, allocated on the heap, with the result of the subtree
49 // or returns NULL if there is no operand
50 // dest is an optional destination operand, if used returns dest
51 // constant is an optional constant operand
52 // dest and constant are always NULL if not optimizing
53 IOperand * Treewalk (Node * node, IOperand *dest = NULL, IOperand *constant = NULL);
54
55 // Generates code for the NODE_RELOP_* nodes.
56 // op is one of the IOP_B??_? operators and node is the relop node.
57 // Returns a new copy of the result operand.
58 IOperand * GenerateRelopCode(IOperator op, Node *node);
59
60 // returns true if operand is a constant zero
61 bool IsZero(IOperand *operand) const;
62 // returns true if operand is a constant one
63 bool IsOne(IOperand *operand) const;
64 // returns true if operand is a constant negative one
65 bool IsMinusOne(IOperand *operand) const;
66 // returns true if operand is a constant
67 bool IsConstant(IOperand *operand) const;
68 // returns true if operand is a constant integer
69 bool IsInt(IOperand *operand) const;
70 // returns true if operand is a constant real
71 bool IsReal(IOperand *operand) const;
72};
73
74#endif
Note: See TracBrowser for help on using the repository browser.