Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "llvm/LLVMContext.h"
- #include "llvm/Module.h"
- #include "llvm/ModuleProvider.h"
- #include "llvm/Type.h"
- #include "llvm/Bitcode/ReaderWriter.h"
- #include "llvm/CodeGen/LinkAllCodegenComponents.h"
- #include "llvm/ExecutionEngine/GenericValue.h"
- #include "llvm/ExecutionEngine/Interpreter.h"
- #include "llvm/ExecutionEngine/JIT.h"
- #include "llvm/ExecutionEngine/JITEventListener.h"
- #include "llvm/Support/CommandLine.h"
- #include "llvm/Support/ManagedStatic.h"
- #include "llvm/Support/MemoryBuffer.h"
- #include "llvm/Support/PluginLoader.h"
- #include "llvm/Support/PrettyStackTrace.h"
- #include "llvm/System/Process.h"
- #include "llvm/System/Signals.h"
- #include "llvm/Target/TargetSelect.h"
- #include "llvm/Linker.h"
- #include "llvm/Analysis/Verifier.h"
- #include "llvm/Bitcode/ReaderWriter.h"
- #include "llvm/Support/CommandLine.h"
- #include "llvm/Support/ManagedStatic.h"
- #include "llvm/Support/MemoryBuffer.h"
- #include "llvm/Support/PrettyStackTrace.h"
- #include "llvm/System/Signals.h"
- #include "llvm/System/Path.h"
- #include <stdio.h>
- #include <string>
- using namespace llvm;
- using namespace std;
- static inline Module* LoadFile(const std::string &FN,
- LLVMContext& Context) {
- Module* Result = 0;
- string ErrorMessage;
- if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(FN,
- &ErrorMessage)) {
- Result = ParseBitcodeFile(Buffer, Context, &ErrorMessage);
- delete Buffer;
- }
- if (Result) return Result; // Load successful!
- else {
- errs() << "Bitcode file: '" << FN.c_str() << "' does not exist.\n";
- }
- return NULL;
- }
- int main(int argc, char **argv, char * const *envp) {
- InitializeNativeTarget();
- LLVMContext &Context = getGlobalContext();
- Module *print1(LoadFile("print1.o", Context));
- Module *print2(LoadFile("print2.o", Context));
- Module *main_file(LoadFile("main_file.o", Context));
- Function *func, *print1f, *print2f;
- print2f = print2->getFunction ("print");
- print2f->setName ("test_name");
- Linker::LinkModules(main_file, print1, NULL);
- Linker::LinkModules(main_file, print2, NULL);
- ExecutionEngine *EE = EngineBuilder(main_file).create();
- EE->runStaticConstructorsDestructors(false);
- func = EE->FindFunctionNamed ("do_print");
- EE->runFunction(func, std::vector<GenericValue> ());
- print1f = main_file->getFunction ("print");
- print2f = main_file->getFunction ("test_name");
- print1f->replaceAllUsesWith (print2f);
- EE->runFunction(func, std::vector<GenericValue> ());
- EE->runStaticConstructorsDestructors(true);
- }
Add Comment
Please, Sign In to add comment