| [7] | 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 | # ËÜ¥œ¥Õ¥È¥Š¥§¥¢€Ï¡€ÌµÊÝŸÚ€ÇÄó¶¡€µ€ì€Æ€€€ë€â€Î€Ç€¢€ë¡¥ŸåµÃøºîž¢ŒÔ€ª |
|---|
| 35 | # €è€ÓTOPPERS¥×¥í¥ž¥§¥¯¥È€Ï¡€ËÜ¥œ¥Õ¥È¥Š¥§¥¢€ËŽØ€·€Æ¡€ÆÃÄê€Î»ÈÍÑÌÜŪ |
|---|
| 36 | # €ËÂЀ¹€ëŬ¹çÀ€âŽÞ€á€Æ¡€€€€«€Ê€ëÊÝŸÚ€â¹Ô€ï€Ê€€¡¥€Þ€¿¡€ËÜ¥œ¥Õ¥È¥Š¥§ |
|---|
| 37 | # ¥¢€ÎÍøÍрˀè€êÄŸÀÜŪ€Þ€¿€ÏŽÖÀÜŪ€ËÀž€ž€¿€€€«€Ê€ë»³²€ËŽØ€·€Æ€â¡€€œ |
|---|
| 38 | # €ÎÀÕÇ€€òÉé€ï€Ê€€¡¥ |
|---|
| 39 | # |
|---|
| 40 | # @(#) $Id$ |
|---|
| 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); |
|---|