Skip to content

Instantly share code, notes, and snippets.

@SimeonEhrig
Last active June 8, 2022 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimeonEhrig/92689b6a5745d7a7013777e61c0a3f6a to your computer and use it in GitHub Desktop.
Save SimeonEhrig/92689b6a5745d7a7013777e61c0a3f6a to your computer and use it in GitHub Desktop.
C++ code to view LLVM IR code of a statement in cling
#include "cling/Interpreter/Interpreter.h"
#include "cling/Interpreter/Transaction.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/raw_ostream.h"
auto T1 = gCling->getLatestTransaction();
// command
T1->getNext()->dumpPretty();
T1->getNext()->getModule()->print(llvm::outs(), nullptr);
@SimeonEhrig
Copy link
Author

Since the LLVM 13 update (version 1.0), the code needs a change:

#include "cling/Interpreter/Interpreter.h"
#include "cling/Interpreter/Transaction.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/raw_ostream.h"

auto T1 = gCling->getLatestTransaction();
// command
T1->getNext()->dumpPretty();
T1->getNext()->getCompiledModule()->print(llvm::outs(), nullptr);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment