Пример #1
0
Файл: Host.cs Проект: tupipa/vcc
        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++;
            }
        }
Пример #2
0
Файл: Host.cs Проект: tupipa/vcc
        internal static string FindMemberNameByLocation(string fileLoc, VccAssembly assem)
        {
            var colonPos = fileLoc.LastIndexOf(':');

            if (colonPos == -1 || colonPos == 0 || colonPos == fileLoc.Length - 1)
            {
                Logger.Instance.Error("invalid source location '{0}' .", fileLoc);
                errorCount++;
                return(null);
            }

            var  fileName = fileLoc.Substring(0, colonPos);
            uint fileLine;

            if (!uint.TryParse(fileLoc.Substring(colonPos + 1), out fileLine))
            {
                Logger.Instance.Error("invalid source location line '{0}' .", fileLoc.Substring(colonPos + 1));
                errorCount++;
                return(null);
            }

            var fullPath = Path.GetFullPath(fileName);

            foreach (var member in ((IAssembly)assem).NamespaceRoot.Members)
            {
                var ploc = new VisitorHelper.DeferredToken(member.Locations).GetToken() as IOriginalDocumentLocation;
                if (ploc != null &&
                    fullPath.Equals(Path.GetFullPath(ploc.OriginalDocumentLocation), StringComparison.OrdinalIgnoreCase) &&
                    ploc.StartLine <= fileLine &&
                    ploc.EndLine >= fileLine)
                {
                    return(member.Name.Value);
                }
            }

            Logger.Instance.Error("could not find source item with location '{0}'", fileLoc);
            errorCount++;
            return(null);
        }
Пример #3
0
Файл: Host.cs Проект: 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);
        }
Пример #4
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++;
       }
 }
Пример #5
0
        internal static string FindMemberNameByLocation(string fileLoc, VccAssembly assem)
        {
            var colonPos = fileLoc.LastIndexOf(':');
              if (colonPos == -1 || colonPos == 0 || colonPos == fileLoc.Length - 1)
              {
            Logger.Instance.Error("invalid source location '{0}' .", fileLoc);
            errorCount++;
            return null;
              }

              var fileName = fileLoc.Substring(0, colonPos);
              uint fileLine;

              if (!uint.TryParse(fileLoc.Substring(colonPos + 1), out fileLine))
              {
            Logger.Instance.Error("invalid source location line '{0}' .", fileLoc.Substring(colonPos + 1));
            errorCount++;
            return null;
              }

              var fullPath = Path.GetFullPath(fileName);

              foreach (var member in ((IAssembly)assem).NamespaceRoot.Members)
              {
            var ploc = new VisitorHelper.DeferredToken(member.Locations).GetToken() as IOriginalDocumentLocation;
            if (ploc != null &&
              fullPath.Equals(Path.GetFullPath(ploc.OriginalDocumentLocation), StringComparison.OrdinalIgnoreCase) &&
              ploc.StartLine <= fileLine &&
              ploc.EndLine >= fileLine)
            {
              return member.Name.Value;
            }
              }

              Logger.Instance.Error( "could not find source item with location '{0}'", fileLoc);
              errorCount++;
              return null;
        }
Пример #6
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;
        }
Пример #7
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);
        }
Пример #8
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));
        }