2005-01-27 04:39:55 +03:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
|
|
|
|
my $asmarch = shift;
|
|
|
|
my $asmformat = shift;
|
|
|
|
my $basedir = shift;
|
|
|
|
my $output = shift;
|
|
|
|
|
|
|
|
if ( ! $asmarch) {
|
|
|
|
print "usage: generate-asm.pl [ASMARCH] [ASMFORMAT] [BASEDIR] [OUTPUT NAME]\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
open(INPUT, "$basedir/$asmarch.asm") ||
|
|
|
|
die "Could not open $basedir/$asmarch.asm: $!\n";
|
|
|
|
open(OUTPUT, ">$output") || die "Could not open $output: $1\n";
|
|
|
|
|
2005-01-31 07:16:54 +03:00
|
|
|
$CONFIG = "default";
|
|
|
|
$TEXT = "";
|
|
|
|
$GLOBAL = "";
|
|
|
|
$SUFFIX = "";
|
|
|
|
$GSYM = "";
|
|
|
|
$LSYM = "";
|
|
|
|
$TYPE = "";
|
|
|
|
$SIZE = 0;
|
|
|
|
$ALIGN_LOG = 0;
|
|
|
|
$DEL_R_REG = 0;
|
|
|
|
$IS64BIT = 0;
|
|
|
|
|
|
|
|
($CONFIG, $TEXT, $GLOBAL, $SUFFIX, $GSYM, $LSYM, $TYPE, $SIZE, $ALIGN_LOG, $DEL_R_REG, $IS64BIT) = (
|
|
|
|
$asmformat =~ /(.*)\-(.*)\-(.*)\-(.*)\-(.*)\-(.*)\-(.*)\-(.*)\-(.*)\-(.*)\-(.*)/);
|
|
|
|
|
|
|
|
if (0) {
|
|
|
|
print "CONFIG: $CONFIG\n";
|
|
|
|
print "TEXT: $TEXT\n";
|
|
|
|
print "GLOBAL: $GLOBAL\n";
|
|
|
|
print "SUFFIX: $SUFFIX\n";
|
|
|
|
print "GSYM: $GSYM\n";
|
|
|
|
print "LSYM: $LSYM\n";
|
|
|
|
}
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
my $current_func = "";
|
|
|
|
my $delete = 0;
|
|
|
|
|
2005-01-31 07:16:54 +03:00
|
|
|
# load our configuration
|
|
|
|
do "$basedir/$CONFIG.conf" or die "Could not open config file $basedir/$CONFIG.conf: $!\n";
|
|
|
|
|
2005-01-27 04:39:55 +03:00
|
|
|
while (<INPUT>) {
|
|
|
|
s/TEXT/$TEXT/g;
|
|
|
|
s/GLOBAL/$GLOBAL/g;
|
2005-02-08 22:27:32 +03:00
|
|
|
s/REFGSYM\((.*)\)/$GSYM$1/g;
|
|
|
|
s/REFLSYM\((.*)\)/$LSYM$1/g;
|
2005-01-27 04:39:55 +03:00
|
|
|
s/GSYM\((.*)\)/$GSYM$1$SUFFIX/g;
|
|
|
|
s/LSYM\((.*)\)/$LSYM$1$SUFFIX/g;
|
2005-02-08 22:27:32 +03:00
|
|
|
|
2005-01-27 04:39:55 +03:00
|
|
|
if ($DEL_R_REG == 0) {
|
2005-02-08 22:27:32 +03:00
|
|
|
s/cr([0-9][0-9]?)/$1/g;
|
2005-01-27 04:39:55 +03:00
|
|
|
s/r([0-9][0-9]?)/$1/g;
|
|
|
|
}
|
|
|
|
|
2005-01-31 07:16:54 +03:00
|
|
|
if (/START_FILE/) {
|
|
|
|
$_ = start_file();
|
|
|
|
}
|
|
|
|
|
2005-01-27 04:39:55 +03:00
|
|
|
if (/START_FUNC\((.*)\)/) {
|
|
|
|
$current_func = $1;
|
2005-01-31 07:16:54 +03:00
|
|
|
$_ = start_func($current_func);
|
2005-01-27 04:39:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (/END_FUNC\((.*)\)/) {
|
2005-01-31 07:16:54 +03:00
|
|
|
$current_func = $1;
|
|
|
|
$_ = end_func($current_func);
|
2005-01-27 04:39:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($ALIGN_LOG == 0) {
|
|
|
|
s/ALIGN\((\d*)\)/.align $1/g;
|
|
|
|
} else {
|
|
|
|
# Ugh...
|
|
|
|
if (m/ALIGN\((\d*)\)/) {
|
|
|
|
$val = $1;
|
|
|
|
$result = 0;
|
|
|
|
while ($val > 1) { $val /= 2; $result++ }
|
|
|
|
s/ALIGN\((\d*)\)/.align $result/;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (/^\#START_64BIT/) {
|
|
|
|
$_ = "";
|
|
|
|
if ($IS64BIT == 0) {
|
|
|
|
$delete = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (/^\#END_64BIT/) {
|
|
|
|
$_ = "";
|
|
|
|
$delete = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($delete == 0) {
|
|
|
|
print OUTPUT $_;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
close(INPUT);
|
|
|
|
close(OUTPUT);
|