/* * ICGenerator.h - Declaration of the ICGenerator class * * Part of the assignment of the Compiler Construction course * LIACS, Leiden University */ #ifndef _ICGENERATOR_H_ #define _ICGENERATOR_H_ #include "debug.h" #include "SyntaxTree.h" #include "SymbolTable.h" #include "types.h" #include "IntermediateCode.h" #include "IOperand.h" // This class handles the intermediate code generation. Extend it to your own // needs. class ICGenerator { public: // Constructor ICGenerator(); // Destructor ~ICGenerator(); // Preprocesses the syntax tree; this method is called before // GenerateIntermediateCode() if optimizations are enabled void Preprocess (SyntaxTree * tree, SymbolTable * symtab); // Takes a SyntaxTree and converts it into an IntermediateCode structure IntermediateCode * GenerateIntermediateCode (SyntaxTree * inputTree, SymbolTable * symtab); // Postprocesses the intermediate code; this method is called after // GenerateIntermediateCode() if optimizations are enabled void Postprocess (IntermediateCode * code, SymbolTable * symtab); private: // Generates a temporary symbol Symbol * GenerateTempVar(ReturnType type); // Generates a Symbol for a label Symbol * GenerateLabel(); // Goes recursively through the syntax tree while appending intermediate code // Returns a new IOperand, allocated on the heap, with the result of the subtree // or returns NULL if there is no operand // dest is an optional destination operand, if used returns dest // constant is an optional constant operand // dest and constant are always NULL if not optimizing IOperand * Treewalk (Node * node, IOperand *dest = NULL, IOperand *constant = NULL); // Generates code for the NODE_RELOP_* nodes. // op is one of the IOP_B??_? operators and node is the relop node. // Returns a new copy of the result operand. IOperand * GenerateRelopCode(IOperator op, Node *node); // returns true if operand is a constant zero bool IsZero(IOperand *operand) const; // returns true if operand is a constant one bool IsOne(IOperand *operand) const; // returns true if operand is a constant negative one bool IsMinusOne(IOperand *operand) const; // returns true if operand is a constant bool IsConstant(IOperand *operand) const; // returns true if operand is a constant integer bool IsInt(IOperand *operand) const; // returns true if operand is a constant real bool IsReal(IOperand *operand) const; }; #endif