Exemplo n.º 1
0
Arquivo: Host.cs Projeto: tupipa/vcc
        internal static int Felt2Cast2Plugin(string fileName, VccOptions commandLineOptions, HostEnvironment hostEnvironment, VccAssembly assem)
        {
            try
            {
                TransHelper.TransEnv helperenv;
                FSharp.Collections.FSharpList <CAST.Top> res;

                try
                {
                    swVisitor.Start();
                    helperenv = new TransEnv(hostEnvironment, commandLineOptions);
                    var visitor = new Microsoft.Research.Vcc.Visitor(assem.Compilation.ContractProvider, helperenv);

                    if (commandLineOptions.VerificationLocation != null)
                    {
                        var memberAtLoc = FindMemberNameByLocation(commandLineOptions.VerificationLocation, assem);
                        if (memberAtLoc != null)
                        {
                            commandLineOptions.Functions.Add(memberAtLoc);
                        }
                    }

                    try
                    {
                        if (commandLineOptions.AggressivePruning && (commandLineOptions.Functions.Count > 0 || commandLineOptions.FunctionsWithExactName.Count > 0))
                        {
                            var pruningRoots = new List <string>();
                            pruningRoots.AddRange(commandLineOptions.Functions.ConvertAll(FunctionOrTypeRoot));
                            pruningRoots.AddRange(commandLineOptions.FunctionsWithExactName.ConvertAll(FunctionOrTypeRoot));
                            visitor.VisitOnly(assem, pruningRoots);
                        }
                        else
                        {
                            ((ICodeVisitor)visitor).Visit(assem);
                        }
                    }
                    catch
                    {
                        if (helperenv.ShouldDumpStack)
                        {
                            throw;
                        }
                        return(0);
                    }

                    res = visitor.GetResult();
                }
                finally
                {
                    swVisitor.Stop();
                }

                if (fileErrorCount > 0)
                {
                    return(fileErrorCount);
                }

                try
                {
                    swPlugin.Start();
                    if (currentPlugin.IsModular())
                    {
                        var fv = currentPlugin.GetFunctionVerifier(fileName, helperenv, res);
                        if (helperenv.ShouldContinue && fileErrorCount == 0)
                        {
                            VerifyFunctions(commandLineOptions, fileName, assem.Name.ToString(), fv);
                        }
                    }
                    else
                    {
                        currentPlugin.Verify(fileName, helperenv, res);
                    }
                }
                finally
                {
                    errorCount    += fileErrorCount;
                    fileErrorCount = 0;
                    swPlugin.Stop();
                }

                return(0);
            }
            catch (ProverDiedException e)
            {
                // we might want to do something else for this one
                Logger.Instance.NewLine();
                Logger.Instance.Error(e.Message);
            }
            catch (UnexpectedProverOutputException e)
            {
                Logger.Instance.NewLine();
                Logger.Instance.Error(e.Message);
            }
            catch (Exception e)
            {
                Logger.Instance.NewLine();
                Logger.Instance.Error(e.Message);
            }

            return(-2);
        }
Exemplo n.º 2
0
 private static void RunPlugin(string fileName, StreamReader instream, VccOptions commandLineOptions)
 {
     HostEnvironment hostEnvironment = new HostEnvironment(commandLineOptions.PointerSize);
       hostEnvironment.Errors += new CciErrorHandler(commandLineOptions).HandleErrors;
       IName assemName = hostEnvironment.NameTable.GetNameFor(Path.GetFileNameWithoutExtension(fileName));
       IName docName = hostEnvironment.NameTable.GetNameFor(Path.GetFileName(fileName));
       List<IAssemblyReference> assemblyReferences = new List<IAssemblyReference>();
       List<IModuleReference> moduleReferences = new List<IModuleReference>();
       assemblyReferences.Add(hostEnvironment.LoadAssembly(hostEnvironment.CoreAssemblySymbolicIdentity));
       assemblyReferences.Add(hostEnvironment.LoadAssembly(hostEnvironment.VccRuntimeAssemblyIdentity));
       List<VccSourceDocument> programSources = new List<VccSourceDocument>(1);
       VccAssembly assem = new VccAssembly(assemName, Path.GetFullPath(fileName), hostEnvironment, commandLineOptions, assemblyReferences, moduleReferences, programSources);
       VccCompilationHelper helper = new VccCompilationHelper(assem.Compilation);
       programSources.Add(new VccSourceDocument(helper, docName, Path.GetFullPath(fileName), instream));
       if (0 != Felt2Cast2Plugin(fileName, commandLineOptions, hostEnvironment, assem))
       {
       fileErrorCount++;
       }
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        internal static int Felt2Cast2Plugin(string fileName, VccOptions commandLineOptions, HostEnvironment hostEnvironment, VccAssembly assem)
        {
            try
              {

            TransHelper.TransEnv helperenv;
            FSharp.Collections.FSharpList<CAST.Top> res;

            try
            {
              swVisitor.Start();
              helperenv = new TransEnv(hostEnvironment, commandLineOptions);
              var visitor = new Microsoft.Research.Vcc.Visitor(assem.Compilation.ContractProvider, helperenv);

              if (commandLineOptions.VerificationLocation != null)
              {
            var memberAtLoc = FindMemberNameByLocation(commandLineOptions.VerificationLocation, assem);
            if (memberAtLoc != null)
            {
              commandLineOptions.Functions.Add(memberAtLoc);
            }
              }

              try
              {
            if (commandLineOptions.AggressivePruning && (commandLineOptions.Functions.Count > 0 || commandLineOptions.FunctionsWithExactName.Count > 0))
            {
              var pruningRoots = new List<string>();
              pruningRoots.AddRange(commandLineOptions.Functions.ConvertAll(FunctionOrTypeRoot));
              pruningRoots.AddRange(commandLineOptions.FunctionsWithExactName.ConvertAll(FunctionOrTypeRoot));
              visitor.VisitOnly(assem, pruningRoots);
            }
            else
              ((ICodeVisitor)visitor).Visit(assem);
              }
              catch
              {
            if (helperenv.ShouldDumpStack) throw;
            return 0;
              }

              res = visitor.GetResult();
            }
            finally
            {
              swVisitor.Stop();
            }

            if (fileErrorCount > 0) return fileErrorCount;

            try
            {
              swPlugin.Start();
              if (currentPlugin.IsModular())
              {
            var fv = currentPlugin.GetFunctionVerifier(fileName, helperenv, res);
            if (helperenv.ShouldContinue && fileErrorCount == 0)
              VerifyFunctions(commandLineOptions, fileName, assem.Name.ToString(), fv);
              }
              else
              {
            currentPlugin.Verify(fileName, helperenv, res);
              }
            }
            finally
            {
              errorCount += fileErrorCount;
              fileErrorCount = 0;
              swPlugin.Stop();
            }

            return 0;

              }
              catch (ProverDiedException e)
              {
            // we might want to do something else for this one
            Logger.Instance.NewLine();
            Logger.Instance.Error(e.Message);
              }
              catch (UnexpectedProverOutputException e)
              {
            Logger.Instance.NewLine();
            Logger.Instance.Error(e.Message);
              }
              catch (Exception e)
              {
            Logger.Instance.NewLine();
            Logger.Instance.Error(e.Message);
              }

              return -2;
        }
Exemplo n.º 5
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));
        }