Implemented the computation of outedges in interprocedural graphs
[libfirm] / tools / remove_cpp_comands.perl
1 #!/usr/local/bin/perl
2
3 #
4 # Project:     libFIRM
5 # File name:   ir/tools/remove_cpp_commands.perl
6 # Purpose:
7 # Author:      Goetz Lindenmaier
8 # Modified by:
9 # Created:     8.2002
10 # CVS-ID:      $Id$
11 # Copyright:   (c) 2002-2003 Universität Karlsruhe
12 # Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
13 #
14
15 # This is necessary until CRECODER is integrated with the preprocessor.
16 #
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
21 #
22 # Call
23 #  perl remove_cpp_comands.perl <file>
24 # for a file with name <file>.h.
25
26 # open files
27 $infile = $ARGV[0];
28
29 open(IN, $infile);
30 @lines = <IN>;
31 close(IN);
32
33 $outfile = $infile;
34 open(OUT, ">$outfile");
35
36 $typedeffile = "firm_typedefs.h";
37 open(TDF, ">>$typedeffile");
38
39 #dump headers
40 print OUT "\n#include \"firm_typedefs.h\"\n\n";
41
42
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 "typedef unsigned long size_t;\n";
48 #print TDF "typedef enum { false = 0, true = 1 } bool;\n";  geht nicht, false und true JAVA Schluesselwoerter
49 print TDF "typedef int bool;\n";
50 # Some typedefs we need because of wrond order resultion by this script
51 print TDF "#ifndef _ENTITY_TYPEDEF_\n#define _ENTITY_TYPEDEF_\ntypedef struct entity entity;\n#endif\n";
52 # Some typedefs we need because we do not include the according header files
53 print TDF "typedef struct dbg_info dbg_info;\n";
54 print TDF "#endif /* MYTYPEDEFS */ \n";
55
56 #to collect typedefs
57 $openbracket = 0;
58 $guardedtypedef = 0;
59
60 $scndlastline = "";
61 $lastline = "";
62
63 foreach $line (@lines) {
64
65     if (($line =~ /^\#/)   ) {
66         # eat the line
67         $scndlastline = $lastline;
68         $lastline = $line;
69     } elsif ($openbracket == 1) {
70         print TDF "$line";
71         if ((index($line, "}") > -1)) {
72             $openbracket = 0;
73             if (($guardedtypedef == 1)) {
74                 print TDF "#endif\n";
75                 $guardedtypedef = 0;
76             }
77         }
78         $lastline = "";
79     } elsif ($line =~ /typedef/) {
80         # move the full typedef to firm_typedefs.h
81
82         if (($lastline =~ /^\#/)   ) {
83             $guardedtypedef = 1;
84             print TDF "$scndlastline"; $scndlastline = "";
85             print TDF "$lastline";      $lastline = "";
86         }
87         print TDF "$line";
88         if ((index($line, "{") > -1)) {
89             $openbracket = 1;
90         } elsif (($guardedtypedef == 1)) {
91             print TDF "#endif\n";
92             $guardedtypedef = 0;
93         }
94         if ((index($line, "}") > -1)) {
95             $openbracket = 0;
96             if (($guardedtypedef == 1)) {
97                 print TDF "#endif\n";
98                 $guardedtypedef = 0;
99             }
100         }
101     } else {
102         print OUT "$line";
103         $scndlastline = $lastline;
104         $lastline = "";
105     }
106 }
107
108
109 close(TDF);
110 close(OUT);