title: Parse LLVM IR Code
body: <p>I'm following the link <a href="https://stackoverflow.com/questions/9167347/parsing-and-modifying-llvm-ir-code">Parsing and Modifying LLVM IR code</a> to read in IR file and trying to parse it. But I found no matter what input file I wrote in argument(.ll or .bc), it just won't parse file and save it into the variable.</p>
  
  <p>Here's my code,</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "llvm/LLVMContext.h"
  #include "llvm/Module.h"
  #include "llvm/Function.h"
  #include "llvm/Support/CFG.h"
  #include "llvm/Support/IRReader.h"
  #include "llvm/Support/SourceMgr.h"
  #include "llvm/Support/raw_ostream.h"
  
  using namespace llvm;
  
  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) {
          std::cout &lt;&lt; "Mod is not null" &lt;&lt; std::endl;
      }
      else {
          std::cout &lt;&lt; "Mod is null" &lt;&lt; std::endl;
      }
      return 0;
  }
  </code></pre>
  
  <p>By running this code with either ll or bc file it always shows Mod is null.</p>
  
  <p>Can someone give me some hints on how to reslove this issue?</p>
  
  <p>Here is my IR code</p>
  
  <pre><code>; ModuleID = 'bubble.bc'
  target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
  target triple = "x86_64-apple-macosx10.9.0"
  
  @Sort = global [8 x i32] [i32 1, i32 4, i32 2, i32 5, i32 7, i32 3, i32 6, i32 3],  align 16
  @.str = private unnamed_addr constant [4 x i8] c"%d \00", align 1
  @.str1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
  
  ; Function Attrs: nounwind ssp uwtable
  define void @bubble() #0 {
    %tmp = alloca i32, align 4
    %i = alloca i32, align 4
    %j = alloca i32, align 4
    store i32 0, i32* %i, align 4
    br label %1
  
  ; &lt;label&gt;:1                                       ; preds = %41, %0
    %2 = load i32* %i, align 4
    %3 = icmp slt i32 %2, 8
    br i1 %3, label %4, label %44
  
  ; &lt;label&gt;:4                                       ; preds = %1
    %5 = load i32* %i, align 4
    %6 = add nsw i32 %5, 1
    store i32 %6, i32* %j, align 4
    br label %7
  
  ; &lt;label&gt;:7                                       ; preds = %37, %4
    %8 = load i32* %j, align 4
    %9 = icmp slt i32 %8, 8
    br i1 %9, label %10, label %40
  
  ; &lt;label&gt;:10                                      ; preds = %7
    %11 = load i32* %i, align 4
    %12 = sext i32 %11 to i64
    %13 = getelementptr inbounds [8 x i32]* @Sort, i32 0, i64 %12
    %14 = load i32* %13, align 4
    %15 = load i32* %j, align 4
    %16 = sext i32 %15 to i64
    %17 = getelementptr inbounds [8 x i32]* @Sort, i32 0, i64 %16
    %18 = load i32* %17, align 4
    %19 = icmp sge i32 %14, %18
    br i1 %19, label %20, label %36
  
  //some similar stuff
  
  !0 = metadata !{metadata !"Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)"}
  </code></pre>
  
  <p>Error meg is ./IRparser: /home/mingaoIrparser/testcase/bubble.ll:10:23: error: expected '{' in function body
  define void @bubble() #0 {
                        ^</p>
  
  <p>One more thing is that this IR is compiled from LLVM3.4 the library I'm using is 2.9 for now. Will it matter?</p>