3 # This script generates C code which emits assembler code for the
4 # assembler ir nodes. It takes a "emit" key from the node specification
5 # and substitutes lines starting with . with a corresponding fprintf().
19 my $target_c = $target_dir."/gen_".$arch."_emitter.c";
20 my $target_h = $target_dir."/gen_".$arch."_emitter.h";
23 my @obst_func; # stack for the emit functions
24 my @obst_register; # stack for emitter register code
34 my @tokens = ($template =~ m/[^\%]+|\%[a-zA-Z_][a-zA-Z0-9_]*|\%./g);
35 push(@{$result}, "${indent}${arch}_emit_char(env, '\t');\n");
38 if (/%\./) { last SWITCH; }
39 if (/%%/) { push(@{$result}, "${indent}${arch}_emit_char(env, '%');\n"); last SWITCH; }
41 if(defined($emit_templates{$1})) {
42 push(@{$result}, "${indent}$emit_templates{$1}\n");
44 print "Warning: No emit_template defined for '$1'\n";
45 push(@{$result}, "${indent}$1(env, node);\n");
49 push(@{$result}, "${indent}${arch}_emit_cstring(env, \"$_\");\n");
52 push(@{$result}, "${indent}${arch}_emit_finish_line(env, node);\n");
57 foreach my $op (keys(%nodes)) {
58 my %n = %{ $nodes{"$op"} };
60 # skip this node description if no emit information is available
61 next if (!defined($n{"emit"}));
63 $line = "static void emit_".$arch."_".$op."(${arch}_emit_env_t *env, const ir_node *node)";
65 push(@obst_register, " BE_EMIT($op);\n");
67 if($n{"emit"} eq "") {
68 push(@obst_func, $line." {\n");
69 push(@obst_func, "}\n\n");
73 push(@obst_func, $line." {\n");
74 my @emit = split(/\n/, $n{"emit"});
76 foreach my $template (@emit) {
77 # substitute only lines, starting with a '.'
78 if ($template =~ /^(\s*)\.\s*(.*)/) {
80 create_emitter(\@obst_func, $indent, $2);
82 push(@obst_func, "\t$template\n");
86 push(@obst_func, "}\n\n");
89 open(OUT, ">$target_h") || die("Could not open $target_h, reason: $!\n");
91 my $creation_time = localtime(time());
96 #ifndef _GEN_$tmp\_EMITTER_H_
97 #define _GEN_$tmp\_EMITTER_H_
100 * Function prototypes for the emitter functions.
101 * DO NOT EDIT THIS FILE, your changes will be lost.
102 * Edit $specfile instead.
103 * created by: $0 $specfile $target_dir
104 * date: $creation_time
108 #include "$arch\_emitter.h"
110 void $arch\_register_spec_emitters(void);
112 #endif /* _GEN_$tmp\_EMITTER_H_ */
118 open(OUT, ">$target_c") || die("Could not open $target_c, reason: $!\n");
120 $creation_time = localtime(time());
124 * Generated functions to emit code for assembler ir nodes.
125 * DO NOT EDIT THIS FILE, your changes will be lost.
126 * Edit $specfile instead.
127 * created by: $0 $specfile $target_dir
128 * date: $creation_time
138 #include "irprog_t.h"
140 #include "gen_${arch}_emitter.h"
141 #include "${arch}_new_nodes.h"
142 #include "${arch}_emitter.h"
146 print OUT @obst_func;
150 * Enters the emitter functions for handled nodes into the generic
151 * pointer of an opcode.
153 void $arch\_register_spec_emitters(void) {
155 #define BE_EMIT(a) op_$arch\_##a->ops.generic = (op_func)emit_$arch\_##a
157 /* generated emitter functions */
160 print OUT @obst_register;