[project @ 1998-04-30 20:43:45 by sof]
[ghc-hetmet.git] / ghc / driver / ghc-split.lprl
index 267315c..962f67d 100644 (file)
@@ -9,7 +9,7 @@ sub inject_split_markers {
     local($hc_file) = @_;
 
     unlink("$Tmp_prefix.unmkd");
-    local($to_do) = "cp $hc_file $Tmp_prefix.unmkd";
+    local($to_do) = "$Cp $hc_file $Tmp_prefix.unmkd";
     &run_something($to_do, 'Prepare to number split markers');
 
     open(TMPI, "< $Tmp_prefix.unmkd") || &tidy_up_and_die(1,"$Pgm: failed to open `$Tmp_prefix.unmkd' (to read)\n");
@@ -24,10 +24,14 @@ sub inject_split_markers {
        $_ = <TMPI>;
     }
     print TMPO "__STG_SPLIT_MARKER(1)\n";
-    print TMPO $_ if ! /\/\* SPLIT \*\//;
+    print TMPO $_ if ! /^\s*\/\* SPLIT \*\/\s*$/;
+
+       # Have to be a bit careful detecting /* SPLIT */ comments
+       # since a progam may use a string containing "/* SPLIT */"
+       # We check that there is nothing else on the line
 
     while (<TMPI>) {
-       if (/\/\* SPLIT \*\//) {
+       if (/^\s*\/\* SPLIT \*\/\s*$/) {
            $marker_no++;
            print TMPO "__STG_SPLIT_MARKER($marker_no)\n";
            next;
@@ -175,6 +179,7 @@ sub process_asm_block {
     return(&process_asm_block_alpha($str)) if $TargetPlatform =~ /^alpha-/;
     return(&process_asm_block_hppa($str))  if $TargetPlatform =~ /^hppa/;
     return(&process_asm_block_mips($str))   if $TargetPlatform =~ /^mips-/;
+    return(&process_asm_block_powerpc($str))   if $TargetPlatform =~ /^powerpc-|^rs6000-/;
 
     # otherwise...
     &tidy_up_and_die(1,"$Pgm: no process_asm_block for $TargetPlatform\n");
@@ -187,15 +192,15 @@ sub process_asm_block_sparc {
     if ( $OptimiseC ) {
        $str =~ s/_?__stg_split_marker.*:\n//;
     } else {
-       $str =~ s/(\.text\n\t\.align .\n)\t\.global\s+.*_?__stg_split_marker.*\n\t\.proc.*\n/\1/;
-       $str =~ s/(\t\.align .\n)\t\.global\s+.*_?__stg_split_marker.*\n\t\.proc.*\n/\1/;
+       $str =~ s/(\.text\n\t\.align .\n)\t\.global\s+.*_?__stg_split_marker.*\n\t\.proc.*\n/$1/;
+       $str =~ s/(\t\.align .\n)\t\.global\s+.*_?__stg_split_marker.*\n\t\.proc.*\n/$1/;
     }
 
     # make sure the *.hc filename gets saved; not just ghc*.c (temp name)
     $str =~ s/^\.stabs "(ghc\d+\.c)"/.stabs "$ifile_root.hc"/g; # HACK HACK
 
     # remove/record any literal constants defined here
-    while ( $str =~ /(\t\.align .\n(LC\d+):\n\t\.ascii.*\n)/ ) {
+    while ( $str =~ /(\t\.align .\n(LC\d+):\n(\t\.ascii.*\n)+)/ ) {
        local($label) = $2;
        local($body)  = $1;
 
@@ -204,7 +209,7 @@ sub process_asm_block_sparc {
 
        $LocalConstant{$label} = $body;
        
-       $str =~ s/\t\.align .\nLC\d+:\n\t\.ascii.*\n//;
+       $str =~ s/\t\.align .\nLC\d+:\n(\t\.ascii.*\n)+//;
     }
 
     # inject definitions for any local constants now used herein
@@ -222,10 +227,10 @@ sub process_asm_block_sparc {
 sub process_asm_block_m68k {
     local($str) = @_;
 
-    # strip the marker (ToDo: something special for unregisterized???)
+    # strip the marker
 
-    $str =~ s/(\.text\n\t\.even\n)\t\.globl\s+.*_?__stg_split_marker.*\n/\1/;
-    $str =~ s/(\t\.even\n)\t\.globl\s+.*_?__stg_split_marker.*\n/\1/;
+    $str =~ s/(\.text\n\t\.even\n)\t\.globl\s+.*_?__stg_split_marker.*\n/$1/;
+    $str =~ s/(\t\.even\n)\t\.globl\s+.*_?__stg_split_marker.*\n/$1/;
 
     # it seems prudent to stick on one of these:
     $str = "\.text\n\t.even\n" . $str;
@@ -262,7 +267,7 @@ sub process_asm_block_alpha {
     if ( $OptimiseC ) {
        $str =~ s/_?__stg_split_marker.*:\n//;
     } else {
-       $str =~ s/(\t\.align .\n)\t\.globl\s+.*_?__stg_split_marker.*\n\t\.ent.*\n/\1/;
+       $str =~ s/(\t\.align .\n)\t\.globl\s+.*_?__stg_split_marker.*\n\t\.ent.*\n/$1/;
     }
 
     # remove/record any literal constants defined here
@@ -288,7 +293,7 @@ sub process_asm_block_alpha {
     # Slide the dummy direct return code into the vtbl .ent/.end block,
     # to keep the label fixed if it's the last thing in a module, and
     # to avoid having any anonymous text that the linker will complain about
-    $str =~ s/(\t\.end [A-Za-z0-9_]+)\n\t# nop/\tnop\n\1/g;
+    $str =~ s/(\t\.end [A-Za-z0-9_]+)\n\t# nop/\tnop\n$1/g;
 
     print STDERR "### STRIPPED BLOCK (alpha):\n$str" if $Dump_asm_splitting_info;
 
@@ -298,10 +303,10 @@ sub process_asm_block_alpha {
 sub process_asm_block_iX86 {
     local($str) = @_;
 
-    # strip the marker (ToDo: something special for unregisterized???)
+    # strip the marker
 
-    $str =~ s/(\.text\n\t\.align .(,0x90)?\n)\.globl\s+.*_?__stg_split_marker.*\n/\1/;
-    $str =~ s/(\t\.align .(,0x90)?\n)\.globl\s+.*_?__stg_split_marker.*\n/\1/;
+    $str =~ s/(\.text\n\t\.align .(,0x90)?\n)\.globl\s+.*_?__stg_split_marker.*\n/$1/;
+    $str =~ s/(\t\.align .(,0x90)?\n)\.globl\s+.*_?__stg_split_marker.*\n/$1/;
 
     # it seems prudent to stick on one of these:
     $str = "\.text\n\t.align 4\n" . $str;
@@ -392,7 +397,7 @@ sub process_asm_block_mips {
     if ( $OptimiseC ) {
        $str =~ s/_?__stg_split_marker.*:\n//;
     } else {
-       $str =~ s/(\t\.align .\n)\t\.globl\s+.*_?__stg_split_marker.*\n\t\.ent.*\n/\1/;
+       $str =~ s/(\t\.align .\n)\t\.globl\s+.*_?__stg_split_marker.*\n\t\.ent.*\n/$1/;
     }
 
     # remove/record any literal constants defined here
@@ -418,7 +423,7 @@ sub process_asm_block_mips {
     # Slide the dummy direct return code into the vtbl .ent/.end block,
     # to keep the label fixed if it's the last thing in a module, and
     # to avoid having any anonymous text that the linker will complain about
-    $str =~ s/(\t\.end [A-Za-z0-9_]+)\n\t# nop/\tnop\n\1/g;
+    $str =~ s/(\t\.end [A-Za-z0-9_]+)\n\t# nop/\tnop\n$1/g;
 
     $str .= $UNDEFINED_FUNS; # pin on gratuitiously-large amount of info
 
@@ -429,6 +434,42 @@ sub process_asm_block_mips {
 \end{code}
 
 \begin{code}
+sub process_asm_block_powerpc {
+    local($str) = @_;
+
+    # strip the marker
+    $str =~ s/___stg_split_marker.*\n//;
+    $str =~ s/___stg_split_marker.*\n//; # yes, twice.
+
+    # remove/record any literal constants defined here
+    while ( $str =~ /^(.csect .data[RW]\n\s+\.align.*\n(LC\.\.\d+):\n(\s\.byte .*\n)+)/ ) {
+       local($label) = $2;
+       local($body)  = $1;
+
+       &tidy_up_and_die(1,"Local constant label $label already defined!\n")
+           if $LocalConstant{$label};
+
+       $LocalConstant{$label} = $body;
+       
+       $str =~ s/^.csect .data[RW]\n\s+\.align.*\nLC\.\.\d+:\n(\s\.byte .*\n)+//;
+    }
+
+    # inject definitions for any local constants now used herein
+    foreach $k (keys %LocalConstant) {
+       if ( $str =~ /\b$k(\b|\[)/ ) {
+           $str = $LocalConstant{$k} . $str;
+       }
+    }
+
+    print STDERR "### STRIPPED BLOCK (powerpc/rs6000):\n$str" if $Dump_asm_splitting_info;
+
+    $str = ".toc\n" . $str;
+
+    $str;
+}
+\end{code}
+
+\begin{code}
 # make "require"r happy...
 1;
 \end{code}