public static void PrintBplFile(string filename, Program program, bool allowPrintDesugaring) { Contract.Requires(program != null); Contract.Requires(filename != null); bool oldPrintDesugaring = CommandLineOptions.Clo.PrintDesugarings; if (!allowPrintDesugaring) { CommandLineOptions.Clo.PrintDesugarings = false; } using (TokenTextWriter writer = filename == "-" ? new TokenTextWriter("<console>", Console.Out, false) : new TokenTextWriter(filename, false)) { if (CommandLineOptions.Clo.ShowEnv != CommandLineOptions.ShowEnvironment.Never) { writer.WriteLine("// " + CommandLineOptions.Clo.Version); writer.WriteLine("// " + CommandLineOptions.Clo.Environment); } writer.WriteLine(); program.Emit(writer); } CommandLineOptions.Clo.PrintDesugarings = oldPrintDesugaring; }
public static void EmitProgram(Program prog, string filename, string extension = "bpl") { using (TokenTextWriter writer = new TokenTextWriter(filename + "." + extension, false)) { prog.Emit(writer); } }
public void Emit(TokenTextWriter t) { Console.Write("\t"); Source.Emit(t, 0); if (!Cons.IsTrue()) { t.WriteLine("\t\tPre: "); t.Write("\t\t\t"); Cons.Emit(t); t.WriteLine(); } if (Gammas.Count != 0) { t.WriteLine("\t\tGammas:"); for (int i = 0; i < Gammas.Count; i++) { if (Gammas.Count > 1) { t.WriteLine("\t\t\t" + i + ": "); } Gammas[i].Emit(t); t.WriteLine("==============="); } } }
private static void printIndent(TokenTextWriter ttw, int indent) { for (int i = 0; i < indent; i++) { ttw.Write(" "); } }
public static void PrintProgram(Program p, string filename) { var outFile = new TokenTextWriter(filename); p.Emit(outFile); outFile.Close(); }
public void PrintInfo(TokenTextWriter writer) { if (writer == null) { return; } writer.WriteLine("================================="); writer.WriteLine("Here's what we know of the program:"); writer.Write("Declared globals: "); foreach (var g in declaredGlobals) { writer.Write(g.Key + " "); } writer.Write("\n"); writer.Write("Modified globals: "); foreach (var g in modifiedGlobals) { writer.Write(g.Key + " "); } writer.Write("\n"); writer.WriteLine("Main procedure: {0}", mainProcName); writer.WriteLine("================================="); }
private static void setupPrint(PersistentCBAProgram program, ErrorTrace trace, string file) { // Set output files pathFile = file == null ? null : new TokenTextWriter(file + "_trace.txt"); if (pathFile != null) { program.writeToFile(file + ".bpl"); } Program prog = program.getProgram(); // Initialization initialize(prog, trace, file == null ? null : file + ".bpl"); if (pathFile != null) { if (traceFormat == TraceFormat.ConcurrencyExplorer) { pathFile.WriteLine("s"); pathFile.WriteLine("#"); } else if (traceFormat == TraceFormat.SDV) { pathFile.WriteLine("0 \"?\" 0 false ^ Call \"OS\" \"main\""); } } }
public static Program ReResolveInMem(Program p, bool doTypecheck = true) { Program output; using (var writer = new System.IO.MemoryStream()) { var st = new System.IO.StreamWriter(writer); var tt = new TokenTextWriter(st); p.Emit(tt); writer.Flush(); st.Flush(); writer.Seek(0, System.IO.SeekOrigin.Begin); var s = ParserHelper.Fill(writer, new List <string>()); var v = Parser.Parse(s, "ReResolveInMem", out output); if (ResolveProgram(output, "ReResolveInMem")) { throw new InvalidProg("Cannot resolve " + "ReResolveInMem"); } if (doTypecheck && TypecheckProgram(output, "ReResolveInMem")) { throw new InvalidProg("Cannot typecheck " + "ReResolveInMem"); } } return(output); }
private string Format(string msg, params object[] args) { Contract.Requires(msg != null); Contract.Ensures(Contract.Result<string>() != null); if (System.Type.GetType("Mono.Runtime") != null) { // MONO // something in mono seems to be broken so that calling // NamedDeclarations.ToString (and similar ToString methods) // causes a stack overflow. We therefore convert those to // strings by hand object[] fixedArgs = new object[cce.NonNull(args).Length]; for (int i = 0; i < args.Length; ++i) { if (args[i] is NamedDeclaration) { fixedArgs[i] = cce.NonNull((NamedDeclaration)args[i]).Name; } else if (args[i] is Type) { System.IO.StringWriter buffer = new System.IO.StringWriter(); using (TokenTextWriter stream = new TokenTextWriter("<buffer>", buffer, /*setTokens=*/ false, /*pretty=*/ false)) { cce.NonNull((Type)args[i]).Emit(stream); } fixedArgs[i] = buffer.ToString(); } else if (args[i] is Expr) { System.IO.StringWriter buffer = new System.IO.StringWriter(); using (TokenTextWriter stream = new TokenTextWriter("<buffer>", buffer, /*setTokens=*/ false, /*pretty=*/ false)) { cce.NonNull((Expr/*!*/)args[i]).Emit(stream, 0, false); } fixedArgs[i] = buffer.ToString(); } else { fixedArgs[i] = args[i]; } } args = fixedArgs; } return string.Format(msg, args); }
public override void Verify(string fileName, TransHelper.TransEnv env, Microsoft.FSharp.Collections.FSharpList <CAST.Top> decls) { // this really only dumps the code to the .bpl file Init(env, fileName); decls = env.ApplyTransformers(decls); if (options.NoVerification) { return; } if (env.ShouldContinue) { if (env.Options.AggressivePruning && env.Options.Functions.Count() > 0) { decls = TransUtil.pruneBy(env, env.Options.Functions.First(), decls); } var boogieDecls = Translator.translate(null, env, () => VccCommandLineHost.StandardPrelude(options), decls); var p = TranslateToBoogie(boogieDecls); if (env.ShouldContinue) { try { swSaveBPL.Start(); CommandLineOptions.Install(new CommandLineOptions()); using (var writer = new TokenTextWriter(AddOutputDirIfRequested(Path.ChangeExtension(fileName, ".bpl")))) { p.Emit(writer); } } finally { swSaveBPL.Stop(); } } } }
public static void PrintProg(Program p) { var filename = Options.outputPath + @"/" + Options.instrumentedFile; var tuo = new TokenTextWriter(filename); try { p.Emit(tuo); } finally { tuo.Close(); } }
// Prints the policy public void print(TokenTextWriter writer) { if (writer == null) { return; } writer.WriteLine("================================="); writer.WriteLine("The instrumentation policy:"); writer.Write(" Globals to instrument: "); foreach (var s in globalsToInstrument) { writer.Write("{0} ", s); } writer.WriteLine(); /* * writer.Write(" Procedures without implementation: "); * foreach (var s in procsWithoutImpl) * { * writer.Write("{0} ", s); * } * writer.WriteLine(); * * writer.WriteLine(" Atomic-block procedures: {0} {1}", atomicBeginProcName, atomicEndProcName); * writer.WriteLine(" Assertion procedure: {0}", assertNotReachableName); */ writer.WriteLine("================================="); }
public static void DumpExceptionInformation(Exception e) { const string DUMP_FILE = "__whoopdump.txt"; #region Give generic internal error messsage Console.Error.WriteLine("\nWhoop: an internal error has occurred, details written to " + DUMP_FILE + "."); #endregion #region Now try to give the user a specific hint if this looks like a common problem try { throw e; } catch (ProverException) { Console.Error.WriteLine("Hint: It looks like Whoop is having trouble invoking its"); Console.Error.WriteLine("supporting theorem prover, which by default is Z3."); Console.Error.WriteLine("Have you installed Z3?"); } catch (Exception) { // Nothing to say about this } #endregion #region Write details of the exception to the dump file using (TokenTextWriter writer = new TokenTextWriter(DUMP_FILE, true)) { writer.Write("Exception ToString:"); writer.Write("==================="); writer.Write(e.ToString()); writer.Close(); } #endregion }
/// <summary> /// The entry point of the program. /// </summary> /// <param name="args">The command line arguments.</param> public static void Main(string[] args) { try { // standard command line options for Boogie CommandLineOptions.Install(new GRCommandLineOptions()); if (!CommandLineOptions.Clo.Parse(args)) { return; } CommandLineOptions.Clo.PrintUnstructured = 2; if (!CommandLineOptions.Clo.Files.Any()) { throw new Exception("An input file must be provided!"); } else if (CommandLineOptions.Clo.Files.Count > 1) { throw new Exception("GPURepair can work on only one file at a time!"); } Logger.FileName = CommandLineOptions.Clo.Files.First(); Logger.DetailedLogging = ((GRCommandLineOptions)CommandLineOptions.Clo).DetailedLogging; Microsoft.Boogie.Program program; Parser.Parse(Logger.FileName, new List <string>() { "FILE_0" }, out program); CommandLineOptions.Clo.DoModSetAnalysis = true; CommandLineOptions.Clo.PruneInfeasibleEdges = true; ResolutionContext context = new ResolutionContext(null); program.Resolve(context); program.Typecheck(); new ModSetCollector().DoModSetAnalysis(program); // start instrumenting the program SourceLanguage sourceLanguage = ((GRCommandLineOptions)CommandLineOptions.Clo).SourceLanguage; bool disableInspection = ((GRCommandLineOptions)CommandLineOptions.Clo).DisableInspection; bool disableGridBarriers = ((GRCommandLineOptions)CommandLineOptions.Clo).DisableGridBarriers; bool useAxioms = ((GRCommandLineOptions)CommandLineOptions.Clo).UseAxioms; Instrumentor instrumentor = new Instrumentor(program, sourceLanguage, disableInspection, disableGridBarriers, useAxioms); instrumentor.Instrument(); // create the instrumented Boogie IR for the next steps using (TokenTextWriter writer = new TokenTextWriter(Logger.FileName.Replace(".gbpl", ".repair.gbpl"), true)) program.Emit(writer); } catch (Exception ex) { Console.Error.WriteLine(ex.Message); Environment.Exit(200); } }
public void Emit(TokenTextWriter t) { t.WriteLine(Source.Label + ":"); foreach (SymbolicCmd c in SCmds) { c.Emit(t); } }
string PrintBoogie(BoogieProgram program) { var result = new StringWriter(); var writer = new TokenTextWriter(result); program.Emit(writer); return(result.ToString()); }
/// <summary> /// Emites to a user specified file. /// </summary> /// <param name="declarations">Declarations</param> /// <param name="file">File</param> internal static void EmitToFile(List <Declaration> declarations, string file) { var fileName = file + ".bpl"; using (TokenTextWriter writer = new TokenTextWriter(fileName, true)) { declarations.Emit(writer); } }
public void Emit(TokenTextWriter t) { foreach (var kv in this) { t.Write("\t\t\t" + kv.Key.ToString() + ": "); kv.Value.Emit(t); Console.WriteLine(); } }
private void EmitProgram(string filename) { using TokenTextWriter writer = new TokenTextWriter(filename, true); int oldPrintUnstructured = CommandLineOptions.Clo.PrintUnstructured; CommandLineOptions.Clo.PrintUnstructured = 2; program.Emit(writer); CommandLineOptions.Clo.PrintUnstructured = oldPrintUnstructured; }
public void print(TokenTextWriter ttw) { ttw.Write(blockName + ":" + num.ToString() + (type.type == InstrTypeEnum.CALL ? ":call" : (type.type == InstrTypeEnum.ASYNC ? ":async" : ""))); }
public static void DumpExceptionInformation(Exception e) { if (e.ToString().Contains("An attempt was made to load an assembly from a network location")) { Console.Error.WriteLine(); Console.Error.WriteLine("GPUVerify has had trouble loading one of its components due to security settings."); Console.Error.WriteLine(); Console.Error.WriteLine("In order to run GPUVerify successfully you need to unblock the archive before unzipping it."); Console.Error.WriteLine(); Console.Error.WriteLine("To do this:"); Console.Error.WriteLine(" - Right click on the .zip file"); Console.Error.WriteLine(" - Click \"Properties\""); Console.Error.WriteLine(" - At the bottom of the \"General\" tab you should see:"); Console.Error.WriteLine(" Security: This file came from another computer and might be blocked"); Console.Error.WriteLine(" to help protect this computer."); Console.Error.WriteLine(" - Click \"Unblock\""); Console.Error.WriteLine(" - Click \"OK\""); Console.Error.WriteLine("Once this is done, unzip GPUVerify afresh and this issue should be resolved."); Environment.Exit((int)ToolExitCodes.INTERNAL_ERROR); } const string DUMP_FILE = "__gvdump.txt"; // Give generic internal error message Console.Error.WriteLine("\nGPUVerify: an internal error has occurred, details written to " + DUMP_FILE + "."); Console.Error.WriteLine(); Console.Error.WriteLine("Please consult the troubleshooting guide in the GPUVerify documentation"); Console.Error.WriteLine("for common problems, and if this does not help, raise an issue via the"); Console.Error.WriteLine("GPUVerify issue tracker:"); Console.Error.WriteLine(); Console.Error.WriteLine(" https://github.com/mc-imperial/gpuverify"); Console.Error.WriteLine(); // Now try to give the user a specific hint if this looks like a common problem try { throw e; } catch (ProverException) { Console.Error.WriteLine("Hint: It looks like GPUVerify is having trouble invoking its"); Console.Error.WriteLine("supporting theorem prover, which by default is Z3. Have you"); Console.Error.WriteLine("installed Z3?"); } catch (Exception) { // Nothing to say about this } // Write details of the exception to the dump file using (TokenTextWriter writer = new TokenTextWriter(DUMP_FILE, false)) { writer.Write("Exception ToString:"); writer.Write("==================="); writer.Write(e.ToString()); } }
// Returns file and line of the failing assert. Dumps // error trace to disk. public Tuple <string, int> PrintErrorTrace(cba.ErrorTrace trace, string filename, List <Tuple <string, int, string> > eeSlicedSourceLines, string failStatus) { trace = mapBackTrace(trace); if (Driver.printTraceMode == Driver.PRINT_TRACE_MODE.Boogie) { cba.PrintProgramPath.print(input, trace, filename); return(null); } else { // relevant lines cba.PrintSdvPath.relevantLines = null; if (eeSlicedSourceLines != null) { cba.PrintSdvPath.relevantLines = new HashSet <Tuple <string, int> >(); eeSlicedSourceLines.Iter(tup => cba.PrintSdvPath.relevantLines.Add(Tuple.Create(tup.Item1, tup.Item2))); } cba.PrintSdvPath.failingLocation = null; cba.PrintSdvPath.failStatus = failStatus; cba.PrintSdvPath.Print(input.getProgram(), trace, new HashSet <string>(), "", filename + ".tt", filename + "stack.txt"); if (cba.PrintSdvPath.abortMessage != null) { var am = new TokenTextWriter(filename + ".txt"); am.WriteLine(cba.PrintSdvPath.abortMessage); am.Close(); } if (cba.PrintSdvPath.lastDriverLocation == null) { return(null); } cba.PrintSdvPath.failingLocation = Tuple.Create(cba.PrintSdvPath.lastDriverLocation.Item1, cba.PrintSdvPath.lastDriverLocation.Item3); cba.PrintSdvPath.Print(input.getProgram(), trace, new HashSet <string>(), "", filename + ".tt", filename + "stack.txt"); if (cba.PrintSdvPath.abortMessage != null) { var am = new TokenTextWriter(filename + ".txt"); am.WriteLine(cba.PrintSdvPath.abortMessage); am.Close(); } cba.PrintSdvPath.relevantLines = null; cba.PrintSdvPath.failingLocation = null; cba.PrintSdvPath.failStatus = null; return(Tuple.Create(cba.PrintSdvPath.lastDriverLocation.Item1, cba.PrintSdvPath.lastDriverLocation.Item3)); } }
///////////////////////////////////////////////////////////////////////////////////// private static void TypeToStringHelper(Type t, StringBuilder sb) { Contract.Requires(t != null); TypeSynonymAnnotation syn = t as TypeSynonymAnnotation; if (syn != null) { TypeToStringHelper(syn.ExpandedType, sb); } else { if (t.IsMap && CommandLineOptions.Clo.UseArrayTheory) { MapType m = t.AsMap; // Contract.Assert(m.MapArity == 1); sb.Append("(Array "); foreach (Type tp in m.Arguments) { sb.Append(TypeToString(tp)).Append(" "); } sb.Append(TypeToString(m.Result)).Append(")"); } else if (t.IsMap) { MapType m = t.AsMap; sb.Append('['); for (int i = 0; i < m.MapArity; ++i) { if (i != 0) { sb.Append(','); } TypeToStringHelper(m.Arguments[i], sb); } sb.Append(']'); TypeToStringHelper(m.Result, sb); } else if (t.IsBool || t.IsInt || t.IsReal || t.IsFloat || t.IsBv || t.IsRMode || t.IsString) { sb.Append(TypeToString(t)); } else { System.IO.StringWriter buffer = new System.IO.StringWriter(); using (TokenTextWriter stream = new TokenTextWriter("<buffer>", buffer, /*setTokens=*/ false, /*pretty=*/ false) ) { t.Emit(stream); } sb.Append(buffer.ToString()); } } }
public static void PrintCindyTrace(List <Block> e, string filename) { var ttt = new TokenTextWriter(filename, true); foreach (Block b in e) { b.Emit(ttt, 0); } ttt.Close(); }
internal static void Emit(List <Declaration> declarations, string file, string suffix, string extension) { string directory = BoogieProgramEmitter.GetDirectoryWithFile(file); var fileName = directory + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(file) + "_" + suffix + "." + extension; using (TokenTextWriter writer = new TokenTextWriter(fileName, true)) { declarations.Emit(writer); } }
private static void init() { if (noDebuggingOutput) { return; } if (debugOut == null) { debugOut = new TokenTextWriter("corraldebug.out"); } }
public void Emit(TokenTextWriter t) { t.Write("vtask: (" + Eq.Name + ", " + Left.Name + ", " + Right.Name + ")"); if (DesiredOutputVars.Count > 0) { t.Write(" / "); foreach (var v in DesiredOutputVars) { t.Write(v.Name + "; "); } } t.WriteLine(); }
/// <summary> /// Writes the program to a temp file. /// </summary> /// <param name="filePath">The file path.</param> /// <param name="program">The program.</param> /// <returns>The temp file path.</returns> public static string WriteFile(string filePath, Microsoft.Boogie.Program program) { string tempFile = filePath.Replace(".cbpl", ".temp.cbpl"); if (File.Exists(tempFile)) { File.Delete(tempFile); } using (TokenTextWriter writer = new TokenTextWriter(tempFile, true)) program.Emit(writer); return(tempFile); }
//call with null filename to print to console public static void PrintProgram(Program p, string filename) { TokenTextWriter outFile; if (filename != null) { outFile = new TokenTextWriter(filename, true); } else { outFile = new TokenTextWriter(Console.Out, true); } p.Emit(outFile); outFile.Close(); }
static void removeTemplates(string file, string outfile) { var program = ParseProgram(file); foreach (var proc in program.TopLevelDeclarations.OfType <Procedure>().Where(p => QKeyValue.FindBoolAttribute(p.Attributes, "template"))) { proc.Ensures.RemoveAll(ens => !ens.Free); } var sw = new StreamWriter(outfile, false); var tw = new TokenTextWriter(sw); program.Emit(tw); sw.Close(); tw.Close(); }
// This version does change the tokens static public void Print(Program prog, TextWriter TW, bool pretty, string filename, bool setTokens, PrintType type) { // FIXME: // Urgh this is Gross! Fix boogie so we can request // printing an unstructured program cleanly // 0 = print only structured, 1 = both structured and unstructured, 2 = only unstructured CommandLineOptions.Clo.PrintUnstructured = (int)type; using (var tokenWriter = new TokenTextWriter(filename, TW, setTokens, pretty)) { foreach (var tld in prog.TopLevelDeclarations) { tld.Emit(tokenWriter, 0); } TW.Flush(); } }
public static Program Desugar(Program program, out List<Expr/*!*/>/*!*/ axioms, out List<Function/*!*/>/*!*/ functions) { Contract.Requires(program != null); Contract.Ensures(cce.NonNullElements(Contract.ValueAtReturn(out functions))); Contract.Ensures(cce.NonNullElements(Contract.ValueAtReturn(out axioms))); Contract.Ensures(Contract.Result<Program>() != null); LambdaVisitor v = new LambdaVisitor(); program = v.VisitProgram(program); axioms = v.lambdaAxioms; functions = v.lambdaFunctions; if (CommandLineOptions.Clo.TraceVerify) { Console.WriteLine("Desugaring of lambda expressions produced {0} functions and {1} axioms:", functions.Count, axioms.Count); TokenTextWriter wr = new TokenTextWriter("<console>", Console.Out, /*pretty=*/ false); foreach (Function f in functions) { f.Emit(wr, 0); } foreach (Expr ax in axioms) { ax.Emit(wr); Console.WriteLine(); } } return program; }
public override void DumpInternalsToFile(string fn, bool generate) { Boogie.Program boogieToDump; if (generate) { var boogieDecls = Translator.translate(null, env, () => VccCommandLineHost.StandardPrelude(parent.options), currentDecls); boogieToDump = PrepareBoogie(boogieDecls); } else { boogieToDump = currentBoogie; } fn = Path.ChangeExtension(fn, (bplFileCounter++) + ".bpl"); if (parent.options.OutputDir != null) { fn = Path.Combine(parent.options.OutputDir, Path.GetFileName(fn)); } CommandLineOptions.Install(new CommandLineOptions()); using (TokenTextWriter writer = new TokenTextWriter(fn)) boogieToDump.Emit(writer); }
public override void Emit(TokenTextWriter stream, int level) { //Contract.Requires(stream != null); stream.Write(this, level, "return "); this.Expr.Emit(stream); stream.WriteLine(";"); }
public Implementation Inject(Implementation implementation, Program programInCachedSnapshot) { Contract.Requires(implementation != null && programInCachedSnapshot != null); this.programInCachedSnapshot = programInCachedSnapshot; assumptionVariableCount = 0; temporaryVariableCount = 0; currentImplementation = implementation; #region Introduce explict assumption about the precondition. var oldProc = programInCachedSnapshot.FindProcedure(currentImplementation.Proc.Name); if (oldProc != null && oldProc.DependencyChecksum != currentImplementation.Proc.DependencyChecksum && currentImplementation.ExplicitAssumptionAboutCachedPrecondition == null) { var axioms = new List<Axiom>(); var after = new List<Cmd>(); Expr assumedExpr = new LiteralExpr(Token.NoToken, false); var canUseSpecs = DependencyCollector.CanExpressOldSpecs(oldProc, Program, true); if (canUseSpecs && oldProc.SignatureEquals(currentImplementation.Proc)) { var always = Substituter.SubstitutionFromHashtable(currentImplementation.GetImplFormalMap(), true, currentImplementation.Proc); var forOld = Substituter.SubstitutionFromHashtable(new Dictionary<Variable, Expr>()); var clauses = oldProc.Requires.Select(r => Substituter.FunctionCallReresolvingApply(always, forOld, r.Condition, Program)); var conj = Expr.And(clauses, true); assumedExpr = conj != null ? FunctionExtractor.Extract(conj, Program, axioms) : new LiteralExpr(Token.NoToken, true); } if (assumedExpr != null) { var lv = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, string.Format("a##cached##{0}", FreshAssumptionVariableName), Type.Bool), new QKeyValue(Token.NoToken, "assumption", new List<object>(), null)); currentImplementation.InjectAssumptionVariable(lv, !canUseSpecs); var lhs = new SimpleAssignLhs(Token.NoToken, new IdentifierExpr(Token.NoToken, lv)); var rhs = LiteralExpr.And(new IdentifierExpr(Token.NoToken, lv), assumedExpr); var assumed = new AssignCmd(currentImplementation.tok, new List<AssignLhs> { lhs }, new List<Expr> { rhs }); assumed.IrrelevantForChecksumComputation = true; currentImplementation.ExplicitAssumptionAboutCachedPrecondition = assumed; after.Add(assumed); } if (CommandLineOptions.Clo.TraceCachingForTesting || CommandLineOptions.Clo.TraceCachingForBenchmarking) { using (var tokTxtWr = new TokenTextWriter("<console>", Console.Out, false, false)) { var loc = currentImplementation.tok != null && currentImplementation.tok != Token.NoToken ? string.Format("{0}({1},{2})", currentImplementation.tok.filename, currentImplementation.tok.line, currentImplementation.tok.col) : "<unknown location>"; Console.Out.WriteLine("Processing implementation {0} (at {1}):", currentImplementation.Name, loc); foreach (var a in axioms) { Console.Out.Write(" >>> added axiom: "); a.Expr.Emit(tokTxtWr); Console.Out.WriteLine(); } foreach (var b in after) { Console.Out.Write(" >>> added after assuming the current precondition: "); b.Emit(tokTxtWr, 0); } } } } #endregion var result = VisitImplementation(currentImplementation); currentImplementation = null; this.programInCachedSnapshot = null; return result; }
public override void Emit(TokenTextWriter stream, int level) { //Contract.Requires(stream != null); stream.WriteLine(this, level, "{"); foreach (Variable/*!*/ v in Locals) { Contract.Assert(v != null); v.Emit(stream, level + 1); } foreach (Cmd/*!*/ c in Cmds) { Contract.Assert(c != null); c.Emit(stream, level + 1); } stream.WriteLine(level, "}"); }
public override void Emit(TokenTextWriter stream, int level) { //Contract.Requires(stream != null); if (CommandLineOptions.Clo.PrintDesugarings) { stream.WriteLine(this, level, "/*** desugaring:"); Desugaring.Emit(stream, level); stream.WriteLine(level, "**** end desugaring */"); } }
public override void Emit(TokenTextWriter stream, int level) { Contract.Requires(stream != null); throw new NotImplementedException(); }
protected virtual void EmitTriggers(TokenTextWriter stream) { Contract.Requires(stream != null); }
public abstract void Emit(TokenTextWriter/*!*/ stream);
public override void Emit(TokenTextWriter stream, int level) { //Contract.Requires(stream != null); stream.Write(this, level, "assume "); EmitAttributes(stream, Attributes); this.Expr.Emit(stream); stream.WriteLine(";"); }
public void Emit(TokenTextWriter stream, int level) { Contract.Requires(stream != null); if (!Anonymous) { stream.WriteLine(level, "{0}:", CommandLineOptions.Clo.PrintWithUniqueASTIds ? String.Format("h{0}^^{1}", this.GetHashCode(), this.LabelName) : this.LabelName); } foreach (Cmd/*!*/ c in this.simpleCmds) { Contract.Assert(c != null); c.Emit(stream, level + 1); } if (this.ec != null) { this.ec.Emit(stream, level + 1); } else if (this.tc != null) { this.tc.Emit(stream, level + 1); } }
public void Emit(TokenTextWriter stream, int level) { Contract.Requires(stream != null); stream.WriteLine(); stream.WriteLine( this, level, "{0}:{1}", CommandLineOptions.Clo.PrintWithUniqueASTIds ? String.Format("h{0}^^{1}", this.GetHashCode(), this.Label) : this.Label, this.widenBlock ? " // cut point" : ""); foreach (Cmd/*!*/ c in this.Cmds) { Contract.Assert(c != null); c.Emit(stream, level + 1); } Contract.Assume(this.TransferCmd != null); this.TransferCmd.Emit(stream, level + 1); }
public override void Emit(TokenTextWriter stream, int level) { if (Label == null) { stream.WriteLine(level, "break;"); } else { stream.WriteLine(level, "break {0};", Label); } }
private Program PrepareBoogie(Microsoft.FSharp.Collections.FSharpList<BoogieAST.Decl> boogieDecls) { var boogieProgram = parent.GetBoogieProgram(boogieDecls); CloseVcGen(); CommandLineOptions.Clo.Parse(standardBoogieOptions); IErrorSink errorSink = new BoogieErrorSink(parent.options.NoPreprocessor); int numErrors; try { parent.swBoogieResolve.Start(); numErrors = boogieProgram.Resolve(errorSink); } finally { parent.swBoogieResolve.Stop(); } if (numErrors == 0) { try { parent.swBoogieTypecheck.Start(); numErrors = boogieProgram.Typecheck(errorSink); } finally { parent.swBoogieTypecheck.Stop(); } } if (numErrors == 0) { try { parent.swBoogieAI.Start(); AbstractInterpretation.RunAbstractInterpretation(boogieProgram); } finally { parent.swBoogieAI.Stop(); } } if (Boogie.CommandLineOptions.Clo.ExpandLambdas && numErrors == 0) { Boogie.LambdaHelper.ExpandLambdas(boogieProgram); } if (numErrors != 0) { VccCommandLineHost.IncreaseErrorCount(); if (!parent.options.RunTestSuite) { Logger.Instance.Error("attempting to dump BPL to buggy.bpl"); var filename = "buggy.bpl"; if (parent.options.OutputDir != null) { filename = Path.Combine(parent.options.OutputDir, filename); } CommandLineOptions.Install(new CommandLineOptions()); using(TokenTextWriter writer = new TokenTextWriter(filename)) boogieProgram.Emit(writer); } errorMode = true; } return boogieProgram; }
public override void Emit(TokenTextWriter stream, int level) { //Contract.Requires(stream != null); stream.WriteLine(this, level, "yield;"); }
public override void Emit(TokenTextWriter stream, int level) { stream.Write(level, "while ("); if (Guard == null) { stream.Write("*"); } else { Guard.Emit(stream); } stream.WriteLine(")"); foreach (PredicateCmd inv in Invariants) { if (inv is AssumeCmd) { stream.Write(level + 1, "free invariant "); } else { stream.Write(level + 1, "invariant "); } Cmd.EmitAttributes(stream, inv.Attributes); inv.Expr.Emit(stream); stream.WriteLine(";"); } stream.WriteLine(level, "{"); Body.Emit(stream, level + 1); stream.WriteLine(level, "}"); }
public override void Emit(TokenTextWriter stream, int contextBindingStrength, bool fragileContext) { //Contract.Requires(stream != null); stream.push(); stream.Write(this, "({0}", Kind.ToString().ToLower()); this.EmitTypeHint(stream); Type.EmitOptionalTypeParams(stream, TypeParameters); stream.Write(this, " "); this.Dummies.Emit(stream, true); stream.Write(" :: "); stream.sep(); for (QKeyValue kv = this.Attributes; kv != null; kv = kv.Next) { kv.Emit(stream); stream.Write(" "); } this.EmitTriggers(stream); stream.sep(); this.Body.Emit(stream); stream.Write(")"); stream.pop(); }
public abstract void Emit(TokenTextWriter/*!*/ stream, int level);
public void Emit(TokenTextWriter stream) { Contract.Requires(stream != null); stream.Write("{:"); stream.Write(Key); string sep = " "; foreach (object p in Params) { stream.Write(sep); sep = ", "; if (p is string) { stream.Write("\""); stream.Write((string)p); stream.Write("\""); } else { ((Expr)p).Emit(stream); } } stream.Write("}"); }
// prints the list of statements, not the surrounding curly braces public void Emit(TokenTextWriter stream, int level) { Contract.Requires(stream != null); bool needSeperator = false; foreach (BigBlock b in BigBlocks) { Contract.Assert(b != null); Contract.Assume(cce.IsPeerConsistent(b)); if (needSeperator) { stream.WriteLine(); } b.Emit(stream, level); needSeperator = true; } }
public void Emit(TokenTextWriter stream) { Contract.Requires(stream != null); stream.SetToken(this); Contract.Assert(this.Tr.Count >= 1); string/*!*/ sep = Pos ? "{ " : "{:nopats "; foreach (Expr/*!*/ e in this.Tr) { Contract.Assert(e != null); stream.Write(sep); sep = ", "; e.Emit(stream); } stream.Write(" }"); }
public override Cmd VisitCallCmd(CallCmd node) { var result = base.VisitCallCmd(node); var oldProc = programInCachedSnapshot.FindProcedure(node.Proc.Name); if (oldProc != null && oldProc.DependencyChecksum != node.Proc.DependencyChecksum && node.AssignedAssumptionVariable == null) { var before = new List<Cmd>(); var beforePrecondtionCheck = new List<Cmd>(); var after = new List<Cmd>(); var axioms = new List<Axiom>(); Expr assumedExpr = new LiteralExpr(Token.NoToken, false); // TODO(wuestholz): Try out two alternatives: only do this for low priority implementations or not at all. var canUseSpecs = DependencyCollector.CanExpressOldSpecs(oldProc, Program); if (canUseSpecs && oldProc.SignatureEquals(node.Proc)) { var desugaring = node.Desugaring; Contract.Assert(desugaring != null); var precond = node.CheckedPrecondition(oldProc, Program, e => FunctionExtractor.Extract(e, Program, axioms)); if (precond != null) { var assume = new AssumeCmd(node.tok, precond, new QKeyValue(Token.NoToken, "precondition_previous_snapshot", new List<object>(), null)); assume.IrrelevantForChecksumComputation = true; beforePrecondtionCheck.Add(assume); } var unmods = node.UnmodifiedBefore(oldProc); var eqs = new List<Expr>(); foreach (var unmod in unmods) { var oldUnmod = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, string.Format("{0}##old##{1}", unmod.Name, FreshTemporaryVariableName), unmod.Type)); var lhs = new SimpleAssignLhs(Token.NoToken, new IdentifierExpr(Token.NoToken, oldUnmod)); var rhs = new IdentifierExpr(Token.NoToken, unmod.Decl); var cmd = new AssignCmd(Token.NoToken, new List<AssignLhs> { lhs }, new List<Expr> { rhs }); cmd.IrrelevantForChecksumComputation = true; before.Add(cmd); var eq = LiteralExpr.Eq(new IdentifierExpr(Token.NoToken, oldUnmod), new IdentifierExpr(Token.NoToken, unmod.Decl)); eq.Type = Type.Bool; eq.TypeParameters = SimpleTypeParamInstantiation.EMPTY; eqs.Add(eq); } var mods = node.ModifiedBefore(oldProc); var oldSubst = new Dictionary<Variable, Expr>(); foreach (var mod in mods) { var oldMod = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, string.Format("{0}##old##{1}", mod.Name, FreshTemporaryVariableName), mod.Type)); oldSubst[mod.Decl] = new IdentifierExpr(Token.NoToken, oldMod); var lhs = new SimpleAssignLhs(Token.NoToken, new IdentifierExpr(Token.NoToken, oldMod)); var rhs = new IdentifierExpr(Token.NoToken, mod.Decl); var cmd = new AssignCmd(Token.NoToken, new List<AssignLhs> { lhs }, new List<Expr> { rhs }); cmd.IrrelevantForChecksumComputation = true; before.Add(cmd); } assumedExpr = node.Postcondition(oldProc, eqs, oldSubst, Program, e => FunctionExtractor.Extract(e, Program, axioms)); if (assumedExpr == null) { assumedExpr = new LiteralExpr(Token.NoToken, true); } } if (assumedExpr != null) { var lv = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, string.Format("a##cached##{0}", FreshAssumptionVariableName), Type.Bool), new QKeyValue(Token.NoToken, "assumption", new List<object>(), null)); node.AssignedAssumptionVariable = lv; currentImplementation.InjectAssumptionVariable(lv, !canUseSpecs); var lhs = new SimpleAssignLhs(Token.NoToken, new IdentifierExpr(Token.NoToken, lv)); var rhs = LiteralExpr.And(new IdentifierExpr(Token.NoToken, lv), assumedExpr); var assumed = new AssignCmd(node.tok, new List<AssignLhs> { lhs }, new List<Expr> { rhs }); assumed.IrrelevantForChecksumComputation = true; after.Add(assumed); } node.ExtendDesugaring(before, beforePrecondtionCheck, after); if (CommandLineOptions.Clo.TraceCachingForTesting || CommandLineOptions.Clo.TraceCachingForBenchmarking) { using (var tokTxtWr = new TokenTextWriter("<console>", Console.Out, false, false)) { var loc = node.tok != null && node.tok != Token.NoToken ? string.Format("{0}({1},{2})", node.tok.filename, node.tok.line, node.tok.col) : "<unknown location>"; Console.Out.WriteLine("Processing call to procedure {0} in implementation {1} (at {2}):", node.Proc.Name, currentImplementation.Name, loc); foreach (var a in axioms) { Console.Out.Write(" >>> added axiom: "); a.Expr.Emit(tokTxtWr); Console.Out.WriteLine(); } foreach (var b in before) { Console.Out.Write(" >>> added before: "); b.Emit(tokTxtWr, 0); } foreach (var b in beforePrecondtionCheck) { Console.Out.Write(" >>> added before precondition check: "); b.Emit(tokTxtWr, 0); } foreach (var a in after) { Console.Out.Write(" >>> added after: "); a.Emit(tokTxtWr, 0); } } } } return result; }
protected override void EmitTriggers(TokenTextWriter stream) { //Contract.Requires(stream != null); stream.push(); for (Trigger tr = this.Triggers; tr != null; tr = tr.Next) { tr.Emit(stream); stream.Write(" "); stream.sep(); } stream.pop(); }
public override void Emit(TokenTextWriter stream) { AssignedVariable.Emit(stream); }
private void PrintFunction(Function function) { var tt = new TokenTextWriter(Console.Out); var invars = new List<Expr>(function.InParams.OfType<Variable>().Select(v => Expr.Ident(v))); function.Body = function2Value[function.Name].Gamma(invars); function.Emit(tt, 0); tt.Close(); }
public override void Emit(TokenTextWriter/*!*/ stream, int contextBindingStrength, bool fragileContext) { Contract.Assert(false);throw new cce.UnreachableException(); }
public override void Emit(TokenTextWriter stream, int level) { stream.Write(this, level, ""); string/*!*/ sep = ""; foreach (AssignLhs/*!*/ l in Lhss) { Contract.Assert(l != null); stream.Write(sep); sep = ", "; l.Emit(stream); } stream.Write(" := "); sep = ""; foreach (Expr/*!*/ e in Rhss) { Contract.Assert(e != null); stream.Write(sep); sep = ", "; e.Emit(stream); } stream.WriteLine(";"); }
public override void Verify(string fileName, TransHelper.TransEnv env, Microsoft.FSharp.Collections.FSharpList<CAST.Top> decls) { // this really only dumps the code to the .bpl file Init(env, fileName); decls = env.ApplyTransformers(decls); if (options.NoVerification) return; if (env.ShouldContinue) { if (env.Options.AggressivePruning && env.Options.Functions.Count() > 0) { decls = TransUtil.pruneBy(env, env.Options.Functions.First(), decls); } var boogieDecls = Translator.translate(null, env, () => VccCommandLineHost.StandardPrelude(options), decls); var p = TranslateToBoogie(boogieDecls); if (env.ShouldContinue) { try { swSaveBPL.Start(); CommandLineOptions.Install(new CommandLineOptions()); using (var writer = new TokenTextWriter(AddOutputDirIfRequested(Path.ChangeExtension(fileName, ".bpl")))) { p.Emit(writer); } } finally { swSaveBPL.Stop(); } } } }
public override void Emit(TokenTextWriter stream, int level) { //Contract.Requires(stream != null); stream.Write(this, level, ""); if (IsFree) { stream.Write("free "); } if (IsAsync) { stream.Write("async "); } stream.Write("call "); EmitAttributes(stream, Attributes); string sep = ""; if (Outs.Count > 0) { foreach (Expr arg in Outs) { stream.Write(sep); sep = ", "; if (arg == null) { stream.Write("*"); } else { arg.Emit(stream); } } stream.Write(" := "); } stream.Write(TokenTextWriter.SanitizeIdentifier(callee)); stream.Write("("); sep = ""; foreach (Expr arg in Ins) { stream.Write(sep); sep = ", "; if (arg == null) { stream.Write("*"); } else { arg.Emit(stream); } } stream.WriteLine(");"); base.Emit(stream, level); }