LLVM_2015

LLVM_2015

# LLVM銈ゃ兂銈广儓銉笺儷鏂规硶

1
2
3
4
5
6
 $ git clone http://llvm.org/git/llvm.git
 $ cd llvm
 $ mkdir build && cd build
 $ (銈ゃ兂銈广儓銉笺儷鍫存墍)/configure --prefix=$PWD --disable-optimized --enable-debug-runtime\
 $ --enable-debug-symbols --enable-assertions 
 $ make -j2 (j銇甫鍒椼佸け鏁椼仐銇熴倝make銇)

# brew銇с伄銈ゃ兂銈广儓銉笺儷鏂规硶锛堣銇夸細鐢╩ini鐗堬級

  • brew銇屽叆銇c仸銇勩仾銇戙倢銇癰rew銈掋偆銉炽偣銉堛兗銉
1
 $ brew install ie-developers/ie/llvm_original`

# hello.c銈掍綔鎴

1
 $ vim hello.c
  • 銈姐兗銈广偝銉笺儔1
1
2
3
4
int main (){
 puts ("Hello , World");
 return 0;
}
  • 銈姐兗銈广偝銉笺儔2
1
2
3
int main(int ac , char *av[]){
  return 55+ac;
}

# lldb銈掕捣鍕

1
 $ lldb -- (銈ゃ兂銈广儓銉笺儷銇椼仧鍫存墍)/Debug+Asserts/bin/clang -cc1 -S hello.c

# ldb銇埄鐢ㄦ柟娉

  • 銉栥儸銈ゃ偗銉濄偆銉炽儓銈掓寚瀹
1
(lldb) b (琛屾暟銆併伨銇熴伅闁㈡暟鍚嶃倓澶夋暟鍚嶃仾銇)
  • 瀹熻
1
(lldb) r
  • 琛屻倰琛ㄧず
1
(lldb) l
  • 闁㈡暟銇叆銈嬨侀枹鏁般亴銇亼銈屻伆娆°伄鍑︾悊銇
1
(lldb) s
  • 娆°伄銉栥儸銈ゃ偗銉濄偆銉炽儓銇俱仹绉诲嫊
1
(lldb) c
  • 娆°伄琛屻伕(闁㈡暟銇屻亗銇c仸銈傜劇瑕栥仌銈屻倠)
1
(lldb) n
  • step鏅傘伀up銇欍倠銇╯tep銇欍倠鍓嶃伀鎴汇倢銈
1
(lldb) up
  • up銇
1
(lldb) down
  • 銇┿亾銇殠灞ゃ伀鏉ャ仸銇勩倠銇亱銈掔⒑瑾
1
(lldb) bt
  • 澶夋暟銇腑韬倰琛ㄧず
1
(lldb) p
  • 闁㈡暟銇祩浜
1
(lldb) fin
  • lldb銇祩浜
1
(lldb) q

1.銇仒銈併伀consumetoken銇儢銉偆銈儩銈ゃ兂銉堛倰缃亸(鏂囧瓧銇垏銈岀洰銈掓帰銇) cosumetoken銇цВ鏋愩仚銈

1
 (lldb) b ConsumeToken

FormTokenWithChars(Token &Result, const char *TokEnd,

12/11———————–

# 2鏃ョ洰

  • Parser.h
1
CodeGenAction鈫掋偝銉笺儔鐢熸垚锛嶪R銇嬮氬父銇儠銈°偆銉亱銇у銈忋倠
  • ConsumeToken
1
2
3
isTokenSpecial鈫掓枃瀛椼仾銇亱锛岃鍙枫仾銇亱銇┿亞銇
int銇ㄣ亱銈兗銉兗銉夈倰鍒ゆ柇
Tok銇甂ind銇偔銉笺儻銉笺儔銇ó椤炪亴鍏ャ仯銇︺亜銈
  • Lexer
1
2
3
4
瀛楀彞瑙f瀽锛
   锛戞枃瀛椼仴銇よ銈撱仹銇勩亸锛
FormTokenWithChars
   Token銇暦銇曪紝鍫存墍锛岀ó椤炪倰Lex(銇甊esult)銇牸绱嶃仐銇︺亰銇
  • ParserFunctionDeclarator
1
Declarator銇瑷?
  • PaserExpression
1
2
3
+銇仼銇▓绠楀紡銇岀従銈屻仧銈夎▓绠椼伄鍎厛闋嗕綅銇悎銈忋仜銇﹁▓绠椼仚銈
Prec銇屽劒鍏堥爢浣嶃倰琛ㄣ仚
   PaeseCastExpression
1
2
ActOnIdExpression
   澶夋暟銇剰鍛(涓韩)銈掕銇广倠
  • PaseCastExpression
1
2
3
cast-expression, unary-expression, postfix-expression, primary-expression銈掓搷浣溿仚銈
銇濄倢銇炪倢銇ó椤炪伀蹇溿仒銇﹀嚘鐞嗐倰澶夈亪銈
II銇獻dentifier Info銇屻亗銈
  • Validator
  • ActOnIdExpression
1
2
3
LookUpResult
  澶夋暟銇屼綍銇嬨倰瑾裤伖銈嬶紟浣曞害銈傛渶閬╁寲銇岃銈忋倢銇︺亜銈嬶紟
      SemaLookUp
  • ActOnNumericConstant
  • getLanOpts
  • ActOnIdExpression
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy