3 # This script generates the data structures for the machine description.
10 my $specfile = $ARGV[0];
11 my $target_dir = $ARGV[1];
22 unless ($return = do $specfile) {
23 warn "couldn't parse $specfile: $@" if $@;
24 warn "couldn't do $specfile: $!" unless defined $return;
25 warn "couldn't run $specfile" unless $return;
29 my $target_c = $target_dir."/gen_".$arch."_machine.c";
30 my $target_h = $target_dir."/gen_".$arch."_machine.h";
33 my @obst_unit_tp_defs; # stack for execution unit type defines
34 my @obst_unit_defs; # stack for execution unit defines
35 my @obst_init; # stack for cpu description initialization
36 my @obst_execunits; # stack for execunit variables
37 my @obst_execunits_header; # stack for execunit variables
38 my @obst_init_unit_types; # stack for unit type variable init
40 my $bundle_size = exists($vliw{"bundle_size"}) ? $vliw{"bundle_size"} : 3;
41 my $bundles_per_cycle = exists($vliw{"bundles_per_cycle"}) ? $vliw{"bundles_per_cycle"} : 1;
43 my $num_unit_types = scalar(keys(%cpu));
46 my $has_desc = defined(%cpu);
49 push(@obst_unit_tp_defs, "/* enum for execution unit types */\n");
50 push(@obst_unit_tp_defs, "enum $arch\_execunit_tp_vals {\n");
53 foreach my $unit_type (keys(%cpu)) {
54 my $tp_name = "$tmp\_EXECUNIT_TP_$unit_type";
55 my @cur_tp = @{ $cpu{"$unit_type"} };
56 my $num_units = scalar(@cur_tp);
58 push(@obst_init_unit_types, "\t{ $num_units, \"$unit_type\", $arch\_execution_units_$unit_type },\n");
59 push(@obst_execunits, "be_execution_unit_t $arch\_execution_units_".$unit_type."[$num_units];\n");
60 push(@obst_execunits_header, "extern be_execution_unit_t $arch\_execution_units_".$unit_type."[$num_units];\n");
62 push(@obst_unit_tp_defs, "\t$tp_name,\n");
63 push(@obst_init, "\n\t\t/* init of execution unit type $tp_name */\n");
64 push(@obst_init, "\t\tcur_unit_tp = &$arch\_execution_unit_types[$tp_name];\n");
66 push(@obst_unit_defs, "/* enum for execution units of type $unit_type */\n");
67 push(@obst_unit_defs, "enum $arch\_execunit_tp_$unit_type\_vals {\n");
68 foreach my $unit (@cur_tp) {
69 my $unit_name = "$tp_name\_$unit";
71 push(@obst_unit_defs, "\t$unit_name,\n");
72 push(@obst_init, "\t\t$arch\_execution_units_".$unit_type."[".$unit_name."].tp = cur_unit_tp;\n");
73 push(@obst_init, "\t\t$arch\_execution_units_".$unit_type."[".$unit_name."].name = \"$unit\";\n");
75 push(@obst_unit_defs, "};\n\n");
78 push(@obst_unit_tp_defs, "};\n\n") if ($has_desc);
80 open(OUT, ">$target_h") || die("Could not open $target_h, reason: $!\n");
82 my $creation_time = localtime(time());
85 #ifndef _GEN_$tmp\_MACHINE_H_
86 #define _GEN_$tmp\_MACHINE_H_
89 * Function prototypes for the machine description.
90 * DO NOT EDIT THIS FILE, your changes will be lost.
91 * Edit $specfile instead.
92 * created by: $0 $specfile $target_dir
93 * date: $creation_time
96 #include "../bemachine.h"
99 * Returns the $arch machine description.
101 const be_machine_t *$arch\_init_machine_description(void);
105 print OUT @obst_execunits_header, "\n";
106 print OUT @obst_unit_tp_defs;
107 print OUT @obst_unit_defs;
111 #endif /* _GEN_$tmp\_MACHINE_H_ */
117 open(OUT, ">$target_c") || die("Could not open $target_c, reason: $!\n");
119 $creation_time = localtime(time());
123 * Generated functions for machine description interface.
124 * DO NOT EDIT THIS FILE, your changes will be lost.
125 * Edit $specfile instead.
126 * created by: $0 $specfile $target_dir
127 * date: $creation_time
133 #include "gen_$arch\_machine.h"
137 print OUT @obst_execunits;
141 be_execution_unit_type_t $arch\_execution_unit_types[] = {
144 print OUT @obst_init_unit_types;
149 be_machine_t $arch\_cpu = {
153 $arch\_execution_unit_types
157 * Returns the $arch machines description
159 const be_machine_t *$arch\_init_machine_description(void) {
160 static int initialized = 0;
163 be_execution_unit_type_t *cur_unit_tp;
166 print OUT @obst_init;