Pages

Tuesday 6 May 2014

get bitcode(.bc) from source in llvm/clang

get bytecode from C++ program. 
test.cpp

int main()
{
  const int count = 3;
  const int value = 5;

  int result = count + value;

  return 0;
}


get bytecode.

clang++ -c -emit-llvm test.cpp -o testbyte.bc -S


read bytecode file (testbyte.bc).

vim testbyte.bc


testbyte.bc
.
.
.
; Function Attrs: nounwind uwtable
define i32 @main() #0 {
entry:
  %retval = alloca i32, align 4
  %count = alloca i32, align 4
  %value = alloca i32, align 4
  %result = alloca i32, align 4
  store i32 0, i32* %retval
  store i32 3, i32* %count, align 4
  store i32 5, i32* %value, align 4
  store i32 8, i32* %result, align 4
  ret i32 0
}
.
.
.

No comments:

Post a Comment