예제 #1
0
        // Return a new copy of the program
        public override Program getProgram()
        {
            var     startTime = DateTime.Now;
            Program ret;

            if (unresolved_program != null)
            {
                FixedDuplicator dup = new FixedDuplicator();
                ret = dup.VisitProgram(unresolved_program);
            }
            else
            {
                var progStr = "";
                if (programStream is FileStream || programStream is MemoryStream)
                {
                    var stream = programStream as Stream;
                    stream.Seek(0, SeekOrigin.Begin);
                    progStr = ParserHelper.Fill(stream, new List <string>());
                }
                else
                {
                    Debug.Assert(programStream is string);
                    progStr = (string)programStream;
                }

                var v = Parser.Parse(progStr, "PersistentProgram", out ret);

                if (v != 0)
                {
                    writeToFile("error.bpl");
                    throw new InternalError("Illegal program given to PersistentProgram");
                }

                if (PersistentProgram.clearTokens)
                {
                    PersistentProgram.ClearTokens(ret);
                }

                // TODO: use this always (sometimes .NET-2-Boogie programs crash)
                if (useDuplicator)
                {
                    FixedDuplicator dup = new FixedDuplicator();
                    unresolved_program = dup.VisitProgram(ret);
                }
            }

            if (ret.Resolve() != 0)
            {
                writeToFile("error.bpl");
                throw new InternalError("Illegal program given to PersistentProgram");
            }

            persistenceCost += (DateTime.Now - startTime);
            return(ret);
        }
예제 #2
0
        public PersistentProgram run(PersistentProgram inp)
        {
            Debug.Assert(!alreadyRan);
            alreadyRan = true;
            passCount++;

            // Save input
            setInput(inp);

            if (writeAllFiles)
            {
                string outfile = "tr" + passCount + "intput.bpl";
                input.writeToFile(outfile);
            }

            Log.WriteMemUsage();
            Log.WriteLine(Log.Debug, "Running transformation pass " + passCount.ToString() + ": " + passName);
            //Log.WriteLine(Log.Normal, "Running transformation pass " + passCount.ToString() + ": " + passName);

            Program outp = runPass(getInput(input));

            // Save output
            if (outp == null)
            {
                return(input);
            }

            output = recordOutput(outp);

            if (writeAllFiles)
            {
                string outfile = "tr" + passCount + "output.bpl";
                output.writeToFile(outfile);
            }

            return(output);
        }
예제 #3
0
 public void setInput(PersistentProgram p)
 {
     input = p;
 }
예제 #4
0
 virtual protected Program getInput(PersistentProgram inp)
 {
     return(inp.getProgram());
 }
예제 #5
0
        public static void CheckMemoryPressure()
        {
            if (PersistentProgram.memLimit == 0)
            {
                return;
            }

            // Check if we're within 80% of the limit
            var mem = BoogieUtil.GetMemUsage();

            if (mem < (0.8) * PersistentProgram.memLimit)
            {
                return;
            }

            PersistentProgram.FreeParserMemory();
            GC.Collect();

            if (changedSettingsForSavingMemory)
            {
                return;
            }
            changedSettingsForSavingMemory = true;

            // Set flags
            useFiles      = true;
            useDuplicator = false;
            PersistentProgram.FreeParserMemory();

            // Move all programs to disk
            programs = programs.Filter(wr => wr.IsAlive);
            var stat = 0;

            foreach (var wr in programs)
            {
                var p = wr.Target as PersistentProgramIO;
                if (p == null)
                {
                    continue;
                }
                if (p.programStream is FileStream)
                {
                    continue;
                }

                p.unresolved_program = null;
                p.fileName           = "temp_corral_file" + count.ToString();
                count++;

                if (p.programStream is MemoryStream)
                {
                    var fs = new FileStream(p.fileName, FileMode.Create);
                    fs.Write((p.programStream as MemoryStream).GetBuffer(), 0, (int)(p.programStream as MemoryStream).Length);
                    p.programStream = fs;
                }
                else
                {
                    Debug.Assert(p.programStream is string);
                    System.IO.File.WriteAllText(p.fileName, (string)p.programStream);
                    p.programStream = new FileStream(p.fileName, FileMode.Open);
                }
                stat++;
            }

            if (stat != 0)
            {
                Console.WriteLine("Moved {0} files to disk to save memory", stat);
            }

            // Force GC
            GC.Collect();
        }