4 # Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
6 # This file is part of libFirm.
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.
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.
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
22 # This script generates the data structures for the machine description.
23 # Creation: 2006/10/20
29 my $specfile = $ARGV[0];
30 my $target_dir = $ARGV[1];
41 unless ($return = do $specfile) {
42 die "Fatal error: couldn't parse $specfile: $@" if $@;
43 die "Fatal error: couldn't do $specfile: $!" unless defined $return;
44 die "Fatal error: couldn't run $specfile" unless $return;
48 my $target_c = $target_dir."/gen_".$arch."_machine.c";
49 my $target_h = $target_dir."/gen_".$arch."_machine.h";
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
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;
64 my $has_desc = defined(%cpu);
65 my $num_unit_types = scalar(keys(%cpu));
68 push(@obst_unit_tp_defs, "/* enum for execution unit types */\n");
69 push(@obst_unit_tp_defs, "enum $arch\_execunit_tp_vals {\n");
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;
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");
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");
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");
89 foreach my $unit (@cur_tp) {
90 my $unit_name = "$tp_name\_$unit";
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");
96 push(@obst_unit_defs, "};\n\n");
99 push(@obst_unit_tp_defs, "};\n\n") if ($has_desc);
101 open(OUT, ">$target_h") || die("Fatal error: Could not open $target_h, reason: $!\n");
103 my $creation_time = localtime(time());
108 * \@brief Function prototypes for the machine description.
109 * \@note DO NOT EDIT THIS FILE, your changes will be lost.
110 * Edit $specfile instead.
111 * created by: $0 $specfile $target_dir
112 * \@date $creation_time
114 #ifndef FIRM_BE_${tmp}_GEN_${tmp}_MACHINE_H
115 #define FIRM_BE_${tmp}_GEN_${tmp}_MACHINE_H
117 #include "../bemachine.h"
120 * Returns the $arch machine description.
122 const be_machine_t *$arch\_init_machine_description(void);
126 print OUT @obst_execunits_header, "\n";
127 print OUT @obst_unit_tp_defs;
128 print OUT @obst_unit_defs;
138 open(OUT, ">$target_c") || die("Fatal error: Could not open $target_c, reason: $!\n");
140 $creation_time = localtime(time());
145 * \@brief Generated functions for machine description interface.
146 * \@note DO NOT EDIT THIS FILE, your changes will be lost.
147 * Edit $specfile instead.
148 * created by: $0 $specfile $target_dir
149 * \@date $creation_time
153 #include "gen_$arch\_machine.h"
157 print OUT @obst_execunits;
161 be_execution_unit_type_t $arch\_execution_unit_types[] = {
164 print OUT @obst_init_unit_types;
169 be_machine_t $arch\_cpu = {
173 $arch\_execution_unit_types
177 * Returns the $arch machines description
179 const be_machine_t *$arch\_init_machine_description(void) {
180 static int initialized = 0;
183 be_execution_unit_type_t *cur_unit_tp;
184 (void) cur_unit_tp; /* avoid warning */
186 be_machine_init_dummy_unit();
189 print OUT @obst_init;