static Program Process(Program program) { // find null var nil = program.TopLevelDeclarations.OfType <Constant>().Where(g => g.Name == "null").FirstOrDefault(); if (nil == null) { Console.WriteLine("Error: null not found in the input program"); return(null); } // Add Freed: [Ref] bool; Freed = new GlobalVariable(Token.NoToken, new TypedIdent(Token.NoToken, "FreedRef", new MapType(Token.NoToken, new List <TypeVariable>(), new List <btype> { nil.TypedIdent.Type }, btype.Bool))); program.AddTopLevelDeclaration(Freed); // Find "Alloc" and add "assume !Freed[x];" var allocProc = program.TopLevelDeclarations.OfType <Implementation>() .Where(impl => impl.Name == "Alloc") .FirstOrDefault(); Alloc = program.TopLevelDeclarations.OfType <GlobalVariable>() .Where(impl => impl.Name == "$Alloc") .FirstOrDefault(); if (allocProc == null || Alloc == null) { Console.WriteLine("Error: Alloc procedure not found in the input program"); return(null); } var x = allocProc.OutParams[0]; allocProc.Blocks[0].Cmds.Add(new AssumeCmd(Token.NoToken, Expr.Not(BoogieAstFactory.MkMapAccessExpr(Freed, Expr.Ident(x))))); // Find System.Heap.Delete, add Freed[x] := true var freeProcs = program.TopLevelDeclarations.OfType <Implementation>() .Where(impl => impl.Name.StartsWith("System.Heap.Delete")).ToList(); if (freeProcs.Count != 1) { Console.WriteLine("Error: Free procedure not found, or multiple found in the input program"); return(null); } x = freeProcs[0].InParams[0]; freeProcs[0].Blocks[0].Cmds.Insert(0, BoogieAstFactory.MkMapAssign(Freed, Expr.Ident(x), Expr.Literal(true))); DesugarIte.Instrument(program); InstrumentMemoryAccesses.Instrument(program, nil); return(program); }
public static void Instrument(Program program) { foreach (var impl in program.TopLevelDeclarations.OfType <Implementation>()) { var obj = new DesugarIte(); obj.Instrument(impl); obj.Desugar(impl); impl.LocVars.AddRange(obj.newVars); } }