[project @ 2002-09-25 10:53:06 by simonmar]
[ghc-hetmet.git] / ghc / driver / mangler / ghc-asm.lprl
index 424477e..3951ca4 100644 (file)
@@ -96,8 +96,8 @@ sub init_TARGET_STUFF {
     $T_CONST_LBL    = '^\$L?C(\d+):$'; # regexp for what such a lbl looks like
     $T_POST_LBL            = ':';
 
-    $T_MOVE_DIRVS   = '^(\s*(\.align\s+\d+|\.(globl|ent)\s+\S+|\#.*|\.(file|loc)\s+\S+\s+\S+|\.text|\.r?data)\n)';
-    $T_COPY_DIRVS   = '^\s*(\#|\.(file|globl|ent|loc))';
+    $T_MOVE_DIRVS   = '^(\s*(\$.*\.\.ng:|\.align\s+\d+|\.(globl|ent)\s+\S+|\#.*|\.(file|loc)\s+\S+\s+\S+|\.text|\.r?data)\n)';
+    $T_COPY_DIRVS   = '^\s*(\$.*\.\.ng:|\#|\.(file|globl|ent|loc))';
 
     $T_hsc_cc_PAT   = '\.ascii.*\)(hsc|cc) (.*)\\\\11"\n\t\.ascii\s+"(.*)\\\\0"';
     $T_DOT_WORD            = '\.(long|quad|byte|word)';
@@ -188,8 +188,8 @@ sub init_TARGET_STUFF {
     $T_X86_PRE_LLBL        = '.L';
     $T_X86_BADJMP   = '^\tjmp\s+[^\.\*]';
 
-    $T_MOVE_DIRVS   = '^(\s*(\.(p2)?align\s+\d+(,\s*0x90)?|\.globl\s+\S+|\.text|\.data|\.section\s+.*|\.type\s+.*|\.Lfe.*\n\s*\.size\s+.*|\.size\s+.*|\.ident.*)\n)';
-    $T_COPY_DIRVS   = '\.(globl)';
+    $T_MOVE_DIRVS   = '^(\s*(\.(p2)?align\s+\d+(,\s*0x90)?|\.globl\s+\S+|\.text|\.data|\.section\s+.*|\.type\s+.*|\.size\s+\S+,\d+|\.ident.*)\n)';
+    $T_COPY_DIRVS   = '^\s*\.(globl|type|size)';
 
     if ( $TargetPlatform =~ /freebsd|netbsd/ ) {
         $T_hsc_cc_PAT   = '\.ascii.*\)(hsc|cc) (.*)\\\\11"\n\t\.ascii\s+"(.*)\\\\0"';
@@ -613,7 +613,8 @@ sub mangle_asm {
                   || ! /^L\$\d+$/ ) ) {
            local($thing);
            chop($thing = $_);
-           print STDERR "Funny global thing?: $_"
+           $thing =~ s/:$//;
+           print STDERR "Warning: retaining unknown function \`$thing' in output from C compiler\n"
                unless # $KNOWN_FUNNY_THING{$thing}
                       /^${T_US}stg_.*${T_POST_LBL}$/o          # RTS internals
                    || /^${T_US}__stg_.*${T_POST_LBL}$/o        # more RTS internals
@@ -700,13 +701,15 @@ sub mangle_asm {
                    $p =~ s/^\tpushl\s+\%edi\n//;
                    $p =~ s/^\tpushl\s+\%esi\n//;
                    $p =~ s/^\tpushl\s+\%ebx\n//;
+                   $p =~ s/^\tmovl\s+\%esi,\s*\d*\(\%esp\)\n//;
+                   $p =~ s/^\tmovl\s+\%edi,\s*\d*\(\%esp\)\n//;
                    $p =~ s/^\tsubl\s+\$\d+,\s*\%esp\n//;
                     $p =~ s/^\tmovl\s+\$\d+,\s*\%eax\n\tcall\s+__alloca\n// if ($TargetPlatform =~ /^.*-cygwin32/);
 
                    # GCC 3.1 is in the habit of adding spurious writes to the
                    # stack in the prologue.  Just to be on the safe side,
                    # chuck these over the fence into the main code.
-                   while ($p =~ /^\tmovl\s+(\$\d+|\%edi),\s*\d*\(\%esp\)\n/) {
+                   while ($p =~ /^\tmovl\s+\$\d+,\s*\d*\(\%esp\)\n/) {
                          # print "Spurious instruction: $&";
                          $p = $` . $';
                          $r = $& . $r;
@@ -843,6 +846,7 @@ sub mangle_asm {
 
        # toss all calls to __DISCARD__
        $c =~ s/^\t(call|jbsr|jal)\s+${T_US}__DISCARD__\n//go;
+       $c =~ s/^\tjsr\s+\$26\s*,\s*${T_US}__DISCARD__\n//go if $TargetPlatform =~ /^alpha-/;
        $c =~ s/^\tbl\s+L___DISCARD__\$stub\n//go if $TargetPlatform =~ /^powerpc-apple-.*/;
 
        # IA64: mangle tailcalls into jumps here
@@ -907,16 +911,18 @@ sub mangle_asm {
        if ( $TargetPlatform =~ /^alpha-/ && $c =~ /^\t\.ent\s+(\S+)/ ) {
            $ent = $1;
            # toss all prologue stuff, except for loading gp, and the ..ng address
-           if (($p, $r) = split(/^\t\.prologue/, $c)) {
-               if (($keep, $junk) = split(/\.\.ng:/, $p)) {
-                   $keep =~ s/^\t\.frame.*\n/\t.frame \$30,0,\$26,0\n/;
-                   $keep =~ s/^\t\.(mask|fmask).*\n//g;
-                   $c = $keep . "..ng:\n";
-               } else {
-                   print STDERR "malformed code block ($ent)?\n"
-               }
-           }
-           $c .= "\t.prologue" . $r;
+           unless ($c =~ /\.ent.*\n\$.*\.\.ng:/) {
+               if (($p, $r) = split(/^\t\.prologue/, $c)) {
+                   if (($keep, $junk) = split(/\.\.ng:/, $p)) {
+                       $keep =~ s/^\t\.frame.*\n/\t.frame \$30,0,\$26,0\n/;
+                       $keep =~ s/^\t\.(mask|fmask).*\n//g;
+                       $c = $keep . "..ng:\n";
+                   } else {
+                       print STDERR "malformed code block ($ent)?\n"
+                   }
+               }
+               $c .= "\t.prologue" . $r;
+           }
        }
   
        $c =~ s/FUNNY#END#THING//;