示例#1
0
文件: Options.cs 项目: tupipa/vcc
        public static VccOptions ParseCommandLineArguments(MetadataHostEnvironment hostEnvironment, IEnumerable <string> arguments, bool oneOrMoreSourceFilesExpected)
        {
            OptionParser parser = new OptionParser(hostEnvironment);

            parser.ParseCommandLineArguments(arguments, oneOrMoreSourceFilesExpected);
            CheckOptions(hostEnvironment, parser.options);
            return(parser.options);
        }
示例#2
0
文件: Options.cs 项目: tupipa/vcc
        public static VccOptions ParseCommandLineArguments(MetadataHostEnvironment hostEnvironment, IEnumerable <string> arguments, VccOptions template)
        {
            OptionParser parser = new OptionParser(hostEnvironment);

            parser.options.CopyFrom(template);
            parser.ParseCommandLineArguments(arguments, false);
            CheckOptions(hostEnvironment, parser.options);
            return(parser.options);
        }
示例#3
0
文件: Host.cs 项目: tupipa/vcc
        public static int Main(string[] args)
        {
            swTotal.Start();

            // reference symbol from Z3 so it gets copied
#pragma warning disable 168
            var y = new Microsoft.Boogie.SMTLib.Factory();
#pragma warning restore 168

            Logger.Instance.Register(ConsoleLogger.Instance);

            try
            {
                startTime                    = GetTime();
                cciErrorHandler              = new CciErrorHandler();
                dummyHostEnvironment.Errors += cciErrorHandler.HandleErrors;
                var commandLineOptions = OptionParser.ParseCommandLineArguments(dummyHostEnvironment, args);
                commandLineOptions.RunningFromCommandLine = true;
                cciErrorHandler.CommandLineOptions        = commandLineOptions;
                verificationErrorHandler = new VerificationErrorHandler(commandLineOptions);

                if (commandLineOptions.DisplayCommandLineHelp)
                {
                    DisplayCommandLineHelp();
                    return(0);
                }

                if (commandLineOptions.DisplayVersion)
                {
                    DisplayVersion();
                    return(0);
                }

                if (errorCount > 0 || fileErrorCount > 0)
                {
                    Console.Error.WriteLine("Exiting with 1 - error parsing arguments.");
                    return(1);
                }

                if (commandLineOptions.RunTestSuite)
                {
                    Logger.Instance.Unregister(ConsoleLogger.Instance);
                    Logger.Instance.Register(new ConsoleLoggerForTestRun());
                }

                if (!String.IsNullOrEmpty(commandLineOptions.XmlLogFile))
                {
                    Stream xmlStream = File.Open(commandLineOptions.XmlLogFile, FileMode.Create, FileAccess.Write);
                    Logger.Instance.Register(new XmlLogger(xmlStream));
                }

                if ((currentPlugin = InitializePlugin(commandLineOptions)) == null)
                {
                    Logger.Instance.Log("Exiting with 2 - error initializing plugin.");
                    return(2);
                }

                if (commandLineOptions.RunTestSuite)
                {
                    errorCount = TestRunner.RunTestSuite(commandLineOptions);
                }
                else
                {
                    RunPlugin(commandLineOptions);
                }

                swTotal.Stop();

                DumpTimes(commandLineOptions);

                int retVal = 0;

                if (errorCount > 0)
                {
                    Logger.Instance.Error("Exiting with 3 ({0} error(s).)", errorCount);
                    retVal = 3;
                }

                return(retVal);
            }
            finally
            {
                Logger.Instance.Dispose();
            }
        }
示例#4
0
文件: Options.cs 项目: tupipa/vcc
 public static VccOptions ParseCommandLineArguments(MetadataHostEnvironment hostEnvironment, IEnumerable <string> arguments)
 {
     return(OptionParser.ParseCommandLineArguments(hostEnvironment, arguments, true));
 }
