2
2
3
3
use crate :: codegen:: cfg:: HashTy ;
4
4
use crate :: codegen:: Expression ;
5
- <<<<<<< HEAD
6
5
use crate :: emit:: binary:: { self , Binary } ;
7
6
use crate :: emit:: soroban:: { SorobanTarget , GET_CONTRACT_DATA , LOG_FROM_LINEAR_MEMORY , PUT_CONTRACT_DATA } ;
8
- =======
9
- use crate :: emit:: binary:: Binary ;
10
- use crate :: emit:: soroban:: { SorobanTarget , GET_CONTRACT_DATA , PUT_CONTRACT_DATA } ;
11
- >>>>>>> 06798 cdeac6fd62ee98f5ae7da38f3af4933dc0f
12
7
use crate :: emit:: ContractArgs ;
13
8
use crate :: emit:: { TargetRuntime , Variable } ;
14
9
use crate :: emit_context;
@@ -18,17 +13,10 @@ use crate::sema::ast::{Function, Namespace, Type};
18
13
19
14
use inkwell:: types:: { BasicTypeEnum , IntType } ;
20
15
use inkwell:: values:: {
21
- <<<<<<< HEAD
22
16
AnyValue , ArrayValue , AsValueRef , BasicMetadataValueEnum , BasicValue , BasicValueEnum , FunctionValue , IntValue , PointerValue
23
17
} ;
24
18
25
19
use inkwell:: AddressSpace ;
26
- =======
27
- ArrayValue , BasicMetadataValueEnum , BasicValue , BasicValueEnum , FunctionValue , IntValue ,
28
- PointerValue ,
29
- } ;
30
-
31
- >>>>>>> 06798 cdeac6fd62ee98f5ae7da38f3af4933dc0f
32
20
use solang_parser:: pt:: Loc ;
33
21
34
22
use std:: collections:: HashMap ;
@@ -248,35 +236,76 @@ impl<'a> TargetRuntime<'a> for SorobanTarget {
248
236
249
237
/// Prints a string
250
238
/// TODO: Implement this function, with a call to the `log` function in the Soroban runtime.
251
- <<<<<<< HEAD
252
239
fn print ( & self , bin : & Binary , string : PointerValue , length : IntValue ) {
253
240
254
241
242
+ if string. is_const ( ) {
255
243
256
- let mut toprint;
257
- unsafe {
258
- toprint = string. as_value_ref( ) . offset( 0 ) ;
259
- println!( "TO PRINT! {:?}" , toprint) ;
260
- }
261
- //println!("print called with string: {:?} ", string.as_value_ref());
262
244
println ! ( "msg_pos: {:?}" , string) ;
263
245
println ! ( "length: {:?}" , length) ;
264
246
265
247
let msg_pos = bin. builder . build_ptr_to_int ( string, bin. context . i64_type ( ) , "msg_pos" ) . unwrap ( ) ;
266
-
267
248
let msg_pos = msg_pos. const_cast ( bin. context . i64_type ( ) , false ) ;
268
249
269
250
270
251
271
252
println ! ( "msg_pos extracted: {:?}" , msg_pos) ;
272
253
println ! ( "=============================================================" ) ;
273
254
255
+ let length = length. const_cast ( bin. context . i64_type ( ) , false ) ;
256
+
257
+
258
+ let eight = bin. context . i64_type ( ) . const_int ( 8 , false ) ;
259
+ let four = bin. context . i64_type ( ) . const_int ( 4 , false ) ;
260
+ let zero = bin. context . i64_type ( ) . const_int ( 0 , false ) ;
261
+ let thirty_two = bin. context . i64_type ( ) . const_int ( 32 , false ) ;
262
+
263
+ // encode msg_pos and length
264
+ let msg_pos_encoded = bin. builder . build_left_shift ( msg_pos, thirty_two, "temp" ) . unwrap ( ) ;
265
+ let msg_pos_encoded = bin. builder . build_int_add ( msg_pos_encoded, four, "msg_pos_encoded" ) . unwrap ( ) ;
266
+
274
267
268
+
269
+ let length_encoded = bin. builder . build_left_shift ( length, thirty_two, "temp" ) . unwrap ( ) ;
270
+ let length_encoded = bin. builder . build_int_add ( length_encoded, four, "length_encoded" ) . unwrap ( ) ;
271
+
272
+
273
+ let zero_encoded = bin. builder . build_left_shift ( zero, eight, "temp" ) . unwrap ( ) ;
275
274
276
275
277
- //let length = bin.context.i64_type().const_int(1024, false);
276
+ let eight_encoded = bin. builder . build_left_shift ( eight, eight, "temp" ) . unwrap ( ) ;
277
+ let eight_encoded = bin. builder . build_int_add ( eight_encoded, four, "eight_encoded" ) . unwrap ( ) ;
278
+
278
279
279
- let length = length. const_cast( bin. context. i64_type( ) , false ) ;
280
+
281
+
282
+ let call_res = bin. builder . build_call (
283
+ bin. module . get_function ( LOG_FROM_LINEAR_MEMORY ) . unwrap ( ) ,
284
+ & [
285
+ msg_pos_encoded. into ( ) ,
286
+ length_encoded. into ( ) ,
287
+ msg_pos_encoded. into ( ) ,
288
+ four. into ( ) ,
289
+ ] ,
290
+ "log" ,
291
+ ) . unwrap ( ) ;
292
+ }
293
+
294
+ else {
295
+
296
+
297
+ /*println!("msg_pos: {:?}", string);
298
+ println!("length: {:?}", length);
299
+
300
+ let msg_pos = bin.builder.build_ptr_to_int(string, bin.context.i64_type(), "msg_pos").unwrap();
301
+ //let msg_pos = msg_pos.const_cast(bin.context.i64_type(), false);
302
+
303
+
304
+
305
+ println!("msg_pos extracted: {:?}", msg_pos);
306
+ println!("=============================================================");
307
+
308
+ //let length = length.const_cast(bin.context.i64_type(), false);
280
309
281
310
282
311
let eight = bin.context.i64_type().const_int(8, false);
@@ -288,11 +317,24 @@ impl<'a> TargetRuntime<'a> for SorobanTarget {
288
317
let msg_pos_encoded = bin.builder.build_left_shift(msg_pos, thirty_two, "temp").unwrap();
289
318
let msg_pos_encoded = bin.builder.build_int_add(msg_pos_encoded, four, "msg_pos_encoded").unwrap();
290
319
320
+ println!("CAN MSG ENCODE");
321
+
322
+
291
323
324
+ //let length = bin.builder.build_int_z_extend(length, bin.context.i64_type(), "extended").unwrap();
325
+
326
+
327
+ let length_type = length.get_type();
328
+ println!("LENGTH TYPE: {:?}", length_type);
329
+
330
+ //let length = bin.builder.build_int_z_extend(length, bin.context.i64_type(), "extended").unwrap();
331
+ //let length = bin.builder.build_int_cast(length, bin.context.i64_type(), "extended").unwrap();
292
332
293
333
let length_encoded = bin.builder.build_left_shift(length, thirty_two, "temp").unwrap();
294
334
let length_encoded = bin.builder.build_int_add(length_encoded, four, "length_encoded").unwrap();
295
335
336
+ println!("CAN LENGTH ENCODE");
337
+
296
338
297
339
let zero_encoded = bin.builder.build_left_shift(zero, eight, "temp").unwrap();
298
340
@@ -313,11 +355,12 @@ impl<'a> TargetRuntime<'a> for SorobanTarget {
313
355
],
314
356
"log",
315
357
).unwrap();
358
+ */
359
+
360
+
361
+ }
316
362
317
363
}
318
- =======
319
- fn print( & self , bin: & Binary , string: PointerValue , length: IntValue ) { }
320
- >>>>>>> 06798 cdeac6fd62ee98f5ae7da38f3af4933dc0f
321
364
322
365
/// Return success without any result
323
366
fn return_empty_abi ( & self , bin : & Binary ) {
0 commit comments