Mercurial > hg > Papers > 2017 > mitsuki-thesis
comparison final_main/chapter5.tex @ 13:ddfca5037e41
update
author | mir3636 |
---|---|
date | Wed, 15 Feb 2017 20:32:30 +0900 |
parents | 11ad5b3e7b85 |
children | 97f70e469150 |
comparison
equal
deleted
inserted
replaced
12:cc8ff782067c | 13:ddfca5037e41 |
---|---|
8 stub Code Gear は Code Gear 間の継続に挟まれる Code Gear が必要な Data Gear を Context から取り出す処理を行うものである。 | 8 stub Code Gear は Code Gear 間の継続に挟まれる Code Gear が必要な Data Gear を Context から取り出す処理を行うものである。 |
9 stub Code Gear は Code Gear 毎に記述する必要があり、そのCode Gear の引数を見て取り出す Data Gear を選択する。 | 9 stub Code Gear は Code Gear 毎に記述する必要があり、そのCode Gear の引数を見て取り出す Data Gear を選択する。 |
10 stub Code Gear を 自動生成することによって Code Gear の記述量を約半分にすることができる。 | 10 stub Code Gear を 自動生成することによって Code Gear の記述量を約半分にすることができる。 |
11 | 11 |
12 stub を生成するために generate\_stub は指定された cbc ファイルの \_\_code型である Code Gear を取得し、引数から必要な Data Gear を選択する。 | 12 stub を生成するために generate\_stub は指定された cbc ファイルの \_\_code型である Code Gear を取得し、引数から必要な Data Gear を選択する。 |
13 generate\_stub は引数と interface を照らし合わせ、Gearef または GearImpl を決定する。 | 13 generate\_stub は引数と interface を照らし合わせ、Gearef または GearImpl を決定する(リスト\ref{generate_stub})。 |
14 この時既に stub Code Gear が記述されている Code Gear は無視される。 | 14 この時既に stub Code Gear が記述されている Code Gear は無視される。 |
15 | 15 |
16 cbc ファイル(リスト\ref{stack_cbc}) から、生成した stub Code Gear を加えて c ファイル(\ref{stack_c})に変換を行う。 | 16 cbc ファイル(リスト\ref{stack_cbc}) から、生成した stub Code Gear を加えて c ファイル(\ref{stack_c})に変換を行う。 |
17 | |
18 \begin{lstlisting}[frame=lrbt,label=generate_stub,caption={\footnotesize generate stub}] | |
19 sub generateStubArgs { | |
20 my($codeGearName, $varName, $typeName, $typeField, $interface,$output) = @_; | |
21 my $varname1 = $output?"O_$varName":$varName; | |
22 for my $n ( @{$dataGearVar{$codeGearName}} ) { | |
23 # we already have it | |
24 return 0 if ( $n eq $varname1); | |
25 } | |
26 push @{$dataGearVar{$codeGearName}}, $varname1; | |
27 if ($typeName eq $implementation) { | |
28 # get implementation | |
29 $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $interface, $varName);\n"; | |
30 } else { | |
31 for my $ivar (keys %{$var{$interface}}) { | |
32 # input data gear field | |
33 if ($varName eq $ivar) { | |
34 if ($typeName eq $var{$interface}->{$ivar}) { | |
35 if ($output) { | |
36 $dataGearName{$codeGearName} .= "\t$typeName** O_$varName = &Gearef(context, $interface)->$varName;\n"; | |
37 $outputVar{$codeGearName} .= "\t$typeName* $varName;\n"; | |
38 return 1; | |
39 } | |
40 | |
41 $dataGearName{$codeGearName} .= "\t$typeName* $varName = Gearef(context, $interface)->$varName;\n"; | |
42 return 1; | |
43 } | |
44 } | |
45 } | |
46 for my $cName (keys %{$code{$interface}}) { | |
47 if ($varName eq $cName) { | |
48 # continuation field | |
49 $dataGearName{$codeGearName} .= "\tenum Code $varName = Gearef(context, $interface)->$varName;\n"; | |
50 return 1; | |
51 } | |
52 } | |
53 # global variable case | |
54 $dataGearName{$codeGearName} .= "\t$typeName* $varName = Gearef(context, $typeName);\n"; | |
55 return 1; | |
56 } | |
57 } | |
58 \end{lstlisting} | |
17 | 59 |
18 \begin{lstlisting}[frame=lrbt,label=stack_cbc,caption={\footnotesize cbcファイルの例}] | 60 \begin{lstlisting}[frame=lrbt,label=stack_cbc,caption={\footnotesize cbcファイルの例}] |
19 #include "../context.h" | 61 #include "../context.h" |
20 | 62 |
21 Stack* createSingleLinkedStack(struct Context* context) { | 63 Stack* createSingleLinkedStack(struct Context* context) { |
81 enum Code next = Gearef(context, Stack)->next; | 123 enum Code next = Gearef(context, Stack)->next; |
82 goto clearSingleLinkedStack(context, stack, next); | 124 goto clearSingleLinkedStack(context, stack, next); |
83 } | 125 } |
84 \end{lstlisting} | 126 \end{lstlisting} |
85 | 127 |
128 | |
129 | |
86 \section{Context の生成} | 130 \section{Context の生成} |
87 Context は Meta Data Gear に相当し、Code Gear や Data Gear を管理している。 | 131 Context は Meta Data Gear に相当し、Code Gear や Data Gear を管理している。 |
88 Data Gear を取得するために generate\_context は context の定義 (リスト\ref{context}) を読み宣言されている Data Gear を取得する。 | 132 Data Gear を取得するために generate\_context は context の定義 (リスト\ref{context}) を読み宣言されている Data Gear を取得する。 |
89 Code Gear は指定された cbc ファイルから stub を見て取得を行う。 | |
90 取得した Code/Data Gear の enum の定義は enumCode.h、enumData.h に生成される。 | |
91 | |
92 Context では Code Gear の名前とポインタの対応は generate\_context によって生成される enum Code と関数ポインタによって表現される。 | |
93 実際に Code Gear に接続する際は enum Code を指定することで接続を行う。 | |
94 | |
95 また、generate\_context は取得した Code/Data Gear から Context の生成を行うコード (リスト\ref{init_context}) も生成する。 | |
96 | |
97 Context には Allocation 等で生成した Data Gear へのポインタが格納されている。 | |
98 Code Gear は Context を通して Data Gear へアクセスする。 | |
99 Data Gear の Allocation を行うコードは dataGearInit.c に生成される。 | |
100 | |
101 Data Gear は union Data とその中の struct によって表現される。 | |
102 Context には Data Gear の Data Type の情報が格納されている。 | |
103 この情報から確保される Data Gear のサイズなどを決定する。 | |
104 | 133 |
105 \begin{lstlisting}[frame=lrbt,label=context,caption={\footnotesize context の定義}] | 134 \begin{lstlisting}[frame=lrbt,label=context,caption={\footnotesize context の定義}] |
106 #define ALLOCATE_SIZE 20000000 | |
107 #define NEW(type) (type*)(calloc(1, sizeof(type))) | |
108 #define NEWN(n, type) (type*)(calloc(n, sizeof(type))) | |
109 | |
110 #define ALLOC_DATA(context, dseg) ({\ | |
111 struct Meta* meta = (struct Meta*)context->heap;\ | |
112 meta->type = D_##dseg;\ | |
113 meta->size = 1;\ | |
114 context->heap += sizeof(struct Meta);\ | |
115 context->data[D_##dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[D_##dseg]; }) | |
116 | |
117 #define ALLOCATE(context, t) ({ \ | |
118 struct Meta* meta = (struct Meta*)context->heap;\ | |
119 context->heap += sizeof(struct Meta);\ | |
120 union Data* data = context->heap; \ | |
121 context->heap += sizeof(struct t); \ | |
122 meta->type = D_##t; \ | |
123 meta->size = 1; \ | |
124 data; }) | |
125 | |
126 #define Gearef(context, t) (&(context)->data[D_##t]->t) | |
127 #define GearImpl(context, intf, name) (Gearef(context, intf)->name->intf.name) | |
128 | |
129 #include "c/enumCode.h" | |
130 | |
131 #include "c/enumData.h" | |
132 | |
133 struct Context { | 135 struct Context { |
134 enum Code next; | 136 enum Code next; |
135 struct Worker* worker; | 137 struct Worker* worker; |
136 struct TaskManager* taskManager; | 138 struct TaskManager* taskManager; |
137 int codeNum; | 139 int codeNum; |
192 } Node; | 194 } Node; |
193 }; // union Data end this is necessary for context generator | 195 }; // union Data end this is necessary for context generator |
194 | 196 |
195 \end{lstlisting} | 197 \end{lstlisting} |
196 | 198 |
199 Code Gear の取得は指定された cbc ファイルから \_\_code 型を見て行う。 | |
200 取得した Code/Data Gear の enum の定義は enumCode.h、enumData.h に生成される。 | |
201 | |
202 Context では Code Gear の名前とポインタの対応は generate\_context によって生成される enum Code と関数ポインタによって表現される。 | |
203 実際に Code Gear に接続する際は enum Code を指定することで接続を行う。 | |
204 | |
205 また、generate\_context は取得した Code/Data Gear から Context の生成を行うコード (リスト\ref{init_context}) も生成する。 | |
206 | |
207 Context には Allocation 等で生成した Data Gear へのポインタが格納されている。 | |
208 Code Gear は Context を通して Data Gear へアクセスする。 | |
209 Data Gear の Allocation を行うコードは dataGearInit.c に生成される。 | |
210 | |
211 Data Gear は union Data とその中の struct によって表現される。 | |
212 Context には Data Gear の Data Type の情報が格納されている。 | |
213 この情報から確保される Data Gear のサイズなどを決定する。 | |
214 | |
197 \begin{lstlisting}[frame=lrbt,label=init_context,caption={\footnotesize 生成された context}] | 215 \begin{lstlisting}[frame=lrbt,label=init_context,caption={\footnotesize 生成された context}] |
198 | 216 |
199 #include <stdlib.h> | 217 #include <stdlib.h> |
200 | 218 |
201 #include "../context.h" | 219 #include "../context.h" |