示例#5
0
文件: VccPlugin.cs 项目: tupipa/vcc
        public override VerificationResult Verify(string funcName)
        {
            double start = VccCommandLineHost.GetTime();

            // Match replacement in Boogie names
            string sanitizedFuncName = funcName.Replace('\\', '#');

            bool restartProver = false;
            bool isolateProof  = HasIsolateProofAttribute(funcName);

            if (isolateProof)
            {
                CloseVcGen();
            }

            if (parent.options.AggressivePruning || isolateProof)
            {
                restartProver = true;
                // this needs to be done before pruning; otherwise call cycles might get hidden
                Termination.checkCallCycles(env, currentDecls);
                var decls       = TransUtil.pruneBy(env, funcName, currentDecls);
                var boogieDecls = Translator.translate(funcName, env, () => VccCommandLineHost.StandardPrelude(parent.options), decls);
                if (!env.ShouldContinue)
                {
                    return(VerificationResult.UserError);
                }
                currentBoogie        = PrepareBoogie(boogieDecls);
                mustRegenerateBoogie = true;
            }
            else
            {
                if (mustRegenerateBoogie || currentBoogie == null)
                {
                    var boogieDecls = Translator.translate(null, env, () => VccCommandLineHost.StandardPrelude(parent.options), currentDecls);
                    if (!env.ShouldContinue)
                    {
                        return(VerificationResult.UserError);
                    }
                    currentBoogie        = PrepareBoogie(boogieDecls);
                    mustRegenerateBoogie = false;
                }
            }

            Implementation impl = null;

            foreach (Declaration decl in currentBoogie.TopLevelDeclarations)
            {
                impl = decl as Implementation;
                if (impl != null && impl.Name == sanitizedFuncName)
                {
                    break;
                }
                impl = null;
            }
            if (impl == null)
            {
                Logger.Instance.Error("cannot find function: {0}", funcName);
                return(VerificationResult.UserError);
            }

            if (this.errorMode || !env.ShouldContinue)
            {
                return(VerificationResult.UserError);
            }

            if (impl.SkipVerification)
            {
                return(VerificationResult.Skipped);
            }

            Logger.Instance.LogMethodStart(funcName);

            string logPath = CommandLineOptions.Clo.SimplifyLogFilePath;

            if (logPath != null)
            {
                logPath = logPath.Replace("@VCCFILE@", TestRunner.currentTestcaseName);
            }
            if (logPath != null && logPath.Contains("@VCCFUNC@"))
            {
                logPath = logPath.Replace("@VCCFUNC@", funcName.Replace("$", "_").Replace("^", "_"));
                CloseVcGen();
            }

            string extraFunctionOptions = null;
            bool   isBvLemmaCheck       = IsBvLemmaCheck(impl);
            bool   skipSmoke            = HasSkipSmokeAttr(impl);

            if ((parent.options.RunInBatchMode && (extraFunctionOptions = GetExtraFunctionOptions(impl)) != null) || isBvLemmaCheck || skipSmoke)
            {
                CloseVcGen();
                extraFunctionOptions = extraFunctionOptions ?? ""; // this prevents parsing errors in case of bv_lemma checks and will also cause the VcGen to be closed later
                VccOptions    extraCommandLineOptions = OptionParser.ParseCommandLineArguments(VccCommandLineHost.dummyHostEnvironment, extraFunctionOptions.Split(' ', '\t'), false);
                List <string> effectiveOptions        = new List <string>(extraCommandLineOptions.BoogieOptions);
                effectiveOptions.AddRange(extraCommandLineOptions.Z3Options.Select(z3option => "/z3opt:" + z3option));
                effectiveOptions.AddRange(options);
                if (isBvLemmaCheck)
                {
                    effectiveOptions.Add("/proverOpt:OPTIMIZE_FOR_BV=true");
                    effectiveOptions.RemoveAll(opt => opt == "/z3opt:CASE_SPLIT");
                    effectiveOptions.Add("/z3opt:CASE_SPLIT=1");
                }

                if (skipSmoke)
                {
                    effectiveOptions.RemoveAll(opt => opt == "/smoke");
                }

                if (restartProver)
                {
                    effectiveOptions.Add("/restartProver");
                }

                if (!ReParseBoogieOptions(effectiveOptions, parent.options.RunningFromCommandLine))
                {
                    Logger.Instance.Error("Error parsing extra options '{0}' for function '{1}'", extraFunctionOptions, impl.Name);
                    return(VerificationResult.UserError);
                }
                try {
                    parent.swBoogie.Start();
                    vcgen = new VC.VCGen(currentBoogie, logPath, CommandLineOptions.Clo.SimplifyLogFileAppend);
                } finally {
                    parent.swBoogie.Stop();
                }
            }
            else if (vcgen == null)
            {
                // run with default options
                ReParseBoogieOptions(options, parent.options.RunningFromCommandLine);
                try {
                    parent.swBoogie.Start();
                    vcgen = new VC.VCGen(currentBoogie, logPath, CommandLineOptions.Clo.SimplifyLogFileAppend);
                } finally {
                    parent.swBoogie.Stop();
                }
            }

            var reporter = new ErrorReporter(parent.options, impl.Proc.Name, impl.Proc.tok, start, VccCommandLineHost.ErrorHandler);

            try {
                parent.swVcOpt.Start();
            } finally {
                parent.swVcOpt.Stop();
            }


            VC.ConditionGeneration.Outcome outcome;
            string extraInfo = null;

            try {
                parent.swVerifyImpl.Start();
                VCGenPlugin plugin = parent.plugin;
                outcome = plugin != null?plugin.VerifyImpl(env, vcgen, impl, currentBoogie, reporter) : vcgen.VerifyImplementation(impl, currentBoogie, reporter);
            } catch (UnexpectedProverOutputException exc) {
                outcome   = VC.ConditionGeneration.Outcome.OutOfMemory;
                extraInfo = "caused an exception \"" + exc.Message + "\"";
            } finally {
                parent.swVerifyImpl.Stop();
            }

            if (extraFunctionOptions != null)
            {
                CloseVcGen();
            }

            reporter.PrintSummary(outcome, extraInfo);

            modelCount += reporter.modelCount;

            switch (outcome)
            {
            case VC.ConditionGeneration.Outcome.Correct: return(VerificationResult.Succeeded);

            case VC.ConditionGeneration.Outcome.Errors: return(VerificationResult.Failed);

            case VC.ConditionGeneration.Outcome.Inconclusive: return(VerificationResult.Inconclusive);

            case VC.ConditionGeneration.Outcome.OutOfMemory: return(VerificationResult.Crashed);

            case VC.ConditionGeneration.Outcome.TimedOut: return(VerificationResult.Crashed);

            default: return(VerificationResult.Crashed);
            }
        }
