public override StatementList AllocLocalVariables(IList <IVariable> variables) { StatementList stmts = new StatementList(); // we allocate an address for all local variables // except they are a pointer, we are assuming that you can't take the address of a pointer foreach (var v in variables) { if (!(v.Type is IManagedPointerType)) { stmts.Add(dispatcher.AllocAddr(v)); } } // load values into stack space foreach (var paramVariable in variables.Where(v => v.IsParameter)) { // paramValue are variables in the three address code // however in boogie they are treated as values // those values are loaded into the stack memory space /* * void foo(int x){ * } * * procedure foo(x : int){ * var _x : Addr; // stack space (done in previous loop) * x_ := AllocAddr(); * * data(_x) := x; // we are doing this conceptually * } */ var boogieParamVariable = BoogieParameter.FromDotNetVariable(paramVariable); if (paramVariable.Type is IManagedPointerType) { stmts.Add(BoogieStatement.VariableAssignment(BoogieVariable.AddressVar(paramVariable), boogieParamVariable)); continue; } Addressable paramAddress = dispatcher.AddressOf(paramVariable); // boogie generator knows that must fetch paramVariable's address (_x and not x) stmts.Add(dispatcher.WriteAddr(paramAddress, boogieParamVariable)); if (Helpers.GetBoogieType(paramVariable).Equals(Helpers.BoogieType.Object)) { stmts.Add(BoogieStatement.AllocObjectAxiom(paramVariable)); } else if (Helpers.GetBoogieType(paramVariable).Equals(Helpers.BoogieType.Addr)) { stmts.Add(BoogieStatement.AllocAddrAxiom(paramVariable)); } } return(stmts); }
public int Transfer(Item source, Addressable destination, long index) { for (int i = 0; i < value; i++) { destination.Set(index + i, (byte)(source.Value * value)); } return(value); }
public int Transfer(T source, Addressable destination, long index) { string value = property.GetValue(source); int length = value != null?Encoding.UTF8.GetByteCount(value) : -1; destination.WriteInt32(index + 0, length); destination.WriteString(index + 4, value); return(NormalizeLength(length)); }
public int Transfer(Addressable source, long index, T destination) { if (source.Get(index) == 0) { nullable.SetNull(destination); return(1); } ; return(inner.Transfer(source, index + 1, destination) + 1); }
public int Transfer(Addressable source, long index, Substitute <T> destination) { if (source.Get(index) == 0) { destination.Add(inner.Name, () => null); return(1); } return(inner.Transfer(source, index + 1, destination) + 1); }
public int Transfer(Addressable source, T destination) { int size = 0; for (int i = 0; i < items.Length; i++) { size = size + items[i].Transfer(source, size, destination); } return(size); }
public int Transfer(T source, Addressable destination, long index) { if (nullable.IsNull(source)) { destination.Set(index, 0); return(1); } destination.Set(index, 1); return(inner.Transfer(source, destination, index + 1) + 1); }
public override Expression ReadAddr(Addressable addr) { if (addr is AddressExpression addrExpr) { var readExpr = ReadTypedMemory.From(addrExpr); return(readExpr); } else { throw new NotImplementedException(); } }
public int Transfer(Addressable source, long index, Substitute <Item> destination) { long sum = 0; for (int i = 0; i < value; i++) { sum = sum + source.Get(index + i); } destination.Add("Value", () => (byte)(sum / value / value)); return(value); }
public int Transfer(Addressable source, long index, Item destination) { long sum = 0; for (int i = 0; i < value; i++) { sum = sum + source.Get(index + i); } destination.Value = (byte)(sum / value / value); return(value); }
public static Int64 ReadInt64(this Addressable addressable, long index) { Int64 value = 0; for (int i = 0; i < 8; i++) { value = value << 8; value = value + addressable.Get(index + i); } return(value); }
public int Transfer(Addressable source, long index, Substitute <T> destination) { int length = source.ReadInt32(index + 0); destination.Add(property.Name, () => { if (length < 0) { return(null); } return(new SubstituteText(length, () => source.ReadString(index + 4, length))); }); return(NormalizeLength(length)); }
public static String ReadString(this Addressable addressable, long index, int length) { if (length < 0) { return(null); } if (length == 0) { return(String.Empty); } byte[] bytes = new byte[length]; addressable.GetBytes(index, bytes); return(Encoding.UTF8.GetString(bytes)); }
public override StatementList AllocLocalVariables(IList <IVariable> variables) { StatementList stmts = new StatementList(); // only allocate an address for variables that are referenced foreach (var v in variables) { if (RequiresAllocation(v)) { stmts.Add(AllocAddr(v)); } } foreach (var paramVariable in variables.Where(v => v.IsParameter && (RequiresAllocation(v) || (v.Type is IManagedPointerType)))) { var boogieParamVariable = BoogieParameter.FromDotNetVariable(paramVariable); //if (!RequiresAllocation(paramVariable)) if (paramVariable.Type is IManagedPointerType) { //BoogieVariable target = RequiresAllocation(paramVariable) || (paramVariable.Type is IManagedPointerType) ? // BoogieVariable.AddressVar(paramVariable) : BoogieVariable.FromDotNetVariable(paramVariable); BoogieVariable target = BoogieVariable.AddressVar(paramVariable); stmts.Add(BoogieStatement.VariableAssignment(target, boogieParamVariable)); continue; } Addressable paramAddress = AddressOf(paramVariable); // boogie generator knows that must fetch paramVariable's address (_x and not x) stmts.Add(WriteAddr(paramAddress, boogieParamVariable)); if (Helpers.GetBoogieType(paramVariable).Equals(Helpers.BoogieType.Object)) { stmts.Add(BoogieStatement.AllocObjectAxiom(paramVariable)); } else if (Helpers.GetBoogieType(paramVariable).Equals(Helpers.BoogieType.Addr)) { stmts.Add(BoogieStatement.AllocAddrAxiom(paramVariable)); } } return(stmts); }
public override StatementList WriteAddr(Addressable addr, Expression expr) { if (addr is AddressExpression addrExpr) { if (expr.Type.Equals(Helpers.BoogieType.Addr)) { // pointer = pointer does not require map indexing in boogie // it is just a variable assignment BoogieVariable v = new BoogieVariable(expr.Type, addrExpr.Expr.Expr); return(BoogieStatement.VariableAssignment(v, expr)); } return(TypedMemoryMapUpdate.ForKeyValue(addrExpr, expr)); } else { throw new NotImplementedException(); } }
public int Transfer(T source, Addressable destination, long index) { long initial = index; V[] value = property.GetValue(source); int length = value?.Length ?? -1; destination.WriteInt32(initial + 4, length); index = index + 8; if (value != null) { foreach (V item in value) { index = index + nested.Transfer(item, destination.Scope(index)); } } destination.WriteInt32(initial, (int)(index - initial)); return((int)(index - initial)); }
public override Expression ReadAddr(Addressable addr) { if (addr is AddressExpression) { return(memAddr.ReadAddr(addr)); } else if (addr is InstanceField) { return(memBCT.ReadAddr(addr)); } else if (addr is StaticField) { return(memBCT.ReadAddr(addr)); } else if (addr is DotNetVariable) { return(memBCT.ReadAddr(addr)); } throw new NotImplementedException(); }
public override StatementList WriteAddr(Addressable addr, Expression value) { if (addr is AddressExpression addrExpr) { return(memAddr.WriteAddr(addr, value)); } else if (addr is InstanceField instanceField) { return(memBCT.WriteAddr(addr, value)); } else if (addr is StaticField staticField) { return(memBCT.WriteAddr(addr, value)); } else if (addr is DotNetVariable dotNetVariable) { return(memBCT.WriteAddr(addr, value)); } throw new NotImplementedException(); }
public AddressableScope(Addressable target, long position) { this.target = target; this.position = position; }
public int Transfer(Addressable source, long index, T destination) { property.SetValue(destination, source.ReadInt64(index)); return(8); }
public int Transfer(Addressable source, long index, Substitute <T> destination) { destination.Add(property.Name, () => source.ReadInt64(index)); return(8); }
public int Transfer(T source, Addressable destination, long index) { destination.WriteInt64(index, property.GetValue(source)); return(8); }
public static Addressable Scope(this Addressable addressable, long offset) { return(new AddressableScope(addressable, offset)); }
public abstract StatementList WriteAddr(Addressable addr, Expression value);
//public abstract Expression ReadAddr(IVariable addr); public abstract Expression ReadAddr(Addressable addr);