public void EmitAccessTrait(Expression baseExpr, Expression memPtr, int ptrSize, int offset) { if (arrayContext) { handler.MemAccessArrayTrait(baseExpr, memPtr, ptrSize, offset, arrayElementSize, arrayLength, eField); } else { handler.MemAccessTrait(baseExpr, memPtr, ptrSize, eField, offset); } }
/// <summary> /// Handle an expression of type 'id + offset', where id is a LinearInductionVariable. /// </summary> /// <param name="id"></param> /// <param name="iv"></param> /// <param name="offset"></param> public void VisitInductionVariable(Identifier id, LinearInductionVariable iv, Constant?cOffset) { int delta = iv.Delta !.ToInt32(); int offset = StructureField.ToOffset(cOffset) ?? 0; var tvBase = basePointer ?? program.Globals; var stride = Math.Abs(delta); int init; if (delta < 0) { // induction variable is decremented, so the actual array begins at ivFinal - delta. if (iv.Final != null) { init = iv.Final.ToInt32() - delta; if (iv.IsSigned) { handler.MemAccessArrayTrait(null, tvBase, cOffset !.DataType.Size, init + offset, stride, iv.IterationCount, eField !); } else { handler.MemAccessArrayTrait(null, tvBase, id.DataType.Size, init + offset, stride, iv.IterationCount, eField !); } } } else { if (iv.Initial != null) { init = iv.Initial.ToInt32(); if (iv.IsSigned) { handler.MemAccessArrayTrait(null, tvBase, cOffset !.DataType.Size, init + offset, stride, iv.IterationCount, eField !); } else { handler.MemAccessArrayTrait(null, tvBase, id.DataType.Size, init + offset, stride, iv.IterationCount, eField !); } } } if (iv.IsSigned) { if (cOffset != null) { handler.MemSizeTrait(basePointer, cOffset, Math.Abs(delta)); EmitAccessTrait(basePointer, cOffset, cOffset.DataType.Size, 0); } } else { handler.MemSizeTrait(basePointer, id, Math.Abs(delta)); EmitAccessTrait(basePointer, id, id.DataType.Size, offset); } }