removed unused header
[libfirm] / ir / be / scripts / generate_machine.pl
1 #!/usr/bin/perl -w
2
3 #
4 # Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
5 #
6 # This file is part of libFirm.
7 #
8 # This file may be distributed and/or modified under the terms of the
9 # GNU General Public License version 2 as published by the Free Software
10 # Foundation and appearing in the file LICENSE.GPL included in the
11 # packaging of this file.
12 #
13 # Licensees holding valid libFirm Professional Edition licenses may use
14 # this file in accordance with the libFirm Commercial License.
15 # Agreement provided with the Software.
16 #
17 # This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 # WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 # PURPOSE.
20 #
21
22 # This script generates the data structures for the machine description.
23 # Creation: 2006/10/20
24 # $Id$
25
26 use strict;
27 use Data::Dumper;
28
29 my $specfile   = $ARGV[0];
30 my $target_dir = $ARGV[1];
31
32 our $arch;
33 our %cpu;
34 our %vliw;
35
36 # include spec file
37
38 my $return;
39
40 no strict "subs";
41 unless ($return = do $specfile) {
42         die "couldn't parse $specfile: $@" if $@;
43         die "couldn't do $specfile: $!"    unless defined $return;
44         die "couldn't run $specfile"       unless $return;
45 }
46 use strict "subs";
47
48 my $target_c = $target_dir."/gen_".$arch."_machine.c";
49 my $target_h = $target_dir."/gen_".$arch."_machine.h";
50
51 # stacks for output
52 my @obst_unit_tp_defs;     # stack for execution unit type defines
53 my @obst_unit_defs;        # stack for execution unit defines
54 my @obst_init;             # stack for cpu description initialization
55 my @obst_execunits;        # stack for execunit variables
56 my @obst_execunits_header; # stack for execunit variables
57 my @obst_init_unit_types;  # stack for unit type variable init
58
59 my $bundle_size       = exists($vliw{"bundle_size"})       ? $vliw{"bundle_size"} : 3;
60 my $bundles_per_cycle = exists($vliw{"bundles_per_cycle"}) ? $vliw{"bundles_per_cycle"} : 1;
61
62 my $num_unit_types = scalar(keys(%cpu));
63 my $tmp            = uc($arch);
64 my $idx            = 0;
65 my $has_desc       = defined(%cpu);
66
67 if ($has_desc) {
68         push(@obst_unit_tp_defs, "/* enum for execution unit types */\n");
69         push(@obst_unit_tp_defs, "enum $arch\_execunit_tp_vals {\n");
70 }
71
72 foreach my $unit_type (keys(%cpu)) {
73         my $tp_name   = "$tmp\_EXECUNIT_TP_$unit_type";
74         my @cur_tp    = @{ $cpu{"$unit_type"} };
75         my $num_units = scalar(@cur_tp) - 1;
76
77         push(@obst_init_unit_types, "\t{ $num_units, ".shift(@cur_tp).", \"$unit_type\", $arch\_execution_units_$unit_type },\n");
78         push(@obst_execunits, "be_execution_unit_t $arch\_execution_units_".$unit_type."[$num_units];\n");
79         push(@obst_execunits_header, "extern be_execution_unit_t $arch\_execution_units_".$unit_type."[$num_units];\n");
80
81         push(@obst_unit_tp_defs, "\t$tp_name,\n");
82         push(@obst_init, "\n\t\t/* init of execution unit type $tp_name */\n");
83         push(@obst_init, "\t\tcur_unit_tp = &$arch\_execution_unit_types[$tp_name];\n");
84         push(@obst_init, "\t\t(void) cur_unit_tp; /* avoid warning */\n");
85
86         push(@obst_unit_defs, "/* enum for execution units of type $unit_type */\n");
87         push(@obst_unit_defs, "enum $arch\_execunit_tp_$unit_type\_vals {\n");
88
89         foreach my $unit (@cur_tp) {
90                 my $unit_name = "$tp_name\_$unit";
91
92                 push(@obst_unit_defs, "\t$unit_name,\n");
93                 push(@obst_init, "\t\t$arch\_execution_units_".$unit_type."[".$unit_name."].tp   = cur_unit_tp;\n");
94                 push(@obst_init, "\t\t$arch\_execution_units_".$unit_type."[".$unit_name."].name = \"$unit\";\n");
95         }
96         push(@obst_unit_defs, "};\n\n");
97 }
98
99 push(@obst_unit_tp_defs, "};\n\n") if ($has_desc);
100
101 open(OUT, ">$target_h") || die("Could not open $target_h, reason: $!\n");
102
103 my $creation_time = localtime(time());
104
105 print OUT<<EOF;
106 #ifndef _GEN_$tmp\_MACHINE_H_
107 #define _GEN_$tmp\_MACHINE_H_
108
109 /**
110  * Function prototypes for the machine description.
111  * DO NOT EDIT THIS FILE, your changes will be lost.
112  * Edit $specfile instead.
113  * created by: $0 $specfile $target_dir
114  * date:       $creation_time
115  */
116
117 #include "../bemachine.h"
118
119 /**
120  * Returns the $arch machine description.
121  */
122 const be_machine_t *$arch\_init_machine_description(void);
123
124 EOF
125
126 print OUT @obst_execunits_header, "\n";
127 print OUT @obst_unit_tp_defs;
128 print OUT @obst_unit_defs;
129
130 print OUT<<EOF;
131
132 #endif /* _GEN_$tmp\_MACHINE_H_ */
133
134 EOF
135
136 close(OUT);
137
138 open(OUT, ">$target_c") || die("Could not open $target_c, reason: $!\n");
139
140 $creation_time = localtime(time());
141
142 print OUT<<EOF;
143 /**
144  * Generated functions for machine description interface.
145  * DO NOT EDIT THIS FILE, your changes will be lost.
146  * Edit $specfile instead.
147  * created by: $0 $specfile $target_dir
148  * date:       $creation_time
149  */
150 #ifdef HAVE_CONFIG_H
151 #include "config.h"
152 #endif
153
154 #include "gen_$arch\_machine.h"
155
156 EOF
157
158 print OUT @obst_execunits;
159
160 print OUT<<EOF;
161
162 be_execution_unit_type_t $arch\_execution_unit_types[] = {
163 EOF
164
165 print OUT @obst_init_unit_types;
166
167 print OUT<<EOF;
168 };
169
170 be_machine_t $arch\_cpu = {
171         $bundle_size,
172         $bundles_per_cycle,
173         $num_unit_types,
174         $arch\_execution_unit_types
175 };
176
177 /**
178  * Returns the $arch machines description
179  */
180 const be_machine_t *$arch\_init_machine_description(void) {
181         static int initialized = 0;
182
183         if (! initialized) {
184                 be_execution_unit_type_t *cur_unit_tp;
185                 (void) cur_unit_tp; /* avoid warning */
186
187                 be_machine_init_dummy_unit();
188 EOF
189
190 print OUT @obst_init;
191
192 print OUT<<EOF;
193
194                 initialized = 1;
195         }
196
197         return &$arch\_cpu;
198 }
199
200 EOF
201
202 close(OUT);