-
Notifications
You must be signed in to change notification settings - Fork 1
/
x86_64_frame.h
111 lines (92 loc) · 2.42 KB
/
x86_64_frame.h
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef _X86_64_FRAME_H
#define _X86_64_FRAME_H
#include "declarations.h"
#include "intermediate.h"
namespace IR {
class X86_64VarLocation: public AbstractVarLocation {
private:
bool is_register;
int offset;
VirtualRegister *reg;
public:
X86_64VarLocation(AbstractFrame *frame, int _offset) :
AbstractVarLocation(frame), is_register(false), offset(_offset),
reg(NULL)
{}
X86_64VarLocation(AbstractFrame *frame, VirtualRegister *_register) :
AbstractVarLocation(frame), is_register(true), offset(0),
reg(_register)
{}
virtual IR::Expression *createCode(AbstractFrame *frame);
virtual bool isRegister() {return reg != NULL;}
VirtualRegister *getRegister() {return reg;}
virtual void prespillRegister(AbstractVarLocation *location)
{
if (reg != NULL)
reg->prespill(location);
}
};
class X86_64Frame: public AbstractFrame {
private:
int frame_size;
IREnvironment *ir_env;
int param_count;
int param_stack_size;
VirtualRegister *framepointer;
public:
X86_64Frame(AbstractFrameManager *_framemanager, const std::string &name,
int _id, X86_64Frame *_parent, IREnvironment *_ir_env,
VirtualRegister *_framepointer) :
AbstractFrame(_framemanager, name, _id, _parent),
ir_env(_ir_env),
framepointer(_framepointer),
frame_size(0),
param_count(0),
param_stack_size(0)
{}
virtual AbstractVarLocation *createVariable(const std::string &name,
int size, bool cant_be_register);
virtual AbstractVarLocation *createParameter(const std::string &name,
int size);
virtual IR::VirtualRegister *getFramePointer() {return framepointer;}
int getFrameSize();
};
class X86_64FrameManager: public AbstractFrameManager {
private:
X86_64Frame *root_frame;
int framecount;
public:
X86_64FrameManager(IREnvironment *env) : AbstractFrameManager(env)
{
root_frame = new X86_64Frame(this, ".root", 0, NULL, IR_env,
IR_env->addRegister("fp"));
framecount = 1;
}
~X86_64FrameManager()
{
delete root_frame;
}
virtual AbstractFrame *rootFrame()
{
return root_frame;
}
virtual AbstractFrame *newFrame(AbstractFrame *parent, const std::string &name)
{
return new X86_64Frame(this, name, framecount++, (X86_64Frame *)parent,
IR_env, IR_env->addRegister("fp"));
}
virtual int getVarSize(Semantic::Type *type)
{
return 8;
}
virtual int getPointerSize()
{
return 8;
}
virtual void updateRecordSize(int &size, Semantic::Type *newFieldType)
{
size += getVarSize(newFieldType);
}
};
}
#endif