bescripts: Remove support for emit templates.
[libfirm] / ir / be / scripts / generate_regalloc_if.pl
index 284ca6b..a448834 100755 (executable)
@@ -22,7 +22,6 @@
 # This script generates C code which creates ands sets up functions and
 # data structures for the register allocator.
 # Creation: 2005/11/14
-# $Id$
 
 use strict;
 use Data::Dumper;
@@ -33,7 +32,6 @@ my $target_dir = $ARGV[1];
 
 our $arch;
 our %reg_classes;
-our %cpu;
 
 # include spec file
 
@@ -51,45 +49,20 @@ my $target_c   = $target_dir."/gen_".$arch."_regalloc_if.c";
 my $target_h   = $target_dir."/gen_".$arch."_regalloc_if.h";
 
 # helper function
-sub translate_reg_type {
-       my $t = shift;
-
-       if ($t == 0) {
-               return "arch_register_type_none";
-       }
-       else {
-               my @types;
-
-               if ($t & 1) {
-                       push(@types, "arch_register_type_ignore");
-               }
-
-               if ($t & 2) {
-                       push(@types, "arch_register_type_joker");
-               }
-
-               if ($t & 4) {
-                       push(@types, "arch_register_type_virtual");
-               }
-
-               if ($t & 8) {
-                       push(@types, "arch_register_type_state");
-               }
-
-               return join(" | ", @types);
-       }
+sub map_flags {
+       my $prefix = shift;
+       my $flags  = shift || "none";
+       return join(" | ", map { "$prefix$_" } split(/\s*\|\s*/, $flags));
 }
 
 # stacks for output
 my $regtypes_def; # stack for the register type variables definitions
-my $regtypes_decl;# stack for the register type variables declarations
 my @regclasses;   # stack for the register class variables
 my $classdef;     # stack to define a name for a class index
 my $regdef;       # stack to define a name for a register index
 my $regdef2;
 my $regcounts;
 my $reginit;      # stack for the register type inits
-my $single_constraints_decls;
 my $single_constraints;
 
 my $class_ptr;
@@ -100,8 +73,6 @@ my %reg2class = ();
 
 $classdef .= "enum reg_classes {\n";
 
-my $class_mode;
-
 foreach my $class_name (keys(%reg_classes)) {
        my @class = @{ $reg_classes{"$class_name"} };
 
@@ -158,23 +129,8 @@ foreach my $class_name (keys(%reg_classes)) {
        $class_name = $arch."_".$class_name;
        $class_ptr  = "&".$arch."_reg_classes[CLASS_".$class_name."]";
        my $flags = pop(@class);
-       $class_mode  = $flags->{"mode"};
-       my $class_flags = $flags->{"flags"};
-       my $flags_prepared = "";
-
-       if(defined($class_flags)) {
-               my $first = 1;
-               foreach my $flag (split(/\|/, $class_flags)) {
-                       if(!$first) {
-                               $flags_prepared .= "|";
-                       } else {
-                               $first = 0;
-                       }
-                       $flags_prepared .= "arch_register_class_flag_$flag";
-               }
-       } else {
-               $flags_prepared = "arch_register_class_flag_none";
-       }
+       my $class_mode = $flags->{"mode"};
+       my $flags_prepared = map_flags("arch_register_class_flag_", $flags->{"flags"});
 
        $single_constraints .= <<EOF;
 static const arch_register_req_t ${arch}_class_reg_req_${old_classname} = {
@@ -198,8 +154,7 @@ EOF
        foreach (@class) {
                my $name   = $_->{"name"};
                my $ucname = uc($name);
-               my $type   = "arch_register_type_none";
-               $type = translate_reg_type($_->{"type"}) if (exists($_->{"type"}));
+               my $type   = map_flags("arch_register_type_", $_->{"type"});
                # realname is name if not set by user
                $_->{"realname"} = $_->{"name"} if (! exists($_->{"realname"}));
                my $realname = $_->{realname};
@@ -207,6 +162,10 @@ EOF
 
                $regdef  .= "\tREG_${ucname},\n";
                $regdef2 .= "\tREG_${classuc}_${ucname} = $idx,\n";
+               my $dwarf_number = 0;
+               if (defined($_->{dwarf})) {
+                       $dwarf_number = $_->{dwarf};
+               }
 
                $regtypes_def .= <<EOF;
        {
@@ -215,7 +174,8 @@ EOF
                REG_${classuc}_${ucname},
                REG_${ucname},
                ${type},
-               &${arch}_single_reg_req_${old_classname}_${name}
+               &${arch}_single_reg_req_${old_classname}_${name},
+               ${dwarf_number}
        },
 EOF
 
@@ -262,7 +222,7 @@ print OUT<<EOF;
 #ifndef FIRM_BE_${archuc}_GEN_${archuc}_REGALLOC_IF_H
 #define FIRM_BE_${archuc}_GEN_${archuc}_REGALLOC_IF_H
 
-#include "../bearch.h"
+#include "bearch.h"
 #include "${arch}_nodes_attr.h"
 
 /** global register indices for ${arch} registers */
@@ -311,7 +271,6 @@ print OUT<<EOF;
 #include "config.h"
 
 #include "gen_${arch}_regalloc_if.h"
-#include "gen_${arch}_machine.h"
 #include "bearch_${arch}_t.h"
 #include "irmode.h"
 
@@ -336,33 +295,3 @@ ${reginit}
 }
 EOF
 close(OUT);
-
-###
-# Gets the variable name for the execution unit assigned to this register.
-###
-sub get_execunit_variable_name {
-       my $unit    = shift;
-       my $name    = "NULL";
-       my $uc_arch = uc($arch);
-
-       if ($unit) {
-               my $found = 0;
-SRCH:  foreach my $cur_type (keys(%cpu)) {
-                       foreach my $cur_unit (@{ $cpu{"$cur_type"} }) {
-                               if ($unit eq $cur_unit) {
-                                       my $tp_name   = "$arch\_execution_units_$cur_type";
-                                       my $unit_name = "$uc_arch\_EXECUNIT_TP_$cur_type\_$unit";
-                                       $name  = "&".$tp_name."[".$unit_name."]";
-                                       $found = 1;
-                                       last SRCH;
-                               }
-                       }
-               }
-
-               if (! $found) {
-                       print STDERR "Invalid execution unit $unit specified!\n";
-               }
-       }
-
-       return $name;
-}