1 | #! /usr/bin/perl
|
---|
2 | #
|
---|
3 | # TOPPERS Software
|
---|
4 | # Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
5 | #
|
---|
6 | # Copyright (C) 2003 by Embedded and Real-Time Systems Laboratory
|
---|
7 | # Toyohashi Univ. of Technology, JAPAN
|
---|
8 | # Copyright (C) 2005-2011 by Embedded and Real-Time Systems Laboratory
|
---|
9 | # Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
10 | #
|
---|
11 | # 上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
12 | # ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
13 | # 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
14 | # (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
15 | # 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
16 | # スコード中に含まれていること.
|
---|
17 | # (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
18 | # 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
19 | # 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
20 | # の無保証規定を掲載すること.
|
---|
21 | # (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
22 | # 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
23 | # と.
|
---|
24 | # (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
25 | # 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
26 | # (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
27 | # 報告すること.
|
---|
28 | # (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
29 | # 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
30 | # また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
31 | # 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
32 | # 免責すること.
|
---|
33 | #
|
---|
34 | # 本ソフトウェアは,AUTOSAR(AUTomotive Open System ARchitecture)仕
|
---|
35 | # 様に基づいている.上記の許諾は,AUTOSARの知的財産権を許諾するもので
|
---|
36 | # はない.AUTOSARは,AUTOSAR仕様に基づいたソフトウェアを商用目的で利
|
---|
37 | # 用する者に対して,AUTOSARパートナーになることを求めている.
|
---|
38 | #
|
---|
39 | # 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
40 | # よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
41 | # に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
42 | # アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
43 | # の責任を負わない.
|
---|
44 | #
|
---|
45 | # @(#) $Id: genrename 2253 2011-09-11 01:23:40Z ertl-hiro $
|
---|
46 | #
|
---|
47 |
|
---|
48 | #
|
---|
49 | # 先頭につける文字列
|
---|
50 | #
|
---|
51 | sub prefix_string {
|
---|
52 | local($sym) = @_;
|
---|
53 |
|
---|
54 | if ($sym =~ /[a-z]/) {
|
---|
55 | return("_kernel_");
|
---|
56 | }
|
---|
57 | else {
|
---|
58 | return("_KERNEL_");
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | #
|
---|
63 | # リネーム定義を生成する
|
---|
64 | #
|
---|
65 | sub generate_define
|
---|
66 | {
|
---|
67 | local($sym, $prefix) = @_;
|
---|
68 |
|
---|
69 | print FILE "#define ",$prefix,$sym;
|
---|
70 | print FILE "\t" if (length($prefix.$sym) < 4);
|
---|
71 | print FILE "\t" if (length($prefix.$sym) < 8);
|
---|
72 | print FILE "\t" if (length($prefix.$sym) < 12);
|
---|
73 | print FILE "\t" if (length($prefix.$sym) < 16);
|
---|
74 | print FILE "\t" if (length($prefix.$sym) < 20);
|
---|
75 | print FILE "\t" if (length($prefix.$sym) < 24);
|
---|
76 | print FILE "\t",$prefix,prefix_string($sym),$sym,"\n";
|
---|
77 | }
|
---|
78 |
|
---|
79 | #
|
---|
80 | # リネーム解除を生成する
|
---|
81 | #
|
---|
82 | sub generate_undef
|
---|
83 | {
|
---|
84 | local($sym, $prefix) = @_;
|
---|
85 |
|
---|
86 | print FILE "#undef ",$prefix,$sym,"\n";
|
---|
87 | }
|
---|
88 |
|
---|
89 | #
|
---|
90 | # インクルードディレクティブを生成する
|
---|
91 | #
|
---|
92 | sub generate_include
|
---|
93 | {
|
---|
94 | local($file, $prefix) = @_;
|
---|
95 |
|
---|
96 | $file =~ s/([>"])$/_$prefix.h$1/;
|
---|
97 | $includes .= "#include ".$file."\n";
|
---|
98 | }
|
---|
99 |
|
---|
100 | #
|
---|
101 | # エラーチェック
|
---|
102 | #
|
---|
103 | if ($#ARGV != 0) {
|
---|
104 | die "Usage: genrename <prefix>\n";
|
---|
105 | }
|
---|
106 |
|
---|
107 | #
|
---|
108 | # 初期化
|
---|
109 | #
|
---|
110 | @syms = ();
|
---|
111 | $name = $ARGV[0];
|
---|
112 | $NAME = $name; $NAME =~ y/a-z/A-Z/;
|
---|
113 |
|
---|
114 | $infile = $name."_rename.def";
|
---|
115 | $header_defsym = "TOPPERS_".$NAME."_RENAME_H";
|
---|
116 |
|
---|
117 | #
|
---|
118 | # シンボルリストを読み込む
|
---|
119 | #
|
---|
120 | open(INFILE, $infile) || die "Cannot open $infile";
|
---|
121 | while ($line = <INFILE>) {
|
---|
122 | chomp $line;
|
---|
123 | @syms = (@syms, $line);
|
---|
124 | }
|
---|
125 | close(INFILE);
|
---|
126 |
|
---|
127 | #
|
---|
128 | # ???_rename.h を生成する
|
---|
129 | #
|
---|
130 | $includes = "";
|
---|
131 | $file = $name."_rename.h";
|
---|
132 | open(FILE, "> ".$file);
|
---|
133 |
|
---|
134 | print FILE <<END;
|
---|
135 | /* This file is generated from $infile by genrename. */
|
---|
136 |
|
---|
137 | #ifndef $header_defsym
|
---|
138 | #define $header_defsym
|
---|
139 |
|
---|
140 | END
|
---|
141 |
|
---|
142 | foreach $sym (@syms) {
|
---|
143 | if ($sym =~ /^#(.*)$/) {
|
---|
144 | print FILE "/*\n";
|
---|
145 | print FILE " * ",$1,"\n";
|
---|
146 | print FILE " */\n";
|
---|
147 | }
|
---|
148 | elsif ($sym =~ /^INCLUDE[ \t]+(.*)$/) {
|
---|
149 | generate_include($1, "rename");
|
---|
150 | }
|
---|
151 | elsif ($sym ne "") {
|
---|
152 | generate_define($sym, "");
|
---|
153 | }
|
---|
154 | else {
|
---|
155 | print FILE "\n";
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 | print FILE <<END;
|
---|
160 |
|
---|
161 | #ifdef TOPPERS_LABEL_ASM
|
---|
162 |
|
---|
163 | END
|
---|
164 |
|
---|
165 | foreach $sym (@syms) {
|
---|
166 | if ($sym =~ /^#(.*)$/) {
|
---|
167 | print FILE "/*\n";
|
---|
168 | print FILE " * ",$1,"\n";
|
---|
169 | print FILE " */\n";
|
---|
170 | }
|
---|
171 | elsif ($sym =~ /^INCLUDE[ \t]+(.*)$/) {
|
---|
172 | # do nothing
|
---|
173 | }
|
---|
174 | elsif ($sym ne "") {
|
---|
175 | generate_define($sym, "_");
|
---|
176 | }
|
---|
177 | else {
|
---|
178 | print FILE "\n";
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 | print FILE <<END;
|
---|
183 |
|
---|
184 | #endif /* TOPPERS_LABEL_ASM */
|
---|
185 |
|
---|
186 | $includes
|
---|
187 | #endif /* $header_defsym */
|
---|
188 | END
|
---|
189 |
|
---|
190 | #
|
---|
191 | # ???_unrename.h を生成する
|
---|
192 | #
|
---|
193 | $includes = "";
|
---|
194 | $file = $name."_unrename.h";
|
---|
195 | open(FILE, "> ".$file);
|
---|
196 |
|
---|
197 | print FILE <<END;
|
---|
198 | /* This file is generated from $infile by genrename. */
|
---|
199 |
|
---|
200 | /* This file is included only when $name\_rename.h has been included. */
|
---|
201 | #ifdef $header_defsym
|
---|
202 | #undef $header_defsym
|
---|
203 |
|
---|
204 | END
|
---|
205 |
|
---|
206 | foreach $sym (@syms) {
|
---|
207 | if ($sym =~ /^#(.*)$/) {
|
---|
208 | print FILE "/*\n";
|
---|
209 | print FILE " * ",$1,"\n";
|
---|
210 | print FILE " */\n";
|
---|
211 | }
|
---|
212 | elsif ($sym =~ /^INCLUDE[ \t]+(.*)$/) {
|
---|
213 | generate_include($1, "unrename");
|
---|
214 | }
|
---|
215 | elsif ($sym ne "") {
|
---|
216 | generate_undef($sym, "");
|
---|
217 | }
|
---|
218 | else {
|
---|
219 | print FILE "\n";
|
---|
220 | }
|
---|
221 | }
|
---|
222 |
|
---|
223 | print FILE <<END;
|
---|
224 |
|
---|
225 | #ifdef TOPPERS_LABEL_ASM
|
---|
226 |
|
---|
227 | END
|
---|
228 |
|
---|
229 | foreach $sym (@syms) {
|
---|
230 | if ($sym =~ /^#(.*)$/) {
|
---|
231 | print FILE "/*\n";
|
---|
232 | print FILE " * ",$1,"\n";
|
---|
233 | print FILE " */\n";
|
---|
234 | }
|
---|
235 | elsif ($sym =~ /^INCLUDE[ \t]+(.*)$/) {
|
---|
236 | # do nothing
|
---|
237 | }
|
---|
238 | elsif ($sym ne "") {
|
---|
239 | generate_undef($sym, "_");
|
---|
240 | }
|
---|
241 | else {
|
---|
242 | print FILE "\n";
|
---|
243 | }
|
---|
244 | }
|
---|
245 |
|
---|
246 | print FILE <<END;
|
---|
247 |
|
---|
248 | #endif /* TOPPERS_LABEL_ASM */
|
---|
249 |
|
---|
250 | $includes
|
---|
251 | #endif /* $header_defsym */
|
---|
252 | END
|
---|
253 |
|
---|
254 | close(FILE);
|
---|