예제 #1
0
        public async Task BuildAsync(EntryPointOperation entryPoint, IList <DirectoryInfo> libraryDirectories, IList <DirectoryInfo> includeDirectories)
        {
            var sourceDirectory = new DirectoryInfo(SourceDirectoryPath);

            if (sourceDirectory.Exists)
            {
                sourceDirectory.Delete(true);
            }

            sourceDirectory.Create();
            logger?.LogInformation($"Created source directory at {sourceDirectory.FullName}.");

            // Create driver.
            var driverFileNameWithExtension = Path.ChangeExtension(DriverFileName, DriverFileExtension);
            var driverFile = new FileInfo(Path.Combine(sourceDirectory.FullName, driverFileNameWithExtension));

            using (var driverFileStream = driverFile.OpenWrite())
            {
                await driverGenerator.GenerateAsync(entryPoint, driverFileStream);
            }
            logger?.LogInformation($"Created driver file at {driverFile.FullName}.");

            // Create bitcode file.
            var bitcodeFile = new FileInfo(Path.Combine(sourceDirectory.FullName, BitcodeFileName));

            using (var bitcodeFileStream = bitcodeFile.OpenWrite())
            {
                await bitcodeFileStream.WriteAsync(qirBitcode);
            }
            logger?.LogInformation($"Created bitcode file at {bitcodeFile.FullName}.");
            await executableGenerator.GenerateExecutableAsync(ExecutableFile, sourceDirectory, libraryDirectories.Concat(this.LibraryDirectories).ToList(), includeDirectories.Concat(this.HeaderDirectories).ToList(), LinkLibraries);
        }
예제 #2
0
        public async Task TestBuild()
        {
            // Set up.
            var entryPoint         = new EntryPointOperation();
            var driverFileContents = "driver file contents";

            driverGeneratorMock.Setup(obj => obj.GenerateAsync(entryPoint, It.IsAny <Stream>())).Callback <EntryPointOperation, Stream>((entryPoint, stream) =>
            {
                using var streamWriter = new StreamWriter(stream);
                streamWriter.Write(driverFileContents);
            });

            // Build the executable.
            await qirExecutable.Object.BuildAsync(entryPoint, new[] { libraryDirectory }, new[] { includeDirectory });

            // Verify that the "bytecode" file was created correctly.
            var bytecodeFilePath = new FileInfo(Path.Combine(sourceDirectory.FullName, "qir.bc"));

            using var bytecodeFileStream = bytecodeFilePath.OpenRead();
            Assert.True(Util.CompareStreams(new MemoryStream(qirBytecode), bytecodeFileStream));

            // Verify that the driver was written to the correct file.
            var driver = new FileInfo(Path.Combine(sourceDirectory.FullName, "driver.cpp"));

            using var driverStreamReader = driver.OpenText();
            var actualDriverContents = driverStreamReader.ReadToEnd();

            Assert.Equal(driverFileContents, actualDriverContents);

            // Verify that the executable was generated.
            executableGeneratorMock.Verify(obj => obj.GenerateExecutableAsync(executableFile, It.Is <DirectoryInfo>(arg => arg.FullName == sourceDirectory.FullName), new[] { libraryDirectory }, new[] { includeDirectory }, linkLibraries));
        }
        public static void GenerateQirDriverCpp(EntryPointOperation entryPointOperation, Stream stream)
        {
            QirDriverCpp qirDriverCpp = new QirDriverCpp(entryPointOperation);
            var          cppSource    = qirDriverCpp.TransformText();

            stream.Write(Encoding.UTF8.GetBytes(cppSource));
            stream.Flush();
            stream.Position = 0;
        }
        public async Task GenerateAsync(EntryPointOperation entryPointOperation, Stream stream)
        {
            var qirCppDriver = new QirCppDriver(entryPointOperation, RuntimeInitalizer);
            var cppSource    = qirCppDriver.TransformText();
            await stream.WriteAsync(Encoding.UTF8.GetBytes(cppSource));

            await stream.FlushAsync();

            stream.Position = 0;
        }
예제 #5
0
 public QirCppDriver(EntryPointOperation entryPoint, IQirRuntimeInitializer runtimeInitializer)
 {
     EntryPoint         = entryPoint;
     RuntimeInitializer = runtimeInitializer;
 }
예제 #6
0
 public static bool ContainsArrayType(this EntryPointOperation @this, DataType type) =>
 @this.Parameters.Where(arg => arg.ArrayType == type).Any();
 public QirDriverCpp(EntryPointOperation entryPoint)
 {
     this.entryPointOperation = entryPoint;
 }