struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / scripts / keil2sdcc.pl
bloba3ba657697998132fcad211df4cac15fe582a90b
1 #!/usr/bin/perl -w
3 # keil2sdcc.pl
4 # Scott Bronson
5 # 22 June 2003
8 # usage (UNIX):
9 # perl keil2sdcc.pl < keil_header.h > sdcc_header.h
10 # or
11 # perl keil2sdcc.pl keil_header.h > sdcc_header.h
13 # usage (Windows):
14 # perl keil2sdcc.pl keil_header.h > sdcc_header.h
17 # keil_header.h and sdcc_header.h must not be the same file since
18 # most shells overwrite the output file before opening the input file.
21 # This script converts Keil-style header files to SDCC. It tries to
22 # be pedantic so don't be surprised if you need to munge it a bit to
23 # get it to work. On the other hand, it doesn't fully parse the C
24 # file (for obvious reasons).
26 # It takes the Keil header file either as an argument or on
27 # stdin and it produces the output on stdout.
29 # This script is inspired by keil2sdcc.pl by Bela Torok but a lot
30 # more pedantic.
32 use strict;
34 while(<>)
36 s/\r//g; # remove DOS line endings if necessary
38 # external register (kind of a weird format)
40 # in: EXTERN xdata volatile BYTE GPIF_WAVE_DATA _AT_ 0xE400;
41 # out: EXTERN xdata at 0xE400 volatile BYTE GPIF_WAVE_DATA;
42 # $1: leading whitespace
43 # $2: variable name
44 # $3: variable location
45 # $4: trailing comments, etc.
47 if(/^(\s*)EXTERN\s*xdata\s*volatile\s*BYTE\s*(\w+(?:\s*\[\s*\d+\s*\])?)\s+_AT_\s*([^;]+);(.*)$/) {
48 print "$1EXTERN xdata at $3 volatile BYTE $2;$4\n";
49 next;
52 # sfr statement
54 # in: sfr IOA = 0x80;
55 # out: sfr at 0x80 IOA;
56 # $1: leading whitespace
57 # $2: variable name
58 # $3: variable location
59 # $4: trailing comments, etc.
61 if(/^(\s*)sfr\s*(\w+)\s*=\s*([^;]+);(.*)$/) {
62 print "$1sfr at $3 $2;$4\n";
63 next;
66 # sbit statement
68 # in: sbit SEL = 0x86+0;
69 # out: sbit at 0x86+0 SEL;
70 # $1: leading whitespace
71 # $2: variable name
72 # $3: variable location
73 # $4: trailing comments, etc.
75 if(/^(\s*)sbit\s*(\w+)\s*=\s*([^;]+);(.*)$/) {
76 print "$1sbit at $3 $2;$4\n";
77 next;
82 # entire line is a C++ comment, output it unchanged.
83 if(/^(\s*)\/\/(.*)$/) {
84 print "$1//$2\n";
85 next;
88 # C comment, slurp lines until the close comment and output it unchanged.
89 if(/^(\s*)\/\*(.*)$/) {
90 my($ws,$cmt) = ($1,"$2\n");
91 $cmt .= <> while $cmt !~ /\*\/\s*$/;
92 $cmt =~ s/\r//g;
93 print "$ws/*$cmt";
94 next;
97 # preprocessor statement (whitespace followed by '#'), don't change
98 if(/^(\s*)\#(.*)$/) {
99 print "$1#$2\n";
100 next;
103 # blank line, don't change
104 if(/^(\s*)$/) {
105 print "\n";
106 next;
109 chomp;
110 die "Unconvertable line: \"$_\"\n";