3 # Take a C header file and remove all preprocessor commands.
4 # Wrap all typedefs with a preprocessor guard,
5 # add all possible typedefs in firm at the beginning of the file, also
6 # wrapped with a preprocessor guard
9 # perl remove_cpp_comands.perl <file>
10 # for a file with name <file>.h.
20 open(OUT, ">$outfile");
22 $typedeffile = "firm_typedefs.h";
23 open(TDF, ">>$typedeffile");
26 print OUT "\n#include \"firm_typedefs.h\"\n\n";
29 #Unresolved preprocessor commands
30 print TDF "#define INLINE\n";
31 print TDF "#define FILE int *\n";
32 print TDF "#ifndef MYTYPEDEFS\n#define MYTYPEDEFS\n";
33 print TDF "typedef unsigned long size_t;\n";
34 #print TDF "typedef enum { false = 0, true = 1 } bool;\n"; geht nicht, false und true JAVA Schluesselwoerter
35 print TDF "typedef int bool;\n";
36 # Some typedefs we need because of wrond order resultion by this script
37 print TDF "#ifndef _ENTITY_TYPEDEF_\n#define _ENTITY_TYPEDEF_\ntypedef struct entity entity;\n#endif\n";
38 # Some typedefs we need because we do not include the according header files
39 print TDF "typedef struct dbg_info dbg_info;\n";
40 print TDF "#endif /* MYTYPEDEFS */ \n";
49 foreach $line (@lines) {
51 if (($line =~ /^\#/) ) {
53 $scndlastline = $lastline;
55 } elsif ($openbracket == 1) {
57 if ((index($line, "}") > -1)) {
59 if (($guardedtypedef == 1)) {
65 } elsif ($line =~ /typedef/) {
66 # move the full typedef to firm_typedefs.h
68 if (($lastline =~ /^\#/) ) {
70 print TDF "$scndlastline"; $scndlastline = "";
71 print TDF "$lastline"; $lastline = "";
74 if ((index($line, "{") > -1)) {
76 } elsif (($guardedtypedef == 1)) {
80 if ((index($line, "}") > -1)) {
82 if (($guardedtypedef == 1)) {
89 $scndlastline = $lastline;