WHIRL Gen 核心邏輯(Spin 2 whirl)
(就是獲取spin的每個node)
gs_t 就是 spin的單個AST node
使用gs_operand(list,0)獲取當前node的is_t,
使用 list = gs_operand(list,1)獲取下一個node
獲取node之后使用 WGEN_Expand_Top_Level_Decl (gs_t decl) 來展開莫個gs_t()
之后就是各種調用WGEN_Expand_Decl ,包括遞歸調用
中間可能出現:
——— ? Function ? ———?
WGEN_Expand_Function_Body
WGEN_Start_Function
WGEN_Handle_Named_Return_Value
Mark_Scopes_And_Labels
WGEN_Expand_Stmt
WGEN_Finish_Function
Pop_Current_Function_Decl
Push_Current_Function_Decl
—— ?Whirl ?———?
WGEN_Whirlify_Decl
WGEN_Initialize_Decl
——— ?Thunk ?———?
WGEN_Adjust_Thunk
WGEN_Generate_Thunk ?— For adjusting return or this pointer.
——— ?Symtab ———?
WN_st_idx()
ST_st_idx(const char *) ?string -> str_id / saving ?function name to symtab?
——— ?WN ———?
WN_Set_Call_Default_Flags
WN_Set_Call_Replace_By_Jump
WN_Ldid
WN_CreateParm(Mtype_comparison (arg_mtype), arg_wn,
? ? ? ? ? ? ? ? ? ? ? ? ? ?arg_ty, WN_PARM_BY_VALUE);
WN_kid = *** ? Set kid of WN
WN_Create (OPR_CALL, ret_mtype, MTYPE_V, nargs)
WN_st
WN_CreateReturn
WN_Stid
—— ? Statement. ———?
WGEN_Stmt_Append(wn, getsrcpos())
Mark_Scopes_And_Labels()
WGEN_Expand_Stmt
WGEN_GetLABEL
WGEN_Assembly_Alias
BT實測結果
frame #0: 0x0000000100070282 wgen`::WGEN_Expand_Decl(decl=0x0000000101800580, can_skip=YES) at wgen_decl.cxx:709
?frame #1: 0x000000010007b5dd wgen`::WGEN_Expand_Top_Level_Decl(top_level_decl=0x0000000101800580) at wgen_decl.cxx:5208
? ? frame #2: 0x0000000100002555 wgen`main(argc=3, argv=0x00007fff5fbffa88, envp=0x00007fff5fbffaa8) at main.c:362