19.01.2015 Views

Build Programming Language Runtime with LLVM

Build Programming Language Runtime with LLVM

Build Programming Language Runtime with LLVM

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

#include <br />

int main(int argc, char *argv[])<br />

{<br />

printf("Hello world!\n");<br />

return 0;<br />

}<br />

函 式 printf() 後 方 僅 有 一 個<br />

字 串 參 數 , 前 端 預 設 將 其<br />

轉 換 為 puts() puts()<br />

• 反 組 譯 BitCode<br />

$ llvm­dis < hello.bc<br />

; ModuleID = ''<br />

target datalayout = "e­p:32:32:32­...<br />

target triple = "i386­pc­linux­gnu"<br />

@str = internal constant [13 x i8] c"Hello world!\00"<br />

define i32 @main(i32 %argc, i8** nocapture %argv) nounwind {<br />

entry:<br />

%puts = tail call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @str, i32 0, i32 0))<br />

ret i32 0<br />

}<br />

Declare i32 @puts(i8* nocapture) nounwind<br />

• 輸 出 x86 後 端 組 合 語 言<br />

$ llc hello.bc ­o hello.s

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!