예제 #1
0
파일: Util.cs 프로젝트: zvonimir/corral
 public static void Close()
 {
     if (debugOut != null)
     {
         debugOut.Close();
     }
 }
예제 #2
0
 public static int TranslateAssemblyAndWriteOutput(List <string> assemblyNames, HeapFactory heapFactory, Options options, List <Regex> exemptionList, bool whiteList)
 {
     Contract.Requires(assemblyNames != null);
     Contract.Requires(heapFactory != null);
     try {
         var pgm      = TranslateAssembly(assemblyNames, heapFactory, options, exemptionList, whiteList);
         var fileName = assemblyNames[0];
         fileName = Path.GetFileNameWithoutExtension(fileName);
         string outputFileName = fileName + ".bpl";
         using (var writer = new Microsoft.Boogie.TokenTextWriter(outputFileName)) {
             Prelude.Emit(writer);
             pgm.Emit(writer);
             writer.Close();
         }
         return(0);          // success
     } catch (Exception e) { // swallow everything and just return an error code
         Console.WriteLine("The byte-code translator failed: {0}", e.Message);
         Console.WriteLine("Stack trace: {0}", e.StackTrace);
         return(-1);
     }
 }
예제 #3
0
        static int Main(string[] args)
        {
            int errorReturnValue = -1;

            #region Parse options and check for errors
            var options = new Options();
            options.Parse(args);
            if (options.HelpRequested)
            {
                options.PrintOptions("");
                return(errorReturnValue);
            }
            if (options.HasErrors)
            {
                options.PrintErrorsAndExit(Console.Out);
            }
            if (!String.IsNullOrWhiteSpace(options.exemptionFile))
            {
                string fileName = options.exemptionFile;
                var    c        = fileName[fileName.Length - 1];
                if (c == '+' || c == '-')
                {
                    fileName = options.exemptionFile.Remove(fileName.Length - 1);
                }
                if (!File.Exists(fileName))
                {
                    Console.WriteLine("Specified exemption file '{0}' not found.", fileName);
                }
            }
            if (options.stub != null)
            {
                Console.WriteLine("/s is no longer used to specify stub assemblies");
                return(errorReturnValue);
            }

            if (options.modelExceptions == 1 && !options.wholeProgram)
            {
                Console.WriteLine("can specify a precise modeling of exceptions only when doing whole program analysis");
                return(errorReturnValue);
            }

            if (options.breakIntoDebugger)
            {
                System.Diagnostics.Debugger.Launch();
            }

            #endregion

            var assemblyNames = options.assemblies;
            if (assemblyNames == null || assemblyNames.Count == 0)
            {
                assemblyNames = new List <string>();
                foreach (var g in options.GeneralArguments)
                {
                    assemblyNames.Add(g);
                }
            }

            #region If an exclusion file has been specified, read in each line as a regular expression
            List <Regex> exemptionList = null;
            bool         whiteList     = false;
            if (!String.IsNullOrWhiteSpace(options.exemptionFile))
            {
                int i = 0;
                exemptionList = new List <Regex>();
                string fileName = options.exemptionFile;
                var    c        = fileName[fileName.Length - 1];
                whiteList = true;
                if (c == '+' || c == '-')
                {
                    fileName = options.exemptionFile.Remove(fileName.Length - 1);
                    if (c == '-')
                    {
                        whiteList = false;
                    }
                }
                try {
                    // Create an instance of StreamReader to read from a file.
                    // The using statement also closes the StreamReader.
                    using (StreamReader sr = new StreamReader(fileName)) {
                        String line;
                        // Read and display lines from the file until the end of
                        // the file is reached.
                        while ((line = sr.ReadLine()) != null)
                        {
                            exemptionList.Add(new Regex(line));
                            i++;
                        }
                        //Console.WriteLine("Read {0} lines from the exclusion file '{1}'.",
                        //  i, options.exemptionFile);
                    }
                } catch (Exception e) {
                    Console.WriteLine("Something went wrong reading the exclusion file '{0}'; read in {1} lines, continuing processing.",
                                      fileName, i);
                    Console.WriteLine(e.Message);
                }
            }
            #endregion

            try {
                HeapFactory heap;
                switch (options.heapRepresentation)
                {
                case Options.HeapRepresentation.splitFields:
                    heap = new SplitFieldsHeap();
                    break;

                case Options.HeapRepresentation.general:
                    heap = new GeneralHeap();
                    break;

                default:
                    Console.WriteLine("Unknown setting for /heap");
                    return(1);
                }

                var pgm      = TranslateAssembly(assemblyNames, heap, options, exemptionList, whiteList);
                var fileName = assemblyNames[0];
                fileName = Path.GetFileNameWithoutExtension(fileName);
                string outputFileName = fileName + ".bpl";
                // Microsoft.Boogie.TokenTextWriter writer = new Microsoft.Boogie.TokenTextWriter("_" + outputFileName);
                Microsoft.Boogie.TokenTextWriter writer = new Microsoft.Boogie.TokenTextWriter(outputFileName);
                Prelude.Emit(writer);
                pgm.Emit(writer);
                writer.Close();
                return(0);
                // return Inline(outputFileName);
            } catch (Exception e) { // swallow everything and just return an error code
                Console.WriteLine("The byte-code translator failed: {0}", e.Message);
                Console.WriteLine("Stack trace: {0}", e.StackTrace);
                return(-1);
            }
        }
