summaryrefslogtreecommitdiff
path: root/macros.pl
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-06-21 15:15:40 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-06-21 15:15:40 -0700
commitcda816306d437d4b7c170afcd983263b5fb83c17 (patch)
tree725589130e196b47088d5e6375c00c21b9823cfa /macros.pl
parentf221b9ee0876124630cbdefc803d94394f847ee9 (diff)
downloadnasm-cda816306d437d4b7c170afcd983263b5fb83c17.tar.gz
Drop the index tables from the canned macros
Instead of an array of strings, just have a character array; that reduces the size of canned macros by up to 30%, and we only did sequential access anyway.
Diffstat (limited to 'macros.pl')
-rwxr-xr-xmacros.pl55
1 files changed, 37 insertions, 18 deletions
diff --git a/macros.pl b/macros.pl
index 18c77596..4fe775ea 100755
--- a/macros.pl
+++ b/macros.pl
@@ -10,26 +10,45 @@
require 'phash.ph';
require 'pptok.ph';
+use bytes;
+
my $fname;
my $line = 0;
my $index = 0;
my $tasm_count = 0;
#
+# Print out a string as a character array
+#
+sub charcify(@) {
+ my $l = '';
+ my $c, $o;
+ foreach $o (unpack("C*", join('',@_))) {
+ $c = pack("C", $o);
+ if ($o < 32 || $o > 126 || $c eq '"' || $c eq "\\") {
+ $l .= sprintf("(char)%3d,", $o);
+ } else {
+ $l .= "\'".$c."\',";
+ }
+ }
+ return $l;
+}
+
+#
# Generate macros.c
#
open(OUT,">macros.c") or die "unable to open macros.c\n";
print OUT "/*\n";
print OUT " * Do not edit - this file auto-generated by macros.pl from:\n";
-print OUT " * ", join(' ', @ARGV), "\n";
+print OUT " * ", join("\n * ", @ARGV), "\n";
print OUT " */\n";
print OUT "\n";
print OUT "#include \"tables.h\"\n";
print OUT "#include \"nasmlib.h\"\n";
print OUT "#include \"hashtbl.h\"\n";
print OUT "\n";
-print OUT "const char * const nasm_stdmac[] = {";
+print OUT "const char nasm_stdmac[] = {";
my $npkg = 0;
my @pkg_list = ();
@@ -38,6 +57,7 @@ my $pkg;
my @out_list = ();
my $outfmt;
my $lastname;
+my $z;
foreach $fname ( @ARGV ) {
open(INPUT,$fname) or die "unable to open $fname\n";
@@ -50,10 +70,10 @@ foreach $fname ( @ARGV ) {
} elsif (m/^OUT:\s*(.*\S)\s*$/) {
undef $pkg;
my @out_alias = split(/\s+/, $1);
- printf OUT " /* %4d */ NULL\n", $index++;
+ printf OUT " /* %4d */ 0\n", $index++;
print OUT "};\n";
$index = 0;
- printf OUT "const char * const %s_stdmac[] = {\n", $out_alias[0];
+ printf OUT "const char %s_stdmac[] = {\n", $out_alias[0];
print OUT " /* From $fname */\n";
$lastname = $fname;
push(@out_list, $out_alias[0]);
@@ -63,23 +83,20 @@ foreach $fname ( @ARGV ) {
if (defined($pkg_number{$pkg})) {
die "$0: $fname: duplicate package: $pkg\n";
}
- printf OUT " /* %4d */ NULL,\n", $index++;
+ printf OUT " /* %4d */ 0\n", $index++;
print OUT "};\n";
$index = 0;
- printf OUT "static const char * const nasm_stdmac_%s[] = {\n", $pkg;
+ printf OUT "static const char nasm_stdmac_%s[] = {\n", $pkg;
print OUT " /* From $fname */\n";
$lastname = $fname;
push(@pkg_list, $pkg);
$pkg_number{$pkg} = $npkg++;
- $pkg_index{$pkg} = $index;
- printf OUT " /* %4d */ \"\\x%02x\"\"%s\",\n",
- $index++, $pptok_hash{'%define'}+128, "__USE_\U$pkg\E__";
+ $z = pack("C", $pptok_hash{'%define'}+128)."__USE_\U$pkg\E__";
+ printf OUT " /* %4d */ %s0,\n", $index, charcify($z);
+ $index += length($z)+1;
} elsif (m/^\s*((\s*([^\"\';\s]+|\"[^\"]*\"|\'[^\']*\'))*)\s*(;.*)?$/) {
my $s1, $s2, $pd, $ws;
$s1 = $1;
- $s1 =~ s/(\s)\s+/$1/g;
- $s1 =~ s/\\/\\\\/g;
- $s1 =~ s/"/\\"/g;
$s2 = '';
while ($s1 =~ /(\%[a-zA-Z_][a-zA-Z0-9_]*)((\s+)(.*)|)$/) {
$s2 .= "$'";
@@ -88,7 +105,7 @@ foreach $fname ( @ARGV ) {
$s1 = $4;
if (defined($pptok_hash{$pd}) &&
$pptok_hash{$pd} <= 127) {
- $s2 .= sprintf("\\x%02x\"\"", $pptok_hash{$pd}+128);
+ $s2 .= pack("C", $pptok_hash{$pd}+128);
} else {
$s2 .= $pd.$ws;
}
@@ -99,7 +116,9 @@ foreach $fname ( @ARGV ) {
print OUT "\n /* From $fname */\n";
$lastname = $fname;
}
- printf OUT " /* %4d */ \"%s\",\n", $index++, $s2;
+ printf OUT " /* %4d */ %s0,\n",
+ $index, charcify($s2);
+ $index += length($s2)+1;
}
} else {
die "$fname:$line: error unterminated quote";
@@ -107,8 +126,8 @@ foreach $fname ( @ARGV ) {
}
close(INPUT);
}
-printf OUT " /* %4d */ NULL\n};\n\n", $index++;
-print OUT "const char * const * const nasm_stdmac_after_tasm = ",
+printf OUT " /* %4d */ 0\n};\n\n", $index++;
+print OUT "const char * const nasm_stdmac_after_tasm = ",
"&nasm_stdmac[$tasm_count];\n\n";
my @hashinfo = gen_perfect_hash(\%pkg_number);
@@ -120,11 +139,11 @@ verify_hash_table(\%pkg_number, \@hashinfo);
my ($n, $sv, $g) = @hashinfo;
die if ($n & ($n-1));
-print OUT "const char * const *nasm_stdmac_find_package(const char *package)\n";
+print OUT "const char *nasm_stdmac_find_package(const char *package)\n";
print OUT "{\n";
print OUT " static const struct {\n";
print OUT " const char *package;\n";
-print OUT " const char * const *macros;\n";
+print OUT " const char *macros;\n";
print OUT " } packages[$npkg] = {\n";
foreach $pkg (@pkg_list) {
printf OUT " { \"%s\", nasm_stdmac_%s },\n",