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