+//===----------------------------------------------------------------------===//
+/// LTOCodeGenerator - C++ class which implements the opaque lto_code_gen_t
+/// type.
+///
+struct LTOCodeGenerator {
+ static const char *getVersionString();
+
+ LTOCodeGenerator();
+ ~LTOCodeGenerator();
+
+ // Merge given module, return true on success.
+ bool addModule(struct LTOModule*, std::string &errMsg);
+
+ void setDebugInfo(lto_debug_model);
+ void setCodePICModel(lto_codegen_model);
+
+ void setCpu(const char* mCpu) { _mCpu = mCpu; }
+
+ void addMustPreserveSymbol(const char* sym) {
+ _mustPreserveSymbols[sym] = 1;
+ }
+
+ // To pass options to the driver and optimization passes. These options are
+ // not necessarily for debugging purpose (The function name is misleading).
+ // This function should be called before LTOCodeGenerator::compilexxx(),
+ // and LTOCodeGenerator::writeMergedModules().
+ //
+ void setCodeGenDebugOptions(const char *opts);
+
+ // Write the merged module to the file specified by the given path.
+ // Return true on success.
+ bool writeMergedModules(const char *path, std::string &errMsg);
+
+ // Compile the merged module into a *single* object file; the path to object
+ // file is returned to the caller via argument "name". Return true on
+ // success.
+ //
+ // NOTE that it is up to the linker to remove the intermediate object file.
+ // Do not try to remove the object file in LTOCodeGenerator's destructor
+ // as we don't who (LTOCodeGenerator or the obj file) will last longer.
+ //
+ bool compile_to_file(const char **name, std::string &errMsg);
+
+ // As with compile_to_file(), this function compiles the merged module into
+ // single object file. Instead of returning the object-file-path to the caller
+ // (linker), it brings the object to a buffer, and return the buffer to the
+ // caller. This function should delete intermediate object file once its content
+ // is brought to memory. Return NULL is the compilation was not successful.
+ //
+ const void *compile(size_t *length, std::string &errMsg);
+
+ // Return the paths of the intermediate files that linker needs to delete
+ // before it exits. The paths are delimited by a single '\0', and the last
+ // path is ended by double '\0's. The file could be a directory. In that
+ // case, the entire directory should be erased recusively. This function
+ // must be called after the compilexxx() is successfuly called, because
+ // only after that moment, compiler is aware which files need to be removed.
+ // If calling compilexxx() is not successful, it is up to compiler to clean
+ // up all the intermediate files generated during the compilation process.
+ //
+ const char *getFilesNeedToRemove();