[project @ 1996-07-25 20:43:49 by partain]
[ghc-hetmet.git] / ghc / driver / ghc-asm.lprl
index 0907b09..eded9b3 100644 (file)
@@ -64,7 +64,7 @@ sub init_TARGET_STUFF {
 
     $T_hsc_cc_PAT   = '\.ascii.*\)(hsc|cc) (.*)\\\\11"\n\t\.ascii\s+"(.*)\\\\0"';
     $T_DOT_WORD            = '\.quad';
-    $T_DOT_GLOBAL   = "\t\.globl";
+    $T_DOT_GLOBAL   = '^\t\.globl';
     $T_HDR_literal  = "\.rdata\n\t\.align 3\n";
     $T_HDR_misc            = "\.text\n\t\.align 3\n";
     $T_HDR_data            = "\.data\n\t\.align 3\n";
@@ -91,7 +91,7 @@ sub init_TARGET_STUFF {
 
     $T_hsc_cc_PAT   = '\.STRING.*\)(hsc|cc) (.*)\\\\x09(.*)\\\\x00';
     $T_DOT_WORD            = '\.word';
-    $T_DOT_GLOBAL   = '\s+\.EXPORT';
+    $T_DOT_GLOBAL   = '^\s+\.EXPORT';
     $T_HDR_literal  = "\t.SPACE \$TEXT\$\n\t.SUBSPA \$LIT\$\n";
     $T_HDR_misc            = "\t.SPACE \$TEXT\$\n\t.SUBSPA \$CODE\$\n\t\.align 4\n";
     $T_HDR_data            = "\t.SPACE \$PRIVATE\$\n\t.SUBSPA \$DATA\$\n\t\.align 4\n";
@@ -121,11 +121,11 @@ sub init_TARGET_STUFF {
     $T_hsc_cc_PAT   = '\.ascii.*\)(hsc|cc) (.*)\\\\11"\n\t\.ascii\s+"(.*)\\\\0"';
     $T_DOT_WORD            = '\.long';
     $T_DOT_GLOBAL   = '\.globl';
-    $T_HDR_literal  = "\.text\n\t\.align 2\n"; # .align 4 is 486-cache friendly
+    $T_HDR_literal  = "\.text\n\t\.align 2\n";
     $T_HDR_misc            = "\.text\n\t\.align 2,0x90\n";
-    $T_HDR_data            = "\.data\n\t\.align 2\n"; # ToDo: change align??
+    $T_HDR_data            = "\.data\n\t\.align 2\n";
     $T_HDR_consist  = "\.text\n";
-    $T_HDR_closure  = "\.data\n\t\.align 2\n"; # ToDo: change align?
+    $T_HDR_closure  = "\.data\n\t\.align 2\n";
     $T_HDR_info            = "\.text\n\t\.align 2\n"; # NB: requires padding
     $T_HDR_entry    = "\.text\n"; # no .align so we're right next to _info (arguably wrong...?)
     $T_HDR_fast            = "\.text\n\t\.align 2,0x90\n";
@@ -138,7 +138,8 @@ sub init_TARGET_STUFF {
     $T_STABBY      = 0; # 1 iff .stab things (usually if a.out format)
     $T_US          = ''; # _ if symbols have an underscore on the front
     $T_DO_GC       = 'PerformGC_wrapper';
-    $T_PRE_APP     = '/'; # regexp that says what comes before APP/NO_APP
+    $T_PRE_APP     = # regexp that says what comes before APP/NO_APP
+                     ($TargetPlatform =~ /-linux$/) ? '#' : '/' ;
     $T_CONST_LBL    = '^\.LC(\d+):$'; # regexp for what such a lbl looks like
     $T_POST_LBL            = ':';
     $T_X86_PRE_LLBL_PAT = '\.L';
@@ -172,7 +173,7 @@ sub init_TARGET_STUFF {
     $T_CONST_LBL    = '^LC(\d+):$';
     $T_POST_LBL            = ':';
 
-    $T_MOVE_DIRVS   = '(\s*(\.align\s+\d+|\.proc\s+\d+|\.const|\.cstring|\.globl\s+\S+|\.text|\.data|\.even|\.stab[^n].*)\n)';
+    $T_MOVE_DIRVS   = '^(\s*(\.align\s+\d+|\.proc\s+\d+|\.const|\.cstring|\.globl\s+\S+|\.text|\.data|\.even|\.stab[^n].*)\n)';
     $T_COPY_DIRVS   = '\.(globl|proc|stab)';
     $T_hsc_cc_PAT   = '\.ascii.*\)(hsc|cc) (.*)\\\\11"\n\t\.ascii\s+"(.*)\\\\0"';
 
@@ -199,12 +200,12 @@ sub init_TARGET_STUFF {
     $T_CONST_LBL    = '^\$LC(\d+):$'; # regexp for what such a lbl looks like
     $T_POST_LBL            = ':';
 
-    $T_MOVE_DIRVS   = '(\s*(\.align\s+\d+|\.(globl|ent)\s+\S+|\.text|\.r?data)\n)';
+    $T_MOVE_DIRVS   = '^(\s*(\.align\s+\d+|\.(globl|ent)\s+\S+|\.text|\.r?data)\n)';
     $T_COPY_DIRVS   = '\.(globl|ent)';
 
     $T_hsc_cc_PAT   = 'I WAS TOO LAZY TO DO THIS BIT (WDP 95/05)';
     $T_DOT_WORD            = '\.word';
-    $T_DOT_GLOBAL   = '\t\.globl';
+    $T_DOT_GLOBAL   = '^\t\.globl';
     $T_HDR_literal  = "\t\.rdata\n\t\.align 2\n";
     $T_HDR_misc            = "\t\.text\n\t\.align 2\n";
     $T_HDR_data            = "\t\.data\n\t\.align 2\n";
@@ -220,28 +221,28 @@ sub init_TARGET_STUFF {
     } elsif ( $TargetPlatform =~ /^powerpc-.*/ ) {
 
     $T_STABBY      = 0; # 1 iff .stab things (usually if a.out format)
-    $T_US          = '\.'; # _ if symbols have an underscore on the front
+    $T_US          = ''; # _ if symbols have an underscore on the front
     $T_DO_GC       = 'PerformGC_wrapper';
     $T_PRE_APP     = 'NOT APPLICABLE'; # regexp that says what comes before APP/NO_APP
     $T_CONST_LBL    = '^LC\.\.(\d+):$'; # regexp for what such a lbl looks like
     $T_POST_LBL            = ':';
 
-    $T_MOVE_DIRVS   = '^(\s*(\.align\s+\d+(,0x90)?|\.globl\s+\S+|\.text|\.data|\.section\s+.*|\.type\s+.*|\.Lfe.*\n\t\.size\s+.*|\.size\s+.*|\.ident.*)\n)';
-    $T_COPY_DIRVS   = '\.(globl)';
+    $T_MOVE_DIRVS   = '^(\s*(\.toc|.csect \S+|\.l?globl \S+|\.align \d+)\n)';
+    $T_COPY_DIRVS   = '\.(l?globl)';
 
     $T_hsc_cc_PAT   = '\.string.*\)(hsc|cc) (.*)\\\\t(.*)"';
     $T_DOT_WORD            = '\.long';
     $T_DOT_GLOBAL   = '\.globl';
-    $T_HDR_literal  = "\.section\t\.rodata\n"; # or just use .text??? (WDP 95/11)
-    $T_HDR_misc            = "\.text\n\t\.align 16\n";
-    $T_HDR_data            = "\.data\n\t\.align 4\n"; # ToDo: change align??
+    $T_HDR_literal  = "\.section\t\.rodata\n";
+    $T_HDR_misc            = "\.text\n\t\.align 2\n";
+    $T_HDR_data            = "\.data\n\t\.align 2\n";
     $T_HDR_consist  = "\.text\n";
-    $T_HDR_closure  = "\.data\n\t\.align 4\n"; # ToDo: change align?
-    $T_HDR_info            = "\.text\n\t\.align 16\n"; # NB: requires padding
-    $T_HDR_entry    = "\.text\n"; # no .align so we're right next to _info (arguably wrong...?)
-    $T_HDR_fast            = "\.text\n\t\.align 16\n";
-    $T_HDR_vector   = "\.text\n\t\.align 16\n"; # NB: requires padding
-    $T_HDR_direct   = "\.text\n\t\.align 16\n";
+    $T_HDR_closure  = "\.data\n\t\.align 2\n";
+    $T_HDR_info            = "\.text\n\t\.align 2\n";
+    $T_HDR_entry    = "\.text\n";
+    $T_HDR_fast            = "\.text\n\t\.align 2\n";
+    $T_HDR_vector   = "\.text\n\t\.align 2\n";
+    $T_HDR_direct   = "\.text\n\t\.align 2\n";
 
     #--------------------------------------------------------#
     } elsif ( $TargetPlatform =~ /^sparc-.*-solaris2/ ) {
@@ -258,7 +259,7 @@ sub init_TARGET_STUFF {
 
     $T_hsc_cc_PAT   = '\.asciz.*\)(hsc|cc) (.*)\\\\t(.*)"';
     $T_DOT_WORD            = '\.word';
-    $T_DOT_GLOBAL   = '\.global';
+    $T_DOT_GLOBAL   = '^\t\.global';
     $T_HDR_literal  = "\.text\n\t\.align 8\n";
     $T_HDR_misc            = "\.text\n\t\.align 4\n";
     $T_HDR_data            = "\.data\n\t\.align 8\n";
@@ -379,7 +380,9 @@ sub mangle_asm {
 
        next if /^;/ && $TargetPlatform =~ /^hppa/;
 
-       next if /(^$|^\t\.file\t|^ # )/ && $TargetPlatform =~ /^mips-/;
+       next if /(^$|^\t\.file\t|^ # )/ && $TargetPlatform =~ /^(mips|powerpc)-/;
+
+       last if /^_section_\.text:$/ && $TargetPlatform =~ /^powerpc-/;
 
        if ( $TargetPlatform =~ /^mips-/ 
          && /^\t\.(globl \S+ \.text|comm\t)/ ) {
@@ -505,7 +508,9 @@ sub mangle_asm {
 
        } elsif ( /^${T_US}[A-Za-z0-9_]/o
                && ( $TargetPlatform !~ /^hppa/ # need to avoid local labels in this case
-                  || /^L\$\d+$/ ) ) {
+                  || ! /^L\$\d+$/ )
+               && ( $TargetPlatform !~ /^powerpc/ # ditto
+                  || ! /^(L\.\.\d+|LT\.\..*):$/ ) ) {
            local($thing);
            chop($thing = $_);
            print STDERR "Funny global thing?: $_"
@@ -584,13 +589,20 @@ sub mangle_asm {
                    print STDERR "$Pgm: unknown prologue mangling? $TargetPlatform\n";
                }
 
-               die "Prologue junk?: $p\n" if $p =~ /^\t[^\.]/;
+               die "Prologue junk?: $p\n" if $p =~ /^\t[^\.]/
+                   && $TargetPlatform !~ /^powerpc-/; #ToDo: remove test
 
                # glue together what's left
                $c = $p . $r;
+               $c =~ s/\n\t\n/\n/; # junk blank line
            }
        }
 
+       if ( $TargetPlatform =~ /^mips-/ ) {
+           # MIPS: first, this basic sequence may occur "--- END ---" or not
+           $c =~ s/^\tlw\t\$31,\d+\(\$sp\)\n\taddu\t\$sp,\$sp,\d+\n\tj\t\$31\n\t\.end/\t\.end/;
+       }
+
        # toss all epilogue stuff; again, paranoidly
        if ( $c =~ /--- END ---/ ) {
            if (($r, $e) = split(/--- END ---/, $c)) {
@@ -610,7 +622,8 @@ sub mangle_asm {
                } else {
                    print STDERR "$Pgm: unknown epilogue mangling? $TargetPlatform\n";
                }
-               die "Epilogue junk?: $e\n" if $e =~ /^\t[^\.]/;
+               die "Epilogue junk?: $e\n" if $e =~ /^\t[^\.]/
+                   && $TargetPlatform !~ /^powerpc-/; #ToDo: remove test
 
                # glue together what's left
                $c = $r . $e;
@@ -630,7 +643,7 @@ sub mangle_asm {
        # On Alphas, the prologue mangling is done a little later (below)
 
        # toss all calls to __DISCARD__
-       $c =~ s/^\t(call|jbsr|jal) ${T_US}__DISCARD__\n//go;
+       $c =~ s/^\t(call|jbsr|jal)\s+${T_US}__DISCARD__\n//go;
 
        # MIPS: that may leave some gratuitous asm macros around
        # (no harm done; but we get rid of them to be tidier)
@@ -655,7 +668,6 @@ sub mangle_asm {
 
        while ( $c =~ /${T_MOVE_DIRVS}FUNNY#END#THING/o ) {
            $to_move = $1;
-
            if ( $i < ($numchks - 1)
              && ( $to_move =~ /${T_COPY_DIRVS}/
                || ($TargetPlatform =~ /^hppa/ && $to_move =~ /align/ && $chkcat[$i+1] eq 'literal') )) {
@@ -766,9 +778,13 @@ sub mangle_asm {
                $consist =~ s/\//./g;
                $consist =~ s/-/_/g;
                $consist =~ s/[^A-Za-z0-9_.]/ZZ/g; # ToDo: properly?
-               print OUTASM $T_HDR_consist, "${consist}${T_POST_LBL}\n"
-                   if $TargetPlatform !~ /^mips-/; # we just don't try in that case
-           } else {
+               print OUTASM $T_HDR_consist, "${consist}${T_POST_LBL}\n";
+
+           } elsif ( $TargetPlatform !~ /^(mips|powerpc)-/ ) { # we just don't try in those case (ToDo)
+               # on mips: consistency string is just a v
+               # horrible bunch of .bytes,
+               # which I am too lazy to sort out (WDP 95/05)
+
                print STDERR "Couldn't grok consistency: ", $chk[$i];
            }
 
@@ -854,7 +870,7 @@ sub mangle_asm {
                if ( ! defined($slowchk{$symb})
                   # ToDo: the || clause can go once we're no longer
                   # concerned about producing exactly the same output as before
-                  || $TargetPlatform =~ /^(m68k|sparc|i386)-/
+#OLD:             || $TargetPlatform =~ /^(m68k|sparc|i386)-/
                   ) {
                    print OUTASM $T_HDR_fast;
                }
@@ -894,6 +910,12 @@ sub mangle_asm {
            &tidy_up_and_die(1,"$Pgm: unknown chkcat (ghc-asm: $TargetPlatform)\n$chkcat[$i]\n$chk[$i]\n");
        }
     }
+
+    print OUTASM $EXTERN_DECLS if $TargetPlatform =~ /^mips-/;
+
+    print OUTASM ".csect .text[PR]\n_section_.text:\n.csect .data[RW]\n\t.long _section_.text\n"
+       if $TargetPlatform =~ /^powerpc-/;
+
     # finished
     close(OUTASM) || &tidy_up_and_die(1,"Failed writing to $out_asmf\n");
     close(INASM)  || &tidy_up_and_die(1,"Failed reading from $in_asmf\n");
@@ -1088,7 +1110,12 @@ sub print_doctored {
     # final peephole fixes
 
     s/^\tmovl \%eax,36\(\%ebx\)\n\tjmp \*36\(\%ebx\)\n/\tmovl \%eax,36\(\%ebx\)\n\tjmp \*\%eax\n/;
-    s/^\tmovl \$_(.*),(\%e[abcd]x)\n\tjmp \*$2/\tjmp _$1/g;
+# the short form may tickle perl bug:
+#    s/^\tmovl \$${T_US}(.*),(\%e[abcd]x)\n\tjmp \*$2/\tjmp $T_US$1/g;
+    s/^\tmovl \$${T_US}(.*),\%eax\n\tjmp \*\%eax/\tjmp $T_US$1/g;
+    s/^\tmovl \$${T_US}(.*),\%ebx\n\tjmp \*\%ebx/\tjmp $T_US$1/g;
+    s/^\tmovl \$${T_US}(.*),\%ecx\n\tjmp \*\%ecx/\tjmp $T_US$1/g;
+    s/^\tmovl \$${T_US}(.*),\%edx\n\tjmp \*\%edx/\tjmp $T_US$1/g;
 
     # Hacks to eliminate some reloads of Hp.  Worth about 5% code size.
     # We could do much better than this, but at least it catches about
@@ -1157,6 +1184,8 @@ sub init_FUNNY_THINGS {
        "${T_US}_PRMarking_MarkNextGA${T_POST_LBL}", 1,
        "${T_US}_PRMarking_MarkNextRoot${T_POST_LBL}", 1,
        "${T_US}_PRMarking_MarkNextSpark${T_POST_LBL}", 1,
+       "${T_US}_PRMarking_MarkNextEvent${T_POST_LBL}", 1,
+       "${T_US}_PRMarking_MarkNextClosureInFetchBuffer${T_POST_LBL}", 1,
        "${T_US}_Scavenge_Forward_Ref${T_POST_LBL}", 1,
        "${T_US}__std_entry_error__${T_POST_LBL}", 1,
        "${T_US}_startMarkWorld${T_POST_LBL}", 1,
@@ -1192,7 +1221,7 @@ sub rev_tbl {
     for ($i = 0; $i <= $#lines && $lines[$i] !~ /^\t${T_DOT_WORD}\s+/o; $i++) {
        $label .= $lines[$i] . "\n",
            next if $lines[$i] =~ /^[A-Za-z0-9_]+_info${T_POST_LBL}$/o
-                || $lines[$i] =~ /^${T_DOT_GLOBAL}/o
+                || $lines[$i] =~ /${T_DOT_GLOBAL}/o
                 || $lines[$i] =~ /^${T_US}vtbl_\S+${T_POST_LBL}$/o;
 
        $before .= $lines[$i] . "\n"; # otherwise...