allow specification of names for in parameters in spec file
[libfirm] / ir / be / scripts / generate_new_opcodes.pl
1 #!/usr/bin/perl -w
2
3 #
4 # Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
5 #
6 # This file is part of libFirm.
7 #
8 # This file may be distributed and/or modified under the terms of the
9 # GNU General Public License version 2 as published by the Free Software
10 # Foundation and appearing in the file LICENSE.GPL included in the
11 # packaging of this file.
12 #
13 # Licensees holding valid libFirm Professional Edition licenses may use
14 # this file in accordance with the libFirm Commercial License.
15 # Agreement provided with the Software.
16 #
17 # This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 # WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 # PURPOSE.
20 #
21
22 # This script generates the 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 %cpu;
41 our $default_cmp_attr;
42
43 # include spec file
44
45 my $return;
46
47 no strict "subs";
48 unless ($return = do $specfile) {
49         die "couldn't parse $specfile: $@" if $@;
50         die "couldn't do $specfile: $!"    unless defined $return;
51         die "couldn't run $specfile"       unless $return;
52 }
53 use strict "subs";
54
55 my $target_c = $target_dir."/gen_".$arch."_new_nodes.c.inl";
56 my $target_h = $target_dir."/gen_".$arch."_new_nodes.h";
57
58 #print Dumper(%nodes);
59 #print Dumper(%operands);
60
61 # create c code file from specs
62
63 my @obst_opvar;       # stack for the "ir_op *op_<arch>_<op-name> = NULL;" statements
64 my @obst_get_opvar;   # stack for the get_op_<arch>_<op-name>() functions
65 my @obst_constructor; # stack for node constructor functions
66 my @obst_new_irop;    # stack for the new_ir_op calls
67 my @obst_enum_op;     # stack for creating the <arch>_opcode enum
68 my @obst_header;      # stack for function prototypes
69 my @obst_is_archirn;  # stack for the is_$arch_irn() function
70 my @obst_cmp_attr;    # stack for the compare attribute functions
71 my @obst_proj;        # stack for the pn_ numbers
72 my $orig_op;
73 my $arity;
74 my $cmp_attr_func;
75 my $temp;
76 my $n_opcodes = 0;    # number of opcodes
77
78 # for registering additional opcodes
79 $n_opcodes += $additional_opcodes if (defined($additional_opcodes));
80
81 push(@obst_header, "void ".$arch."_create_opcodes(void);\n");
82
83 # create default compare function
84 if(defined($default_cmp_attr)) {
85         my $cmpcode = $default_cmp_attr;
86         push(@obst_cmp_attr, "static int default_cmp_attr(ir_node *a, ir_node *b) {\n");
87         if($cmpcode =~ m/attr_a/) {
88                 push(@obst_cmp_attr, "\t$arch\_attr_t *attr_a = get_$arch\_attr(a);\n");
89         }
90         if($cmpcode =~ m/attr_b/) {
91                 push(@obst_cmp_attr, "\t$arch\_attr_t *attr_b = get_$arch\_attr(b);\n");
92         }
93         push(@obst_cmp_attr, "\t${cmpcode}\n");
94         push(@obst_cmp_attr, "}\n\n");
95 }
96
97 push(@obst_enum_op, "typedef enum _$arch\_opcodes {\n");
98 foreach my $op (keys(%nodes)) {
99         my %n        = %{ $nodes{"$op"} };
100         my $known_mode;
101         my $n_res    = 0;
102         my $num_outs = 0;
103         my @out_flags;
104
105         # determine arity from in requirements
106         $arity = exists($n{"arity"}) ? $n{"arity"} : 0;
107         if (exists($n{"reg_req"}) && exists($n{"reg_req"}{"in"})) {
108                 $arity = scalar(@{ $n{"reg_req"}{"in"} });
109         }
110
111         $orig_op = $op;
112         $op      = $arch."_".$op;
113         $temp    = "";
114
115         # define some proj numbers
116         if (exists($n{"outs"})) {
117                 undef my @outs;
118
119                 @outs     = @{ $n{"outs"} };
120                 $num_outs = $#outs + 1;
121
122                 push(@obst_proj, "\nenum pn_$op {\n");
123
124                 for (my $idx = 0; $idx <= $#outs; $idx++) {
125                         # check, if we have additional flags annotated to out
126                         if ($outs[$idx] =~ /:((S|I)(\|(S|I))*)/) {
127                                 push(@out_flags, $1);
128                                 $outs[$idx] =~ s/:((S|I)(\|(S|I))*)//;
129                         }
130                         push(@obst_proj, "\tpn_$op\_".$outs[$idx]." = $idx,\n");
131                 }
132
133                 push(@obst_proj, "};\n");
134                 # outs have names, it must be a mode_T node
135                 $known_mode = "mode_T";
136         }
137         if (exists($n{"ins"})) {
138                 undef my @ins;
139
140                 @ins = @{ $n{"ins"} };
141                 my $num_ins = $#ins + 1;
142
143                 push(@obst_proj, "\nenum n_$op {\n");
144
145                 for (my $idx = 0; $idx <= $#ins; $idx++) {
146                         push(@obst_proj, "\tn_${op}_".$ins[$idx]." = $idx,\n");
147                 }
148
149                 push(@obst_proj, "};\n");
150         }
151         if (exists($n{"mode"})) {
152                 $known_mode = $n{"mode"};
153         }
154
155         push(@obst_opvar, "ir_op *op_$op = NULL;\n");
156         push(@obst_get_opvar, "ir_op *get_op_$op(void)         { return op_$op; }\n");
157         push(@obst_get_opvar, "int    is_$op(const ir_node *n) { return get_$arch\_irn_opcode(n) == iro_$op; }\n\n");
158
159         push(@obst_is_archirn, "is_$op(node)");
160
161         push(@obst_header, "extern ir_op *op_$op;\n");
162         push(@obst_header, "ir_op *get_op_$op(void);\n");
163         push(@obst_header, "int is_$op(const ir_node *n);\n");
164
165         my $cmp_attr_func;
166         if(defined($default_cmp_attr)) {
167                 $cmp_attr_func = "default_cmp_attr";
168         }
169         # create compare attribute function if needed
170         if (exists($n{"cmp_attr"})) {
171                 my $cmpcode = $n{"cmp_attr"};
172
173                 push(@obst_cmp_attr, "static int cmp_attr_$op(ir_node *a, ir_node *b) {\n");
174                 if($cmpcode =~ m/attr_a/) {
175                         push(@obst_cmp_attr, "\t$arch\_attr_t *attr_a = get_$arch\_attr(a);\n");
176                 }
177                 if($cmpcode =~ m/attr_b/) {
178                         push(@obst_cmp_attr, "\t$arch\_attr_t *attr_b = get_$arch\_attr(b);\n");
179                 }
180                 push(@obst_cmp_attr, "\t${cmpcode}\n");
181                 push(@obst_cmp_attr, "}\n\n");
182
183                 $cmp_attr_func = "cmp_attr_${op}";
184         }
185
186         if (exists($n{"rd_constructor"}) && $n{"rd_constructor"} =~ /^NONE$/i) {
187                 # we explicitly skip the constructor if the specification entry says NONE
188         }
189         else {
190                 $n{"comment"} = "construct $op" if(!exists($n{"comment"}));
191                 $n{"comment"} =~ s/^"|"$//g;    # remove "
192                 $n{"comment"} = "/* ".$n{"comment"}." */\n";
193                 push(@obst_constructor, $n{"comment"});
194
195                 # create constructor head
196                 my $complete_args = "";
197                 my $arg_names     = "";
198                 $temp             = "";
199
200                 $temp = "ir_node *new_rd_$op(dbg_info *db, ir_graph *irg, ir_node *block";
201                 if (!exists($n{"args"}) || $n{"args"} =~ /^DEFAULT$/i) { # default args
202                         if ($arity !~ /^\d+$/) {
203                                 print "DEFAULT args require numeric arity (0, 1, 2, ...)! Ignoring op $orig_op!\n";
204                                 next;
205                         }
206                         for (my $i = 1; $i <= $arity; $i++) {
207                                 $complete_args .= ", ir_node *op".$i;
208                                 $arg_names     .= ", op".$i;
209                         }
210                         if (!defined($known_mode)) {
211                                 $complete_args .= ", ir_mode *mode";
212                                 $arg_names     .= ", mode";
213                         }
214                 }
215                 else { # user defined args
216                         for my $href (@{ $n{"args"} }) {
217                                 $href->{"type"} .= " " if ($href->{"type"} !~ / [*]?$/); # put a space between name and type if there is none at the end
218                                 $complete_args  .= ", ".$href->{"type"}.$href->{"name"};
219                                 $arg_names      .= ", ".$href->{"name"};
220                         }
221                 }
222
223                 # we have additional attribute arguements
224                 if (exists($n{"attr"})) {
225                         $complete_args .= ", ".$n{"attr"};
226                 }
227
228                 # $complete_args = substr($complete_args, 2);
229                 $temp .= "$complete_args)";
230                 push(@obst_constructor, $temp." {\n");
231                 push(@obst_header, $n{"comment"});
232                 push(@obst_header, $temp.";\n");
233
234                 # emit constructor code
235                 if (!exists($n{"rd_constructor"}) || $n{"rd_constructor"} =~ /^DEFAULT$/i) { # default constructor
236                         if ($arity !~ /^\d+$/) {
237                                 print "DEFAULT rd_constructor requires numeric arity! Ignoring op $orig_op!\n";
238                                 next;
239                         }
240
241                         $temp  = "\tir_node *res;\n";
242                         $temp .= "\tir_node *in[$arity];\n" if ($arity > 0);
243                         $temp .= "\tint flags = 0;\n";
244                         $temp .= "\t$arch\_attr_t *attr;\n" if (exists($n{"init_attr"}));
245
246                         my $exec_units = "NULL";
247                         # set up static variables for cpu execution unit assigments
248                         if (exists($n{"units"})) {
249                                 $temp .= gen_execunit_list_initializer($n{"units"});
250                                 $exec_units = "_exec_units";
251                         }
252
253                         undef my $in_req_var;
254                         undef my $out_req_var;
255
256                         # set up static variables for requirements and registers
257                         if (exists($n{"reg_req"})) {
258                                 my %req = %{ $n{"reg_req"} };
259                                 my $idx;
260
261                                 undef my @in;
262                                 @in = @{ $req{"in"} } if (exists($req{"in"}));
263                                 undef my @out;
264                                 @out = @{ $req{"out"} } if exists(($req{"out"}));
265
266                                 if (@in) {
267                                         $in_req_var = "_in_req_$op";
268                                         $temp .= "\tstatic const arch_register_req_t *".$in_req_var."[] =\n";
269                                         $temp .= "\t{\n";
270                                         for ($idx = 0; $idx <= $#in; $idx++) {
271                                                 $temp .= "\t\t&".$op."_reg_req_in_".$idx.",\n";
272                                         }
273                                         $temp .= "\t};\n";
274                                 }
275
276                                 if (@out) {
277                                         $out_req_var = "_out_req_$op";
278
279                                         $temp .= "\tstatic const arch_register_req_t *".$out_req_var."[] =\n";
280                                         $temp .= "\t{\n";
281                                         for ($idx = 0; $idx <= $#out; $idx++) {
282                                                 $temp .= "\t\t&".$op."_reg_req_out_".$idx.",\n";
283                                         }
284                                         $temp .= "\t};\n";
285                                 }
286                         }
287
288                         $temp .= "\n";
289                         $temp .= "\tassert(op_$op != NULL);\n\n";
290
291                         for (my $i = 1; $i <= $arity; $i++) {
292                                 $temp .= "\tin[".($i - 1)."] = op".$i.";\n";
293                         }
294
295                         # set flags
296                         if (exists($n{"irn_flags"})) {
297                                 foreach my $flag (split(/\|/, $n{"irn_flags"})) {
298                                         if ($flag eq "R") {
299                                                 $temp .= "\tflags |= arch_irn_flags_rematerializable;   /* op can be easily recalculated */\n";
300                                         }
301                                         elsif ($flag eq "N") {
302                                                 $temp .= "\tflags |= arch_irn_flags_dont_spill;         /* op is NOT spillable */\n";
303                                         }
304                                         elsif ($flag eq "I") {
305                                                 $temp .= "\tflags |= arch_irn_flags_ignore;             /* ignore op for register allocation */\n";
306                                         }
307                                         elsif ($flag eq "S") {
308                                                 $temp .= "\tflags |= arch_irn_flags_modify_sp;          /* op modifies stack pointer */\n";
309                                         }
310                                 }
311                         }
312
313                         my $in_param;
314                         my $out_param;
315                         # allocate memory and set pointer to register requirements
316                         if (exists($n{"reg_req"})) {
317                                 my %req = %{ $n{"reg_req"} };
318
319                                 undef my @in;
320                                 @in = @{ $req{"in"} } if (exists($req{"in"}));
321                                 undef my @out;
322                                 @out = @{ $req{"out"} } if exists(($req{"out"}));
323
324                                 if (@in) {
325                                         $in_param = $in_req_var;
326                                 }
327                                 else {
328                                         $in_param = "NULL";
329                                 }
330
331                                 if (@out) {
332                                         $n_res     = $#out + 1;
333                                         $out_param = "$out_req_var, $exec_units, $n_res";
334                                 }
335                                 else {
336                                         $out_param = "NULL, $exec_units, 0";
337                                 }
338                         }
339                         else {
340                                 $in_param  = "NULL";
341                                 $out_param = "NULL, $exec_units, 0";
342                         }
343                         $temp .= "\n\t/* create node */\n";
344
345                         my $latency = 1;
346                         if (exists($n{"latency"})) {
347                                 $latency = $n{"latency"};
348                         }
349
350                         my $mode = "mode";
351                         if (defined($known_mode)) {
352                                 $mode = $known_mode;
353                         }
354                         $temp .= "\tres = new_ir_node(db, irg, block, op_$op, $mode, $arity, ".($arity > 0 ? "in" : "NULL").");\n";
355
356                         $temp .= "\n\t/* init node attributes */\n";
357                         $temp .= "\tinit_$arch\_attributes(res, flags, $in_param, $out_param, $latency);\n";
358
359                         # set flags for outs
360                         if ($#out_flags >= 0) {
361                                 $temp .= "\n\t/* set flags for outs */\n";
362                                 for (my $idx = 0; $idx <= $#out_flags; $idx++) {
363                                         my $flags  = "";
364                                         my $prefix = "";
365
366                                         foreach my $flag (split(/\|/, $out_flags[$idx])) {
367                                                 if ($flag eq "I") {
368                                                         $flags .= $prefix."arch_irn_flags_ignore";
369                                                         $prefix = " | ";
370                                                 }
371                                                 elsif ($flag eq "S") {
372                                                         $flags .= $prefix."arch_irn_flags_modify_sp";
373                                                         $prefix = " | ";
374                                                 }
375                                         }
376
377                                         $temp .= "\tset_$arch\_out_flags(res, $flags, $idx);\n";
378                                 }
379                         }
380
381
382                         if (exists($n{"init_attr"})) {
383                                 $temp .= "\tattr = get_$arch\_attr(res);\n";
384                                 $temp .= $n{"init_attr"}."\n";
385                         }
386
387                         $temp .= "\n\t/* optimize node */\n";
388                         $temp .= "\tres = optimize_node(res);\n";
389                         $temp .= "\tirn_vrfy_irg(res, irg);\n\n";
390
391                         $temp .= "\n\treturn res;\n";
392
393                         push(@obst_constructor, $temp);
394                 }
395                 else { # user defined constructor
396                         push(@obst_constructor, $n{"rd_constructor"});
397                 }
398
399                 # close constructor function
400                 push(@obst_constructor, "}\n\n");
401         } # constructor creation
402
403         # set default values for state and flags if not given
404         $n{"state"}    = "floats" if (! exists($n{"state"}));
405         $n{"op_flags"} = "N"      if (! exists($n{"op_flags"}));
406
407
408         push(@obst_new_irop, "\n\tmemset(&ops, 0, sizeof(ops));\n");
409         push(@obst_new_irop, "\tops.dump_node     = $arch\_dump_node;\n");
410
411         if (defined($cmp_attr_func)) {
412                 push(@obst_new_irop, "\tops.node_cmp_attr = ${cmp_attr_func};\n");
413         }
414
415         $n_opcodes++;
416         $temp  = "\top_$op = new_ir_op(cur_opcode + iro_$op, \"$op\", op_pin_state_".$n{"state"}.", ".$n{"op_flags"};
417         $temp .= "|M, ".translate_arity($arity).", 0, sizeof($arch\_attr_t) + $n_res * sizeof(arch_register_t *), &ops);\n";
418         push(@obst_new_irop, $temp);
419         push(@obst_new_irop, "\tset_op_tag(op_$op, &$arch\_op_tag);\n");
420         push(@obst_enum_op, "\tiro_$op,\n");
421
422         push(@obst_header, "\n");
423 }
424 push(@obst_enum_op, "\tiro_$arch\_last_generated,\n");
425 push(@obst_enum_op, "\tiro_$arch\_last = iro_$arch\_last_generated");
426 push(@obst_enum_op, " + $additional_opcodes") if (defined($additional_opcodes));
427 push(@obst_enum_op, "\n} $arch\_opcodes;\n\n");
428
429 # emit the code
430
431 open(OUT, ">$target_c") || die("Could not open $target_c, reason: $!\n");
432
433 print OUT "#include \"gen_$arch\_regalloc_if_t.h\"\n\n";
434 print OUT @obst_cmp_attr;
435 print OUT "\n";
436 print OUT @obst_opvar;
437 print OUT "\n";
438 print OUT @obst_get_opvar;
439 print OUT "\n";
440
441 print OUT<<EOF;
442
443 static int $arch\_opcode_start = -1;
444 static int $arch\_opcode_end   = -1;
445
446 EOF
447
448 # build the FOURCC arguments from $arch
449
450 my ($a, $b, $c, $d) = ('\0', '\0', '\0', '\0');
451
452 if (length($arch) >= 1) {
453         $a = uc(substr($arch, 0, 1));
454 }
455
456 if (length($arch) >= 2) {
457         $b = uc(substr($arch, 1, 1));
458 }
459
460 if (length($arch) >= 3) {
461         $c = uc(substr($arch, 2, 1));
462 }
463
464 if (length($arch) >= 4) {
465         $d = uc(substr($arch, 3, 1));
466 }
467
468 print OUT "static unsigned $arch\_op_tag = FOURCC('$a', '$b', '$c', '$d');\n";
469
470 print OUT<<ENDOFISIRN;
471
472 /** Return the opcode number of the first $arch opcode. */
473 int get_$arch\_opcode_first(void) {
474         return $arch\_opcode_start;
475 }
476
477 /** Return the opcode number of the last $arch opcode + 1. */
478 int get_$arch\_opcode_last(void) {
479         return $arch\_opcode_end;
480 }
481
482 /** Return 1 if the given node is a $arch machine node, 0 otherwise */
483 int is_$arch\_irn(const ir_node *node) {
484         return get_op_tag(get_irn_op(node)) == &$arch\_op_tag;
485 }
486
487 int get_$arch\_irn_opcode(const ir_node *node) {
488         if (is_$arch\_irn(node))
489                 return get_irn_opcode(node) - $arch\_opcode_start;
490         return -1;
491 }
492
493 ENDOFISIRN
494
495 print OUT @obst_constructor;
496
497 print OUT<<ENDOFMAIN;
498 /**
499  * Creates the $arch specific Firm machine operations
500  * needed for the assembler irgs.
501  */
502 void $arch\_create_opcodes(void) {
503 #define N   irop_flag_none
504 #define L   irop_flag_labeled
505 #define C   irop_flag_commutative
506 #define X   irop_flag_cfopcode
507 #define I   irop_flag_ip_cfopcode
508 #define F   irop_flag_fragile
509 #define Y   irop_flag_forking
510 #define H   irop_flag_highlevel
511 #define c   irop_flag_constlike
512 #define K   irop_flag_keep
513 #define M   irop_flag_machine
514 #define O   irop_flag_machine_op
515 #define R   (irop_flag_user << 0)
516
517         ir_op_ops  ops;
518         int        cur_opcode;
519         static int run_once = 0;
520
521         if (run_once)
522                 return;
523         run_once = 1;
524
525         cur_opcode = get_next_ir_opcodes(iro_$arch\_last);
526
527         $arch\_opcode_start = cur_opcode;
528 ENDOFMAIN
529
530 print OUT @obst_new_irop;
531 print OUT "\n";
532 print OUT "\t$arch\_register_additional_opcodes(cur_opcode);\n" if (defined($additional_opcodes));
533 print OUT "\t$arch\_opcode_end = cur_opcode + iro_$arch\_last";
534 print OUT " + $additional_opcodes" if (defined($additional_opcodes));
535 print OUT ";\n";
536 print OUT "}\n";
537
538 close(OUT);
539
540 open(OUT, ">$target_h") || die("Could not open $target_h, reason: $!\n");
541
542 my $creation_time = localtime(time());
543 my $tmp = uc($arch);
544
545 print OUT<<EOF;
546 /**
547  * \@file
548  * \@brief Function prototypes for the new opcode functions.
549  * \@note  DO NOT EDIT THIS FILE, your changes will be lost.
550  *        Edit $specfile instead.
551  *        created by: $0 $specfile $target_dir
552  * \@date  $creation_time
553  */
554 #ifndef FIRM_BE_${tmp}_GEN_${tmp}_NEW_NODES_H
555 #define FIRM_BE_${tmp}_GEN_${tmp}_NEW_NODES_H
556
557 EOF
558
559 print OUT @obst_enum_op;
560 print OUT "int is_$arch\_irn(const ir_node *node);\n\n";
561 print OUT "int get_$arch\_opcode_first(void);\n";
562 print OUT "int get_$arch\_opcode_last(void);\n";
563 print OUT "int get_$arch\_irn_opcode(const ir_node *node);\n";
564 print OUT @obst_header;
565 print OUT @obst_proj;
566
567 print OUT <<EOF;
568 #endif
569 EOF
570
571 close(OUT);
572
573 ###
574 # Translates numeric arity into string constant.
575 ###
576 sub translate_arity {
577         my $arity = shift;
578
579         if ($arity =~ /^\d+$/) {
580                 if    ($arity == 0) {
581                         return "oparity_zero";
582                 }
583                 elsif ($arity == 1) {
584                         return "oparity_unary";
585                 }
586                 elsif ($arity == 2) {
587                         return "oparity_binary";
588                 }
589                 elsif ($arity == 3) {
590                         return "oparity_trinary";
591                 }
592                 else {
593                         return "oparity_any";
594                 }
595         }
596         else {
597                 return "oparity_".$arity;
598         }
599 }
600
601 ###
602 # Return the list of pointers for the given execution units.
603 ###
604 sub gen_execunit_list_initializer {
605         my $units   = shift;
606         my $uc_arch = uc($arch);
607         my $ret     = "";
608         my $ret2    = "";
609         my %init;
610
611         foreach my $unit (@{ $units }) {
612                 if ($unit eq "DUMMY") {
613                         push(@{ $init{"DUMMY"} }, "\t\t&be_machine_execution_units_DUMMY[0]");
614                 }
615                 elsif (exists($cpu{"$unit"})) {
616                         # operation can be executed on all units of this type
617                         # -> add them all
618                         my $tp_name = "$arch\_execution_units_$unit";
619                         my $idx     = 0;
620                         foreach (@{ $cpu{"$unit"} }) {
621                                 next if ($idx++ == 0);  # skip first element (it's not a unit)
622                                 my $unit_name = "$uc_arch\_EXECUNIT_TP_$unit\_$_";
623                                 push(@{ $init{"$unit"} }, "\t\t&".$tp_name."[".$unit_name."]");
624                         }
625                 }
626                 else {
627                         # operation can be executed only a certain unit
628                         # -> find corresponding unit type
629                         my $found = 0;
630 TP_SEARCH:      foreach my $cur_type (keys(%cpu)) {
631                                 foreach my $cur_unit (@{ $cpu{"$cur_type"} }) {
632                                         if ($unit eq $cur_unit) {
633                                                 my $tp_name   = "$arch\_execution_units_$cur_type";
634                                                 my $unit_name = "$uc_arch\_EXECUNIT_TP_$cur_type\_$unit";
635                                                 push(@{ $init{"$unit"} }, "\t\t&".$tp_name."[".$unit_name."]");
636                                                 $found = 1;
637                                                 last TP_SEARCH;
638                                         }
639                                 }
640                         }
641
642                         if (! $found) {
643                                 print STDERR "Invalid execution unit $unit specified!\n";
644                         }
645                 }
646         }
647
648         # prepare the 2-dim array init
649         foreach my $key (keys(%init)) {
650                 $ret .= "\tstatic const be_execution_unit_t *_allowed_units_".$key."[] =\n";
651                 $ret .= "\t{\n";
652                 foreach (@{ $init{"$key"} }) {
653                         $ret .= "$_,\n";
654                 }
655                 $ret .= "\t\tNULL\n";
656                 $ret .= "\t};\n";
657                 $ret2 .= "\t\t_allowed_units_$key,\n";
658         }
659         $ret2 .= "\t\tNULL\n";
660
661         $ret .= "\tstatic const be_execution_unit_t **_exec_units[] =\n";
662         $ret .= "\t{\n";
663         $ret .= $ret2;
664         $ret .= "\t};\n";
665
666         return $ret;
667 }