Skip to content

Commit

Permalink
Update_clang_version
Browse files Browse the repository at this point in the history
  • Loading branch information
anutosh491 committed Nov 9, 2023
1 parent e17a10a commit 6eeef54
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mamba install`xeus-cpp` notebook -c conda-forge
Or you can install it from the sources, you will first need to install dependencies

```bash
mamba install cmake cxx-compiler xeus-zmq nlohmann_json cppzmq xtl jupyterlab clangdev=16 cpp-argparse pugixml -c conda-forge
mamba install cmake cxx-compiler xeus-zmq nlohmann_json cppzmq xtl jupyterlab clangdev=17 cpp-argparse pugixml -c conda-forge
```

Then you can compile the sources (replace `$CONDA_PREFIX` with a custom installation
Expand Down
2 changes: 1 addition & 1 deletion docs/InstallationAndUsage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ You will first need to install dependencies.
.. code-block:: bash
mamba install cmake cxx-compiler xeus-zmq nlohmann_json cppzmq xtl jupyterlab
clangdev=16 cpp-argparse pugixml -c conda-forge
clangdev=17 cpp-argparse pugixml -c conda-forge
**Note:** Use a mamba environment with python version >= 3.11 for fetching clang-versions.
Expand Down
2 changes: 1 addition & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- nlohmann_json
- cppzmq
- xtl
- clangdev >=16,<17
- clangdev >=17,<18
- pugixml
- cpp-argparse
- zlib
Expand Down
31 changes: 20 additions & 11 deletions src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ create_interpreter(const Args& ExtraArgs = {}, clang::DiagnosticConsumer* Client

Args ClangArgs = {"-Xclang", "-emit-llvm-only", "-Xclang", "-diagnostic-log-file", "-Xclang", "-", "-xc++"};
ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end());
auto CI = cantFail(clang::IncrementalCompilerBuilder::create(ClangArgs));
clang::IncrementalCompilerBuilder builder;
builder.SetCompilerArgs(ClangArgs);
auto CI = cantFail(builder.CreateCpp());
if (Client)
{
CI->getDiagnostics().setClient(Client, /*ShouldOwnClient=*/false);
Expand All @@ -139,7 +141,7 @@ create_interpreter(const Args& ExtraArgs = {}, clang::DiagnosticConsumer* Client
}

static void
inject_symbol(llvm::StringRef LinkerMangledName, llvm::JITTargetAddress KnownAddr, clang::Interpreter& Interp)
inject_symbol(llvm::StringRef LinkerMangledName, llvm::orc::ExecutorAddr KnownAddr, clang::Interpreter& Interp)
{
using namespace llvm;
using namespace llvm::orc;
Expand All @@ -153,7 +155,7 @@ inject_symbol(llvm::StringRef LinkerMangledName, llvm::JITTargetAddress KnownAdd
}

// Nothing to define, we are redefining the same function. FIXME: Diagnose.
if (*Symbol && (JITTargetAddress) *Symbol == KnownAddr)
if (*Symbol && (ExecutorAddr) *Symbol == KnownAddr)
{
return;
}
Expand All @@ -163,12 +165,19 @@ inject_symbol(llvm::StringRef LinkerMangledName, llvm::JITTargetAddress KnownAdd
SymbolMap::iterator It;
static llvm::orc::SymbolMap m_InjectedSymbols;

llvm::orc::LLJIT* Jit = const_cast<llvm::orc::LLJIT*>(Interp.getExecutionEngine());
JITDylib& DyLib = Jit->getMainJITDylib();
auto JitOrError = Interp.getExecutionEngine();

if (Error Err = JitOrError.takeError())
{
logAllUnhandledErrors(std::move(Err), errs(), "[IncrementalJIT] define() failed2: ");
return;
}

llvm::orc::LLJIT &Jit = *JitOrError;
llvm::orc::JITDylib &DyLib = Jit.getMainJITDylib();
std::tie(It, Inserted) = m_InjectedSymbols.try_emplace(
Jit->getExecutionSession().intern(LinkerMangledName),
JITEvaluatedSymbol(KnownAddr, JITSymbolFlags::Exported)
Jit.getExecutionSession().intern(LinkerMangledName),
ExecutorSymbolDef(KnownAddr, JITSymbolFlags::Exported)
);
assert(Inserted && "Why wasn't this found in the initial Jit lookup?");

Expand All @@ -178,14 +187,14 @@ inject_symbol(llvm::StringRef LinkerMangledName, llvm::JITTargetAddress KnownAdd
// The symbol be in the DyLib or in-process.
if (auto Err = DyLib.remove({It->first}))
{
logAllUnhandledErrors(std::move(Err), errs(), "[IncrementalJIT] define() failed2: ");
logAllUnhandledErrors(std::move(Err), errs(), "[IncrementalJIT] define() failed3: ");
return;
}
}

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

Expand Down Expand Up @@ -559,8 +568,8 @@ namespace xcpp

// Inject versions of printf and fprintf that output to std::cout
// and std::cerr (see implementation above).
inject_symbol("printf", llvm::pointerToJITTargetAddress(printf_jit), *m_interpreter);
inject_symbol("fprintf", llvm::pointerToJITTargetAddress(fprintf_jit), *m_interpreter);
inject_symbol("printf", llvm::orc::ExecutorAddr::fromPtr(printf_jit), *m_interpreter);
inject_symbol("fprintf", llvm::orc::ExecutorAddr::fromPtr(fprintf_jit), *m_interpreter);
}

void interpreter::restore_output()
Expand Down

0 comments on commit 6eeef54

Please sign in to comment.