0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-10-10 00:25:06 -04:00

Merge branch 'netwide-assembler:master' into master

This commit is contained in:
yjh-styx
2025-10-03 01:45:35 +03:00
committed by GitHub
16 changed files with 684 additions and 371 deletions

2
.gitignore vendored
View File

@@ -78,9 +78,9 @@ TAGS
/doc/pptok.src
/doc/fontpath
/doc/Fontmap
/editors/nasmtok.el
/include/warnings.h
/macros/macros.c
/misc/nasmtok.el
/misc/omfdump
/misc/Makefile
/nasm

View File

@@ -15,6 +15,7 @@ exec_prefix = @exec_prefix@
bindir = @bindir@
mandir = @mandir@
datarootdir = @datarootdir@
datadir = @datadir@
CC = @CC@
CFLAGS = @CFLAGS@
@@ -47,6 +48,7 @@ PERLFLAGS = -I$(top_srcdir)/perllib -I$(srcdir)
RUNPERL = $(PERL) $(PERLFLAGS)
EMPTY = : >
SIDE = @: Generated by side effect
PYTHON3 = python3
@@ -93,7 +95,7 @@ endif
.PHONY: all doc misc install clean distclean cleaner spotless test
.PHONY: install_doc everything install_everything strip perlreq dist tags TAGS
.PHONY: nothing manpages nsis
.PHONY: nothing manpages nsis editors
.c.$(O):
$(CC) -c $(ALL_CFLAGS) -o $@ $<
@@ -211,8 +213,11 @@ ALLOBJ_W = $(NASM) $(LIBOBJ_W)
ALLOBJ = $(PROGOBJ) $(LIBOBJ)
SUBDIRS = stdlib nasmlib include config output asm disasm x86 \
common zlib macros misc
XSUBDIRS = nsis win test doc
XSUBDIRS = nsis win test doc editors
DEPDIRS = . $(SUBDIRS)
EDITORS = editors/nasmtok.el
#-- End File Lists --#
all: $(PROGS)
@@ -243,7 +248,6 @@ ndisasm$(X): $(NDISASM) $(MANIFEST) $(DISLIB) $(NASMLIB)
$(DISLIB) $(NASMLIB) $(LIBS)
# These are specific to certain Makefile syntaxes...
WARNTIMES = $(WARNFILES:=.time)
WARNSRCS = $(ALLOBJ_W:.$(O)=.c)
# Make sure we have subdirectories set up...
@@ -264,7 +268,6 @@ PERLREQ_CLEANABLE = \
macros/macros.c \
asm/pptok.ph asm/directbl.c asm/directiv.h \
$(WARNFILES) \
misc/nasmtok.el \
version.h version.mac version.mak nsis/version.nsh
PERLREQ = $(PERLREQ_CLEANABLE)
@@ -338,43 +341,6 @@ x86/regs.h: x86/regs.dat x86/regs.pl
$(RUNPERL) $(srcdir)/x86/regs.pl h \
$(srcdir)/x86/regs.dat > x86/regs.h
# Extract warnings from source code. This is done automatically if any
# C files have changed; the script is fast enough that that is
# reasonable, but doesn't update the time stamp if the files aren't
# changed, to avoid rebuilding everything every time. Track the actual
# dependency by the empty file asm/warnings.time.
.PHONY: warnings
warnings:
$(RM_F) $(WARNFILES) $(WARNTIMES) asm/warnings.time
$(MAKE) asm/warnings.time
asm/warnings.time: $(WARNSRCS) asm/warnings.pl
$(EMPTY) asm/warnings.time
$(MAKE) $(WARNTIMES)
asm/warnings_c.h.time: asm/warnings.pl asm/warnings.time
$(RUNPERL) $(srcdir)/asm/warnings.pl c asm/warnings_c.h \
$(srcdir) $(WARNSRCS)
$(EMPTY) asm/warnings_c.h.time
asm/warnings_c.h: asm/warnings_c.h.time
@: Side effect
include/warnings.h.time: asm/warnings.pl asm/warnings.time
$(RUNPERL) $(srcdir)/asm/warnings.pl h include/warnings.h \
$(srcdir) $(WARNSRCS)
$(EMPTY) include/warnings.h.time
include/warnings.h: include/warnings.h.time
@: Side effect
doc/warnings.src.time: asm/warnings.pl asm/warnings.time
$(RUNPERL) $(srcdir)/asm/warnings.pl doc doc/warnings.src \
$(srcdir) $(WARNSRCS)
$(EMPTY) doc/warnings.src.time
doc/warnings.src : doc/warnings.src.time
@: Side effect
# Assembler token hash
asm/tokhash.c: x86/insns.xda x86/insnsn.c asm/tokens.dat asm/tokhash.pl \
@@ -413,12 +379,60 @@ asm/directbl.c: asm/directiv.dat nasmlib/perfhash.pl perllib/phash.ph
$(srcdir)/asm/directiv.dat asm/directbl.c
# Emacs token files
misc/nasmtok.el: misc/emacstbl.pl asm/tokhash.c asm/pptok.c \
asm/directiv.dat version
$(RUNPERL) $(srcdir)/misc/emacstbl.pl $@ $(srcdir) $(objdir)
editors/nasmtok.el: editors/nasmtok.pl asm/tokhash.c asm/pptok.c \
asm/directiv.dat macros/macros.c editors/builtin.mac \
version.mak
$(RUNPERL) $(srcdir)/editors/nasmtok.pl -el $@ $(srcdir) $(objdir)
editors: $(EDITORS)
#-- End Generated File Rules --#
# Extract warnings from source code. This is done automatically if any
# C files have changed; the script is fast enough that that is
# reasonable, but doesn't update the time stamp if the files aren't
# changed, to avoid rebuilding everything every time. Track the actual
# dependency by the empty file asm/warnings.time.
#
# This doesn't seem to work for non-Unix Makefile variants, so don't
# export those rules here (non-Unix Makefiles only guaranteed to build
# a distribution ball anyway.)
WARNTIMES = $(WARNFILES:=.time)
.PHONY: warnings
warnings:
$(RM_F) $(WARNFILES) $(WARNTIMES) asm/warnings.time
$(MAKE) asm/warnings.time
asm/warnings.time: $(WARNSRCS) asm/warnings.pl
$(EMPTY) asm/warnings.time
$(MAKE) $(WARNTIMES)
asm/warnings_c.h.time: asm/warnings.pl asm/warnings.time
$(RUNPERL) $(srcdir)/asm/warnings.pl c asm/warnings_c.h \
$(srcdir) $(WARNSRCS)
$(EMPTY) asm/warnings_c.h.time
asm/warnings_c.h: asm/warnings_c.h.time
$(SIDE)
include/warnings.h.time: asm/warnings.pl asm/warnings.time
$(RUNPERL) $(srcdir)/asm/warnings.pl h include/warnings.h \
$(srcdir) $(WARNSRCS)
$(EMPTY) include/warnings.h.time
include/warnings.h: include/warnings.h.time
$(SIDE)
doc/warnings.src.time: asm/warnings.pl asm/warnings.time
$(RUNPERL) $(srcdir)/asm/warnings.pl doc doc/warnings.src \
$(srcdir) $(WARNSRCS)
$(EMPTY) doc/warnings.src.time
doc/warnings.src : doc/warnings.src.time
$(SIDE)
$(PERLREQ): $(DIRS)
perlreq: $(PERLREQ)
@@ -453,6 +467,10 @@ install: $(PROGS)
$(INSTALL_DATA) $(srcdir)/nasm.1 $(DESTDIR)$(mandir)/man1/nasm.1
$(INSTALL_DATA) $(srcdir)/ndisasm.1 $(DESTDIR)$(mandir)/man1/ndisasm.1
install_editors: $(EDITORS)
$(MKDIR_P) $(DESTDIR)$(datadir)
$(INSTALL_DATA) $(EDITORS) $(DESTDIR)$(datadir)
clean:
for d in . $(SUBDIRS) $(XSUBDIRS); do \
$(RM_F) "$$d"/*.$(O) "$$d"/*.s "$$d"/*.i "$$d"/*.$(A) ; \
@@ -473,7 +491,7 @@ distclean: clean
-$(SHELL) autoconf/clean.sh || $(SHELL) $(srcdir)/autoconf/clean.sh
cleaner:
$(RM_F) $(PERLREQ_CL) *.1 nasm.spec
$(RM_F) $(PERLREQ_CL) $(EDITORS) *.1 nasm.spec
$(MAKE) -C doc clean
$(MAKE) -C misc clean
$(MAKE) distclean
@@ -521,7 +539,7 @@ always_everything: $(DIRS)
everything: always_everything
$(MAKE) $(MANPAGES) $(NSIS) nothing
install_everything: everything install install_doc
install_everything: everything install install_doc install_editors
dist:
$(MAKE) alldeps

View File

@@ -18,39 +18,49 @@ exec_prefix = $(prefix)
bindir = $(prefix)/bin
mandir = $(prefix)/man
MANIFEST_FLAGS = /MANIFEST:EMBED /MANIFESTFILE:$(MANIFEST)
MANIFEST_FLAGS = /manifest:embed /manifestfile:$(MANIFEST)
!IF "$(DEBUG)" == "1"
CFLAGS = /Od /Zi
LDFLAGS = /DEBUG
OPTFLAGS = /Od
LDFLAGS = /debug
!ELSE
CFLAGS = /O2 /Zi
OPTFLAGS = /O2
# /OPT:REF and /OPT:ICF two undo /DEBUG harm
LDFLAGS = /DEBUG /OPT:REF /OPT:ICF
LDFLAGS = /debug /opt:ref /opt:icf
!ENDIF
CC = cl
AR = lib
ARFLAGS = /nologo
CFLAGS = $(OPTFLAGS) /Zi /nologo /std:c11 /bigobj
BUILD_CFLAGS = $(CFLAGS) /W2
INTERNAL_CFLAGS = /I$(srcdir) /I. \
/I$(srcdir)/include /I./include \
/I$(srcdir)/x86 /I./x86 \
/I$(srcdir)/asm /I./asm \
/I$(srcdir)/disasm /I./disasm \
/I$(srcdir)/output /I./output
/I$(srcdir)/output /I./output \
/I$(srcdir)/zlib
ALL_CFLAGS = $(BUILD_CFLAGS) $(INTERNAL_CFLAGS)
MANIFEST_FLAGS = /MANIFEST:EMBED /MANIFESTINPUT:$(MANIFEST)
ALL_LDFLAGS = /link $(LDFLAGS) $(MANIFEST_FLAGS) /SUBSYSTEM:CONSOLE /RELEASE
MANIFEST_FLAGS = /manifest:embed /manifestinput:$(MANIFEST)
ALL_LDFLAGS = /link $(LDFLAGS) $(MANIFEST_FLAGS) /subsystem:console /release
LIBS =
PERL = perl
PERLFLAGS = -I$(srcdir)/perllib -I$(srcdir)
!IF [$(PERL) $(PERLFLAGS) -e "exit 0;"] == 0
RUNPERL = $(PERL) $(PERLFLAGS)
!ELSE
RUNPERL = :
!ENDIF
MAKENSIS = makensis
RM_F = -del /f
LN_S = copy
RM_F = -del /s /f /q
LN_S = copy /y
EMPTY = copy /y nul:
SIDE = @rem Created by side effect
# Binary suffixes
O = obj
@@ -60,7 +70,7 @@ X = .exe
.SUFFIXES: $(X) .$(A) .obj .c .i .s .1 .man
.c.obj:
$(CC) /c $(ALL_CFLAGS) /Fo$@ $<
$(CC) /c $(ALL_CFLAGS) /Fo:$@ $<
MANIFEST = win/manifest.xml
@@ -178,20 +188,21 @@ NDISLIB = libndis.$(A)
all: nasm$(X) ndisasm$(X)
nasm$(X): $(NASM) $(MANIFEST) $(NASMLIB)
$(CC) /Fe$@ $(NASM) $(ALL_LDFLAGS) $(NASMLIB) $(LIBS)
$(CC) /Fe:$@ $(ALL_CFLAGS) $(NASM) $(NASMLIB) $(LIBS) \
$(ALL_LDFLAGS)
ndisasm$(X): $(NDISASM) $(MANIFEST) $(NDISLIB) $(NASMLIB)
$(CC) /Fe$@ $(NDISASM) $(ALL_LDFLAGS) $(NDISLIB) $(NASMLIB) $(LIBS)
$(CC) /Fe:$@ $(ALL_CFLAGS) $(NDISASM) $(NDISLIB) $(NASMLIB) $(LIBS) \
$(ALL_LDFLAGS)
$(NASMLIB): $(LIBOBJ)
$(AR) $(ARFLAGS) /OUT:$@ $**
$(AR) $(ARFLAGS) /out:$@ $**
$(NDISLIB): $(LIBOBJ_DIS)
$(AR) $(ARFLAGS) /OUT:$@ $**
$(AR) $(ARFLAGS) /out:$@ $**
# These are specific to certain Makefile syntaxes...
WARNTIMES = $(patsubst %,%.time,$(WARNFILES))
WARNSRCS = $(patsubst %.obj,%.c,$(LIBOBJ_NW))
WARNSRCS = $(LIBOBJ_NW:.c=.obj)
#-- Begin Generated File Rules --#
# Edit in Makefile.in, not here!
@@ -283,43 +294,6 @@ x86\regs.h: x86\regs.dat x86\regs.pl
$(RUNPERL) $(srcdir)\x86\regs.pl h \
$(srcdir)\x86\regs.dat > x86\regs.h
# Extract warnings from source code. This is done automatically if any
# C files have changed; the script is fast enough that that is
# reasonable, but doesn't update the time stamp if the files aren't
# changed, to avoid rebuilding everything every time. Track the actual
# dependency by the empty file asm\warnings.time.
.PHONY: warnings
warnings:
$(RM_F) $(WARNFILES) $(WARNTIMES) asm\warnings.time
$(MAKE) asm\warnings.time
asm\warnings.time: $(WARNSRCS) asm\warnings.pl
$(EMPTY) asm\warnings.time
$(MAKE) $(WARNTIMES)
asm\warnings_c.h.time: asm\warnings.pl asm\warnings.time
$(RUNPERL) $(srcdir)\asm\warnings.pl c asm\warnings_c.h \
$(srcdir) $(WARNSRCS)
$(EMPTY) asm\warnings_c.h.time
asm\warnings_c.h: asm\warnings_c.h.time
@: Side effect
include\warnings.h.time: asm\warnings.pl asm\warnings.time
$(RUNPERL) $(srcdir)\asm\warnings.pl h include\warnings.h \
$(srcdir) $(WARNSRCS)
$(EMPTY) include\warnings.h.time
include\warnings.h: include\warnings.h.time
@: Side effect
doc\warnings.src.time: asm\warnings.pl asm\warnings.time
$(RUNPERL) $(srcdir)\asm\warnings.pl doc doc\warnings.src \
$(srcdir) $(WARNSRCS)
$(EMPTY) doc\warnings.src.time
doc\warnings.src : doc\warnings.src.time
@: Side effect
# Assembler token hash
asm\tokhash.c: x86\insns.xda x86\insnsn.c asm\tokens.dat asm\tokhash.pl \

View File

@@ -28,12 +28,19 @@ PERL = perl
PERLFLAGS = -I$(srcdir)\perllib -I$(srcdir)
RUNPERL = $(PERL) $(PERLFLAGS)
EMPTY = $(RUNPERL) -e ""
.BEFORE
set COPYCMD=/y
RM_F = -del /f
LN_S = copy
EMPTY = copy nul:
SIDE = @rem Created by side effect
MAKENSIS = makensis
# Binary suffixes
O = obj
A = lib
X = .exe
# WMAKE errors out if a suffix is declared more than once, including
@@ -41,7 +48,7 @@ X = .exe
# first. Also, WMAKE only allows implicit rules that point "to the left"
# in this list!
.SUFFIXES:
.SUFFIXES: .man .1 .obj .i .c
.SUFFIXES: .man .1 .obj .i .c .lib .exe
# Needed to find C files anywhere but in the current directory
.c : $(VPATH)
@@ -296,43 +303,6 @@ x86\regs.h: x86\regs.dat x86\regs.pl
$(RUNPERL) $(srcdir)\x86\regs.pl h &
$(srcdir)\x86\regs.dat > x86\regs.h
# Extract warnings from source code. This is done automatically if any
# C files have changed; the script is fast enough that that is
# reasonable, but doesn't update the time stamp if the files aren't
# changed, to avoid rebuilding everything every time. Track the actual
# dependency by the empty file asm\warnings.time.
.PHONY: warnings
warnings:
$(RM_F) $(WARNFILES) $(WARNTIMES) asm\warnings.time
$(MAKE) asm\warnings.time
asm\warnings.time: $(WARNSRCS) asm\warnings.pl
$(EMPTY) asm\warnings.time
$(MAKE) $(WARNTIMES)
asm\warnings_c.h.time: asm\warnings.pl asm\warnings.time
$(RUNPERL) $(srcdir)\asm\warnings.pl c asm\warnings_c.h &
$(srcdir) $(WARNSRCS)
$(EMPTY) asm\warnings_c.h.time
asm\warnings_c.h: asm\warnings_c.h.time
@: Side effect
include\warnings.h.time: asm\warnings.pl asm\warnings.time
$(RUNPERL) $(srcdir)\asm\warnings.pl h include\warnings.h &
$(srcdir) $(WARNSRCS)
$(EMPTY) include\warnings.h.time
include\warnings.h: include\warnings.h.time
@: Side effect
doc\warnings.src.time: asm\warnings.pl asm\warnings.time
$(RUNPERL) $(srcdir)\asm\warnings.pl doc doc\warnings.src &
$(srcdir) $(WARNSRCS)
$(EMPTY) doc\warnings.src.time
doc\warnings.src : doc\warnings.src.time
@: Side effect
# Assembler token hash
asm\tokhash.c: x86\insns.xda x86\insnsn.c asm\tokens.dat asm\tokhash.pl &

View File

@@ -27,7 +27,7 @@ static void nasm_z_free(void *opaque, void *ptr)
nasm_free(ptr);
}
char *uncompress_stdmac(const macros_t *sm)
char *uncompress_stdmac(macros_t *sm)
{
z_stream zs;
void *buf = nasm_malloc(sm->dsize);

161
editors/builtin.mac Normal file
View File

@@ -0,0 +1,161 @@
;;; Automatically generated list of builtin macros
%define __?FILE?__
%define __?LINE?__
%define __?BITS?__
%define __?PTR?__
%define __?DEFAULT?__
%idefine %abs(=)
%idefine %chr(=+)
%idefine %count(+)
%idefine %depend()
%idefine %eval(=+)
%idefine %hs2b(&&+)
%idefine %map(+)
%idefine %null(+)
%idefine %pathsearch()
%idefine %realpath()
%idefine %str(&+)
%idefine %strcat(&&+)
%idefine %strlen(&&)
%idefine %tok(&&)
%idefine %is(+)
%idefine %isctx(+)
%idefine %isdef(+)
%idefine %isdefalias(+)
%idefine %isdifi(+)
%idefine %isdirective(+)
%idefine %isempty(+)
%idefine %isenv(+)
%idefine %isfile(+)
%idefine %isid(+)
%idefine %isidn(+)
%idefine %isidni(+)
%idefine %ismacro(+)
%idefine %isnum(+)
%idefine %isstr(+)
%idefine %istoken(+)
%idefine %isusable(+)
%idefine %isusing(+)
%idefine %isn(+)
%idefine %isnctx(+)
%idefine %isndef(+)
%idefine %isndefalias(+)
%idefine %isndifi(+)
%idefine %isndirective(+)
%idefine %isnempty(+)
%idefine %isnenv(+)
%idefine %isnfile(+)
%idefine %isnid(+)
%idefine %isnidn(+)
%idefine %isnidni(+)
%idefine %isnmacro(+)
%idefine %isnnum(+)
%idefine %isnstr(+)
%idefine %isntoken(+)
%idefine %isnusable(+)
%idefine %isnusing(+)
%idefine %hex(=+/ux)
%idefine %sel(=,+)
%idefine %cond(=,,)
%idefine %num(=,=,=)
%idefine %substr(&&,=,=)
%idefine %ord(&&,=,=)
%idefine %b2hs(&&,&&)
%idefine %findi(&&,+)
%idefine %find(&&,+)
%define __?PASS?__
%define __?SECT?__
%defalias __SECT__
%define __?SECTALIGN_ALIGN_UPDATES_SECTION?__
%defalias __SECTALIGN_ALIGN_UPDATES_SECTION__
%define __?FLOAT_DAZ?__
%define __?FLOAT_ROUND?__
%define __?FLOAT?__
%defalias __FLOAT_DAZ__
%defalias __FLOAT_ROUND__
%defalias __FLOAT__
%defalias __NASM_MAJOR__
%defalias __NASM_MINOR__
%defalias __NASM_SUBMINOR__
%defalias __NASM_PATCHLEVEL__
%defalias __NASM_SNAPSHOT__
%defalias __NASM_VERSION_ID__
%defalias __NASM_VER__
%defalias __OUTPUT_FORMAT__
%defalias __DEBUG_FORMAT__
%defalias __DATE__
%defalias __DATE_NUM__
%defalias __TIME__
%defalias __TIME_NUM__
%defalias __UTC_DATE__
%defalias __UTC_DATE_NUM__
%defalias __UTC_TIME__
%defalias __UTC_TIME_NUM__
%defalias __POSIX_TIME__
%defalias __FILE__
%defalias __LINE__
%defalias __BITS__
%defalias __PTR__
%defalias __PASS__
%idefine __?infinity?__
%idefine __?nan?__
%idefine __?qnan?__
%idefine __?snan?__
%idefine __?float8?__
%idefine __?float16?__
%idefine __?float32?__
%idefine __?float64?__
%idefine __?float80m?__
%idefine __?float80e?__
%idefine __?float128l?__
%idefine __?float128h?__
%idefine __?utf16?__
%idefine __?utf16le?__
%idefine __?utf16be?__
%idefine __?utf32?__
%idefine __?utf32le?__
%idefine __?utf32be?__
%idefine __?ilog2e?__
%idefine __?ilog2w?__
%idefine __?ilog2f?__
%idefine __?ilog2c?__
%idefalias __infinity__
%idefalias __nan__
%idefalias __qnan__
%idefalias __snan__
%idefalias __float8__
%idefalias __float16__
%idefalias __float32__
%idefalias __float64__
%idefalias __float80m__
%idefalias __float80e__
%idefalias __float128l__
%idefalias __float128h__
%idefalias __utf16__
%idefalias __utf16le__
%idefalias __utf16be__
%idefalias __utf32__
%idefalias __utf32le__
%idefalias __utf32be__
%idefalias __ilog2e__
%idefalias __ilog2w__
%idefalias __ilog2f__
%idefalias __ilog2c__
%define __?NASM_HAS_IFDIRECTIVE?__
%define __?NASM_MAJOR?__
%define __?NASM_MINOR?__
%define __?NASM_SUBMINOR?__
%define __?NASM_PATCHLEVEL?__
%define __?NASM_VERSION_ID?__
%define __?NASM_VER?__
%define __?SECT?__
%define __?DATE?__
%define __?DATE_NUM?__
%define __?TIME?__
%define __?TIME_NUM?__
%define __?UTC_DATE?__
%define __?UTC_DATE_NUM?__
%define __?UTC_TIME?__
%define __?UTC_TIME_NUM?__
%define __?POSIX_TIME?__
%define __?OUTPUT_FORMAT?__

20
editors/dumpbuiltin.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/sh -
# Copyright 1996-20xx The NASM Authors - All Rights Reserved
# SPDX-License-Identifier: BSD-2-Clause
#
# Run the nasm binary and extract the list of macros that may or may
# not be defined in .mac files.
#
tmp="$(mktemp -d)"
[ -n "$tmp" ] || exit 1
NASM="${NASM:-../nasm}"
: > "$tmp/junk.asm"
"$NASM" -f bin -o "$tmp/junk.bin" -Lsb -l "$tmp/junk.lst" "$tmp/junk.asm"
printf ';;; Automatically generated list of builtin macros\n'
sed -n -E -e 's/^[^;]*;;; *(%i?(define|defalias|macro)) ([^ ]*) .*$/\1 \3/p'\
< "$tmp/junk.lst"
rm -rf "$tmp"

380
editors/nasmtok.pl Executable file
View File

@@ -0,0 +1,380 @@
#!/usr/bin/perl
#
# Automatically produce some tables useful for a NASM major mode
#
use integer;
use strict;
use File::Spec;
use File::Find;
my $format = 'el';
if ($ARGV[0] =~ /^-(\S+)$/) {
$format = $1;
shift @ARGV;
}
my($outfile, $srcdir, $objdir) = @ARGV;
if (!defined($outfile)) {
die "Usage: $0 [-format] outfile srcdir objdir\n";
}
my @vpath;
$srcdir = $srcdir || File::Spec->curdir();
$objdir = $objdir || $srcdir;
push(@vpath, $objdir) if ($objdir ne $srcdir);
push(@vpath, $srcdir);
my %tokens = (); # Token lists per category
my %token_category = (); # Tokens to category map
sub xpush($@) {
my $ref = shift @_;
$$ref = [] unless (defined($$ref));
return push(@$$ref, @_);
}
# Search for a file, and return a file handle if successfully opened
sub open_vpath($$) {
my($mode, $file) = @_;
my %tried;
# For simplicity, allow filenames to be specified
# with Unix / syntax internally
$file = File::Spec->catfile(split(/\//, $file));
foreach my $d (@vpath) {
my $fn = File::Spec->catfile($d, $file);
next if ($tried{$fn});
$tried{$fn}++;
my $fh;
return $fh if (open($fh, $mode, $fn));
}
return undef;
}
sub must_open($) {
my($file) = @_;
my $fh = open_vpath('<', $file);
return $fh if (defined($fh));
die "$0:$file: $!\n";
}
# Combine some specific token types
my %override = (
'brcconst' => 'special-constant',
'id' => 'special',
'float' => 'function',
'floatize' => 'function',
'strfunc' => 'function',
'ifunc' => 'function',
'insn' => 'instruction',
'reg' => 'register',
'seg' => 'special',
'wrt' => 'special',
'times' => 'special');
sub addtoken($@) {
my $type = shift @_;
foreach my $token (@_) {
unless (defined($token_category{$token})) {
$type = $override{$type} if (defined($override{$type}));
xpush(\$tokens{$type}, $token);
$token_category{$token} = $type;
}
}
}
sub read_tokhash_c($) {
my($tokhash_c) = @_;
my $th = must_open($tokhash_c);
my $l;
my $tokendata = 0;
while (defined($l = <$th>)) {
if ($l =~ /\bstruct tokendata tokendata\[/) {
$tokendata = 1;
next;
} elsif (!$tokendata) {
next;
}
last if ($l =~ /\}\;/);
if ($l =~ /^\s*\{\s*\"(.*?)\",.*?,\s*TOKEN_(\w+),(.*)\}/) {
my $token = $1;
my $type = lc($2);
my $flags = $3;
$token = "{${token}}" if ($flags =~ /\bTFLAG_BRC\b/);
# Parametric token: omit the actual parameter(s)
$token =~ s/^(\{[\w-]+=).+(\})$/$1$2/;
if ($token !~ /^(\{[\w-]+=?\}|\w+)$/) {
$type = 'operator';
} elsif ($token =~ /^__\?masm_.*\?__$/) {
next;
}
addtoken($type, $token);
if ($token =~ /^__\?(.*)\?__$/) {
# Also encode the "user" (macro) form without __?...?__
addtoken($type, $1);
}
}
}
close($th);
}
sub read_pptok_c($) {
my($pptok_c) = @_;
my $pt = must_open($pptok_c);
my $l;
my $pp_dir = 0;
while (defined($l = <$pt>)) {
if ($l =~ /\bpp_directives\[/) {
$pp_dir = 1;
next;
} elsif (!$pp_dir) {
next;
}
last if ($l =~ /\}\;/);
if ($l =~ /^\s*\"(.*?)\"/) {
addtoken('pp-directive', $1);
}
}
close($pt);
}
sub read_directiv_dat($) {
my($directiv_dat) = @_;
my $dd = must_open($directiv_dat);
my $l;
my $directiv = 0;
while (defined($l = <$dd>)) {
if ($l =~ /^\; ---.*?(pragma)?/) {
$directiv = ($1 ne 'pragma');
next;
} elsif (!$directiv) {
next;
}
if ($l =~ /^\s*(\w+)/) {
addtoken('directive', $1);
}
}
close($dd);
}
my %version;
sub read_version($) {
my($vfile) = @_;
my $v = must_open($vfile);
while (defined(my $vl = <$v>)) {
if ($vl =~ /^NASM_(\w+)=(\S+)\s*$/) {
$version{lc($1)} = $2;
}
}
close($v);
}
# This is called from the directory search in read_macros(), so
# don't use must_open() here.
sub read_macro_file($) {
my($file) = @_;
open(my $fh, '<', $file) or die "$0:$file: $!\n";
while (defined(my $l = <$fh>)) {
next unless ($l =~ /^\s*\%/);
my @f = split(/\s+/, $l);
next unless (scalar(@f) >= 2);
next if ($f[1] =~ /^[\%\$][^\(]+$/); # Internal use only
$f[1] =~ s/\(.*$//; # Strip argument list if any
$f[1] = lc($f[1]) if ($f[0] =~ /^\%i/);
if ($f[0] =~ /^\%(i)?(assign|defalias|define|defstr|substr|xdefine)\b/) {
addtoken('smacro', $f[1]);
} elsif ($f[0] =~ /^\%i?macro$/) {
addtoken('mmacro', $f[1]);
}
}
close($fh);
}
sub read_macros(@) {
my %visited;
my @dirs = (File::Spec->curdir(), qw(macros output editors));
@dirs = map { my $od = $_; map { File::Spec->catdir($od, $_) } @dirs } @_;
foreach my $dir (@dirs) {
next if ($visited{$dir});
$visited{$dir}++;
next unless opendir(my $dh, $dir);
while (defined(my $fn = readdir($dh))) {
next unless ($fn =~ /\.mac$/i);
read_macro_file(File::Spec->catfile($dir, $fn));
}
closedir($dh);
}
}
# Handle special tokens which may not have been picked up by the automatic
# process, because they depend on the build parameters, or are buried
# deep in C code...
sub add_special_cases() {
# Not defined in non-snapshot builds
addtoken('smacro', '__NASM_SNAPSHOT__', '__?NASM_SNAPSHOT?__');
}
sub make_lines($$@) {
my $maxline = shift @_;
my $indent = shift @_;
# The first line isn't explicitly indented and the last line
# doesn't end in "\n"; assumed the surrounding formatter wants
# do control that
my $linepos = 0;
my $linewidth = $maxline - $indent;
my $line = '';
my @lines = ();
foreach my $w (@_) {
my $l = length($w);
if ($linepos > 0 && $linepos+$l+1 >= $linewidth) {
$line .= "\n" . (' ' x $indent);
push(@lines, $line);
$linepos = 0;
$line = '';
}
if ($linepos > 0) {
$line .= ' ';
$linepos++;
}
$line .= $w;
$linepos += $l;
}
if ($linepos > 0) {
push(@lines, $line);
}
return @lines;
}
sub quote_for_emacs(@) {
return map { s/[\\\"\']/\\$1/g; '"'.$_.'"' } @_;
}
# Emacs LISP
sub write_output_el {
my($out, $outfile, $file) = @_;
my $whoami = 'NASM '.$version{'ver'};
print $out ";;; ${file} --- lists of NASM assembler tokens\n\n";
print $out ";;; Commentary:\n\n";
print $out ";; This file contains list of tokens from the NASM x86\n";
print $out ";; assembler, automatically extracted from ${whoami}.\n";
print $out ";;\n";
print $out ";; This file is intended to be (require)d from a `nasm-mode\'\n";
print $out ";; major mode definition.\n";
print $out ";;\n";
print $out ";; Tokens that are only recognized inside curly braces are\n";
print $out ";; noted as such. Tokens of the form {xxx=} are parametric\n";
print $out ";; tokens, where the token may contain additional text on\n";
print $out ";; the right side of the = sign. For example,\n";
print $out ";; {dfv=} should be matched by {dfv=cf,zf}.\n";
print $out "\n";
print $out ";;; Code:\n";
my @types = sort keys(%tokens);
# Write the individual token type lists
foreach my $type (sort keys(%tokens)) {
print $out "\n(defconst nasm-${type}\n";
print $out " \'(";
print $out make_lines(78, 4, quote_for_emacs(sort @{$tokens{$type}}));
print $out ")\n";
print $out " \"${whoami} ${type} tokens for `nasm-mode\'.\")\n";
}
# Generate a list of all the token type lists.
print $out "\n(defconst nasm-token-lists\n";
print $out " \'(";
print $out make_lines(78, 4, map { "'nasm-$_" } sort keys(%tokens));
print $out ")\n";
print $out " \"List of all ${whoami} token type lists.\")\n";
# The NASM token extracted version
printf $out "\n(defconst nasm-token-version %s\n",
quote_for_emacs($version{'ver'});
print $out " \"Version of NASM from which tokens were extracted,\n";
print $out "as a human-readable string.\")\n";
printf $out "\n(defconst nasm-token-version-id #x%08x\n",
$version{'version_id'};
print $out " \"Version of NASM from which tokens were extracted,\n";
print $out "as numeric identifier, for comparisons. Equivalent to the\n";
print $out "__?NASM_VERSION_ID?__ NASM macro value.\")\n";
printf $out "\n(defconst nasm-token-version-snapshot %s\n",
$version{'snapshot'} || 'nil';
print $out " \"Daily NASM snapshot build from which tokens were extracted,\n";
print $out "as a decimal number in YYYYMMDD format, or nil if not a\n";
print $out "daily snapshot build.\")\n";
# Footer
print $out "\n(provide 'nasmtok)\n";
print $out ";;; ${file} ends here\n";
return 0;
}
sub write_output($$) {
my($format, $outfile) = @_;
my %formats = (
'el' => \&write_output_el
);
my $outfunc = $formats{$format};
if (!defined($outfunc)) {
die "$0: unknown output format: $format\n";
}
open(my $out, '>', $outfile)
or die "$0:$outfile: $!\n";
my($vol,$dir,$file) = File::Spec->splitpath($outfile);
my $err = $outfunc->($out, $outfile, $file);
close($out);
if ($err) {
unlink($outfile);
die "$0:$outfile: error writing output\n";
}
}
add_special_cases();
read_tokhash_c('asm/tokhash.c');
read_pptok_c('asm/pptok.c');
read_directiv_dat('asm/directiv.dat');
read_version('version.mak');
read_macros(@vpath);
write_output($format, $outfile);

View File

@@ -17,7 +17,7 @@ struct builtin_macros {
};
typedef const struct builtin_macros macros_t;
char *uncompress_stdmac(const macros_t *sm);
char *uncompress_stdmac(macros_t *sm);
/* --- From standard.mac via macros.pl -> macros.c --- */

