annotate CbC-implemantation.ja @ 88:f214c1d5b862

merge 89
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 20 Dec 2011 18:53:46 +0900
parents e62c90c8e699
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1
29
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 GCC への CbC コンパイル機能の実装について
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
32
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
5
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
6 ___________________________________________________________
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
7 Code Segmentの実装
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
8 -----------------------------------------------------------
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
9
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
10 Code SegmentをC言語に組み込む。
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
11 コンパイラとしては単なるvoidの関数として扱い、parse treeにcode
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
12 segmentであることのフラグを追加する。
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
13
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
14 * 予約語''__code``の追加
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
15 c-common.cで定義されているc_common_reswords配列に追加
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
16 { "__code", RID_CbC_CODE, 0} # D_CONLYも入れるか?
29
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
32
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
18 * treeの生成関数
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
19 関数の型を表すtreeはbuild_funciton_type関数で生成されるが、code
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
20 segmentではこれを使えない。build_function_typeはhash管理でまったく同
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
21 じ引数型、返り値型を持つものは同じオブジェクトを使うから。
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
22 なのでbuild_code_segment_typeでこの代わりを行う。
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
23 # 本当はbuild_function_typeのhashにcbcフラグも含める方がいいかもし
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
24 # れない。
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
25 この関数は主にgrokdeclaratorから呼ばれる
29
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
32
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
27 * cbc_set_codesegment関数
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
28 Undocumented.
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
29 でも今は意味なかったような…
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
30
29
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
32
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
33 ___________________________________________________________
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
34 goto文の実装
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
35 -----------------------------------------------------------
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
36
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
37 CbCについて重要な構文''goto cs(a, b, c);``を実装する。
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
38 c-parser.c内の c_parser_statement_after_labels()関数における巨大なスイ
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
39 ッチ文のcase RID_GOTOのコードを修正する。
29
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
32
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
41 * アイデア
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
42 全てのgoto文を単なる関数呼び出しとその後のリターン文と解釈することで
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
43 tail callを可能にする。
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
44 次のgoto文は
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
45 goto cs(a);
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
46 このparse treeでもこの様に解釈される
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
47 cs(a);
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
48 return;
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
49
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
50 * Parser側での修正
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
51
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
52 オリジナルC言語のパース方法
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
53 1. gotoに続くトークンがCPP_NAME
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
54 通常のgoto文として処理
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
55 2. gotoに続くトークンが'*`
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
56 computed gotoとして処理
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
57 see "GCC Manual" Sec 6.3. (not internals Manual)
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
58 これを以下の様に変更する
29
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59
32
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
60 CbCでのパース方法
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
61 1. gotoに続くトークンがCPP_NAME && CPP_NAMEに次ぐトークンが';`
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
62 通常のgoto文として処理
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
63 2. gotoに続くトークンが'*`
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
64 computed gotoとして処理
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
65 3. それ以外
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
66 CbCのgotoとして処理
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
67
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
68 処理内容
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
69 1. gotoトークンに続く文を関数呼び出しとみて
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
70 c_parser_expr_no_commas()関数を使ってパース、treeを取得
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
71 # これで(*csp)(a)などにも対応できる
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
72 2. 取得したtreeがCALL_EXPRでなければエラー
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
73 3. treeにCbC_GOTOのフラグを立てる
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
74 4. treeにTAILCALLのフラグを立てる
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
75 5. add_stmt
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
76 6. return文のtreeを生成
29
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77
32
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
78 * RTL expansion
29
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79
32
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
80 通常のCALL_EXPRを解析するexpand_callを一部修正する。この関数の途中か
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
81 らでexpand_cbc_goto関数に切り替えてRTLの生成はそこで全てを請け負う。
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
82 本来expand_callではtreeにsibcallフラグが立っていても、生成の過程で不
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
83 可能と検知するとsibcallを中断して通常のcallになるが、cbc_expand_call
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
84 では無理やりsibcallにする。
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
85
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
86 expand_callでの修正内容
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
87 Undocumented.
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
88 expand_cbc_gotoの処理内容
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
89 Undocumented.
29
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
32
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
91 ___________________________________________________________
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
92 goto文における並列代入の実装 Nov 26, 2009
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
93 -----------------------------------------------------------
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
94
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
95 c-parser.c: c_parser_statement_after_labels()における goto文のパースの
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
96 段階で全ての引数を一時変数に代入する形に変更する。
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
97 もちろんこれだけで並列代入ができる分けではないが、おそらくGCCの最適化
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
98 機構でできると考える。
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
99
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
100 1. c_parser_expr_no_commasでCALL_EXPRを取得
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
101 2. 全ての引数に対して一時変数を作成
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
102 3. それぞれを代入
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
103 4. CALL_EXPRの引数を一時変数に置き換え
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
104 2-4の処理をcbc_replace_argumentsで行う。
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
105
29
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
32
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
108 ___________________________________________________________
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
109 return擬似変数の実装
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
110 -----------------------------------------------------------
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
111
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
112 ___________________________________________________________
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
113 environmentの実装
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
114 -----------------------------------------------------------
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
115
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
116
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
117
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
118
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
119
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
120
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
121
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
122
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
123
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
124
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
125
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
126
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
127
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
128
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
129
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
130
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
131
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
132 ___________________________________________
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
133 * goto文における並列代入実装について考える
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
134 -------------------------------------------
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
135
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
136 Nov 26, 2009
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
137 c-parser.c: c_parser_statement_after_labels()における goto文のパースの
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
138 段階で全ての引数を一時変数に代入する形に変更する。
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
139 もちろんこれだけで並列代入ができる分けではないが、おそらくGCCの最適化
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
140 機構でできると考える。
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
141
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
142 1. c_parser_expr_no_commasでCALL_EXPRを取得
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
143 2. 全ての引数に対して一時変数を作成 build_decl?
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
144 名前なしでできるか?
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
145 3. それぞれを代入
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
146 4. CALL_EXPRの引数を一時変数に置き換え
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
147 5. expand_callでの実装を元に戻す?
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
148 現状のままでも動きはするはず
33
e62c90c8e699 modify CbC-implementation.ja
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
149 引数のタイプ
e62c90c8e699 modify CbC-implementation.ja
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
150 関数
e62c90c8e699 modify CbC-implementation.ja
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
151 o ADDR_EXPR
e62c90c8e699 modify CbC-implementation.ja
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
152 o PARM_DECL, VAR_DECL,
e62c90c8e699 modify CbC-implementation.ja
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
153 other
e62c90c8e699 modify CbC-implementation.ja
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
154 o *_EXPR
e62c90c8e699 modify CbC-implementation.ja
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
155 o PARM_DECL, VAR_DECL,
32
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
156
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
157 実装の準備
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
158 o CALL_EXPRから引数リストを取得
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
159 DECL_ARGUMENTS(fundecl)
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
160 tree args = DECL_ARGUMENTS (fndecl);
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
161 for (; args; args = TREE_CHAIN (args))
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
162 {
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
163 tree type = TREE_TYPE (args);
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
164 if (INTEGRAL_TYPE_P (type)
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
165 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
166 DECL_ARG_TYPE (args) = integer_type_node;
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
167 }
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
168 o 名前なしの変数作成
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
169 var = build_decl(VAR_DECL, NULL_TREE, TYPE);
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
170 DECL_ARTIFICIAL (val) = 1;
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
171 o 代入文
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
172 build_modify_expr (loc, TO_EXPR, NOP_EXPR, FROM_EXPR)
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
173 o Constantなら一時変数いらない
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
174 もしくはcallerの引数と同じ場合にのみ一時変数を使うか
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
175 o CALL_EXPRは取得後に引数を変えても大丈夫なのか?
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
176 o expand_callでのstore_one_arg, check_sibcall_argument_overlapの動作
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
177
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
178 <del>実装に邪魔ないくつかの関数の解析</del>
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
179 o mem_overlaps_already_clobbered_arg_p(addr, size)
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
180 指定したメモリ[addr,addr+size]範囲がすでに前の引数格納によって上書
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
181 きされていないかをチェックする。
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
182 引数範囲を1byte毎にbitmapの1bitに表し、上書きされた場所は1がセット
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
183 されている。それにかぶるとNG.
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
184 また、addrが動的(esp+eaxなど)ならNG.
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
185 o sotre_one_args()
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
186 この実装ではexpand_cbc_gotoをいじらない事にした
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
187
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
188
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
189
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
190 * DEBUG手法
59194914942b add documents.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
191
29
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 gccコマンドではなくcc1コマンドに対してgdbを起動
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 $ ls
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 GCC/ build-test/ test/
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 $ cd test
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 $ gdb ../build-test/gcc/cc1
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 treeの表示
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 (gdb) p browse_tree (exp) <== expはtree構造体
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 rtxの表示
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 (gdb) p debug_rtx (exp) <== expはrtx構造体
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 browse_treeはtree, debug_rtxはrtxをconfigureの
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 --enable-checkingで指定している必要がある
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206
cc07adb17855 deleting old commented out code.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207