@@ -167,12 +167,90 @@ public function implement(): void {
167
167
// These variables are a hack because compile{}
168
168
// blocks currently only accept variables as arguments.
169
169
$ jit = $ this ->context ->constantFromString ("jit " );
170
- $ two = 2 ;
170
+ $ __type = $ this ->context ->getTypeFromString ('int32 ' );
171
+
172
+
173
+ $ __kind = $ __type ->getKind ();
174
+ $ __value = 2 ;
175
+ switch ($ __kind ) {
176
+ case \PHPLLVM \Type::KIND_INTEGER :
177
+ if (!is_object ($ __value )) {
178
+ $ two = $ __type ->constInt ($ __value , false );
179
+ break ;
180
+ }
181
+ $ __other_type = $ __value ->typeOf ();
182
+ switch ($ __other_type ->getKind ()) {
183
+ case \PHPLLVM \Type::KIND_INTEGER :
184
+ if ($ __other_type ->getWidth () >= $ __type ->getWidth ()) {
185
+ $ two = $ this ->context ->builder ->truncOrBitCast ($ __value , $ __type );
186
+ } else {
187
+ $ two = $ this ->context ->builder ->zExtOrBitCast ($ __value , $ __type );
188
+ }
189
+ break ;
190
+ case \PHPLLVM \Type::KIND_DOUBLE :
191
+
192
+ $ two = $ this ->context ->builder ->fpToSi ($ __value , $ __type );
193
+
194
+ break ;
195
+ case \PHPLLVM \Type::KIND_ARRAY :
196
+ case \PHPLLVM \Type::KIND_POINTER :
197
+ $ two = $ this ->context ->builder ->ptrToInt ($ __value , $ __type );
198
+ break ;
199
+ default :
200
+ throw new \LogicException ("Unknown how to handle type pair (int, " . $ __other_type ->toString () . ") " );
201
+ }
202
+ break ;
203
+ case \PHPLLVM \Type::KIND_DOUBLE :
204
+ if (!is_object ($ __value )) {
205
+ $ two = $ __type ->constReal (2 );
206
+ break ;
207
+ }
208
+ $ __other_type = $ __value ->typeOf ();
209
+ switch ($ __other_type ->getKind ()) {
210
+ case \PHPLLVM \Type::KIND_INTEGER :
211
+
212
+ $ two = $ this ->context ->builder ->siToFp ($ __value , $ __type );
213
+
214
+ break ;
215
+ case \PHPLLVM \Type::KIND_DOUBLE :
216
+ $ two = $ this ->context ->builder ->fpCast ($ __value , $ __type );
217
+ break ;
218
+ default :
219
+ throw new \LogicException ("Unknown how to handle type pair (double, " . $ __other_type ->toString () . ") " );
220
+ }
221
+ break ;
222
+ case \PHPLLVM \Type::KIND_ARRAY :
223
+ case \PHPLLVM \Type::KIND_POINTER :
224
+ if (!is_object ($ __value )) {
225
+ // this is very likely very wrong...
226
+ $ two = $ __type ->constInt ($ __value , false );
227
+ break ;
228
+ }
229
+ $ __other_type = $ __value ->typeOf ();
230
+ switch ($ __other_type ->getKind ()) {
231
+ case \PHPLLVM \Type::KIND_INTEGER :
232
+ $ two = $ this ->context ->builder ->intToPtr ($ __value , $ __type );
233
+ break ;
234
+ case \PHPLLVM \Type::KIND_ARRAY :
235
+ // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type());
236
+ // $(result) = $this->context->builder->intToPtr($__tmp, $__type);
237
+ // break;
238
+ case \PHPLLVM \Type::KIND_POINTER :
239
+ $ two = $ this ->context ->builder ->pointerCast ($ __value , $ __type );
240
+ break ;
241
+ default :
242
+ throw new \LogicException ("Unknown how to handle type pair (double, " . $ __other_type ->toString () . ") " );
243
+ }
244
+ break ;
245
+ default :
246
+ throw new \LogicException ("Unsupported type cast: " . $ __type ->toString ());
247
+ }
248
+
171
249
172
- $ fn___c81e728d9d4c2f636f067f89cc14862c = $ this ->context ->lookupFunction ('__mm__malloc ' );
173
- $ block___c81e728d9d4c2f636f067f89cc14862c = $ fn___c81e728d9d4c2f636f067f89cc14862c ->appendBasicBlock ('main ' );
174
- $ this ->context ->builder ->positionAtEnd ($ block___c81e728d9d4c2f636f067f89cc14862c );
175
- $ size = $ fn___c81e728d9d4c2f636f067f89cc14862c ->getParam (0 );
250
+ $ fn___eccbc87e4b5ce2fe28308fd9f2a7baf3 = $ this ->context ->lookupFunction ('__mm__malloc ' );
251
+ $ block___eccbc87e4b5ce2fe28308fd9f2a7baf3 = $ fn___eccbc87e4b5ce2fe28308fd9f2a7baf3 ->appendBasicBlock ('main ' );
252
+ $ this ->context ->builder ->positionAtEnd ($ block___eccbc87e4b5ce2fe28308fd9f2a7baf3 );
253
+ $ size = $ fn___eccbc87e4b5ce2fe28308fd9f2a7baf3 ->getParam (0 );
176
254
177
255
$ result = $ this ->context ->builder ->call (
178
256
$ this ->context ->lookupFunction ('_emalloc ' ) ,
@@ -186,11 +264,11 @@ public function implement(): void {
186
264
$ this ->context ->builder ->returnValue ($ result );
187
265
188
266
$ this ->context ->builder ->clearInsertionPosition ();
189
- $ fn___a87ff679a2f3e71d9181a67b7542122c = $ this ->context ->lookupFunction ('__mm__realloc ' );
190
- $ block___a87ff679a2f3e71d9181a67b7542122c = $ fn___a87ff679a2f3e71d9181a67b7542122c ->appendBasicBlock ('main ' );
191
- $ this ->context ->builder ->positionAtEnd ($ block___a87ff679a2f3e71d9181a67b7542122c );
192
- $ void = $ fn___a87ff679a2f3e71d9181a67b7542122c ->getParam (0 );
193
- $ size = $ fn___a87ff679a2f3e71d9181a67b7542122c ->getParam (1 );
267
+ $ fn___e4da3b7fbbce2345d7772b0674a318d5 = $ this ->context ->lookupFunction ('__mm__realloc ' );
268
+ $ block___e4da3b7fbbce2345d7772b0674a318d5 = $ fn___e4da3b7fbbce2345d7772b0674a318d5 ->appendBasicBlock ('main ' );
269
+ $ this ->context ->builder ->positionAtEnd ($ block___e4da3b7fbbce2345d7772b0674a318d5 );
270
+ $ void = $ fn___e4da3b7fbbce2345d7772b0674a318d5 ->getParam (0 );
271
+ $ size = $ fn___e4da3b7fbbce2345d7772b0674a318d5 ->getParam (1 );
194
272
195
273
$ result = $ this ->context ->builder ->call (
196
274
$ this ->context ->lookupFunction ('_erealloc ' ) ,
@@ -205,10 +283,10 @@ public function implement(): void {
205
283
$ this ->context ->builder ->returnValue ($ result );
206
284
207
285
$ this ->context ->builder ->clearInsertionPosition ();
208
- $ fn___1679091c5a880faf6fb5e6087eb1b2dc = $ this ->context ->lookupFunction ('__mm__free ' );
209
- $ block___1679091c5a880faf6fb5e6087eb1b2dc = $ fn___1679091c5a880faf6fb5e6087eb1b2dc ->appendBasicBlock ('main ' );
210
- $ this ->context ->builder ->positionAtEnd ($ block___1679091c5a880faf6fb5e6087eb1b2dc );
211
- $ void = $ fn___1679091c5a880faf6fb5e6087eb1b2dc ->getParam (0 );
286
+ $ fn___8f14e45fceea167a5a36dedd4bea2543 = $ this ->context ->lookupFunction ('__mm__free ' );
287
+ $ block___8f14e45fceea167a5a36dedd4bea2543 = $ fn___8f14e45fceea167a5a36dedd4bea2543 ->appendBasicBlock ('main ' );
288
+ $ this ->context ->builder ->positionAtEnd ($ block___8f14e45fceea167a5a36dedd4bea2543 );
289
+ $ void = $ fn___8f14e45fceea167a5a36dedd4bea2543 ->getParam (0 );
212
290
213
291
$ this ->context ->builder ->call (
214
292
$ this ->context ->lookupFunction ('_efree ' ) ,
@@ -223,10 +301,10 @@ public function implement(): void {
223
301
224
302
$ this ->context ->builder ->clearInsertionPosition ();
225
303
} else {
226
- $ fn___c9f0f895fb98ab9159f51fd0297e236d = $ this ->context ->lookupFunction ('__mm__malloc ' );
227
- $ block___c9f0f895fb98ab9159f51fd0297e236d = $ fn___c9f0f895fb98ab9159f51fd0297e236d ->appendBasicBlock ('main ' );
228
- $ this ->context ->builder ->positionAtEnd ($ block___c9f0f895fb98ab9159f51fd0297e236d );
229
- $ size = $ fn___c9f0f895fb98ab9159f51fd0297e236d ->getParam (0 );
304
+ $ fn___45c48cce2e2d7fbdea1afc51c7c6ad26 = $ this ->context ->lookupFunction ('__mm__malloc ' );
305
+ $ block___45c48cce2e2d7fbdea1afc51c7c6ad26 = $ fn___45c48cce2e2d7fbdea1afc51c7c6ad26 ->appendBasicBlock ('main ' );
306
+ $ this ->context ->builder ->positionAtEnd ($ block___45c48cce2e2d7fbdea1afc51c7c6ad26 );
307
+ $ size = $ fn___45c48cce2e2d7fbdea1afc51c7c6ad26 ->getParam (0 );
230
308
231
309
$ result = $ this ->context ->builder ->call (
232
310
$ this ->context ->lookupFunction ('_emalloc ' ) ,
@@ -236,11 +314,11 @@ public function implement(): void {
236
314
$ this ->context ->builder ->returnValue ($ result );
237
315
238
316
$ this ->context ->builder ->clearInsertionPosition ();
239
- $ fn___d3d9446802a44259755d38e6d163e820 = $ this ->context ->lookupFunction ('__mm__realloc ' );
240
- $ block___d3d9446802a44259755d38e6d163e820 = $ fn___d3d9446802a44259755d38e6d163e820 ->appendBasicBlock ('main ' );
241
- $ this ->context ->builder ->positionAtEnd ($ block___d3d9446802a44259755d38e6d163e820 );
242
- $ void = $ fn___d3d9446802a44259755d38e6d163e820 ->getParam (0 );
243
- $ size = $ fn___d3d9446802a44259755d38e6d163e820 ->getParam (1 );
317
+ $ fn___6512bd43d9caa6e02c990b0a82652dca = $ this ->context ->lookupFunction ('__mm__realloc ' );
318
+ $ block___6512bd43d9caa6e02c990b0a82652dca = $ fn___6512bd43d9caa6e02c990b0a82652dca ->appendBasicBlock ('main ' );
319
+ $ this ->context ->builder ->positionAtEnd ($ block___6512bd43d9caa6e02c990b0a82652dca );
320
+ $ void = $ fn___6512bd43d9caa6e02c990b0a82652dca ->getParam (0 );
321
+ $ size = $ fn___6512bd43d9caa6e02c990b0a82652dca ->getParam (1 );
244
322
245
323
$ result = $ this ->context ->builder ->call (
246
324
$ this ->context ->lookupFunction ('_erealloc ' ) ,
@@ -251,10 +329,10 @@ public function implement(): void {
251
329
$ this ->context ->builder ->returnValue ($ result );
252
330
253
331
$ this ->context ->builder ->clearInsertionPosition ();
254
- $ fn___c20ad4d76fe97759aa27a0c99bff6710 = $ this ->context ->lookupFunction ('__mm__free ' );
255
- $ block___c20ad4d76fe97759aa27a0c99bff6710 = $ fn___c20ad4d76fe97759aa27a0c99bff6710 ->appendBasicBlock ('main ' );
256
- $ this ->context ->builder ->positionAtEnd ($ block___c20ad4d76fe97759aa27a0c99bff6710 );
257
- $ void = $ fn___c20ad4d76fe97759aa27a0c99bff6710 ->getParam (0 );
332
+ $ fn___c51ce410c124a10e0db5e4b97fc2af39 = $ this ->context ->lookupFunction ('__mm__free ' );
333
+ $ block___c51ce410c124a10e0db5e4b97fc2af39 = $ fn___c51ce410c124a10e0db5e4b97fc2af39 ->appendBasicBlock ('main ' );
334
+ $ this ->context ->builder ->positionAtEnd ($ block___c51ce410c124a10e0db5e4b97fc2af39 );
335
+ $ void = $ fn___c51ce410c124a10e0db5e4b97fc2af39 ->getParam (0 );
258
336
259
337
$ this ->context ->builder ->call (
260
338
$ this ->context ->lookupFunction ('_efree ' ) ,
0 commit comments