Modify nomacro.pl to expand assembler macros
This commit is contained in:
parent
9373a5c433
commit
35b4288a33
1 changed files with 22 additions and 20 deletions
40
nomacro.pl
40
nomacro.pl
|
@ -1,45 +1,47 @@
|
||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
# Copyright 2012 pooler@litecoinpool.org
|
# Copyright 2012, 2015 pooler@litecoinpool.org
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify it
|
# This program is free software; you can redistribute it and/or modify it
|
||||||
# under the terms of the GNU General Public License as published by the Free
|
# under the terms of the GNU General Public License as published by the Free
|
||||||
# Software Foundation; either version 2 of the License, or (at your option)
|
# Software Foundation; either version 2 of the License, or (at your option)
|
||||||
# any later version. See COPYING for more details.
|
# any later version. See COPYING for more details.
|
||||||
#
|
#
|
||||||
# nomacro.pl - convert assembler macros to C preprocessor macros.
|
# nomacro.pl - expand assembler macros.
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
foreach my $f (<*.S>) {
|
foreach my $f (<*.S>) {
|
||||||
rename $f, "$f.orig";
|
rename $f, "$f.orig" unless -e "$f.orig";
|
||||||
open FIN, "$f.orig";
|
open FIN, "$f.orig";
|
||||||
open FOUT, ">$f";
|
open FOUT, ">$f";
|
||||||
my $inmacro = 0;
|
|
||||||
my %macros = ();
|
my %macros = ();
|
||||||
|
my %m = ();
|
||||||
while (<FIN>) {
|
while (<FIN>) {
|
||||||
if (m/^\.macro\s+([_0-9A-Z]+)(?:\s*)(.*)$/i) {
|
if (m/^\.macro\s+(\w+)\s*(.*)$/) {
|
||||||
print FOUT "#define $1($2) \\\n";
|
$m{name} = $1;
|
||||||
$macros{$1} = 1;
|
@m{args} = [split /\s*,\s*/, $2];
|
||||||
$inmacro = 1;
|
$m{body} = "";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if (m/^\.endm/) {
|
if (m/^\.endm/) {
|
||||||
print FOUT "\n";
|
$macros{$m{name}} = {%m};
|
||||||
$inmacro = 0;
|
%m = ();
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
for my $m (keys %macros) {
|
for my $n (keys %macros) {
|
||||||
s/^([ \t]*)($m)(?:[ \t]+([^#\n]*))?([;\n])/\1\2(\3)\4/;
|
if (m/^\s*$n\b\s*(.*)$/) {
|
||||||
|
my @a = split /\s*,\s*/, $1;
|
||||||
|
$_ = $macros{$n}{body};
|
||||||
|
for my $i (0 .. $#{$macros{$n}{args}}) {
|
||||||
|
s/\\$macros{$n}{args}[$i]\b/$a[$i]/g;
|
||||||
}
|
}
|
||||||
if ($inmacro) {
|
last;
|
||||||
if (m/^\s*#if/) {
|
}
|
||||||
$_ = <FIN> while (!m/^\s*#endif/);
|
}
|
||||||
|
if (%m) {
|
||||||
|
$m{body} .= $_;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
next if (m/^\s*$/);
|
|
||||||
s/\\//g;
|
|
||||||
s/$/; \\/;
|
|
||||||
}
|
|
||||||
print FOUT;
|
print FOUT;
|
||||||
}
|
}
|
||||||
close FOUT;
|
close FOUT;
|
||||||
|
|
Loading…
Reference in a new issue