View File

@@ -116,7 +116,7 @@ sub flush_mac($$)
printf $out "static const unsigned char %s_blob[%d] = {\n", $name, $zlen;
print_data($out, $zblob);
printf $out "\n%sconst macros_t %s = {\n %d, %d, %s_blob\n};\n",
printf $out "\n%smacros_t %s = {\n %d, %d, %s_blob\n};\n",
$mac->{'static'} ? 'static ' : '',
$name, $dlen, $zlen, $name;

View File

@@ -51,7 +51,7 @@ CP_F = cp -f
CP_UF = cp -uf
PROGS = omfdump$(X)
GENDATA = nasmtok.el
GENDATA =
SRCDATA = README \
c16.mac c32.mac exebin.mac exebin2.mac \
myC32.mac scitech.mac \
@@ -85,9 +85,6 @@ all: $(PROGS) $(GENDATA)
omfdump$(X): omfdump.$(O)
$(CC) $(ALL_LDFLAGS) -o $@ $< $(LIBS)
nasmtok.el:
$(MAKE) -C ..
install-prog: $(PROGS)
$(MKDIR_P) $(DESTDIR)$(bindir)
$(INSTALL_PROGRAM) $(PROGS) $(DESTDIR)$(bindir)/

View File

@@ -1,215 +0,0 @@
#!/usr/bin/perl
#
# Automatically produce some tables useful for a NASM major mode
#
use integer;
use strict;
use File::Spec;
my($outfile, $srcdir, $objdir) = @ARGV;
if (!defined($outfile)) {
die "Usage: $0 outfile srcdir objdir\n";
}
$srcdir = File::Spec->curdir() unless (defined($srcdir));
$objdir = $srcdir unless (defined($objdir));
my %tokens = ();
sub xpush($@) {
my $ref = shift @_;
$$ref = [] unless (defined($$ref));
return push(@$$ref, @_);
}
# Combine some specific token types
my %override = ( 'id' => 'special',
'float' => 'function',
'floatize' => 'function',
'strfunc' => 'function',
'ifunc' => 'function',
'insn' => 'instruction',
'reg' => 'register',
'seg' => 'special',
'wrt' => 'special' );
sub read_tokhash_c($) {
my($tokhash_c) = @_;
open(my $th, '<', $tokhash_c)
or die "$0:$tokhash_c: $!\n";
my $l;
my $tokendata = 0;
while (defined($l = <$th>)) {
if ($l =~ /\bstruct tokendata tokendata\[/) {
$tokendata = 1;
next;
} elsif (!$tokendata) {
next;
}
last if ($l =~ /\}\;/);
if ($l =~ /^\s*\{\s*\"(.*?)\",.*?,\s*TOKEN_(\w+),.*\}/) {
my $token = $1;
my $type = lc($2);
if ($override{$type}) {
$type = $override{$type};
} elsif ($token !~ /^\w/) {
$type = 'operator';
} elsif ($token =~ /^__\?masm_.*\?__$/) {
next;
}
xpush(\$tokens{$type}, $token);
if ($token =~ /^__\?(.*)\?__$/) {
# Also encode the "user" (macro) form without __?...?__
xpush(\$tokens{$type}, $1);
}
}
}
close($th);
}
sub read_pptok_c($) {
my($pptok_c) = @_;
open(my $pt, '<', $pptok_c)
or die "$0:$pptok_c: $!\n";
my $l;
my $pp_dir = 0;
while (defined($l = <$pt>)) {
if ($l =~ /\bpp_directives\[/) {
$pp_dir = 1;
next;
} elsif (!$pp_dir) {
next;
}
last if ($l =~ /\}\;/);
if ($l =~ /^\s*\"(.*?)\"/) {
xpush(\$tokens{'pp-directive'}, $1);
}
}
close($pt);
}
sub read_directiv_dat($) {
my($directiv_dat) = @_;
open(my $dd, '<', $directiv_dat)
or die "$0:$directiv_dat: $!\n";
my $l;
my $directiv = 0;
while (defined($l = <$dd>)) {
if ($l =~ /^\; ---.*?(pragma)?/) {
$directiv = ($1 ne 'pragma');
next;
} elsif (!$directiv) {
next;
}
if ($l =~ /^\s*(\w+)/) {
xpush(\$tokens{'directive'}, $1);
}
}
close($dd);
}
my $version;
sub read_version($) {
my($vfile) = @_;
open(my $v, '<', $vfile)
or die "$0:$vfile: $!\n";
$version = <$v>;
chomp $version;
close($v);
}
sub make_lines($$@) {
my $maxline = shift @_;
my $indent = shift @_;
# The first line isn't explicitly indented and the last line
# doesn't end in "\n"; assumed the surrounding formatter wants
# do control that
my $linepos = 0;
my $linewidth = $maxline - $indent;
my $line = '';
my @lines = ();
foreach my $w (@_) {
my $l = length($w);
if ($linepos > 0 && $linepos+$l+1 >= $linewidth) {
$line .= "\n" . (' ' x $indent);
push(@lines, $line);
$linepos = 0;
$line = '';
}
if ($linepos > 0) {
$line .= ' ';
$linepos++;
}
$line .= $w;
$linepos += $l;
}
if ($linepos > 0) {
push(@lines, $line);
}
return @lines;
}
sub quote_for_emacs(@) {
return map { s/[\\\"\']/\\$1/g; '"'.$_.'"' } @_;
}
sub write_output($) {
my($outfile) = @_;
open(my $out, '>', $outfile)
or die "$0:$outfile: $!\n";
my($vol,$dir,$file) = File::Spec->splitpath($outfile);
print $out ";;; ${file} --- lists of NASM assembler tokens\n";
print $out ";;;\n";
print $out ";;; This file contains list of tokens from the NASM x86\n";
print $out ";;; assembler, automatically extracted from NASM ${version}.\n";
print $out ";;;\n";
print $out ";;; This file is intended to be (require)d from a `nasm-mode\'\n";
print $out ";;; major mode definition.\n";
foreach my $type (sort keys(%tokens)) {
print $out "\n(defconst nasm-${type}\n";
print $out " \'(";
print $out make_lines(78, 4, quote_for_emacs(sort @{$tokens{$type}}));
print $out ")\n";
print $out " \"NASM ${version} ${type} tokens for `nasm-mode\'.\")\n";
}
close($out);
}
read_tokhash_c(File::Spec->catfile($objdir, 'asm', 'tokhash.c'));
read_pptok_c(File::Spec->catfile($objdir, 'asm', 'pptok.c'));
read_directiv_dat(File::Spec->catfile($srcdir, 'asm', 'directiv.dat'));
read_version(File::Spec->catfile($srcdir, 'version'));
write_output($outfile);

View File

@@ -1,6 +1,5 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/* Copyright 2020 The NASM Authors - All Rights Reserved */
/* ----------------------------------------------------------------------- *
#include "compiler.h"
#include "nasmlib.h"

View File

@@ -19,7 +19,7 @@ use File::Temp;
use Fcntl;
my $barrier =
"#-- Everything below is generated by mkdep.pl - do not edit --#\n";
'#-- Everything below is generated by mkdep.pl - do not edit --#';
# This converts from filenames to full pathnames for our dependencies
# These are arrays of [full path, Makefile path]
@@ -61,7 +61,7 @@ sub scandeps {
}
while ( defined($line = <$fh>) ) {
chomp $line;
$line =~ s/\s+$//;
$line =~ s:/\*.*\*/::g;
$line =~ s://.*$::;
if ( $line =~ /^\s*\#\s*include\s+\"(.*)\"\s*$/ ) {
@@ -159,13 +159,14 @@ sub insert_deps($) {
my $is_external = 0;
while ( defined($line = <$in>) ) {
$line =~ s/\s+$//;
if ( $line =~ /^([^\s\#\$\:]+\.h):/ ) {
# Note: we trust the first Makefile given best
my $fpath = $1;
my $fbase = basename($fpath);
if (!defined($dep_path{$fbase})) {
$dep_path{$fbase} = [$fpath, $fpath];
print STDERR "Makefile: $fbase -> $fpath\n";
print STDERR "Makefile: $fbase -> $fpath\n" if ( $debug );
}
} elsif ( $line =~ /^\s*\#\s*@([a-z0-9-]+):\s*\"([^\"]*)\"/ ) {
$parm = $1; $val = $2;
@@ -190,12 +191,12 @@ sub insert_deps($) {
} elsif ( $line =~ /^(\s*\#?\s*EXTERNAL_DEPENDENCIES\s*=\s*)([01])\s*$/ ) {
# If this line is not present, we cannot externalize
$is_external = $externalize ? 1 : $force_inline ? 0 : $2+0;
$line = $1.$is_external."\n";
$line = $1.$is_external;
} elsif ( $line eq $barrier ) {
last; # Stop reading at barrier line
}
push @outfile, $line;
push @outfile, $line."\n";
}
close($in);
@@ -214,7 +215,7 @@ sub insert_deps($) {
$out = File::Temp->new(DIR => dirname($outpath = $external));
}
print $out $barrier;
print $out $barrier, "\n";
if ( $externalize ) {
# Just strip internal file dependency information

View File

@@ -1 +1 @@
3.00rc17
3.00rc18

View File

@@ -134,7 +134,7 @@ if ( $what eq 'h' ) {
printf "s/\@\@NASM_PATCHLEVEL\@\@/%d/g\n", $nplvl;
printf "s/\@\@NASM_SNAPSHOT\@\@/%d/g\n", $snapshot; # Possibly empty
printf "s/\@\@NASM_VERSION_ID\@\@/%d/g\n", $nasm_id;
printf "s/\@\@NASM_VERSION_XID\@\@/0x%08x/g\n", $nasm_id;
printf "s/\@\@NASM_VERSION_XID\@\@/%08x/g\n", $nasm_id;
printf "s/\@\@NASM_VER\@\@/%s/g\n", $line;
printf "s/\@\@NASM_MANGLED_VER\@\@/%s/g\n", $mangled_ver;
} elsif ( $what eq 'make' ) {
@@ -143,12 +143,20 @@ if ( $what eq 'h' ) {
printf "NASM_MINOR_VER=%d\n", $nmin;
printf "NASM_SUBMINOR_VER=%d\n", $nsmin;
printf "NASM_PATCHLEVEL_VER=%d\n", $nplvl;
printf "NASM_VERSION_ID=%d\n", $nasm_id;
printf "NASM_VERSION_XID=%08x\n", $nasm_id;
if (defined($snapshot)) {
printf "NASM_SNAPSHOT=%d\n", $snapshot;
}
} elsif ( $what eq 'nsis' ) {
printf "!define VERSION \"%s\"\n", $line;
printf "!define MAJOR_VER %d\n", $nmin;
printf "!define MINOR_VER %d\n", $nmin;
printf "!define SUBMINOR_VER %d\n", $nsmin;
printf "!define PATCHLEVEL_VER %d\n", $nplvl;
if (defined($snapshot)) {
printf "!define SNAPSHOT_VER=%d\n", $snapshot;
}
} elsif ( $what eq 'id' ) {
print $nasm_id, "\n"; # Print ID in decimal
} elsif ( $what eq 'xid' ) {