5 # File name: ir/tools/remove_cpp_commands.perl
7 # Author: Goetz Lindenmaier
11 # Copyright: (c) 2002-2003 Universität Karlsruhe
12 # Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
15 # This is necessary until CRECODER is integrated with the preprocessor.
17 # Take a C header file and remove all preprocessor commands.
18 # Wrap all typedefs with a preprocessor guard,
19 # add all possible typedefs in firm at the beginning of the file, also
20 # wrapped with a preprocessor guard
23 # perl remove_cpp_comands.perl <file>
24 # for a file with name <file>.h.
34 open(OUT, ">$outfile");
36 $typedeffile = "firm_typedefs.h";
37 open(TDF, ">>$typedeffile");
40 print OUT "\n#include \"firm_typedefs.h\"\n\n";
43 #Unresolved preprocessor commands
44 print TDF "#define INLINE\n";
45 print TDF "#define FILE int *\n";
46 print TDF "#ifndef MYTYPEDEFS\n#define MYTYPEDEFS\n";
47 #print TDF "#undef __cplusplus\n";
48 print TDF "typedef unsigned long size_t;\n";
49 #print TDF "typedef enum { false = 0, true = 1 } bool;\n"; geht nicht, false und true JAVA Schluesselwoerter
50 print TDF "typedef int bool;\n";
51 # Some typedefs we need because of wrond order resultion by this script
52 print TDF "#ifndef _ENTITY_TYPEDEF_\n#define _ENTITY_TYPEDEF_\ntypedef struct entity entity;\n#endif\n";
53 # Some typedefs we need because we do not include the according header files
54 print TDF "typedef struct dbg_info dbg_info;\n";
55 print TDF "#endif /* MYTYPEDEFS */ \n";
67 foreach $line (@lines) {
69 if ($line =~ /\#ifdef __cplusplus/) {
70 # There is extern "C" in firm.h, guarded by #ifdef __cplusplus
71 # crecoder does not grok the extern "C", so remove thses three lines.
75 } elsif ($multiline > 0) {
76 # this line connects a previous one, kill it
82 } elsif ($line =~ /^\#/) {
84 $scndlastline = $lastline;
91 } elsif ($openbracket == 1) {
93 if ((index($line, "}") > -1)) {
95 if (($guardedtypedef == 1)) {
101 } elsif ($line =~ /typedef/) {
102 # move the full typedef to firm_typedefs.h
104 if (($lastline =~ /^\#/) ) {
106 print TDF "$scndlastline"; $scndlastline = "";
107 print TDF "$lastline"; $lastline = "";
110 if ((index($line, "{") > -1)) {
112 } elsif (($guardedtypedef == 1)) {
113 print TDF "#endif\n";
116 if ((index($line, "}") > -1)) {
118 if (($guardedtypedef == 1)) {
119 print TDF "#endif\n";
125 $scndlastline = $lastline;