forked from arenfro1987/TD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubprogram_epilog.cpp
More file actions
87 lines (86 loc) · 3.17 KB
/
subprogram_epilog.cpp
File metadata and controls
87 lines (86 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//-------------------------------------------------------------------------
//File subprogram_epilog.cpp produces the epilog for functions and procedures.
//-------------------------------------------------------------------------
//---------------------------------------------------------------------
//Author: Thomas R. Turner
//E-Mail: trturner@uco.edu
//Date: April, 2012
//---------------------------------------------------------------------
//Copyright April, 2012 by Thomas R. Turner.
//Do not reproduce without permission from Thomas R. Turner.
//---------------------------------------------------------------------
//C++ inlcude files
//---------------------------------------------------------------------
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
//---------------------------------------------------------------------
//Supporting utilities
//---------------------------------------------------------------------
#include "List.h"
#include "yyerror.h"
//---------------------------------------------------------------------
//Symbol Table
//---------------------------------------------------------------------
#include "Typ.h"
#include "Sym.h"
#include "Namespace.h"
#include "Locality.h"
#include "LocalityStack.h"
#include "SymbolTable.h"
#include "Label.h"
//---------------------------------------------------------------------
//P-Code and Expression Trees
//---------------------------------------------------------------------
#include "PCode.h"
#include "Exp.h"
#include "ToString.h"
#include "Height.h"
//-------------------------------------------------------------------------
//subprogram_prolog.h
//-------------------------------------------------------------------------
#include "subprogram_epilog.h"
//---------------------------------------------------------------------
//Externals
//---------------------------------------------------------------------
extern ofstream pfs;
extern ofstream o;
extern int line;
extern int col;
extern SymbolTable ST;
extern Label L;
//---------------------------------------------------------------------
//---------------------------------------------------------------------
List<Exp*>* subprogram_epilog(SubprogramSymbol* S,List<Exp*>* compound_statement)
{ List<Exp*>* L=new List<Exp*>;
string tc=S->ReturnType()->TypeChar();
PCode* P=new PCode("","rtn",tc,"");
Exp* E=new Exp(ST.TVoid(),P);
E->Print(tfs);
tfs << endl;
L->Insert(E);
int spvalue =ST.Offset();
P=new PCode("#define",S->SPLabel(),spvalue,"");
E=new Exp(ST.TVoid(),P);
E->Print(tfs);
tfs << endl;
L->Insert(E);
Height H;
//-----------------------------------------------------------------------
//Find the maximum height of the computation stack, epvalue
//-----------------------------------------------------------------------
for (compound_statement->First();!compound_statement->IsEol();compound_statement->Next()) {
Exp* E=compound_statement->Member();
H.FindHeight(E);
}
tfs << endl;
int epvalue=spvalue+H.Maximum();
P=new PCode("#define",S->EPLabel(),epvalue,"");
E=new Exp(ST.TVoid(),P);
E->Print(tfs);
tfs << endl;
L->Insert(E);
return L;
}