-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectType.cpp
More file actions
42 lines (37 loc) · 1012 Bytes
/
ObjectType.cpp
File metadata and controls
42 lines (37 loc) · 1012 Bytes
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
#include "ObjectType.h"
#define kObjectFieldDataTy(C) Type::getInt64Ty(C)
#define kObjectFieldTypeTy(C) Type::getInt1Ty(C)
StructType * getObjTy(LLVMContext &C)
{
static StructType *Ty = NULL;
if (!Ty) {
/* struct obj { long int data; int type:1; }; */
Ty = StructType::create("obj",
kObjectFieldDataTy(C),
kObjectFieldTypeTy(C), NULL);
}
return Ty;
}
PointerType * getObjPtrTy(LLVMContext &C)
{
static PointerType *PtrTy = NULL;
if (!PtrTy) {
PtrTy = getObjTy(C)->getPointerTo();
}
return PtrTy;
}
/* Return the size (in bytes) of the "obj" type */
unsigned ObjectTypeSize(LLVMContext &C)
{
static unsigned Size = 0;
if (Size == 0) {
StructType *STy = getObjTy(C);
int NumElements = STy->getNumElements();
for (int i = 0; i < NumElements; i++)
Size += STy->getElementType(i)->getScalarSizeInBits();
Size = ceilf(Size / 8.);
}
return Size;
}
#undef kObjectFieldTypeTy
#undef kObjectFieldDataTy