/* * StackFrameManager.h - Declaration of the StackFrameManager class * * Part of the assignment of the Compiler Construction course * LIACS, Leiden University */ #ifndef _STACKFRAMEMANAGER_H_ #define _STACKFRAMEMANAGER_H_ #include #include "SymbolTable.h" #include "AssemblerCode.h" // This class gathers information about the stack frame (also known as // an activation record) of a subprogram and provides methods to generate // code based on the gathered information. class StackFrameManager { public: // Constructor: StackFrameManager(AssemblerCode& ac); // Destructor: ~StackFrameManager(); // Analyzes a subprogram and computes the stack frame layout. // This function should always be called once for a subprogram before // calls to GeneratePrologue/Epilogue or GenerateLocalAddress are made. void AnalyzeSubprogram(SymbolTable * symtab, Symbol * subprogram); // Generates the code that sets up the stack frame at the entry point of a // subprogram. void GeneratePrologue(FILE * out); // Generates the code that discards the stack frame at the leaving point of // a subprogram. void GenerateEpilogue(FILE * out); // Generates a $fp-relative address for a local variable or parameter. // The output can be used directly as an operand for load/store instructions. void GenerateLocalAddress(FILE * out, Symbol * sym); // ... your own public members and methods ... private: // The current subprogram Symbol * currentSubprogram; AssemblerCode& ac; int frameSize; // the size of the stack frame for this subprogram int localFrameSize; // the size of stack frame without parameters int raOffset; // the offset on the stack frame for the return address int fpOffset; // the offset on the stack frame for the old frame pointer int rvOffset; // the offset on the stack frame for the return value }; #endif