Exemplo n.º 1
0
        public BootableAppVerb(SourcePath dfyroot, DafnyCCVerb.FramePointerMode useFramePointer, VerificationRequest verificationRequest)
        {
            this.dfyroot = dfyroot;
            this.verificationRequest = verificationRequest;
            string concreteId = verificationRequest.ToString() + "," + useFramePointer.ToString();
            this.abstractId = new AbstractId(this.GetType().Name, version, dfyroot.ToString(), concrete: concreteId);

            string targetDirectory = Path.Combine(
                BuildEngine.theEngine.getObjRoot(),
                dfyroot.getDirPath(),
                "bootable-" + verificationRequest.ToString());
            this.bootIniFile = new BuildObject(Path.Combine(targetDirectory, "safeos\\boot.ini"));

            // TODO: Create the bootloader verb.

            this.loaderVerb = new IroncladAppVerb(new SourcePath(LOADER_DFY), IroncladAppVerb.TARGET.BARE_METAL, useFramePointer, verificationRequest);
            this.appVerb = new IroncladAppVerb(dfyroot, IroncladAppVerb.TARGET.BARE_METAL, useFramePointer, verificationRequest);

            this.batchVerb = new BatchVerifyVerb(dfyroot, new HashSet<IObligationsProducer>() { this.appVerb, this.loaderVerb }, BatchVerifyVerb.BatchMode.APP);
            this.batchSummaryVerb = new VerificationResultSummaryVerb(this.batchVerb);

            this.loaderCopy = new BuildObject(Path.Combine(targetDirectory, this.targetExecutableName(this.loaderVerb)));
            this.bootloaderCopy = new BuildObject(Path.Combine(targetDirectory, this.bootloader.getFileName()));
            this.appExecutableCopy = new BuildObject(Path.Combine(targetDirectory, this.targetExecutableName(this.appVerb)));
        }
Exemplo n.º 2
0
        public BootableAppVerb(SourcePath dfyroot, DafnyCCVerb.FramePointerMode useFramePointer, VerificationRequest verificationRequest)
        {
            this.dfyroot             = dfyroot;
            this.verificationRequest = verificationRequest;
            string concreteId = verificationRequest.ToString() + "," + useFramePointer.ToString();

            this.abstractId = new AbstractId(this.GetType().Name, version, dfyroot.ToString(), concrete: concreteId);

            string targetDirectory = Path.Combine(
                BuildEngine.theEngine.getObjRoot(),
                dfyroot.getDirPath(),
                "bootable-" + verificationRequest.ToString());

            this.bootIniFile = new BuildObject(Path.Combine(targetDirectory, "safeos\\boot.ini"));

            // TODO: Create the bootloader verb.

            this.loaderVerb = new IroncladAppVerb(new SourcePath(LOADER_DFY), IroncladAppVerb.TARGET.BARE_METAL, useFramePointer, verificationRequest);
            this.appVerb    = new IroncladAppVerb(dfyroot, IroncladAppVerb.TARGET.BARE_METAL, useFramePointer, verificationRequest);

            this.batchVerb = new BatchVerifyVerb(dfyroot, new HashSet <IObligationsProducer>()
            {
                this.appVerb, this.loaderVerb
            }, BatchVerifyVerb.BatchMode.APP);
            this.batchSummaryVerb = new VerificationResultSummaryVerb(this.batchVerb);

            this.loaderCopy        = new BuildObject(Path.Combine(targetDirectory, this.targetExecutableName(this.loaderVerb)));
            this.bootloaderCopy    = new BuildObject(Path.Combine(targetDirectory, this.bootloader.getFileName()));
            this.appExecutableCopy = new BuildObject(Path.Combine(targetDirectory, this.targetExecutableName(this.appVerb)));
        }
