-
Notifications
You must be signed in to change notification settings - Fork 0
/
Block.java
126 lines (103 loc) · 2.93 KB
/
Block.java
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
package com.destranix.glslang;
public class Block extends PointerBoundObject {
protected final long id;
protected final Function parent;
private final int constructorIndex;
public Block(long id, Function parent) {
this.id = id;
this.parent = parent;
this.constructorIndex = 0;
load();
}
protected Block(byte[] ptr) {
this.ptr = ptr;
this.id = -1;
this.parent = null;
this.constructorIndex = -1;
}
@Override
protected void load_intern() {
if (ptr == null) {
switch (constructorIndex) {
case -1:
throw new IllegalStateException(EXCEPTION_MSG_NOT_LOADABLE);
case 0:
ptr = Main.Block(id, parent.getPtr());
break;
default:
throw new AssertionError("Reached unreachable state!");
}
}
}
@Override
protected void free_intern() {
if (ptr != null) {
switch (constructorIndex) {
case -1:
throw new IllegalStateException(EXCEPTION_MSG_NOT_FREEABLE);
case 0:
Main.delete(ptr);
ptr = null;
break;
default:
throw new AssertionError("Reached unreachable state!");
}
}
}
public long getId() {
return Main.Block_getId(ptr);
}
public Function getParent() {
return fromPtr(Main.Block_getParent(ptr), Function.class);
}
public void addInstruction(Instruction inst) {
Main.Block_addInstruction(ptr, inst.getPtr());
}
public void addPredecessor(Block pred) {
Main.Block_addPredecessor(ptr, pred.getPtr());
}
public void addLocalVariable(Instruction inst) {
Main.Block_addLocalVariable(ptr, inst.getPtr());
}
public CVector<Block> getPredecessors() {
@SuppressWarnings("unchecked")
CVector<Block> ret = (CVector<Block>) fromPtr(Main.Block_getPredecessors(ptr), CVector.class);
return ret;
}
public CVector<Block> getSuccessors() {
@SuppressWarnings("unchecked")
CVector<Block> ret = (CVector<Block>) fromPtr(Main.Block_getSuccessors(ptr), CVector.class);
return ret;
}
public CVector<Instruction> getInstructions() {
@SuppressWarnings("unchecked")
CVector<Instruction> ret = (CVector<Instruction>) fromPtr(Main.Block_getInstructions(ptr), CVector.class);
return ret;
}
public CVector<Instruction> getLocalVariables() {
@SuppressWarnings("unchecked")
CVector<Instruction> ret = (CVector<Instruction>) fromPtr(Main.Block_getLocalVariables(ptr), CVector.class);
return ret;
}
public void setUnreachable() {
Main.Block_setUnreachable(ptr);
}
public boolean isUnreachable() {
return Main.Block_isUnreachable(ptr);
}
public Instruction getMergeInstruction() {
return fromPtr(Main.Block_getMergeInstruction(ptr), Instruction.class);
}
public void rewriteAsCanonicalUnreachableMerge() {
Main.Block_rewriteAsCanonicalUnreachableMerge(ptr);
}
public void rewriteAsCanonicalUnreachableContinue(Block header) {
Main.Block_rewriteAsCanonicalUnreachableContinue(ptr, header.getPtr());
}
public boolean isTerminated() {
return Main.Block_isTerminated(ptr);
}
public void dump(long[][] out) {
Main.Block_dump(ptr, out);
}
}