Exemplo 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);
                }
            }
Exemplo n.º 2
0
 public int WriteBitcodeToFile(string path) => _module.WriteBitcodeToFile(path);