예제 #4
0
        public static int Inline(string bplFileName)
        {
            Bpl.CommandLineOptions options = new Bpl.CommandLineOptions();
            Bpl.CommandLineOptions.Install(options);
            Bpl.CommandLineOptions.Clo.DoModSetAnalysis = true;
            Bpl.Program program;
            string      _bplFileName = "_" + bplFileName;

            Bpl.Parser.Parse(_bplFileName, new List <string>(), out program);
            int errorCount = program.Resolve();

            if (errorCount != 0)
            {
                Console.WriteLine("{0} name resolution errors detected in {1}", errorCount, _bplFileName);
                return(-1);
            }
            errorCount = program.Typecheck();
            if (errorCount != 0)
            {
                Console.WriteLine("{0} type checking errors detected in {1}", errorCount, _bplFileName);
                return(-1);
            }
            bool inline = false;

            foreach (var d in program.TopLevelDeclarations)
            {
                if (d.FindExprAttribute("inline") != null)
                {
                    inline = true;
                }
            }
            if (inline)
            {
                foreach (var d in program.TopLevelDeclarations)
                {
                    var impl = d as Bpl.Implementation;
                    if (impl != null)
                    {
                        impl.OriginalBlocks  = impl.Blocks;
                        impl.OriginalLocVars = impl.LocVars;
                    }
                }
                foreach (var d in program.TopLevelDeclarations)
                {
                    var impl = d as Bpl.Implementation;
                    if (impl != null && !impl.SkipVerification)
                    {
                        Bpl.Inliner.ProcessImplementation(program, impl);
                    }
                }
                foreach (var d in program.TopLevelDeclarations)
                {
                    var impl = d as Bpl.Implementation;
                    if (impl != null)
                    {
                        impl.OriginalBlocks  = null;
                        impl.OriginalLocVars = null;
                    }
                }
            }
            Microsoft.Boogie.TokenTextWriter writer = new Microsoft.Boogie.TokenTextWriter(bplFileName);
            options.PrintInstrumented = true;
            program.Emit(writer);
            writer.Close();
            return(0);
        }
예제 #5
0
    static int Main(string[] args)
    {
      int errorReturnValue = -1;

      #region Parse options and check for errors
      var options = new Options();
      options.Parse(args);
      if (options.HelpRequested) {
        options.PrintOptions("");
        return errorReturnValue;
      }
      if (options.HasErrors) {
        options.PrintErrorsAndExit(Console.Out);
      }
      if (!String.IsNullOrWhiteSpace(options.exemptionFile)) {
        string fileName = options.exemptionFile;
        var c = fileName[fileName.Length - 1];
        if (c == '+' || c == '-') fileName = options.exemptionFile.Remove(fileName.Length - 1);
        if (!File.Exists(fileName)) {
          Console.WriteLine("Specified exemption file '{0}' not found.", fileName);
        }
      }
      if (options.stub != null) {
        Console.WriteLine("/s is no longer used to specify stub assemblies");
        return errorReturnValue;
      }

      if (options.modelExceptions == 1 && !options.wholeProgram) {
        Console.WriteLine("can specify a precise modeling of exceptions only when doing whole program analysis");
        return errorReturnValue;
      }

      if (options.breakIntoDebugger) {
        System.Diagnostics.Debugger.Launch();
      }

      #endregion

      var assemblyNames = options.assemblies;
      if (assemblyNames == null || assemblyNames.Count == 0) {
        assemblyNames = new List<string>();
        foreach (var g in options.GeneralArguments) {
          assemblyNames.Add(g);
        }
      }

      #region If an exclusion file has been specified, read in each line as a regular expression
      List<Regex> exemptionList = null;
      bool whiteList = false;
      if (!String.IsNullOrWhiteSpace(options.exemptionFile)) {
        int i = 0;
        exemptionList = new List<Regex>();
        string fileName = options.exemptionFile;
        var c = fileName[fileName.Length - 1];
        whiteList = true;
        if (c == '+' || c == '-') {
          fileName = options.exemptionFile.Remove(fileName.Length - 1);
          if (c == '-') whiteList = false;
        }
        try {
          // Create an instance of StreamReader to read from a file.
          // The using statement also closes the StreamReader.
          using (StreamReader sr = new StreamReader(fileName)) {
            String line;
            // Read and display lines from the file until the end of 
            // the file is reached.
            while ((line = sr.ReadLine()) != null) {
              exemptionList.Add(new Regex(line));
              i++;
            }
            //Console.WriteLine("Read {0} lines from the exclusion file '{1}'.",
            //  i, options.exemptionFile);
          }
        } catch (Exception e) {
          Console.WriteLine("Something went wrong reading the exclusion file '{0}'; read in {1} lines, continuing processing.",
            fileName, i);
          Console.WriteLine(e.Message);
        }
      }
      #endregion

      try {
        HeapFactory heap;
        switch (options.heapRepresentation) {
          case Options.HeapRepresentation.splitFields:
            heap = new SplitFieldsHeap();
            break;
          case Options.HeapRepresentation.general:
            heap = new GeneralHeap();
            break;
          default:
            Console.WriteLine("Unknown setting for /heap");
            return 1;
        }

        if ((options.phoneFeedbackCode || options.phoneNavigationCode) && (options.phoneControls == null || options.phoneControls == "")) {
          Console.WriteLine("Options /phoneNavigationCode and /phoneFeedbackCode need /phoneControls option set.");
          return 1;
        }

        var pgm = TranslateAssembly(assemblyNames, heap, options, exemptionList, whiteList);
        var fileName = assemblyNames[0];
        fileName = Path.GetFileNameWithoutExtension(fileName);
        string outputFileName = fileName + ".bpl";
        // Microsoft.Boogie.TokenTextWriter writer = new Microsoft.Boogie.TokenTextWriter("_" + outputFileName);
        Microsoft.Boogie.TokenTextWriter writer = new Microsoft.Boogie.TokenTextWriter(outputFileName);
        Prelude.Emit(writer);
        pgm.Emit(writer);
        writer.Close();
        return 0;
        // return Inline(outputFileName);
      } catch (Exception e) { // swallow everything and just return an error code
        Console.WriteLine("The byte-code translator failed: {0}", e.Message);
        // Console.WriteLine("Stack trace: {0}", e.StackTrace);
        return -1;
      }
    }