Exemplo n.º 3
0
        public NmakeVerb(SourcePath makefile)
        {
            _makefile   = makefile;
            _abstractId = new AbstractId(this.GetType().Name, version, _makefile.ToString());

            //- Generate output path
            _outputPath = ".";
            int depth = _makefile.getDirPath().Split(@"\/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length;

            for (int i = 0; i < depth; i++)
            {
                _outputPath = Path.Combine(_outputPath, "..");
            }

            _outputPathSuffix = Path.Combine(BuildEngine.theEngine.getObjRoot(), _makefile.getDirPath());
            _outputPath       = Path.Combine(_outputPath, _outputPathSuffix);
            _customManifest   = new CustomManifestParser(makefile);
        }
Exemplo n.º 4
0
        public VSSolutionVerb(SourcePath solutionFile)
        {
            _solutionFile = solutionFile;
            _abstractId   = new AbstractId(this.GetType().Name, version, _solutionFile.ToString());

            //- Parse the solution file
            _solutionParser = new VSSolutionParser(_solutionFile);

            //- Generate output path
            _outputPath = ".";
            int depth = _solutionFile.getDirPath().Split(@"\/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length;

            for (int i = 0; i < depth; i++)
            {
                _outputPath = Path.Combine(_outputPath, "..");
            }

            _outputPathSuffix = Path.Combine(BuildEngine.theEngine.getObjRoot(), _solutionFile.getDirPath());
            _outputPath       = Path.Combine(_outputPath, _outputPathSuffix);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Helper function for ExpandDafny method.
        /// </summary>
        /// <param name="input">Next include file to visit.</param>
        /// <returns>True if the given file wasn't already included, false otherwise.</returns>
        private bool ExpandDafnyRecurse(SourcePath input)
        {
            // Only visit each unique include file once.
            // Note that SourcePaths (like all BuildObjects) have normalized file paths.
            string inputPath = input.getRelativePath();

            if (this.visited.Contains(inputPath))
            {
                return(false);
            }
            else
            {
                this.visited.Add(inputPath);
            }

            using (TextReader reader = new StreamReader(this.workingDirectory.PathTo(input)))
            {
                while (true)
                {
                    string line = reader.ReadLine();
                    if (line == null)
                    {
                        return(true);
                    }

                    Match match = this.includeRegex.Match(line);
                    if (match.Success)
                    {
                        // This is an "include" line.  Find the included object.
                        string     includedPath = match.Groups[1].ToString();
                        string     gluedPath    = Path.Combine(input.getDirPath(), includedPath);
                        SourcePath nextInclude  = new SourcePath(gluedPath);
                        string     nextPath     = nextInclude.getRelativePath();

                        // Recurse on the new include file.
                        this.outputWriter.WriteLine("//- Begin include {0} (from {1})", nextPath, inputPath);
                        if (!this.ExpandDafnyRecurse(nextInclude))
                        {
                            this.outputWriter.WriteLine("//- Already included {0}", nextPath);
                        }

                        this.outputWriter.WriteLine("//- End include {0} (from {1})", nextPath, inputPath);
                    }
                    else
                    {
                        // This isn't an "include" line.  Write it to our output.
                        this.outputWriter.WriteLine(line);
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void parseCustomManifest(SourcePath basePath)
        {
            SourcePath manifest = basePath.getNewSourcePath("nubuild-manifest.txt");

            this.dependencies.Add(manifest);

            using (StreamReader stream = new StreamReader(IronRootDirectory.PathTo(manifest)))
            {
                string origline;

                while ((origline = stream.ReadLine()) != null)
                {
                    string line = origline.Trim();

                    if (line.Length == 0)
                    {
                        continue;
                    }

                    if (line.Substring(0, 1) == "#")
                    {
                        continue;
                    }

                    string[] parts = line.Split();

                    if (parts.Length != 2)
                    {
                        throw new UserError(string.Format("{0}: badly formed manifest line {1}", IronRootDirectory.PathTo(manifest), origline));
                    }

                    if ("output".Equals(parts[0]))
                    {
                        this.outputs.Add(new BuildObject(Path.Combine(basePath.getDirPath(), parts[1])));
                    }
                    else if ("dependency".Equals(parts[0]))
                    {
                        this.dependencies.Add(basePath.getNewSourcePath(parts[1]));
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void parseCustomManifest(SourcePath basePath)
        {
            SourcePath manifest = basePath.getNewSourcePath("nubuild-manifest.txt");
            this.dependencies.Add(manifest);

            using (StreamReader stream = new StreamReader(IronRootDirectory.PathTo(manifest)))
            {
                string origline;

                while ((origline = stream.ReadLine()) != null)
                {
                    string line = origline.Trim();

                    if (line.Length == 0)
                    {
                        continue;
                    }

                    if (line.Substring(0, 1) == "#")
                    {
                        continue;
                    }

                    string[] parts = line.Split();

                    if (parts.Length != 2)
                    {
                        throw new UserError(string.Format("{0}: badly formed manifest line {1}", IronRootDirectory.PathTo(manifest), origline));
                    }

                    if ("output".Equals(parts[0]))
                    {
                        this.outputs.Add(new BuildObject(Path.Combine(basePath.getDirPath(), parts[1])));
                    }
                    else if ("dependency".Equals(parts[0]))
                    {
                        this.dependencies.Add(basePath.getNewSourcePath(parts[1]));
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void _parse()
        {
            _dependencies.Add(_projectFile);

            using (XmlTextReader reader = new XmlTextReader(_projectFile.getFilesystemPath()))
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (String.Compare(reader.Name, "Compile") == 0)
                        {
                            _dependencies.Add(_projectFile.getNewSourcePath(reader.GetAttribute("Include")));
                        }
                        else if (String.Compare(reader.Name, "PropertyGroup") == 0)
                        {
                            _parseOutput(reader);
                        }
                    }

                }

                reader.Close();
            }

            if (_outputType != null && _assemblyName != null) //- && _outputPath != null)
            {
                string path = Path.Combine(_projectFile.getDirPath(), String.Format("{0}.{1}", _assemblyName, outputTypeToExtension(_outputType)));
                //-Console.WriteLine("{0}: generating {1}", _projectFile.getRelativePath(), path);
                _outputs.Add(new BuildObject(path));
            }
            else
            {
                throw new UserError(String.Format("Project {0} doesn't seem to have output specification in the expected format", _projectFile.getRelativePath()));
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Helper function for ExpandDafny method.
        /// </summary>
        /// <param name="input">Next include file to visit.</param>
        /// <returns>True if the given file wasn't already included, false otherwise.</returns>
        private bool ExpandDafnyRecurse(SourcePath input)
        {
            // Only visit each unique include file once.
            // Note that SourcePaths (like all BuildObjects) have normalized file paths.
            string inputPath = input.getRelativePath();
            if (this.visited.Contains(inputPath))
            {
                return false;
            }
            else
            {
                this.visited.Add(inputPath);
            }

            using (TextReader reader = new StreamReader(this.workingDirectory.PathTo(input)))
            {
                while (true)
                {
                    string line = reader.ReadLine();
                    if (line == null)
                    {
                        return true;
                    }

                    Match match = this.includeRegex.Match(line);
                    if (match.Success)
                    {
                        // This is an "include" line.  Find the included object.
                        string includedPath = match.Groups[1].ToString();
                        string gluedPath = Path.Combine(input.getDirPath(), includedPath);
                        SourcePath nextInclude = new SourcePath(gluedPath);
                        string nextPath = nextInclude.getRelativePath();

                        // Recurse on the new include file.
                        this.outputWriter.WriteLine("//- Begin include {0} (from {1})", nextPath, inputPath);
                        if (!this.ExpandDafnyRecurse(nextInclude))
                        {
                            this.outputWriter.WriteLine("//- Already included {0}", nextPath);
                        }

                        this.outputWriter.WriteLine("//- End include {0} (from {1})", nextPath, inputPath);
                    }
                    else
                    {
                        // This isn't an "include" line.  Write it to our output.
                        this.outputWriter.WriteLine(line);
                    }
                }
            }
        }
Exemplo n.º 10
0
        public IroncladAppVerb(SourcePath dfyroot, TARGET target, DafnyCCVerb.FramePointerMode framePointerMode, VerificationRequest verificationRequest)
        {
            this.dfyroot = dfyroot;

            // TODO this is the only #define we support just yet, so I'm stuffing it in here.
            // We'll need to plumb more carefully when we want to add x64.
            if (dfyroot.getDirPath().Split(Path.DirectorySeparatorChar).Last().Equals("AppLoader"))
            {
                this.poundDefines = new PoundDefines(new string[] { "AppLoader" });
            }
            else
            {
                this.poundDefines = PoundDefines.empty();
            }

            this.verificationRequest = verificationRequest;
            this.abstractId = new AbstractId(
                this.GetType().Name,
                version,
                dfyroot.ToString(),
                this.poundDefines,
                concrete: string.Format(
                    "{0},{1},{2}",
                    target,
                    framePointerMode.ToString(),
                    verificationRequest.ToString()));
            this.appLabel = dfyroot.getDirPath().Split(Path.DirectorySeparatorChar).Last();
            this.dafnyspecVerb = new DafnySpecVerb(dfyroot, this.appLabel);
            this.dafnyccVerb = new DafnyCCVerb(dfyroot, this.appLabel, framePointerMode);

            bool isLoader = dfyroot.getRelativePath().Equals(BootableAppVerb.LOADER_DFY);

            // NB we keep dafnyccVerb as the lowest-priority context, so that our hand-written
            // beat impls will override its output.
            IContextGeneratingVerb contextWithDafny = new ConcatContextVerb(
                BuildEngine.theEngine.getVerveContextVerb(this.poundDefines),
                new VerbOutputsContextVerb(this.dafnyspecVerb, false),
                new VerbOutputsContextVerb(this.dafnyccVerb, true),
                this.poundDefines);
            this.stitcherVerb = new EntryStitcherVerb(contextWithDafny, this.appLabel);
            IContextGeneratingVerb contextWithDafnyAndEntry = new ConcatContextVerb(
                new VerbOutputsContextVerb(this.stitcherVerb, false),
                contextWithDafny,
                this.poundDefines);

            BuildObject entryImpObj = this.stitcherVerb.getEntryImpOutput();
            BoogieAsmLinkVerb entryVerb = new BoogieAsmLinkVerb(contextWithDafnyAndEntry, entryImpObj);
            if (target == TARGET.BARE_METAL)
            {
                MasmVerb masmVerb = new MasmVerb(entryVerb);
                this.linkerVerb = new LinkerVerb(masmVerb, isLoader);
            }
            else if (target == TARGET.WINDOWS)
            {     // Rewrite the asm that comes out of entryVerb before linking it
                AsmRewriterVerb rewriter = new AsmRewriterVerb(entryVerb);
                MasmVerb masmVerb = new MasmVerb(rewriter);
                this.linkerVerb = new WinLinkerVerb(masmVerb, isLoader);
            }

            BoogieAsmVerificationObligationListVerb bavolVerb =
                new BoogieAsmVerificationObligationListVerb(contextWithDafnyAndEntry, entryImpObj, verificationRequest);

            this.verifyResultsVerb = new VerificationResultSummaryVerb(bavolVerb);

            this.srcObject = this.linkerVerb.getUntrustedExe();
            if (verificationRequest.isComplete())
            {
                this.exeObject = dfyroot.makeOutputObject(TRUSTED_EXE_EXTN);
                this.outputObject = this.exeObject;
            }
            else
            {
                this.exeObject = this.srcObject;
                this.outputObject = dfyroot.makeVirtualObject(UNVERIFIED_SENTINEL_EXTENSION);
            }
        }
Exemplo n.º 11
0
        public IroncladAppVerb(SourcePath dfyroot, TARGET target, DafnyCCVerb.FramePointerMode framePointerMode, VerificationRequest verificationRequest)
        {
            this.dfyroot = dfyroot;

            // TODO this is the only #define we support just yet, so I'm stuffing it in here.
            // We'll need to plumb more carefully when we want to add x64.
            if (dfyroot.getDirPath().Split(Path.DirectorySeparatorChar).Last().Equals("AppLoader"))
            {
                this.poundDefines = new PoundDefines(new string[] { "AppLoader" });
            }
            else
            {
                this.poundDefines = PoundDefines.empty();
            }

            this.verificationRequest = verificationRequest;
            this.abstractId          = new AbstractId(
                this.GetType().Name,
                version,
                dfyroot.ToString(),
                this.poundDefines,
                concrete: string.Format(
                    "{0},{1},{2}",
                    target,
                    framePointerMode.ToString(),
                    verificationRequest.ToString()));
            this.appLabel      = dfyroot.getDirPath().Split(Path.DirectorySeparatorChar).Last();
            this.dafnyspecVerb = new DafnySpecVerb(dfyroot, this.appLabel);
            this.dafnyccVerb   = new DafnyCCVerb(dfyroot, this.appLabel, framePointerMode);

            bool isLoader = dfyroot.getRelativePath().Equals(BootableAppVerb.LOADER_DFY);

            // NB we keep dafnyccVerb as the lowest-priority context, so that our hand-written
            // beat impls will override its output.
            IContextGeneratingVerb contextWithDafny = new ConcatContextVerb(
                BuildEngine.theEngine.getVerveContextVerb(this.poundDefines),
                new VerbOutputsContextVerb(this.dafnyspecVerb, false),
                new VerbOutputsContextVerb(this.dafnyccVerb, true),
                this.poundDefines);

            this.stitcherVerb = new EntryStitcherVerb(contextWithDafny, this.appLabel);
            IContextGeneratingVerb contextWithDafnyAndEntry = new ConcatContextVerb(
                new VerbOutputsContextVerb(this.stitcherVerb, false),
                contextWithDafny,
                this.poundDefines);

            BuildObject       entryImpObj = this.stitcherVerb.getEntryImpOutput();
            BoogieAsmLinkVerb entryVerb   = new BoogieAsmLinkVerb(contextWithDafnyAndEntry, entryImpObj);

            if (target == TARGET.BARE_METAL)
            {
                MasmVerb masmVerb = new MasmVerb(entryVerb);
                this.linkerVerb = new LinkerVerb(masmVerb, isLoader);
            }
            else if (target == TARGET.WINDOWS)
            {     // Rewrite the asm that comes out of entryVerb before linking it
                AsmRewriterVerb rewriter = new AsmRewriterVerb(entryVerb);
                MasmVerb        masmVerb = new MasmVerb(rewriter);
                this.linkerVerb = new WinLinkerVerb(masmVerb, isLoader);
            }

            BoogieAsmVerificationObligationListVerb bavolVerb =
                new BoogieAsmVerificationObligationListVerb(contextWithDafnyAndEntry, entryImpObj, verificationRequest);

            this.verifyResultsVerb = new VerificationResultSummaryVerb(bavolVerb);

            this.srcObject = this.linkerVerb.getUntrustedExe();
            if (verificationRequest.isComplete())
            {
                this.exeObject    = dfyroot.makeOutputObject(TRUSTED_EXE_EXTN);
                this.outputObject = this.exeObject;
            }
            else
            {
                this.exeObject    = this.srcObject;
                this.outputObject = dfyroot.makeVirtualObject(UNVERIFIED_SENTINEL_EXTENSION);
            }
        }