-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.ll
More file actions
39 lines (30 loc) · 1.02 KB
/
object.ll
File metadata and controls
39 lines (30 loc) · 1.02 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
declare i8* @malloc(i32) nounwind
; Tag values:
; 0 - List
; 1 - Token
; 2 - Native Function
%object = type {
i32, ; Tag
i8* ; Value (may be bitcast, if it safely fits in a pointer)
}
define %object* @newObject(i32 %tag, i8* %val) {
%objSizePtr = getelementptr %object, %object* null, i32 1
%objSize = ptrtoint %object* %objSizePtr to i32
%objSpace = call i8* @malloc(i32 %objSize)
%objPtr = bitcast i8* %objSpace to %object*
%tagPtr = getelementptr %object, %object* %objPtr, i32 0, i32 0
store i32 %tag, i32* %tagPtr
%valPtr = getelementptr %object, %object* %objPtr, i32 0, i32 1
store i8* %val, i8** %valPtr
ret %object* %objPtr
}
define i32 @tag(%object* %obj) {
%tagPtr = getelementptr %object, %object* %obj, i32 0, i32 0
%tag = load i32, i32* %tagPtr
ret i32 %tag
}
define i8* @unbox(%object* %obj) {
%valPtr = getelementptr %object, %object* %obj, i32 0, i32 1
%val = load i8*, i8** %valPtr
ret i8* %val
}