use irg from block instead of current_ir_graph in backend node constructors
[libfirm] / ir / be / scripts / generate_new_opcodes.pl
1 #!/usr/bin/perl -w
2
3 #
4 # Copyright (C) 1995-2008 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 C code which creates the irop's and
23 # their coresponding node constructors for all operations in a given spec
24 # so they can be used as normal firm nodes.
25 # Creation: 2005/10/19
26 # $Id$
27
28 use strict;
29 use Data::Dumper;
30
31 my $specfile   = $ARGV[0];
32 my $target_dir = $ARGV[1];
33 my $state      = 1;
34 my $cur_op     = "";
35 my $line_nr    = 0;
36
37 our $arch;
38 our $additional_opcodes;
39 our %nodes;
40 our %operands;
41 our %cpu;
42 our $default_op_attr_type;
43 our $default_attr_type;
44 our $default_cmp_attr;
45 our $default_copy_attr;
46 our %init_attr;
47 our $custom_init_attr_func;
48 our %compare_attr;
49 our %copy_attr;
50 our %reg_classes;
51 our %custom_irn_flags;
52
53 # include spec file
54
55 my $return;
56
57 no strict "subs";
58 unless ($return = do $specfile) {
59         die "Fatal error: couldn't parse $specfile: $@" if $@;
60         die "Fatal error: couldn't do $specfile: $!"    unless defined $return;
61         die "Fatal error: couldn't run $specfile"       unless $return;
62 }
63 use strict "subs";
64
65 my $target_c = $target_dir."/gen_".$arch."_new_nodes.c.inl";
66 my $target_h = $target_dir."/gen_".$arch."_new_nodes.h";
67
68 if(!defined($default_attr_type)) {
69         $default_attr_type = "${arch}_attr_t";
70 }
71 if(!defined(%init_attr)) {
72         %init_attr = (
73                 "$default_attr_type" => "\tinit_${arch}_attributes(res, flags, in_reqs, exec_units, n_res);",
74         );
75 }
76 if(!defined($default_cmp_attr)) {
77         $default_cmp_attr = "${arch}_compare_attr";
78 }
79 if(!defined(%compare_attr)) {
80         %compare_attr = (
81                 "${default_attr_type}" => "${default_cmp_attr}",
82         );
83 }
84
85 # Operands are really just nodes with some special constraints, we check
86 # these and create new entries in the nodes hashmap
87 foreach my $op (keys(%operands)) {
88         my %operand = %{ $operands{"$op"} };
89         my %op_node;
90
91         # constraints
92         if(defined($operand{op_flags})) { die "Fatal error: operands can't have op_flags ($op)"; }
93         if(defined($operand{cmp_attr})) { die "Fatal error: cmp_attr not allowed for operands ($op)"; }
94         if(defined($operand{mode})) { die "Operand must not have a mode defined ($op)"; }
95         if(defined($operand{out_arity})) { die "operand must not have out_arity defined ($op)"; }
96         if(defined($nodes{$op})) { die "$op defined as operand and as node"; };
97
98
99         foreach my $flag (keys(%operand)) {
100                 $op_node{$flag} = $operand{$flag};
101         }
102         $op_node{op_flags} = "O";
103         $op_node{cmp_attr} = 'return 1;';
104         $op_node{mode}     = 'mode_ANY';
105
106         $nodes{$op} = \%op_node;
107 }
108
109 #print Dumper(%nodes);
110 #print Dumper(%operands);
111
112 # create c code file from specs
113
114 my @obst_limit_func;
115 my @obst_reg_reqs;
116 my @obst_opvar;       # stack for the "ir_op *op_<arch>_<op-name> = NULL;" statements
117 my @obst_get_opvar;   # stack for the get_op_<arch>_<op-name>() functions
118 my $obst_constructor; # stack for node constructor functions
119 my @obst_new_irop;    # stack for the new_ir_op calls
120 my @obst_enum_op;     # stack for creating the <arch>_opcode enum
121 my $obst_header;      # stack for function prototypes
122 my @obst_is_archirn;  # stack for the is_$arch_irn() function
123 my @obst_cmp_attr;    # stack for the compare attribute functions
124 my $obst_proj = "";   # stack for the pn_ numbers
125 my $orig_op;
126 my $arity;
127 my $cmp_attr_func;
128 my $temp;
129 my $n_opcodes = 0;    # number of opcodes
130 my $ARITY_VARIABLE = -1;
131 my $ARITY_DYNAMIC  = -2;
132 my %requirements = ();
133 my %limit_bitsets = ();
134 my %reg2class = ();
135 my %regclass2len = ();
136
137 # build register->class hashes
138 foreach my $class_name (keys(%reg_classes)) {
139         my @class         = @{ $reg_classes{"$class_name"} };
140         my $old_classname = $class_name;
141
142         pop(@class);
143
144         $class_name = $arch."_".$class_name;
145
146         my $idx = 0;
147         foreach (@class) {
148                 $reg2class{$_->{name}} = {
149                         "class" => $old_classname,
150                         "index" => $idx
151                 };
152                 $idx++;
153         }
154
155         $regclass2len{$old_classname} = $idx;
156 }
157
158
159 # for registering additional opcodes
160 $n_opcodes += $additional_opcodes if (defined($additional_opcodes));
161
162 $obst_header .= "void ${arch}_create_opcodes(const arch_irn_ops_t *be_ops);\n";
163
164 sub create_constructor {
165         my $op   = shift;
166         my $name = shift;
167         my $n    = shift;
168         my $on   = shift;
169         my $known_mode;
170
171         my $suffix = "";
172         if ($name ne "") {
173                 $suffix = "_${name}";
174         }
175
176         # determine mode
177         if (exists($n->{mode})) {
178                 $known_mode = $n->{mode};
179         }
180
181         # determine arity
182         my $arity = 0;
183         if(exists($n->{"arity"})) {
184                 $arity = $n->{"arity"};
185         } elsif (exists($n->{"reg_req"}) && exists($n->{"reg_req"}{"in"})) {
186                 $arity = scalar(@{ $n->{"reg_req"}{"in"} });
187         } elsif (exists($n->{"ins"})) {
188                 $arity = scalar(@{ $n->{"ins"} });
189         }
190         if($arity eq "variable") {
191                 $arity = $ARITY_VARIABLE;
192         } elsif($arity eq "dynamic") {
193                 $arity = $ARITY_DYNAMIC;
194         }
195
196         # determine out arity
197         my $out_arity = 0;
198         if(exists($n->{"out_arity"})) {
199                 $out_arity = $n->{"out_arity"};
200         } elsif (exists($n->{"reg_req"}) && exists($n->{"reg_req"}{"out"})) {
201                 $out_arity = scalar(@{ $n->{"reg_req"}{"out"} });
202         } elsif (exists($n->{"outs"})) {
203                 $out_arity = scalar(@{ $n->{"outs"} });
204         }
205         if($out_arity eq "variable") {
206                 $out_arity = $ARITY_VARIABLE;
207         } elsif($out_arity eq "dynamic") {
208                 $out_arity = $ARITY_DYNAMIC;
209         }
210         if ($out_arity != 0 && $out_arity != 1 && !defined($known_mode)) {
211                 $known_mode = "mode_T";
212         }
213
214         my $comment = $n->{"comment"};
215         if(!exists($n->{"comment"})) {
216                 $comment = "construct ${orig_op} node";
217         }
218         $comment =
219                 "/**\n".
220                 " * ${comment}\n".
221                 " */\n";
222
223         $obst_constructor .= $comment;
224
225         # create constructor head
226         my $complete_args = "";
227         $temp             = "";
228
229         $temp = "ir_node *new_bd_${arch}_${op}${suffix}(dbg_info *dbgi, ir_node *block";
230         if (!exists($n->{"args"})) { # default args
231                 if ($arity == $ARITY_VARIABLE) {
232                         $complete_args = ", int arity, ir_node *in[]";
233                 } elsif ($arity == $ARITY_DYNAMIC) {
234                         $complete_args = "";
235                 } else {
236                         for (my $i = 0; $i < $arity; $i++) {
237                                 my $opname = "op${i}";
238                                 if (exists($n->{"ins"})) {
239                                         my @ins = @{ $n->{"ins"} };
240                                         $opname = $ins[$i];
241                                 }
242
243                                 $complete_args .= ", ir_node *${opname}";
244                         }
245                 }
246                 if ($out_arity == $ARITY_VARIABLE) {
247                         $complete_args .= ", int n_res";
248                 }
249
250                 if (!defined($known_mode)) {
251                         $complete_args .= ", ir_mode *mode";
252                 }
253         } else { # user defined args
254                 for my $href (@{ $n->{"args"} }) {
255                         $href->{"type"} .= " " if ($href->{"type"} !~ / [*]?$/); # put a space between name and type if there is none at the end
256                         $complete_args  .= ", ".$href->{"type"}.$href->{"name"};
257                 }
258         }
259
260         # we have additional attribute arguements
261         if (exists($n->{"attr"})) {
262                 $complete_args .= ", ".$n->{"attr"};
263         }
264
265         $temp .= "$complete_args)";
266         $obst_constructor .= "${temp}\n{\n";
267
268         $obst_header .= $comment;
269         $obst_header .= "${temp};\n";
270
271         # emit constructor code
272         $temp = <<EOF;
273         ir_graph         *irg     = get_irn_irg(block);
274         ir_op            *op      = op_${arch}_${op};
275         arch_irn_flags_t  flags   = arch_irn_flags_none;
276         ir_node          *res;
277         backend_info_t   *info;
278 EOF
279
280         if($arity == $ARITY_DYNAMIC) {
281                 $temp .= <<EOF;
282         int             arity   = -1;
283         ir_node       **in      = NULL;
284 EOF
285         } elsif($arity == $ARITY_VARIABLE) {
286         } else {
287                 $temp .= <<EOF;
288         int             arity   = $arity;
289 EOF
290                 if($arity > 0) {
291                         $temp .= <<EOF;
292         ir_node        *in[$arity];
293 EOF
294                 } else {
295                         $temp .= <<EOF;
296         ir_node       **in      = NULL;
297 EOF
298                 }
299         }
300         if($out_arity == $ARITY_DYNAMIC) {
301                 $temp .= <<EOF;
302         int             n_res   = -1;
303 EOF
304         } elsif($out_arity == $ARITY_VARIABLE) {
305         } else {
306                 $temp .= <<EOF;
307         int             n_res   = ${out_arity};
308 EOF
309         }
310
311         if (defined($known_mode)) {
312                 $temp .= <<EOF;
313         ir_mode        *mode    = ${known_mode};
314 EOF
315         }
316
317         # set up static variables for cpu execution unit assigments
318         if (exists($n->{"units"})) {
319                 $temp .= gen_execunit_list_initializer($n->{"units"});
320         } else {
321                 $temp .= <<EOF;
322         static const be_execution_unit_t ***exec_units = NULL;
323 EOF
324         }
325
326         undef my $in_req_var;
327         undef my $out_req_var;
328
329         my $set_out_reqs = "";
330
331         # set up static variables for requirements and registers
332         if (exists($n->{"reg_req"})) {
333                 my %req = %{ $n->{"reg_req"} };
334                 my $idx;
335
336                 undef my @in;
337                 @in = @{ $req{"in"} } if (exists($req{"in"}));
338                 undef my @out;
339                 @out = @{ $req{"out"} } if exists(($req{"out"}));
340
341                 for(my $idx = 0; $idx < $#in; $idx++) {
342                         my $req = $in[$idx];
343                         generate_requirements($req, $n, "${arch}_${op}", $idx, 1);
344                 }
345                 for(my $idx = 0; $idx < $#out; $idx++) {
346                         my $req = $out[$idx];
347                         generate_requirements($req, $n, "${arch}_${op}", $idx, 0);
348                 }
349
350                 if (@in) {
351                         if($arity >= 0 && scalar(@in) != $arity) {
352                                 die "Fatal error: Arity and number of in requirements don't match for ${op}\n";
353                         }
354
355                         $temp .= "\tstatic const arch_register_req_t *in_reqs[] =\n";
356                         $temp .= "\t{\n";
357                         for ($idx = 0; $idx <= $#in; $idx++) {
358                                 my $req = $in[$idx];
359                                 my $reqstruct = generate_requirements($req, $n, "${arch}_${op}", $idx, 1);
360                                 $temp .= "\t\t& ${reqstruct},\n";
361                         }
362                         $temp .= "\t};\n";
363                 } else {
364                         if($arity > 0) {
365                                 die "Fatal error: need in requirements for ${op}\n";
366                         }
367                         $temp .= "\tstatic const arch_register_req_t **in_reqs = NULL;\n";
368                 }
369
370                 if (@out) {
371                         if($out_arity >= 0 && scalar(@out) != $out_arity) {
372                                 die "Fatal error: Out-Arity and number of out requirements don't match for ${op}\n";
373                         }
374
375                         for ($idx = 0; $idx <= $#out; $idx++) {
376                                 my $req = $out[$idx];
377                                 my $reqstruct = generate_requirements($req, $n, "${arch}_${op}", $idx, 0);
378                                 $set_out_reqs .= <<EOF;
379         info->out_infos[${idx}].req = &${reqstruct};
380 EOF
381                         }
382                 } else {
383                         if($out_arity > 0) {
384                                 die "Fatal error: need out requirements for ${op}\n";
385                         }
386                 }
387         } else {
388                 $temp .= "\tstatic const arch_register_req_t **in_reqs = NULL;\n";
389         }
390         my $attr_type = $on->{attr_type};
391         if(exists($n->{"init_attr"})) {
392                 $temp .= "\t${attr_type} *attr;\n";
393         }
394
395         $temp .= "\n";
396
397         if($arity > 0) {
398                 $temp .= "\t/* construct in array */\n";
399                 for (my $i = 0; $i < $arity; $i++) {
400                         my $opname = "op${i}";
401                         if (exists($n->{"ins"})) {
402                                 my @ins = @{ $n->{"ins"} };
403                                 $opname = $ins[$i];
404                         }
405
406                         $temp .= "\tin[${i}] = ${opname};\n";
407                 }
408                 $temp .= "\n";
409         }
410
411         # set flags
412         if (exists($n->{"irn_flags"})) {
413                 $temp .= "\t/* flags */\n";
414                 my %known_irn_flags = (
415                         "none"             => "arch_irn_flags_none",
416                         "dont_spill"       => "arch_irn_flags_dont_spill",
417                         "rematerializable" => "arch_irn_flags_rematerializable",
418                         "modify_flags"     => "arch_irn_flags_modify_flags",
419                         "simple_jump"      => "arch_irn_flags_simple_jump",
420                         "not_scheduled"    => "arch_irn_flags_not_scheduled",
421                 );
422                 if (defined(%custom_irn_flags)) {
423                         %known_irn_flags = (%known_irn_flags, %custom_irn_flags);
424                 }
425                 foreach my $flag (@{$n->{"irn_flags"}}) {
426                         if (not defined($known_irn_flags{$flag})) {
427                                 print STDERR "WARNING: irn_flag '$flag' in opcode $op is unknown\n";
428                         } else {
429                                 $temp .= "\tflags |= " . $known_irn_flags{$flag} . ";\n";
430                         }
431                 }
432                 $temp .= "\n";
433         }
434
435         # lookup init function
436         my $attr_init_code = "(void)in;(void)exec_units;(void)flags;(void)in_reqs;(void)n_res;";
437         if ($attr_type ne "") {
438                 $attr_init_code = $init_attr{$attr_type};
439                 if(!defined($attr_init_code)) {
440                         die "Fatal error: Couldn't find attribute initialisation code for type '${attr_type}'";
441                 }
442         }
443         my $custominit = "";
444         if(defined($custom_init_attr_func)) {
445                 $custominit .= &$custom_init_attr_func($n, $on, "${arch}_${op}");
446         }
447         if(defined($n->{custominit})) {
448                 $custominit .= $n->{custominit};
449         }
450
451         $temp .= <<EOF;
452         /* create node */
453         assert(op != NULL);
454         res = new_ir_node(dbgi, irg, block, op, mode, arity, in);
455
456         /* init node attributes */
457         ${attr_init_code}
458         ${custominit}
459         info = be_get_info(res);
460         (void) info; /* avoid potential warning */
461 ${set_out_reqs}
462
463 EOF
464
465         if (exists($n->{"init_attr"})) {
466                 $temp .= "\tattr = (${attr_type}*)get_irn_generic_attr(res);\n";
467                 $temp .= "\t".$n->{"init_attr"}."\n";
468         }
469
470         $temp .= <<EOF;
471         /* optimize node */
472         res = optimize_node(res);
473         irn_verify_irg(res, irg);
474
475         return res;
476 EOF
477
478         $obst_constructor .= $temp;
479
480         # close constructor function
481         $obst_constructor .= "}\n\n";
482 }
483
484 push(@obst_enum_op, "typedef enum ${arch}_opcodes {\n");
485 foreach my $op (keys(%nodes)) {
486         my %n        = %{ $nodes{"$op"} };
487         my $known_mode;
488         my $num_outs = 0;
489         my $out_arity;
490         my @out_flags;
491
492         # determine arity
493         $arity = 0;
494         if(exists($n{"arity"})) {
495                 $arity = $n{"arity"};
496         } elsif (exists($n{"reg_req"}) && exists($n{"reg_req"}{"in"})) {
497                 $arity = scalar(@{ $n{"reg_req"}{"in"} });
498         } elsif (exists($n{"ins"})) {
499                 $arity = scalar(@{ $n{"ins"} });
500         }
501         if($arity eq "variable") {
502                 $arity = $ARITY_VARIABLE;
503         } elsif($arity eq "dynamic") {
504                 $arity = $ARITY_DYNAMIC;
505         }
506
507         # determine out arity
508         $out_arity = 0;
509         if(exists($n{"out_arity"})) {
510                 $out_arity = $n{"out_arity"};
511         } elsif (exists($n{"reg_req"}) && exists($n{"reg_req"}{"out"})) {
512                 $out_arity = scalar(@{ $n{"reg_req"}{"out"} });
513         } elsif (exists($n{"outs"})) {
514                 $out_arity = scalar(@{ $n{"outs"} });
515         }
516         if($out_arity eq "variable") {
517                 $out_arity = $ARITY_VARIABLE;
518         } elsif($out_arity eq "dynamic") {
519                 $out_arity = $ARITY_DYNAMIC;
520         }
521
522         $orig_op = $op;
523         $op      = $arch."_".$op;
524         $temp    = "";
525
526         # define proj numbers and in numbers
527         if (exists($n{"outs"})) {
528                 undef my @outs;
529
530                 @outs = @{ $n{"outs"} };
531                 if($out_arity >= 0 && scalar(@outs) != $out_arity) {
532                         die "Fatal error: Op ${op} has different number of outs and out_arity\n";
533                 }
534
535                 $num_outs = $#outs + 1;
536
537                 if ($num_outs > 0) {
538                         $obst_proj .= "\nenum pn_${op} {\n";
539
540                         for (my $idx = 0; $idx <= $#outs; $idx++) {
541                                 # check, if we have additional flags annotated to out
542                                 if ($outs[$idx] =~ /:((S|I)(\|(S|I))*)/) {
543                                         push(@out_flags, $1);
544                                         $outs[$idx] =~ s/:((S|I)(\|(S|I))*)//;
545                                 }
546                                 $obst_proj .= "\tpn_${op}_".$outs[$idx]." = ${idx},\n";
547                         }
548
549                         $obst_proj .= "};\n";
550                 }
551                 # outs have names, it must be a mode_T node
552                 if (!defined($n{mode})) {
553                         $n{mode} = "mode_T";
554                 }
555         }
556         if (exists($n{"ins"})) {
557                 undef my @ins;
558
559                 @ins = @{ $n{"ins"} };
560                 if($arity >= 0 && scalar(@ins) != $arity) {
561                         die "Fatal error: Op ${op} has different number of ins and arity\n";
562                 }
563
564                 if ($#ins >= 0) {
565                         $obst_proj .= "\nenum n_$op {\n";
566                         for (my $idx = 0; $idx <= $#ins; $idx++) {
567                                 $obst_proj .= "\tn_${op}_".$ins[$idx]." = ${idx},\n";
568                         }
569                         $obst_proj .= "};\n";
570                 }
571         }
572
573         # Create opcode
574         push(@obst_opvar, "ir_op *op_$op = NULL;\n");
575         push(@obst_get_opvar, "ir_op *get_op_$op(void)         { return op_$op; }\n");
576         push(@obst_get_opvar, "int    is_$op(const ir_node *n) { return get_$arch\_irn_opcode(n) == iro_$op; }\n\n");
577
578         push(@obst_is_archirn, "is_$op(node)");
579
580         $obst_header .= <<EOF;
581 extern ir_op *op_${op};
582 ir_op *get_op_${op}(void);
583 int is_${op}(const ir_node *n);
584 EOF
585
586         my $attr_type= $n{attr_type};
587         if(!defined($attr_type)) {
588                 $attr_type = $default_attr_type;
589                 $n{attr_type} = $attr_type;
590         }
591
592         # determine hash function
593         my $hash_func;
594         if (exists($n{"hash_func"})) {
595                 $hash_func = $n{"hash_func"};
596         }
597
598         # determine compare function
599         my $cmp_attr_func;
600         if (exists($n{"cmp_attr"})) {
601                 my $cmpcode = $n{"cmp_attr"};
602
603                 push(@obst_cmp_attr, "static int cmp_attr_$op(const ir_node *a, const ir_node *b) {\n");
604                 if($cmpcode =~ m/attr_a/) {
605                         push(@obst_cmp_attr, "\tconst ${attr_type} *attr_a = get_irn_generic_attr_const(a);\n");
606                 } else {
607                         push(@obst_cmp_attr, "\t(void) a;\n");
608                 }
609                 if($cmpcode =~ m/attr_b/) {
610                         push(@obst_cmp_attr, "\tconst ${attr_type} *attr_b = get_irn_generic_attr_const(b);\n");
611                 } else {
612                         push(@obst_cmp_attr, "\t(void) b;\n");
613                 }
614                 push(@obst_cmp_attr, "\t${cmpcode}\n");
615                 push(@obst_cmp_attr, "}\n\n");
616
617                 $cmp_attr_func = "cmp_attr_${op}";
618         } elsif ($attr_type eq "") {
619                 $cmp_attr_func = "NULL";
620         } else {
621                 if(defined($compare_attr{${attr_type}})) {
622                         $cmp_attr_func = $compare_attr{${attr_type}};
623                 } else {
624                         die "Fatal error: No compare function defined for ${attr_type} attributes.";
625                 }
626         }
627
628         my %constructors;
629         if (exists($n{constructors})) {
630                 %constructors = %{ $n{constructors} };
631         } else {
632                 # Create 1 default constructor
633                 my %constructor = ();
634                 foreach my $a ("comment", "ins", "outs", "args", "attr", "units",
635                                 "reg_req", "init_attr", "irn_flags", "mode", "arity",
636                                 "out_arity", "custominit") {
637                         if (defined($n{$a})) {
638                                 $constructor{$a} = $n{$a};
639                         }
640                 }
641                 %constructors = ( "" => \%constructor );
642         }
643
644         foreach my $constr (keys(%constructors)) {
645                 my %cstr = %{ $constructors{$constr} };
646                 # Copy some values from outer node if they don't exists in the constr
647                 foreach my $a ("ins", "outs", "irn_flags", "mode", "args", "attr",
648                                "custominit") {
649                         if (!defined($cstr{$a}) && defined($n{$a})) {
650                                 $cstr{$a} = $n{$a};
651                         }
652                 }
653                 create_constructor($orig_op, $constr, \%cstr, \%n);
654         }
655
656         # set default values for state and flags if not given
657         $n{"state"}    = "floats" if (! exists($n{"state"}));
658         $n{"op_flags"} = ["none"] if (! exists($n{"op_flags"}));
659
660         push(@obst_new_irop, "\n\tmemset(&ops, 0, sizeof(ops));\n");
661         push(@obst_new_irop, "\tops.be_ops        = be_ops;\n");
662         push(@obst_new_irop, "\tops.dump_node     = $arch\_dump_node;\n");
663
664         if (defined($cmp_attr_func)) {
665                 push(@obst_new_irop, "\tops.node_cmp_attr = ${cmp_attr_func};\n");
666         }
667         my $copy_attr_func = $copy_attr{$attr_type};
668         if (!defined($copy_attr_func)) {
669                 $copy_attr_func = $default_copy_attr;
670         }
671         if (defined($copy_attr_func)) {
672                 push(@obst_new_irop, "\tops.copy_attr = ${copy_attr_func};\n");
673         }
674         if (defined($hash_func)) {
675                 push(@obst_new_irop, "\tops.hash = ${hash_func};\n");
676         }
677
678         my %known_flags = map { $_ => 1 } (
679                 "none", "labeled", "commutative", "cfopcode", "unknown_jump", "fragile",
680                 "forking", "highlevel", "constlike", "always_opt", "keep",
681                 "start_block", "uses_memory", "dump_noblock", "dump_noinput",
682                 "machine", "machine_op", "cse_neutral"
683         );
684         foreach my $flag (@{$n{"op_flags"}}) {
685                 if (not defined($known_flags{$flag})) {
686                         print STDERR "WARNING: Flag '$flag' in opcode $op is unknown\n";
687                 }
688         }
689         my @mapped = map { "irop_flag_$_" } @{$n{"op_flags"}};
690         my $op_flags = join('|', @mapped);
691
692         my $attr_size = "0";
693         if ($attr_type ne "") {
694                 $attr_size = "sizeof(${attr_type})"
695         }
696
697         $n_opcodes++;
698         $temp  = "\top_$op = new_ir_op(cur_opcode + iro_$op, \"$op\", op_pin_state_".$n{"state"}.", $op_flags";
699         $temp .= "|irop_flag_machine, ".translate_arity($arity).", 0, ${attr_size}, &ops);\n";
700         push(@obst_new_irop, $temp);
701         push(@obst_new_irop, "\tset_op_tag(op_$op, $arch\_op_tag);\n");
702         if(defined($default_op_attr_type)) {
703                 push(@obst_new_irop, "\tattr = &attrs[iro_$op];\n");
704                 if(defined($n{op_attr_init})) {
705                         push(@obst_new_irop, "\t".$n{op_attr_init}."\n");
706                 }
707                 push(@obst_new_irop, "\tset_op_attr(op_$op, attr);\n");
708         }
709
710         push(@obst_enum_op, "\tiro_$op,\n");
711
712         $obst_header .= "\n";
713 }
714 push(@obst_enum_op, "\tiro_$arch\_last_generated,\n");
715 push(@obst_enum_op, "\tiro_$arch\_last = iro_$arch\_last_generated");
716 push(@obst_enum_op, " + $additional_opcodes") if (defined($additional_opcodes));
717 push(@obst_enum_op, "\n} $arch\_opcodes;\n\n");
718
719 # emit the code
720
721 open(OUT, ">$target_c") || die("Fatal error: Could not open $target_c, reason: $!\n");
722
723 print OUT "#include \"gen_$arch\_regalloc_if.h\"\n";
724 print OUT "#include \"irverify_t.h\"\n";
725 print OUT "\n";
726 print OUT @obst_cmp_attr;
727 print OUT "\n";
728 print OUT @obst_opvar;
729 print OUT "\n";
730 print OUT @obst_get_opvar;
731 print OUT "\n";
732
733 print OUT<<EOF;
734
735 static int $arch\_opcode_start = -1;
736 static int $arch\_opcode_end   = -1;
737
738 EOF
739
740 # build the FOURCC arguments from $arch
741
742 my ($a, $b, $c, $d) = ('\0', '\0', '\0', '\0');
743
744 if (length($arch) >= 1) {
745         $a = uc(substr($arch, 0, 1));
746 }
747
748 if (length($arch) >= 2) {
749         $b = uc(substr($arch, 1, 1));
750 }
751
752 if (length($arch) >= 3) {
753         $c = uc(substr($arch, 2, 1));
754 }
755
756 if (length($arch) >= 4) {
757         $d = uc(substr($arch, 3, 1));
758 }
759
760 print OUT<<ENDOFISIRN;
761
762 /** A tag for the $arch opcodes. Note that the address is used as a tag value, NOT the FOURCC code. */
763 #define $arch\_op_tag FOURCC('$a', '$b', '$c', '$d')
764
765 /** Return the opcode number of the first $arch opcode. */
766 int get_$arch\_opcode_first(void) {
767         return $arch\_opcode_start;
768 }
769
770 /** Return the opcode number of the last $arch opcode + 1. */
771 int get_$arch\_opcode_last(void) {
772         return $arch\_opcode_end;
773 }
774
775 /** Return 1 if the given opcode is a $arch machine op, 0 otherwise */
776 int is_$arch\_op(const ir_op *op) {
777         return get_op_tag(op) == $arch\_op_tag;
778 }
779
780 /** Return 1 if the given node is a $arch machine node, 0 otherwise */
781 int is_$arch\_irn(const ir_node *node) {
782         return is_$arch\_op(get_irn_op(node));
783 }
784
785 int get_$arch\_irn_opcode(const ir_node *node) {
786         if (is_$arch\_irn(node))
787                 return get_irn_opcode(node) - $arch\_opcode_start;
788         return -1;
789 }
790
791 ENDOFISIRN
792
793 print OUT <<END;
794 #ifdef BIT
795 #undef BIT
796 #endif
797 #define BIT(x)  (1 << (x))
798
799 END
800
801 print OUT @obst_limit_func;
802 print OUT "\n";
803
804 print OUT @obst_reg_reqs;
805 print OUT "\n";
806
807 print OUT<<ENDOFMAIN;
808 $obst_constructor
809
810 /**
811  * Creates the $arch specific Firm machine operations
812  * needed for the assembler irgs.
813  */
814 void $arch\_create_opcodes(const arch_irn_ops_t *be_ops) {
815         ir_op_ops  ops;
816         int        cur_opcode;
817         static int run_once = 0;
818 ENDOFMAIN
819
820         if (defined($default_op_attr_type)) {
821                 print OUT "\t$default_op_attr_type *attr, *attrs;\n";
822         }
823
824 print OUT<<ENDOFMAIN;
825
826         if (run_once)
827                 return;
828         run_once = 1;
829
830         cur_opcode = get_next_ir_opcodes(iro_$arch\_last);
831
832         $arch\_opcode_start = cur_opcode;
833 ENDOFMAIN
834
835         if (defined($default_op_attr_type)) {
836                 print OUT "\tattrs = XMALLOCNZ(${default_op_attr_type}, iro_${arch}_last);\n";
837         }
838
839 print OUT @obst_new_irop;
840 print OUT "\n";
841 print OUT "\t$arch\_register_additional_opcodes(cur_opcode);\n" if (defined($additional_opcodes));
842 print OUT "\t$arch\_opcode_end = cur_opcode + iro_$arch\_last";
843 print OUT " + $additional_opcodes" if (defined($additional_opcodes));
844 print OUT ";\n";
845 print OUT "}\n";
846
847 close(OUT);
848
849 open(OUT, ">$target_h") || die("Fatal error: Could not open $target_h, reason: $!\n");
850
851 my $creation_time = localtime(time());
852 my $tmp = uc($arch);
853
854 print OUT<<EOF;
855 /**
856  * \@file
857  * \@brief Function prototypes for the new opcode functions.
858  * \@note  DO NOT EDIT THIS FILE, your changes will be lost.
859  *        Edit $specfile instead.
860  *        created by: $0 $specfile $target_dir
861  * \@date  $creation_time
862  */
863 #ifndef FIRM_BE_${tmp}_GEN_${tmp}_NEW_NODES_H
864 #define FIRM_BE_${tmp}_GEN_${tmp}_NEW_NODES_H
865
866 EOF
867
868 print OUT @obst_enum_op;
869 print OUT <<EOF;
870 int is_${arch}_irn(const ir_node *node);
871 int is_${arch}_op(const ir_op *op);
872
873 int get_${arch}_opcode_first(void);
874 int get_${arch}_opcode_last(void);
875 int get_${arch}_irn_opcode(const ir_node *node);
876 ${obst_header}
877 ${obst_proj}
878
879 #endif
880 EOF
881
882 close(OUT);
883
884 ###
885 # Translates numeric arity into string constant.
886 ###
887 sub translate_arity {
888         my $arity = shift;
889
890         if ($arity =~ /^\d+$/) {
891                 if    ($arity == 0) {
892                         return "oparity_zero";
893                 }
894                 elsif ($arity == 1) {
895                         return "oparity_unary";
896                 }
897                 elsif ($arity == 2) {
898                         return "oparity_binary";
899                 }
900                 elsif ($arity == 3) {
901                         return "oparity_trinary";
902                 }
903                 else {
904                         return "oparity_any";
905                 }
906         } elsif ($arity == $ARITY_VARIABLE) {
907                 return "oparity_variable";
908         } elsif ($arity == $ARITY_DYNAMIC) {
909                 return "oparity_dynamic";
910         } else {
911                 die "Fatal error: Unknown arity $arity";
912         }
913 }
914
915 ###
916 # Return the list of pointers for the given execution units.
917 ###
918 sub gen_execunit_list_initializer {
919         my $units   = shift;
920         my $uc_arch = uc($arch);
921         my $ret     = "";
922         my $ret2    = "";
923         my %init;
924
925         foreach my $unit (@{ $units }) {
926                 if ($unit eq "DUMMY") {
927                         push(@{ $init{"DUMMY"} }, "\t\t&be_machine_execution_units_DUMMY[0]");
928                 }
929                 elsif (exists($cpu{"$unit"})) {
930                         # operation can be executed on all units of this type
931                         # -> add them all
932                         my $tp_name = "$arch\_execution_units_$unit";
933                         my $idx     = 0;
934                         foreach (@{ $cpu{"$unit"} }) {
935                                 next if ($idx++ == 0);  # skip first element (it's not a unit)
936                                 my $unit_name = "$uc_arch\_EXECUNIT_TP_$unit\_$_";
937                                 push(@{ $init{"$unit"} }, "\t\t&".$tp_name."[".$unit_name."]");
938                         }
939                 }
940                 else {
941                         # operation can be executed only a certain unit
942                         # -> find corresponding unit type
943                         my $found = 0;
944 TP_SEARCH:      foreach my $cur_type (keys(%cpu)) {
945                                 foreach my $cur_unit (@{ $cpu{"$cur_type"} }) {
946                                         if ($unit eq $cur_unit) {
947                                                 my $tp_name   = "$arch\_execution_units_$cur_type";
948                                                 my $unit_name = "$uc_arch\_EXECUNIT_TP_$cur_type\_$unit";
949                                                 push(@{ $init{"$unit"} }, "\t\t&".$tp_name."[".$unit_name."]");
950                                                 $found = 1;
951                                                 last TP_SEARCH;
952                                         }
953                                 }
954                         }
955
956                         if (! $found) {
957                                 print STDERR "Invalid execution unit $unit specified!\n";
958                         }
959                 }
960         }
961
962         # prepare the 2-dim array init
963         foreach my $key (keys(%init)) {
964                 $ret .= "\tstatic const be_execution_unit_t *allowed_units_".$key."[] =\n";
965                 $ret .= "\t{\n";
966                 foreach (@{ $init{"$key"} }) {
967                         $ret .= "$_,\n";
968                 }
969                 $ret .= "\t\tNULL\n";
970                 $ret .= "\t};\n";
971                 $ret2 .= "\t\tallowed_units_$key,\n";
972         }
973         $ret2 .= "\t\tNULL\n";
974
975         $ret .= "\tstatic const be_execution_unit_t **exec_units[] =\n";
976         $ret .= "\t{\n";
977         $ret .= $ret2;
978         $ret .= "\t};\n";
979
980         return $ret;
981 }
982
983 sub mangle_requirements {
984         my $reqs  = shift;
985         my $class = shift;
986         my $flags = shift;
987
988         my @alternatives = split(/ /, $reqs);
989         for(my $idx = 0; $idx < scalar(@alternatives); $idx++) {
990                 $alternatives[$idx] =~ s/!/not_/g;
991         }
992
993         @alternatives = sort @alternatives;
994
995         my $name = $class."_".join('_', @alternatives);
996         if (defined($flags)) {
997                 $flags =~ s/\|/_/g;
998                 $name .= "_$flags";
999         }
1000
1001         return $name;
1002 }
1003
1004 ###
1005 # Determines whether $name is a specified register class or not.
1006 # @return 1 if name is register class, 0 otherwise
1007 ###
1008 sub is_reg_class {
1009     my $name = shift;
1010     return 1 if exists($reg_classes{"$name"});
1011     return 0;
1012 }
1013
1014 ###
1015 # Returns the register class for a given register.
1016 # @return class or undef
1017 ###
1018 sub get_reg_class {
1019     my $reg = shift;
1020     $reg = substr($reg, 1) if ($reg =~ /!.*/);
1021     return $reg2class{"$reg"}{"class"} if (exists($reg2class{"$reg"}));
1022     return undef;
1023 }
1024
1025 ###
1026 # Returns the index of a given register within its register class.
1027 # @return index or undef
1028 ###
1029 sub get_reg_index {
1030     my $reg = shift;
1031     return $reg2class{"$reg"}{"index"} if (exists($reg2class{"$reg"}));
1032     return undef;
1033 }
1034
1035 ###
1036 # Remember the register class for each index in the given requirements.
1037 # We need this information for requirements like "in_sX" or "out_dX"
1038 # @return array of classes corresponding to the requirement for each index
1039 ###
1040 sub build_inout_idx_class {
1041         my $n     = shift;
1042         my $op    = shift;
1043         my $is_in = shift;
1044         my @idx_class;
1045
1046         my $inout = ($is_in ? "in" : "out");
1047
1048         if (exists($n->{"reg_req"}{"$inout"})) {
1049                 my @reqs = @{ $n->{"reg_req"}{"$inout"} };
1050
1051                 for (my $idx = 0; $idx <= $#reqs; $idx++) {
1052                         my $class = undef;
1053                         my ($req,) = split(/:/, $reqs[$idx]);
1054
1055                         if ($req eq "none") {
1056                                 $class = "none";
1057                         } elsif (is_reg_class($req)) {
1058                                 $class = $req;
1059                         } else {
1060                                 my @regs = split(/ /, $req);
1061 GET_CLASS:              foreach my $reg (@regs) {
1062                                         if ($reg =~ /!?(in|out)\_r\d+/ || $reg =~ /!in/) {
1063                                                 $class = "UNKNOWN_CLASS";
1064                                         } else {
1065                                                 $class = get_reg_class($reg);
1066                                                 if (!defined $class) {
1067                                                         die("Fatal error: Could not get ".uc($inout)." register class for '$op' pos $idx (reg $reg) ... exiting.\n");
1068                                                 } else {
1069                                                         last GET_CLASS;
1070                                                 } # !defined class
1071                                         } # if (reg =~ ...
1072                                 } # foreach
1073                         } # if
1074
1075                         push(@idx_class, $class);
1076                 } # for
1077         } # if
1078
1079         return @idx_class;
1080 }
1081
1082 ###
1083 # Generates the function for a given $op and a given IN-index
1084 # which returns a subset of possible register from a register class
1085 # @return classname from which the subset is derived or undef and
1086 #         pos which corresponds to in/out reference position or undef
1087 ###
1088 sub build_subset_class_func {
1089         my $neg           = undef;
1090         my $class         = undef;
1091         my $has_limit     = 0;
1092         my $limit_name;
1093         my $same_pos      = 0;
1094         my $different_pos = 0;
1095         my $temp;
1096         my @obst_init;
1097         my @obst_limits;
1098         my @obst_ignore;
1099         my @limit_array;
1100         my $limit_reqs;   #used for name mangling
1101
1102         # build function header
1103         my $node  = shift;
1104         my $op    = shift;
1105         my $idx   = shift;
1106         my $is_in = shift;
1107         my @regs  = split(/ /, shift);
1108         my $flags = shift;
1109
1110         my @idx_class = build_inout_idx_class($node, $op, !$is_in);
1111
1112         # set/unset registers
1113 CHECK_REQS: foreach (@regs) {
1114                 if (!$is_in && /(!)?in_r(\d+)/) {
1115                         my $bit_pos = 1 << ($2 - 1);
1116                         if ($different_pos & $bit_pos) {
1117                                 if ($1) {
1118                                         print STDERR "duplicate !in constraint\n";
1119                                 } else {
1120                                         print STDERR "conflicting !in and in constraints\n";
1121                                 }
1122                                 return (undef, undef, undef, undef);
1123                         }
1124
1125                         if ($same_pos & $bit_pos) {
1126                                 if ($1) {
1127                                         print STDERR "conflicting !in and in constraints\n";
1128                                 } else {
1129                                         print STDERR "duplicate in constraint\n";
1130                                 }
1131                                 return (undef, undef, undef, undef);
1132                         }
1133
1134                         if ($1) {
1135                                 $different_pos |= $bit_pos;
1136                         } else {
1137                                 $same_pos      |= $bit_pos;
1138                         }
1139
1140                         $class = $idx_class[$2 - 1];
1141                         next CHECK_REQS;
1142                 }
1143
1144                 # check for negate
1145                 if (substr($_, 0, 1) eq "!") {
1146                         if (defined($neg) && $neg == 0) {
1147                                 # we have seen a positiv constraint as first one but this one is negative
1148                                 # this doesn't make sense
1149                                 print STDERR "Mixed positive and negative constraints for the same slot are not allowed.\n";
1150                                 return (undef, undef, undef, undef);
1151                         }
1152
1153                         if (!defined($neg)) {
1154                                 $has_limit = 1;
1155                         }
1156
1157                         $_   = substr($_, 1); # skip '!'
1158                         $neg = 1;
1159                 } else {
1160                         if (defined($neg) && $neg == 1) {
1161                                 # we have seen a negative constraint as first one but this one is positive
1162                                 # this doesn't make sense
1163                                 print STDERR "Mixed positive and negative constraints for the same slot are not allowed.\n";
1164                                 return (undef, undef, undef, undef);
1165                         }
1166
1167                         $has_limit = 1;
1168                         $neg = 0;
1169                 }
1170
1171                 # check if register belongs to one of the given classes
1172                 $temp = get_reg_class($_);
1173                 if (!defined($temp)) {
1174                         print STDERR "Unknown register '$_'!\n";
1175                         return (undef, undef, undef, undef);
1176                 }
1177
1178                 # set class
1179                 if (!defined($class)) {
1180                         $class = $temp;
1181                 } elsif ($class ne $temp) {
1182                         # all registers must belong to the same class
1183                         print STDERR "Registerclass mismatch. '$_' is not member of class '$class'.\n";
1184                         return (undef, undef, undef, undef);
1185                 }
1186
1187                 # calculate position inside the initializer bitfield (only 32 bits per
1188                 # element)
1189                 my $regidx = get_reg_index($_);
1190                 my $arrayp = $regidx / 32;
1191                 push(@{$limit_array[$arrayp]}, $_);
1192                 $limit_reqs .= "$_ ";
1193         }
1194
1195         # don't allow ignore regs in negative constraints
1196         if($neg) {
1197                 my @cur_class = @{ $reg_classes{"$class"} };
1198                 for (my $idx = 0; $idx <= $#cur_class; $idx++) {
1199                         if (defined($cur_class[$idx]{"type"}) && ($cur_class[$idx]{"type"} & 4)) {
1200                                 my $reg    = $cur_class[$idx]{"name"};
1201                                 my $regix  = get_reg_index($reg);
1202                                 my $arrayp = $regix / 32;
1203                                 push(@{$limit_array[$arrayp]}, $reg);
1204                                 $limit_reqs .= "$reg ";
1205                         }
1206                 }
1207         }
1208
1209         if ($has_limit == 1) {
1210                 $limit_name = "${arch}_limit_".mangle_requirements($limit_reqs, $class);
1211
1212                 if(defined($limit_bitsets{$limit_name})) {
1213                         $limit_name = $limit_bitsets{$limit_name};
1214                         return ($class, $limit_name, $same_pos, $different_pos);
1215                 }
1216
1217                 $limit_bitsets{$limit_name} = $limit_name;
1218
1219                 push(@obst_limit_func, "static const unsigned " . $limit_name . "[] = { ");
1220                 my $first = 1;
1221                 my $limitbitsetlen = $regclass2len{$class};
1222                 my $limitarraylen = ($limitbitsetlen+31) / 32;
1223                 for(my $i = 0; $i < $limitarraylen; $i++) {
1224
1225                         my $limitarraypart = $limit_array[$i];
1226                         if($first) {
1227                                 $first = 0;
1228                         } else {
1229                                 push(@obst_limit_func, ", ");
1230                         }
1231                         my $temp;
1232                         if($neg) {
1233                                 $temp = "0xFFFFFFFF";
1234                         }
1235                         foreach my $reg (@{$limitarraypart}) {
1236                                 if($neg) {
1237                                         $temp .= " & ~";
1238                                 } elsif(defined($temp)) {
1239                                         $temp .= " | ";
1240                                 }
1241                                 my $firstreg = uc($reg_classes{$class}[0]->{"name"});
1242                                 my $classuc = uc($class);
1243                                 my $reguc = uc($reg);
1244                                 $temp .= "BIT(REG_${classuc}_${reguc})";
1245                         }
1246                         if(defined($temp)) {
1247                                 push(@obst_limit_func, "${temp}");
1248                         } else {
1249                                 push(@obst_limit_func, "0");
1250                         }
1251                 }
1252                 push(@obst_limit_func, " };\n");
1253         }
1254
1255         return ($class, $limit_name, $same_pos, $different_pos);
1256 }
1257
1258 ###
1259 # Generate register requirements structure
1260 ###
1261 sub generate_requirements {
1262         my ($reqs, $flags) = split(/:/, shift);
1263         my $node  = shift;
1264         my $op    = shift;
1265         my $idx   = shift;
1266         my $is_in = shift;
1267         my $class = "";
1268         my $width = 1;
1269         my $result;
1270
1271         my @req_type_mask;
1272         if (defined($flags)) {
1273                 foreach my $f (split(/|/, $flags)) {
1274                         if ($f eq "I") {
1275                                 push(@req_type_mask, "arch_register_req_type_ignore");
1276                         } elsif ($f eq "S") {
1277                                 push(@req_type_mask, "arch_register_req_type_produces_sp");
1278                         } elsif ($f eq "a") {
1279                                 push(@req_type_mask, "arch_register_req_type_aligned");
1280                         } elsif ($f eq "2" or $f eq "4" or $f eq "8") {
1281                                 $width = int($f);
1282                         }
1283                 }
1284         }
1285
1286         if ($reqs eq "none") {
1287
1288                 $result = <<EOF;
1289 {
1290         arch_register_req_type_none,
1291         NULL,                         /* regclass */
1292         NULL,                         /* limit bitset */
1293         0,                            /* same pos */
1294         0,                            /* different pos */
1295         0                             /* width */
1296 };
1297
1298 EOF
1299         } elsif (is_reg_class($reqs)) {
1300                 push(@req_type_mask, "arch_register_req_type_normal");
1301                 my $reqtype = join(" | ", @req_type_mask);
1302                 $class  = $reqs;
1303                 $result = <<EOF;
1304 {
1305         ${reqtype},
1306         & ${arch}_reg_classes[CLASS_${arch}_${class}],
1307         NULL,        /* limit bitset */
1308         0,           /* same pos */
1309         0,           /* different pos */
1310         $width            /* width */
1311 };
1312
1313 EOF
1314
1315         } else {
1316                 my ($regclass, $limit_bitset, $same_pos, $different_pos)
1317                         = build_subset_class_func($node, $op, $idx, $is_in, $reqs, $flags);
1318
1319                 if (!defined($regclass)) {
1320                         die("Fatal error: Could not build subset for requirements '$reqs' of '$op' pos $idx ... exiting.\n");
1321                 }
1322
1323                 if (defined($limit_bitset) && $limit_bitset ne "NULL") {
1324                         push(@req_type_mask, "arch_register_req_type_limited");
1325                 }
1326                 if ($same_pos != 0) {
1327                         push(@req_type_mask, "arch_register_req_type_should_be_same");
1328                 }
1329                 if ($different_pos != 0) {
1330                         push(@req_type_mask, "arch_register_req_type_must_be_different");
1331                 }
1332                 my $reqtype = join(" | ", @req_type_mask);
1333
1334                 if(!defined($limit_bitset)) {
1335                         $limit_bitset = "NULL";
1336                 }
1337
1338                 $class  = $regclass;
1339                 $result = <<EOF;
1340 {
1341         ${reqtype},
1342         & ${arch}_reg_classes[CLASS_${arch}_${class}],
1343         ${limit_bitset},
1344         ${same_pos},        /* same pos */
1345         ${different_pos},       /* different pos */
1346         $width             /* width */
1347 };
1348
1349 EOF
1350         }
1351
1352         my $name = "${arch}_requirements_".mangle_requirements($reqs, $class, $flags);
1353         if(defined($requirements{$name})) {
1354                 return $name;
1355         }
1356         $requirements{$name} = $name;
1357         push(@obst_reg_reqs, <<EOF);
1358 static const arch_register_req_t ${name} = ${result}
1359 EOF
1360
1361         return $name;
1362 }