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
; end
# Create a new JIT::Value. If value is specified, the value will be
# variable, otherwise it will be a constant with the given value.
#
# +function+:: The function to which this value will belong.
# +type+:: The type of the new value.
# +value+: The value to use, if this is a constant.
#
# TODO: Not sure if I like this...
if value == UNINITIALIZED then
return function.value(type)
else
return function.const(type, value)
end
end
# Assign +value+ to this JIT::Value.
#
# +value+:: The value to assign.
#
lhs, rhs = coerce(value)
self.function.insn_store(lhs, rhs)
end
# Return the address of this value.
return self.function.insn_address_of(self)
end
# Add this value to another and return the result.
#
# +rhs+:: The right hand side of the addition operator.
#
lhs, rhs = coerce(rhs)
return self.function.insn_add(lhs, rhs)
end
# Subtract another value from this one and return the result.
#
# +rhs+:: The right hand side of the subtraction operator.
#
lhs, rhs = coerce(rhs)
return self.function.insn_sub(lhs, rhs)
end
# Multiply this value by another and return the result.
#
# +rhs+:: The right hand side of the multiplication operator.
#
lhs, rhs = coerce(rhs)
return self.function.insn_mul(lhs, rhs)
end
# Divide this value by another and return the quotient.
#
# +rhs+:: The right hand side of the division operator.
#
lhs, rhs = coerce(rhs)
return self.function.insn_div(lhs, rhs)
end
# Return the additive inverse (negation) of this value.
rhs, lhs = coerce(0) # inverted, since we are subtracting from 0
return lhs - rhs
end
# Divide this value by another and return the remainder.
#
# +rhs+:: The right hand side of the modulus operator.
#
lhs, rhs = coerce(rhs)
return self.function.insn_rem(lhs, rhs)
end
# Perform a bitwise and between this value and another.
#
# +rhs+:: The right hand side of the operator.
#
lhs, rhs = coerce(rhs)
return self.function.insn_and(lhs, rhs)
end
# Perform a bitwise or between this value and another.
#
# +rhs+:: The right hand side of the operator.
#
lhs, rhs = coerce(rhs)
return self.function.insn_or(lhs, rhs)
end
# Perform a bitwise xor between this value and another.
#
# +rhs+:: The right hand side of the operator.
#
^(rhs)
lhs, rhs = coerce(rhs)
return self.function.insn_xor(lhs, rhs)
end
# Compare this value to another, returning 1 if the left hand is
# less than the right hand side or 0 otherwise.
#
# +rhs+:: The right hand side of the comparison.
#
lhs, rhs = coerce(rhs)
return self.function.insn_lt(lhs, rhs)
end
# Compare this value to another, returning 1 if the left hand is
# greater than the right hand side or 0 otherwise.
#
# +rhs+:: The right hand side of the comparison.
#
lhs, rhs = coerce(rhs)
return self.function.insn_gt(lhs, rhs)
end
# Compare this value to another, returning 1 if the left hand is
# equal to the right hand side or 0 otherwise.
#
# +rhs+:: The right hand side of the comparison.
#
lhs, rhs = coerce(rhs)
return self.function.insn_eq(lhs, rhs)
end
# Compare this value to another, returning 1 if the left hand is
# not equal to the right hand side or 0 otherwise.
#
# +rhs+:: The right hand side of the comparison.
#
lhs, rhs = coerce(rhs)
return self.function.insn_ne(lhs, rhs)
end
# Compare this value to another, returning 1 if the left hand is
# less than or equal to the right hand side or 0 otherwise.
#
# +rhs+:: The right hand side of the comparison.
#
lhs, rhs = coerce(rhs)
return self.function.insn_le(lhs, rhs)
end
# Compare this value to another, returning 1 if the left hand is
# greater than or equal to the right hand side or 0 otherwise.
#
# +rhs+:: The right hand side of the comparison.
#
lhs, rhs = coerce(rhs)
return self.function.insn_ge(lhs, rhs)
end
# Shift this value left by the given number of bits.
#
# +rhs+:: The number of bits to shift by.
#
lhs, rhs = coerce(rhs)
return self.function.insn_shl(lhs, rhs)
end
# Shift this value right by the given number of bits.
#
# +rhs+:: The number of bits to shift by.
#
lhs, rhs = coerce(rhs)
return self.function.insn_shr(lhs, rhs)
end
# Return the logical inverse of this value.
return self.function.insn_not(self)
end
end
end