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