示例#6
0
        private static int RunTest(CciErrorHandler errorHandler, string suiteName, string fileNameWithoutExt,
                                   string test, VccOptions commandLineOptions, List <string> compilerParameters)
        {
            VccCommandLineHost.ResetErrorCount();
            string fileNameC = fileNameWithoutExt + ".c";
            string fileNameI = fileNameWithoutExt + ".i";

            StreamWriter tempStreamWriter = new StreamWriter(fileNameC);

            tempStreamWriter.Write(test);
            tempStreamWriter.Close();

            VccOptions options = new VccOptions();

            options.CopyFrom(commandLineOptions);

            if (compilerParameters != null)
            {
                options = OptionParser.ParseCommandLineArguments(VccCommandLineHost.dummyHostEnvironment, compilerParameters, options);
            }

            options.NoPreprocessor    = false;
            options.CheckedArithmetic = true;
            options.RunTestSuite      = true;
            options.FileNames         = new List <string> {
                fileNameC
            };

            HostEnvironment hostEnvironment = new HostEnvironment(options.PointerSize);

            hostEnvironment.Errors += errorHandler.HandleErrors;

            bool errorsInPreprocessor;
            var  f = CCompilerHelper.Preprocess(options, out errorsInPreprocessor);

            if (errorsInPreprocessor)
            {
                return(-1);
            }
            var st = f.First();

            test = st.ReadToEnd();
            st.Close();
            File.Delete(fileNameC);
            // if (!options.KeepPreprocessorFiles) File.Delete(fileNameI);

            IName name = hostEnvironment.NameTable.GetNameFor(suiteName);
            List <IAssemblyReference> assemblyReferences = new List <IAssemblyReference>();
            List <IModuleReference>   moduleReferences   = new List <IModuleReference>();

            assemblyReferences.Add(hostEnvironment.LoadAssembly(hostEnvironment.CoreAssemblySymbolicIdentity));
            assemblyReferences.Add(hostEnvironment.LoadAssembly(hostEnvironment.VccRuntimeAssemblyIdentity));
            VccAssembly /*?*/ assem = null;

            if (hostEnvironment.previousDocument == null || compilerParameters == null ||
                !compilerParameters.Contains("/incremental"))
            {
                List <VccSourceDocument> programSources = new List <VccSourceDocument>(1);
                assem = new VccAssembly(name, "", hostEnvironment, options, assemblyReferences, moduleReferences, programSources);
                var helper = new VccCompilationHelper(assem.Compilation);
                programSources.Add(hostEnvironment.previousDocument = new VccSourceDocument(helper, name, name.ToString(), test));
            }
            VccCommandLineHost.ResetStartTime();
            return(VccCommandLineHost.Felt2Cast2Plugin("testcase", options, hostEnvironment, assem));
        }