%************************************************************************
%* *
+\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}
%* *
%************************************************************************
$T_HDR_data = "\.data\n\t\.align 3\n";
$T_HDR_consist = "\.text\n";
$T_HDR_closure = "\.data\n\t\.align 3\n";
- $T_HDR_srt = "\.data\n\t\.align 3\n";
+ $T_HDR_srt = "\.text\n\t\.align 3\n";
$T_HDR_info = "\.text\n\t\.align 3\n";
$T_HDR_entry = "\.text\n\t\.align 3\n";
$T_HDR_fast = "\.text\n\t\.align 3\n";
$T_HDR_consist = "\.text\n";
$T_HDR_closure = "\.data\n\t\.align 2\n";
$T_HDR_closure = "\.data\n\t\.align 2\n\t.long 0\n" if ( $TargetPlatform =~ /.*-mingw32$/ );
- $T_HDR_srt = "\.data\n\t\.align 2\n";
+ $T_HDR_srt = "\.text\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";
$T_HDR_direct = "\.text\n\t\.align 2,0x90\n";
#--------------------------------------------------------#
- } elsif ( $TargetPlatform =~ /^i386-.*-(solaris2|linux|freebsd3|netbsd_elf)$/ ) {
+ } elsif ( $TargetPlatform =~ /^i386-.*-(solaris2|linux|freebsd|netbsd_elf)$/ ) {
$T_STABBY = 0; # 1 iff .stab things (usually if a.out format)
$T_US = ''; # _ if symbols have an underscore on the front
$T_PRE_APP = # regexp that says what comes before APP/NO_APP
- ($TargetPlatform =~ /-(linux|freebsd3|netbsd_elf)$/) ? '#' : '/' ;
+ ($TargetPlatform =~ /-(linux|freebsd|netbsd_elf)$/) ? '#' : '/' ;
$T_CONST_LBL = '^\.LC(\d+):$'; # regexp for what such a lbl looks like
$T_POST_LBL = ':';
$T_X86_PRE_LLBL_PAT = '\.L';
$T_MOVE_DIRVS = '^(\s*(\.(p2)?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)';
- if ( $TargetPlatform =~ /freebsd3|netbsd_elf/ ) {
+ if ( $TargetPlatform =~ /freebsd|netbsd_elf/ ) {
$T_hsc_cc_PAT = '\.ascii.*\)(hsc|cc) (.*)\\\\11"\n\t\.ascii\s+"(.*)\\\\0"';
} else {
$T_hsc_cc_PAT = '\.string.*\)(hsc|cc) (.*)\\\\t(.*)"';
$T_HDR_data = "\.data\n\t\.align 4\n"; # ToDo: change align??
$T_HDR_consist = "\.text\n";
$T_HDR_closure = "\.data\n\t\.align 4\n"; # ToDo: change align?
- $T_HDR_srt = "\.data\n\t\.align 4\n"; # ToDo: change align?
+ $T_HDR_srt = "\.text\n\t\.align 4\n"; # ToDo: change align?
$T_HDR_info = "\.text\n\t\.align 4\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 4\n";
$T_HDR_data = "\.data\n\t\.even\n";
$T_HDR_consist = "\.text\n";
$T_HDR_closure = "\.data\n\t\.even\n";
- $T_HDR_srt = "\.data\n\t\.even\n";
+ $T_HDR_srt = "\.text\n\t\.even\n";
$T_HDR_info = "\.text\n\t\.even\n";
$T_HDR_entry = "\.text\n\t\.even\n";
$T_HDR_fast = "\.text\n\t\.even\n";
$T_HDR_data = "\t\.data\n\t\.align 2\n";
$T_HDR_consist = 'TOO LAZY TO DO THIS TOO';
$T_HDR_closure = "\t\.data\n\t\.align 2\n";
- $T_HDR_srt = "\t\.data\n\t\.align 2\n";
+ $T_HDR_srt = "\t\.text\n\t\.align 2\n";
$T_HDR_info = "\t\.text\n\t\.align 2\n";
$T_HDR_entry = "\t\.text\n\t\.align 2\n";
$T_HDR_fast = "\t\.text\n\t\.align 2\n";
$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;
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] = $_;
$e =~ s/^\tpopl \%esi\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//;
# 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
# (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/ && $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];
};
&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 }
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;
}
};
$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}