#! /usr/pkg/gnu/bin/perl

# written by NM; adds the code, originally missing, to have a separate
# stack for each processor

# check the command line input; arg should be file.mas

die "$0 requires one source filename as an argument.\n" if $#ARGV < 0;

$infile = $ARGV[0];

open (INFILE,"$infile");
$tmp_file = "tmp_file";
open (TMP_FILE,"> $tmp_file");

while (<INFILE>) {
    print TMP_FILE $_;
    last if (/^.text/);
}

# print _main:, "boilerplate" comment, add r0,&_stackp,r30 instruction
# from the original setup

$one_line = <INFILE>;
print TMP_FILE $one_line;
$one_line = <INFILE>;
print TMP_FILE $one_line;
$one_line = <INFILE>;
print TMP_FILE $one_line;

# print NM's stack-separation code 

print TMP_FILE "cpunum r10\n"; 
print TMP_FILE "mul r10,2000,r29\n"; 
print TMP_FILE "sub r30,r29,r30\n"; 

# copy the rest

while (<INFILE>) {
   print TMP_FILE $_;
}

close(TMP_FILE);

system "mv $tmp_file $infile";
 


