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 override StatementList VariableAssignment(IVariable variableA, IValue value) { Constant cons = value as Constant; BoogieLiteral boogieConstant = null; if (cons != null) { boogieConstant = BoogieLiteral.FromDotNetConstant(cons); } var boogieType = Helpers.GetBoogieType(variableA); if (value is Constant) { if (boogieConstant != null) { return(bg.VariableAssignment(variableA, boogieConstant)); } else { throw new NotImplementedException(); // return WriteAddr(variableA, value.ToString()); } } else if (value is IVariable && !(value.Type is IManagedPointerType)) { // right operand is not a pointer (therefore left operand is not a pointer) return(dispatcher.WriteAddr(dispatcher.AddressOf(variableA), dispatcher.ReadAddr(value as IVariable))); } else if (value is Dereference) { var dereference = value as Dereference; var content = dispatcher.ReadAddr(dereference.Reference); return(dispatcher.WriteAddr(dispatcher.AddressOf(variableA), content)); } else if (value.Type is IManagedPointerType) { // if the right operand is a pointer also the left one is a pointer // there are two cases for value: // 1) value has the form &<something> (in analysis-net this is a Reference object) // 2) value is just a variable (static, instance, local, array element) with pointer type // for 1) we want to take the allocated address of something and assign it to the boogie variable of the left operand // for 2) we just want to make a boogie assignment between the boogie variables of the left and right operands // AddressOf will do the work to separate case 1) and 2) var addr = dispatcher.AddressOf(value) as AddressExpression; Contract.Assume(addr != null); return(BoogieStatement.VariableAssignment(BoogieVariable.AddressVar(variableA), addr.Expr)); } Contract.Assert(false); // This shouldn't be reachable. throw new NotImplementedException(); }
// hides implementation in super class //public new string VariableAssignment(string variableA, string expr) //{ // return string.Format("{0} := {1};", variableA, expr); //} public override StatementList DeclareLocalVariables(IList <IVariable> variables, Dictionary <string, BoogieVariable> temporalVariables) { var stmts = new StatementList(); foreach (var v in variables) { stmts.Add(BoogieStatement.VariableDeclaration(BoogieVariable.AddressVar(v))); } foreach (var kv in temporalVariables) { stmts.Add(BoogieStatement.VariableDeclaration(kv.Value)); } return(stmts); }
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 DeclareLocalVariables(IList <IVariable> variables, Dictionary <string, BoogieVariable> temporalVariables) { var stmts = new StatementList(); foreach (var v in variables) { if (RequiresAllocation(v) || v.Type is IManagedPointerType) { stmts.Add(BoogieStatement.VariableDeclaration(BoogieVariable.AddressVar(v))); } else if (!v.IsParameter) { stmts.Add(BoogieStatement.VariableDeclaration(v)); } } foreach (var kv in temporalVariables) { stmts.Add(BoogieStatement.VariableDeclaration(kv.Value)); } return(stmts); }
public override Addressable AddressOf(IVariable var) { return(new AddressExpression(var.Type, BoogieVariable.AddressVar(var))); }
// hides implementation in super class public override StatementList AllocAddr(IVariable var) { var resultBoogieVar = BoogieVariable.AddressVar(var); return(dispatcher.AllocAddr(resultBoogieVar)); }