nasm/macros.pl

58 lines
1.5 KiB
Perl
Raw Normal View History

2002-05-01 05:01:08 +08:00
#!/usr/bin/perl -w
#
2002-05-01 04:52:26 +08:00
# macros.pl produce macros.c from standard.mac
#
# The Netwide Assembler is copyright (C) 1996 Simon Tatham and
# Julian Hall. All rights reserved. The software is
# redistributable under the license given in the file "LICENSE"
2002-05-01 04:52:26 +08:00
# distributed in the NASM archive.
2002-05-01 05:01:38 +08:00
2002-05-18 15:28:31 +08:00
use strict;
2002-05-01 05:01:08 +08:00
my $fname;
my $line = 0;
my $index = 0;
my $tasm_count;
2002-05-01 04:52:26 +08:00
undef $tasm_count;
2002-05-01 04:52:26 +08:00
open(OUTPUT,">macros.c") or die "unable to open macros.c\n";
print OUTPUT "/*\n";
print OUTPUT " * Do not edit - this file auto-generated by macros.pl from:\n";
print OUTPUT " * ", join(' ', @ARGV), "\n";
print OUTPUT " */\n";
2008-02-17 05:58:45 +08:00
print OUTPUT "\n";
print OUTPUT "#include \"tables.h\"\n";
2008-02-17 05:58:45 +08:00
print OUTPUT "\n";
2008-05-27 02:39:00 +08:00
print OUTPUT "const char * const nasm_stdmac[] = {";
foreach $fname ( @ARGV ) {
open(INPUT,$fname) or die "unable to open $fname\n";
2008-05-27 02:39:00 +08:00
print OUTPUT "\n /* From $fname */\n";
while (<INPUT>) {
2002-05-01 05:01:08 +08:00
$line++;
chomp;
if (m/^\s*\*END\*TASM\*MACROS\*\s*$/) {
$tasm_count = $index;
2008-05-27 02:39:00 +08:00
print OUTPUT " /* End of TASM macros */\n";
} elsif (m/^\s*((\s*([^\"\';\s]+|\"[^\"]*\"|\'[^\']*\'))*)\s*(;.*)?$/) {
$_ = $1;
s/\\/\\\\/g;
s/"/\\"/g;
if (length > 0) {
2008-05-27 02:39:00 +08:00
print OUTPUT " \"$_\",\n";
$index++;
}
} else {
die "$fname:$line: error unterminated quote";
2002-05-01 05:01:08 +08:00
}
}
close(INPUT);
2002-05-01 04:52:26 +08:00
}
2008-05-27 02:39:00 +08:00
print OUTPUT "\n NULL\n};\n\n";
$tasm_count = $index unless ( defined($tasm_count) );
print OUTPUT "const char * const * nasm_stdmac_after_tasm = ",
"&nasm_stdmac[$tasm_count];\n";
close(OUTPUT);