protected string Build(Ion.CodeGeneration.Module module) { // Create the resulting string. string result; // Create the full, target output path. string targetPath; // Default to IR file extension. string extension = FileExtension.IR; // Print the resulting LLVM IR code to the output target if applicable. if (!this.options.Bitcode) { // TODO: Make use of this. string error; // Create the target path. targetPath = Path.Join(this.options.Output, $"{module.FileName}.{extension}"); // TODO: Should not write to file/create file. // Emit IR to target path. LLVM.PrintModuleToFile(module.Target, targetPath, out error); } // Otherwise, emit LLVM Bitcode result. else { // Set the extension to Bitcode. extension = FileExtension.BitcodeObj; // Create the target path. targetPath = Path.Join(this.options.Output, $"{module.FileName}.{extension}"); // TODO: Should not write to file/create file. // Write bitcode to target path. if (LLVM.WriteBitcodeToFile(module.Target, targetPath) != 0) { Log.Error($"There was an error writing LLVM bitcode to '{targetPath}'."); } } // Read and obtain emitted data. result = File.ReadAllText(targetPath); // Return result. return(result); }
protected Project ProcessScanner(string root) { // Create the scanner. Scanner scanner = new Scanner(root); // Scan for files. string[] files = scanner.Scan(); // No matching files. if (files.Length == 0) { Log.Warning("No matching files discovered."); Environment.Exit(0); } // Ensure output directory exists, otherwise create it. if (!Directory.Exists(this.options.Output)) { Directory.CreateDirectory(this.options.Output); Log.Verbose("Created output directory."); } // Create a new project instance. Project project = new Project(); // Process files. foreach (string file in files) { // Inform the user that of the file being processed. Log.Compose($"Processing {file} ..."); // TODO: Process output file path if possible. // Process file and obtain the resulting module. Ion.CodeGeneration.Module module = this.processor.ProcessFile(file); // Append the module to the project. project.Modules.Add(module); } // Inform the user that the operation completed successfully. Log.Verbose($"Processed {files.Length} file(s)."); // Return the project. return(project); }