summaryrefslogtreecommitdiff
path: root/includes/compiler/objects.h
blob: 5f56877ac0837d0407e9ddb199a2ec0df3fb9cc8 (plain)
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
246
#ifndef COMPILER_OBJECTS_H
#define COMPILER_OBJECTS_H

#include "compiler/common.h"
#include "compiler/tokens.h"

#ifdef __MWERKS__
#pragma options align=mac68k
#endif

typedef enum ObjectType {
    OT_ENUMCONST,
    OT_TYPE,
    OT_TYPETAG,
    OT_NAMESPACE,
    OT_MEMBERVAR,
    OT_OBJECT,
    OT_ILLEGAL
} ObjectType;


struct ObjectList {
    ObjectList *next;
    Object *object;
};


/// General structure with all shared fields for all kinds of objects
struct ObjBase {
    ObjectType otype;
    AccessType access;
};


/// Type 0 (OT_ENUMCONST)
struct ObjEnumConst {
    ObjectType otype;
    AccessType access;
    ObjEnumConst *next;
    HashNameNode *name;
    Type *type;
    CInt64 val;
};


/// Type 1 (OT_TYPE)
struct ObjType {
    ObjectType otype;
    AccessType access;
    Type *type;
    UInt32 qual;
};


/// Type 2 (OT_TYPETAG)
struct ObjTypeTag {
    ObjectType otype;
    AccessType access;
    Type *type;
};


/// Type 3 (OT_NAMESPACE)
struct ObjNameSpace {
    ObjectType otype;
    AccessType access;
    NameSpace *nspace;
};


/// Type 4 (OT_MEMBERVAR)
struct ObjMemberVar {
    ObjectType otype;
    AccessType access;
    Boolean anonunion;
    Boolean has_path;
    struct ObjMemberVar *next;
    HashNameNode *name;
    Type *type;
    UInt32 qual;
    UInt32 offset;
};
struct ObjMemberVarPath {
    ObjectType otype;
    AccessType access;
    Boolean anonunion;
    Boolean has_path;
    struct ObjMemberVar *next;
    HashNameNode *name;
    Type *type;
    UInt32 qual;
    UInt32 offset;
    BClassList *path;
};


typedef enum DataType {
    DDATA,
    DLOCAL,
    DABSOLUTE,
    DFUNC,
    DVFUNC,
    DINLINEFUNC,
    DALIAS,
    DEXPR,
    DNONLAZYPTR,
    DLABEL,
    DUNUSED
} DataType;

/// Type 5 (OT_OBJECT)
struct Object {
    ObjectType otype;
    AccessType access;
    DataType datatype;
    Section section;
    NameSpace *nspace;
    HashNameNode *name;
    Type *type;
    UInt32 qual;
    SInt16 sclass;
    UInt8 flags;
    ExtendedParam *extParam;
    Object *toc;
    VarRecord *varptr;
    union {
        struct {
            union {
                CInt64 intconst;
                Float *floatconst;
                MWVector128 *vector128const;
                char *string;
                struct {
                    char *data;
                    SInt32 size;
                } switchtable;
            } u;
            VarInfo *info;
            HashNameNode *linkname;
            Boolean islocalstatic;
        } data;
        UInt32 address;
        struct {
            VarInfo *info;
            HashNameNode *linkname;
            Object *over_load;
        } toc;
        struct {
            union {
                TemplateFunction *templ;
                CI_FuncData *ifuncdata;
                SInt32 intrinsicid;
            } u;
            DefArgCtorInfo *defargdata;
            HashNameNode *linkname;
            TemplFuncInstance *inst;
            PTFList *ptfList;
            ObjectList *argList;
        } func; // Used with DFUNC and DVFUNC
        struct {
            char *data;
            SInt32 size;
            InlineXRef *xrefs;
        } ifunc; // Used with DINLINEFUNC
        struct {
            VarInfo *info;
            SInt32 uid;
            // SInt32 offset; // ???
            Object *realObj;
        } var;
        struct {
            Object *object;
            //TypeClass *member;
            BClassList *member; // ???
            SInt32 offset;
        } alias;
        struct {
            Object *function;
            HashNameNode *labelname;
        } label;
        ENode *expr;
    } u;
};

struct ObjectTemplated {
    Object object;
    Object *parent;
};

enum {
    OBJECT_FLAGS_1 = 1,
    OBJECT_FLAGS_2 = 2,
    OBJECT_FLAGS_4 = 4,
    OBJECT_FLAGS_8 = 8,
    OBJECT_FLAGS_10 = 0x10, // internal
    OBJECT_FLAGS_20 = 0x20, // import
    OBJECT_FLAGS_40 = 0x40, // export
    OBJECT_FLAGS_60 = 0x60  // lib export
};

#define OBJ_BASE(obj) ((ObjBase *) (obj))
#define OBJ_ENUM_CONST(obj) ((ObjEnumConst *) (obj))
#define OBJ_TYPE(obj) ((ObjType *) (obj))
#define OBJ_TYPE_TAG(obj) ((ObjTypeTag *) (obj))
#define OBJ_NAMESPACE(obj) ((ObjNameSpace *) (obj))
#define OBJ_MEMBER_VAR(obj) ((ObjMemberVar *) (obj))
#define OBJ_MEMBER_VAR_PATH(obj) ((ObjMemberVarPath *) (obj))
#define OBJECT(obj) ((Object *) (obj))
#define OBJECT_TEMPL(obj) ((ObjectTemplated *) (obj))


struct VarInfo { // OK!
    Object *func;
    SInt32 usage;
    TStreamElement deftoken;
    SInt16 varnumber;
    Boolean noregister;
    Boolean used;
    UInt8 flags;
    UInt8 rclass;
    SInt16 reg;
    SInt16 regHi;
};

enum {
    VarInfoFlag1 = 1, // is parameter?
    VarInfoFlag2 = 2, // spill related?
    VarInfoFlag4 = 4, // 64-bit spill related?
    VarInfoFlag40 = 0x40,
    VarInfoFlag80 = 0x80
};

#define OBJECT_OR_ALIAS(_object) ( ((_object)->datatype == DALIAS) ? ((_object)->u.alias.object) : (_object) )

// placing these here until further notice

// unknown name, mwcppc.exe 7.0: 484870
CW_INLINE Boolean Inline_IsObjectData(Object *object) {
    return object->datatype == DDATA;
}

#ifdef __MWERKS__
#pragma options align=reset
#endif

#endif