Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, to fix an obvious misunderstanding: LLVM is a framework for manipulating code in IR format. There are no ASTs in sight (*) - you read IR, transform/manipulate/analyze it, and you write IR back.</p> <p>Reading IR is really simple:</p> <pre><code>int main(int argc, char** argv) { if (argc &lt; 2) { errs() &lt;&lt; "Expected an argument - IR file name\n"; exit(1); } LLVMContext &amp;Context = getGlobalContext(); SMDiagnostic Err; Module *Mod = ParseIRFile(argv[1], Err, Context); if (!Mod) { Err.print(argv[0], errs()); return 1; } [...] } </code></pre> <p>This code accepts a file name. This should be an LLVM IR file (textual). It then goes on to parse it into a <code>Module</code>, which represents a module of IR in LLVM's internal in-memory format. This can then be manipulated with the various passes LLVM has or you add on your own. Take a look at some examples in the LLVM code base (such as <code>lib/Transforms/Hello/Hello.cpp</code>) and read this - <a href="http://llvm.org/docs/WritingAnLLVMPass.html" rel="nofollow noreferrer">http://llvm.org/docs/WritingAnLLVMPass.html</a>.</p> <p>Spitting IR back into a file is even easier. The <code>Module</code> class just writes itself to a stream:</p> <pre><code> some_stream &lt;&lt; *Mod; </code></pre> <p>That's it.</p> <p>Now, if you have any <em>specific</em> questions about <em>specific</em> modifications you want to do to IR code, you should really ask something more focused. I hope this answer shows you how to parse IR and write it back.</p> <hr> <p>(*) <sub>IR doesn't have an AST representation inside LLVM, because it's a simple assembly-like language. If you go one step up, to C or C++, you can use Clang to parse that into ASTs, and then do manipulations at the AST level. Clang then knows how to produce LLVM IR from its AST. However, you do have to start with C/C++ here, and not LLVM IR. If LLVM IR is all you care about, forget about ASTs.</sub></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload