Skip to content

Commit

Permalink
Rewire the printf symbols in the Jit
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvassilev committed Aug 12, 2023
1 parent c2965a0 commit 19725f5
Showing 1 changed file with 2 additions and 55 deletions.
57 changes: 2 additions & 55 deletions src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,52 +365,6 @@ static int fprintf_jit(std::FILE *stream, const char *format, ...) {

return ret;
}
// static void injectSymbol(llvm::StringRef LinkerMangledName,
// llvm::JITTargetAddress KnownAddr,
// clang::Interpreter &Interp) {
// using namespace llvm;
// using namespace llvm::orc;

// auto Symbol =
// Interp.getSymbolAddress(LinkerMangledName); //, /*IncludeFromHost=*/true);
// if (Error Err = Symbol.takeError()) {
// logAllUnhandledErrors(std::move(Err), errs(),
// "[IncrementalJIT] define() failed1: ");
// return;
// }

// // Nothing to define, we are redefining the same function. FIXME: Diagnose.
// // if (*Symbol && (JITTargetAddress)*Symbol == KnownAddr)
// if (*Symbol && (*Symbol).getValue() == KnownAddr)
// return;

// // Let's inject it
// bool Inserted;
// SymbolMap::iterator It;
// static llvm::orc::SymbolMap m_InjectedSymbols;

// llvm::orc::LLJIT &Jit = *Interp.getExecutionEngine();
// JITDylib &DyLib = Jit.getMainJITDylib();

// std::tie(It, Inserted) = m_InjectedSymbols.try_emplace(
// Jit.getExecutionSession().intern(LinkerMangledName),
// JITEvaluatedSymbol(KnownAddr, JITSymbolFlags::Exported));
// assert(Inserted && "Why wasn't this found in the initial Jit lookup?");

// // We want to replace a symbol with a custom provided one.
// if (Symbol && KnownAddr) {
// // The symbol be in the DyLib or in-process.
// if (auto Err = DyLib.remove({It->first})) {
// logAllUnhandledErrors(std::move(Err), errs(),
// "[IncrementalJIT] define() failed2: ");
// return;
// }
// }

// if (Error Err = DyLib.define(absoluteSymbols({*It})))
// logAllUnhandledErrors(std::move(Err), errs(),
// "[IncrementalJIT] define() failed3: ");
// }

void interpreter::redirect_output() {
p_cout_strbuf = std::cout.rdbuf();
Expand All @@ -419,15 +373,8 @@ void interpreter::redirect_output() {
std::cout.rdbuf(&m_cout_buffer);
std::cerr.rdbuf(&m_cerr_buffer);

// Inject versions of printf and fprintf that output to std::cout
// and std::cerr (see implementation above).
// FIXME: Move this facility to CppInterOp.
// injectSymbol("printf", llvm::pointerToJITTargetAddress(printf_jit),
// m_interpreter);
// injectSymbol("fprintf", llvm::pointerToJITTargetAddress(fprintf_jit),
// m_interpreter);
// llvm::sys::DynamicLibrary::AddSymbol("printf", (void*) &printf_jit);
// llvm::sys::DynamicLibrary::AddSymbol("fprintf", (void*) &fprintf_jit);
Cpp::InsertOrReplaceJitSymbol("printf", (uint64_t) &printf_jit);
Cpp::InsertOrReplaceJitSymbol("fprintf", (uint64_t) &fprintf_jit);
}

void interpreter::restore_output() {
Expand Down

0 comments on commit 19725f5

Please sign in to comment.