Hold the LLVMContext by reference rather than by pointer.
[oota-llvm.git] / tools / lto / lto.cpp
index f60f7b5ac0943e84fea03743a9f0db736ce5d62b..02034bbf84660abfd4f8d883c901411bc772b729 100644 (file)
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm-c/lto.h"
+#include "llvm-c/Core.h"
 
 #include "LTOModule.h"
 #include "LTOCodeGenerator.h"
@@ -85,9 +86,10 @@ bool lto_module_is_object_file_in_memory_for_target(const void* mem,
 // loads an object file from disk  
 // returns NULL on error (check lto_get_error_message() for details)
 //
-lto_module_t lto_module_create(const char* path)
+lto_module_t lto_module_create(const char* path, LLVMContextRef Ctxt)
 {
-     return LTOModule::makeLTOModule(path, sLastErrorString);
+     return LTOModule::makeLTOModule(path, *llvm::unwrap(Ctxt), 
+                                     sLastErrorString);
 }
 
 
@@ -95,9 +97,11 @@ lto_module_t lto_module_create(const char* path)
 // loads an object file from memory 
 // returns NULL on error (check lto_get_error_message() for details)
 //
-lto_module_t lto_module_create_from_memory(const void* mem, size_t length)
+lto_module_t lto_module_create_from_memory(const void* mem, size_t length,
+                                           LLVMContextRef Ctxt)
 {
-     return LTOModule::makeLTOModule(mem, length, sLastErrorString);
+     return LTOModule::makeLTOModule(mem, length, *llvm::unwrap(Ctxt),
+                                     sLastErrorString);
 }
 
 
@@ -154,9 +158,9 @@ lto_symbol_attributes lto_module_get_symbol_attribute(lto_module_t mod,
 // instantiates a code generator
 // returns NULL if there is an error
 //
-lto_code_gen_t lto_codegen_create()
+lto_code_gen_t lto_codegen_create(LLVMContextRef ContextRef)
 {
-     return new LTOCodeGenerator();
+     return new LTOCodeGenerator(*llvm::unwrap(ContextRef));
 }
 
 
@@ -198,7 +202,23 @@ bool lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model debug)
 //
 bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model)
 {
-    return cg->setCodePICModel(model, sLastErrorString);
+  return cg->setCodePICModel(model, sLastErrorString);
+}
+
+//
+// sets the path to gcc
+//
+void lto_codegen_set_gcc_path(lto_code_gen_t cg, const char* path)
+{
+  cg->setGccPath(path);
+}
+
+//
+// sets the path to the assembler tool
+//
+void lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path)
+{
+    cg->setAssemblerPath(path);
 }
 
 //
@@ -208,7 +228,7 @@ bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model)
 //
 void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol)
 {
-    cg->addMustPreserveSymbol(symbol);
+  cg->addMustPreserveSymbol(symbol);
 }
 
 
@@ -219,7 +239,7 @@ void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol)
 //
 bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path)
 {
-   return cg->writeMergedModules(path, sLastErrorString);
+  return cg->writeMergedModules(path, sLastErrorString);
 }
 
 
@@ -234,8 +254,15 @@ bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path)
 extern const void*
 lto_codegen_compile(lto_code_gen_t cg, size_t* length)
 {
-    return cg->compile(length, sLastErrorString);
+  return cg->compile(length, sLastErrorString);
 }
 
 
-
+//
+// Used to pass extra options to the code generator
+//
+extern void
+lto_codegen_debug_options(lto_code_gen_t cg, const char * opt)
+{
+  cg->setCodeGenDebugOptions(opt);
+}
\ No newline at end of file