source: liacs/coco/assignment4/StackFrameManager.h@ 297

Last change on this file since 297 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.9 KB
RevLine 
[2]1/*
2 * StackFrameManager.h - Declaration of the StackFrameManager class
3 *
4 * Part of the assignment of the Compiler Construction course
5 * LIACS, Leiden University
6 */
7
8#ifndef _STACKFRAMEMANAGER_H_
9#define _STACKFRAMEMANAGER_H_
10
11#include <cstdio>
12#include "SymbolTable.h"
13#include "AssemblerCode.h"
14
15// This class gathers information about the stack frame (also known as
16// an activation record) of a subprogram and provides methods to generate
17// code based on the gathered information.
18class StackFrameManager {
19 public:
20 // Constructor:
21 StackFrameManager(AssemblerCode& ac);
22
23 // Destructor:
24 ~StackFrameManager();
25
26 // Analyzes a subprogram and computes the stack frame layout.
27 // This function should always be called once for a subprogram before
28 // calls to GeneratePrologue/Epilogue or GenerateLocalAddress are made.
29 void AnalyzeSubprogram(SymbolTable * symtab, Symbol * subprogram);
30
31 // Generates the code that sets up the stack frame at the entry point of a
32 // subprogram.
33 void GeneratePrologue(FILE * out);
34
35 // Generates the code that discards the stack frame at the leaving point of
36 // a subprogram.
37 void GenerateEpilogue(FILE * out);
38
39 // Generates a $fp-relative address for a local variable or parameter.
40 // The output can be used directly as an operand for load/store instructions.
41 void GenerateLocalAddress(FILE * out, Symbol * sym);
42
43 // ... your own public members and methods ...
44
45 private:
46
47 // The current subprogram
48 Symbol * currentSubprogram;
49
50 AssemblerCode& ac;
51
52 int frameSize; // the size of the stack frame for this subprogram
53 int localFrameSize; // the size of stack frame without parameters
54 int raOffset; // the offset on the stack frame for the return address
55 int fpOffset; // the offset on the stack frame for the old frame pointer
56 int rvOffset; // the offset on the stack frame for the return value
57};
58
59
60#endif
Note: See TracBrowser for help on using the repository browser.