From 35b4288a3300782b308604b39c5d8e19c6902f42 Mon Sep 17 00:00:00 2001 From: pooler Date: Wed, 25 Feb 2015 13:22:54 +0100 Subject: [PATCH] Modify nomacro.pl to expand assembler macros --- nomacro.pl | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/nomacro.pl b/nomacro.pl index e91cda3..17a28fd 100755 --- a/nomacro.pl +++ b/nomacro.pl @@ -1,44 +1,46 @@ #!/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 # 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) # any later version. See COPYING for more details. # -# nomacro.pl - convert assembler macros to C preprocessor macros. +# nomacro.pl - expand assembler macros. use strict; foreach my $f (<*.S>) { - rename $f, "$f.orig"; + rename $f, "$f.orig" unless -e "$f.orig"; open FIN, "$f.orig"; open FOUT, ">$f"; - my $inmacro = 0; my %macros = (); + my %m = (); while () { - if (m/^\.macro\s+([_0-9A-Z]+)(?:\s*)(.*)$/i) { - print FOUT "#define $1($2) \\\n"; - $macros{$1} = 1; - $inmacro = 1; + if (m/^\.macro\s+(\w+)\s*(.*)$/) { + $m{name} = $1; + @m{args} = [split /\s*,\s*/, $2]; + $m{body} = ""; next; } if (m/^\.endm/) { - print FOUT "\n"; - $inmacro = 0; + $macros{$m{name}} = {%m}; + %m = (); next; } - for my $m (keys %macros) { - s/^([ \t]*)($m)(?:[ \t]+([^#\n]*))?([;\n])/\1\2(\3)\4/; - } - if ($inmacro) { - if (m/^\s*#if/) { - $_ = while (!m/^\s*#endif/); - next; + for my $n (keys %macros) { + 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; + } + last; } - next if (m/^\s*$/); - s/\\//g; - s/$/; \\/; + } + if (%m) { + $m{body} .= $_; + next; } print FOUT; }