@@ -255,8 +255,8 @@ def visit_Expr(self, node):
255
255
def visit_Pass (self , node ):
256
256
# Insert a dummy instruction so that analyses which extract
257
257
# locations from CFG have something to use.
258
- self .append (ir .BinaryOp (ast .Add (loc = None ),
259
- ir .Constant (0 , self ._size_type ), ir .Constant (0 , self ._size_type )))
258
+ self .append (ir .Arith (ast .Add (loc = None ),
259
+ ir .Constant (0 , self ._size_type ), ir .Constant (0 , self ._size_type )))
260
260
261
261
def visit_Assign (self , node ):
262
262
try :
@@ -270,7 +270,7 @@ def visit_Assign(self, node):
270
270
def visit_AugAssign (self , node ):
271
271
lhs = self .visit (target )
272
272
rhs = self .visit (node .value )
273
- value = self .append (ir .BinaryOp (node .op , lhs , rhs ))
273
+ value = self .append (ir .Arith (node .op , lhs , rhs ))
274
274
try :
275
275
self .current_assign = value
276
276
self .visit (node .target )
@@ -346,8 +346,8 @@ def _iterable_len(self, value, typ=builtins.TInt(types.TValue(32))):
346
346
start = self .append (ir .GetAttr (value , "start" ))
347
347
stop = self .append (ir .GetAttr (value , "stop" ))
348
348
step = self .append (ir .GetAttr (value , "step" ))
349
- spread = self .append (ir .BinaryOp (ast .Sub (loc = None ), stop , start ))
350
- return self .append (ir .BinaryOp (ast .FloorDiv (loc = None ), spread , step ))
349
+ spread = self .append (ir .Arith (ast .Sub (loc = None ), stop , start ))
350
+ return self .append (ir .Arith (ast .FloorDiv (loc = None ), spread , step ))
351
351
else :
352
352
assert False
353
353
@@ -358,8 +358,8 @@ def _iterable_get(self, value, index):
358
358
elif builtins .is_range (value .type ):
359
359
start = self .append (ir .GetAttr (value , "start" ))
360
360
step = self .append (ir .GetAttr (value , "step" ))
361
- offset = self .append (ir .BinaryOp (ast .Mult (loc = None ), step , index ))
362
- return self .append (ir .BinaryOp (ast .Add (loc = None ), start , offset ))
361
+ offset = self .append (ir .Arith (ast .Mult (loc = None ), step , index ))
362
+ return self .append (ir .Arith (ast .Add (loc = None ), start , offset ))
363
363
else :
364
364
assert False
365
365
@@ -382,8 +382,7 @@ def visit_For(self, node):
382
382
old_continue , self .continue_target = self .continue_target , continue_block
383
383
self .current_block = continue_block
384
384
385
- updated_index = self .append (ir .BinaryOp (ast .Add (loc = None ), phi ,
386
- ir .Constant (1 , phi .type )))
385
+ updated_index = self .append (ir .Arith (ast .Add (loc = None ), phi , ir .Constant (1 , phi .type )))
387
386
phi .add_incoming (updated_index , continue_block )
388
387
self .append (ir .Branch (head ))
389
388
@@ -604,7 +603,7 @@ def visit_AttributeT(self, node):
604
603
def _map_index (self , length , index ):
605
604
lt_0 = self .append (ir .Compare (ast .Lt (loc = None ),
606
605
index , ir .Constant (0 , index .type )))
607
- from_end = self .append (ir .BinaryOp (ast .Add (loc = None ), length , index ))
606
+ from_end = self .append (ir .Arith (ast .Add (loc = None ), length , index ))
608
607
mapped_index = self .append (ir .Select (lt_0 , from_end , index ))
609
608
mapped_ge_0 = self .append (ir .Compare (ast .GtE (loc = None ),
610
609
mapped_index , ir .Constant (0 , mapped_index .type )))
@@ -696,9 +695,9 @@ def visit_SubscriptT(self, node):
696
695
else :
697
696
step = ir .Constant (1 , node .slice .type )
698
697
699
- unstepped_size = self .append (ir .BinaryOp (ast .Sub (loc = None ),
700
- mapped_max_index , mapped_min_index ))
701
- slice_size = self .append (ir .BinaryOp (ast .FloorDiv (loc = None ), unstepped_size , step ))
698
+ unstepped_size = self .append (ir .Arith (ast .Sub (loc = None ),
699
+ mapped_max_index , mapped_min_index ))
700
+ slice_size = self .append (ir .Arith (ast .FloorDiv (loc = None ), unstepped_size , step ))
702
701
703
702
self ._make_check (self .append (ir .Compare (ast .Eq (loc = None ), slice_size , length )),
704
703
lambda : self .append (ir .Alloc ([], builtins .TValueError ())))
@@ -709,8 +708,8 @@ def visit_SubscriptT(self, node):
709
708
other_value = self .current_assign
710
709
711
710
def body_gen (other_index ):
712
- offset = self .append (ir .BinaryOp (ast .Mult (loc = None ), step , other_index ))
713
- index = self .append (ir .BinaryOp (ast .Add (loc = None ), min_index , offset ))
711
+ offset = self .append (ir .Arith (ast .Mult (loc = None ), step , other_index ))
712
+ index = self .append (ir .Arith (ast .Add (loc = None ), min_index , offset ))
714
713
715
714
if self .current_assign is None :
716
715
elem = self ._iterable_get (value , index )
@@ -719,8 +718,8 @@ def body_gen(other_index):
719
718
elem = self .append (ir .GetElem (self .current_assign , other_index ))
720
719
self .append (ir .SetElem (value , index , elem ))
721
720
722
- return self .append (ir .BinaryOp (ast .Add (loc = None ), other_index ,
723
- ir .Constant (1 , node .slice .type )))
721
+ return self .append (ir .Arith (ast .Add (loc = None ), other_index ,
722
+ ir .Constant (1 , node .slice .type )))
724
723
self ._make_loop (ir .Constant (0 , node .slice .type ),
725
724
lambda index : self .append (ir .Compare (ast .Lt (loc = None ), index , slice_size )),
726
725
body_gen )
@@ -790,8 +789,8 @@ def body_gen(index):
790
789
791
790
mapped_elt = self .visit (node .elt )
792
791
self .append (ir .SetElem (result , index , mapped_elt ))
793
- return self .append (ir .BinaryOp (ast .Add (loc = None ), index ,
794
- ir .Constant (1 , length .type )))
792
+ return self .append (ir .Arith (ast .Add (loc = None ), index ,
793
+ ir .Constant (1 , length .type )))
795
794
self ._make_loop (ir .Constant (0 , length .type ),
796
795
lambda index : self .append (ir .Compare (ast .Lt (loc = None ), index , length )),
797
796
body_gen )
@@ -822,8 +821,15 @@ def visit_UnaryOpT(self, node):
822
821
return self .append (ir .Select (node .operand ,
823
822
ir .Constant (False , builtins .TBool ()),
824
823
ir .Constant (True , builtins .TBool ())))
825
- else : # Numeric operators
826
- return self .append (ir .UnaryOp (node .op , self .visit (node .operand )))
824
+ elif isinstance (node .op , ast .USub ):
825
+ operand = self .visit (node .operand )
826
+ return self .append (ir .Arith (ast .Sub (loc = None ),
827
+ ir .Constant (0 , operand .type ), operand ))
828
+ elif isinstance (node .op , ast .UAdd ):
829
+ # No-op.
830
+ return self .visit (node .operand )
831
+ else :
832
+ assert False
827
833
828
834
def visit_CoerceT (self , node ):
829
835
value = self .visit (node .value )
@@ -836,9 +842,7 @@ def visit_CoerceT(self, node):
836
842
837
843
def visit_BinOpT (self , node ):
838
844
if builtins .is_numeric (node .type ):
839
- return self .append (ir .BinaryOp (node .op ,
840
- self .visit (node .left ),
841
- self .visit (node .right )))
845
+ return self .append (ir .Arith (node .op , self .visit (node .left ), self .visit (node .right )))
842
846
elif isinstance (node .op , ast .Add ): # list + list, tuple + tuple
843
847
lhs , rhs = self .visit (node .left ), self .visit (node .right )
844
848
if types .is_tuple (node .left .type ) and builtins .is_tuple (node .right .type ):
@@ -852,26 +856,26 @@ def visit_BinOpT(self, node):
852
856
lhs_length = self .append (ir .Builtin ("len" , [lhs ], self ._size_type ))
853
857
rhs_length = self .append (ir .Builtin ("len" , [rhs ], self ._size_type ))
854
858
855
- result_length = self .append (ir .BinaryOp (ast .Add (loc = None ), lhs_length , rhs_length ))
859
+ result_length = self .append (ir .Arith (ast .Add (loc = None ), lhs_length , rhs_length ))
856
860
result = self .append (ir .Alloc ([result_length ], node .type ))
857
861
858
862
# Copy lhs
859
863
def body_gen (index ):
860
864
elt = self .append (ir .GetElem (lhs , index ))
861
865
self .append (ir .SetElem (result , index , elt ))
862
- return self .append (ir .BinaryOp (ast .Add (loc = None ), index ,
863
- ir .Constant (1 , self ._size_type )))
866
+ return self .append (ir .Arith (ast .Add (loc = None ), index ,
867
+ ir .Constant (1 , self ._size_type )))
864
868
self ._make_loop (ir .Constant (0 , self ._size_type ),
865
869
lambda index : self .append (ir .Compare (ast .Lt (loc = None ), index , lhs_length )),
866
870
body_gen )
867
871
868
872
# Copy rhs
869
873
def body_gen (index ):
870
874
elt = self .append (ir .GetElem (rhs , index ))
871
- result_index = self .append (ir .BinaryOp (ast .Add (loc = None ), index , lhs_length ))
875
+ result_index = self .append (ir .Arith (ast .Add (loc = None ), index , lhs_length ))
872
876
self .append (ir .SetElem (result , result_index , elt ))
873
- return self .append (ir .BinaryOp (ast .Add (loc = None ), index ,
874
- ir .Constant (1 , self ._size_type )))
877
+ return self .append (ir .Arith (ast .Add (loc = None ), index ,
878
+ ir .Constant (1 , self ._size_type )))
875
879
self ._make_loop (ir .Constant (0 , self ._size_type ),
876
880
lambda index : self .append (ir .Compare (ast .Lt (loc = None ), index , rhs_length )),
877
881
body_gen )
@@ -890,27 +894,27 @@ def body_gen(index):
890
894
891
895
lst_length = self .append (ir .Builtin ("len" , [lst ], self ._size_type ))
892
896
893
- result_length = self .append (ir .BinaryOp (ast .Mult (loc = None ), lst_length , num ))
897
+ result_length = self .append (ir .Arith (ast .Mult (loc = None ), lst_length , num ))
894
898
result = self .append (ir .Alloc ([result_length ], node .type ))
895
899
896
900
# num times...
897
901
def body_gen (num_index ):
898
902
# ... copy the list
899
903
def body_gen (lst_index ):
900
904
elt = self .append (ir .GetElem (lst , lst_index ))
901
- base_index = self .append (ir .BinaryOp (ast .Mult (loc = None ),
902
- num_index , lst_length ))
903
- result_index = self .append (ir .BinaryOp (ast .Add (loc = None ),
904
- base_index , lst_index ))
905
+ base_index = self .append (ir .Arith (ast .Mult (loc = None ),
906
+ num_index , lst_length ))
907
+ result_index = self .append (ir .Arith (ast .Add (loc = None ),
908
+ base_index , lst_index ))
905
909
self .append (ir .SetElem (result , base_index , elt ))
906
- return self .append (ir .BinaryOp (ast .Add (loc = None ), lst_index ,
907
- ir .Constant (1 , self ._size_type )))
910
+ return self .append (ir .Arith (ast .Add (loc = None ), lst_index ,
911
+ ir .Constant (1 , self ._size_type )))
908
912
self ._make_loop (ir .Constant (0 , self ._size_type ),
909
913
lambda index : self .append (ir .Compare (ast .Lt (loc = None ), index , lst_length )),
910
914
body_gen )
911
915
912
- return self .append (ir .BinaryOp (ast .Add (loc = None ), lst_length ,
913
- ir .Constant (1 , self ._size_type )))
916
+ return self .append (ir .Arith (ast .Add (loc = None ), lst_length ,
917
+ ir .Constant (1 , self ._size_type )))
914
918
self ._make_loop (ir .Constant (0 , self ._size_type ),
915
919
lambda index : self .append (ir .Compare (ast .Lt (loc = None ), index , num )),
916
920
body_gen )
@@ -955,8 +959,8 @@ def _compare_pair_order(self, op, lhs, rhs):
955
959
956
960
loop_body2 = self .add_block ()
957
961
self .current_block = loop_body2
958
- index_next = self .append (ir .BinaryOp (ast .Add (loc = None ), index_phi ,
959
- ir .Constant (1 , self ._size_type )))
962
+ index_next = self .append (ir .Arith (ast .Add (loc = None ), index_phi ,
963
+ ir .Constant (1 , self ._size_type )))
960
964
self .append (ir .Branch (loop_head ))
961
965
index_phi .add_incoming (index_next , loop_body2 )
962
966
@@ -988,8 +992,8 @@ def _compare_pair_inclusion(self, op, needle, haystack):
988
992
step = self .append (ir .GetAttr (haystack , "step" ))
989
993
after_start = self .append (ir .Compare (ast .GtE (loc = None ), needle , start ))
990
994
after_stop = self .append (ir .Compare (ast .Lt (loc = None ), needle , stop ))
991
- from_start = self .append (ir .BinaryOp (ast .Sub (loc = None ), needle , start ))
992
- mod_step = self .append (ir .BinaryOp (ast .Mod (loc = None ), from_start , step ))
995
+ from_start = self .append (ir .Arith (ast .Sub (loc = None ), needle , start ))
996
+ mod_step = self .append (ir .Arith (ast .Mod (loc = None ), from_start , step ))
993
997
on_step = self .append (ir .Compare (ast .Eq (loc = None ), mod_step ,
994
998
ir .Constant (0 , mod_step .type )))
995
999
result = self .append (ir .Select (after_start , after_stop ,
@@ -1008,8 +1012,8 @@ def body_gen(index):
1008
1012
1009
1013
loop_body2 = self .add_block ()
1010
1014
self .current_block = loop_body2
1011
- return self .append (ir .BinaryOp (ast .Add (loc = None ), index ,
1012
- ir .Constant (1 , length .type )))
1015
+ return self .append (ir .Arith (ast .Add (loc = None ), index ,
1016
+ ir .Constant (1 , length .type )))
1013
1017
loop_head , loop_body , loop_tail = \
1014
1018
self ._make_loop (ir .Constant (0 , length .type ),
1015
1019
lambda index : self .append (ir .Compare (ast .Lt (loc = None ), index , length )),
@@ -1117,8 +1121,8 @@ def visit_builtin_call(self, node):
1117
1121
def body_gen (index ):
1118
1122
elt = self ._iterable_get (arg , index )
1119
1123
self .append (ir .SetElem (result , index , elt ))
1120
- return self .append (ir .BinaryOp (ast .Add (loc = None ), index ,
1121
- ir .Constant (1 , length .type )))
1124
+ return self .append (ir .Arith (ast .Add (loc = None ), index ,
1125
+ ir .Constant (1 , length .type )))
1122
1126
self ._make_loop (ir .Constant (0 , length .type ),
1123
1127
lambda index : self .append (ir .Compare (ast .Lt (loc = None ), index , length )),
1124
1128
body_gen )
0 commit comments