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().
25 # Creation: 2005/11/07
37 our $finish_line_template = "be_emit_finish_line_gas(node);";
39 my $target_c = $target_dir."/gen_".$arch."_emitter.c";
40 my $target_h = $target_dir."/gen_".$arch."_emitter.h";
43 my @obst_func; # stack for the emit functions
44 my @obst_register; # stack for emitter register code
54 my @tokens = ($template =~ m/[^\%]+|\%[a-zA-Z_][a-zA-Z0-9_]*|\%./g);
55 push(@{$result}, "${indent}be_emit_char('\t');\n");
58 if (/%\./) { last SWITCH; }
59 if (/%%/) { push(@{$result}, "${indent}be_emit_char('%');\n"); last SWITCH; }
61 if(defined($emit_templates{$1})) {
62 push(@{$result}, "${indent}$emit_templates{$1}\n");
64 print "Warning: No emit_template defined for '$1'\n";
65 push(@{$result}, "${indent}$1(node);\n");
69 push(@{$result}, "${indent}be_emit_cstring(\"$_\");\n");
72 push(@{$result}, "${indent}${finish_line_template}\n");
77 foreach my $op (keys(%nodes)) {
78 my %n = %{ $nodes{"$op"} };
80 # skip this node description if no emit information is available
81 next if (!defined($n{"emit"}));
83 $line = "static void emit_${arch}_${op}(const ir_node *node)";
85 push(@obst_register, " BE_EMIT($op);\n");
87 if($n{"emit"} eq "") {
88 push(@obst_func, $line." {\n");
89 push(@obst_func, "\t(void) node;\n");
90 push(@obst_func, "}\n\n");
94 push(@obst_func, $line." {\n");
96 my @emit = split(/\n/, $n{"emit"});
98 foreach my $template (@emit) {
99 # substitute only lines, starting with a '.'
100 if ($template =~ /^(\s*)\.\s*(.*)/) {
102 create_emitter(\@obst_func, $indent, $2);
104 push(@obst_func, "\t$template\n");
108 push(@obst_func, "}\n\n");
111 open(OUT, ">$target_h") || die("Could not open $target_h, reason: $!\n");
113 my $creation_time = localtime(time());
120 * \@brief Function prototypes for the emitter functions.
121 * \@note DO NOT EDIT THIS FILE, your changes will be lost.
122 * Edit $specfile instead.
123 * created by: $0 $specfile $target_dir
124 * \@date $creation_time
126 #ifndef FIRM_BE_${tmp}_GEN_${tmp}_EMITTER_H
127 #define FIRM_BE_${tmp}_GEN_${tmp}_EMITTER_H
130 #include "${arch}_emitter.h"
132 void ${arch}_register_spec_emitters(void);
140 open(OUT, ">$target_c") || die("Could not open $target_c, reason: $!\n");
142 $creation_time = localtime(time());
147 * \@brief Generated functions to emit code for assembler ir nodes.
148 * \@note DO NOT EDIT THIS FILE, your changes will be lost.
149 * Edit $specfile instead.
150 * created by: $0 $specfile $target_dir
151 * \@date $creation_time
161 #include "irprog_t.h"
163 #include "gen_${arch}_emitter.h"
164 #include "${arch}_new_nodes.h"
165 #include "${arch}_emitter.h"
169 print OUT @obst_func;
173 * Enters the emitter functions for handled nodes into the generic
174 * pointer of an opcode.
176 void $arch\_register_spec_emitters(void) {
178 #define BE_EMIT(a) op_$arch\_##a->ops.generic = (op_func)emit_$arch\_##a
180 /* generated emitter functions */
183 print OUT @obst_register;