4 # Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
6 # This file is part of libFirm.
8 # This file may be distributed and/or modified under the terms of the
9 # GNU General Public License version 2 as published by the Free Software
10 # Foundation and appearing in the file LICENSE.GPL included in the
11 # packaging of this file.
13 # Licensees holding valid libFirm Professional Edition licenses may use
14 # this file in accordance with the libFirm Commercial License.
15 # Agreement provided with the Software.
17 # This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 # WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 # This script generates C code which emits assembler code for the
23 # assembler ir nodes. It takes a "emit" key from the node specification
24 # and substitutes lines starting with . with a corresponding fprintf().
29 our $specfile = $ARGV[0];
30 our $target_dir = $ARGV[1];
38 unless ($return = do $specfile) {
39 die "Fatal error: couldn't parse $specfile: $@" if $@;
40 die "Fatal error: couldn't do $specfile: $!" unless defined $return;
41 die "Fatal error: couldn't run $specfile" unless $return;
45 my $target_c = $target_dir."/gen_".$arch."_emitter.c";
46 my $target_h = $target_dir."/gen_".$arch."_emitter.h";
49 my @obst_func; # stack for the emit functions
50 my @obst_register; # stack for emitter register code
53 foreach my $op (keys(%nodes)) {
54 my %n = %{ $nodes{"$op"} };
56 # skip this node description if no emit information is available
57 next if (!defined($n{"emit"}));
59 if ($n{"emit"} eq "") {
60 push(@obst_register, "\tbe_set_emitter(op_${arch}_${op}, be_emit_nothing);\n");
64 push(@obst_register, "\tbe_set_emitter(op_${arch}_${op}, emit_${arch}_${op});\n");
66 push(@obst_func, "static void emit_${arch}_${op}(const ir_node *node)\n");
67 push(@obst_func, "{\n");
69 my @emit = split(/\n/, $n{"emit"});
71 foreach my $template (@emit) {
72 if ($template ne '') {
73 push(@obst_func, "\t${arch}_emitf(node, \"$template\");\n");
77 push(@obst_func, "}\n\n");
80 open(OUT, ">$target_h") || die("Could not open $target_h, reason: $!\n");
82 my $creation_time = localtime(time());
89 * \@brief Function prototypes for the emitter functions.
90 * \@note DO NOT EDIT THIS FILE, your changes will be lost.
91 * Edit $specfile instead.
92 * created by: $0 $specfile $target_dir
93 * \@date $creation_time
95 #ifndef FIRM_BE_${tmp}_GEN_${tmp}_EMITTER_H
96 #define FIRM_BE_${tmp}_GEN_${tmp}_EMITTER_H
99 #include "${arch}_emitter.h"
101 void ${arch}_register_spec_emitters(void);
109 open(OUT, ">$target_c") || die("Could not open $target_c, reason: $!\n");
111 $creation_time = localtime(time());
116 * \@brief Generated functions to emit code for assembler ir nodes.
117 * \@note DO NOT EDIT THIS FILE, your changes will be lost.
118 * Edit $specfile instead.
119 * created by: $0 $specfile $target_dir
120 * \@date $creation_time
129 #include "irprog_t.h"
130 #include "beemitter.h"
132 #include "gen_${arch}_emitter.h"
133 #include "${arch}_new_nodes.h"
134 #include "${arch}_emitter.h"
138 print OUT @obst_func;
143 * Enters the emitter functions for handled nodes into the generic
144 * pointer of an opcode.
146 void $arch\_register_spec_emitters(void)
150 print OUT @obst_register;