예제 #6
0
 public static int TranslateAssemblyAndWriteOutput(List<string> assemblyNames, HeapFactory heapFactory, Options options, List<Regex> exemptionList, bool whiteList) {
   Contract.Requires(assemblyNames != null);
   Contract.Requires(heapFactory != null);
   try {
     var pgm = TranslateAssembly(assemblyNames, heapFactory, options, exemptionList, whiteList);
     var fileName = assemblyNames[0];
     fileName = Path.GetFileNameWithoutExtension(fileName);
     string outputFileName = fileName + ".bpl";
     using (var writer = new Microsoft.Boogie.TokenTextWriter(outputFileName)) {
       Prelude.Emit(writer);
       pgm.Emit(writer);
       writer.Close();
     }
     return 0; // success
   } catch (Exception e) { // swallow everything and just return an error code
     Console.WriteLine("The byte-code translator failed: {0}", e.Message);
     // Console.WriteLine("Stack trace: {0}", e.StackTrace);
     return -1;
   }
 }
예제 #7
0
    public static int Inline(string bplFileName) {
      Bpl.CommandLineOptions options = new Bpl.CommandLineOptions();
      Bpl.CommandLineOptions.Install(options);
      Bpl.CommandLineOptions.Clo.DoModSetAnalysis = true;
      Bpl.Program program;
      string _bplFileName = "_" + bplFileName;

      Bpl.Parser.Parse(_bplFileName, new List<string>(), out program);
      int errorCount = program.Resolve();
      if (errorCount != 0) {
        Console.WriteLine("{0} name resolution errors detected in {1}", errorCount, _bplFileName);
        return -1;
      }
      errorCount = program.Typecheck();
      if (errorCount != 0) {
        Console.WriteLine("{0} type checking errors detected in {1}", errorCount, _bplFileName);
        return -1;
      }
      bool inline = false;
      foreach (var d in program.TopLevelDeclarations) {
        if (d.FindExprAttribute("inline") != null) {
          inline = true;
        }
      }
      if (inline) {
        foreach (var d in program.TopLevelDeclarations) {
          var impl = d as Bpl.Implementation;
          if (impl != null) {
            impl.OriginalBlocks = impl.Blocks;
            impl.OriginalLocVars = impl.LocVars;
          }
        }
        foreach (var d in program.TopLevelDeclarations) {
          var impl = d as Bpl.Implementation;
          if (impl != null && !impl.SkipVerification) {
            Bpl.Inliner.ProcessImplementation(program, impl);
          }
        }
        foreach (var d in program.TopLevelDeclarations) {
          var impl = d as Bpl.Implementation;
          if (impl != null) {
            impl.OriginalBlocks = null;
            impl.OriginalLocVars = null;
          }
        }
      }
      Microsoft.Boogie.TokenTextWriter writer = new Microsoft.Boogie.TokenTextWriter(bplFileName);
      options.PrintInstrumented = true;
      program.Emit(writer);
      writer.Close();
      return 0;
    }