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
54 foreach my $op (keys(%nodes)) {
55 my %n = %{ $nodes{"$op"} };
57 # skip this node description if no emit information is available
58 next if (!defined($n{"emit"}));
60 $line = "static void emit_${arch}_${op}(const ir_node *node)";
62 push(@obst_register, "\tbe_set_emitter(op_${arch}_${op}, emit_${arch}_${op});\n");
64 if($n{"emit"} eq "") {
65 push(@obst_func, $line."\n");
66 push(@obst_func, "{\n");
67 push(@obst_func, "\t(void) node;\n");
68 push(@obst_func, "}\n\n");
72 push(@obst_func, $line."\n");
73 push(@obst_func, "{\n");
75 my @emit = split(/\n/, $n{"emit"});
77 foreach my $template (@emit) {
78 if ($template ne '') {
79 push(@obst_func, "\t${arch}_emitf(node, \"$template\");\n");
83 push(@obst_func, "}\n\n");
86 open(OUT, ">$target_h") || die("Could not open $target_h, reason: $!\n");
88 my $creation_time = localtime(time());
95 * \@brief Function prototypes for the emitter functions.
96 * \@note DO NOT EDIT THIS FILE, your changes will be lost.
97 * Edit $specfile instead.
98 * created by: $0 $specfile $target_dir
99 * \@date $creation_time
101 #ifndef FIRM_BE_${tmp}_GEN_${tmp}_EMITTER_H
102 #define FIRM_BE_${tmp}_GEN_${tmp}_EMITTER_H
105 #include "${arch}_emitter.h"
107 void ${arch}_register_spec_emitters(void);
115 open(OUT, ">$target_c") || die("Could not open $target_c, reason: $!\n");
117 $creation_time = localtime(time());
122 * \@brief Generated functions to emit code for assembler ir nodes.
123 * \@note DO NOT EDIT THIS FILE, your changes will be lost.
124 * Edit $specfile instead.
125 * created by: $0 $specfile $target_dir
126 * \@date $creation_time
135 #include "irprog_t.h"
136 #include "beemitter.h"
138 #include "gen_${arch}_emitter.h"
139 #include "${arch}_new_nodes.h"
140 #include "${arch}_emitter.h"
144 print OUT @obst_func;
149 * Enters the emitter functions for handled nodes into the generic
150 * pointer of an opcode.
152 void $arch\_register_spec_emitters(void)
156 print OUT @obst_register;