@@ -34,6 +34,7 @@ pub const MAX_MAKE_VEC_ARGS: usize = 4;
34
34
pub const TABLE_NATIVE_SPEC_ERROR : & str =
35
35
"Native functions defined in Table cannot be used as specification functions" ;
36
36
const NUM_TYPE_BASE_ERROR : & str = "cannot infer concrete integer type from `num`, consider using a concrete integer type or explicit type cast" ;
37
+ pub const BITWISE_NOT_ENABLED_ERROR : & str = "bitwise operations not enabled for this type" ;
37
38
38
39
/// Return boogie name of given module.
39
40
pub fn boogie_module_name ( env : & ModuleEnv < ' _ > ) -> String {
@@ -338,14 +339,11 @@ pub fn boogie_type(env: &GlobalEnv, ty: &Type) -> String {
338
339
use Type :: * ;
339
340
match ty {
340
341
Primitive ( p) => match p {
341
- U8 | U16 | U32 | U64 | U128 | U256 | Num | Address => "int" . to_string ( ) ,
342
+ U8 | U16 | U32 | U64 | U128 | U256 | I8 | I16 | I32 | I64 | I128 | I256 | Num
343
+ | Address => "int" . to_string ( ) ,
342
344
Signer => "$signer" . to_string ( ) ,
343
345
Bool => "bool" . to_string ( ) ,
344
346
Range | EventStore => panic ! ( "unexpected type" ) ,
345
- I8 | I16 | I32 | I64 | I128 | I256 => {
346
- // TODO(#17645): add support
347
- unimplemented ! ( "signed integer not supported" ) ;
348
- } ,
349
347
} ,
350
348
Vector ( et) => format ! ( "Vec ({})" , boogie_type( env, et) ) ,
351
349
Struct ( mid, sid, inst) => boogie_struct_name ( & env. get_module ( * mid) . into_struct ( * sid) , inst) ,
@@ -389,6 +387,7 @@ pub fn boogie_bv_type(env: &GlobalEnv, ty: &Type) -> String {
389
387
U64 => "bv64" . to_string ( ) ,
390
388
U128 => "bv128" . to_string ( ) ,
391
389
U256 => "bv256" . to_string ( ) ,
390
+ I8 | I16 | I32 | I64 | I128 | I256 => unreachable ! ( "{}" , BITWISE_NOT_ENABLED_ERROR ) ,
392
391
Address => "int" . to_string ( ) ,
393
392
Signer => "$signer" . to_string ( ) ,
394
393
Bool => "bool" . to_string ( ) ,
@@ -397,10 +396,6 @@ pub fn boogie_bv_type(env: &GlobalEnv, ty: &Type) -> String {
397
396
//TODO(tengzhang): add error message with accurate location info
398
397
"<<num is not unsupported here>>" . to_string ( )
399
398
} ,
400
- I8 | I16 | I32 | I64 | I128 | I256 => {
401
- // TODO(#17645): add support
402
- unimplemented ! ( "signed integer not supported" )
403
- } ,
404
399
} ,
405
400
Vector ( et) => format ! ( "Vec ({})" , boogie_bv_type( env, et) ) ,
406
401
Struct ( mid, sid, inst) => {
@@ -424,6 +419,14 @@ pub fn boogie_num_type_base_bv(env: &GlobalEnv, loc: Option<Loc>, ty: &Type) ->
424
419
Type :: Primitive ( PrimitiveType :: U64 ) => "Bv64" ,
425
420
Type :: Primitive ( PrimitiveType :: U128 ) => "Bv128" ,
426
421
Type :: Primitive ( PrimitiveType :: U256 ) => "Bv256" ,
422
+ Type :: Primitive ( PrimitiveType :: I8 )
423
+ | Type :: Primitive ( PrimitiveType :: I16 )
424
+ | Type :: Primitive ( PrimitiveType :: I32 )
425
+ | Type :: Primitive ( PrimitiveType :: I64 )
426
+ | Type :: Primitive ( PrimitiveType :: I128 )
427
+ | Type :: Primitive ( PrimitiveType :: I256 ) => {
428
+ unreachable ! ( "{}" , BITWISE_NOT_ENABLED_ERROR ) ;
429
+ } ,
427
430
Type :: Primitive ( PrimitiveType :: Num ) => {
428
431
env. error ( & loc. unwrap_or_default ( ) , NUM_TYPE_BASE_ERROR ) ;
429
432
"<<num is not unsupported here>>"
@@ -454,13 +457,13 @@ pub fn boogie_num_literal(num: &String, base: usize, bv_flag: bool) -> String {
454
457
}
455
458
}
456
459
457
- pub fn boogie_num_type_string ( num : & str , bv_flag : bool ) -> String {
458
- let pre = if bv_flag { "bv" } else { "u" } ;
460
+ pub fn boogie_num_type_string ( kind : & str , num : & str , bv_flag : bool ) -> String {
461
+ let pre = if bv_flag { "bv" } else { kind } ;
459
462
[ pre, num] . join ( "" )
460
463
}
461
464
462
- pub fn boogie_num_type_string_capital ( num : & str , bv_flag : bool ) -> String {
463
- let pre = if bv_flag { "Bv" } else { "U" } ;
465
+ pub fn boogie_num_type_string_capital ( kind : & str , num : & str , bv_flag : bool ) -> String {
466
+ let pre = if bv_flag { "Bv" } else { kind } ;
464
467
[ pre, num] . join ( "" )
465
468
}
466
469
@@ -475,6 +478,9 @@ pub fn boogie_num_type_base(env: &GlobalEnv, loc: Option<Loc>, ty: &Type) -> Str
475
478
U64 => "64" . to_string ( ) ,
476
479
U128 => "128" . to_string ( ) ,
477
480
U256 => "256" . to_string ( ) ,
481
+ I8 | I16 | I32 | I64 | I128 | I256 => {
482
+ unreachable ! ( "{}" , BITWISE_NOT_ENABLED_ERROR ) ;
483
+ } ,
478
484
Num => {
479
485
env. error ( & loc. unwrap_or_default ( ) , NUM_TYPE_BASE_ERROR ) ;
480
486
"<<num is not unsupported here>>" . to_string ( )
@@ -492,12 +498,18 @@ pub fn boogie_type_suffix_bv(env: &GlobalEnv, ty: &Type, bv_flag: bool) -> Strin
492
498
493
499
match ty {
494
500
Primitive ( p) => match p {
495
- U8 => boogie_num_type_string ( "8" , bv_flag) ,
496
- U16 => boogie_num_type_string ( "16" , bv_flag) ,
497
- U32 => boogie_num_type_string ( "32" , bv_flag) ,
498
- U64 => boogie_num_type_string ( "64" , bv_flag) ,
499
- U128 => boogie_num_type_string ( "128" , bv_flag) ,
500
- U256 => boogie_num_type_string ( "256" , bv_flag) ,
501
+ U8 => boogie_num_type_string ( "u" , "8" , bv_flag) ,
502
+ U16 => boogie_num_type_string ( "u" , "16" , bv_flag) ,
503
+ U32 => boogie_num_type_string ( "u" , "32" , bv_flag) ,
504
+ U64 => boogie_num_type_string ( "u" , "64" , bv_flag) ,
505
+ U128 => boogie_num_type_string ( "u" , "128" , bv_flag) ,
506
+ U256 => boogie_num_type_string ( "u" , "256" , bv_flag) ,
507
+ I8 => boogie_num_type_string ( "i" , "8" , bv_flag) ,
508
+ I16 => boogie_num_type_string ( "i" , "16" , bv_flag) ,
509
+ I32 => boogie_num_type_string ( "i" , "32" , bv_flag) ,
510
+ I64 => boogie_num_type_string ( "i" , "64" , bv_flag) ,
511
+ I128 => boogie_num_type_string ( "i" , "128" , bv_flag) ,
512
+ I256 => boogie_num_type_string ( "i" , "256" , bv_flag) ,
501
513
Num => {
502
514
if bv_flag {
503
515
//TODO(tengzhang): add error message with accurate location info
@@ -511,10 +523,6 @@ pub fn boogie_type_suffix_bv(env: &GlobalEnv, ty: &Type, bv_flag: bool) -> Strin
511
523
Bool => "bool" . to_string ( ) ,
512
524
Range => "range" . to_string ( ) ,
513
525
EventStore => format ! ( "<<unsupported {:?}>>" , ty) ,
514
- I8 | I16 | I32 | I64 | I128 | I256 => {
515
- // TODO(#17645): add support
516
- unimplemented ! ( "signed integer not supported" )
517
- } ,
518
526
} ,
519
527
Vector ( et) => format ! (
520
528
"vec{}" ,
@@ -704,9 +712,17 @@ pub fn boogie_constant(env: &GlobalEnv, _options: &BoogieOptions, val: &Constant
704
712
Constant :: Bool ( true ) => "true" . to_string ( ) ,
705
713
Constant :: Bool ( false ) => "false" . to_string ( ) ,
706
714
Constant :: U8 ( num) => num. to_string ( ) ,
715
+ Constant :: U16 ( num) => num. to_string ( ) ,
716
+ Constant :: U32 ( num) => num. to_string ( ) ,
707
717
Constant :: U64 ( num) => num. to_string ( ) ,
708
718
Constant :: U128 ( num) => num. to_string ( ) ,
709
719
Constant :: U256 ( num) => num. to_string ( ) ,
720
+ Constant :: I8 ( num) => num. to_string ( ) ,
721
+ Constant :: I16 ( num) => num. to_string ( ) ,
722
+ Constant :: I32 ( num) => num. to_string ( ) ,
723
+ Constant :: I64 ( num) => num. to_string ( ) ,
724
+ Constant :: I128 ( num) => num. to_string ( ) ,
725
+ Constant :: I256 ( num) => num. to_string ( ) ,
710
726
Constant :: Address ( v) => boogie_address ( env, v) ,
711
727
Constant :: ByteArray ( v) => boogie_byte_blob ( _options, v, false ) ,
712
728
Constant :: AddressArray ( v) => boogie_address_blob ( env, _options, v) ,
@@ -715,17 +731,6 @@ pub fn boogie_constant(env: &GlobalEnv, _options: &BoogieOptions, val: &Constant
715
731
. map ( |v| boogie_constant ( env, _options, v) )
716
732
. collect_vec ( ) ,
717
733
) ,
718
- Constant :: U16 ( num) => num. to_string ( ) ,
719
- Constant :: U32 ( num) => num. to_string ( ) ,
720
- Constant :: I8 ( _)
721
- | Constant :: I16 ( _)
722
- | Constant :: I32 ( _)
723
- | Constant :: I64 ( _)
724
- | Constant :: I128 ( _)
725
- | Constant :: I256 ( _) => {
726
- // TODO(#17645): add support
727
- unimplemented ! ( "signed integer not supported" )
728
- } ,
729
734
}
730
735
}
731
736
@@ -967,6 +972,12 @@ fn type_name_to_ident_tokens(
967
972
Type :: Primitive ( PrimitiveType :: U64 ) => TypeIdentToken :: make ( "u64" ) ,
968
973
Type :: Primitive ( PrimitiveType :: U128 ) => TypeIdentToken :: make ( "u128" ) ,
969
974
Type :: Primitive ( PrimitiveType :: U256 ) => TypeIdentToken :: make ( "u256" ) ,
975
+ Type :: Primitive ( PrimitiveType :: I8 ) => TypeIdentToken :: make ( "i8" ) ,
976
+ Type :: Primitive ( PrimitiveType :: I16 ) => TypeIdentToken :: make ( "i16" ) ,
977
+ Type :: Primitive ( PrimitiveType :: I32 ) => TypeIdentToken :: make ( "i32" ) ,
978
+ Type :: Primitive ( PrimitiveType :: I64 ) => TypeIdentToken :: make ( "i64" ) ,
979
+ Type :: Primitive ( PrimitiveType :: I128 ) => TypeIdentToken :: make ( "i128" ) ,
980
+ Type :: Primitive ( PrimitiveType :: I256 ) => TypeIdentToken :: make ( "i256" ) ,
970
981
Type :: Primitive ( PrimitiveType :: Address ) => TypeIdentToken :: make ( "address" ) ,
971
982
Type :: Primitive ( PrimitiveType :: Signer ) => TypeIdentToken :: make ( "signer" ) ,
972
983
Type :: Vector ( element) => {
@@ -1022,15 +1033,6 @@ fn type_name_to_ident_tokens(
1022
1033
Type :: Error | Type :: Var ( ..) => {
1023
1034
unreachable ! ( "Unexpected temporary type in type_name call" ) ;
1024
1035
} ,
1025
- Type :: Primitive ( PrimitiveType :: I8 )
1026
- | Type :: Primitive ( PrimitiveType :: I16 )
1027
- | Type :: Primitive ( PrimitiveType :: I32 )
1028
- | Type :: Primitive ( PrimitiveType :: I64 )
1029
- | Type :: Primitive ( PrimitiveType :: I128 )
1030
- | Type :: Primitive ( PrimitiveType :: I256 ) => {
1031
- // TODO(#17645): add support
1032
- unimplemented ! ( "signed integer not supported" )
1033
- } ,
1034
1036
}
1035
1037
}
1036
1038
@@ -1103,6 +1105,12 @@ fn type_name_to_info_pack(env: &GlobalEnv, ty: &Type) -> Option<TypeInfoPack> {
1103
1105
| Type :: Primitive ( PrimitiveType :: U64 )
1104
1106
| Type :: Primitive ( PrimitiveType :: U128 )
1105
1107
| Type :: Primitive ( PrimitiveType :: U256 )
1108
+ | Type :: Primitive ( PrimitiveType :: I8 )
1109
+ | Type :: Primitive ( PrimitiveType :: I16 )
1110
+ | Type :: Primitive ( PrimitiveType :: I32 )
1111
+ | Type :: Primitive ( PrimitiveType :: I64 )
1112
+ | Type :: Primitive ( PrimitiveType :: I128 )
1113
+ | Type :: Primitive ( PrimitiveType :: I256 )
1106
1114
| Type :: Primitive ( PrimitiveType :: Address )
1107
1115
| Type :: Primitive ( PrimitiveType :: Signer )
1108
1116
| Type :: Vector ( _) => None ,
@@ -1123,15 +1131,6 @@ fn type_name_to_info_pack(env: &GlobalEnv, ty: &Type) -> Option<TypeInfoPack> {
1123
1131
Type :: Error | Type :: Var ( ..) => {
1124
1132
unreachable ! ( "Unexpected temporary type in type_name call" ) ;
1125
1133
} ,
1126
- Type :: Primitive ( PrimitiveType :: I8 )
1127
- | Type :: Primitive ( PrimitiveType :: I16 )
1128
- | Type :: Primitive ( PrimitiveType :: I32 )
1129
- | Type :: Primitive ( PrimitiveType :: I64 )
1130
- | Type :: Primitive ( PrimitiveType :: I128 )
1131
- | Type :: Primitive ( PrimitiveType :: I256 ) => {
1132
- // TODO(#17645): add support
1133
- unimplemented ! ( "signed integer not supported" )
1134
- } ,
1135
1134
}
1136
1135
}
1137
1136
0 commit comments