122122 VMemoryOffsetConstantOffset ,
123123 VMemoryOffsetFieldOffset ,
124124 VMemoryOffsetArrayIndexOffset ,
125+ VMemoryOffsetBasePtrArrayIndexOffset ,
125126 VMemoryOffsetIndexOffset )
126127 from chb .mips .MIPSRegister import MIPSRegister
127128
@@ -437,7 +438,10 @@ def memory_variable_to_lval_expression(
437438 return astree .mk_memref_expr (
438439 astbase , offset = astoffset , anonymous = anonymous )
439440
440- else :
441+ elif (
442+ offset .is_field_offset
443+ or offset .is_array_index_offset
444+ or offset .is_constant_value_offset ):
441445 astlval = xvariable_to_ast_def_lval_expression (
442446 base .basevar , xdata , iaddr , astree , anonymous = anonymous )
443447 if offset .is_field_offset :
@@ -451,10 +455,27 @@ def memory_variable_to_lval_expression(
451455 elif offset .is_constant_value_offset :
452456 astoffset = astree .mk_scalar_index_offset (offset .offsetvalue ())
453457 else :
458+ chklogger .logger .warning (
459+ "Offset %s not yet handled at address %s" ,
460+ str (offset ), iaddr )
454461 astoffset = nooffset
455462 return astree .mk_memref_expr (
456463 astlval , offset = astoffset , anonymous = anonymous )
457464
465+ elif offset .is_baseptr_array_index_offset :
466+ astlval = xvariable_to_ast_def_lval_expression (
467+ base .basevar , xdata , iaddr , astree , anonymous = anonymous )
468+ offset = cast ("VMemoryOffsetBasePtrArrayIndexOffset" , offset )
469+ (ptroffset , astoffset ) = base_ptr_array_offset_to_ast_offset (
470+ offset , xdata , iaddr , astree , anonymous = anonymous )
471+ if ptroffset .is_integer_constant_zero :
472+ return astree .mk_memref_expr (
473+ astlval , offset = astoffset , anonymous = anonymous )
474+ else :
475+ ptrexpr = astree .mk_binary_op ("plus" , ptroffset , astlval )
476+ return astree .mk_memref_expr (
477+ ptrexpr , offset = astoffset , anonymous = anonymous )
478+
458479 name = str (base )
459480
460481 if not astree .globalsymboltable .has_symbol (name ):
@@ -1499,6 +1520,25 @@ def stack_variable_to_ast_lval(
14991520 return astree .mk_temp_lval ()
15001521
15011522
1523+ def base_ptr_array_offset_to_ast_offset (
1524+ offset : "VMemoryOffsetBasePtrArrayIndexOffset" ,
1525+ xdata : "InstrXData" ,
1526+ iaddr : str ,
1527+ astree : ASTInterface ,
1528+ anonymous : bool = False ) -> Tuple [AST .ASTExpr , AST .ASTOffset ]:
1529+
1530+ indexxpr = xxpr_to_ast_def_expr (
1531+ offset .index_expression , xdata , iaddr , astree , anonymous = anonymous )
1532+
1533+ if offset .has_no_offset () and indexxpr .is_integer_constant :
1534+ return (indexxpr , nooffset )
1535+
1536+ chklogger .logger .error (
1537+ "Base ptr array offset %s not yet handled at address %s" ,
1538+ str (offset ), iaddr )
1539+ return (astree .mk_integer_constant (0 ), nooffset )
1540+
1541+
15021542def array_offset_to_ast_offset (
15031543 offset : "VMemoryOffsetArrayIndexOffset" ,
15041544 xdata : "InstrXData" ,
@@ -1675,8 +1715,7 @@ def xvariable_to_ast_lval(
16751715 if (
16761716 rhs is not None
16771717 and (rhs .is_constant
1678- or (rhs .is_constant_value_variable
1679- and not rhs .is_function_return_value ))):
1718+ or (rhs .is_constant_value_variable ))):
16801719 astrhs : Optional [AST .ASTExpr ] = xxpr_to_ast_def_expr (
16811720 rhs , xdata , iaddr , astree , anonymous = anonymous )
16821721 else :
0 commit comments