[project @ 2000-08-04 23:31:43 by lewie]
[ghc-hetmet.git] / ghc / driver / mangler / ghc-asm.lprl
index 6139b3c..605b6c2 100644 (file)
@@ -42,6 +42,28 @@ for the same reason.  Advantage: No more ridiculous call sequences.
 
 %************************************************************************
 %*                                                                     *
+\subsection{Top-level code}
+%*                                                                     *
+%************************************************************************
+
+\begin{code}
+$TargetPlatform = $TARGETPLATFORM;
+
+($Pgm = $0) =~ s|.*/||;
+$ifile = $ARGV[0];
+$ofile = $ARGV[1];
+
+if ( $TargetPlatform =~ /^i386-/ ) {
+    $StolenX86Regs = $ARGV[2];
+}
+
+&mangle_asm($ifile,$ofile);
+
+exit(0);
+\end{code}
+
+%************************************************************************
+%*                                                                     *
 \subsection{Constants for various architectures}
 %*                                                                     *
 %************************************************************************
@@ -104,7 +126,7 @@ sub init_TARGET_STUFF {
     $T_HDR_direct   = "\t.SPACE \$TEXT\$\n\t.SUBSPA \$CODE\$\n\t\.align 4\n";
 
     #--------------------------------------------------------#
-    } elsif ( $TargetPlatform =~ /^i386-.*-(linuxaout|freebsd2|netbsd|nextstep3|cygwin32|mingw32)$/ ) {
+    } elsif ( $TargetPlatform =~ /^i386-.*-(linuxaout|freebsd2|netbsd|openbsd|nextstep3|cygwin32|mingw32)$/ ) {
                                # NeXT added but not tested. CaS
 
     $T_STABBY      = 1; # 1 iff .stab things (usually if a.out format)
@@ -435,7 +457,7 @@ sub mangle_asm {
            $chkcat[$i]  = 'literal';
            $chksymb[$i] = $1;
 
-       } elsif ( /^$TUS[@]?__stg_split_marker(\d+)$TPOSTLBL[@]?$/o ) {
+       } elsif ( /^$TUS[@]?__stg_split_marker(\d*)$TPOSTLBL[@]?$/o ) {
            $chk[++$i]   = $_;
            $chkcat[$i]  = 'splitmarker';
            $chksymb[$i] = $1;
@@ -564,7 +586,7 @@ sub mangle_asm {
                unless $KNOWN_FUNNY_THING{$thing}
                    || /^$TUS[@]?stg_.*$TPOSTLBL[@]?$/o    # RTS internals
                    || /^$TUS[@]__fexp_.*$TPOSTLBL$/o      # foreign export
-                   || /^$TUS[@]?_reg.*$TPOSTLBL$/o        # PROF: __reg<module>
+                   || /^$TUS[@]?__init.*$TPOSTLBL$/o      # __init<module>
                    || /^$TUS[@]?.*_btm$TPOSTLBL$/o        # large bitmaps
                    || /^$TUS[@]?.*_closure_tbl$TPOSTLBL$/o; # closure tables
            $chk[++$i]   = $_;
@@ -711,8 +733,10 @@ sub mangle_asm {
                    $e =~ s/^\tret\n//;
                    $e =~ s/^\tpopl \%edi\n//;
                    $e =~ s/^\tpopl \%esi\n//;
+                   $e =~ s/^\tpopl \%edx\n//;
                    $e =~ s/^\tpopl \%ecx\n//;
                    $e =~ s/^\taddl \$\d+,\%esp\n//;
+                   $e =~ s/^\tsubl \$-\d+,\%esp\n//;
                } elsif ($TargetPlatform =~ /^m68k-/) {
                    $e =~ s/^\tunlk a6\n//;
                    $e =~ s/^\trts\n//;
@@ -733,7 +757,7 @@ sub mangle_asm {
                # HWL HACK: dont die, just print a warning
                #print stderr "HWL: this should die! Epilogue junk?: $e\n" if $e =~ /^\t[^\.]/
                #    && $TargetPlatform !~ /^powerpc-/; #ToDo: remove test
-               die "Epilogue junk?: $e\n" if $e =~ /^\t[^\.]/
+               die "Epilogue junk?: $e\n" if $e =~ /^\t[^\.\n]/
                    && $TargetPlatform !~ /^powerpc-/; #ToDo: remove test
 
                # glue together what's left
@@ -781,7 +805,28 @@ sub mangle_asm {
                                                           # (this SEGVs perl4 on alphas, you see)
 
            $to_move = $1;
-           if ( $i < ($numchks - 1)
+
+           # on x86 we try not to copy any directives into a literal
+           # chunk, rather we keep looking for the next real chunk.  This
+           # is because we get things like
+           #
+           #    .globl blah_closure
+           #    .LC32
+           #           .string "..."
+           #    blah_closure:
+           #           ...
+            #
+           if ( $TargetPlatform =~ /^(i386|sparc)/ && $to_move =~ /$TCOPYDIRVS/ ) {
+               $j = $i + 1;
+               while ( $j < $numchks  && $chk[$j] =~ /$T_CONST_LBL/) {
+                       $j++;
+               }
+               if ( $j < $numchks ) {
+                       $chk[$j] = $to_move . $chk[$j];
+               }
+           }
+
+           elsif ( $i < ($numchks - 1)
              && ( $to_move =~ /$TCOPYDIRVS/
                || ($TargetPlatform =~ /^hppa/ && $to_move =~ /align/ && $chkcat[$i+1] eq 'literal') )) {
                $chk[$i + 1] = $to_move . $chk[$i + 1];
@@ -887,7 +932,7 @@ sub mangle_asm {
                 };
                &print_doctored($chk[$i], 0);
                 if ($TargetPlatform =~ /^powerpc-|^rs6000-/ && $printDS) { 
-#ok                   if ($chksymb[$i] !~ /\_regMain/) {
+#ok                   if ($chksymb[$i] !~ /\__init_Main/) {
                     print OUTASM "\.csect ${chksymb[$i]}[DS]\n";       
                     print OUTASM "${p}TOC[tc0], 0\n";
 #ok                   }
@@ -1168,7 +1213,7 @@ sub print_doctored {
 
     if ( $TargetPlatform !~ /^i386-/ 
       || ! /^\t[a-z]/  # no instructions in here, apparently
-      || /^${T_US}_reg[A-Za-z0-9_]+${T_POST_LBL}/) {
+      || /^${T_US}__init_[A-Za-z0-9_]+${T_POST_LBL}/) {
        print OUTASM $_;
        return;
     }
@@ -1473,7 +1518,12 @@ sub mangle_powerpc_tailjump {
       };
     $c;
 }
+\end{code}
 
-# make "require"r happy...
-1;
+\begin{code}
+sub tidy_up_and_die {
+    local($return_val, $msg) = @_;
+    print STDERR $msg;
+    exit (($return_val == 0) ? 0 : 1);
+}
 \end{code}