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-2007 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 | # 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
35 | # よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
36 | # に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
37 | # アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
38 | # の責任を負わない.
|
---|
39 | #
|
---|
40 | # @(#) $Id: genrename 109 2015-06-11 09:37:56Z coas-nagasima $
|
---|
41 | #
|
---|
42 |
|
---|
43 | #
|
---|
44 | # 先頭につける文字列
|
---|
45 | #
|
---|
46 | sub prefix_string {
|
---|
47 | local($sym) = @_;
|
---|
48 |
|
---|
49 | if ($sym =~ /[a-z]/) {
|
---|
50 | return("_kernel_");
|
---|
51 | }
|
---|
52 | else {
|
---|
53 | return("_KERNEL_");
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | #
|
---|
58 | # リネーム定義を生成する
|
---|
59 | #
|
---|
60 | sub generate_define
|
---|
61 | {
|
---|
62 | local($sym, $prefix) = @_;
|
---|
63 |
|
---|
64 | print FILE "#define ",$prefix,$sym;
|
---|
65 | print FILE "\t" if (length($prefix.$sym) < 4);
|
---|
66 | print FILE "\t" if (length($prefix.$sym) < 8);
|
---|
67 | print FILE "\t" if (length($prefix.$sym) < 12);
|
---|
68 | print FILE "\t" if (length($prefix.$sym) < 16);
|
---|
69 | print FILE "\t" if (length($prefix.$sym) < 20);
|
---|
70 | print FILE "\t" if (length($prefix.$sym) < 24);
|
---|
71 | print FILE "\t",$prefix, prefix_string($sym),$sym,"\n";
|
---|
72 | }
|
---|
73 |
|
---|
74 | #
|
---|
75 | # リネーム解除を生成する
|
---|
76 | #
|
---|
77 | sub generate_undef
|
---|
78 | {
|
---|
79 | local($sym, $prefix) = @_;
|
---|
80 |
|
---|
81 | print FILE "#undef ",$prefix,$sym,"\n";
|
---|
82 | }
|
---|
83 |
|
---|
84 | #
|
---|
85 | # インクルードディレクティブを生成する
|
---|
86 | #
|
---|
87 | sub generate_include
|
---|
88 | {
|
---|
89 | local($file, $prefix) = @_;
|
---|
90 |
|
---|
91 | $file =~ s/([>"])$/_$prefix.h$1/;
|
---|
92 | $includes .= "#include ".$file."\n";
|
---|
93 | }
|
---|
94 |
|
---|
95 | #
|
---|
96 | # エラーチェック
|
---|
97 | #
|
---|
98 | if ($#ARGV != 0) {
|
---|
99 | die "Usage: genrename <prefix>\n";
|
---|
100 | }
|
---|
101 |
|
---|
102 | #
|
---|
103 | # 初期化
|
---|
104 | #
|
---|
105 | @syms = ();
|
---|
106 | $name = $ARGV[0];
|
---|
107 | $NAME = $name; $NAME =~ y/a-z/A-Z/;
|
---|
108 |
|
---|
109 | $infile = $name."_rename.def";
|
---|
110 | $header_defsym = "TOPPERS_".$NAME."_RENAME_H";
|
---|
111 |
|
---|
112 | #
|
---|
113 | # シンボルリストを読み込む
|
---|
114 | #
|
---|
115 | open(INFILE, $infile) || die "Cannot open $infile";
|
---|
116 | while ($line = <INFILE>) {
|
---|
117 | chomp $line;
|
---|
118 | @syms = (@syms, $line);
|
---|
119 | }
|
---|
120 | close(INFILE);
|
---|
121 |
|
---|
122 | #
|
---|
123 | # ???_rename.h を生成する
|
---|
124 | #
|
---|
125 | $includes = "";
|
---|
126 | $file = $name."_rename.h";
|
---|
127 | open(FILE, "> ".$file);
|
---|
128 |
|
---|
129 | print FILE <<END;
|
---|
130 | /* This file is generated from $infile by genrename. */
|
---|
131 |
|
---|
132 | #ifndef $header_defsym
|
---|
133 | #define $header_defsym
|
---|
134 |
|
---|
135 | END
|
---|
136 |
|
---|
137 | foreach $sym (@syms) {
|
---|
138 | if ($sym =~ /^#(.*)$/) {
|
---|
139 | print FILE "/*\n";
|
---|
140 | print FILE " * ",$1,"\n";
|
---|
141 | print FILE " */\n";
|
---|
142 | }
|
---|
143 | elsif ($sym =~ /^INCLUDE[ \t]+(.*)$/) {
|
---|
144 | generate_include($1, "rename");
|
---|
145 | }
|
---|
146 | elsif ($sym ne "") {
|
---|
147 | generate_define($sym, "");
|
---|
148 | }
|
---|
149 | else {
|
---|
150 | print FILE "\n";
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | print FILE <<END;
|
---|
155 |
|
---|
156 | #ifdef TOPPERS_LABEL_ASM
|
---|
157 |
|
---|
158 | END
|
---|
159 |
|
---|
160 | foreach $sym (@syms) {
|
---|
161 | if ($sym =~ /^#(.*)$/) {
|
---|
162 | print FILE "/*\n";
|
---|
163 | print FILE " * ",$1,"\n";
|
---|
164 | print FILE " */\n";
|
---|
165 | }
|
---|
166 | elsif ($sym =~ /^INCLUDE[ \t]+(.*)$/) {
|
---|
167 | # do nothing
|
---|
168 | }
|
---|
169 | elsif ($sym ne "") {
|
---|
170 | generate_define($sym, "_");
|
---|
171 | }
|
---|
172 | else {
|
---|
173 | print FILE "\n";
|
---|
174 | }
|
---|
175 | }
|
---|
176 |
|
---|
177 | print FILE <<END;
|
---|
178 |
|
---|
179 | #endif /* TOPPERS_LABEL_ASM */
|
---|
180 |
|
---|
181 | $includes
|
---|
182 | #endif /* $header_defsym */
|
---|
183 | END
|
---|
184 |
|
---|
185 | #
|
---|
186 | # ???_unrename.h を生成する
|
---|
187 | #
|
---|
188 | $includes = "";
|
---|
189 | $file = $name."_unrename.h";
|
---|
190 | open(FILE, "> ".$file);
|
---|
191 |
|
---|
192 | print FILE <<END;
|
---|
193 | /* This file is generated from $infile by genrename. */
|
---|
194 |
|
---|
195 | /* This file is included only when $name\_rename.h has been included. */
|
---|
196 | #ifdef $header_defsym
|
---|
197 | #undef $header_defsym
|
---|
198 |
|
---|
199 | END
|
---|
200 |
|
---|
201 | foreach $sym (@syms) {
|
---|
202 | if ($sym =~ /^#(.*)$/) {
|
---|
203 | print FILE "/*\n";
|
---|
204 | print FILE " * ",$1,"\n";
|
---|
205 | print FILE " */\n";
|
---|
206 | }
|
---|
207 | elsif ($sym =~ /^INCLUDE[ \t]+(.*)$/) {
|
---|
208 | generate_include($1, "unrename");
|
---|
209 | }
|
---|
210 | elsif ($sym ne "") {
|
---|
211 | generate_undef($sym, "");
|
---|
212 | }
|
---|
213 | else {
|
---|
214 | print FILE "\n";
|
---|
215 | }
|
---|
216 | }
|
---|
217 |
|
---|
218 | print FILE <<END;
|
---|
219 |
|
---|
220 | #ifdef TOPPERS_LABEL_ASM
|
---|
221 |
|
---|
222 | END
|
---|
223 |
|
---|
224 | foreach $sym (@syms) {
|
---|
225 | if ($sym =~ /^#(.*)$/) {
|
---|
226 | print FILE "/*\n";
|
---|
227 | print FILE " * ",$1,"\n";
|
---|
228 | print FILE " */\n";
|
---|
229 | }
|
---|
230 | elsif ($sym =~ /^INCLUDE[ \t]+(.*)$/) {
|
---|
231 | # do nothing
|
---|
232 | }
|
---|
233 | elsif ($sym ne "") {
|
---|
234 | generate_undef($sym, "_");
|
---|
235 | }
|
---|
236 | else {
|
---|
237 | print FILE "\n";
|
---|
238 | }
|
---|
239 | }
|
---|
240 |
|
---|
241 | print FILE <<END;
|
---|
242 |
|
---|
243 | #endif /* TOPPERS_LABEL_ASM */
|
---|
244 |
|
---|
245 | $includes
|
---|
246 | #endif /* $header_defsym */
|
---|
247 | END
|
---|
248 |
|
---|
249 | close(FILE);
|
---|