@@ -1222,7 +1222,7 @@ def mkIfExpr(site, cond, texpr, fexpr):
12221222 (texpr , fexpr , utype ) = usual_int_conv (
12231223 texpr , ttype , fexpr , ftype )
12241224 else :
1225- if not compatible_types (ttype , ftype ):
1225+ if not compatible_types_fuzzy (ttype , ftype ):
12261226 raise EBINOP (site , ':' , texpr , fexpr )
12271227 # TODO: in C, the rules are more complex,
12281228 # but our type system is too primitive to cover that
@@ -1396,7 +1396,7 @@ def make(cls, site, lh, rh):
13961396 if ((lhtype .is_arith and rhtype .is_arith )
13971397 or (isinstance (lhtype , (TPtr , TArray ))
13981398 and isinstance (rhtype , (TPtr , TArray ))
1399- and compatible_types (lhtype .base , rhtype .base ))):
1399+ and compatible_types_fuzzy (lhtype .base , rhtype .base ))):
14001400 return cls .make_simple (site , lh , rh )
14011401 raise EILLCOMP (site , lh , lhtype , rh , rhtype )
14021402
@@ -1601,7 +1601,7 @@ def make(cls, site, lh, rh):
16011601 if ((lhtype .is_arith and rhtype .is_arith )
16021602 or (isinstance (lhtype , (TPtr , TArray ))
16031603 and isinstance (rhtype , (TPtr , TArray ))
1604- and compatible_types (lhtype , rhtype ))
1604+ and compatible_types_fuzzy (lhtype , rhtype ))
16051605 or (isinstance (lhtype , TBool ) and isinstance (rhtype , TBool ))):
16061606 return Equals (site , lh , rh )
16071607
@@ -2932,8 +2932,8 @@ def mkInterfaceMethodRef(site, iface_node, indices, method_name):
29322932 if (not isinstance (ftype , TPtr )
29332933 or not isinstance (ftype .base , TFunction )
29342934 or not ftype .base .input_types
2935- or TPtr (safe_realtype (TNamed ('conf_object_t' ))).cmp (
2936- safe_realtype (ftype .base .input_types [0 ])) != 0 ):
2935+ or TPtr (safe_realtype_unconst (TNamed ('conf_object_t' ))).cmp (
2936+ safe_realtype_unconst (ftype .base .input_types [0 ])) != 0 ):
29372937 # non-method members are not accessible
29382938 raise EMEMBER (site , struct_name , method_name )
29392939
@@ -4684,7 +4684,10 @@ class ArrayRef(LValue):
46844684 explicit_type = True
46854685 @auto_init
46864686 def __init__ (self , site , expr , idx ):
4687- self .type = realtype_shallow (expr .ctype ()).base
4687+ expr_type = realtype_shallow (expr .ctype ())
4688+ self .type = conv_const (expr_type .const
4689+ and isinstance (expr_type , TArray ),
4690+ expr_type .base )
46884691 def __str__ (self ):
46894692 return '%s[%s]' % (self .expr , self .idx )
46904693 def read (self ):
@@ -4797,30 +4800,41 @@ def mkCast(site, expr, new_type):
47974800 raise ETEMPLATEUPCAST (site , "object" , new_type )
47984801 else :
47994802 return mkTraitUpcast (site , expr , real .trait )
4803+
4804+ if (compat .dml12_misc in dml .globals .enabled_compat
4805+ and isinstance (expr , InterfaceMethodRef )):
4806+ # Workaround for SIMICS-9868
4807+ return mkLit (site , "%s->%s" % (
4808+ expr .node_expr .read (), expr .method_name ), new_type )
4809+
4810+ if isinstance (expr , NonValue ):
4811+ raise expr .exc ()
48004812 old_type = safe_realtype (expr .ctype ())
48014813 if (dml .globals .compat_dml12_int (site )
48024814 and (isinstance (old_type , (TStruct , TVector ))
48034815 or isinstance (real , (TStruct , TVector )))):
48044816 # these casts are permitted by C only if old and new are
48054817 # the same type, which is useless
48064818 return Cast (site , expr , new_type )
4807- if isinstance (real , TStruct ):
4808- if isinstance (old_type , TStruct ) and old_type .label == real .label :
4809- return expr
4810- raise ECAST (site , expr , new_type )
4811- if isinstance (real , TExternStruct ):
4812- if isinstance (old_type , TExternStruct ) and old_type .id == real .id :
4813- return expr
4819+ if isinstance (real , (TVoid , TArray , TFunction )):
48144820 raise ECAST (site , expr , new_type )
4815- if isinstance (real , (TVoid , TArray , TVector , TTraitList , TFunction )):
4821+ if old_type .cmp (real ) == 0 :
4822+ if (old_type .is_int
4823+ and not old_type .is_endian
4824+ and dml .globals .compat_dml12_int (expr .site )):
4825+ # 1.2 integer expressions often lie about their actual type,
4826+ # and require a "redundant" cast! Why yes, this IS horrid!
4827+ return Cast (site , expr , new_type )
4828+ return mkRValue (expr )
4829+ if isinstance (real , (TStruct , TExternStruct , TVector , TTraitList )):
48164830 raise ECAST (site , expr , new_type )
48174831 if isinstance (old_type , (TVoid , TStruct , TVector , TTraitList , TTrait )):
48184832 raise ECAST (site , expr , new_type )
48194833 if old_type .is_int and old_type .is_endian :
48204834 expr = as_int (expr )
48214835 old_type = safe_realtype (expr .ctype ())
48224836 if real .is_int and not real .is_endian :
4823- if isinstance ( expr , IntegerConstant ) :
4837+ if old_type . is_int and expr . constant :
48244838 value = truncate_int_bits (expr .value , real .signed , real .bits )
48254839 if dml .globals .compat_dml12_int (site ):
48264840 return IntegerConstant_dml12 (site , value , real )
@@ -4831,8 +4845,8 @@ def mkCast(site, expr, new_type):
48314845 # Shorten redundant chains of integer casts. Avoids insane C
48324846 # output for expressions like a+b+c+d.
48334847 if (isinstance (expr , Cast )
4834- and isinstance (expr . type , TInt )
4835- and expr . type .bits >= real .bits ):
4848+ and isinstance (old_type , TInt )
4849+ and old_type .bits >= real .bits ):
48364850 # (uint64)(int64)x -> (uint64)x
48374851 expr = expr .expr
48384852 old_type = safe_realtype (expr .ctype ())
@@ -4868,9 +4882,7 @@ def mkCast(site, expr, new_type):
48684882 return expr
48694883 elif real .is_int and real .is_endian :
48704884 old_type = safe_realtype (expr .ctype ())
4871- if real .cmp (old_type ) == 0 :
4872- return expr
4873- elif old_type .is_arith or isinstance (old_type , TPtr ):
4885+ if old_type .is_arith or isinstance (old_type , TPtr ):
48744886 return mkApply (
48754887 expr .site ,
48764888 mkLit (expr .site , * real .get_store_fun ()),
@@ -4927,7 +4939,6 @@ def mkCast(site, expr, new_type):
49274939class RValue (Expression ):
49284940 '''Wraps an lvalue to prohibit write. Useful when a composite
49294941 expression is reduced down to a single variable.'''
4930- writable = False
49314942 @auto_init
49324943 def __init__ (self , site , expr ): pass
49334944 def __str__ (self ):
@@ -4936,11 +4947,22 @@ def ctype(self):
49364947 return self .expr .ctype ()
49374948 def read (self ):
49384949 return self .expr .read ()
4939- def discard (self ): pass
4950+ def discard (self ):
4951+ return self .expr .discard ()
49404952 def incref (self ):
49414953 self .expr .incref ()
49424954 def decref (self ):
49434955 self .expr .decref ()
4956+ @property
4957+ def explicit_type (self ):
4958+ return self .expr .explicit_type
4959+ @property
4960+ def type (self ):
4961+ assert self .explicit_type
4962+ return self .expr .type
4963+ @property
4964+ def is_pointer_to_stack_allocation (self ):
4965+ return self .expr .is_pointer_to_stack_allocation
49444966
49454967def mkRValue (expr ):
49464968 if isinstance (expr , LValue ) or expr .writable :
0 commit comments