Esempio n. 1
0
            /// writes the bytecode to a file, calls clang on it and deletes the bytecode file
            static void writeFile(LLVMModuleRef module, int optimizazioneLevel, string bitcode, string output, bool onlyBitcode, string optionalFlag)
            {
                // deletes a possible file named in the same way as the result, to avoid bugs in the while under
                if (File.Exists(bitcode))
                {
                    File.Delete(bitcode);
                }

                // writes the module to a file
                if (module.WriteBitcodeToFile(bitcode) != 0)
                {
                    CompilationErrors.Throw("Error writing to file");
                }

                if (onlyBitcode)
                {
                    return;
                }

                // the program goes in this keeps the program waiting until it finds the file containing the compiled program
                while (!File.Exists(bitcode))
                {
                    nothing();
                }

                // clang compiler
                CallClang($"{bitcode} -o {output} {optionalFlag}", optimizazioneLevel);

                // deletes the bytecode file, now remains only the executable generated by clang
                if (File.Exists(bitcode))
                {
                    File.Delete(bitcode);
                }
            }
Esempio n. 2
0
        public CompilationUnit(string path, bool isMainModule, bool throwerror)
        {
            if (!File.Exists(path))
            {
                if (throwerror)
                {
                    CompilationErrors.Throw($"Unable to open path: `{path}`");
                }

                FailedOpeningPath = true;
            }
            else
            {
                IRGenerator = new(path, File.ReadAllText(path), isMainModule);
            }
        }