forked from ztachip/ztachip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ident.h
executable file
·245 lines (222 loc) · 7.16 KB
/
ident.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
//----------------------------------------------------------------------------
// Copyright [2014] [Ztachip Technologies Inc]
//
// Author: Vuong Nguyen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except IN compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to IN writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//------------------------------------------------------------------------------
#ifndef _IDENT_H_
#define _IDENT_H_
#include "util.h"
#include "object.h"
#include "ast.h"
class cIdentifierVector;
class cGraphColor;
class cIdentifier;
class cIdentifierStack;
class cIdentifierReturnValue;
class cIdentifierVector : public std::vector<cIdentifier *>
{
public:
cIdentifierVector();
virtual ~cIdentifierVector();
void append(cIdentifier *_id);
void clone(cIdentifierVector *x);
void vector_union(cIdentifierVector *x);
void vector_minus(cIdentifierVector *x);
bool equal(cIdentifierVector *x);
bool exist(cIdentifier *x);
bool exist(cIdentifierVector *v);
bool isOverlap(cIdentifierVector *x);
};
class cIdentifierShared;
class cIdentifier : public cListItem
{
DECLARE_ROOT_OBJECT(cIdentifier);
public:
cIdentifier(cAstNode *owner,cAstNode *parent,cAstNode *type);
virtual ~cIdentifier();
bool isPointerOverlap(cIdentifier *pointer);
bool isTemp() {return (m_name.size()==0);}
int getNumDim() {return m_num_dim;}
int getDim(int index) {return m_dim[index];}
int *getDim() {return m_dim;}
int getDimSize(int index);
int getOffset() {return m_offset;}
int getByteOffset() {return m_byteOffset;}
int getVectorWidth();
int getLen();
bool isParameter();
bool isStack();
bool isFixed();
bool isSameContext(cAstNode *func);
cIdentifier *getAlias();
cAstNode *getType() {return m_type;}
void allocate(int offset);
void setInitializer(cAstNode *init,int level,int *levelIndex);
static bool isReservedName(char *name);
char *getPrintName(char *buf);
static int M_id;
int m_id;
public:
static RETCODE Process(cAstNode *_root);
public:
static cIdentifier *lookupParm(cAstNode *_root,char *funcName,char *parmName);
static cIdentifierReturnValue *getReturnValue(cAstNode *owner);
static int getFuncParameterCount(cAstNode *owner);
static cIdentifier *getFuncParameter(cAstNode *owner,int index);
static cIdentifierStack *getStackVariable(cAstNode *owner,int pos,int width);
private:
static cIdentifier *lookup(cAstNode *_root,cAstNode *func,char *name,cAstNode **stack,int stackSize);
static void assign(cAstNode *_root,cAstNode *func,cAstNode *node,cAstNode **stack,int stackSize);
static void scan(cAstNode *_func,cAstNode *owner,cAstNode *parent,bool _global);
static void scanParm(cAstNode *_func,cAstNode *owner,cAstNode *parent);
public:
std::string m_name;
std::string m_context;
public:
cAstNode *m_owner;
cAstNode *m_type;
int m_len;
int m_offset;
int m_byteOffset;
int m_num_dim;
int m_dim[MAX_VAR_DIM];
public:
int m_interference;
cGraphColor *m_color;
int m_defCount;
int m_useCount;
std::vector<float> m_init;
public:
static void Init();
};
class cIdentifierFloat : public cIdentifier
{
DECLARE_OBJECT(cIdentifierFloat,cIdentifier);
public:
cIdentifierFloat(cAstNode *owner,cAstNode *parent,cAstNode *type);
virtual ~cIdentifierFloat();
};
class cIdentifierStorage: public cIdentifierFloat
{
DECLARE_OBJECT(cIdentifierStorage,cIdentifierFloat);
public:
cIdentifierStorage(cAstNode *owner,cAstNode *parent,cAstNode *type,int width);
virtual ~cIdentifierStorage();
public:
int m_w;
};
class cIdentifierShared : public cIdentifierStorage
{
DECLARE_OBJECT(cIdentifierShared,cIdentifierStorage);
public:
cIdentifierShared(cAstNode *owner,cAstNode *parent,cAstNode *type,cIdentifier *alias,int _width);
virtual ~cIdentifierShared() {}
cIdentifier *m_alias;
};
class cIdentifierPrivate : public cIdentifierStorage
{
DECLARE_OBJECT(cIdentifierPrivate,cIdentifierStorage);
public:
cIdentifierPrivate(cAstNode *owner,cAstNode *parent,cAstNode *type,int _width);
virtual ~cIdentifierPrivate() {}
};
class cIdentifierParameter : public cIdentifierPrivate
{
DECLARE_OBJECT(cIdentifierParameter,cIdentifierPrivate);
public:
cIdentifierParameter(cAstNode *owner,cAstNode *parent,cAstNode *type,cIdentifier *alias,int _width);
virtual ~cIdentifierParameter() {}
public:
cIdentifier *m_alias;
};
class cIdentifierStack : public cIdentifierPrivate
{
DECLARE_OBJECT(cIdentifierStack,cIdentifierPrivate);
public:
cIdentifierStack(cAstNode *owner,cAstNode *parent,cAstNode *type,int pos,int _width);
virtual ~cIdentifierStack() {}
int m_pos;
};
class cIdentifierReturnValue : public cIdentifierPrivate
{
DECLARE_OBJECT(cIdentifierReturnValue,cIdentifierPrivate);
public:
cIdentifierReturnValue(cAstNode *owner,cAstNode *parent,cAstNode *type,bool _isFloat,int _width);
virtual ~cIdentifierReturnValue() {}
bool m_float;
};
class cIdentifierConst : public cIdentifierFloat
{
DECLARE_OBJECT(cIdentifierConst,cIdentifierFloat);
public:
cIdentifierConst(cAstNode *owner,cAstNode *parent,cAstNode *type);
virtual ~cIdentifierConst() {}
};
class cIdentifierFixed : public cIdentifier
{
DECLARE_OBJECT(cIdentifierFixed,cIdentifier);
public:
cIdentifierFixed(cAstNode *owner,cAstNode *parent,cAstNode *type,bool persistent,int persistentIndex);
virtual ~cIdentifierFixed();
public:
bool m_persistent;
int m_persistentIndex;
};
class cIdentifierPointer : public cIdentifierFixed
{
DECLARE_OBJECT(cIdentifierPointer,cIdentifierFixed);
public:
cIdentifierPointer(cAstNode *owner,cAstNode *parent,cAstNode *type,bool isConst,int _width,bool persistent=false);
virtual ~cIdentifierPointer() {}
void getIdentifierScope(cIdentifierVector *lst);
bool isConst() {return m_isConst;}
private:
void _getIdentifierScope(cIdentifierVector *lst,cIdentifierVector *dirtyLst);
public:
cIdentifierVector m_scope;
bool m_isConst;
int m_width;
};
class cIdentifierInteger : public cIdentifierFixed
{
DECLARE_OBJECT(cIdentifierInteger,cIdentifierFixed);
public:
cIdentifierInteger(cAstNode *owner,cAstNode *parent,cAstNode *type,bool isUnsigned,bool persistent,int persistentIndex);
virtual ~cIdentifierInteger() {}
bool m_isUnsigned;
bool m_useForMuIndex;
};
class cIdentifierResult : public cIdentifierFixed
{
DECLARE_OBJECT(cIdentifierResult,cIdentifierFixed);
public:
cIdentifierResult();
static cIdentifierResult M_singleInstance;
};
class cIdentifierLane : public cIdentifierFixed
{
DECLARE_OBJECT(cIdentifierLane,cIdentifierFixed);
public:
cIdentifierLane();
static cIdentifierLane M_singleInstance;
};
class cIdentifierExReg : public cIdentifierStorage
{
DECLARE_OBJECT(cIdentifierExReg,cIdentifierStorage);
public:
cIdentifierExReg(cAstNode *owner,cAstNode *parent,cAstNode *type,int _width,bool _persistent);
bool m_persistent;
};
#endif