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 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); }