Merge branch 'new-preproc'
authorH. Peter Anvin <hpa@zytor.com>
Mon, 20 Jul 2009 05:36:44 +0000 (22:36 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Mon, 20 Jul 2009 05:36:44 +0000 (22:36 -0700)
42 files changed:
.gitignore
Makefile.in
Mkfiles/msvc.mak
Mkfiles/netware.mak
Mkfiles/openwcom.mak
Mkfiles/owlinux.mak
directives.dat [new file with mode: 0644]
directives.pl [new file with mode: 0755]
doc/nasmdoc.src
labels.c
labels.h
misc/crcgen.c [new file with mode: 0644]
misc/xcrcgen.c [new file with mode: 0644]
nasm.c
nasm.h
nasmlib.c
nasmlib.h
ndisasm.c
output/nulldbg.c
output/nullout.c [new file with mode: 0644]
output/outaout.c
output/outas86.c
output/outbin.c
output/outcoff.c
output/outdbg.c
output/outelf32.c
output/outelf64.c
output/outform.c
output/outform.h
output/outieee.c
output/outlib.h
output/outmacho32.c
output/outmacho64.c
output/outobj.c
output/outrdf.c
output/outrdf2.c
parser.c
parser.h
pptok.dat
preproc.c
raa.c
saa.c

index d68b892..26f905d 100644 (file)
@@ -19,6 +19,8 @@
 /config.log
 /config.status
 /configure
+/directives.c
+/directives.h
 /doc/*.dip
 /doc/*.hpj
 /doc/*.pdf
@@ -66,4 +68,6 @@
 /tokhash.c
 /version.h
 /version.mac
+/version.mak
+/version.nsh
 /version.sed
index 5bb73b2..fc10a5c 100644 (file)
@@ -62,8 +62,10 @@ X               = @EXEEXT@
 NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \
        raa.$(O) saa.$(O) rbtree.$(O) \
        float.$(O) insnsa.$(O) insnsb.$(O) \
+       directives.$(O) \
        assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \
        output/outform.$(O) output/outlib.$(O) output/nulldbg.$(O) \
+       output/nullout.$(O) \
        output/outbin.$(O) output/outaout.$(O) output/outcoff.$(O) \
        output/outelf.$(O) output/outelf32.$(O) output/outelf64.$(O) \
        output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \
@@ -155,11 +157,18 @@ pptok.c: pptok.dat pptok.pl perllib/phash.ph
 pptok.ph: pptok.dat pptok.pl perllib/phash.ph
        $(PERL) $(srcdir)/pptok.pl ph $(srcdir)/pptok.dat pptok.ph
 
+# Directives hash
+directives.h: directives.dat directives.pl perllib/phash.ph
+       $(PERL) $(srcdir)/directives.pl h $(srcdir)/directives.dat directives.h
+directives.c: directives.dat directives.pl perllib/phash.ph
+       $(PERL) $(srcdir)/directives.pl c $(srcdir)/directives.dat directives.c
+
 # This target generates all files that require perl.
 # This allows easier generation of distribution (see dist target).
 PERLREQ = macros.c insnsb.c insnsa.c insnsd.c insnsi.h insnsn.c \
          regs.c regs.h regflags.c regdis.c regdis.h regvals.c \
          tokhash.c tokens.h pptok.h pptok.c pptok.ph \
+         directives.c directives.h \
          version.h version.mac version.mak version.nsh
 perlreq: $(PERLREQ)
 
@@ -244,110 +253,120 @@ alldeps: perlreq
 # @object-ending: ".$(O)"
 # @path-separator: "/"
 #-- Everything below is generated by mkdep.pl - do not edit --#
-assemble.$(O): assemble.c assemble.h compiler.h config.h insns.h insnsi.h \
- nasm.h nasmlib.h pptok.h preproc.h regs.h tables.h tokens.h
+assemble.$(O): assemble.c assemble.h compiler.h config.h directives.h \
+ insns.h insnsi.h nasm.h nasmlib.h pptok.h preproc.h regs.h tables.h \
+ tokens.h
 crc64.$(O): crc64.c compiler.h config.h nasmlib.h
-disasm.$(O): disasm.c compiler.h config.h disasm.h insns.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h regdis.h regs.h sync.h tables.h tokens.h
-eval.$(O): eval.c compiler.h config.h eval.h float.h insnsi.h labels.h \
- nasm.h nasmlib.h pptok.h preproc.h regs.h
-exprlib.$(O): exprlib.c compiler.h config.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h
-float.$(O): float.c compiler.h config.h float.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h
-hashtbl.$(O): hashtbl.c compiler.h config.h hashtbl.h insnsi.h nasm.h \
+directives.$(O): directives.c compiler.h config.h directives.h hashtbl.h \
+ insnsi.h nasm.h nasmlib.h pptok.h preproc.h regs.h
+disasm.$(O): disasm.c compiler.h config.h directives.h disasm.h insns.h \
+ insnsi.h nasm.h nasmlib.h pptok.h preproc.h regdis.h regs.h sync.h tables.h \
+ tokens.h
+eval.$(O): eval.c compiler.h config.h directives.h eval.h float.h insnsi.h \
+ labels.h nasm.h nasmlib.h pptok.h preproc.h regs.h
+exprlib.$(O): exprlib.c compiler.h config.h directives.h insnsi.h nasm.h \
  nasmlib.h pptok.h preproc.h regs.h
-insnsa.$(O): insnsa.c compiler.h config.h insns.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h tokens.h
-insnsb.$(O): insnsb.c compiler.h config.h insns.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h tokens.h
-insnsd.$(O): insnsd.c compiler.h config.h insns.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h tokens.h
-insnsn.$(O): insnsn.c compiler.h config.h insnsi.h tables.h
-labels.$(O): labels.c compiler.h config.h hashtbl.h insnsi.h nasm.h \
+float.$(O): float.c compiler.h config.h directives.h float.h insnsi.h nasm.h \
  nasmlib.h pptok.h preproc.h regs.h
+hashtbl.$(O): hashtbl.c compiler.h config.h directives.h hashtbl.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h
+insnsa.$(O): insnsa.c compiler.h config.h directives.h insns.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h tokens.h
+insnsb.$(O): insnsb.c compiler.h config.h directives.h insns.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h tokens.h
+insnsd.$(O): insnsd.c compiler.h config.h directives.h insns.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h tokens.h
+insnsn.$(O): insnsn.c compiler.h config.h insnsi.h tables.h
+labels.$(O): labels.c compiler.h config.h directives.h hashtbl.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h
 lib/snprintf.$(O): lib/snprintf.c compiler.h config.h nasmlib.h
 lib/vsnprintf.$(O): lib/vsnprintf.c compiler.h config.h nasmlib.h
-listing.$(O): listing.c compiler.h config.h insnsi.h listing.h nasm.h \
- nasmlib.h pptok.h preproc.h regs.h
-macros.$(O): macros.c compiler.h config.h hashtbl.h insnsi.h nasm.h \
- nasmlib.h output/outform.h pptok.h preproc.h regs.h tables.h
-nasm.$(O): nasm.c assemble.h compiler.h config.h eval.h float.h insns.h \
- insnsi.h labels.h listing.h nasm.h nasmlib.h output/outform.h parser.h \
- pptok.h preproc.h raa.h regs.h saa.h stdscan.h tokens.h
-nasmlib.$(O): nasmlib.c compiler.h config.h insns.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h regs.h tokens.h
-ndisasm.$(O): ndisasm.c compiler.h config.h disasm.h insns.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h regs.h sync.h tokens.h
-output/nulldbg.$(O): output/nulldbg.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h regs.h
-output/outaout.$(O): output/outaout.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h raa.h regs.h \
- saa.h stdscan.h
-output/outas86.$(O): output/outas86.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h raa.h regs.h \
- saa.h
-output/outbin.$(O): output/outbin.c compiler.h config.h eval.h insnsi.h \
- labels.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
+listing.$(O): listing.c compiler.h config.h directives.h insnsi.h listing.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h
+macros.$(O): macros.c compiler.h config.h directives.h hashtbl.h insnsi.h \
+ nasm.h nasmlib.h output/outform.h pptok.h preproc.h regs.h tables.h
+nasm.$(O): nasm.c assemble.h compiler.h config.h directives.h eval.h float.h \
+ insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h output/outform.h \
+ parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h tokens.h
+nasmlib.$(O): nasmlib.c compiler.h config.h directives.h insns.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h tokens.h
+ndisasm.$(O): ndisasm.c compiler.h config.h directives.h disasm.h insns.h \
+ insnsi.h nasm.h nasmlib.h pptok.h preproc.h regs.h sync.h tokens.h
+output/nulldbg.$(O): output/nulldbg.c compiler.h config.h directives.h \
+ insnsi.h nasm.h nasmlib.h pptok.h preproc.h regs.h
+output/nullout.$(O): output/nullout.c compiler.h config.h directives.h \
+ insnsi.h nasm.h nasmlib.h output/outlib.h pptok.h preproc.h regs.h
+output/outaout.$(O): output/outaout.c compiler.h config.h directives.h \
+ eval.h insnsi.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
+ preproc.h raa.h regs.h saa.h stdscan.h
+output/outas86.$(O): output/outas86.c compiler.h config.h directives.h \
+ insnsi.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
+ preproc.h raa.h regs.h saa.h
+output/outbin.$(O): output/outbin.c compiler.h config.h directives.h eval.h \
+ insnsi.h labels.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
  preproc.h regs.h saa.h stdscan.h
-output/outcoff.$(O): output/outcoff.c compiler.h config.h insnsi.h nasm.h \
nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h raa.h regs.h \
- saa.h
-output/outdbg.$(O): output/outdbg.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h output/outform.h pptok.h preproc.h regs.h
-output/outelf.$(O): output/outelf.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h output/dwarf.h output/elfcommon.h output/outelf.h \
+output/outcoff.$(O): output/outcoff.c compiler.h config.h directives.h \
eval.h insnsi.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
preproc.h raa.h regs.h saa.h
+output/outdbg.$(O): output/outdbg.c compiler.h config.h directives.h \
insnsi.h nasm.h nasmlib.h output/outform.h pptok.h preproc.h regs.h
+output/outelf.$(O): output/outelf.c compiler.h config.h directives.h \
insnsi.h nasm.h nasmlib.h output/dwarf.h output/elfcommon.h output/outelf.h \
  output/outform.h pptok.h preproc.h regs.h
-output/outelf32.$(O): output/outelf32.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h output/dwarf.h output/elf32.h output/elfcommon.h output/outelf.h \
- output/outform.h output/outlib.h pptok.h preproc.h raa.h rbtree.h regs.h \
- saa.h stdscan.h
-output/outelf64.$(O): output/outelf64.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h output/dwarf.h output/elf64.h output/elfcommon.h output/outelf.h \
- output/outform.h output/outlib.h pptok.h preproc.h raa.h rbtree.h regs.h \
- saa.h stdscan.h
-output/outform.$(O): output/outform.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h output/outform.h pptok.h preproc.h regs.h
-output/outieee.$(O): output/outieee.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h regs.h
-output/outlib.$(O): output/outlib.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h output/outlib.h pptok.h preproc.h regs.h
-output/outmacho32.$(O): output/outmacho32.c compiler.h config.h insnsi.h \
- nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h raa.h \
- regs.h saa.h
-output/outmacho64.$(O): output/outmacho64.c compiler.h config.h insnsi.h \
- nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h raa.h \
- regs.h saa.h
-output/outobj.$(O): output/outobj.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h regs.h \
- stdscan.h
-output/outrdf.$(O): output/outrdf.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h output/outform.h pptok.h preproc.h regs.h
-output/outrdf2.$(O): output/outrdf2.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h rdoff/rdoff.h \
- regs.h saa.h
-owtest.$(O): owtest.c
-parser.$(O): parser.c compiler.h config.h float.h insns.h insnsi.h nasm.h \
- nasmlib.h parser.h pptok.h preproc.h regs.h stdscan.h tables.h tokens.h
+output/outelf32.$(O): output/outelf32.c compiler.h config.h directives.h \
+ eval.h insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf32.h \
+ output/elfcommon.h output/outelf.h output/outform.h output/outlib.h pptok.h \
+ preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
+output/outelf64.$(O): output/outelf64.c compiler.h config.h directives.h \
+ eval.h insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf64.h \
+ output/elfcommon.h output/outelf.h output/outform.h output/outlib.h pptok.h \
+ preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
+output/outexe.$(O): output/outexe.c compiler.h config.h directives.h \
+ insnsi.h nasm.h nasmlib.h output/outform.h pptok.h preproc.h regs.h
+output/outform.$(O): output/outform.c compiler.h config.h directives.h \
+ insnsi.h nasm.h nasmlib.h output/outform.h pptok.h preproc.h regs.h
+output/outieee.$(O): output/outieee.c compiler.h config.h directives.h \
+ insnsi.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
+ preproc.h regs.h
+output/outlib.$(O): output/outlib.c compiler.h config.h directives.h \
+ insnsi.h nasm.h nasmlib.h output/outlib.h pptok.h preproc.h regs.h
+output/outmacho32.$(O): output/outmacho32.c compiler.h config.h directives.h \
+ eval.h insnsi.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
+ preproc.h raa.h regs.h saa.h
+output/outmacho64.$(O): output/outmacho64.c compiler.h config.h directives.h \
+ insnsi.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
+ preproc.h raa.h regs.h saa.h
+output/outobj.$(O): output/outobj.c compiler.h config.h directives.h eval.h \
+ insnsi.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
+ preproc.h regs.h stdscan.h
+output/outrdf.$(O): output/outrdf.c compiler.h config.h directives.h \
+ insnsi.h nasm.h nasmlib.h output/outform.h pptok.h preproc.h regs.h
+output/outrdf2.$(O): output/outrdf2.c compiler.h config.h directives.h \
+ insnsi.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
+ preproc.h rdoff/rdoff.h regs.h saa.h
+parser.$(O): parser.c compiler.h config.h directives.h float.h insns.h \
+ insnsi.h nasm.h nasmlib.h parser.h pptok.h preproc.h regs.h stdscan.h \
+ tables.h tokens.h
 pptok.$(O): pptok.c compiler.h config.h hashtbl.h nasmlib.h pptok.h \
  preproc.h
-preproc.$(O): preproc.c compiler.h config.h hashtbl.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tables.h tokens.h
+preproc.$(O): preproc.c compiler.h config.h directives.h hashtbl.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tables.h \
+ tokens.h
 quote.$(O): quote.c compiler.h config.h nasmlib.h quote.h
 raa.$(O): raa.c compiler.h config.h nasmlib.h raa.h
 rbtree.$(O): rbtree.c compiler.h config.h rbtree.h
 regdis.$(O): regdis.c regdis.h regs.h
-regflags.$(O): regflags.c compiler.h config.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h tables.h
+regflags.$(O): regflags.c compiler.h config.h directives.h insnsi.h nasm.h \
nasmlib.h pptok.h preproc.h regs.h tables.h
 regs.$(O): regs.c compiler.h config.h insnsi.h tables.h
 regvals.$(O): regvals.c compiler.h config.h insnsi.h tables.h
 saa.$(O): saa.c compiler.h config.h nasmlib.h saa.h
-stdscan.$(O): stdscan.c compiler.h config.h insns.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tokens.h
-strfunc.$(O): strfunc.c compiler.h config.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h
+stdscan.$(O): stdscan.c compiler.h config.h directives.h insns.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tokens.h
+strfunc.$(O): strfunc.c compiler.h config.h directives.h insnsi.h nasm.h \
nasmlib.h pptok.h preproc.h regs.h
 sync.$(O): sync.c compiler.h config.h nasmlib.h sync.h
-tokhash.$(O): tokhash.c compiler.h config.h hashtbl.h insns.h insnsi.h \
- nasm.h nasmlib.h pptok.h preproc.h regs.h tokens.h
-ver.$(O): ver.c compiler.h config.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h version.h
+tokhash.$(O): tokhash.c compiler.h config.h directives.h hashtbl.h insns.h \
insnsi.h nasm.h nasmlib.h pptok.h preproc.h regs.h tokens.h
+ver.$(O): ver.c compiler.h config.h directives.h insnsi.h nasm.h nasmlib.h \
+ pptok.h preproc.h regs.h version.h
index 8dcb5da..d1c744a 100644 (file)
@@ -37,15 +37,17 @@ X               = .exe
 NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \
        raa.$(O) saa.$(O) rbtree.$(O) \
        float.$(O) insnsa.$(O) insnsb.$(O) \
+       directives.$(O) \
        assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \
        output/outform.$(O) output/outlib.$(O) output/nulldbg.$(O) \
+       output/nullout.$(O) \
        output/outbin.$(O) output/outaout.$(O) output/outcoff.$(O) \
        output/outelf.$(O) output/outelf32.$(O) output/outelf64.$(O) \
        output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \
-       output/outdbg.$(O) output/outieee.$(O) output/outmacho.$(O) \
-       preproc.$(O) quote.$(O) pptok.$(O) macros.$(O) \
-       listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) strfunc.$(O) \
-       tokhash.$(O) regvals.$(O) regflags.$(O)
+       output/outdbg.$(O) output/outieee.$(O) output/outmacho32.$(O) \
+       output/outmacho64.$(O) preproc.$(O) quote.$(O) pptok.$(O) \
+       macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \
+       strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O)
 
 NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \
        insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O)
@@ -182,102 +184,115 @@ everything: all doc rdf
 # @path-separator: "/"
 # @exclude: "config.h"
 #-- Everything below is generated by mkdep.pl - do not edit --#
-assemble.$(O): assemble.c assemble.h compiler.h insns.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h regs.h tables.h tokens.h
+assemble.$(O): assemble.c assemble.h compiler.h directives.h insns.h \
insnsi.h nasm.h nasmlib.h pptok.h preproc.h regs.h tables.h tokens.h
 crc64.$(O): crc64.c compiler.h nasmlib.h
-disasm.$(O): disasm.c compiler.h disasm.h insns.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regdis.h regs.h sync.h tables.h tokens.h
-eval.$(O): eval.c compiler.h eval.h float.h insnsi.h labels.h nasm.h \
- nasmlib.h pptok.h preproc.h regs.h
-exprlib.$(O): exprlib.c compiler.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h
-float.$(O): float.c compiler.h float.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h
-hashtbl.$(O): hashtbl.c compiler.h hashtbl.h insnsi.h nasm.h nasmlib.h \
+directives.$(O): directives.c compiler.h directives.h hashtbl.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h
+disasm.$(O): disasm.c compiler.h directives.h disasm.h insns.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regdis.h regs.h sync.h tables.h tokens.h
+eval.$(O): eval.c compiler.h directives.h eval.h float.h insnsi.h labels.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h
+exprlib.$(O): exprlib.c compiler.h directives.h insnsi.h nasm.h nasmlib.h \
  pptok.h preproc.h regs.h
-insnsa.$(O): insnsa.c compiler.h insns.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h tokens.h
-insnsb.$(O): insnsb.c compiler.h insns.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h tokens.h
-insnsd.$(O): insnsd.c compiler.h insns.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h tokens.h
+float.$(O): float.c compiler.h directives.h float.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h
+hashtbl.$(O): hashtbl.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h
+insnsa.$(O): insnsa.c compiler.h directives.h insns.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h tokens.h
+insnsb.$(O): insnsb.c compiler.h directives.h insns.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h tokens.h
+insnsd.$(O): insnsd.c compiler.h directives.h insns.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h tokens.h
 insnsn.$(O): insnsn.c compiler.h insnsi.h tables.h
-labels.$(O): labels.c compiler.h hashtbl.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h
+labels.$(O): labels.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
nasmlib.h pptok.h preproc.h regs.h
 lib/snprintf.$(O): lib/snprintf.c compiler.h nasmlib.h
 lib/vsnprintf.$(O): lib/vsnprintf.c compiler.h nasmlib.h
-listing.$(O): listing.c compiler.h insnsi.h listing.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h
-macros.$(O): macros.c compiler.h hashtbl.h insnsi.h nasm.h nasmlib.h \
- output/outform.h pptok.h preproc.h regs.h tables.h
-nasm.$(O): nasm.c assemble.h compiler.h eval.h float.h insns.h insnsi.h \
- labels.h listing.h nasm.h nasmlib.h output/outform.h parser.h pptok.h \
- preproc.h raa.h regs.h saa.h stdscan.h tokens.h
-nasmlib.$(O): nasmlib.c compiler.h insns.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h tokens.h
-ndisasm.$(O): ndisasm.c compiler.h disasm.h insns.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h regs.h sync.h tokens.h
-output/nulldbg.$(O): output/nulldbg.c compiler.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h
-output/outaout.$(O): output/outaout.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h output/outlib.h pptok.h preproc.h raa.h regs.h saa.h \
- stdscan.h
-output/outas86.$(O): output/outas86.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h output/outlib.h pptok.h preproc.h raa.h regs.h saa.h
-output/outbin.$(O): output/outbin.c compiler.h eval.h insnsi.h labels.h \
- nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h regs.h \
- saa.h stdscan.h
-output/outcoff.$(O): output/outcoff.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h output/outlib.h pptok.h preproc.h raa.h regs.h saa.h
-output/outdbg.$(O): output/outdbg.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h pptok.h preproc.h regs.h
-output/outelf.$(O): output/outelf.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/dwarf.h output/elfcommon.h output/outelf.h output/outform.h pptok.h \
- preproc.h regs.h
-output/outelf32.$(O): output/outelf32.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/dwarf.h output/elf32.h output/elfcommon.h output/outelf.h \
- output/outform.h output/outlib.h pptok.h preproc.h raa.h rbtree.h regs.h \
- saa.h stdscan.h
-output/outelf64.$(O): output/outelf64.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/dwarf.h output/elf64.h output/elfcommon.h output/outelf.h \
- output/outform.h output/outlib.h pptok.h preproc.h raa.h rbtree.h regs.h \
- saa.h stdscan.h
-output/outform.$(O): output/outform.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h pptok.h preproc.h regs.h
-output/outieee.$(O): output/outieee.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h output/outlib.h pptok.h preproc.h regs.h
-output/outlib.$(O): output/outlib.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outlib.h pptok.h preproc.h regs.h
-output/outmacho.$(O): output/outmacho.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h output/outlib.h pptok.h preproc.h raa.h regs.h saa.h
-output/outobj.$(O): output/outobj.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h output/outlib.h pptok.h preproc.h regs.h stdscan.h
-output/outrdf.$(O): output/outrdf.c compiler.h insnsi.h nasm.h nasmlib.h \
+listing.$(O): listing.c compiler.h directives.h insnsi.h listing.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h
+macros.$(O): macros.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
+ nasmlib.h output/outform.h pptok.h preproc.h regs.h tables.h
+nasm.$(O): nasm.c assemble.h compiler.h directives.h eval.h float.h insns.h \
+ insnsi.h labels.h listing.h nasm.h nasmlib.h output/outform.h parser.h \
+ pptok.h preproc.h raa.h regs.h saa.h stdscan.h tokens.h
+nasmlib.$(O): nasmlib.c compiler.h directives.h insns.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h tokens.h
+ndisasm.$(O): ndisasm.c compiler.h directives.h disasm.h insns.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h sync.h tokens.h
+output/nulldbg.$(O): output/nulldbg.c compiler.h directives.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h
+output/nullout.$(O): output/nullout.c compiler.h directives.h insnsi.h \
+ nasm.h nasmlib.h output/outlib.h pptok.h preproc.h regs.h
+output/outaout.$(O): output/outaout.c compiler.h directives.h eval.h \
+ insnsi.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
+ preproc.h raa.h regs.h saa.h stdscan.h
+output/outas86.$(O): output/outas86.c compiler.h directives.h insnsi.h \
+ nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h raa.h \
+ regs.h saa.h
+output/outbin.$(O): output/outbin.c compiler.h directives.h eval.h insnsi.h \
+ labels.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
+ preproc.h regs.h saa.h stdscan.h
+output/outcoff.$(O): output/outcoff.c compiler.h directives.h eval.h \
+ insnsi.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
+ preproc.h raa.h regs.h saa.h
+output/outdbg.$(O): output/outdbg.c compiler.h directives.h insnsi.h nasm.h \
+ nasmlib.h output/outform.h pptok.h preproc.h regs.h
+output/outelf.$(O): output/outelf.c compiler.h directives.h insnsi.h nasm.h \
+ nasmlib.h output/dwarf.h output/elfcommon.h output/outelf.h \
  output/outform.h pptok.h preproc.h regs.h
-output/outrdf2.$(O): output/outrdf2.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h output/outlib.h pptok.h preproc.h rdoff/rdoff.h regs.h \
- saa.h
-owtest.$(O): owtest.c
-parser.$(O): parser.c compiler.h float.h insns.h insnsi.h nasm.h nasmlib.h \
- parser.h pptok.h preproc.h regs.h stdscan.h tables.h tokens.h
+output/outelf32.$(O): output/outelf32.c compiler.h directives.h eval.h \
+ insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf32.h output/elfcommon.h \
+ output/outelf.h output/outform.h output/outlib.h pptok.h preproc.h raa.h \
+ rbtree.h regs.h saa.h stdscan.h
+output/outelf64.$(O): output/outelf64.c compiler.h directives.h eval.h \
+ insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf64.h output/elfcommon.h \
+ output/outelf.h output/outform.h output/outlib.h pptok.h preproc.h raa.h \
+ rbtree.h regs.h saa.h stdscan.h
+output/outexe.$(O): output/outexe.c compiler.h directives.h insnsi.h nasm.h \
+ nasmlib.h output/outform.h pptok.h preproc.h regs.h
+output/outform.$(O): output/outform.c compiler.h directives.h insnsi.h \
+ nasm.h nasmlib.h output/outform.h pptok.h preproc.h regs.h
+output/outieee.$(O): output/outieee.c compiler.h directives.h insnsi.h \
+ nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h regs.h
+output/outlib.$(O): output/outlib.c compiler.h directives.h insnsi.h nasm.h \
+ nasmlib.h output/outlib.h pptok.h preproc.h regs.h
+output/outmacho32.$(O): output/outmacho32.c compiler.h directives.h eval.h \
+ insnsi.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
+ preproc.h raa.h regs.h saa.h
+output/outmacho64.$(O): output/outmacho64.c compiler.h directives.h insnsi.h \
+ nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h raa.h \
+ regs.h saa.h
+output/outobj.$(O): output/outobj.c compiler.h directives.h eval.h insnsi.h \
+ nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h regs.h \
+ stdscan.h
+output/outrdf.$(O): output/outrdf.c compiler.h directives.h insnsi.h nasm.h \
+ nasmlib.h output/outform.h pptok.h preproc.h regs.h
+output/outrdf2.$(O): output/outrdf2.c compiler.h directives.h insnsi.h \
+ nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h \
+ rdoff/rdoff.h regs.h saa.h
+parser.$(O): parser.c compiler.h directives.h float.h insns.h insnsi.h \
+ nasm.h nasmlib.h parser.h pptok.h preproc.h regs.h stdscan.h tables.h \
+ tokens.h
 pptok.$(O): pptok.c compiler.h hashtbl.h nasmlib.h pptok.h preproc.h
-preproc.$(O): preproc.c compiler.h hashtbl.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h quote.h regs.h stdscan.h tables.h tokens.h
+preproc.$(O): preproc.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tables.h tokens.h
 quote.$(O): quote.c compiler.h nasmlib.h quote.h
 raa.$(O): raa.c compiler.h nasmlib.h raa.h
 rbtree.$(O): rbtree.c compiler.h rbtree.h
 regdis.$(O): regdis.c regdis.h regs.h
-regflags.$(O): regflags.c compiler.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h tables.h
+regflags.$(O): regflags.c compiler.h directives.h insnsi.h nasm.h nasmlib.h \
+ pptok.h preproc.h regs.h tables.h
 regs.$(O): regs.c compiler.h insnsi.h tables.h
 regvals.$(O): regvals.c compiler.h insnsi.h tables.h
 saa.$(O): saa.c compiler.h nasmlib.h saa.h
-stdscan.$(O): stdscan.c compiler.h insns.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h quote.h regs.h stdscan.h tokens.h
-strfunc.$(O): strfunc.c compiler.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h
+stdscan.$(O): stdscan.c compiler.h directives.h insns.h insnsi.h nasm.h \
nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tokens.h
+strfunc.$(O): strfunc.c compiler.h directives.h insnsi.h nasm.h nasmlib.h \
+ pptok.h preproc.h regs.h
 sync.$(O): sync.c compiler.h nasmlib.h sync.h
-tokhash.$(O): tokhash.c compiler.h hashtbl.h insns.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h regs.h tokens.h
-ver.$(O): ver.c compiler.h insnsi.h nasm.h nasmlib.h pptok.h preproc.h \
- regs.h version.h
+tokhash.$(O): tokhash.c compiler.h directives.h hashtbl.h insns.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h tokens.h
+ver.$(O): ver.c compiler.h directives.h insnsi.h nasm.h nasmlib.h pptok.h \
preproc.h regs.h version.h
index 9309cd5..e809c33 100644 (file)
@@ -33,15 +33,17 @@ O = o
 NASM = nasm.o nasmlib.o ver.o \
        raa.o saa.o rbtree.o \
        float.o insnsa.o insnsb.o \
+       directives.o \
        assemble.o labels.o hashtbl.o crc64.o parser.o \
        outform.o outlib.o nulldbg.o \
+       nullout.o \
        outbin.o outaout.o outcoff.o \
        outelf.o outelf32.o outelf64.o \
        outobj.o outas86.o outrdf2.o \
-       outdbg.o outieee.o outmacho.o \
-       preproc.o quote.o pptok.o macros.o \
-       listing.o eval.o exprlib.o stdscan.o strfunc.o \
-       tokhash.o regvals.o regflags.o
+       outdbg.o outieee.o outmacho32.o \
+       outmacho64.o preproc.o quote.o pptok.o \
+       macros.o listing.o eval.o exprlib.o stdscan.o \
+       strfunc.o tokhash.o regvals.o regflags.o
 
 NDISASM = ndisasm.o disasm.o sync.o nasmlib.o ver.o \
        insnsd.o insnsb.o insnsn.o regs.o regdis.o
@@ -122,96 +124,107 @@ $(OBJDIR)/version.mak: $(PROOT)/version $(PROOT)/version.pl $(OBJDIR)
 # @path-separator: ""
 # @continuation: "\"
 #-- Everything below is generated by mkdep.pl - do not edit --#
-assemble.o: assemble.c assemble.h compiler.h config.h insns.h insnsi.h \
- nasm.h nasmlib.h pptok.h preproc.h regs.h tables.h tokens.h
+assemble.o: assemble.c assemble.h compiler.h config.h directives.h insns.h \
insnsi.h nasm.h nasmlib.h pptok.h preproc.h regs.h tables.h tokens.h
 crc64.o: crc64.c compiler.h config.h nasmlib.h
-disasm.o: disasm.c compiler.h config.h disasm.h insns.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h regdis.h regs.h sync.h tables.h tokens.h
-eval.o: eval.c compiler.h config.h eval.h float.h insnsi.h labels.h nasm.h \
+directives.o: directives.c compiler.h config.h directives.h hashtbl.h \
+ insnsi.h nasm.h nasmlib.h pptok.h preproc.h regs.h
+disasm.o: disasm.c compiler.h config.h directives.h disasm.h insns.h \
+ insnsi.h nasm.h nasmlib.h pptok.h preproc.h regdis.h regs.h sync.h tables.h \
+ tokens.h
+eval.o: eval.c compiler.h config.h directives.h eval.h float.h insnsi.h \
+ labels.h nasm.h nasmlib.h pptok.h preproc.h regs.h
+exprlib.o: exprlib.c compiler.h config.h directives.h insnsi.h nasm.h \
  nasmlib.h pptok.h preproc.h regs.h
-exprlib.o: exprlib.c compiler.h config.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h
-float.o: float.c compiler.h config.h float.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h
-hashtbl.o: hashtbl.c compiler.h config.h hashtbl.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h
-insnsa.o: insnsa.c compiler.h config.h insns.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h tokens.h
-insnsb.o: insnsb.c compiler.h config.h insns.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h tokens.h
-insnsd.o: insnsd.c compiler.h config.h insns.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h tokens.h
+float.o: float.c compiler.h config.h directives.h float.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h
+hashtbl.o: hashtbl.c compiler.h config.h directives.h hashtbl.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h
+insnsa.o: insnsa.c compiler.h config.h directives.h insns.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h tokens.h
+insnsb.o: insnsb.c compiler.h config.h directives.h insns.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h tokens.h
+insnsd.o: insnsd.c compiler.h config.h directives.h insns.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h tokens.h
 insnsn.o: insnsn.c compiler.h config.h insnsi.h tables.h
-labels.o: labels.c compiler.h config.h hashtbl.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h
+labels.o: labels.c compiler.h config.h directives.h hashtbl.h insnsi.h \
nasm.h nasmlib.h pptok.h preproc.h regs.h
 snprintf.o: snprintf.c compiler.h config.h nasmlib.h
 vsnprintf.o: vsnprintf.c compiler.h config.h nasmlib.h
-listing.o: listing.c compiler.h config.h insnsi.h listing.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h
-macros.o: macros.c compiler.h config.h hashtbl.h insnsi.h nasm.h nasmlib.h \
- outform.h pptok.h preproc.h regs.h tables.h
-nasm.o: nasm.c assemble.h compiler.h config.h eval.h float.h insns.h \
- insnsi.h labels.h listing.h nasm.h nasmlib.h outform.h parser.h pptok.h \
- preproc.h raa.h regs.h saa.h stdscan.h tokens.h
-nasmlib.o: nasmlib.c compiler.h config.h insns.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h tokens.h
-ndisasm.o: ndisasm.c compiler.h config.h disasm.h insns.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h regs.h sync.h tokens.h
-nulldbg.o: nulldbg.c compiler.h config.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h
-outaout.o: outaout.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \
- outlib.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h
-outas86.o: outas86.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \
- outlib.h pptok.h preproc.h raa.h regs.h saa.h
-outbin.o: outbin.c compiler.h config.h eval.h insnsi.h labels.h nasm.h \
- nasmlib.h outform.h outlib.h pptok.h preproc.h regs.h saa.h stdscan.h
-outcoff.o: outcoff.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \
- outlib.h pptok.h preproc.h raa.h regs.h saa.h
-outdbg.o: outdbg.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \
- pptok.h preproc.h regs.h
-outelf.o: outelf.c compiler.h config.h insnsi.h nasm.h nasmlib.h dwarf.h \
- elfcommon.h outelf.h outform.h pptok.h preproc.h regs.h
-outelf32.o: outelf32.c compiler.h config.h insnsi.h nasm.h nasmlib.h dwarf.h \
- elf32.h elfcommon.h outelf.h outform.h outlib.h pptok.h preproc.h raa.h \
- rbtree.h regs.h saa.h stdscan.h
-outelf64.o: outelf64.c compiler.h config.h insnsi.h nasm.h nasmlib.h dwarf.h \
- elf64.h elfcommon.h outelf.h outform.h outlib.h pptok.h preproc.h raa.h \
- rbtree.h regs.h saa.h stdscan.h
-outform.o: outform.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \
- pptok.h preproc.h regs.h
-outieee.o: outieee.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \
- outlib.h pptok.h preproc.h regs.h
-outlib.o: outlib.c compiler.h config.h insnsi.h nasm.h nasmlib.h outlib.h \
- pptok.h preproc.h regs.h
-outmacho.o: outmacho.c compiler.h config.h insnsi.h nasm.h nasmlib.h \
- outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h
-outobj.o: outobj.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \
- outlib.h pptok.h preproc.h regs.h stdscan.h
-outrdf.o: outrdf.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \
- pptok.h preproc.h regs.h
-outrdf2.o: outrdf2.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \
- outlib.h pptok.h preproc.h rdoff.h regs.h saa.h
-owtest.o: owtest.c
-parser.o: parser.c compiler.h config.h float.h insns.h insnsi.h nasm.h \
- nasmlib.h parser.h pptok.h preproc.h regs.h stdscan.h tables.h tokens.h
+listing.o: listing.c compiler.h config.h directives.h insnsi.h listing.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h
+macros.o: macros.c compiler.h config.h directives.h hashtbl.h insnsi.h \
+ nasm.h nasmlib.h outform.h pptok.h preproc.h regs.h tables.h
+nasm.o: nasm.c assemble.h compiler.h config.h directives.h eval.h float.h \
+ insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h outform.h parser.h \
+ pptok.h preproc.h raa.h regs.h saa.h stdscan.h tokens.h
+nasmlib.o: nasmlib.c compiler.h config.h directives.h insns.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h tokens.h
+ndisasm.o: ndisasm.c compiler.h config.h directives.h disasm.h insns.h \
+ insnsi.h nasm.h nasmlib.h pptok.h preproc.h regs.h sync.h tokens.h
+nulldbg.o: nulldbg.c compiler.h config.h directives.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h
+nullout.o: nullout.c compiler.h config.h directives.h insnsi.h nasm.h \
+ nasmlib.h outlib.h pptok.h preproc.h regs.h
+outaout.o: outaout.c compiler.h config.h directives.h eval.h insnsi.h nasm.h \
+ nasmlib.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h
+outas86.o: outas86.c compiler.h config.h directives.h insnsi.h nasm.h \
+ nasmlib.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h
+outbin.o: outbin.c compiler.h config.h directives.h eval.h insnsi.h labels.h \
+ nasm.h nasmlib.h outform.h outlib.h pptok.h preproc.h regs.h saa.h \
+ stdscan.h
+outcoff.o: outcoff.c compiler.h config.h directives.h eval.h insnsi.h nasm.h \
+ nasmlib.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h
+outdbg.o: outdbg.c compiler.h config.h directives.h insnsi.h nasm.h \
+ nasmlib.h outform.h pptok.h preproc.h regs.h
+outelf.o: outelf.c compiler.h config.h directives.h insnsi.h nasm.h \
+ nasmlib.h dwarf.h elfcommon.h outelf.h outform.h pptok.h preproc.h regs.h
+outelf32.o: outelf32.c compiler.h config.h directives.h eval.h insnsi.h \
+ nasm.h nasmlib.h dwarf.h elf32.h elfcommon.h outelf.h outform.h outlib.h \
+ pptok.h preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
+outelf64.o: outelf64.c compiler.h config.h directives.h eval.h insnsi.h \
+ nasm.h nasmlib.h dwarf.h elf64.h elfcommon.h outelf.h outform.h outlib.h \
+ pptok.h preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
+outexe.o: outexe.c compiler.h config.h directives.h insnsi.h nasm.h \
+ nasmlib.h outform.h pptok.h preproc.h regs.h
+outform.o: outform.c compiler.h config.h directives.h insnsi.h nasm.h \
+ nasmlib.h outform.h pptok.h preproc.h regs.h
+outieee.o: outieee.c compiler.h config.h directives.h insnsi.h nasm.h \
+ nasmlib.h outform.h outlib.h pptok.h preproc.h regs.h
+outlib.o: outlib.c compiler.h config.h directives.h insnsi.h nasm.h \
+ nasmlib.h outlib.h pptok.h preproc.h regs.h
+outmacho32.o: outmacho32.c compiler.h config.h directives.h eval.h insnsi.h \
+ nasm.h nasmlib.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h
+outmacho64.o: outmacho64.c compiler.h config.h directives.h insnsi.h nasm.h \
+ nasmlib.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h
+outobj.o: outobj.c compiler.h config.h directives.h eval.h insnsi.h nasm.h \
+ nasmlib.h outform.h outlib.h pptok.h preproc.h regs.h stdscan.h
+outrdf.o: outrdf.c compiler.h config.h directives.h insnsi.h nasm.h \
+ nasmlib.h outform.h pptok.h preproc.h regs.h
+outrdf2.o: outrdf2.c compiler.h config.h directives.h insnsi.h nasm.h \
+ nasmlib.h outform.h outlib.h pptok.h preproc.h rdoff.h regs.h saa.h
+parser.o: parser.c compiler.h config.h directives.h float.h insns.h insnsi.h \
+ nasm.h nasmlib.h parser.h pptok.h preproc.h regs.h stdscan.h tables.h \
+ tokens.h
 pptok.o: pptok.c compiler.h config.h hashtbl.h nasmlib.h pptok.h preproc.h
-preproc.o: preproc.c compiler.h config.h hashtbl.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h quote.h regs.h stdscan.h tables.h tokens.h
+preproc.o: preproc.c compiler.h config.h directives.h hashtbl.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tables.h \
+ tokens.h
 quote.o: quote.c compiler.h config.h nasmlib.h quote.h
 raa.o: raa.c compiler.h config.h nasmlib.h raa.h
 rbtree.o: rbtree.c compiler.h config.h rbtree.h
 regdis.o: regdis.c regdis.h regs.h
-regflags.o: regflags.c compiler.h config.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h tables.h
+regflags.o: regflags.c compiler.h config.h directives.h insnsi.h nasm.h \
nasmlib.h pptok.h preproc.h regs.h tables.h
 regs.o: regs.c compiler.h config.h insnsi.h tables.h
 regvals.o: regvals.c compiler.h config.h insnsi.h tables.h
 saa.o: saa.c compiler.h config.h nasmlib.h saa.h
-stdscan.o: stdscan.c compiler.h config.h insns.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h quote.h regs.h stdscan.h tokens.h
-strfunc.o: strfunc.c compiler.h config.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h
+stdscan.o: stdscan.c compiler.h config.h directives.h insns.h insnsi.h \
nasm.h nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tokens.h
+strfunc.o: strfunc.c compiler.h config.h directives.h insnsi.h nasm.h \
nasmlib.h pptok.h preproc.h regs.h
 sync.o: sync.c compiler.h config.h nasmlib.h sync.h
-tokhash.o: tokhash.c compiler.h config.h hashtbl.h insns.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h regs.h tokens.h
-ver.o: ver.c compiler.h config.h insnsi.h nasm.h nasmlib.h pptok.h preproc.h \
- regs.h version.h
+tokhash.o: tokhash.c compiler.h config.h directives.h hashtbl.h insns.h \
insnsi.h nasm.h nasmlib.h pptok.h preproc.h regs.h tokens.h
+ver.o: ver.c compiler.h config.h directives.h insnsi.h nasm.h nasmlib.h \
pptok.h preproc.h regs.h version.h
index a25ba66..663e80c 100644 (file)
@@ -49,15 +49,17 @@ X               = .exe
 NASM = nasm.$(O) nasmlib.$(O) ver.$(O) &
        raa.$(O) saa.$(O) rbtree.$(O) &
        float.$(O) insnsa.$(O) insnsb.$(O) &
+       directives.$(O) &
        assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) &
        output\outform.$(O) output\outlib.$(O) output\nulldbg.$(O) &
+       output\nullout.$(O) &
        output\outbin.$(O) output\outaout.$(O) output\outcoff.$(O) &
        output\outelf.$(O) output\outelf32.$(O) output\outelf64.$(O) &
        output\outobj.$(O) output\outas86.$(O) output\outrdf2.$(O) &
-       output\outdbg.$(O) output\outieee.$(O) output\outmacho.$(O) &
-       preproc.$(O) quote.$(O) pptok.$(O) macros.$(O) &
-       listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) strfunc.$(O) &
-       tokhash.$(O) regvals.$(O) regflags.$(O)
+       output\outdbg.$(O) output\outieee.$(O) output\outmacho32.$(O) &
+       output\outmacho64.$(O) preproc.$(O) quote.$(O) pptok.$(O) &
+       macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) &
+       strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O)
 
 NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) &
        insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O)
@@ -211,102 +213,115 @@ everything: all doc rdf
 # @exclude: "config.h"
 # @continuation: "&"
 #-- Everything below is generated by mkdep.pl - do not edit --#
-assemble.$(O): assemble.c assemble.h compiler.h insns.h insnsi.h nasm.h &
- nasmlib.h pptok.h preproc.h regs.h tables.h tokens.h
+assemble.$(O): assemble.c assemble.h compiler.h directives.h insns.h &
insnsi.h nasm.h nasmlib.h pptok.h preproc.h regs.h tables.h tokens.h
 crc64.$(O): crc64.c compiler.h nasmlib.h
-disasm.$(O): disasm.c compiler.h disasm.h insns.h insnsi.h nasm.h nasmlib.h &
- pptok.h preproc.h regdis.h regs.h sync.h tables.h tokens.h
-eval.$(O): eval.c compiler.h eval.h float.h insnsi.h labels.h nasm.h &
- nasmlib.h pptok.h preproc.h regs.h
-exprlib.$(O): exprlib.c compiler.h insnsi.h nasm.h nasmlib.h pptok.h &
- preproc.h regs.h
-float.$(O): float.c compiler.h float.h insnsi.h nasm.h nasmlib.h pptok.h &
- preproc.h regs.h
-hashtbl.$(O): hashtbl.c compiler.h hashtbl.h insnsi.h nasm.h nasmlib.h &
+directives.$(O): directives.c compiler.h directives.h hashtbl.h insnsi.h &
+ nasm.h nasmlib.h pptok.h preproc.h regs.h
+disasm.$(O): disasm.c compiler.h directives.h disasm.h insns.h insnsi.h &
+ nasm.h nasmlib.h pptok.h preproc.h regdis.h regs.h sync.h tables.h tokens.h
+eval.$(O): eval.c compiler.h directives.h eval.h float.h insnsi.h labels.h &
+ nasm.h nasmlib.h pptok.h preproc.h regs.h
+exprlib.$(O): exprlib.c compiler.h directives.h insnsi.h nasm.h nasmlib.h &
  pptok.h preproc.h regs.h
-insnsa.$(O): insnsa.c compiler.h insns.h insnsi.h nasm.h nasmlib.h pptok.h &
- preproc.h regs.h tokens.h
-insnsb.$(O): insnsb.c compiler.h insns.h insnsi.h nasm.h nasmlib.h pptok.h &
- preproc.h regs.h tokens.h
-insnsd.$(O): insnsd.c compiler.h insns.h insnsi.h nasm.h nasmlib.h pptok.h &
- preproc.h regs.h tokens.h
+float.$(O): float.c compiler.h directives.h float.h insnsi.h nasm.h &
+ nasmlib.h pptok.h preproc.h regs.h
+hashtbl.$(O): hashtbl.c compiler.h directives.h hashtbl.h insnsi.h nasm.h &
+ nasmlib.h pptok.h preproc.h regs.h
+insnsa.$(O): insnsa.c compiler.h directives.h insns.h insnsi.h nasm.h &
+ nasmlib.h pptok.h preproc.h regs.h tokens.h
+insnsb.$(O): insnsb.c compiler.h directives.h insns.h insnsi.h nasm.h &
+ nasmlib.h pptok.h preproc.h regs.h tokens.h
+insnsd.$(O): insnsd.c compiler.h directives.h insns.h insnsi.h nasm.h &
+ nasmlib.h pptok.h preproc.h regs.h tokens.h
 insnsn.$(O): insnsn.c compiler.h insnsi.h tables.h
-labels.$(O): labels.c compiler.h hashtbl.h insnsi.h nasm.h nasmlib.h pptok.h &
- preproc.h regs.h
+labels.$(O): labels.c compiler.h directives.h hashtbl.h insnsi.h nasm.h &
nasmlib.h pptok.h preproc.h regs.h
 lib\snprintf.$(O): lib\snprintf.c compiler.h nasmlib.h
 lib\vsnprintf.$(O): lib\vsnprintf.c compiler.h nasmlib.h
-listing.$(O): listing.c compiler.h insnsi.h listing.h nasm.h nasmlib.h &
- pptok.h preproc.h regs.h
-macros.$(O): macros.c compiler.h hashtbl.h insnsi.h nasm.h nasmlib.h &
- output\outform.h pptok.h preproc.h regs.h tables.h
-nasm.$(O): nasm.c assemble.h compiler.h eval.h float.h insns.h insnsi.h &
- labels.h listing.h nasm.h nasmlib.h output\outform.h parser.h pptok.h &
- preproc.h raa.h regs.h saa.h stdscan.h tokens.h
-nasmlib.$(O): nasmlib.c compiler.h insns.h insnsi.h nasm.h nasmlib.h pptok.h &
- preproc.h regs.h tokens.h
-ndisasm.$(O): ndisasm.c compiler.h disasm.h insns.h insnsi.h nasm.h &
- nasmlib.h pptok.h preproc.h regs.h sync.h tokens.h
-output\nulldbg.$(O): output\nulldbg.c compiler.h insnsi.h nasm.h nasmlib.h &
- pptok.h preproc.h regs.h
-output\outaout.$(O): output\outaout.c compiler.h insnsi.h nasm.h nasmlib.h &
- output\outform.h output\outlib.h pptok.h preproc.h raa.h regs.h saa.h &
- stdscan.h
-output\outas86.$(O): output\outas86.c compiler.h insnsi.h nasm.h nasmlib.h &
- output\outform.h output\outlib.h pptok.h preproc.h raa.h regs.h saa.h
-output\outbin.$(O): output\outbin.c compiler.h eval.h insnsi.h labels.h &
- nasm.h nasmlib.h output\outform.h output\outlib.h pptok.h preproc.h regs.h &
- saa.h stdscan.h
-output\outcoff.$(O): output\outcoff.c compiler.h insnsi.h nasm.h nasmlib.h &
- output\outform.h output\outlib.h pptok.h preproc.h raa.h regs.h saa.h
-output\outdbg.$(O): output\outdbg.c compiler.h insnsi.h nasm.h nasmlib.h &
- output\outform.h pptok.h preproc.h regs.h
-output\outelf.$(O): output\outelf.c compiler.h insnsi.h nasm.h nasmlib.h &
- output\dwarf.h output\elfcommon.h output\outelf.h output\outform.h pptok.h &
- preproc.h regs.h
-output\outelf32.$(O): output\outelf32.c compiler.h insnsi.h nasm.h nasmlib.h &
- output\dwarf.h output\elf32.h output\elfcommon.h output\outelf.h &
- output\outform.h output\outlib.h pptok.h preproc.h raa.h rbtree.h regs.h &
- saa.h stdscan.h
-output\outelf64.$(O): output\outelf64.c compiler.h insnsi.h nasm.h nasmlib.h &
- output\dwarf.h output\elf64.h output\elfcommon.h output\outelf.h &
- output\outform.h output\outlib.h pptok.h preproc.h raa.h rbtree.h regs.h &
- saa.h stdscan.h
-output\outform.$(O): output\outform.c compiler.h insnsi.h nasm.h nasmlib.h &
- output\outform.h pptok.h preproc.h regs.h
-output\outieee.$(O): output\outieee.c compiler.h insnsi.h nasm.h nasmlib.h &
- output\outform.h output\outlib.h pptok.h preproc.h regs.h
-output\outlib.$(O): output\outlib.c compiler.h insnsi.h nasm.h nasmlib.h &
- output\outlib.h pptok.h preproc.h regs.h
-output\outmacho.$(O): output\outmacho.c compiler.h insnsi.h nasm.h nasmlib.h &
- output\outform.h output\outlib.h pptok.h preproc.h raa.h regs.h saa.h
-output\outobj.$(O): output\outobj.c compiler.h insnsi.h nasm.h nasmlib.h &
- output\outform.h output\outlib.h pptok.h preproc.h regs.h stdscan.h
-output\outrdf.$(O): output\outrdf.c compiler.h insnsi.h nasm.h nasmlib.h &
+listing.$(O): listing.c compiler.h directives.h insnsi.h listing.h nasm.h &
+ nasmlib.h pptok.h preproc.h regs.h
+macros.$(O): macros.c compiler.h directives.h hashtbl.h insnsi.h nasm.h &
+ nasmlib.h output\outform.h pptok.h preproc.h regs.h tables.h
+nasm.$(O): nasm.c assemble.h compiler.h directives.h eval.h float.h insns.h &
+ insnsi.h labels.h listing.h nasm.h nasmlib.h output\outform.h parser.h &
+ pptok.h preproc.h raa.h regs.h saa.h stdscan.h tokens.h
+nasmlib.$(O): nasmlib.c compiler.h directives.h insns.h insnsi.h nasm.h &
+ nasmlib.h pptok.h preproc.h regs.h tokens.h
+ndisasm.$(O): ndisasm.c compiler.h directives.h disasm.h insns.h insnsi.h &
+ nasm.h nasmlib.h pptok.h preproc.h regs.h sync.h tokens.h
+output\nulldbg.$(O): output\nulldbg.c compiler.h directives.h insnsi.h &
+ nasm.h nasmlib.h pptok.h preproc.h regs.h
+output\nullout.$(O): output\nullout.c compiler.h directives.h insnsi.h &
+ nasm.h nasmlib.h output\outlib.h pptok.h preproc.h regs.h
+output\outaout.$(O): output\outaout.c compiler.h directives.h eval.h &
+ insnsi.h nasm.h nasmlib.h output\outform.h output\outlib.h pptok.h &
+ preproc.h raa.h regs.h saa.h stdscan.h
+output\outas86.$(O): output\outas86.c compiler.h directives.h insnsi.h &
+ nasm.h nasmlib.h output\outform.h output\outlib.h pptok.h preproc.h raa.h &
+ regs.h saa.h
+output\outbin.$(O): output\outbin.c compiler.h directives.h eval.h insnsi.h &
+ labels.h nasm.h nasmlib.h output\outform.h output\outlib.h pptok.h &
+ preproc.h regs.h saa.h stdscan.h
+output\outcoff.$(O): output\outcoff.c compiler.h directives.h eval.h &
+ insnsi.h nasm.h nasmlib.h output\outform.h output\outlib.h pptok.h &
+ preproc.h raa.h regs.h saa.h
+output\outdbg.$(O): output\outdbg.c compiler.h directives.h insnsi.h nasm.h &
+ nasmlib.h output\outform.h pptok.h preproc.h regs.h
+output\outelf.$(O): output\outelf.c compiler.h directives.h insnsi.h nasm.h &
+ nasmlib.h output\dwarf.h output\elfcommon.h output\outelf.h &
  output\outform.h pptok.h preproc.h regs.h
-output\outrdf2.$(O): output\outrdf2.c compiler.h insnsi.h nasm.h nasmlib.h &
- output\outform.h output\outlib.h pptok.h preproc.h rdoff\rdoff.h regs.h &
- saa.h
-owtest.$(O): owtest.c
-parser.$(O): parser.c compiler.h float.h insns.h insnsi.h nasm.h nasmlib.h &
- parser.h pptok.h preproc.h regs.h stdscan.h tables.h tokens.h
+output\outelf32.$(O): output\outelf32.c compiler.h directives.h eval.h &
+ insnsi.h nasm.h nasmlib.h output\dwarf.h output\elf32.h output\elfcommon.h &
+ output\outelf.h output\outform.h output\outlib.h pptok.h preproc.h raa.h &
+ rbtree.h regs.h saa.h stdscan.h
+output\outelf64.$(O): output\outelf64.c compiler.h directives.h eval.h &
+ insnsi.h nasm.h nasmlib.h output\dwarf.h output\elf64.h output\elfcommon.h &
+ output\outelf.h output\outform.h output\outlib.h pptok.h preproc.h raa.h &
+ rbtree.h regs.h saa.h stdscan.h
+output\outexe.$(O): output\outexe.c compiler.h directives.h insnsi.h nasm.h &
+ nasmlib.h output\outform.h pptok.h preproc.h regs.h
+output\outform.$(O): output\outform.c compiler.h directives.h insnsi.h &
+ nasm.h nasmlib.h output\outform.h pptok.h preproc.h regs.h
+output\outieee.$(O): output\outieee.c compiler.h directives.h insnsi.h &
+ nasm.h nasmlib.h output\outform.h output\outlib.h pptok.h preproc.h regs.h
+output\outlib.$(O): output\outlib.c compiler.h directives.h insnsi.h nasm.h &
+ nasmlib.h output\outlib.h pptok.h preproc.h regs.h
+output\outmacho32.$(O): output\outmacho32.c compiler.h directives.h eval.h &
+ insnsi.h nasm.h nasmlib.h output\outform.h output\outlib.h pptok.h &
+ preproc.h raa.h regs.h saa.h
+output\outmacho64.$(O): output\outmacho64.c compiler.h directives.h insnsi.h &
+ nasm.h nasmlib.h output\outform.h output\outlib.h pptok.h preproc.h raa.h &
+ regs.h saa.h
+output\outobj.$(O): output\outobj.c compiler.h directives.h eval.h insnsi.h &
+ nasm.h nasmlib.h output\outform.h output\outlib.h pptok.h preproc.h regs.h &
+ stdscan.h
+output\outrdf.$(O): output\outrdf.c compiler.h directives.h insnsi.h nasm.h &
+ nasmlib.h output\outform.h pptok.h preproc.h regs.h
+output\outrdf2.$(O): output\outrdf2.c compiler.h directives.h insnsi.h &
+ nasm.h nasmlib.h output\outform.h output\outlib.h pptok.h preproc.h &
+ rdoff\rdoff.h regs.h saa.h
+parser.$(O): parser.c compiler.h directives.h float.h insns.h insnsi.h &
+ nasm.h nasmlib.h parser.h pptok.h preproc.h regs.h stdscan.h tables.h &
+ tokens.h
 pptok.$(O): pptok.c compiler.h hashtbl.h nasmlib.h pptok.h preproc.h
-preproc.$(O): preproc.c compiler.h hashtbl.h insnsi.h nasm.h nasmlib.h &
- pptok.h preproc.h quote.h regs.h stdscan.h tables.h tokens.h
+preproc.$(O): preproc.c compiler.h directives.h hashtbl.h insnsi.h nasm.h &
nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tables.h tokens.h
 quote.$(O): quote.c compiler.h nasmlib.h quote.h
 raa.$(O): raa.c compiler.h nasmlib.h raa.h
 rbtree.$(O): rbtree.c compiler.h rbtree.h
 regdis.$(O): regdis.c regdis.h regs.h
-regflags.$(O): regflags.c compiler.h insnsi.h nasm.h nasmlib.h pptok.h &
- preproc.h regs.h tables.h
+regflags.$(O): regflags.c compiler.h directives.h insnsi.h nasm.h nasmlib.h &
+ pptok.h preproc.h regs.h tables.h
 regs.$(O): regs.c compiler.h insnsi.h tables.h
 regvals.$(O): regvals.c compiler.h insnsi.h tables.h
 saa.$(O): saa.c compiler.h nasmlib.h saa.h
-stdscan.$(O): stdscan.c compiler.h insns.h insnsi.h nasm.h nasmlib.h pptok.h &
- preproc.h quote.h regs.h stdscan.h tokens.h
-strfunc.$(O): strfunc.c compiler.h insnsi.h nasm.h nasmlib.h pptok.h &
- preproc.h regs.h
+stdscan.$(O): stdscan.c compiler.h directives.h insns.h insnsi.h nasm.h &
nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tokens.h
+strfunc.$(O): strfunc.c compiler.h directives.h insnsi.h nasm.h nasmlib.h &
+ pptok.h preproc.h regs.h
 sync.$(O): sync.c compiler.h nasmlib.h sync.h
-tokhash.$(O): tokhash.c compiler.h hashtbl.h insns.h insnsi.h nasm.h &
- nasmlib.h pptok.h preproc.h regs.h tokens.h
-ver.$(O): ver.c compiler.h insnsi.h nasm.h nasmlib.h pptok.h preproc.h &
- regs.h version.h
+tokhash.$(O): tokhash.c compiler.h directives.h hashtbl.h insns.h insnsi.h &
+ nasm.h nasmlib.h pptok.h preproc.h regs.h tokens.h
+ver.$(O): ver.c compiler.h directives.h insnsi.h nasm.h nasmlib.h pptok.h &
preproc.h regs.h version.h
index 7299892..0c6f96f 100644 (file)
@@ -60,15 +60,17 @@ X               = .exe
 NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \
        raa.$(O) saa.$(O) rbtree.$(O) \
        float.$(O) insnsa.$(O) insnsb.$(O) \
+       directives.$(O) \
        assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \
        output/outform.$(O) output/outlib.$(O) output/nulldbg.$(O) \
+       output/nullout.$(O) \
        output/outbin.$(O) output/outaout.$(O) output/outcoff.$(O) \
        output/outelf.$(O) output/outelf32.$(O) output/outelf64.$(O) \
        output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \
-       output/outdbg.$(O) output/outieee.$(O) output/outmacho.$(O) \
-       preproc.$(O) quote.$(O) pptok.$(O) macros.$(O) \
-       listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) strfunc.$(O) \
-       tokhash.$(O) regvals.$(O) regflags.$(O)
+       output/outdbg.$(O) output/outieee.$(O) output/outmacho32.$(O) \
+       output/outmacho64.$(O) preproc.$(O) quote.$(O) pptok.$(O) \
+       macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \
+       strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O)
 
 NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \
        insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O)
@@ -221,102 +223,115 @@ everything: all doc rdf
 # @exclude: "config.h"
 # @continuation: "\"
 #-- Everything below is generated by mkdep.pl - do not edit --#
-assemble.$(O): assemble.c assemble.h compiler.h insns.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h regs.h tables.h tokens.h
+assemble.$(O): assemble.c assemble.h compiler.h directives.h insns.h \
insnsi.h nasm.h nasmlib.h pptok.h preproc.h regs.h tables.h tokens.h
 crc64.$(O): crc64.c compiler.h nasmlib.h
-disasm.$(O): disasm.c compiler.h disasm.h insns.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regdis.h regs.h sync.h tables.h tokens.h
-eval.$(O): eval.c compiler.h eval.h float.h insnsi.h labels.h nasm.h \
- nasmlib.h pptok.h preproc.h regs.h
-exprlib.$(O): exprlib.c compiler.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h
-float.$(O): float.c compiler.h float.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h
-hashtbl.$(O): hashtbl.c compiler.h hashtbl.h insnsi.h nasm.h nasmlib.h \
+directives.$(O): directives.c compiler.h directives.h hashtbl.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h
+disasm.$(O): disasm.c compiler.h directives.h disasm.h insns.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regdis.h regs.h sync.h tables.h tokens.h
+eval.$(O): eval.c compiler.h directives.h eval.h float.h insnsi.h labels.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h
+exprlib.$(O): exprlib.c compiler.h directives.h insnsi.h nasm.h nasmlib.h \
  pptok.h preproc.h regs.h
-insnsa.$(O): insnsa.c compiler.h insns.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h tokens.h
-insnsb.$(O): insnsb.c compiler.h insns.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h tokens.h
-insnsd.$(O): insnsd.c compiler.h insns.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h tokens.h
+float.$(O): float.c compiler.h directives.h float.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h
+hashtbl.$(O): hashtbl.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h
+insnsa.$(O): insnsa.c compiler.h directives.h insns.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h tokens.h
+insnsb.$(O): insnsb.c compiler.h directives.h insns.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h tokens.h
+insnsd.$(O): insnsd.c compiler.h directives.h insns.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h tokens.h
 insnsn.$(O): insnsn.c compiler.h insnsi.h tables.h
-labels.$(O): labels.c compiler.h hashtbl.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h
+labels.$(O): labels.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
nasmlib.h pptok.h preproc.h regs.h
 lib/snprintf.$(O): lib/snprintf.c compiler.h nasmlib.h
 lib/vsnprintf.$(O): lib/vsnprintf.c compiler.h nasmlib.h
-listing.$(O): listing.c compiler.h insnsi.h listing.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h
-macros.$(O): macros.c compiler.h hashtbl.h insnsi.h nasm.h nasmlib.h \
- output/outform.h pptok.h preproc.h regs.h tables.h
-nasm.$(O): nasm.c assemble.h compiler.h eval.h float.h insns.h insnsi.h \
- labels.h listing.h nasm.h nasmlib.h output/outform.h parser.h pptok.h \
- preproc.h raa.h regs.h saa.h stdscan.h tokens.h
-nasmlib.$(O): nasmlib.c compiler.h insns.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h tokens.h
-ndisasm.$(O): ndisasm.c compiler.h disasm.h insns.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h regs.h sync.h tokens.h
-output/nulldbg.$(O): output/nulldbg.c compiler.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h regs.h
-output/outaout.$(O): output/outaout.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h output/outlib.h pptok.h preproc.h raa.h regs.h saa.h \
- stdscan.h
-output/outas86.$(O): output/outas86.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h output/outlib.h pptok.h preproc.h raa.h regs.h saa.h
-output/outbin.$(O): output/outbin.c compiler.h eval.h insnsi.h labels.h \
- nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h regs.h \
- saa.h stdscan.h
-output/outcoff.$(O): output/outcoff.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h output/outlib.h pptok.h preproc.h raa.h regs.h saa.h
-output/outdbg.$(O): output/outdbg.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h pptok.h preproc.h regs.h
-output/outelf.$(O): output/outelf.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/dwarf.h output/elfcommon.h output/outelf.h output/outform.h pptok.h \
- preproc.h regs.h
-output/outelf32.$(O): output/outelf32.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/dwarf.h output/elf32.h output/elfcommon.h output/outelf.h \
- output/outform.h output/outlib.h pptok.h preproc.h raa.h rbtree.h regs.h \
- saa.h stdscan.h
-output/outelf64.$(O): output/outelf64.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/dwarf.h output/elf64.h output/elfcommon.h output/outelf.h \
- output/outform.h output/outlib.h pptok.h preproc.h raa.h rbtree.h regs.h \
- saa.h stdscan.h
-output/outform.$(O): output/outform.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h pptok.h preproc.h regs.h
-output/outieee.$(O): output/outieee.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h output/outlib.h pptok.h preproc.h regs.h
-output/outlib.$(O): output/outlib.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outlib.h pptok.h preproc.h regs.h
-output/outmacho.$(O): output/outmacho.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h output/outlib.h pptok.h preproc.h raa.h regs.h saa.h
-output/outobj.$(O): output/outobj.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h output/outlib.h pptok.h preproc.h regs.h stdscan.h
-output/outrdf.$(O): output/outrdf.c compiler.h insnsi.h nasm.h nasmlib.h \
+listing.$(O): listing.c compiler.h directives.h insnsi.h listing.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h
+macros.$(O): macros.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
+ nasmlib.h output/outform.h pptok.h preproc.h regs.h tables.h
+nasm.$(O): nasm.c assemble.h compiler.h directives.h eval.h float.h insns.h \
+ insnsi.h labels.h listing.h nasm.h nasmlib.h output/outform.h parser.h \
+ pptok.h preproc.h raa.h regs.h saa.h stdscan.h tokens.h
+nasmlib.$(O): nasmlib.c compiler.h directives.h insns.h insnsi.h nasm.h \
+ nasmlib.h pptok.h preproc.h regs.h tokens.h
+ndisasm.$(O): ndisasm.c compiler.h directives.h disasm.h insns.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h sync.h tokens.h
+output/nulldbg.$(O): output/nulldbg.c compiler.h directives.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h
+output/nullout.$(O): output/nullout.c compiler.h directives.h insnsi.h \
+ nasm.h nasmlib.h output/outlib.h pptok.h preproc.h regs.h
+output/outaout.$(O): output/outaout.c compiler.h directives.h eval.h \
+ insnsi.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
+ preproc.h raa.h regs.h saa.h stdscan.h
+output/outas86.$(O): output/outas86.c compiler.h directives.h insnsi.h \
+ nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h raa.h \
+ regs.h saa.h
+output/outbin.$(O): output/outbin.c compiler.h directives.h eval.h insnsi.h \
+ labels.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
+ preproc.h regs.h saa.h stdscan.h
+output/outcoff.$(O): output/outcoff.c compiler.h directives.h eval.h \
+ insnsi.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
+ preproc.h raa.h regs.h saa.h
+output/outdbg.$(O): output/outdbg.c compiler.h directives.h insnsi.h nasm.h \
+ nasmlib.h output/outform.h pptok.h preproc.h regs.h
+output/outelf.$(O): output/outelf.c compiler.h directives.h insnsi.h nasm.h \
+ nasmlib.h output/dwarf.h output/elfcommon.h output/outelf.h \
  output/outform.h pptok.h preproc.h regs.h
-output/outrdf2.$(O): output/outrdf2.c compiler.h insnsi.h nasm.h nasmlib.h \
- output/outform.h output/outlib.h pptok.h preproc.h rdoff/rdoff.h regs.h \
- saa.h
-owtest.$(O): owtest.c
-parser.$(O): parser.c compiler.h float.h insns.h insnsi.h nasm.h nasmlib.h \
- parser.h pptok.h preproc.h regs.h stdscan.h tables.h tokens.h
+output/outelf32.$(O): output/outelf32.c compiler.h directives.h eval.h \
+ insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf32.h output/elfcommon.h \
+ output/outelf.h output/outform.h output/outlib.h pptok.h preproc.h raa.h \
+ rbtree.h regs.h saa.h stdscan.h
+output/outelf64.$(O): output/outelf64.c compiler.h directives.h eval.h \
+ insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf64.h output/elfcommon.h \
+ output/outelf.h output/outform.h output/outlib.h pptok.h preproc.h raa.h \
+ rbtree.h regs.h saa.h stdscan.h
+output/outexe.$(O): output/outexe.c compiler.h directives.h insnsi.h nasm.h \
+ nasmlib.h output/outform.h pptok.h preproc.h regs.h
+output/outform.$(O): output/outform.c compiler.h directives.h insnsi.h \
+ nasm.h nasmlib.h output/outform.h pptok.h preproc.h regs.h
+output/outieee.$(O): output/outieee.c compiler.h directives.h insnsi.h \
+ nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h regs.h
+output/outlib.$(O): output/outlib.c compiler.h directives.h insnsi.h nasm.h \
+ nasmlib.h output/outlib.h pptok.h preproc.h regs.h
+output/outmacho32.$(O): output/outmacho32.c compiler.h directives.h eval.h \
+ insnsi.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
+ preproc.h raa.h regs.h saa.h
+output/outmacho64.$(O): output/outmacho64.c compiler.h directives.h insnsi.h \
+ nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h raa.h \
+ regs.h saa.h
+output/outobj.$(O): output/outobj.c compiler.h directives.h eval.h insnsi.h \
+ nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h regs.h \
+ stdscan.h
+output/outrdf.$(O): output/outrdf.c compiler.h directives.h insnsi.h nasm.h \
+ nasmlib.h output/outform.h pptok.h preproc.h regs.h
+output/outrdf2.$(O): output/outrdf2.c compiler.h directives.h insnsi.h \
+ nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h \
+ rdoff/rdoff.h regs.h saa.h
+parser.$(O): parser.c compiler.h directives.h float.h insns.h insnsi.h \
+ nasm.h nasmlib.h parser.h pptok.h preproc.h regs.h stdscan.h tables.h \
+ tokens.h
 pptok.$(O): pptok.c compiler.h hashtbl.h nasmlib.h pptok.h preproc.h
-preproc.$(O): preproc.c compiler.h hashtbl.h insnsi.h nasm.h nasmlib.h \
- pptok.h preproc.h quote.h regs.h stdscan.h tables.h tokens.h
+preproc.$(O): preproc.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tables.h tokens.h
 quote.$(O): quote.c compiler.h nasmlib.h quote.h
 raa.$(O): raa.c compiler.h nasmlib.h raa.h
 rbtree.$(O): rbtree.c compiler.h rbtree.h
 regdis.$(O): regdis.c regdis.h regs.h
-regflags.$(O): regflags.c compiler.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h tables.h
+regflags.$(O): regflags.c compiler.h directives.h insnsi.h nasm.h nasmlib.h \
+ pptok.h preproc.h regs.h tables.h
 regs.$(O): regs.c compiler.h insnsi.h tables.h
 regvals.$(O): regvals.c compiler.h insnsi.h tables.h
 saa.$(O): saa.c compiler.h nasmlib.h saa.h
-stdscan.$(O): stdscan.c compiler.h insns.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h quote.h regs.h stdscan.h tokens.h
-strfunc.$(O): strfunc.c compiler.h insnsi.h nasm.h nasmlib.h pptok.h \
- preproc.h regs.h
+stdscan.$(O): stdscan.c compiler.h directives.h insns.h insnsi.h nasm.h \
nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tokens.h
+strfunc.$(O): strfunc.c compiler.h directives.h insnsi.h nasm.h nasmlib.h \
+ pptok.h preproc.h regs.h
 sync.$(O): sync.c compiler.h nasmlib.h sync.h
-tokhash.$(O): tokhash.c compiler.h hashtbl.h insns.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h regs.h tokens.h
-ver.$(O): ver.c compiler.h insnsi.h nasm.h nasmlib.h pptok.h preproc.h \
- regs.h version.h
+tokhash.$(O): tokhash.c compiler.h directives.h hashtbl.h insns.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h regs.h tokens.h
+ver.$(O): ver.c compiler.h directives.h insnsi.h nasm.h nasmlib.h pptok.h \
preproc.h regs.h version.h
diff --git a/directives.dat b/directives.dat
new file mode 100644 (file)
index 0000000..b08d387
--- /dev/null
@@ -0,0 +1,62 @@
+;; --------------------------------------------------------------------------
+;;
+;;   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+;;   See the file AUTHORS included with the NASM distribution for
+;;   the specific copyright holders.
+;;
+;;   Redistribution and use in source and binary forms, with or without
+;;   modification, are permitted provided that the following
+;;   conditions are met:
+;;
+;;   * Redistributions of source code must retain the above copyright
+;;     notice, this list of conditions and the following disclaimer.
+;;   * Redistributions in binary form must reproduce the above
+;;     copyright notice, this list of conditions and the following
+;;     disclaimer in the documentation and/or other materials provided
+;;     with the distribution.
+;;
+;;     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+;;     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+;;     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+;;     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+;;     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+;;     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;;     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+;;     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+;;     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+;;     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+;;     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+;;     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+;;     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+;;
+;; --------------------------------------------------------------------------
+;;
+;; List of global NASM directives (including backend-specific ones)
+;;
+
+; --- Global directives
+absolute
+bits
+common
+cpu
+debug
+default
+extern
+float
+global
+list
+section
+segment
+warning
+
+; --- Format-specific directives
+export                         ; outcoff, outobj
+group                          ; outobj
+import                         ; outobj
+library                                ; outrdf2
+map                            ; outbin
+module                         ; outrdf2
+org                            ; outbin
+osabi                          ; outelf
+safeseh                                ; outcoff
+uppercase                      ; outieee, outobj
diff --git a/directives.pl b/directives.pl
new file mode 100755 (executable)
index 0000000..d8bc6e8
--- /dev/null
@@ -0,0 +1,171 @@
+#!/usr/bin/perl
+## --------------------------------------------------------------------------
+##
+##   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+##   See the file AUTHORS included with the NASM distribution for
+##   the specific copyright holders.
+##
+##   Redistribution and use in source and binary forms, with or without
+##   modification, are permitted provided that the following
+##   conditions are met:
+##
+##   * Redistributions of source code must retain the above copyright
+##     notice, this list of conditions and the following disclaimer.
+##   * Redistributions in binary form must reproduce the above
+##     copyright notice, this list of conditions and the following
+##     disclaimer in the documentation and/or other materials provided
+##     with the distribution.
+##
+##     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+##     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+##     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+##     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+##     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+##     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+##     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+##     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+##     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+##     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+##     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+##     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+##     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+##
+## --------------------------------------------------------------------------
+
+#
+# Generate a perfect hash for directive parsing
+#
+# Usage: directives.pl directives.dat directives.c directives.h
+#
+
+require 'phash.ph';
+
+my($output, $directives_dat, $outfile) = @ARGV;
+
+@directives = ();
+
+open(DD, "< ${directives_dat}\0")
+    or die "$0: cannot open: ${directives_dat}: $!\n";
+while (defined($line = <DD>)) {
+    chomp $line;
+    if ($line =~ /^\s*([[:alnum:]]+)\s*(|[\;\#].*)$/) {
+       push(@directives, $1);
+    }
+}
+close(DD);
+
+if ($output eq 'h') {
+    open(H, "> ${outfile}\0")
+       or die "$0: cannot create: ${outfile}: $!\n";
+
+    print H "/*\n";
+    print H " * This    file is generated from directives.dat\n";
+    print H " * by directives.pl; do not edit.\n";
+    print H " */\n";
+    print H "\n";
+
+    print H "#ifndef NASM_DIRECTIVES_H\n";
+    print H "#define NASM_DIRECTIVES_H\n";
+    print H "\n";
+
+    print H "enum directives {\n";
+    print H "    D_NONE";
+    foreach $d (@directives) {
+       print H ",\n    D_\U$d";
+    }
+    print H "\n};\n\n";
+    printf H "extern const char * const directives[%d];\n",
+        scalar(@directives)+1;
+    print H "enum directives find_directive(const char *token);\n\n";
+    print H "#endif /* NASM_DIRECTIVES_H */\n";
+} elsif ($output eq 'c') {
+    %directive = ();
+    $n = 0;
+    foreach $d (@directives) {
+       if (exists($directive{$d})) {
+           die "$0: $directives_dat: duplicate directive: $d\n";
+       }
+       $directive{$d} = $n++;  # This is zero-based, unlike the enum!
+    }
+
+    @hashinfo = gen_perfect_hash(\%directive);
+    if (!defined(@hashinfo)) {
+       die "$0: no hash found\n";
+    }
+
+    # Paranoia...
+    verify_hash_table(\%directive, \@hashinfo);
+
+    ($n, $sv, $g) = @hashinfo;
+    $sv2 = $sv+2;
+
+    die if ($n & ($n-1));
+
+    open(C, "> ${outfile}\0")
+       or die "$0: cannot create: ${directives_c}: $!\n";
+
+    print C "/*\n";
+    print C " * This file is generated from directives.dat\n";
+    print C " * by directives.pl; do not edit.\n";
+    print C " */\n";
+    print C "\n";
+
+    print C "#include \"compiler.h\"\n";
+    print C "#include <string.h>\n";
+    print C "#include \"nasm.h\"\n";
+    print C "#include \"hashtbl.h\"\n";
+    print C "#include \"directives.h\"\n";
+    print C "\n";
+
+    printf C "const char * const directives[%d] = {\n",
+        scalar(@directives)+1;
+    print C "    NULL";
+    foreach $d (@directives) {
+       print C ",\n    \"$d\"";
+    }
+    print C "\n};\n\n";
+
+    print C "enum directives find_directive(const char *token)\n";
+    print C "{\n";
+
+    # Put a large value in unused slots.  This makes it extremely unlikely
+    # that any combination that involves unused slot will pass the range test.
+    # This speeds up rejection of unrecognized tokens, i.e. identifiers.
+    print C "#define UNUSED 16383\n";
+
+    print C "    static const int16_t hash1[$n] = {\n";
+    for ($i = 0; $i < $n; $i++) {
+       my $h = ${$g}[$i*2+0];
+       print C "        ", defined($h) ? $h : 'UNUSED', ",\n";
+    }
+    print C "    };\n";
+
+    print C "    static const int16_t hash2[$n] = {\n";
+    for ($i = 0; $i < $n; $i++) {
+       my $h = ${$g}[$i*2+1];
+       print C "        ", defined($h) ? $h : 'UNUSED', ",\n";
+    }
+    print C "    };\n";
+
+    print C  "    uint32_t k1, k2;\n";
+    print C  "    uint64_t crc;\n";
+    # For correct overflow behavior, "ix" should be unsigned of the same
+    # width as the hash arrays.
+    print C  "    uint16_t ix;\n";
+    print C  "\n";
+    printf C "    crc = crc64i(UINT64_C(0x%08x%08x), token);\n",
+       $$sv[0], $$sv[1];
+    print C  "    k1 = (uint32_t)crc;\n";
+    print C  "    k2 = (uint32_t)(crc >> 32);\n";
+    print C  "\n";
+    printf C "    ix = hash1[k1 & 0x%x] + hash2[k2 & 0x%x];\n", $n-1, $n-1;
+    printf C "    if (ix >= %d)\n", scalar(@directives);
+    print C  "        return D_NONE;\n";
+    print C  "\n";
+    print C  "    ix++;\n";    # Account for D_NONE
+    print C  "    if (nasm_stricmp(token, directives[ix]))\n";
+    print C  "        return D_NONE;\n";
+    print C  "\n";
+    print C  "    return ix;\n";
+    print C  "}\n";
+}
index 6fb60d8..ac49561 100644 (file)
@@ -2262,6 +2262,21 @@ This can be used, for example, with the \c{%!} construct (see
 \c %defstr PATH %!PATH          ; The operating system PATH variable
 
 
+\S{deftok} Defining Tokens: \I\c{%ideftok}\i\c{%deftok}
+
+\c{%deftok}, and its case-insensitive counterpart \c{%ideftok}, define
+or redefine a single-line macro without parameters but converts the
+second parameter, after string conversion, to a sequence of tokens.
+
+For example:
+
+\c %deftok test 'TEST'
+
+is equivalent to
+
+\c %define test TEST
+
+
 \H{strlen} \i{String Manipulation in Macros}
 
 It's often useful to be able to handle strings in macros. NASM
@@ -2386,6 +2401,22 @@ things like
 \c         silly {13,10}, crlf             ; crlf:      db 13,10
 
 
+\S{mlrmacro} \i{Recursive Multi-Line Macros}: \I\c{%irmacro}\i\c{%rmacro}
+
+A multi-line macro cannot be referenced within itself, in order to
+prevent accidental infinite recursion.
+
+Recursive multi-line macros allow for self-referencing, with the
+caveat that the user is aware of the existence, use and purpose of
+recursive multi-line macros. There is also a generous, but sane, upper
+limit to the number of recursions, in order to prevent run-away memory
+consumption in case of accidental infinite recursion.
+
+As with non-recursive multi-line macros, recursive multi-line macros are
+\i{case-sensitive}, unless you define them using the alternative
+directive \c{%irmacro}.
+
+
 \S{mlmacover} Overloading Multi-Line Macros\I{overloading, multi-line macros}
 
 As with single-line macros, multi-line macros can be overloaded by
index 7e7b7f3..8c850c3 100644 (file)
--- a/labels.c
+++ b/labels.c
@@ -206,8 +206,7 @@ bool is_extern(char *label)
 }
 
 void redefine_label(char *label, int32_t segment, int64_t offset, char *special,
-                    bool is_norm, bool isextrn, struct ofmt *ofmt,
-                    efunc error)
+                    bool is_norm, bool isextrn)
 {
     union label *lptr;
     int exi;
@@ -220,19 +219,18 @@ void redefine_label(char *label, int32_t segment, int64_t offset, char *special,
     (void)special;              /* Don't warn that this parameter is unused */
     (void)is_norm;              /* Don't warn that this parameter is unused */
     (void)isextrn;              /* Don't warn that this parameter is unused */
-    (void)ofmt;                 /* Don't warn that this parameter is unused */
 
 #ifdef DEBUG
 #if DEBUG<3
     if (!strncmp(label, "debugdump", 9))
 #endif
-        error(ERR_DEBUG, "redefine_label (%s, %ld, %08lx, %s, %d, %d)",
+        nasm_error(ERR_DEBUG, "redefine_label (%s, %ld, %08lx, %s, %d, %d)",
               label, segment, offset, special, is_norm, isextrn);
 #endif
 
     lptr = find_label(label, 1);
     if (!lptr)
-        error(ERR_PANIC, "can't find label `%s' on pass two", label);
+        nasm_error(ERR_PANIC, "can't find label `%s' on pass two", label);
 
     if (!islocal(label)) {
         if (!islocalchar(*label) && lptr->defn.is_norm)
@@ -281,7 +279,7 @@ void redefine_label(char *label, int32_t segment, int64_t offset, char *special,
 }
 
 void define_label(char *label, int32_t segment, int64_t offset, char *special,
-                  bool is_norm, bool isextrn, struct ofmt *ofmt, efunc error)
+                  bool is_norm, bool isextrn)
 {
     union label *lptr;
     int exi;
@@ -290,12 +288,12 @@ void define_label(char *label, int32_t segment, int64_t offset, char *special,
 #if DEBUG<3
     if (!strncmp(label, "debugdump", 9))
 #endif
-        error(ERR_DEBUG, "define_label (%s, %ld, %08lx, %s, %d, %d)",
+        nasm_error(ERR_DEBUG, "define_label (%s, %ld, %08lx, %s, %d, %d)",
               label, segment, offset, special, is_norm, isextrn);
 #endif
     lptr = find_label(label, 1);
     if (lptr->defn.is_global & DEFINED_BIT) {
-        error(ERR_NONFATAL, "symbol `%s' redefined", label);
+        nasm_error(ERR_NONFATAL, "symbol `%s' redefined", label);
         return;
     }
     lptr->defn.is_global |= DEFINED_BIT;
@@ -306,7 +304,7 @@ void define_label(char *label, int32_t segment, int64_t offset, char *special,
        /* not local, but not special either */
         prevlabel = lptr->defn.label;
     } else if (islocal(label) && !*prevlabel) {
-        error(ERR_NONFATAL, "attempt to define a local label before any"
+        nasm_error(ERR_NONFATAL, "attempt to define a local label before any"
               " non-local labels");
     }
 
@@ -348,15 +346,14 @@ void define_label(char *label, int32_t segment, int64_t offset, char *special,
     }                           /* if (pass0 == 1) */
 }
 
-void define_common(char *label, int32_t segment, int32_t size, char *special,
-                   struct ofmt *ofmt, efunc error)
+void define_common(char *label, int32_t segment, int32_t size, char *special)
 {
     union label *lptr;
 
     lptr = find_label(label, 1);
     if ((lptr->defn.is_global & DEFINED_BIT) &&
        (passn == 1 || !(lptr->defn.is_global & COMMON_BIT))) {
-           error(ERR_NONFATAL, "symbol `%s' redefined", label);
+           nasm_error(ERR_NONFATAL, "symbol `%s' redefined", label);
            return;
     }
     lptr->defn.is_global |= DEFINED_BIT|COMMON_BIT;
@@ -364,7 +361,7 @@ void define_common(char *label, int32_t segment, int32_t size, char *special,
     if (!islocalchar(label[0])) {
         prevlabel = lptr->defn.label;
     } else {
-        error(ERR_NONFATAL, "attempt to define a local label as a "
+        nasm_error(ERR_NONFATAL, "attempt to define a local label as a "
               "common variable");
        return;
     }
@@ -382,12 +379,12 @@ void define_common(char *label, int32_t segment, int32_t size, char *special,
                                       special);
 }
 
-void declare_as_global(char *label, char *special, efunc error)
+void declare_as_global(char *label, char *special)
 {
     union label *lptr;
 
     if (islocal(label)) {
-        error(ERR_NONFATAL, "attempt to declare local symbol `%s' as"
+        nasm_error(ERR_NONFATAL, "attempt to declare local symbol `%s' as"
               " global", label);
         return;
     }
@@ -402,7 +399,7 @@ void declare_as_global(char *label, char *special, efunc error)
         break;
     case LOCAL_SYMBOL:
         if (!(lptr->defn.is_global & EXTERN_BIT)) {
-            error(ERR_WARNING, "symbol `%s': GLOBAL directive "
+            nasm_error(ERR_WARNING, "symbol `%s': GLOBAL directive "
                   "after symbol definition is an experimental feature", label);
             lptr->defn.is_global = GLOBAL_SYMBOL;
         }
index 59e83ba..865a557 100644 (file)
--- a/labels.h
+++ b/labels.h
@@ -44,14 +44,11 @@ extern char lpostfix[PREFIX_MAX];
 bool lookup_label(char *label, int32_t *segment, int64_t *offset);
 bool is_extern(char *label);
 void define_label(char *label, int32_t segment, int64_t offset, char *special,
-                 bool is_norm, bool isextrn, struct ofmt *ofmt,
-                  efunc error);
+                 bool is_norm, bool isextrn);
 void redefine_label(char *label, int32_t segment, int64_t offset, char *special,
-                    bool is_norm, bool isextrn, struct ofmt *ofmt,
-                    efunc error);
-void define_common(char *label, int32_t segment, int32_t size, char *special,
-                   struct ofmt *ofmt, efunc error);
-void declare_as_global(char *label, char *special, efunc error);
+                    bool is_norm, bool isextrn);
+void define_common(char *label, int32_t segment, int32_t size, char *special);
+void declare_as_global(char *label, char *special);
 int init_labels(void);
 void cleanup_labels(void);
 char *local_scope(char *label);
diff --git a/misc/crcgen.c b/misc/crcgen.c
new file mode 100644 (file)
index 0000000..f11e252
--- /dev/null
@@ -0,0 +1,44 @@
+#include <inttypes.h>
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+    /* Polynomial in bit-reversed notation */
+    uint64_t poly;
+    uint64_t crctab[256], v;
+    int i, j;
+
+    poly = strtoumax(argv[1], NULL, 0);
+
+    printf("/* C */\n");
+    printf("static const uint64_t crc64_tab[256] = {\n");
+    for (i = 0; i < 256; i++) {
+       v = i;
+       for (j = 0; j < 8; j++)
+           v = (v >> 1) ^ ((v & 1) ? poly : 0);
+       crctab[i] = v;
+    }
+
+    for (i = 0; i < 256; i += 2) {
+       printf("    /* %02x */ UINT64_C(0x%016"PRIx64"), "
+              "UINT64_C(0x%016"PRIx64")%s\n",
+              i, crctab[i], crctab[i+1], (i == 254) ? "" : ",");
+    }
+    printf("};\n\n");
+
+    printf("# perl\n");
+    printf("@crc64_tab = (\n");
+    for (i = 0; i < 256; i += 2) {
+       printf("    [0x%08"PRIx32", 0x%08"PRIx32"], "
+              "[0x%08"PRIx32", 0x%08"PRIx32"]%-1s    # %02x\n",
+              (uint32_t)(crctab[i] >> 32),
+              (uint32_t)(crctab[i]),
+              (uint32_t)(crctab[i+1] >> 32),
+              (uint32_t)(crctab[i+1]),
+              (i == 254) ? "" : ",",
+              i);
+    }
+    printf(");\n");
+
+    return 0;
+}
diff --git a/misc/xcrcgen.c b/misc/xcrcgen.c
new file mode 100644 (file)
index 0000000..acfd48e
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Produce a "generalized CRC" table.  Assumes a platform with
+ * /dev/urandom -- otherwise reimplement get_random_byte().
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static uint8_t get_random_byte(void)
+{
+    static int fd = -1;
+    uint8_t buf;
+    int rv;
+
+    if (fd < 0)
+       fd = open("/dev/urandom", O_RDONLY);
+
+    do {
+       errno = 0;
+       rv = read(fd, &buf, 1);
+       if (rv < 1 && errno != EAGAIN)
+           abort();
+    } while (rv < 1);
+
+    return buf;
+}
+
+static void random_permute(uint8_t *buf)
+{
+    int i, j, k;
+    int m;
+
+    for (i = 0; i < 256; i++)
+       buf[i] = i;
+
+    m = 255;
+    for (i = 255; i > 0; i--) {
+       if (i <= (m >> 1))
+           m >>= 1;
+       do {
+           j = get_random_byte() & m;
+       } while (j > i);
+       k = buf[i];
+       buf[i] = buf[j];
+       buf[j] = k;
+    }
+}
+
+static void xcrc_table(uint64_t *buf)
+{
+    uint8_t perm[256];
+    int i, j;
+
+    memset(buf, 0, 8*256);     /* Make static checkers happy */
+
+    for (i = 0; i < 8; i++) {
+       random_permute(perm);
+       for (j = 0; j < 256; j++)
+           buf[j] = (buf[j] << 8) | perm[j];
+    }
+}
+
+int main(void)
+{
+    int i;
+    uint64_t buf[256];
+
+    xcrc_table(buf);
+
+    for (i = 0; i < 256; i++) {
+       printf("%016"PRIx64"\n", buf[i]);
+    }
+
+    return 0;
+}
diff --git a/nasm.c b/nasm.c
index 8c7e271..b2ceacc 100644 (file)
--- a/nasm.c
+++ b/nasm.c
@@ -1,5 +1,5 @@
 /* ----------------------------------------------------------------------- *
- *   
+ *
  *   Copyright 1996-2009 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
@@ -14,7 +14,7 @@
  *     copyright notice, this list of conditions and the following
  *     disclaimer in the documentation and/or other materials provided
  *     with the distribution.
- *     
+ *
  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -31,7 +31,7 @@
  *
  * ----------------------------------------------------------------------- */
 
-/* 
+/*
  * The Netwide Assembler main program module
  */
 
@@ -70,14 +70,11 @@ static int get_bits(char *value);
 static uint32_t get_cpu(char *cpu_str);
 static void parse_cmdline(int, char **);
 static void assemble_file(char *, StrList **);
-static void register_output_formats(void);
-static void report_error_gnu(int severity, const char *fmt, ...);
-static void report_error_vc(int severity, const char *fmt, ...);
-static void report_error_common(int severity, const char *fmt,
-                                va_list args);
+static void nasm_verror_gnu(int severity, const char *fmt, va_list args);
+static void nasm_verror_vc(int severity, const char *fmt, va_list args);
+static void nasm_verror_common(int severity, const char *fmt, va_list args);
 static bool is_suppressed_warning(int severity);
 static void usage(void);
-static efunc report_error;
 
 static int using_debug_info, opt_verbose_info;
 bool tasm_compatible_mode = false;
@@ -85,7 +82,7 @@ int pass0, passn;
 int maxbits = 0;
 int globalrel = 0;
 
-time_t official_compile_time;
+static time_t official_compile_time;
 
 static char inname[FILENAME_MAX];
 static char outname[FILENAME_MAX];
@@ -93,11 +90,12 @@ static char listname[FILENAME_MAX];
 static char errname[FILENAME_MAX];
 static int globallineno;        /* for forward-reference tracking */
 /* static int pass = 0; */
-static struct ofmt *ofmt = NULL;
+struct ofmt *ofmt = &OF_DEFAULT;
+const struct dfmt *dfmt;
 
 static FILE *error_file;        /* Where to write error messages */
 
-static FILE *ofile = NULL;
+FILE *ofile = NULL;
 int optimizing = -1;            /* number of optimization passes to take */
 static int sb, cmd_sb = 16;     /* by default */
 static uint32_t cmd_cpu = IF_PLEVEL;       /* highest level by default */
@@ -162,7 +160,7 @@ static const struct warning {
  * not preprocess their source file.
  */
 
-static void no_pp_reset(char *, int, efunc, evalfunc, ListGen *, StrList **);
+static void no_pp_reset(char *, int, ListGen *, StrList **);
 static char *no_pp_getline(void);
 static void no_pp_cleanup(int);
 static Preproc no_pp = {
@@ -277,14 +275,14 @@ static void emit_dependencies(StrList *list)
     if (depend_file && strcmp(depend_file, "-")) {
        deps = fopen(depend_file, "w");
        if (!deps) {
-           report_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE,
+           nasm_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE,
                         "unable to write dependency file `%s'", depend_file);
            return;
        }
     } else {
        deps = stdout;
     }
-    
+
     linepos = fprintf(deps, "%s:", depend_target);
     for (l = list; l; l = l->next) {
        len = strlen(l->str);
@@ -296,11 +294,11 @@ static void emit_dependencies(StrList *list)
        linepos += len+1;
     }
     fprintf(deps, "\n\n");
-    
+
     for (l = list; l; l = nl) {
        if (depend_emit_phony)
            fprintf(deps, "%s:\n\n", l->str);
-           
+
        nl = l->next;
        nasm_free(l);
     }
@@ -317,13 +315,13 @@ int main(int argc, char **argv)
 
     pass0 = 0;
     want_usage = terminate_after_phase = false;
-    report_error = report_error_gnu;
+    nasm_set_verror(nasm_verror_gnu);
 
     error_file = stderr;
 
     tolower_init();
 
-    nasm_set_malloc_error(report_error);
+    nasm_init_malloc_error();
     offsets = raa_init();
     forwrefs = saa_init((int32_t)sizeof(struct forwrefinfo));
 
@@ -332,8 +330,6 @@ int main(int argc, char **argv)
 
     seg_init();
 
-    register_output_formats();
-
     /* Define some macros dependent on the runtime, but not
        on the command line. */
     define_macros_early();
@@ -352,7 +348,7 @@ int main(int argc, char **argv)
 
     if (ofmt->stdmac)
         pp_extra_stdmac(ofmt->stdmac);
-    parser_global_info(ofmt, &location);
+    parser_global_info(&location);
     eval_global_info(ofmt, lookup_label, &location);
 
     /* define some macros dependent of command-line */
@@ -371,10 +367,9 @@ int main(int argc, char **argv)
            if (depend_missing_ok)
                pp_include_path(NULL);  /* "assume generated" */
 
-            preproc->reset(inname, 0, report_error, evaluate, &nasmlist,
-                          depend_ptr);
+            preproc->reset(inname, 0, &nasmlist, depend_ptr);
             if (outname[0] == '\0')
-                ofmt->filename(inname, outname, report_error);
+                ofmt->filename(inname, outname);
             ofile = NULL;
             while ((line = preproc->getline()))
                 nasm_free(line);
@@ -392,7 +387,7 @@ int main(int argc, char **argv)
             if (*outname) {
                 ofile = fopen(outname, "w");
                 if (!ofile)
-                    report_error(ERR_FATAL | ERR_NOFILE,
+                    nasm_error(ERR_FATAL | ERR_NOFILE,
                                  "unable to open output file `%s'",
                                  outname);
             } else
@@ -401,8 +396,7 @@ int main(int argc, char **argv)
             location.known = false;
 
            /* pass = 1; */
-            preproc->reset(inname, 3, report_error, evaluate, &nasmlist,
-                          depend_ptr);
+            preproc->reset(inname, 3, &nasmlist, depend_ptr);
 
             while ((line = preproc->getline())) {
                 /*
@@ -430,6 +424,7 @@ int main(int argc, char **argv)
                 fclose(ofile);
             if (ofile && terminate_after_phase)
                 remove(outname);
+           ofile = NULL;
         }
         break;
 
@@ -442,11 +437,11 @@ int main(int argc, char **argv)
              * the name of the input file and then put that inside the
              * file.
              */
-            ofmt->filename(inname, outname, report_error);
+            ofmt->filename(inname, outname);
 
             ofile = fopen(outname, (ofmt->flags & OFMT_TEXT) ? "w" : "wb");
             if (!ofile) {
-                report_error(ERR_FATAL | ERR_NOFILE,
+                nasm_error(ERR_FATAL | ERR_NOFILE,
                              "unable to open output file `%s'", outname);
             }
 
@@ -457,24 +452,28 @@ int main(int argc, char **argv)
              */
             init_labels();
 
-            ofmt->init(ofile, report_error, define_label, evaluate);
-            ofmt->current_dfmt->init(ofmt, NULL, ofile, report_error);
+            ofmt->init();
+           dfmt = ofmt->current_dfmt;
+            dfmt->init();
 
             assemble_file(inname, depend_ptr);
 
             if (!terminate_after_phase) {
                 ofmt->cleanup(using_debug_info);
                 cleanup_labels();
-            } else {
-                /*
-                 * Despite earlier comments, we need this fclose.
-                 * The object output drivers only fclose on cleanup,
-                 * and we just skipped that.
-                 */
-                fclose (ofile);
+               fflush(ofile);
+               if (ferror(ofile)) {
+                   nasm_error(ERR_NONFATAL|ERR_NOFILE,
+                                "write error on output file `%s'", outname);
+               }
+           }
 
-                remove(outname);
-            }
+           if (ofile) {
+               fclose(ofile);
+               if (terminate_after_phase)
+                   remove(outname);
+               ofile = NULL;
+           }
         }
         break;
     }
@@ -510,7 +509,7 @@ static char *get_param(char *p, char *q, bool *advance)
         *advance = true;
         return q;
     }
-    report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
+    nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
                  "option `-%c' requires an argument", p[1]);
     return NULL;
 }
@@ -523,7 +522,7 @@ static void copy_filename(char *dst, const char *src)
     size_t len = strlen(src);
 
     if (len >= (size_t)FILENAME_MAX) {
-       report_error(ERR_FATAL | ERR_NOFILE, "file name too long");
+       nasm_error(ERR_FATAL | ERR_NOFILE, "file name too long");
        return;
     }
     strncpy(dst, src, FILENAME_MAX);
@@ -654,7 +653,7 @@ static bool process_arg(char *p, char *q)
        case 'f':               /* output format */
            ofmt = ofmt_find(param);
            if (!ofmt) {
-               report_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE,
+               nasm_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE,
                             "unrecognised output format `%s' - "
                             "use -hf for a list", param);
            }
@@ -694,7 +693,7 @@ static bool process_arg(char *p, char *q)
                        break;
 
                    default:
-                       report_error(ERR_FATAL,
+                       nasm_error(ERR_FATAL,
                                     "unknown optimization option -O%c\n",
                                     *param);
                        break;
@@ -735,7 +734,7 @@ static bool process_arg(char *p, char *q)
        case 'F':                       /* specify debug format */
            ofmt->current_dfmt = dfmt_find(ofmt, param);
            if (!ofmt->current_dfmt) {
-               report_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE,
+               nasm_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE,
                             "unrecognized debug format `%s' for"
                             " output format `%s'",
                             param, ofmt->shortname);
@@ -745,11 +744,11 @@ static bool process_arg(char *p, char *q)
 
        case 'X':               /* specify error reporting format */
            if (nasm_stricmp("vc", param) == 0)
-               report_error = report_error_vc;
+               nasm_set_verror(nasm_verror_vc);
            else if (nasm_stricmp("gnu", param) == 0)
-               report_error = report_error_gnu;
+               nasm_set_verror(nasm_verror_gnu);
            else
-               report_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE,
+               nasm_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE,
                             "unrecognized error reporting format `%s'",
                             param);
             break;
@@ -839,7 +838,7 @@ static bool process_arg(char *p, char *q)
 
         case 'w':
             if (param[0] != '+' && param[0] != '-') {
-                report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
+                nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
                              "invalid option to `-w'");
                break;
             }
@@ -859,7 +858,7 @@ static bool process_arg(char *p, char *q)
                for (i = 1; i <= ERR_WARN_MAX; i++)
                    warning_on_global[i] = !do_warn;
            else
-               report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
+               nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
                             "invalid warning `%s'", param);
             break;
 
@@ -888,12 +887,12 @@ static bool process_arg(char *p, char *q)
                advance = true;
                break;
            default:
-               report_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE,
+               nasm_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE,
                             "unknown dependency option `-M%c'", p[2]);
                break;
            }
            if (advance && (!q || !q[0])) {
-               report_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE,
+               nasm_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE,
                             "option `-M%c' requires a parameter", p[2]);
                break;
            }
@@ -919,7 +918,7 @@ static bool process_arg(char *p, char *q)
                 case OPT_POSTFIX:
                     {
                         if (!q) {
-                            report_error(ERR_NONFATAL | ERR_NOFILE |
+                            nasm_error(ERR_NONFATAL | ERR_NOFILE |
                                          ERR_USAGE,
                                          "option `--%s' requires an argument",
                                          p + 2);
@@ -942,7 +941,7 @@ static bool process_arg(char *p, char *q)
                     }
                 default:
                     {
-                        report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
+                        nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
                                      "unrecognised option `--%s'", p + 2);
                         break;
                     }
@@ -952,13 +951,13 @@ static bool process_arg(char *p, char *q)
 
         default:
             if (!ofmt->setinfo(GI_SWITCH, &p))
-                report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
+                nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
                              "unrecognised option `-%c'", p[1]);
             break;
         }
     } else {
         if (*inname) {
-            report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
+            nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
                          "more than one input file specified");
         } else {
             copy_filename(inname, p);
@@ -1118,7 +1117,7 @@ static void parse_cmdline(int argc, char **argv)
                     process_respfile(rfile);
                     fclose(rfile);
                 } else
-                    report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
+                    nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
                                  "unable to open response file `%s'", p);
             }
         } else
@@ -1129,13 +1128,13 @@ static void parse_cmdline(int argc, char **argv)
     /* Look for basic command line typos.  This definitely doesn't
        catch all errors, but it might help cases of fumbled fingers. */
     if (!*inname)
-        report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
+        nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
                      "no input file specified");
     else if (!strcmp(inname, errname) ||
             !strcmp(inname, outname) ||
             !strcmp(inname, listname) ||
             (depend_file && !strcmp(inname, depend_file)))
-       report_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE,
+       nasm_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE,
                     "file `%s' is both input and output file",
                     inname);
 
@@ -1143,22 +1142,13 @@ static void parse_cmdline(int argc, char **argv)
        error_file = fopen(errname, "w");
        if (!error_file) {
            error_file = stderr;        /* Revert to default! */
-           report_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE,
+           nasm_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE,
                         "cannot open file `%s' for error messages",
                         errname);
        }
     }
 }
 
-/* List of directives */
-enum directives {
-    D_NONE, D_ABSOLUTE, D_BITS, D_COMMON, D_CPU, D_DEBUG, D_DEFAULT,
-    D_EXTERN, D_FLOAT, D_GLOBAL, D_LIST, D_SECTION, D_SEGMENT, D_WARNING
-};
-static const char *directives[] = {
-    "", "absolute", "bits", "common", "cpu", "debug", "default",
-    "extern", "float", "global", "list", "section", "segment", "warning"
-};
 static enum directives getkw(char **directive, char **value);
 
 static void assemble_file(char *fname, StrList **depend_ptr)
@@ -1174,7 +1164,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
     int pass_max;
 
     if (cmd_sb == 32 && cmd_cpu < IF_386)
-        report_error(ERR_FATAL, "command line: "
+        nasm_error(ERR_FATAL, "command line: "
                      "32-bit segment size requires a higher cpu");
 
     pass_max = prev_offset_changed = (INT_MAX >> 1) + 2; /* Almost unlimited */
@@ -1192,7 +1182,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
         cpu = cmd_cpu;
         if (pass0 == 2) {
             if (*listname)
-                nasmlist.init(listname, report_error);
+                nasmlist.init(listname, nasm_error);
         }
         in_abs_seg = false;
         global_offset_changed = 0;  /* set by redefine_label */
@@ -1204,7 +1194,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
             raa_free(offsets);
             offsets = raa_init();
         }
-        preproc->reset(fname, pass1, report_error, evaluate, &nasmlist,
+        preproc->reset(fname, pass1, &nasmlist,
                       pass1 == 2 ? depend_ptr : NULL);
         memcpy(warning_on, warning_on_global, (ERR_WARN_MAX+1) * sizeof(bool));
 
@@ -1231,7 +1221,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                case D_SECTION:
                     seg = ofmt->section(value, pass2, &sb);
                     if (seg == NO_SEG) {
-                        report_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC,
+                        nasm_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC,
                                      "segment name `%s' not recognized",
                                      value);
                     } else {
@@ -1261,7 +1251,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                             q++;
                         }
                         if (!validid) {
-                            report_error(ERR_NONFATAL,
+                            nasm_error(ERR_NONFATAL,
                                          "identifier expected after EXTERN");
                             break;
                         }
@@ -1273,10 +1263,9 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                         if (!is_extern(value)) {        /* allow re-EXTERN to be ignored */
                             int temp = pass0;
                             pass0 = 1;  /* fake pass 1 in labels.c */
-                            declare_as_global(value, special,
-                                              report_error);
+                            declare_as_global(value, special);
                             define_label(value, seg_alloc(), 0L, NULL,
-                                         false, true, ofmt, report_error);
+                                         false, true);
                             pass0 = temp;
                         }
                     }           /* else  pass0 == 1 */
@@ -1306,7 +1295,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                             q++;
                         }
                         if (!validid) {
-                            report_error(ERR_NONFATAL,
+                            nasm_error(ERR_NONFATAL,
                                          "identifier expected after GLOBAL");
                             break;
                         }
@@ -1315,7 +1304,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                             special = q;
                         } else
                             special = NULL;
-                        declare_as_global(value, special, report_error);
+                        declare_as_global(value, special);
                     }           /* pass == 1 */
                     break;
                 case D_COMMON:         /* [COMMON symbol size:special] */
@@ -1334,7 +1323,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                        p++;
                    }
                    if (!validid) {
-                       report_error(ERR_NONFATAL,
+                       nasm_error(ERR_NONFATAL,
                                     "identifier expected after COMMON");
                        break;
                    }
@@ -1352,21 +1341,20 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                        }
                        size = readnum(p, &rn_error);
                        if (rn_error) {
-                           report_error(ERR_NONFATAL,
+                           nasm_error(ERR_NONFATAL,
                                         "invalid size specified"
                                         " in COMMON declaration");
                            break;
                        }
                    } else {
-                       report_error(ERR_NONFATAL,
+                       nasm_error(ERR_NONFATAL,
                                     "no size specified in"
                                     " COMMON declaration");
                        break;
                    }
 
                     if (pass0 < 2) {
-                       define_common(value, seg_alloc(), size,
-                                     special, ofmt, report_error);
+                       define_common(value, seg_alloc(), size, special);
                     } else if (pass0 == 2) {
                        if (special)
                            ofmt->symdef(value, 0L, 0L, 3, special);
@@ -1378,10 +1366,10 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                     stdscan_bufptr = value;
                     tokval.t_type = TOKEN_INVALID;
                     e = evaluate(stdscan, NULL, &tokval, NULL, pass2,
-                                 report_error, NULL);
+                                 nasm_error, NULL);
                     if (e) {
                         if (!is_reloc(e))
-                            report_error(pass0 ==
+                            nasm_error(pass0 ==
                                          1 ? ERR_NONFATAL : ERR_PANIC,
                                          "cannot use non-relocatable expression as "
                                          "ABSOLUTE address");
@@ -1392,7 +1380,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                     } else if (passn == 1)
                         abs_offset = 0x100;     /* don't go near zero in case of / */
                     else
-                        report_error(ERR_PANIC, "invalid ABSOLUTE address "
+                        nasm_error(ERR_PANIC, "invalid ABSOLUTE address "
                                      "in pass two");
                     in_abs_seg = true;
                     location.segment = NO_SEG;
@@ -1410,14 +1398,14 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                     }
                     *q++ = 0;
                     if (!validid) {
-                        report_error(passn == 1 ? ERR_NONFATAL : ERR_PANIC,
+                        nasm_error(passn == 1 ? ERR_NONFATAL : ERR_PANIC,
                                      "identifier expected after DEBUG");
                         break;
                     }
                     while (*p && nasm_isspace(*p))
                         p++;
                     if (pass0 == 2)
-                        ofmt->current_dfmt->debug_directive(debugid, p);
+                        dfmt->debug_directive(debugid, p);
                     break;
                 case D_WARNING:                /* [WARNING {+|-|*}warn-name] */
                    while (*value && nasm_isspace(*value))
@@ -1447,7 +1435,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                        }
                    }
                    else
-                       report_error(ERR_NONFATAL,
+                       nasm_error(ERR_NONFATAL,
                                     "invalid warning id in WARNING directive");
                     break;
                 case D_CPU:            /* [CPU] */
@@ -1489,26 +1477,25 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                    break;
                case D_FLOAT:
                    if (float_option(value)) {
-                       report_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC,
+                       nasm_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC,
                                     "unknown 'float' directive: %s",
                                     value);
                    }
                    break;
                 default:
-                    if (!ofmt->directive(directive, value, pass2))
-                        report_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC,
+                   if (!d || !ofmt->directive(d, value, pass2))
+                        nasm_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC,
                                      "unrecognised directive [%s]",
                                      directive);
+                   break;
                 }
                if (err) {
-                   report_error(ERR_NONFATAL,
+                   nasm_error(ERR_NONFATAL,
                                 "invalid parameter to [%s] directive",
                                 directive);
                }
             } else {            /* it isn't a directive */
-
-                parse_line(pass1, line, &output_ins,
-                           report_error, evaluate, def_label);
+                parse_line(pass1, line, &output_ins, def_label);
 
                 if (optimizing > 0) {
                     if (forwref != NULL && globallineno == forwref->lineno) {
@@ -1521,7 +1508,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                                  && forwref->lineno == globallineno);
                     } else
                         output_ins.forw_ref = false;
-                   
+
                    if (output_ins.forw_ref) {
                        if (passn == 1) {
                            for (i = 0; i < output_ins.operands; i++) {
@@ -1547,7 +1534,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                          * in the normal place.
                          */
                         if (!output_ins.label)
-                            report_error(ERR_NONFATAL,
+                            nasm_error(ERR_NONFATAL,
                                          "EQU not preceded by label");
 
                         else if (output_ins.label[0] != '.' ||
@@ -1561,8 +1548,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                                 def_label(output_ins.label,
                                           output_ins.oprs[0].segment,
                                           output_ins.oprs[0].offset, NULL,
-                                          false, isext, ofmt,
-                                          report_error);
+                                          false, isext);
                             } else if (output_ins.operands == 2
                                        && (output_ins.oprs[0].type & IMMEDIATE)
                                        && (output_ins.oprs[0].type & COLON)
@@ -1574,10 +1560,9 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                                 def_label(output_ins.label,
                                           output_ins.oprs[0].offset | SEG_ABS,
                                           output_ins.oprs[1].offset,
-                                         NULL, false, false, ofmt,
-                                          report_error);
+                                         NULL, false, false);
                             } else
-                                report_error(ERR_NONFATAL,
+                                nasm_error(ERR_NONFATAL,
                                              "bad syntax for EQU");
                         }
                     } else {
@@ -1593,8 +1578,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                                 define_label(output_ins.label,
                                              output_ins.oprs[0].segment,
                                              output_ins.oprs[0].offset,
-                                             NULL, false, false, ofmt,
-                                             report_error);
+                                             NULL, false, false);
                             } else if (output_ins.operands == 2
                                        && (output_ins.oprs[0].
                                            type & IMMEDIATE)
@@ -1609,10 +1593,9 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                                              output_ins.oprs[0].
                                              offset | SEG_ABS,
                                              output_ins.oprs[1].offset,
-                                             NULL, false, false, ofmt,
-                                             report_error);
+                                             NULL, false, false);
                             } else
-                                report_error(ERR_NONFATAL,
+                                nasm_error(ERR_NONFATAL,
                                              "bad syntax for EQU");
                         }
                     }
@@ -1621,7 +1604,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                     if (pass1 == 1) {
 
                         int64_t l = insn_size(location.segment, offs, sb, cpu,
-                                           &output_ins, report_error);
+                                           &output_ins, nasm_error);
 
                         /* if (using_debug_info)  && output_ins.opcode != -1) */
                         if (using_debug_info)
@@ -1694,8 +1677,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
 
                             }
 
-                            ofmt->current_dfmt->debug_typevalue(typeinfo);
-
+                            dfmt->debug_typevalue(typeinfo);
                         }
                         if (l != -1) {
                             offs += l;
@@ -1708,7 +1690,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
 
                     } else {
                         offs += assemble(location.segment, offs, sb, cpu,
-                                         &output_ins, ofmt, report_error,
+                                         &output_ins, ofmt, nasm_error,
                                          &nasmlist);
                         SET_CURR_OFFS(offs);
 
@@ -1721,7 +1703,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
         }                       /* end while (line = preproc->getline... */
 
         if (pass0 == 2 && global_offset_changed && !terminate_after_phase)
-            report_error(ERR_NONFATAL,
+            nasm_error(ERR_NONFATAL,
                         "phase error detected at end of assembly.");
 
         if (pass1 == 1)
@@ -1744,10 +1726,10 @@ static void assemble_file(char *fname, StrList **depend_ptr)
             /* We get here if the labels don't converge
              * Example: FOO equ FOO + 1
              */
-             report_error(ERR_NONFATAL,
+             nasm_error(ERR_NONFATAL,
                           "Can't find valid values for all labels "
                           "after %d passes, giving up.", passn);
-            report_error(ERR_NONFATAL,
+            nasm_error(ERR_NONFATAL,
                          "Possible causes: recursive EQUs, macro abuse.");
             break;
        }
@@ -1807,7 +1789,7 @@ static enum directives getkw(char **directive, char **value)
         *buf++ = '\0';
     }
 
-    return bsii(*directive, directives, elements(directives));
+    return find_directive(*directive);
 }
 
 /**
@@ -1824,9 +1806,8 @@ static enum directives getkw(char **directive, char **value)
  * @param severity the severity of the warning or error
  * @param fmt the printf style format string
  */
-static void report_error_gnu(int severity, const char *fmt, ...)
+static void nasm_verror_gnu(int severity, const char *fmt, va_list ap)
 {
-    va_list ap;
     char *currentfile = NULL;
     int32_t lineno = 0;
 
@@ -1843,9 +1824,7 @@ static void report_error_gnu(int severity, const char *fmt, ...)
        fputs("nasm: ", error_file);
     }
 
-    va_start(ap, fmt);
-    report_error_common(severity, fmt, ap);
-    va_end(ap);
+    nasm_verror_common(severity, fmt, ap);
 }
 
 /**
@@ -1863,9 +1842,8 @@ static void report_error_gnu(int severity, const char *fmt, ...)
  * @param severity the severity of the warning or error
  * @param fmt the printf style format string
  */
-static void report_error_vc(int severity, const char *fmt, ...)
+static void nasm_verror_vc(int severity, const char *fmt, va_list ap)
 {
-    va_list ap;
     char *currentfile = NULL;
     int32_t lineno = 0;
 
@@ -1882,9 +1860,7 @@ static void report_error_vc(int severity, const char *fmt, ...)
         fputs("nasm: ", error_file);
     }
 
-    va_start(ap, fmt);
-    report_error_common(severity, fmt, ap);
-    va_end(ap);
+    nasm_verror_common(severity, fmt, ap);
 }
 
 /**
@@ -1918,12 +1894,11 @@ static bool is_suppressed_warning(int severity)
  * @param severity the severity of the warning or error
  * @param fmt the printf style format string
  */
-static void report_error_common(int severity, const char *fmt,
-                                va_list args)
+static void nasm_verror_common(int severity, const char *fmt, va_list args)
 {
     char msg[1024];
     const char *pfx;
-    
+
     switch (severity & (ERR_MASK|ERR_NO_SEVERITY)) {
     case ERR_WARNING:
         pfx = "warning: ";
@@ -1970,6 +1945,7 @@ static void report_error_common(int severity, const char *fmt,
         if (ofile) {
             fclose(ofile);
             remove(outname);
+           ofile = NULL;
         }
         if (want_usage)
             usage();
@@ -1988,32 +1964,24 @@ static void usage(void)
     fputs("type `nasm -h' for help\n", error_file);
 }
 
-static void register_output_formats(void)
-{
-    ofmt = ofmt_register(report_error);
-}
-
 #define BUF_DELTA 512
 
 static FILE *no_pp_fp;
-static efunc no_pp_err;
 static ListGen *no_pp_list;
 static int32_t no_pp_lineinc;
 
-static void no_pp_reset(char *file, int pass, efunc error, evalfunc eval,
-                        ListGen * listgen, StrList **deplist)
+static void no_pp_reset(char *file, int pass, ListGen * listgen,
+                       StrList **deplist)
 {
     src_set_fname(nasm_strdup(file));
     src_set_linnum(0);
     no_pp_lineinc = 1;
-    no_pp_err = error;
     no_pp_fp = fopen(file, "r");
     if (!no_pp_fp)
-        no_pp_err(ERR_FATAL | ERR_NOFILE,
-                  "unable to open input file `%s'", file);
+        nasm_error(ERR_FATAL | ERR_NOFILE,
+                  "unable to open input file `%s'", file);
     no_pp_list = listgen;
     (void)pass;                 /* placate compilers */
-    (void)eval;                 /* placate compilers */
 
     if (deplist) {
        StrList *sl = nasm_malloc(strlen(file)+1+sizeof sl->next);
@@ -2122,7 +2090,7 @@ static uint32_t get_cpu(char *value)
         !nasm_stricmp(value, "itanic") || !nasm_stricmp(value, "merced"))
         return IF_IA64;
 
-    report_error(pass0 < 2 ? ERR_NONFATAL : ERR_FATAL,
+    nasm_error(pass0 < 2 ? ERR_NONFATAL : ERR_FATAL,
                  "unknown 'cpu' type");
 
     return IF_PLEVEL;           /* the maximum level */
@@ -2136,24 +2104,24 @@ static int get_bits(char *value)
         return i;               /* set for a 16-bit segment */
     else if (i == 32) {
         if (cpu < IF_386) {
-            report_error(ERR_NONFATAL,
+            nasm_error(ERR_NONFATAL,
                          "cannot specify 32-bit segment on processor below a 386");
             i = 16;
         }
     } else if (i == 64) {
         if (cpu < IF_X86_64) {
-            report_error(ERR_NONFATAL,
+            nasm_error(ERR_NONFATAL,
                          "cannot specify 64-bit segment on processor below an x86-64");
             i = 16;
         }
         if (i != maxbits) {
-            report_error(ERR_NONFATAL,
+            nasm_error(ERR_NONFATAL,
                          "%s output format does not support 64-bit code",
                          ofmt->shortname);
             i = 16;
         }
     } else {
-        report_error(pass0 < 2 ? ERR_NONFATAL : ERR_FATAL,
+        nasm_error(pass0 < 2 ? ERR_NONFATAL : ERR_FATAL,
                      "`%s' is not a valid segment size; must be 16, 32 or 64",
                      value);
         i = 16;
diff --git a/nasm.h b/nasm.h
index 0e6482b..9e233fc 100644 (file)
--- a/nasm.h
+++ b/nasm.h
@@ -45,6 +45,7 @@
 #include "nasmlib.h"
 #include "preproc.h"
 #include "insnsi.h"            /* For enum opcode */
+#include "directives.h"                /* For enum directive */
 
 #define NO_SEG -1L              /* null segment value */
 #define SEG_ABS 0x40000000L     /* mask for far-absolute segments */
@@ -121,9 +122,10 @@ typedef bool (*lfunc) (char *label, int32_t *segment, int64_t *offset);
  * should affect the local-label system), or something odder like
  * an EQU or a segment-base symbol, which shouldn't.
  */
-typedef void (*ldfunc) (char *label, int32_t segment, int64_t offset,
-                        char *special, bool is_norm, bool isextrn,
-                        struct ofmt * ofmt, efunc error);
+typedef void (*ldfunc)(char *label, int32_t segment, int64_t offset,
+                      char *special, bool is_norm, bool isextrn);
+void define_label(char *label, int32_t segment, int64_t offset,
+                 char *special, bool is_norm, bool isextrn);
 
 /*
  * List-file generators should look like this:
@@ -353,7 +355,7 @@ typedef struct preproc_ops {
      * of the pass, an error reporting function, an evaluator
      * function, and a listing generator to talk to.
      */
-    void (*reset) (char *, int, efunc, evalfunc, ListGen *, StrList **);
+    void (*reset) (char *, int, ListGen *, StrList **);
 
     /*
      * Called to fetch a line of preprocessed source. The line
@@ -785,7 +787,7 @@ struct ofmt {
      * an output format, be sure to set this to whatever default you want
      *
      */
-    struct dfmt *current_dfmt;
+    const struct dfmt *current_dfmt;
 
     /*
      * This, if non-NULL, is a NULL-terminated list of `char *'s
@@ -797,13 +799,10 @@ struct ofmt {
     macros_t *stdmac;
 
     /*
-     * This procedure is called at the start of an output session.
-     * It tells the output format what file it will be writing to,
-     * what routine to report errors through, and how to interface
-     * to the label manager and expression evaluator if necessary.
-     * It also gives it a chance to do other initialisation.
+     * This procedure is called at the start of an output session to set
+     * up internal parameters.
      */
-    void (*init) (FILE * fp, efunc error, ldfunc ldef, evalfunc eval);
+    void (*init)(void);
 
     /*
      * This procedure is called to pass generic information to the
@@ -904,7 +903,7 @@ struct ofmt {
      * should also return non-zero if it correctly processes the
      * directive.
      */
-    int (*directive) (char *directive, char *value, int pass);
+    int (*directive)(enum directives directive, char *value, int pass);
 
     /*
      * This procedure is called before anything else - even before
@@ -923,7 +922,7 @@ struct ofmt {
      * The parameter `outname' points to an area of storage
      * guaranteed to be at least FILENAME_MAX in size.
      */
-    void (*filename) (char *inname, char *outname, efunc error);
+    void (*filename) (char *inname, char *outname);
 
     /*
      * This procedure is called after assembly finishes, to allow
@@ -937,6 +936,8 @@ struct ofmt {
     void (*cleanup) (int debuginfo);
 };
 
+extern struct ofmt *ofmt;
+extern FILE *ofile;
 
 /*
  * ------------------------------------------------------------
@@ -958,17 +959,15 @@ struct dfmt {
     const char *shortname;
 
     /*
-     * init - called initially to set up local pointer to object format,
-     * void pointer to implementation defined data, file pointer (which
-     * probably won't be used, but who knows?), and error function.
+     * init - called initially to set up local pointer to object format.
      */
-    void (*init) (struct ofmt * of, void *id, FILE * fp, efunc error);
+    void (*init)(void);
 
     /*
      * linenum - called any time there is output with a change of
      * line number or file.
      */
-    void (*linenum) (const char *filename, int32_t linenumber, int32_t segto);
+    void (*linenum)(const char *filename, int32_t linenumber, int32_t segto);
 
     /*
      * debug_deflabel - called whenever a label is defined. Parameters
@@ -976,8 +975,8 @@ struct dfmt {
      * would be called before the output format version.
      */
 
-    void (*debug_deflabel) (char *name, int32_t segment, int64_t offset,
-                            int is_global, char *special);
+    void (*debug_deflabel)(char *name, int32_t segment, int64_t offset,
+                          int is_global, char *special);
     /*
      * debug_directive - called whenever a DEBUG directive other than 'LINE'
      * is encountered. 'directive' contains the first parameter to the
@@ -986,27 +985,29 @@ struct dfmt {
      * function with 'directive' equal to "VAR" and 'params' equal to
      * "_somevar:int".
      */
-    void (*debug_directive) (const char *directive, const char *params);
+    void (*debug_directive)(const char *directive, const char *params);
 
     /*
      * typevalue - called whenever the assembler wishes to register a type
      * for the last defined label.  This routine MUST detect if a type was
      * already registered and not re-register it.
      */
-    void (*debug_typevalue) (int32_t type);
+    void (*debug_typevalue)(int32_t type);
 
     /*
      * debug_output - called whenever output is required
      * 'type' is the type of info required, and this is format-specific
      */
-    void (*debug_output) (int type, void *param);
+    void (*debug_output)(int type, void *param);
 
     /*
      * cleanup - called after processing of file is complete
      */
-    void (*cleanup) (void);
-
+    void (*cleanup)(void);
 };
+
+extern const struct dfmt *dfmt;
+
 /*
  * The type definition macros
  * for debugging
index ae7abfb..35aa505 100644 (file)
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -48,7 +48,7 @@
 #include "insns.h"
 
 int globalbits = 0;    /* defined in nasm.h, works better here for ASM+DISASM */
-efunc nasm_malloc_error;       /* Exported for the benefit of vsnprintf.c */
+static vefunc nasm_verror;     /* Global error handling function */
 
 #ifdef LOGALLOC
 static FILE *logfp;
@@ -72,9 +72,22 @@ void tolower_init(void)
        nasm_tolower_tab[i] = tolower(i);
 }
 
-void nasm_set_malloc_error(efunc error)
+void nasm_set_verror(vefunc ve)
+{
+    nasm_verror = ve;
+}
+
+void nasm_error(int severity, const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    nasm_verror(severity, fmt, ap);
+    va_end(ap);
+}
+
+void nasm_init_malloc_error(void)
 {
-    nasm_malloc_error = error;
 #ifdef LOGALLOC
     logfp = fopen("malloc.log", "w");
     setvbuf(logfp, NULL, _IOLBF, BUFSIZ);
@@ -90,7 +103,7 @@ void *nasm_malloc(size_t size)
 {
     void *p = malloc(size);
     if (!p)
-        nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
+        nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory");
 #ifdef LOGALLOC
     else
         fprintf(logfp, "%s %d malloc(%ld) returns %p\n",
@@ -107,7 +120,7 @@ void *nasm_zalloc(size_t size)
 {
     void *p = calloc(size, 1);
     if (!p)
-        nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
+        nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory");
 #ifdef LOGALLOC
     else
         fprintf(logfp, "%s %d calloc(%ld, 1) returns %p\n",
@@ -124,7 +137,7 @@ void *nasm_realloc(void *q, size_t size)
 {
     void *p = q ? realloc(q, size) : malloc(size);
     if (!p)
-        nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
+        nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory");
 #ifdef LOGALLOC
     else if (q)
         fprintf(logfp, "%s %d realloc(%p,%ld) returns %p\n",
@@ -161,7 +174,7 @@ char *nasm_strdup(const char *s)
 
     p = malloc(size);
     if (!p)
-        nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
+        nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory");
 #ifdef LOGALLOC
     else
         fprintf(logfp, "%s %d strdup(%ld) returns %p\n",
@@ -182,7 +195,7 @@ char *nasm_strndup(const char *s, size_t len)
 
     p = malloc(size);
     if (!p)
-        nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
+        nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory");
 #ifdef LOGALLOC
     else
         fprintf(logfp, "%s %d strndup(%ld) returns %p\n",
@@ -195,8 +208,7 @@ char *nasm_strndup(const char *s, size_t len)
 
 no_return nasm_assert_failed(const char *file, int line, const char *msg)
 {
-    nasm_malloc_error(ERR_FATAL, "assertion %s failed at %s:%d",
-                     msg, file, line);
+    nasm_error(ERR_FATAL, "assertion %s failed at %s:%d", msg, file, line);
     exit(1);
 }
 
@@ -396,9 +408,9 @@ int64_t readnum(char *str, bool *error)
     }
 
     if (warn)
-        nasm_malloc_error(ERR_WARNING | ERR_PASS1 | ERR_WARN_NOV,
-                          "numeric constant %s does not fit in 64 bits",
-                          str);
+        nasm_error(ERR_WARNING | ERR_PASS1 | ERR_WARN_NOV,
+                  "numeric constant %s does not fit in 64 bits",
+                  str);
 
     return result * sign;
 }
@@ -513,8 +525,7 @@ size_t fwritezero(size_t bytes, FILE *fp)
     return count;
 }
 
-void standard_extension(char *inname, char *outname, char *extension,
-                        efunc error)
+void standard_extension(char *inname, char *outname, char *extension)
 {
     char *p, *q;
 
@@ -531,13 +542,13 @@ void standard_extension(char *inname, char *outname, char *extension,
             p++;                /* go back to end if none found */
     if (!strcmp(p, extension)) {        /* is the extension already there? */
         if (*extension)
-            error(ERR_WARNING | ERR_NOFILE,
-                  "file name already ends in `%s': "
-                  "output will be in `nasm.out'", extension);
+            nasm_error(ERR_WARNING | ERR_NOFILE,
+                      "file name already ends in `%s': "
+                      "output will be in `nasm.out'", extension);
         else
-            error(ERR_WARNING | ERR_NOFILE,
-                  "file name already has no extension: "
-                  "output will be in `nasm.out'");
+            nasm_error(ERR_WARNING | ERR_NOFILE,
+                      "file name already has no extension: "
+                      "output will be in `nasm.out'");
         strcpy(outname, "nasm.out");
     } else
         strcpy(p, extension);
index 421e8cc..21e976e 100644 (file)
--- a/nasmlib.h
+++ b/nasmlib.h
@@ -83,7 +83,9 @@ extern unsigned char nasm_tolower_tab[256];
  * An error reporting function should look like this.
  */
 typedef void (*efunc) (int severity, const char *fmt, ...);
-extern efunc nasm_malloc_error;
+typedef void (*vefunc) (int severity, const char *fmt, va_list ap);
+void nasm_error(int severity, const char *fmt, ...);
+void nasm_set_verror(vefunc);
 
 /*
  * These are the error severity codes which get passed as the first
@@ -133,7 +135,7 @@ extern efunc nasm_malloc_error;
  * passed a NULL pointer; nasm_free will do nothing if it is passed
  * a NULL pointer.
  */
-void nasm_set_malloc_error(efunc);
+void nasm_init_malloc_error(void);
 #ifndef LOGALLOC
 void *nasm_malloc(size_t);
 void *nasm_zalloc(size_t);
@@ -220,10 +222,7 @@ int32_t seg_alloc(void);
  * many output formats will be able to make use of this: a standard
  * function to add an extension to the name of the input file
  */
-#ifdef NASM_NASM_H
-void standard_extension(char *inname, char *outname, char *extension,
-                        efunc error);
-#endif
+void standard_extension(char *inname, char *outname, char *extension);
 
 /*
  * Utility macros...
index 9234c6e..8c924b9 100644 (file)
--- a/ndisasm.c
+++ b/ndisasm.c
@@ -68,11 +68,8 @@ static const char *help =
 static void output_ins(uint32_t, uint8_t *, int, char *);
 static void skip(uint32_t dist, FILE * fp);
 
-static void ndisasm_error(int severity, const char *fmt, ...)
+static void ndisasm_verror(int severity, const char *fmt, va_list va)
 {
-    va_list va;
-
-    va_start(va, fmt);
     vfprintf(stderr, fmt, va);
 
     if (severity & ERR_FATAL)
@@ -97,7 +94,8 @@ int main(int argc, char **argv)
     FILE *fp;
 
     tolower_init();
-    nasm_set_malloc_error(ndisasm_error);
+    nasm_set_verror(ndisasm_verror);
+    nasm_init_malloc_error();
 
     offset = 0;
     init_sync();
index 54a4580..2b985c5 100644 (file)
 #include "nasm.h"
 #include "nasmlib.h"
 
-void null_debug_init(struct ofmt *of, void *id, FILE * fp, efunc error)
+void null_debug_init(void)
 {
-       (void)of;
-       (void)id;
-       (void)fp;
-       (void)error;
 }
+
 void null_debug_linenum(const char *filename, int32_t linenumber, int32_t segto)
 {
        (void)filename;
        (void)linenumber;
        (void)segto;
 }
+
 void null_debug_deflabel(char *name, int32_t segment, int64_t offset,
                          int is_global, char *special)
 {
@@ -56,20 +54,24 @@ void null_debug_deflabel(char *name, int32_t segment, int64_t offset,
        (void)is_global;
        (void)special;
 }
+
 void null_debug_routine(const char *directive, const char *params)
 {
        (void)directive;
        (void)params;
 }
+
 void null_debug_typevalue(int32_t type)
 {
        (void)type;
 }
+
 void null_debug_output(int type, void *param)
 {
        (void)type;
        (void)param;
 }
+
 void null_debug_cleanup(void)
 {
 }
diff --git a/output/nullout.c b/output/nullout.c
new file mode 100644 (file)
index 0000000..228fa16
--- /dev/null
@@ -0,0 +1,51 @@
+/* ----------------------------------------------------------------------- *
+ *   
+ *   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+ *   See the file AUTHORS included with the NASM distribution for
+ *   the specific copyright holders.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following
+ *   conditions are met:
+ *
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above
+ *     copyright notice, this list of conditions and the following
+ *     disclaimer in the documentation and/or other materials provided
+ *     with the distribution.
+ *     
+ *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ----------------------------------------------------------------------- */
+
+#include "nasm.h"
+#include "nasmlib.h"
+#include "output/outlib.h"
+
+int null_setinfo(enum geninfo type, char **string)
+{
+    (void)type;
+    (void)string;
+    return 0;
+}
+
+int null_directive(enum directives directive, char *value, int pass)
+{
+    (void)directive;
+    (void)value;
+    (void)pass;
+    return 0;
+}
index 4d38cdf..8bff63e 100644 (file)
@@ -49,6 +49,7 @@
 #include "saa.h"
 #include "raa.h"
 #include "stdscan.h"
+#include "eval.h"
 #include "output/outform.h"
 #include "output/outlib.h"
 
@@ -129,10 +130,6 @@ static uint32_t strslen;
 
 static struct Symbol *fwds;
 
-static FILE *aoutfp;
-static efunc error;
-static evalfunc evaluate;
-
 static int bsd;
 static int is_pic;
 
@@ -153,13 +150,8 @@ static int32_t aout_gotpc_sect, aout_gotoff_sect;
 static int32_t aout_got_sect, aout_plt_sect;
 static int32_t aout_sym_sect;
 
-static void aoutg_init(FILE * fp, efunc errfunc, ldfunc ldef,
-                       evalfunc eval)
+static void aoutg_init(void)
 {
-    aoutfp = fp;
-    error = errfunc;
-    evaluate = eval;
-    (void)ldef;                 /* placate optimisers */
     stext.data = saa_init(1L);
     stext.head = NULL;
     stext.tail = &stext.head;
@@ -183,10 +175,10 @@ static void aoutg_init(FILE * fp, efunc errfunc, ldfunc ldef,
 
 #ifdef OF_AOUT
 
-static void aout_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void aout_init(void)
 {
     bsd = false;
-    aoutg_init(fp, errfunc, ldef, eval);
+    aoutg_init();
 
     aout_gotpc_sect = aout_gotoff_sect = aout_got_sect =
         aout_plt_sect = aout_sym_sect = NO_SEG;
@@ -198,29 +190,23 @@ static void aout_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
 
 extern struct ofmt of_aoutb;
 
-static void aoutb_init(FILE * fp, efunc errfunc, ldfunc ldef,
-                       evalfunc eval)
+static void aoutb_init(void)
 {
     bsd = true;
-    aoutg_init(fp, errfunc, ldef, eval);
+    aoutg_init();
 
     is_pic = 0x00;              /* may become 0x40 */
 
     aout_gotpc_sect = seg_alloc();
-    ldef("..gotpc", aout_gotpc_sect + 1, 0L, NULL, false, false, &of_aoutb,
-         error);
+    define_label("..gotpc", aout_gotpc_sect + 1, 0L, NULL, false, false);
     aout_gotoff_sect = seg_alloc();
-    ldef("..gotoff", aout_gotoff_sect + 1, 0L, NULL, false, false,
-         &of_aoutb, error);
+    define_label("..gotoff", aout_gotoff_sect + 1, 0L, NULL, false, false);
     aout_got_sect = seg_alloc();
-    ldef("..got", aout_got_sect + 1, 0L, NULL, false, false, &of_aoutb,
-         error);
+    define_label("..got", aout_got_sect + 1, 0L, NULL, false, false);
     aout_plt_sect = seg_alloc();
-    ldef("..plt", aout_plt_sect + 1, 0L, NULL, false, false, &of_aoutb,
-         error);
+    define_label("..plt", aout_plt_sect + 1, 0L, NULL, false, false);
     aout_sym_sect = seg_alloc();
-    ldef("..sym", aout_sym_sect + 1, 0L, NULL, false, false, &of_aoutb,
-         error);
+    define_label("..sym", aout_sym_sect + 1, 0L, NULL, false, false);
 }
 
 #endif
@@ -235,7 +221,6 @@ static void aout_cleanup(int debuginfo)
     aout_fixup_relocs(&stext);
     aout_fixup_relocs(&sdata);
     aout_write();
-    fclose(aoutfp);
     saa_free(stext.data);
     while (stext.head) {
         r = stext.head;
@@ -293,7 +278,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset,
         if (strcmp(name, "..gotpc") && strcmp(name, "..gotoff") &&
             strcmp(name, "..got") && strcmp(name, "..plt") &&
             strcmp(name, "..sym"))
-            error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
+            nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
         return;
     }
 
@@ -316,10 +301,10 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset,
                 stdscan_reset();
                 stdscan_bufptr = p;
                 tokval.t_type = TOKEN_INVALID;
-                e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL);
+                e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
                 if (e) {
                     if (!is_simple(e))
-                        error(ERR_NONFATAL, "cannot use relocatable"
+                        nasm_error(ERR_NONFATAL, "cannot use relocatable"
                               " expression as symbol size");
                     else
                         (*s)->size = reloc_value(e);
@@ -388,7 +373,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset,
                      !nasm_strnicmp(special, "object", n))
                 sym->type |= SYM_DATA;
             else
-                error(ERR_NONFATAL, "unrecognised symbol type `%.*s'",
+                nasm_error(ERR_NONFATAL, "unrecognised symbol type `%.*s'",
                       n, special);
             if (special[n]) {
                 struct tokenval tokval;
@@ -397,7 +382,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset,
                 char *saveme = stdscan_bufptr;  /* bugfix? fbk 8/10/00 */
 
                 if (!bsd) {
-                    error(ERR_NONFATAL, "Linux a.out does not support"
+                    nasm_error(ERR_NONFATAL, "Linux a.out does not support"
                           " symbol size information");
                 } else {
                     while (special[n] && nasm_isspace(special[n]))
@@ -410,7 +395,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset,
                     stdscan_reset();
                     stdscan_bufptr = special + n;
                     tokval.t_type = TOKEN_INVALID;
-                    e = evaluate(stdscan, NULL, &tokval, &fwd, 0, error,
+                    e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error,
                                  NULL);
                     if (fwd) {
                         sym->nextfwd = fwds;
@@ -418,7 +403,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset,
                         sym->name = nasm_strdup(name);
                     } else if (e) {
                         if (!is_simple(e))
-                            error(ERR_NONFATAL, "cannot use relocatable"
+                            nasm_error(ERR_NONFATAL, "cannot use relocatable"
                                   " expression as symbol size");
                         else
                             sym->size = reloc_value(e);
@@ -444,7 +429,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset,
         nsyms++;                /* and another for the size */
 
     if (special && !special_used)
-        error(ERR_NONFATAL, "no special symbol features supported here");
+        nasm_error(ERR_NONFATAL, "no special symbol features supported here");
 }
 
 static void aout_add_reloc(struct Section *sect, int32_t segment,
@@ -512,7 +497,7 @@ static int32_t aout_add_gsym_reloc(struct Section *sect,
         shead = sbss.gsyms;
     if (!shead) {
         if (exact && offset != 0)
-            error(ERR_NONFATAL, "unable to find a suitable global symbol"
+            nasm_error(ERR_NONFATAL, "unable to find a suitable global symbol"
                   " for this reference");
         else
             aout_add_reloc(sect, segment, type, bytes);
@@ -536,7 +521,7 @@ static int32_t aout_add_gsym_reloc(struct Section *sect,
                 sym = sm;
     }
     if (!sym && exact) {
-        error(ERR_NONFATAL, "unable to find a suitable global symbol"
+        nasm_error(ERR_NONFATAL, "unable to find a suitable global symbol"
               " for this reference");
         return 0;
     }
@@ -583,7 +568,7 @@ static int32_t aout_add_gotoff_reloc(struct Section *sect, int32_t segment,
     else if (segment == sbss.index)
         asym = sbss.asym;
     if (!asym)
-        error(ERR_NONFATAL, "`..gotoff' relocations require a non-global"
+        nasm_error(ERR_NONFATAL, "`..gotoff' relocations require a non-global"
               " symbol in the section");
 
     r = *sect->tail = nasm_malloc(sizeof(struct Reloc));
@@ -613,7 +598,7 @@ static void aout_out(int32_t segto, const void *data,
      */
     if (segto == NO_SEG) {
         if (type != OUT_RESERVE)
-            error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
+            nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
                   " space");
         return;
     }
@@ -625,13 +610,13 @@ static void aout_out(int32_t segto, const void *data,
     else if (segto == sbss.index)
         s = NULL;
     else {
-        error(ERR_WARNING, "attempt to assemble code in"
+        nasm_error(ERR_WARNING, "attempt to assemble code in"
               " segment %d: defaulting to `.text'", segto);
         s = &stext;
     }
 
     if (!s && type != OUT_RESERVE) {
-        error(ERR_WARNING, "attempt to initialize memory in the"
+        nasm_error(ERR_WARNING, "attempt to initialize memory in the"
               " BSS section: ignored");
         sbss.len += realsize(type, size);
         return;
@@ -639,7 +624,7 @@ static void aout_out(int32_t segto, const void *data,
 
     if (type == OUT_RESERVE) {
         if (s) {
-            error(ERR_WARNING, "uninitialized space declared in"
+            nasm_error(ERR_WARNING, "uninitialized space declared in"
                   " %s section: zeroing",
                   (segto == stext.index ? "code" : "data"));
             aout_sect_write(s, NULL, size);
@@ -647,20 +632,20 @@ static void aout_out(int32_t segto, const void *data,
             sbss.len += size;
     } else if (type == OUT_RAWDATA) {
         if (segment != NO_SEG)
-            error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
+            nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
         aout_sect_write(s, data, size);
     } else if (type == OUT_ADDRESS) {
         addr = *(int64_t *)data;
         if (segment != NO_SEG) {
             if (segment % 2) {
-                error(ERR_NONFATAL, "a.out format does not support"
+                nasm_error(ERR_NONFATAL, "a.out format does not support"
                       " segment base references");
             } else {
                 if (wrt == NO_SEG) {
                     aout_add_reloc(s, segment, RELTYPE_ABSOLUTE,
                                    size);
                 } else if (!bsd) {
-                    error(ERR_NONFATAL,
+                    nasm_error(ERR_NONFATAL,
                           "Linux a.out format does not support"
                           " any use of WRT");
                     wrt = NO_SEG;       /* we can at least _try_ to continue */
@@ -682,11 +667,11 @@ static void aout_out(int32_t segto, const void *data,
                                                false);
                 } else if (wrt == aout_plt_sect + 1) {
                     is_pic = 0x40;
-                    error(ERR_NONFATAL,
+                    nasm_error(ERR_NONFATAL,
                           "a.out format cannot produce non-PC-"
                           "relative PLT references");
                 } else {
-                    error(ERR_NONFATAL,
+                    nasm_error(ERR_NONFATAL,
                           "a.out format does not support this"
                           " use of WRT");
                     wrt = NO_SEG;       /* we can at least _try_ to continue */
@@ -701,15 +686,15 @@ static void aout_out(int32_t segto, const void *data,
         aout_sect_write(s, mydata, size);
     } else if (type == OUT_REL2ADR) {
         if (segment == segto)
-            error(ERR_PANIC, "intra-segment OUT_REL2ADR");
+            nasm_error(ERR_PANIC, "intra-segment OUT_REL2ADR");
         if (segment != NO_SEG && segment % 2) {
-            error(ERR_NONFATAL, "a.out format does not support"
+            nasm_error(ERR_NONFATAL, "a.out format does not support"
                   " segment base references");
         } else {
             if (wrt == NO_SEG) {
                 aout_add_reloc(s, segment, RELTYPE_RELATIVE, 2);
             } else if (!bsd) {
-                error(ERR_NONFATAL, "Linux a.out format does not support"
+                nasm_error(ERR_NONFATAL, "Linux a.out format does not support"
                       " any use of WRT");
                 wrt = NO_SEG;   /* we can at least _try_ to continue */
             } else if (wrt == aout_plt_sect + 1) {
@@ -718,10 +703,10 @@ static void aout_out(int32_t segto, const void *data,
             } else if (wrt == aout_gotpc_sect + 1 ||
                        wrt == aout_gotoff_sect + 1 ||
                        wrt == aout_got_sect + 1) {
-                error(ERR_NONFATAL, "a.out format cannot produce PC-"
+                nasm_error(ERR_NONFATAL, "a.out format cannot produce PC-"
                       "relative GOT references");
             } else {
-                error(ERR_NONFATAL, "a.out format does not support this"
+                nasm_error(ERR_NONFATAL, "a.out format does not support this"
                       " use of WRT");
                 wrt = NO_SEG;   /* we can at least _try_ to continue */
             }
@@ -731,15 +716,15 @@ static void aout_out(int32_t segto, const void *data,
         aout_sect_write(s, mydata, 2L);
     } else if (type == OUT_REL4ADR) {
         if (segment == segto)
-            error(ERR_PANIC, "intra-segment OUT_REL4ADR");
+            nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR");
         if (segment != NO_SEG && segment % 2) {
-            error(ERR_NONFATAL, "a.out format does not support"
+            nasm_error(ERR_NONFATAL, "a.out format does not support"
                   " segment base references");
         } else {
             if (wrt == NO_SEG) {
                 aout_add_reloc(s, segment, RELTYPE_RELATIVE, 4);
             } else if (!bsd) {
-                error(ERR_NONFATAL, "Linux a.out format does not support"
+                nasm_error(ERR_NONFATAL, "Linux a.out format does not support"
                       " any use of WRT");
                 wrt = NO_SEG;   /* we can at least _try_ to continue */
             } else if (wrt == aout_plt_sect + 1) {
@@ -748,10 +733,10 @@ static void aout_out(int32_t segto, const void *data,
             } else if (wrt == aout_gotpc_sect + 1 ||
                        wrt == aout_gotoff_sect + 1 ||
                        wrt == aout_got_sect + 1) {
-                error(ERR_NONFATAL, "a.out format cannot produce PC-"
+                nasm_error(ERR_NONFATAL, "a.out format cannot produce PC-"
                       "relative GOT references");
             } else {
-                error(ERR_NONFATAL, "a.out format does not support this"
+                nasm_error(ERR_NONFATAL, "a.out format does not support this"
                       " use of WRT");
                 wrt = NO_SEG;   /* we can at least _try_ to continue */
             }
@@ -823,20 +808,20 @@ static void aout_write(void)
      * Emit the a.out header.
      */
     /* OMAGIC, M_386 or MID_I386, no flags */
-    fwriteint32_t(bsd ? 0x07018600 | is_pic : 0x640107L, aoutfp);
-    fwriteint32_t(stext.len, aoutfp);
-    fwriteint32_t(sdata.len, aoutfp);
-    fwriteint32_t(sbss.len, aoutfp);
-    fwriteint32_t(nsyms * 12, aoutfp);     /* length of symbol table */
-    fwriteint32_t(0L, aoutfp);     /* object files have no entry point */
-    fwriteint32_t(stext.nrelocs * 8, aoutfp);      /* size of text relocs */
-    fwriteint32_t(sdata.nrelocs * 8, aoutfp);      /* size of data relocs */
+    fwriteint32_t(bsd ? 0x07018600 | is_pic : 0x640107L, ofile);
+    fwriteint32_t(stext.len, ofile);
+    fwriteint32_t(sdata.len, ofile);
+    fwriteint32_t(sbss.len, ofile);
+    fwriteint32_t(nsyms * 12, ofile);     /* length of symbol table */
+    fwriteint32_t(0L, ofile);     /* object files have no entry point */
+    fwriteint32_t(stext.nrelocs * 8, ofile);      /* size of text relocs */
+    fwriteint32_t(sdata.nrelocs * 8, ofile);      /* size of data relocs */
 
     /*
      * Write out the code section and the data section.
      */
-    saa_fpwrite(stext.data, aoutfp);
-    saa_fpwrite(sdata.data, aoutfp);
+    saa_fpwrite(stext.data, ofile);
+    saa_fpwrite(sdata.data, ofile);
 
     /*
      * Write out the relocations.
@@ -852,8 +837,8 @@ static void aout_write(void)
     /*
      * And the string table.
      */
-    fwriteint32_t(strslen + 4, aoutfp);    /* length includes length count */
-    saa_fpwrite(strs, aoutfp);
+    fwriteint32_t(strslen + 4, ofile);    /* length includes length count */
+    saa_fpwrite(strs, ofile);
 }
 
 static void aout_write_relocs(struct Reloc *r)
@@ -861,7 +846,7 @@ static void aout_write_relocs(struct Reloc *r)
     while (r) {
         uint32_t word2;
 
-        fwriteint32_t(r->address, aoutfp);
+        fwriteint32_t(r->address, ofile);
 
         if (r->symbol >= 0)
             word2 = r->symbol;
@@ -870,7 +855,7 @@ static void aout_write_relocs(struct Reloc *r)
         word2 |= r->reltype << 24;
         word2 |= (r->bytes == 1 ? 0 :
                   r->bytes == 2 ? 0x2000000L : 0x4000000L);
-        fwriteint32_t(word2, aoutfp);
+        fwriteint32_t(word2, ofile);
 
         r = r->next;
     }
@@ -883,8 +868,8 @@ static void aout_write_syms(void)
     saa_rewind(syms);
     for (i = 0; i < nsyms; i++) {
         struct Symbol *sym = saa_rstruct(syms);
-        fwriteint32_t(sym->strpos, aoutfp);
-        fwriteint32_t((int32_t)sym->type & ~SYM_WITH_SIZE, aoutfp);
+        fwriteint32_t(sym->strpos, ofile);
+        fwriteint32_t((int32_t)sym->type & ~SYM_WITH_SIZE, ofile);
         /*
          * Fix up the symbol value now we know the final section
          * sizes.
@@ -893,14 +878,14 @@ static void aout_write_syms(void)
             sym->value += stext.len;
         if ((sym->type & SECT_MASK) == SECT_BSS)
             sym->value += stext.len + sdata.len;
-        fwriteint32_t(sym->value, aoutfp);
+        fwriteint32_t(sym->value, ofile);
         /*
          * Output a size record if necessary.
          */
         if (sym->type & SYM_WITH_SIZE) {
-            fwriteint32_t(sym->strpos, aoutfp);
-            fwriteint32_t(0x0DL, aoutfp);  /* special value: means size */
-            fwriteint32_t(sym->size, aoutfp);
+            fwriteint32_t(sym->strpos, ofile);
+            fwriteint32_t(0x0DL, ofile);  /* special value: means size */
+            fwriteint32_t(sym->size, ofile);
             i++;                /* use up another of `nsyms' */
         }
     }
@@ -918,27 +903,13 @@ static int32_t aout_segbase(int32_t segment)
     return segment;
 }
 
-static int aout_directive(char *directive, char *value, int pass)
+static void aout_filename(char *inname, char *outname)
 {
-    (void)directive;
-    (void)value;
-    (void)pass;
-    return 0;
-}
-
-static void aout_filename(char *inname, char *outname, efunc error)
-{
-    standard_extension(inname, outname, ".o", error);
+    standard_extension(inname, outname, ".o");
 }
 
 extern macros_t aout_stdmac[];
 
-static int aout_set_info(enum geninfo type, char **val)
-{
-    (void)type;
-    (void)val;
-    return 0;
-}
 #endif                          /* OF_AOUT || OF_AOUTB */
 
 #ifdef OF_AOUT
@@ -951,12 +922,12 @@ struct ofmt of_aout = {
     &null_debug_form,
     aout_stdmac,
     aout_init,
-    aout_set_info,
+    null_setinfo,
     aout_out,
     aout_deflabel,
     aout_section_names,
     aout_segbase,
-    aout_directive,
+    null_directive,
     aout_filename,
     aout_cleanup
 };
@@ -973,12 +944,12 @@ struct ofmt of_aoutb = {
     &null_debug_form,
     aout_stdmac,
     aoutb_init,
-    aout_set_info,
+    null_setinfo,
     aout_out,
     aout_deflabel,
     aout_section_names,
     aout_segbase,
-    aout_directive,
+    null_directive,
     aout_filename,
     aout_cleanup
 };
index 2fa4efc..877eebd 100644 (file)
@@ -107,21 +107,14 @@ static uint32_t strslen;
 
 static int as86_reloc_size;
 
-static FILE *as86fp;
-static efunc error;
-
 static void as86_write(void);
 static void as86_write_section(struct Section *, int);
 static int as86_add_string(char *name);
 static void as86_sect_write(struct Section *, const uint8_t *,
                             uint32_t);
 
-static void as86_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void as86_init(void)
 {
-    as86fp = fp;
-    error = errfunc;
-    (void)ldef;                 /* placate optimisers */
-    (void)eval;
     stext.data = saa_init(1L);
     stext.datalen = 0L;
     stext.head = stext.last = NULL;
@@ -152,7 +145,6 @@ static void as86_cleanup(int debuginfo)
     (void)debuginfo;
 
     as86_write();
-    fclose(as86fp);
     saa_free(stext.data);
     while (stext.head) {
         p = stext.head;
@@ -212,13 +204,13 @@ static void as86_deflabel(char *name, int32_t segment, int64_t offset,
     struct Symbol *sym;
 
     if (special)
-        error(ERR_NONFATAL, "as86 format does not support any"
+        nasm_error(ERR_NONFATAL, "as86 format does not support any"
               " special symbol types");
 
 
     if (name[0] == '.' && name[1] == '.' && name[2] != '@') {
        if (strcmp(name, "..start")) {
-           error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
+           nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
            return;
        } else {
            is_start = true;
@@ -306,7 +298,7 @@ static void as86_out(int32_t segto, const void *data,
 
     if (wrt != NO_SEG) {
         wrt = NO_SEG;           /* continue to do _something_ */
-        error(ERR_NONFATAL, "WRT not supported by as86 output format");
+        nasm_error(ERR_NONFATAL, "WRT not supported by as86 output format");
     }
 
     /*
@@ -314,7 +306,7 @@ static void as86_out(int32_t segto, const void *data,
      */
     if (segto == NO_SEG) {
         if (type != OUT_RESERVE)
-            error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
+            nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
                   " space");
         return;
     }
@@ -326,13 +318,13 @@ static void as86_out(int32_t segto, const void *data,
     else if (segto == bssindex)
         s = NULL;
     else {
-        error(ERR_WARNING, "attempt to assemble code in"
+        nasm_error(ERR_WARNING, "attempt to assemble code in"
               " segment %d: defaulting to `.text'", segto);
         s = &stext;
     }
 
     if (!s && type != OUT_RESERVE) {
-        error(ERR_WARNING, "attempt to initialize memory in the"
+        nasm_error(ERR_WARNING, "attempt to initialize memory in the"
               " BSS section: ignored");
        bsslen += realsize(type, size);
         return;
@@ -340,7 +332,7 @@ static void as86_out(int32_t segto, const void *data,
 
     if (type == OUT_RESERVE) {
         if (s) {
-            error(ERR_WARNING, "uninitialized space declared in"
+            nasm_error(ERR_WARNING, "uninitialized space declared in"
                   " %s section: zeroing",
                   (segto == stext.index ? "code" : "data"));
             as86_sect_write(s, NULL, size);
@@ -349,13 +341,13 @@ static void as86_out(int32_t segto, const void *data,
             bsslen += size;
     } else if (type == OUT_RAWDATA) {
         if (segment != NO_SEG)
-            error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
+            nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
         as86_sect_write(s, data, size);
         as86_add_piece(s, 0, 0L, 0L, size, 0);
     } else if (type == OUT_ADDRESS) {
         if (segment != NO_SEG) {
             if (segment % 2) {
-                error(ERR_NONFATAL, "as86 format does not support"
+                nasm_error(ERR_NONFATAL, "as86 format does not support"
                       " segment base references");
             } else {
                 offset = *(int64_t *)data;
@@ -369,10 +361,10 @@ static void as86_out(int32_t segto, const void *data,
         }
     } else if (type == OUT_REL2ADR) {
         if (segment == segto)
-            error(ERR_PANIC, "intra-segment OUT_REL2ADR");
+            nasm_error(ERR_PANIC, "intra-segment OUT_REL2ADR");
         if (segment != NO_SEG) {
             if (segment % 2) {
-                error(ERR_NONFATAL, "as86 format does not support"
+                nasm_error(ERR_NONFATAL, "as86 format does not support"
                       " segment base references");
             } else {
                 offset = *(int64_t *)data;
@@ -382,10 +374,10 @@ static void as86_out(int32_t segto, const void *data,
         }
     } else if (type == OUT_REL4ADR) {
         if (segment == segto)
-            error(ERR_PANIC, "intra-segment OUT_REL4ADR");
+            nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR");
         if (segment != NO_SEG) {
             if (segment % 2) {
-                error(ERR_NONFATAL, "as86 format does not support"
+                nasm_error(ERR_NONFATAL, "as86 format does not support"
                       " segment base references");
             } else {
                 offset = *(int64_t *)data;
@@ -440,23 +432,23 @@ static void as86_write(void)
     /*
      * Emit the as86 header.
      */
-    fwriteint32_t(0x000186A3L, as86fp);
-    fputc(0x2A, as86fp);
-    fwriteint32_t(27 + symlen + seglen + strslen, as86fp); /* header length */
-    fwriteint32_t(stext.len + sdata.len + bsslen, as86fp);
-    fwriteint16_t(strslen, as86fp);
-    fwriteint16_t(0, as86fp);     /* class = revision = 0 */
-    fwriteint32_t(0x55555555L, as86fp);    /* segment max sizes: always this */
-    fwriteint32_t(segsize, as86fp);        /* segment size descriptors */
+    fwriteint32_t(0x000186A3L, ofile);
+    fputc(0x2A, ofile);
+    fwriteint32_t(27 + symlen + seglen + strslen, ofile); /* header length */
+    fwriteint32_t(stext.len + sdata.len + bsslen, ofile);
+    fwriteint16_t(strslen, ofile);
+    fwriteint16_t(0, ofile);     /* class = revision = 0 */
+    fwriteint32_t(0x55555555L, ofile);    /* segment max sizes: always this */
+    fwriteint32_t(segsize, ofile);        /* segment size descriptors */
     if (segsize & 0x01000000L)
-        fwriteint32_t(stext.len, as86fp);
+        fwriteint32_t(stext.len, ofile);
     else
-        fwriteint16_t(stext.len, as86fp);
+        fwriteint16_t(stext.len, ofile);
     if (segsize & 0x40000000L)
-        fwriteint32_t(sdata.len + bsslen, as86fp);
+        fwriteint32_t(sdata.len + bsslen, ofile);
     else
-        fwriteint16_t(sdata.len + bsslen, as86fp);
-    fwriteint16_t(nsyms, as86fp);
+        fwriteint16_t(sdata.len + bsslen, ofile);
+    fwriteint16_t(nsyms, ofile);
 
     /*
      * Write the symbol table.
@@ -464,19 +456,19 @@ static void as86_write(void)
     saa_rewind(syms);
     for (i = 0; i < nsyms; i++) {
         struct Symbol *sym = saa_rstruct(syms);
-        fwriteint16_t(sym->strpos, as86fp);
-        fwriteint16_t(sym->flags, as86fp);
+        fwriteint16_t(sym->strpos, ofile);
+        fwriteint16_t(sym->flags, ofile);
         switch (sym->flags & (3 << 14)) {
         case 0 << 14:
             break;
         case 1 << 14:
-            fputc(sym->value, as86fp);
+            fputc(sym->value, ofile);
             break;
         case 2 << 14:
-            fwriteint16_t(sym->value, as86fp);
+            fwriteint16_t(sym->value, ofile);
             break;
         case 3 << 14:
-            fwriteint32_t(sym->value, as86fp);
+            fwriteint32_t(sym->value, ofile);
             break;
         }
     }
@@ -484,7 +476,7 @@ static void as86_write(void)
     /*
      * Write out the string table.
      */
-    saa_fpwrite(strs, as86fp);
+    saa_fpwrite(strs, ofile);
 
     /*
      * Write the program text.
@@ -496,17 +488,17 @@ static void as86_write(void)
      * Append the BSS section to the .data section
      */
     if (bsslen > 65535L) {
-        fputc(0x13, as86fp);
-        fwriteint32_t(bsslen, as86fp);
+        fputc(0x13, ofile);
+        fwriteint32_t(bsslen, ofile);
     } else if (bsslen > 255) {
-        fputc(0x12, as86fp);
-        fwriteint16_t(bsslen, as86fp);
+        fputc(0x12, ofile);
+        fwriteint16_t(bsslen, ofile);
     } else if (bsslen) {
-        fputc(0x11, as86fp);
-        fputc(bsslen, as86fp);
+        fputc(0x11, ofile);
+        fputc(bsslen, ofile);
     }
 
-    fputc(0, as86fp);           /* termination */
+    fputc(0, ofile);           /* termination */
 }
 
 static void as86_set_rsize(int size)
@@ -514,16 +506,17 @@ static void as86_set_rsize(int size)
     if (as86_reloc_size != size) {
         switch (as86_reloc_size = size) {
         case 1:
-            fputc(0x01, as86fp);
+            fputc(0x01, ofile);
             break;
         case 2:
-            fputc(0x02, as86fp);
+            fputc(0x02, ofile);
             break;
         case 4:
-            fputc(0x03, as86fp);
+            fputc(0x03, ofile);
             break;
         default:
-            error(ERR_PANIC, "bizarre relocation size %d", size);
+            nasm_error(ERR_PANIC, "bizarre relocation size %d", size);
+           break;
         }
     }
 }
@@ -534,7 +527,7 @@ static void as86_write_section(struct Section *sect, int index)
     uint32_t s;
     int32_t length;
 
-    fputc(0x20 + index, as86fp);        /* select the right section */
+    fputc(0x20 + index, ofile);        /* select the right section */
 
     saa_rewind(sect->data);
 
@@ -549,9 +542,9 @@ static void as86_write_section(struct Section *sect, int index)
             do {
                 char buf[64];
                 int32_t tmplen = (length > 64 ? 64 : length);
-                fputc(0x40 | (tmplen & 0x3F), as86fp);
+                fputc(0x40 | (tmplen & 0x3F), ofile);
                 saa_rnbytes(sect->data, buf, tmplen);
-                fwrite(buf, 1, tmplen, as86fp);
+                fwrite(buf, 1, tmplen, ofile);
                 length -= tmplen;
             } while (length > 0);
             break;
@@ -562,11 +555,11 @@ static void as86_write_section(struct Section *sect, int index)
             if (p->number == SECT_BSS)
                 p->number = SECT_DATA, p->offset += sdata.len;
             as86_set_rsize(p->bytes);
-            fputc(0x80 | (p->relative ? 0x20 : 0) | p->number, as86fp);
+            fputc(0x80 | (p->relative ? 0x20 : 0) | p->number, ofile);
             if (as86_reloc_size == 2)
-                fwriteint16_t(p->offset, as86fp);
+                fwriteint16_t(p->offset, ofile);
             else
-                fwriteint32_t(p->offset, as86fp);
+                fwriteint32_t(p->offset, ofile);
             break;
         case 2:
             /*
@@ -584,22 +577,22 @@ static void as86_write_section(struct Section *sect, int index)
                 s = 0;
             fputc(0xC0 |
                   (p->relative ? 0x20 : 0) |
-                  (p->number > 255 ? 0x04 : 0) | s, as86fp);
+                  (p->number > 255 ? 0x04 : 0) | s, ofile);
             if (p->number > 255)
-                fwriteint16_t(p->number, as86fp);
+                fwriteint16_t(p->number, ofile);
             else
-                fputc(p->number, as86fp);
+                fputc(p->number, ofile);
             switch ((int)s) {
             case 0:
                 break;
             case 1:
-                fputc(p->offset, as86fp);
+                fputc(p->offset, ofile);
                 break;
             case 2:
-                fwriteint16_t(p->offset, as86fp);
+                fwriteint16_t(p->offset, ofile);
                 break;
             case 3:
-                fwriteint32_t(p->offset, as86fp);
+                fwriteint32_t(p->offset, ofile);
                 break;
             }
             break;
@@ -618,15 +611,7 @@ static int32_t as86_segbase(int32_t segment)
     return segment;
 }
 
-static int as86_directive(char *directive, char *value, int pass)
-{
-    (void)directive;
-    (void)value;
-    (void)pass;
-    return 0;
-}
-
-static void as86_filename(char *inname, char *outname, efunc error)
+static void as86_filename(char *inname, char *outname)
 {
     char *p;
 
@@ -636,26 +621,11 @@ static void as86_filename(char *inname, char *outname, efunc error)
     } else
         strcpy(as86_module, inname);
 
-    standard_extension(inname, outname, ".o", error);
+    standard_extension(inname, outname, ".o");
 }
 
 extern macros_t as86_stdmac[];
 
-static int as86_set_info(enum geninfo type, char **val)
-{
-    (void)type;
-    (void)val;
-    return 0;
-}
-void as86_linenumber(char *name, int32_t segment, int32_t offset, int is_main,
-                     int lineno)
-{
-    (void)name;
-    (void)segment;
-    (void)offset;
-    (void)is_main;
-    (void)lineno;
-}
 struct ofmt of_as86 = {
     "Linux as86 (bin86 version 0.3) object files",
     "as86",
@@ -664,12 +634,12 @@ struct ofmt of_as86 = {
     &null_debug_form,
     as86_stdmac,
     as86_init,
-    as86_set_info,
+    null_setinfo,
     as86_out,
     as86_deflabel,
     as86_section_names,
     as86_segbase,
-    as86_directive,
+    null_directive,
     as86_filename,
     as86_cleanup
 };
index 8942acf..6f08e87 100644 (file)
@@ -92,9 +92,7 @@
 
 #ifdef OF_BIN
 
-static FILE *fp, *rf = NULL;
-static efunc error;
-static struct ofmt *my_ofmt;
+static FILE *rf = NULL;
 static void (*do_output)(void);
 
 /* Section flags keep track of which attributes the user has defined. */
@@ -278,7 +276,7 @@ static void bin_cleanup(int debuginfo)
         if (s->flags & (START_DEFINED | ALIGN_DEFINED | FOLLOWS_DEFINED)) {     /* Check for a mixture of real and virtual section attributes. */
             if (s->flags & (VSTART_DEFINED | VALIGN_DEFINED |
                            VFOLLOWS_DEFINED))
-                error(ERR_FATAL|ERR_NOFILE,
+                nasm_error(ERR_FATAL|ERR_NOFILE,
                       "cannot mix real and virtual attributes"
                       " in nobits section (%s)", s->name);
             /* Real and virtual attributes mean the same thing for nobits sections. */
@@ -349,11 +347,11 @@ static void bin_cleanup(int debuginfo)
              s && strcmp(s->name, g->follows);
              sp = &s->next, s = s->next) ;
         if (!s)
-            error(ERR_FATAL|ERR_NOFILE, "section %s follows an invalid or"
+            nasm_error(ERR_FATAL|ERR_NOFILE, "section %s follows an invalid or"
                   " unknown section (%s)", g->name, g->follows);
         if (s->next && (s->next->flags & FOLLOWS_DEFINED) &&
             !strcmp(s->name, s->next->follows))
-            error(ERR_FATAL|ERR_NOFILE, "sections %s and %s can't both follow"
+            nasm_error(ERR_FATAL|ERR_NOFILE, "sections %s and %s can't both follow"
                   " section %s", g->name, s->next->name, s->name);
         /* Find the end of the current follows group (gs). */
         for (gsp = &g->next, gs = g->next;
@@ -397,7 +395,7 @@ static void bin_cleanup(int debuginfo)
        if (sections->flags & START_DEFINED) {
             /* Make sure this section doesn't begin before the origin. */
             if (sections->start < origin)
-                error(ERR_FATAL|ERR_NOFILE, "section %s begins"
+                nasm_error(ERR_FATAL|ERR_NOFILE, "section %s begins"
                       " before program origin", sections->name);
        } else if (sections->flags & ALIGN_DEFINED) {
             sections->start = ((origin + sections->align - 1) &
@@ -454,13 +452,13 @@ static void bin_cleanup(int debuginfo)
         /* Check for section overlap. */
         if (s) {
            if (s->start < origin)
-               error(ERR_FATAL|ERR_NOFILE, "section %s beings before program origin",
+               nasm_error(ERR_FATAL|ERR_NOFILE, "section %s beings before program origin",
                      s->name);
            if (g->start > s->start)
-                error(ERR_FATAL|ERR_NOFILE, "sections %s ~ %s and %s overlap!",
+                nasm_error(ERR_FATAL|ERR_NOFILE, "sections %s ~ %s and %s overlap!",
                       gs->name, g->name, s->name);
             if (pend > s->start)
-                error(ERR_FATAL|ERR_NOFILE, "sections %s and %s overlap!",
+                nasm_error(ERR_FATAL|ERR_NOFILE, "sections %s and %s overlap!",
                       g->name, s->name);
         }
         /* Remember this section as the latest >0 length section. */
@@ -489,7 +487,7 @@ static void bin_cleanup(int debuginfo)
                 for (s = sections; s && strcmp(g->vfollows, s->name);
                      s = s->next) ;
                 if (!s)
-                    error(ERR_FATAL|ERR_NOFILE,
+                    nasm_error(ERR_FATAL|ERR_NOFILE,
                           "section %s vfollows unknown section (%s)",
                           g->name, g->vfollows);
             } else if (g->ifollows != NULL)
@@ -523,13 +521,13 @@ static void bin_cleanup(int debuginfo)
     for (h = 0, s = sections; s; s = s->next) {
         if (!(s->flags & VSTART_DEFINED)) {     /* Non-fatal errors after assembly has completed are generally a
                                                  * no-no, but we'll throw a fatal one eventually so it's ok.  */
-            error(ERR_NONFATAL, "cannot compute vstart for section %s",
+            nasm_error(ERR_NONFATAL, "cannot compute vstart for section %s",
                   s->name);
             h++;
         }
     }
     if (h)
-        error(ERR_FATAL|ERR_NOFILE, "circular vfollows path detected");
+        nasm_error(ERR_FATAL|ERR_NOFILE, "circular vfollows path detected");
 
 #ifdef DEBUG
     fprintf(stdout,
@@ -593,7 +591,6 @@ static void bin_cleanup(int debuginfo)
 
     /* Step 6: Write the section data to the output file. */
     do_output();
-    fclose(fp);                        /* Done with the output file */
 
     /* Step 7: Generate the map file. */
 
@@ -757,13 +754,13 @@ static void bin_out(int32_t segto, const void *data,
 
     if (wrt != NO_SEG) {
         wrt = NO_SEG;           /* continue to do _something_ */
-        error(ERR_NONFATAL, "WRT not supported by binary output format");
+        nasm_error(ERR_NONFATAL, "WRT not supported by binary output format");
     }
 
     /* Handle absolute-assembly (structure definitions). */
     if (segto == NO_SEG) {
         if (type != OUT_RESERVE)
-            error(ERR_NONFATAL, "attempt to assemble code in"
+            nasm_error(ERR_NONFATAL, "attempt to assemble code in"
                   " [ABSOLUTE] space");
         return;
     }
@@ -771,7 +768,7 @@ static void bin_out(int32_t segto, const void *data,
     /* Find the segment we are targeting. */
     s = find_section_by_index(segto);
     if (!s)
-        error(ERR_PANIC, "code directed to nonexistent segment?");
+        nasm_error(ERR_PANIC, "code directed to nonexistent segment?");
 
     /* "Smart" section-type adaptation code. */
     if (!(s->flags & TYPE_DEFINED)) {
@@ -782,16 +779,16 @@ static void bin_out(int32_t segto, const void *data,
     }
 
     if ((s->flags & TYPE_NOBITS) && (type != OUT_RESERVE))
-        error(ERR_WARNING, "attempt to initialize memory in a"
+        nasm_error(ERR_WARNING, "attempt to initialize memory in a"
               " nobits section: ignored");
 
     if (type == OUT_ADDRESS) {
         if (segment != NO_SEG && !find_section_by_index(segment)) {
             if (segment % 2)
-                error(ERR_NONFATAL, "binary output format does not support"
+                nasm_error(ERR_NONFATAL, "binary output format does not support"
                       " segment base references");
             else
-                error(ERR_NONFATAL, "binary output format does not support"
+                nasm_error(ERR_NONFATAL, "binary output format does not support"
                       " external references");
             segment = NO_SEG;
         }
@@ -809,7 +806,7 @@ static void bin_out(int32_t segto, const void *data,
         s->length += size;
     } else if (type == OUT_RESERVE) {
         if (s->flags & TYPE_PROGBITS) {
-            error(ERR_WARNING, "uninitialized space declared in"
+            nasm_error(ERR_WARNING, "uninitialized space declared in"
                   " %s section: zeroing", s->name);
             saa_wbytes(s->contents, NULL, size);
         }
@@ -820,10 +817,10 @@ static void bin_out(int32_t segto, const void *data,
        size = realsize(type, size);
         if (segment != NO_SEG && !find_section_by_index(segment)) {
             if (segment % 2)
-                error(ERR_NONFATAL, "binary output format does not support"
+                nasm_error(ERR_NONFATAL, "binary output format does not support"
                       " segment base references");
             else
-                error(ERR_NONFATAL, "binary output format does not support"
+                nasm_error(ERR_NONFATAL, "binary output format does not support"
                       " external references");
             segment = NO_SEG;
         }
@@ -844,12 +841,12 @@ static void bin_deflabel(char *name, int32_t segment, int64_t offset,
     (void)offset;               /* Don't warn that this parameter is unused */
 
     if (special)
-        error(ERR_NONFATAL, "binary format does not support any"
+        nasm_error(ERR_NONFATAL, "binary format does not support any"
               " special symbol types");
     else if (name[0] == '.' && name[1] == '.' && name[2] != '@')
-        error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
+        nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
     else if (is_global == 2)
-        error(ERR_NONFATAL, "binary output format does not support common"
+        nasm_error(ERR_NONFATAL, "binary output format does not support common"
               " variables");
     else {
         struct Section *s;
@@ -965,14 +962,14 @@ static int bin_read_attribute(char **line, int *attribute,
                         break;
                 }
                 if (!**line) {
-                    error(ERR_NONFATAL,
+                    nasm_error(ERR_NONFATAL,
                           "invalid syntax in `section' directive");
                     return -1;
                 }
                 ++(*line);
             }
             if (!**line) {
-                error(ERR_NONFATAL, "expecting `)'");
+                nasm_error(ERR_NONFATAL, "expecting `)'");
                 return -1;
             }
         }
@@ -981,7 +978,7 @@ static int bin_read_attribute(char **line, int *attribute,
 
     /* Check for no value given. */
     if (!*exp) {
-        error(ERR_WARNING, "No value given to attribute in"
+        nasm_error(ERR_WARNING, "No value given to attribute in"
               " `section' directive");
         return -1;
     }
@@ -990,15 +987,15 @@ static int bin_read_attribute(char **line, int *attribute,
     stdscan_reset();
     stdscan_bufptr = exp;
     tokval.t_type = TOKEN_INVALID;
-    e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL);
+    e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
     if (e) {
         if (!is_really_simple(e)) {
-            error(ERR_NONFATAL, "section attribute value must be"
+            nasm_error(ERR_NONFATAL, "section attribute value must be"
                   " a critical expression");
             return -1;
         }
     } else {
-        error(ERR_NONFATAL, "Invalid attribute value"
+        nasm_error(ERR_NONFATAL, "Invalid attribute value"
               " specified in `section' directive.");
         return -1;
     }
@@ -1029,7 +1026,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
                     *astring = '\0';
                     astring++;
                 }
-                error(ERR_WARNING, "ignoring unknown section attribute:"
+                nasm_error(ERR_WARNING, "ignoring unknown section attribute:"
                       " \"%s\"", p);
             }
             continue;
@@ -1039,7 +1036,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
         case ATTRIB_NOBITS:
             if ((sec->flags & TYPE_DEFINED)
                 && (sec->flags & TYPE_PROGBITS))
-                error(ERR_NONFATAL,
+                nasm_error(ERR_NONFATAL,
                       "attempt to change section type"
                       " from progbits to nobits");
             else
@@ -1049,7 +1046,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
             /* Handle progbits attribute. */
         case ATTRIB_PROGBITS:
             if ((sec->flags & TYPE_DEFINED) && (sec->flags & TYPE_NOBITS))
-                error(ERR_NONFATAL, "attempt to change section type"
+                nasm_error(ERR_NONFATAL, "attempt to change section type"
                       " from nobits to progbits");
             else
                 sec->flags |= TYPE_DEFINED | TYPE_PROGBITS;
@@ -1058,11 +1055,11 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
             /* Handle align attribute. */
         case ATTRIB_ALIGN:
             if (!format_mode && (!strcmp(sec->name, ".text")))
-                error(ERR_NONFATAL, "cannot specify an alignment"
+                nasm_error(ERR_NONFATAL, "cannot specify an alignment"
                       " to the .text section");
             else {
                 if (!value || ((value - 1) & value))
-                    error(ERR_NONFATAL, "argument to `align' is not a"
+                    nasm_error(ERR_NONFATAL, "argument to `align' is not a"
                           " power of two");
                 else {          /* Alignment is already satisfied if the previous
                                  * align value is greater. */
@@ -1073,7 +1070,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
                     /* Don't allow a conflicting align value. */
                     if ((sec->flags & START_DEFINED)
                         && (sec->start & (value - 1)))
-                        error(ERR_NONFATAL,
+                        nasm_error(ERR_NONFATAL,
                               "`align' value conflicts "
                               "with section start address");
                     else {
@@ -1087,7 +1084,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
             /* Handle valign attribute. */
         case ATTRIB_VALIGN:
             if (!value || ((value - 1) & value))
-                error(ERR_NONFATAL, "argument to `valign' is not a"
+                nasm_error(ERR_NONFATAL, "argument to `valign' is not a"
                       " power of two");
             else {              /* Alignment is already satisfied if the previous
                                  * align value is greater. */
@@ -1097,7 +1094,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
                 /* Don't allow a conflicting valign value. */
                 if ((sec->flags & VSTART_DEFINED)
                     && (sec->vstart & (value - 1)))
-                    error(ERR_NONFATAL,
+                    nasm_error(ERR_NONFATAL,
                           "`valign' value conflicts "
                           "with `vstart' address");
                 else {
@@ -1110,16 +1107,16 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
             /* Handle start attribute. */
         case ATTRIB_START:
             if (sec->flags & FOLLOWS_DEFINED)
-                error(ERR_NONFATAL, "cannot combine `start' and `follows'"
+                nasm_error(ERR_NONFATAL, "cannot combine `start' and `follows'"
                       " section attributes");
             else if ((sec->flags & START_DEFINED) && (value != sec->start))
-                error(ERR_NONFATAL, "section start address redefined");
+                nasm_error(ERR_NONFATAL, "section start address redefined");
             else {
                 sec->start = value;
                 sec->flags |= START_DEFINED;
                 if (sec->flags & ALIGN_DEFINED) {
                     if (sec->start & (sec->align - 1))
-                        error(ERR_NONFATAL, "`start' address conflicts"
+                        nasm_error(ERR_NONFATAL, "`start' address conflicts"
                               " with section alignment");
                     sec->flags ^= ALIGN_DEFINED;
                 }
@@ -1129,12 +1126,12 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
             /* Handle vstart attribute. */
         case ATTRIB_VSTART:
             if (sec->flags & VFOLLOWS_DEFINED)
-                error(ERR_NONFATAL,
+                nasm_error(ERR_NONFATAL,
                       "cannot combine `vstart' and `vfollows'"
                       " section attributes");
             else if ((sec->flags & VSTART_DEFINED)
                      && (value != sec->vstart))
-                error(ERR_NONFATAL,
+                nasm_error(ERR_NONFATAL,
                       "section virtual start address"
                       " (vstart) redefined");
             else {
@@ -1142,7 +1139,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
                 sec->flags |= VSTART_DEFINED;
                 if (sec->flags & VALIGN_DEFINED) {
                     if (sec->vstart & (sec->valign - 1))
-                        error(ERR_NONFATAL, "`vstart' address conflicts"
+                        nasm_error(ERR_NONFATAL, "`vstart' address conflicts"
                               " with `valign' value");
                     sec->flags ^= VALIGN_DEFINED;
                 }
@@ -1154,12 +1151,12 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
             p = astring;
             astring += strcspn(astring, " \t");
             if (astring == p)
-                error(ERR_NONFATAL, "expecting section name for `follows'"
+                nasm_error(ERR_NONFATAL, "expecting section name for `follows'"
                       " attribute");
             else {
                 *(astring++) = '\0';
                 if (sec->flags & START_DEFINED)
-                    error(ERR_NONFATAL,
+                    nasm_error(ERR_NONFATAL,
                           "cannot combine `start' and `follows'"
                           " section attributes");
                 sec->follows = nasm_strdup(p);
@@ -1170,14 +1167,14 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
             /* Handle vfollows attribute. */
         case ATTRIB_VFOLLOWS:
             if (sec->flags & VSTART_DEFINED)
-                error(ERR_NONFATAL,
+                nasm_error(ERR_NONFATAL,
                       "cannot combine `vstart' and `vfollows'"
                       " section attributes");
             else {
                 p = astring;
                 astring += strcspn(astring, " \t");
                 if (astring == p)
-                    error(ERR_NONFATAL,
+                    nasm_error(ERR_NONFATAL,
                           "expecting section name for `vfollows'"
                           " attribute");
                 else {
@@ -1208,13 +1205,11 @@ static void bin_define_section_labels(void)
 
         /* section.<name>.start */
         strcpy(label_name + base_len, ".start");
-        define_label(label_name, sec->start_index, 0L,
-                     NULL, 0, 0, my_ofmt, error);
+        define_label(label_name, sec->start_index, 0L, NULL, 0, 0);
 
         /* section.<name>.vstart */
         strcpy(label_name + base_len, ".vstart");
-        define_label(label_name, sec->vstart_index, 0L,
-                     NULL, 0, 0, my_ofmt, error);
+        define_label(label_name, sec->vstart_index, 0L, NULL, 0, 0);
 
         nasm_free(label_name);
     }
@@ -1264,7 +1259,7 @@ static int32_t bin_secname(char *name, int pass, int *bits)
             sec->flags |= TYPE_DEFINED | TYPE_NOBITS;
             sec->ifollows = NULL;
         } else if (!format_mode) {
-            error(ERR_NONFATAL, "section name must be "
+            nasm_error(ERR_NONFATAL, "section name must be "
                   ".text, .data, or .bss");
             return current_section;
         }
@@ -1287,10 +1282,11 @@ static int32_t bin_secname(char *name, int pass, int *bits)
     return current_section;
 }
 
-static int bin_directive(char *directive, char *args, int pass)
+static int bin_directive(enum directives directive, char *args, int pass)
 {
-    /* Handle ORG directive */
-    if (!nasm_stricmp(directive, "org")) {
+    switch (directive) {
+    case D_ORG:
+    {
         struct tokenval tokval;
         uint64_t value;
         expr *e;
@@ -1298,32 +1294,32 @@ static int bin_directive(char *directive, char *args, int pass)
         stdscan_reset();
         stdscan_bufptr = args;
         tokval.t_type = TOKEN_INVALID;
-        e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL);
+        e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
         if (e) {
             if (!is_really_simple(e))
-                error(ERR_NONFATAL, "org value must be a critical"
+                nasm_error(ERR_NONFATAL, "org value must be a critical"
                       " expression");
             else {
                 value = reloc_value(e);
                 /* Check for ORG redefinition. */
                 if (origin_defined && (value != origin))
-                    error(ERR_NONFATAL, "program origin redefined");
+                    nasm_error(ERR_NONFATAL, "program origin redefined");
                 else {
                     origin = value;
                     origin_defined = 1;
                 }
             }
         } else
-            error(ERR_NONFATAL, "No or invalid offset specified"
+            nasm_error(ERR_NONFATAL, "No or invalid offset specified"
                   " in ORG directive.");
         return 1;
     }
-
+    case D_MAP:
+    {
     /* The 'map' directive allows the user to generate section
      * and symbol information to stdout, stderr, or to a file. */
-    else if (format_mode && !nasm_stricmp(directive, "map")) {
-        char *p;
-
+       char *p;
+       
         if (pass != 1)
             return 1;
         args += strspn(args, " \t");
@@ -1351,14 +1347,14 @@ static int bin_directive(char *directive, char *args, int pass)
                 else {          /* Must be a filename. */
                     rf = fopen(p, "wt");
                     if (!rf) {
-                        error(ERR_WARNING, "unable to open map file `%s'",
+                        nasm_error(ERR_WARNING, "unable to open map file `%s'",
                               p);
                         map_control = 0;
                         return 1;
                     }
                 }
             } else
-                error(ERR_WARNING, "map file already specified");
+                nasm_error(ERR_WARNING, "map file already specified");
         }
         if (map_control == 0)
             map_control |= MAP_ORIGIN | MAP_SUMMARY;
@@ -1366,26 +1362,28 @@ static int bin_directive(char *directive, char *args, int pass)
             rf = stdout;
         return 1;
     }
-    return 0;
+    default:
+       return 0;
+    }
 }
 
-static void bin_filename(char *inname, char *outname, efunc error)
+static void bin_filename(char *inname, char *outname)
 {
-    standard_extension(inname, outname, "", error);
+    standard_extension(inname, outname, "");
     infile = inname;
     outfile = outname;
 }
 
-static void ith_filename(char *inname, char *outname, efunc error)
+static void ith_filename(char *inname, char *outname)
 {
-    standard_extension(inname, outname, ".ith", error);
+    standard_extension(inname, outname, ".ith");
     infile = inname;
     outfile = outname;
 }
 
-static void srec_filename(char *inname, char *outname, efunc error)
+static void srec_filename(char *inname, char *outname)
 {
-    standard_extension(inname, outname, ".srec", error);
+    standard_extension(inname, outname, ".srec");
     infile = inname;
     outfile = outname;
 }
@@ -1402,41 +1400,32 @@ static int bin_set_info(enum geninfo type, char **val)
     return 0;
 }
 
-static void binfmt_init(FILE *afp, efunc errfunc, ldfunc ldef, evalfunc eval);
 struct ofmt of_bin, of_ith, of_srec;
+static void binfmt_init(void);
 static void do_output_bin(void);
 static void do_output_ith(void);
 static void do_output_srec(void);
 
-static void bin_init(FILE *afp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void bin_init(void)
 {
-    my_ofmt   = &of_bin;
     do_output = do_output_bin;
-    binfmt_init(afp, errfunc, ldef, eval);
+    binfmt_init();
 }
 
-static void ith_init(FILE *afp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void ith_init(void)
 {
-    my_ofmt   = &of_ith;
     do_output = do_output_ith;
-    binfmt_init(afp, errfunc, ldef, eval);
+    binfmt_init();
 }    
     
-static void srec_init(FILE *afp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void srec_init(void)
 {
-    my_ofmt   = &of_srec;
     do_output = do_output_srec;
-    binfmt_init(afp, errfunc, ldef, eval);
+    binfmt_init();
 }
 
-static void binfmt_init(FILE *afp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void binfmt_init(void)
 {
-    fp = afp;
-    error = errfunc;
-
-    (void)eval;                 /* Don't warn that this parameter is unused. */
-    (void)ldef;                 /* Placate optimizers. */
-
     maxbits = 64;               /* Support 64-bit Segments */
     relocs = NULL;
     reloctail = &relocs;
@@ -1478,10 +1467,10 @@ static void do_output_bin(void)
 
         /* Pad the space between sections. */
        nasm_assert(addr <= s->start);
-       fwritezero(s->start - addr, fp);
+       fwritezero(s->start - addr, ofile);
 
         /* Write the section to the output file. */
-       saa_fpwrite(s->contents, fp);
+       saa_fpwrite(s->contents, ofile);
         
        /* Keep track of the current file position */
        addr = s->start + s->length;
@@ -1509,7 +1498,7 @@ static int write_ith_record(unsigned int len, uint16_t addr,
        p += sprintf(p, "%02X", dptr[i]);
     p += sprintf(p, "%02X\n", csum);
 
-    if (fwrite(buf, 1, p-buf, fp) != (size_t)(p-buf))
+    if (fwrite(buf, 1, p-buf, ofile) != (size_t)(p-buf))
        return -1;
 
     return 0;
@@ -1597,7 +1586,7 @@ static int write_srecord(unsigned int len,  unsigned int alen,
        p += sprintf(p, "%02X", dptr[i]);
     p += sprintf(p, "%02X\n", csum);
 
-    if (fwrite(buf, 1, p-buf, fp) != (size_t)(p-buf))
+    if (fwrite(buf, 1, p-buf, ofile) != (size_t)(p-buf))
        return -1;
 
     return 0;
index b27cc94..4277744 100644 (file)
@@ -49,6 +49,7 @@
 #include "nasmlib.h"
 #include "saa.h"
 #include "raa.h"
+#include "eval.h"
 #include "output/outform.h"
 #include "output/outlib.h"
 
@@ -135,8 +136,6 @@ struct Symbol {
     int32_t namlen;            /* full name length */
 };
 
-static FILE *coffp;
-static efunc error;
 static char coff_infile[FILENAME_MAX];
 
 struct Section {
@@ -172,7 +171,7 @@ static struct RAA *bsym, *symval;
 static struct SAA *strs;
 static uint32_t strslen;
 
-static void coff_gen_init(FILE *, efunc);
+static void coff_gen_init(void);
 static void coff_sect_write(struct Section *, const uint8_t *,
                             uint32_t);
 static void coff_write(void);
@@ -180,43 +179,32 @@ static void coff_section_header(char *, int32_t, int32_t, int32_t, int32_t, int,
 static void coff_write_relocs(struct Section *);
 static void coff_write_symbols(void);
 
-static void coff_win32_init(FILE * fp, efunc errfunc,
-                            ldfunc ldef, evalfunc eval)
+static void coff_win32_init(void)
 {
-    win32 = true; win64 = false;
-    (void)ldef;                 /* placate optimizers */
-    (void)eval;
-    coff_gen_init(fp, errfunc);
+    win32 = true;
+    win64 = false;
+    coff_gen_init();
 }
 
-static void coff_win64_init(FILE * fp, efunc errfunc,
-                            ldfunc ldef, evalfunc eval)
+static void coff_win64_init(void)
 {
-    extern struct ofmt of_win64;
-
     maxbits = 64;
-    win32 = false; win64 = true;
-    (void)ldef;                 /* placate optimizers */
-    (void)eval;
-    coff_gen_init(fp, errfunc);
+    win32 = false;
+    win64 = true;
+    coff_gen_init();
     imagebase_sect = seg_alloc()+1;
-    ldef(WRT_IMAGEBASE,imagebase_sect,0,NULL,false,false,&of_win64,errfunc);
+    define_label(WRT_IMAGEBASE, imagebase_sect, 0, NULL, false, false);
 }
 
-static void coff_std_init(FILE * fp, efunc errfunc, ldfunc ldef,
-                          evalfunc eval)
+static void coff_std_init(void)
 {
     win32 = win64 = false;
-    (void)ldef;                 /* placate optimizers */
-    (void)eval;
-    coff_gen_init(fp, errfunc);
+    coff_gen_init();
 }
 
-static void coff_gen_init(FILE * fp, efunc errfunc)
+static void coff_gen_init(void)
 {
 
-    coffp = fp;
-    error = errfunc;
     sects = NULL;
     nsects = sectlen = 0;
     syms = saa_init(sizeof(struct Symbol));
@@ -236,7 +224,6 @@ static void coff_cleanup(int debuginfo)
     (void)debuginfo;
 
     coff_write();
-    fclose(coffp);
     for (i = 0; i < nsects; i++) {
         if (sects[i]->data)
             saa_free(sects[i]->data);
@@ -310,7 +297,7 @@ static int32_t coff_section_names(char *name, int pass, int *bits)
     if (*p)
         *p++ = '\0';
     if (strlen(name) > 8) {
-        error(ERR_WARNING, "COFF section names limited to 8 characters:"
+        nasm_error(ERR_WARNING, "COFF section names limited to 8 characters:"
               " truncating");
         name[8] = '\0';
     }
@@ -336,7 +323,7 @@ static int32_t coff_section_names(char *name, int pass, int *bits)
                 flags = RDATA_FLAGS;
             else {
                 flags = DATA_FLAGS;     /* gotta do something */
-                error(ERR_NONFATAL, "standard COFF does not support"
+                nasm_error(ERR_NONFATAL, "standard COFF does not support"
                       " read-only data sections");
             }
         } else if (!nasm_stricmp(q, "bss")) {
@@ -346,24 +333,24 @@ static int32_t coff_section_names(char *name, int pass, int *bits)
                 flags = INFO_FLAGS;
             else {
                 flags = DATA_FLAGS;     /* gotta do something */
-                error(ERR_NONFATAL, "standard COFF does not support"
+                nasm_error(ERR_NONFATAL, "standard COFF does not support"
                       " informational sections");
             }
         } else if (!nasm_strnicmp(q, "align=", 6)) {
             if (!(win32 | win64))
-                error(ERR_NONFATAL, "standard COFF does not support"
+                nasm_error(ERR_NONFATAL, "standard COFF does not support"
                       " section alignment specification");
             else {
                 if (q[6 + strspn(q + 6, "0123456789")])
-                    error(ERR_NONFATAL,
+                    nasm_error(ERR_NONFATAL,
                           "argument to `align' is not numeric");
                 else {
                     unsigned int align = atoi(q + 6);
                     if (!align || ((align - 1) & align))
-                        error(ERR_NONFATAL, "argument to `align' is not a"
+                        nasm_error(ERR_NONFATAL, "argument to `align' is not a"
                               " power of two");
                     else if (align > 64)
-                        error(ERR_NONFATAL, "Win32 cannot align sections"
+                        nasm_error(ERR_NONFATAL, "Win32 cannot align sections"
                               " to better than 64-byte boundaries");
                     else {
                         align_and = ~0x00F00000L;
@@ -405,7 +392,7 @@ static int32_t coff_section_names(char *name, int pass, int *bits)
         sects[i]->flags |= align_or;
     } else if (pass == 1) {
         if (flags)
-            error(ERR_WARNING, "section attributes ignored on"
+            nasm_error(ERR_WARNING, "section attributes ignored on"
                   " redeclaration of section `%s'", name);
     }
 
@@ -419,12 +406,12 @@ static void coff_deflabel(char *name, int32_t segment, int64_t offset,
     struct Symbol *sym;
 
     if (special)
-        error(ERR_NONFATAL, "COFF format does not support any"
+        nasm_error(ERR_NONFATAL, "COFF format does not support any"
               " special symbol types");
 
     if (name[0] == '.' && name[1] == '.' && name[2] != '@') {
        if (strcmp(name,WRT_IMAGEBASE))
-            error(ERR_NONFATAL, "unrecognized special symbol `%s'", name);
+            nasm_error(ERR_NONFATAL, "unrecognized special symbol `%s'", name);
         return;
     }
 
@@ -522,7 +509,7 @@ static void coff_out(int32_t segto, const void *data,
 
     if (wrt != NO_SEG && !win64) {
         wrt = NO_SEG;           /* continue to do _something_ */
-        error(ERR_NONFATAL, "WRT not supported by COFF output formats");
+        nasm_error(ERR_NONFATAL, "WRT not supported by COFF output formats");
     }
 
     /*
@@ -530,7 +517,7 @@ static void coff_out(int32_t segto, const void *data,
      */
     if (segto == NO_SEG) {
         if (type != OUT_RESERVE)
-            error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
+            nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
                   " space");
         return;
     }
@@ -544,7 +531,7 @@ static void coff_out(int32_t segto, const void *data,
     if (!s) {
         int tempint;            /* ignored */
         if (segto != coff_section_names(".text", 2, &tempint))
-            error(ERR_PANIC, "strange segment conditions in COFF driver");
+            nasm_error(ERR_PANIC, "strange segment conditions in COFF driver");
         else
             s = sects[nsects - 1];
     }
@@ -555,7 +542,7 @@ static void coff_out(int32_t segto, const void *data,
        wrt = imagebase_sect;
 
     if (!s->data && type != OUT_RESERVE) {
-        error(ERR_WARNING, "attempt to initialize memory in"
+        nasm_error(ERR_WARNING, "attempt to initialize memory in"
               " BSS section `%s': ignored", s->name);
         s->len += realsize(type, size);
         return;
@@ -563,28 +550,28 @@ static void coff_out(int32_t segto, const void *data,
 
     if (type == OUT_RESERVE) {
         if (s->data) {
-            error(ERR_WARNING, "uninitialised space declared in"
+            nasm_error(ERR_WARNING, "uninitialised space declared in"
                   " non-BSS section `%s': zeroing", s->name);
             coff_sect_write(s, NULL, size);
         } else
             s->len += size;
     } else if (type == OUT_RAWDATA) {
         if (segment != NO_SEG)
-            error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
+            nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
         coff_sect_write(s, data, size);
     } else if (type == OUT_ADDRESS) {
         if (!(win64)) {
             if (size != 4 && (segment != NO_SEG || wrt != NO_SEG))
-                error(ERR_NONFATAL, "COFF format does not support non-32-bit"
+                nasm_error(ERR_NONFATAL, "COFF format does not support non-32-bit"
                       " relocations");
             else {
                 int32_t fix = 0;
                 if (segment != NO_SEG || wrt != NO_SEG) {
                     if (wrt != NO_SEG) {
-                        error(ERR_NONFATAL, "COFF format does not support"
+                        nasm_error(ERR_NONFATAL, "COFF format does not support"
                               " WRT types");
                     } else if (segment % 2) {
-                        error(ERR_NONFATAL, "COFF format does not support"
+                        nasm_error(ERR_NONFATAL, "COFF format does not support"
                               " segment base references");
                     } else
                         fix = coff_add_reloc(s, segment, IMAGE_REL_I386_DIR32);
@@ -598,7 +585,7 @@ static void coff_out(int32_t segto, const void *data,
             p = mydata;
             if (size == 8) {
                if (wrt == imagebase_sect) {
-                   error(ERR_NONFATAL, "operand size mismatch: 'wrt "
+                   nasm_error(ERR_NONFATAL, "operand size mismatch: 'wrt "
                        WRT_IMAGEBASE "' is a 32-bit operand");
                }
                 fix = coff_add_reloc(s, segment, IMAGE_REL_AMD64_ADDR64);
@@ -613,18 +600,18 @@ static void coff_out(int32_t segto, const void *data,
             }
         }
     } else if (type == OUT_REL2ADR) {
-        error(ERR_NONFATAL, "COFF format does not support 16-bit"
+        nasm_error(ERR_NONFATAL, "COFF format does not support 16-bit"
               " relocations");
     } else if (type == OUT_REL4ADR) {
         if (segment == segto && !(win64))  /* Acceptable for RIP-relative */
-            error(ERR_PANIC, "intra-segment OUT_REL4ADR");
+            nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR");
         else if (segment == NO_SEG && win32)
-            error(ERR_NONFATAL, "Win32 COFF does not correctly support"
+            nasm_error(ERR_NONFATAL, "Win32 COFF does not correctly support"
                   " relative references to absolute addresses");
         else {
             int32_t fix = 0;
             if (segment != NO_SEG && segment % 2) {
-                error(ERR_NONFATAL, "COFF format does not support"
+                nasm_error(ERR_NONFATAL, "COFF format does not support"
                       " segment base references");
             } else
                 fix = coff_add_reloc(s, segment,
@@ -717,9 +704,11 @@ void BuildExportTable(void)
     Exports = NULL;
 }
 
-static int coff_directives(char *directive, char *value, int pass)
+static int coff_directives(enum directives directive, char *value, int pass)
 {
-    if (!strcmp(directive, "export")) {
+    switch (directive) {
+    case D_EXPORT:
+    {
         char *q, *name;
 
         if (pass == 2)
@@ -734,18 +723,24 @@ static int coff_directives(char *directive, char *value, int pass)
         }
 
         if (!*name) {
-            error(ERR_NONFATAL, "`export' directive requires export name");
+            nasm_error(ERR_NONFATAL, "`export' directive requires export name");
             return 1;
         }
         if (*q) {
-            error(ERR_NONFATAL, "unrecognized export qualifier `%s'", q);
+            nasm_error(ERR_NONFATAL, "unrecognized export qualifier `%s'", q);
             return 1;
         }
         AddExport(name);
         return 1;
-    } else if (win32 && !strcmp(directive,"safeseh")) {
+    }
+    case D_SAFESEH:
+    {
        static int sxseg=-1;
        int i;
+
+       if (!win32)             /* Only applicable for -f win32 */
+           return 0;
+
        if (sxseg==-1)
        {   for (i = 0; i < nsects; i++)
                if (!strcmp(".sxdata",sects[i]->name))
@@ -788,13 +783,15 @@ static int coff_directives(char *directive, char *value, int pass)
                }
            }
            if (n == nsyms) {
-               error(ERR_NONFATAL,
+               nasm_error(ERR_NONFATAL,
                      "`safeseh' directive requires valid symbol");
            }
        }
        return 1;
     }
-    return 0;
+    default:
+       return 0;
+    }
 }
 
 static void coff_write(void)
@@ -840,16 +837,16 @@ static void coff_write(void)
      * Output the COFF header.
      */
     if (win64)
-        fwriteint16_t(0x8664, coffp);  /* MACHINE_x86-64 */
+        fwriteint16_t(0x8664, ofile);  /* MACHINE_x86-64 */
     else
-        fwriteint16_t(0x014C, coffp);  /* MACHINE_i386 */
-    fwriteint16_t(nsects, coffp); /* number of sections */
-    fwriteint32_t(time(NULL), coffp);      /* time stamp */
-    fwriteint32_t(sympos, coffp);
-    fwriteint32_t(nsyms + initsym, coffp);
-    fwriteint16_t(0, coffp);      /* no optional header */
+        fwriteint16_t(0x014C, ofile);  /* MACHINE_i386 */
+    fwriteint16_t(nsects, ofile); /* number of sections */
+    fwriteint32_t(time(NULL), ofile);      /* time stamp */
+    fwriteint32_t(sympos, ofile);
+    fwriteint32_t(nsyms + initsym, ofile);
+    fwriteint16_t(0, ofile);      /* no optional header */
     /* Flags: 32-bit, no line numbers. Win32 doesn't even bother with them. */
-    fwriteint16_t((win32 | win64) ? 0 : 0x104, coffp);
+    fwriteint16_t((win32 | win64) ? 0 : 0x104, ofile);
 
     /*
      * Output the section headers.
@@ -867,7 +864,7 @@ static void coff_write(void)
      */
     for (i = 0; i < nsects; i++)
         if (sects[i]->data) {
-            saa_fpwrite(sects[i]->data, coffp);
+            saa_fpwrite(sects[i]->data, ofile);
             coff_write_relocs(sects[i]);
         }
 
@@ -875,8 +872,8 @@ static void coff_write(void)
      * Output the symbol and string tables.
      */
     coff_write_symbols();
-    fwriteint32_t(strslen + 4, coffp);     /* length includes length count */
-    saa_fpwrite(strs, coffp);
+    fwriteint32_t(strslen + 4, ofile);     /* length includes length count */
+    saa_fpwrite(strs, ofile);
 }
 
 static void coff_section_header(char *name, int32_t vsize,
@@ -889,16 +886,16 @@ static void coff_section_header(char *name, int32_t vsize,
 
     memset(padname, 0, 8);
     strncpy(padname, name, 8);
-    fwrite(padname, 8, 1, coffp);
-    fwriteint32_t(0, coffp);   /* Virtual size field - set to 0 or vsize */
-    fwriteint32_t(0L, coffp);      /* RVA/offset - we ignore */
-    fwriteint32_t(datalen, coffp);
-    fwriteint32_t(datapos, coffp);
-    fwriteint32_t(relpos, coffp);
-    fwriteint32_t(0L, coffp);      /* no line numbers - we don't do 'em */
-    fwriteint16_t(nrelocs, coffp);
-    fwriteint16_t(0, coffp);      /* again, no line numbers */
-    fwriteint32_t(flags, coffp);
+    fwrite(padname, 8, 1, ofile);
+    fwriteint32_t(0, ofile);   /* Virtual size field - set to 0 or vsize */
+    fwriteint32_t(0L, ofile);      /* RVA/offset - we ignore */
+    fwriteint32_t(datalen, ofile);
+    fwriteint32_t(datapos, ofile);
+    fwriteint32_t(relpos, ofile);
+    fwriteint32_t(0L, ofile);      /* no line numbers - we don't do 'em */
+    fwriteint16_t(nrelocs, ofile);
+    fwriteint16_t(0, ofile);      /* again, no line numbers */
+    fwriteint32_t(flags, ofile);
 }
 
 static void coff_write_relocs(struct Section *s)
@@ -906,12 +903,12 @@ static void coff_write_relocs(struct Section *s)
     struct Reloc *r;
 
     for (r = s->head; r; r = r->next) {
-        fwriteint32_t(r->address, coffp);
+        fwriteint32_t(r->address, ofile);
         fwriteint32_t(r->symbol + (r->symbase == REAL_SYMBOLS ? initsym :
                                 r->symbase == ABS_SYMBOL ? initsym - 1 :
                                 r->symbase == SECT_SYMBOLS ? 2 : 0),
-                   coffp);
-       fwriteint16_t(r->type, coffp);
+                   ofile);
+       fwriteint16_t(r->type, ofile);
     }
 }
 
@@ -923,16 +920,16 @@ static void coff_symbol(char *name, int32_t strpos, int32_t value,
     if (name) {
         memset(padname, 0, 8);
         strncpy(padname, name, 8);
-        fwrite(padname, 8, 1, coffp);
+        fwrite(padname, 8, 1, ofile);
     } else {
-        fwriteint32_t(0, coffp);
-        fwriteint32_t(strpos, coffp);
+        fwriteint32_t(0, ofile);
+        fwriteint32_t(strpos, ofile);
     }
-    fwriteint32_t(value, coffp);
-    fwriteint16_t(section, coffp);
-    fwriteint16_t(type, coffp);
-    fputc(storageclass, coffp);
-    fputc(aux, coffp);
+    fwriteint32_t(value, ofile);
+    fwriteint16_t(section, ofile);
+    fwriteint16_t(type, ofile);
+    fputc(storageclass, ofile);
+    fputc(aux, ofile);
 }
 
 static void coff_write_symbols(void)
@@ -946,7 +943,7 @@ static void coff_write_symbols(void)
     coff_symbol(".file", 0L, 0L, -2, 0, 0x67, 1);
     memset(filename, 0, 18);
     strncpy(filename, coff_infile, 18);
-    fwrite(filename, 18, 1, coffp);
+    fwrite(filename, 18, 1, ofile);
 
     /*
      * The section records, with their auxiliaries.
@@ -955,9 +952,9 @@ static void coff_write_symbols(void)
 
     for (i = 0; i < (uint32_t) nsects; i++) {
         coff_symbol(sects[i]->name, 0L, 0L, i + 1, 0, 3, 1);
-        fwriteint32_t(sects[i]->len, coffp);
-        fwriteint16_t(sects[i]->nrelocs, coffp);
-        fwrite(filename, 12, 1, coffp);
+        fwriteint32_t(sects[i]->len, ofile);
+        fwriteint16_t(sects[i]->nrelocs, ofile);
+        fwrite(filename, 12, 1, ofile);
     }
 
     /*
@@ -982,16 +979,16 @@ static int32_t coff_segbase(int32_t segment)
     return segment;
 }
 
-static void coff_std_filename(char *inname, char *outname, efunc error)
+static void coff_std_filename(char *inname, char *outname)
 {
     strcpy(coff_infile, inname);
-    standard_extension(inname, outname, ".o", error);
+    standard_extension(inname, outname, ".o");
 }
 
-static void coff_win32_filename(char *inname, char *outname, efunc error)
+static void coff_win32_filename(char *inname, char *outname)
 {
     strcpy(coff_infile, inname);
-    standard_extension(inname, outname, ".obj", error);
+    standard_extension(inname, outname, ".obj");
 }
 
 extern macros_t coff_stdmac[];
index 1ee16ea..891bc17 100644 (file)
@@ -56,19 +56,11 @@ struct Section {
     char *name;
 } *dbgsect;
 
-FILE *dbgf;
-efunc dbgef;
-
 struct ofmt of_dbg;
-static void dbg_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void dbg_init(void)
 {
-    (void)eval;
-
-    dbgf = fp;
-    dbgef = errfunc;
     dbgsect = NULL;
-    (void)ldef;
-    fprintf(fp, "NASM Output format debug dump\n");
+    fprintf(ofile, "NASM Output format debug dump\n");
 }
 
 static void dbg_cleanup(int debuginfo)
@@ -81,7 +73,6 @@ static void dbg_cleanup(int debuginfo)
         nasm_free(tmp->name);
         nasm_free(tmp);
     }
-    fclose(dbgf);
 }
 
 static int32_t dbg_section_names(char *name, int pass, int *bits)
@@ -95,7 +86,7 @@ static int32_t dbg_section_names(char *name, int pass, int *bits)
         *bits = 16;
 
     if (!name)
-        fprintf(dbgf, "section_name on init: returning %d\n",
+        fprintf(ofile, "section_name on init: returning %d\n",
                 seg = seg_alloc());
     else {
         int n = strcspn(name, " \t");
@@ -113,7 +104,7 @@ static int32_t dbg_section_names(char *name, int pass, int *bits)
             s->number = seg = seg_alloc();
             s->next = dbgsect;
             dbgsect = s;
-            fprintf(dbgf, "section_name %s (pass %d): returning %d\n",
+            fprintf(ofile, "section_name %s (pass %d): returning %d\n",
                     name, pass, seg);
         }
     }
@@ -123,7 +114,7 @@ static int32_t dbg_section_names(char *name, int pass, int *bits)
 static void dbg_deflabel(char *name, int32_t segment, int64_t offset,
                          int is_global, char *special)
 {
-    fprintf(dbgf, "deflabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n",
+    fprintf(ofile, "deflabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n",
             name, segment, offset,
             is_global == 2 ? "common" : is_global ? "global" : "local",
             is_global, special ? ": " : "", special);
@@ -136,41 +127,41 @@ static void dbg_out(int32_t segto, const void *data,
     int32_t ldata;
     int id;
 
-    fprintf(dbgf, "out to %"PRIx32", len = %"PRIu64": ", segto, size);
+    fprintf(ofile, "out to %"PRIx32", len = %"PRIu64": ", segto, size);
 
     switch (type) {
     case OUT_RESERVE:
-        fprintf(dbgf, "reserved.\n");
+        fprintf(ofile, "reserved.\n");
         break;
     case OUT_RAWDATA:
-        fprintf(dbgf, "raw data = ");
+        fprintf(ofile, "raw data = ");
         while (size--) {
             id = *(uint8_t *)data;
             data = (char *)data + 1;
-            fprintf(dbgf, "%02x ", id);
+            fprintf(ofile, "%02x ", id);
         }
-        fprintf(dbgf, "\n");
+        fprintf(ofile, "\n");
         break;
     case OUT_ADDRESS:
        ldata = *(int64_t *)data;
-        fprintf(dbgf, "addr %08"PRIx32" (seg %08"PRIx32", wrt %08"PRIx32")\n", ldata,
+        fprintf(ofile, "addr %08"PRIx32" (seg %08"PRIx32", wrt %08"PRIx32")\n", ldata,
                 segment, wrt);
         break;
     case OUT_REL2ADR:
-        fprintf(dbgf, "rel2adr %04"PRIx16" (seg %08"PRIx32")\n",
+        fprintf(ofile, "rel2adr %04"PRIx16" (seg %08"PRIx32")\n",
                (uint16_t)*(int64_t *)data, segment);
         break;
     case OUT_REL4ADR:
-        fprintf(dbgf, "rel4adr %08"PRIx32" (seg %08"PRIx32")\n",
+        fprintf(ofile, "rel4adr %08"PRIx32" (seg %08"PRIx32")\n",
                (uint32_t)*(int64_t *)data,
                 segment);
         break;
     case OUT_REL8ADR:
-        fprintf(dbgf, "rel8adr %016"PRIx64" (seg %08"PRIx32")\n",
+        fprintf(ofile, "rel8adr %016"PRIx64" (seg %08"PRIx32")\n",
                (uint64_t)*(int64_t *)data, segment);
         break;
     default:
-        fprintf(dbgf, "unknown\n");
+        fprintf(ofile, "unknown\n");
         break;
     }
 }
@@ -180,16 +171,16 @@ static int32_t dbg_segbase(int32_t segment)
     return segment;
 }
 
-static int dbg_directive(char *directive, char *value, int pass)
+static int dbg_directive(enum directives directive, char *value, int pass)
 {
-    fprintf(dbgf, "directive [%s] value [%s] (pass %d)\n",
-            directive, value, pass);
+    fprintf(ofile, "directive [%s] value [%s] (pass %d)\n",
+            directives[directive], value, pass);
     return 1;
 }
 
-static void dbg_filename(char *inname, char *outname, efunc error)
+static void dbg_filename(char *inname, char *outname)
 {
-    standard_extension(inname, outname, ".dbg", error);
+    standard_extension(inname, outname, ".dbg");
 }
 
 static int dbg_set_info(enum geninfo type, char **val)
@@ -202,13 +193,9 @@ static int dbg_set_info(enum geninfo type, char **val)
 char *types[] = {
     "unknown", "label", "byte", "word", "dword", "float", "qword", "tbyte"
 };
-void dbgdbg_init(struct ofmt *of, void *id, FILE * fp, efunc error)
+void dbgdbg_init(void)
 {
-    (void)of;
-    (void)id;
-    (void)fp;
-    (void)error;
-    fprintf(fp, "   With debug info\n");
+    fprintf(ofile, "   With debug info\n");
 }
 static void dbgdbg_cleanup(void)
 {
@@ -216,13 +203,13 @@ static void dbgdbg_cleanup(void)
 
 static void dbgdbg_linnum(const char *lnfname, int32_t lineno, int32_t segto)
 {
-    fprintf(dbgf, "dbglinenum %s(%"PRId32") := %08"PRIx32"\n",
+    fprintf(ofile, "dbglinenum %s(%"PRId32") := %08"PRIx32"\n",
            lnfname, lineno, segto);
 }
 static void dbgdbg_deflabel(char *name, int32_t segment,
                             int64_t offset, int is_global, char *special)
 {
-    fprintf(dbgf, "dbglabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n",
+    fprintf(ofile, "dbglabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n",
             name,
             segment, offset,
             is_global == 2 ? "common" : is_global ? "global" : "local",
@@ -230,7 +217,7 @@ static void dbgdbg_deflabel(char *name, int32_t segment,
 }
 static void dbgdbg_define(const char *type, const char *params)
 {
-    fprintf(dbgf, "dbgdirective [%s] value [%s]\n", type, params);
+    fprintf(ofile, "dbgdirective [%s] value [%s]\n", type, params);
 }
 static void dbgdbg_output(int output_type, void *param)
 {
@@ -239,7 +226,7 @@ static void dbgdbg_output(int output_type, void *param)
 }
 static void dbgdbg_typevalue(int32_t type)
 {
-    fprintf(dbgf, "new type: %s(%"PRIX32")\n",
+    fprintf(ofile, "new type: %s(%"PRIX32")\n",
             types[TYM_TYPE(type) >> 3], TYM_ELEMENTS(type));
 }
 static struct dfmt debug_debug_form = {
index adf6c34..7dce165 100644 (file)
@@ -49,6 +49,7 @@
 #include "saa.h"
 #include "raa.h"
 #include "stdscan.h"
+#include "eval.h"
 #include "output/outform.h"
 #include "output/outlib.h"
 #include "rbtree.h"
@@ -113,10 +114,6 @@ static struct RAA *bsym;
 static struct SAA *strs;
 static uint32_t strslen;
 
-static FILE *elffp;
-static efunc error;
-static evalfunc evaluate;
-
 static struct Symbol *fwds;
 
 static char elf_module[FILENAME_MAX];
@@ -221,7 +218,7 @@ static void stabs32_generate(void);
 static void stabs32_cleanup(void);
 
 /* dwarf debugging routines */
-static void dwarf32_init(struct ofmt *, void *, FILE *, efunc);
+static void dwarf32_init(void);
 static void dwarf32_linenum(const char *filename, int32_t linenumber, int32_t);
 static void dwarf32_output(int, void *);
 static void dwarf32_generate(void);
@@ -238,12 +235,8 @@ static int32_t elf_gotpc_sect, elf_gotoff_sect;
 static int32_t elf_got_sect, elf_plt_sect;
 static int32_t elf_sym_sect, elf_tlsie_sect;
 
-static void elf_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void elf_init(void)
 {
-    elffp = fp;
-    error = errfunc;
-    evaluate = eval;
-    (void)ldef;                 /* placate optimisers */
     sects = NULL;
     nsects = sectlen = 0;
     syms = saa_init((int32_t)sizeof(struct Symbol));
@@ -260,32 +253,25 @@ static void elf_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
     fwds = NULL;
 
     elf_gotpc_sect = seg_alloc();
-    ldef("..gotpc", elf_gotpc_sect + 1, 0L, NULL, false, false, &of_elf32,
-         error);
+    define_label("..gotpc", elf_gotpc_sect + 1, 0L, NULL, false, false);
     elf_gotoff_sect = seg_alloc();
-    ldef("..gotoff", elf_gotoff_sect + 1, 0L, NULL, false, false, &of_elf32,
-         error);
+    define_label("..gotoff", elf_gotoff_sect + 1, 0L, NULL, false, false);
     elf_got_sect = seg_alloc();
-    ldef("..got", elf_got_sect + 1, 0L, NULL, false, false, &of_elf32,
-         error);
+    define_label("..got", elf_got_sect + 1, 0L, NULL, false, false);
     elf_plt_sect = seg_alloc();
-    ldef("..plt", elf_plt_sect + 1, 0L, NULL, false, false, &of_elf32,
-         error);
+    define_label("..plt", elf_plt_sect + 1, 0L, NULL, false, false);
     elf_sym_sect = seg_alloc();
-    ldef("..sym", elf_sym_sect + 1, 0L, NULL, false, false, &of_elf32,
-         error);
+    define_label("..sym", elf_sym_sect + 1, 0L, NULL, false, false);
     elf_tlsie_sect = seg_alloc();
-    ldef("..tlsie", elf_tlsie_sect + 1, 0L, NULL, false, false, &of_elf32,
-         error);
+    define_label("..tlsie", elf_tlsie_sect + 1, 0L, NULL, false, false);
 
     def_seg = seg_alloc();
 }
 
-static void elf_init_hack(FILE * fp, efunc errfunc, ldfunc ldef,
-                           evalfunc eval)
+static void elf_init_hack(void)
 {
     of_elf32.current_dfmt = of_elf.current_dfmt; /* Sync debugging format */
-    elf_init(fp, errfunc, ldef, eval);
+    elf_init();
 }
 
 static void elf_cleanup(int debuginfo)
@@ -296,7 +282,6 @@ static void elf_cleanup(int debuginfo)
     (void)debuginfo;
 
     elf_write();
-    fclose(elffp);
     for (i = 0; i < nsects; i++) {
         if (sects[i]->type != SHT_NOBITS)
             saa_free(sects[i]->data);
@@ -397,7 +382,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits)
             if (align == 0)
                 align = 1;
             if ((align - 1) & align) {  /* means it's not a power of two */
-                error(ERR_NONFATAL, "section alignment %d is not"
+                nasm_error(ERR_NONFATAL, "section alignment %d is not"
                       " a power of two", align);
                 align = 1;
             }
@@ -427,7 +412,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits)
         } else if (!nasm_stricmp(q, "nobits")) {
             type = SHT_NOBITS;
         } else if (pass == 1) {
-           error(ERR_WARNING, "Unknown section attribute '%s' ignored on"
+           nasm_error(ERR_WARNING, "Unknown section attribute '%s' ignored on"
                   " declaration of section `%s'", q, name);
        }
     }
@@ -435,7 +420,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits)
     if (!strcmp(name, ".shstrtab") ||
         !strcmp(name, ".symtab") ||
         !strcmp(name, ".strtab")) {
-        error(ERR_NONFATAL, "attempt to redefine reserved section"
+        nasm_error(ERR_NONFATAL, "attempt to redefine reserved section"
               "name `%s'", name);
         return NO_SEG;
     }
@@ -461,7 +446,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits)
           if ((type && sects[i]->type != type)
              || (align && sects[i]->align != align)
              || (flags_and && ((sects[i]->flags & flags_and) != flags_or)))
-            error(ERR_WARNING, "section attributes ignored on"
+            nasm_error(ERR_WARNING, "section attributes ignored on"
                   " redeclaration of section `%s'", name);
     }
 
@@ -489,7 +474,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
         if (strcmp(name, "..gotpc") && strcmp(name, "..gotoff") &&
             strcmp(name, "..got") && strcmp(name, "..plt") &&
             strcmp(name, "..sym") && strcmp(name, "..tlsie"))
-            error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
+            nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
         return;
     }
 
@@ -512,10 +497,10 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
                 stdscan_reset();
                 stdscan_bufptr = p;
                 tokval.t_type = TOKEN_INVALID;
-                e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL);
+                e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
                 if (e) {
                     if (!is_simple(e))
-                        error(ERR_NONFATAL, "cannot use relocatable"
+                        nasm_error(ERR_NONFATAL, "cannot use relocatable"
                               " expression as symbol size");
                     else
                         (*s)->size = reloc_value(e);
@@ -550,7 +535,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
         if (nsects == 0 && segment == def_seg) {
             int tempint;
             if (segment != elf_section_names(".text", 2, &tempint))
-                error(ERR_PANIC,
+                nasm_error(ERR_PANIC,
                       "strange segment conditions in ELF driver");
             sym->section = nsects;
         } else {
@@ -575,11 +560,11 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
             bool err;
             sym->symv.key = readnum(special, &err);
             if (err)
-                error(ERR_NONFATAL, "alignment constraint `%s' is not a"
+                nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a"
                       " valid number", special);
             else if ((sym->symv.key | (sym->symv.key - 1))
                     != 2 * sym->symv.key - 1)
-                error(ERR_NONFATAL, "alignment constraint `%s' is not a"
+                nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a"
                       " power of two", special);
         }
         special_used = true;
@@ -621,7 +606,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
                 else if (!nasm_strnicmp(special, "notype", n))
                     sym->type |= STT_NOTYPE;
                 else
-                    error(ERR_NONFATAL, "unrecognised symbol type `%.*s'",
+                    nasm_error(ERR_NONFATAL, "unrecognised symbol type `%.*s'",
                           n, special);
                 special += n;
 
@@ -657,7 +642,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
                     stdscan_reset();
                     stdscan_bufptr = special + n;
                     tokval.t_type = TOKEN_INVALID;
-                    e = evaluate(stdscan, NULL, &tokval, &fwd, 0, error,
+                    e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error,
                                  NULL);
                     if (fwd) {
                         sym->nextfwd = fwds;
@@ -665,7 +650,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
                         sym->name = nasm_strdup(name);
                     } else if (e) {
                         if (!is_simple(e))
-                            error(ERR_NONFATAL, "cannot use relocatable"
+                            nasm_error(ERR_NONFATAL, "cannot use relocatable"
                                   " expression as symbol size");
                         else
                             sym->size = reloc_value(e);
@@ -688,7 +673,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
         nlocals++;
 
     if (special && !special_used)
-        error(ERR_NONFATAL, "no special symbol features supported here");
+        nasm_error(ERR_NONFATAL, "no special symbol features supported here");
 }
 
 static void elf_add_reloc(struct Section *sect, int32_t segment, int type)
@@ -763,7 +748,7 @@ static int32_t elf_add_gsym_reloc(struct Section *sect,
         }
     if (!s) {
         if (exact && offset != 0)
-            error(ERR_NONFATAL, "unable to find a suitable global symbol"
+            nasm_error(ERR_NONFATAL, "unable to find a suitable global symbol"
                   " for this reference");
         else
             elf_add_reloc(sect, segment, type);
@@ -772,7 +757,7 @@ static int32_t elf_add_gsym_reloc(struct Section *sect,
 
     srb = rb_search(s->gsyms, offset);
     if (!srb || (exact && srb->key != offset)) {
-       error(ERR_NONFATAL, "unable to find a suitable global symbol"
+       nasm_error(ERR_NONFATAL, "unable to find a suitable global symbol"
              " for this reference");
        return 0;
     }
@@ -806,7 +791,7 @@ static void elf_out(int32_t segto, const void *data,
      */
     if (segto == NO_SEG) {
         if (type != OUT_RESERVE)
-            error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
+            nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
                   " space");
         return;
     }
@@ -820,7 +805,7 @@ static void elf_out(int32_t segto, const void *data,
     if (!s) {
         int tempint;            /* ignored */
         if (segto != elf_section_names(".text", 2, &tempint))
-            error(ERR_PANIC, "strange segment conditions in ELF driver");
+            nasm_error(ERR_PANIC, "strange segment conditions in ELF driver");
         else {
             s = sects[nsects - 1];
             i = nsects - 1;
@@ -837,7 +822,7 @@ static void elf_out(int32_t segto, const void *data,
     /* end of debugging stuff */
 
     if (s->type == SHT_NOBITS && type != OUT_RESERVE) {
-        error(ERR_WARNING, "attempt to initialize memory in"
+        nasm_error(ERR_WARNING, "attempt to initialize memory in"
               " BSS section `%s': ignored", s->name);
        s->len += realsize(type, size);
         return;
@@ -845,21 +830,21 @@ static void elf_out(int32_t segto, const void *data,
 
     if (type == OUT_RESERVE) {
         if (s->type == SHT_PROGBITS) {
-            error(ERR_WARNING, "uninitialized space declared in"
+            nasm_error(ERR_WARNING, "uninitialized space declared in"
                   " non-BSS section `%s': zeroing", s->name);
             elf_sect_write(s, NULL, size);
         } else
             s->len += size;
     } else if (type == OUT_RAWDATA) {
         if (segment != NO_SEG)
-            error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
+            nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
         elf_sect_write(s, data, size);
     } else if (type == OUT_ADDRESS) {
         bool gnu16 = false;
         addr = *(int64_t *)data;
         if (segment != NO_SEG) {
             if (segment % 2) {
-                error(ERR_NONFATAL, "ELF format does not support"
+                nasm_error(ERR_NONFATAL, "ELF format does not support"
                       " segment base references");
             } else {
                 if (wrt == NO_SEG) {
@@ -895,10 +880,10 @@ static void elf_out(int32_t segto, const void *data,
                                                   R_386_32, false);
                     }
                 } else if (wrt == elf_plt_sect + 1) {
-                    error(ERR_NONFATAL, "ELF format cannot produce non-PC-"
+                    nasm_error(ERR_NONFATAL, "ELF format cannot produce non-PC-"
                           "relative PLT references");
                 } else {
-                    error(ERR_NONFATAL, "ELF format does not support this"
+                    nasm_error(ERR_NONFATAL, "ELF format does not support this"
                           " use of WRT");
                     wrt = NO_SEG;       /* we can at least _try_ to continue */
                 }
@@ -906,12 +891,12 @@ static void elf_out(int32_t segto, const void *data,
         }
         p = mydata;
         if (gnu16) {
-            error(ERR_WARNING | ERR_WARN_GNUELF,
+            nasm_error(ERR_WARNING | ERR_WARN_GNUELF,
                   "16-bit relocations in ELF is a GNU extension");
             WRITESHORT(p, addr);
         } else {
             if (size != 4 && segment != NO_SEG) {
-                error(ERR_NONFATAL,
+                nasm_error(ERR_NONFATAL,
                       "Unsupported non-32-bit ELF relocation");
             }
             WRITELONG(p, addr);
@@ -919,17 +904,17 @@ static void elf_out(int32_t segto, const void *data,
         elf_sect_write(s, mydata, size);
     } else if (type == OUT_REL2ADR) {
         if (segment == segto)
-            error(ERR_PANIC, "intra-segment OUT_REL2ADR");
+            nasm_error(ERR_PANIC, "intra-segment OUT_REL2ADR");
         if (segment != NO_SEG && segment % 2) {
-            error(ERR_NONFATAL, "ELF format does not support"
+            nasm_error(ERR_NONFATAL, "ELF format does not support"
                   " segment base references");
         } else {
             if (wrt == NO_SEG) {
-                error(ERR_WARNING | ERR_WARN_GNUELF,
+                nasm_error(ERR_WARNING | ERR_WARN_GNUELF,
                       "16-bit relocations in ELF is a GNU extension");
                 elf_add_reloc(s, segment, R_386_PC16);
             } else {
-                error(ERR_NONFATAL,
+                nasm_error(ERR_NONFATAL,
                       "Unsupported non-32-bit ELF relocation");
             }
         }
@@ -938,9 +923,9 @@ static void elf_out(int32_t segto, const void *data,
         elf_sect_write(s, mydata, 2L);
     } else if (type == OUT_REL4ADR) {
         if (segment == segto)
-            error(ERR_PANIC, "intra-segment OUT_REL4ADR");
+            nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR");
         if (segment != NO_SEG && segment % 2) {
-            error(ERR_NONFATAL, "ELF format does not support"
+            nasm_error(ERR_NONFATAL, "ELF format does not support"
                   " segment base references");
         } else {
             if (wrt == NO_SEG) {
@@ -950,10 +935,10 @@ static void elf_out(int32_t segto, const void *data,
             } else if (wrt == elf_gotpc_sect + 1 ||
                        wrt == elf_gotoff_sect + 1 ||
                        wrt == elf_got_sect + 1) {
-                error(ERR_NONFATAL, "ELF format cannot produce PC-"
+                nasm_error(ERR_NONFATAL, "ELF format cannot produce PC-"
                       "relative GOT references");
             } else {
-                error(ERR_NONFATAL, "ELF format does not support this"
+                nasm_error(ERR_NONFATAL, "ELF format does not support this"
                       " use of WRT");
                 wrt = NO_SEG;   /* we can at least _try_ to continue */
             }
@@ -1020,28 +1005,28 @@ static void elf_write(void)
     /*
      * Output the ELF header.
      */
-    fwrite("\177ELF\1\1\1", 7, 1, elffp);
-    fputc(elf_osabi, elffp);
-    fputc(elf_abiver, elffp);
-    fwritezero(7, elffp);
-    fwriteint16_t(1, elffp);      /* ET_REL relocatable file */
-    fwriteint16_t(3, elffp);      /* EM_386 processor ID */
-    fwriteint32_t(1L, elffp);      /* EV_CURRENT file format version */
-    fwriteint32_t(0L, elffp);      /* no entry point */
-    fwriteint32_t(0L, elffp);      /* no program header table */
-    fwriteint32_t(0x40L, elffp);   /* section headers straight after
+    fwrite("\177ELF\1\1\1", 7, 1, ofile);
+    fputc(elf_osabi, ofile);
+    fputc(elf_abiver, ofile);
+    fwritezero(7, ofile);
+    fwriteint16_t(1, ofile);      /* ET_REL relocatable file */
+    fwriteint16_t(3, ofile);      /* EM_386 processor ID */
+    fwriteint32_t(1L, ofile);      /* EV_CURRENT file format version */
+    fwriteint32_t(0L, ofile);      /* no entry point */
+    fwriteint32_t(0L, ofile);      /* no program header table */
+    fwriteint32_t(0x40L, ofile);   /* section headers straight after
                                    * ELF header plus alignment */
-    fwriteint32_t(0L, elffp);      /* 386 defines no special flags */
-    fwriteint16_t(0x34, elffp);   /* size of ELF header */
-    fwriteint16_t(0, elffp);      /* no program header table, again */
-    fwriteint16_t(0, elffp);      /* still no program header table */
-    fwriteint16_t(0x28, elffp);   /* size of section header */
-    fwriteint16_t(nsections, elffp);      /* number of sections */
-    fwriteint16_t(sec_shstrtab, elffp);   /* string table section index for
+    fwriteint32_t(0L, ofile);      /* 386 defines no special flags */
+    fwriteint16_t(0x34, ofile);   /* size of ELF header */
+    fwriteint16_t(0, ofile);      /* no program header table, again */
+    fwriteint16_t(0, ofile);      /* still no program header table */
+    fwriteint16_t(0x28, ofile);   /* size of section header */
+    fwriteint16_t(nsections, ofile);      /* number of sections */
+    fwriteint16_t(sec_shstrtab, ofile);   /* string table section index for
                                           * section header table */
-    fwriteint32_t(0L, elffp);      /* align to 0x40 bytes */
-    fwriteint32_t(0L, elffp);
-    fwriteint32_t(0L, elffp);
+    fwriteint32_t(0L, ofile);      /* align to 0x40 bytes */
+    fwriteint32_t(0L, ofile);
+    fwriteint32_t(0L, ofile);
 
     /*
      * Build the symbol table and relocation tables.
@@ -1168,7 +1153,7 @@ static void elf_write(void)
                                loclen, 0, 0, 1, 0);
             p += strlen(p) + 1;
     }
-    fwritezero(align, elffp);
+    fwritezero(align, ofile);
 
     /*
      * Now output the sections.
@@ -1351,18 +1336,18 @@ static void elf_section_header(int name, int type, int flags,
     elf_sects[elf_nsect].is_saa = is_saa;
     elf_nsect++;
 
-    fwriteint32_t((int32_t)name, elffp);
-    fwriteint32_t((int32_t)type, elffp);
-    fwriteint32_t((int32_t)flags, elffp);
-    fwriteint32_t(0L, elffp);      /* no address, ever, in object files */
-    fwriteint32_t(type == 0 ? 0L : elf_foffs, elffp);
-    fwriteint32_t(datalen, elffp);
+    fwriteint32_t((int32_t)name, ofile);
+    fwriteint32_t((int32_t)type, ofile);
+    fwriteint32_t((int32_t)flags, ofile);
+    fwriteint32_t(0L, ofile);      /* no address, ever, in object files */
+    fwriteint32_t(type == 0 ? 0L : elf_foffs, ofile);
+    fwriteint32_t(datalen, ofile);
     if (data)
         elf_foffs += (datalen + SEG_ALIGN_1) & ~SEG_ALIGN_1;
-    fwriteint32_t((int32_t)link, elffp);
-    fwriteint32_t((int32_t)info, elffp);
-    fwriteint32_t((int32_t)align, elffp);
-    fwriteint32_t((int32_t)eltsize, elffp);
+    fwriteint32_t((int32_t)link, ofile);
+    fwriteint32_t((int32_t)info, ofile);
+    fwriteint32_t((int32_t)align, ofile);
+    fwriteint32_t((int32_t)eltsize, ofile);
 }
 
 static void elf_write_sections(void)
@@ -1374,10 +1359,10 @@ static void elf_write_sections(void)
             int32_t reallen = (len + SEG_ALIGN_1) & ~SEG_ALIGN_1;
             int32_t align = reallen - len;
             if (elf_sects[i].is_saa)
-                saa_fpwrite(elf_sects[i].data, elffp);
+                saa_fpwrite(elf_sects[i].data, ofile);
             else
-                fwrite(elf_sects[i].data, len, 1, elffp);
-            fwritezero(align, elffp);
+                fwrite(elf_sects[i].data, len, 1, ofile);
+            fwritezero(align, ofile);
         }
 }
 
@@ -1393,23 +1378,24 @@ static int32_t elf_segbase(int32_t segment)
     return segment;
 }
 
-static int elf_directive(char *directive, char *value, int pass)
+static int elf_directive(enum directives directive, char *value, int pass)
 {
     bool err;
     int64_t n;
     char *p;
 
-    if (!strcmp(directive, "osabi")) {
+    switch (directive) {
+    case D_OSABI:
        if (pass == 2)
            return 1;           /* ignore in pass 2 */
 
        n = readnum(value, &err);
        if (err) {
-           error(ERR_NONFATAL, "`osabi' directive requires a parameter");
+           nasm_error(ERR_NONFATAL, "`osabi' directive requires a parameter");
            return 1;
        }
        if (n < 0 || n > 255) {
-           error(ERR_NONFATAL, "valid osabi numbers are 0 to 255");
+           nasm_error(ERR_NONFATAL, "valid osabi numbers are 0 to 255");
            return 1;
        }
        elf_osabi  = n;
@@ -1420,21 +1406,22 @@ static int elf_directive(char *directive, char *value, int pass)
 
        n = readnum(p+1, &err);
        if (err || n < 0 || n > 255) {
-           error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)");
+           nasm_error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)");
            return 1;
        }
        
        elf_abiver = n;
        return 1;
+    
+    default:
+       return 0;
     }
-       
-    return 0;
 }
 
-static void elf_filename(char *inname, char *outname, efunc error)
+static void elf_filename(char *inname, char *outname)
 {
     strcpy(elf_module, inname);
-    standard_extension(inname, outname, ".o", error);
+    standard_extension(inname, outname, ".o");
 }
 
 extern macros_t elf_stdmac[];
@@ -1806,13 +1793,8 @@ static void stabs32_cleanup(void)
 
 /* dwarf routines */
 
-static void dwarf32_init(struct ofmt *of, void *id, FILE * fp, efunc error)
+static void dwarf32_init(void)
 {
-    (void)of;
-    (void)id;
-    (void)fp;
-    (void)error;
-
     ndebugs = 3;               /* 3 debug symbols */
 }
 
index a7c51b8..5ccdf51 100644 (file)
@@ -49,6 +49,7 @@
 #include "saa.h"
 #include "raa.h"
 #include "stdscan.h"
+#include "eval.h"
 #include "output/outform.h"
 #include "output/outlib.h"
 #include "rbtree.h"
@@ -114,10 +115,6 @@ static struct RAA *bsym;
 static struct SAA *strs;
 static uint32_t strslen;
 
-static FILE *elffp;
-static efunc error;
-static evalfunc evaluate;
-
 static struct Symbol *fwds;
 
 static char elf_module[FILENAME_MAX];
@@ -229,7 +226,7 @@ static void stabs64_generate(void);
 static void stabs64_cleanup(void);
 
 /* dwarf debugging routines */
-static void dwarf64_init(struct ofmt *, void *, FILE *, efunc);
+static void dwarf64_init(void);
 static void dwarf64_linenum(const char *filename, int32_t linenumber, int32_t);
 static void dwarf64_output(int, void *);
 static void dwarf64_generate(void);
@@ -247,13 +244,9 @@ static int32_t elf_got_sect, elf_plt_sect;
 static int32_t elf_sym_sect;
 static int32_t elf_gottpoff_sect;
 
-static void elf_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void elf_init(void)
 {
     maxbits = 64;
-    elffp = fp;
-    error = errfunc;
-    evaluate = eval;
-    (void)ldef;                 /* placate optimisers */
     sects = NULL;
     nsects = sectlen = 0;
     syms = saa_init((int32_t)sizeof(struct Symbol));
@@ -270,23 +263,17 @@ static void elf_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
     fwds = NULL;
 
     elf_gotpc_sect = seg_alloc();
-    ldef("..gotpc", elf_gotpc_sect + 1, 0L, NULL, false, false, &of_elf64,
-         error);
+    define_label("..gotpc", elf_gotpc_sect + 1, 0L, NULL, false, false);
     elf_gotoff_sect = seg_alloc();
-    ldef("..gotoff", elf_gotoff_sect + 1, 0L, NULL, false, false, &of_elf64,
-         error);
+    define_label("..gotoff", elf_gotoff_sect + 1, 0L, NULL, false, false);
     elf_got_sect = seg_alloc();
-    ldef("..got", elf_got_sect + 1, 0L, NULL, false, false, &of_elf64,
-         error);
+    define_label("..got", elf_got_sect + 1, 0L, NULL, false, false);
     elf_plt_sect = seg_alloc();
-    ldef("..plt", elf_plt_sect + 1, 0L, NULL, false, false, &of_elf64,
-         error);
+    define_label("..plt", elf_plt_sect + 1, 0L, NULL, false, false);
     elf_sym_sect = seg_alloc();
-    ldef("..sym", elf_sym_sect + 1, 0L, NULL, false, false, &of_elf64,
-         error);
+    define_label("..sym", elf_sym_sect + 1, 0L, NULL, false, false);
     elf_gottpoff_sect = seg_alloc();
-    ldef("..gottpoff", elf_gottpoff_sect + 1, 0L, NULL, false, false, &of_elf64,
-         error);
+    define_label("..gottpoff", elf_gottpoff_sect + 1, 0L, NULL, false, false);
 
     def_seg = seg_alloc();
 
@@ -300,7 +287,6 @@ static void elf_cleanup(int debuginfo)
     (void)debuginfo;
 
     elf_write();
-    fclose(elffp);
     for (i = 0; i < nsects; i++) {
         if (sects[i]->type != SHT_NOBITS)
             saa_free(sects[i]->data);
@@ -400,7 +386,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits)
             if (align == 0)
                 align = 1;
             if ((align - 1) & align) {  /* means it's not a power of two */
-                error(ERR_NONFATAL, "section alignment %d is not"
+                nasm_error(ERR_NONFATAL, "section alignment %d is not"
                       " a power of two", align);
                 align = 1;
             }
@@ -430,7 +416,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits)
         } else if (!nasm_stricmp(q, "nobits")) {
             type = SHT_NOBITS;
         } else if (pass == 1) {
-           error(ERR_WARNING, "Unknown section attribute '%s' ignored on"
+           nasm_error(ERR_WARNING, "Unknown section attribute '%s' ignored on"
                   " declaration of section `%s'", q, name);
        }
     }
@@ -438,7 +424,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits)
     if (!strcmp(name, ".shstrtab") ||
         !strcmp(name, ".symtab") ||
         !strcmp(name, ".strtab")) {
-        error(ERR_NONFATAL, "attempt to redefine reserved section"
+        nasm_error(ERR_NONFATAL, "attempt to redefine reserved section"
               "name `%s'", name);
         return NO_SEG;
     }
@@ -464,7 +450,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits)
           if ((type && sects[i]->type != type)
              || (align && sects[i]->align != align)
              || (flags_and && ((sects[i]->flags & flags_and) != flags_or)))
-            error(ERR_WARNING, "incompatible section attributes ignored on"
+            nasm_error(ERR_WARNING, "incompatible section attributes ignored on"
                   " redeclaration of section `%s'", name);
     }
 
@@ -492,7 +478,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
         if (strcmp(name, "..gotpc") && strcmp(name, "..gotoff") &&
             strcmp(name, "..got") && strcmp(name, "..plt") &&
             strcmp(name, "..sym") && strcmp(name, "..gottpoff"))
-            error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
+            nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
         return;
     }
 
@@ -515,10 +501,10 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
                 stdscan_reset();
                 stdscan_bufptr = p;
                 tokval.t_type = TOKEN_INVALID;
-                e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL);
+                e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
                 if (e) {
                     if (!is_simple(e))
-                        error(ERR_NONFATAL, "cannot use relocatable"
+                        nasm_error(ERR_NONFATAL, "cannot use relocatable"
                               " expression as symbol size");
                     else
                         (*s)->size = reloc_value(e);
@@ -553,7 +539,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
         if (nsects == 0 && segment == def_seg) {
             int tempint;
             if (segment != elf_section_names(".text", 2, &tempint))
-                error(ERR_PANIC,
+                nasm_error(ERR_PANIC,
                       "strange segment conditions in ELF driver");
             sym->section = nsects;
         } else {
@@ -578,11 +564,11 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
             bool err;
             sym->symv.key = readnum(special, &err);
             if (err)
-                error(ERR_NONFATAL, "alignment constraint `%s' is not a"
+                nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a"
                       " valid number", special);
             else if ((sym->symv.key | (sym->symv.key - 1))
                     != 2 * sym->symv.key - 1)
-                error(ERR_NONFATAL, "alignment constraint `%s' is not a"
+                nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a"
                       " power of two", special);
         }
         special_used = true;
@@ -624,7 +610,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
                 else if (!nasm_strnicmp(special, "notype", n))
                     sym->type |= STT_NOTYPE;
                 else
-                    error(ERR_NONFATAL, "unrecognised symbol type `%.*s'",
+                    nasm_error(ERR_NONFATAL, "unrecognised symbol type `%.*s'",
                           n, special);
                 special += n;
 
@@ -660,7 +646,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
                     stdscan_reset();
                     stdscan_bufptr = special + n;
                     tokval.t_type = TOKEN_INVALID;
-                    e = evaluate(stdscan, NULL, &tokval, &fwd, 0, error,
+                    e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error,
                                  NULL);
                     if (fwd) {
                         sym->nextfwd = fwds;
@@ -668,7 +654,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
                         sym->name = nasm_strdup(name);
                     } else if (e) {
                         if (!is_simple(e))
-                            error(ERR_NONFATAL, "cannot use relocatable"
+                            nasm_error(ERR_NONFATAL, "cannot use relocatable"
                                   " expression as symbol size");
                         else
                             sym->size = reloc_value(e);
@@ -691,7 +677,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
         nlocals++;
 
     if (special && !special_used)
-        error(ERR_NONFATAL, "no special symbol features supported here");
+        nasm_error(ERR_NONFATAL, "no special symbol features supported here");
 }
 
 static void elf_add_reloc(struct Section *sect, int32_t segment,
@@ -768,7 +754,7 @@ static void elf_add_gsym_reloc(struct Section *sect,
 
     if (!s) {
        if (exact && offset)
-           error(ERR_NONFATAL, "invalid access to an external symbol");
+           nasm_error(ERR_NONFATAL, "invalid access to an external symbol");
        else 
            elf_add_reloc(sect, segment, offset - pcrel, type);
        return;
@@ -776,7 +762,7 @@ static void elf_add_gsym_reloc(struct Section *sect,
 
     srb = rb_search(s->gsyms, offset);
     if (!srb || (exact && srb->key != offset)) {
-       error(ERR_NONFATAL, "unable to find a suitable global symbol"
+       nasm_error(ERR_NONFATAL, "unable to find a suitable global symbol"
              " for this reference");
        return;
     }
@@ -819,7 +805,7 @@ static void elf_out(int32_t segto, const void *data,
      */
     if (segto == NO_SEG) {
         if (type != OUT_RESERVE)
-            error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
+            nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
                   " space");
         return;
     }
@@ -833,7 +819,7 @@ static void elf_out(int32_t segto, const void *data,
     if (!s) {
         int tempint;            /* ignored */
         if (segto != elf_section_names(".text", 2, &tempint))
-            error(ERR_PANIC, "strange segment conditions in ELF driver");
+            nasm_error(ERR_PANIC, "strange segment conditions in ELF driver");
         else {
             s = sects[nsects - 1];
             i = nsects - 1;
@@ -850,7 +836,7 @@ static void elf_out(int32_t segto, const void *data,
     /* end of debugging stuff */
 
     if (s->type == SHT_NOBITS && type != OUT_RESERVE) {
-        error(ERR_WARNING, "attempt to initialize memory in"
+        nasm_error(ERR_WARNING, "attempt to initialize memory in"
               " BSS section `%s': ignored", s->name);
         s->len += realsize(type, size);
         return;
@@ -858,21 +844,21 @@ static void elf_out(int32_t segto, const void *data,
 
     if (type == OUT_RESERVE) {
         if (s->type == SHT_PROGBITS) {
-            error(ERR_WARNING, "uninitialized space declared in"
+            nasm_error(ERR_WARNING, "uninitialized space declared in"
                   " non-BSS section `%s': zeroing", s->name);
             elf_sect_write(s, NULL, size);
         } else
             s->len += size;
     } else if (type == OUT_RAWDATA) {
         if (segment != NO_SEG)
-            error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
+            nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
         elf_sect_write(s, data, size);
     } else if (type == OUT_ADDRESS) {
         addr = *(int64_t *)data;
         if (segment == NO_SEG) {
            /* Do nothing */
        } else if (segment % 2) {
-           error(ERR_NONFATAL, "ELF format does not support"
+           nasm_error(ERR_NONFATAL, "ELF format does not support"
                  " segment base references");
        } else {
            if (wrt == NO_SEG) {
@@ -890,7 +876,7 @@ static void elf_out(int32_t segto, const void *data,
                    elf_add_reloc(s, segment, addr, R_X86_64_64);
                    break;
                default:
-                   error(ERR_PANIC, "internal error elf64-hpa-871");
+                   nasm_error(ERR_PANIC, "internal error elf64-hpa-871");
                    break;
                }
                addr = 0;
@@ -905,7 +891,7 @@ static void elf_out(int32_t segto, const void *data,
                addr = 0;
            } else if (wrt == elf_gotoff_sect + 1) {
                if (size != 8) {
-                   error(ERR_NONFATAL, "ELF64 requires ..gotoff "
+                   nasm_error(ERR_NONFATAL, "ELF64 requires ..gotoff "
                          "references to be qword");
                } else {
                    elf_add_reloc(s, segment, addr, R_X86_64_GOTOFF64);
@@ -924,7 +910,7 @@ static void elf_out(int32_t segto, const void *data,
                    addr = 0;
                    break;
                default:
-                   error(ERR_NONFATAL, "invalid ..got reference");
+                   nasm_error(ERR_NONFATAL, "invalid ..got reference");
                    break;
                }
            } else if (wrt == elf_sym_sect + 1) {
@@ -950,14 +936,14 @@ static void elf_out(int32_t segto, const void *data,
                    addr = 0;
                    break;
                default:
-                   error(ERR_PANIC, "internal error elf64-hpa-903");
+                   nasm_error(ERR_PANIC, "internal error elf64-hpa-903");
                    break;
                }
            } else if (wrt == elf_plt_sect + 1) {
-               error(ERR_NONFATAL, "ELF format cannot produce non-PC-"
+               nasm_error(ERR_NONFATAL, "ELF format cannot produce non-PC-"
                      "relative PLT references");
            } else {
-               error(ERR_NONFATAL, "ELF format does not support this"
+               nasm_error(ERR_NONFATAL, "ELF format does not support this"
                      " use of WRT");
            }
        }
@@ -965,18 +951,18 @@ static void elf_out(int32_t segto, const void *data,
     } else if (type == OUT_REL2ADR) {
        addr = *(int64_t *)data - size;
         if (segment == segto)
-            error(ERR_PANIC, "intra-segment OUT_REL2ADR");
+            nasm_error(ERR_PANIC, "intra-segment OUT_REL2ADR");
         if (segment == NO_SEG) {
            /* Do nothing */
        } else if (segment % 2) {
-            error(ERR_NONFATAL, "ELF format does not support"
+            nasm_error(ERR_NONFATAL, "ELF format does not support"
                   " segment base references");
         } else {
             if (wrt == NO_SEG) {
                 elf_add_reloc(s, segment, addr, R_X86_64_PC16);
                addr = 0;
             } else {
-                error(ERR_NONFATAL,
+                nasm_error(ERR_NONFATAL,
                       "Unsupported non-32-bit ELF relocation [2]");
             }
         }
@@ -984,11 +970,11 @@ static void elf_out(int32_t segto, const void *data,
     } else if (type == OUT_REL4ADR) {
        addr = *(int64_t *)data - size;
         if (segment == segto)
-            error(ERR_PANIC, "intra-segment OUT_REL4ADR");
+            nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR");
         if (segment == NO_SEG) {
            /* Do nothing */
        } else if (segment % 2) {
-            error(ERR_NONFATAL, "ELF64 format does not support"
+            nasm_error(ERR_NONFATAL, "ELF64 format does not support"
                   " segment base references");
         } else {
             if (wrt == NO_SEG) {
@@ -1005,14 +991,14 @@ static void elf_out(int32_t segto, const void *data,
                addr = 0;
             } else if (wrt == elf_gotoff_sect + 1 ||
                       wrt == elf_got_sect + 1) {
-               error(ERR_NONFATAL, "ELF64 requires ..gotoff references to be "
+               nasm_error(ERR_NONFATAL, "ELF64 requires ..gotoff references to be "
                      "qword absolute");
             } else if (wrt == elf_gottpoff_sect + 1) {
                 elf_add_gsym_reloc(s, segment, addr+size, size,
                                   R_X86_64_GOTTPOFF, true);
                addr = 0;
             } else {
-                error(ERR_NONFATAL, "ELF64 format does not support this"
+                nasm_error(ERR_NONFATAL, "ELF64 format does not support this"
                       " use of WRT");
             }
         }
@@ -1020,11 +1006,11 @@ static void elf_out(int32_t segto, const void *data,
     } else if (type == OUT_REL8ADR) {
        addr = *(int64_t *)data - size;
         if (segment == segto)
-            error(ERR_PANIC, "intra-segment OUT_REL8ADR");
+            nasm_error(ERR_PANIC, "intra-segment OUT_REL8ADR");
         if (segment == NO_SEG) {
            /* Do nothing */
        } else if (segment % 2) {
-            error(ERR_NONFATAL, "ELF64 format does not support"
+            nasm_error(ERR_NONFATAL, "ELF64 format does not support"
                   " segment base references");
         } else {
             if (wrt == NO_SEG) {
@@ -1037,13 +1023,13 @@ static void elf_out(int32_t segto, const void *data,
                addr = 0;
             } else if (wrt == elf_gotoff_sect + 1 ||
                       wrt == elf_got_sect + 1) {
-               error(ERR_NONFATAL, "ELF64 requires ..gotoff references to be "
+               nasm_error(ERR_NONFATAL, "ELF64 requires ..gotoff references to be "
                      "absolute");
             } else if (wrt == elf_gottpoff_sect + 1) {
-               error(ERR_NONFATAL, "ELF64 requires ..gottpoff references to be "
+               nasm_error(ERR_NONFATAL, "ELF64 requires ..gottpoff references to be "
                      "dword");
             } else {
-                error(ERR_NONFATAL, "ELF64 format does not support this"
+                nasm_error(ERR_NONFATAL, "ELF64 format does not support this"
                       " use of WRT");
             }
         }
@@ -1113,24 +1099,24 @@ static void elf_write(void)
     /*
      * Output the ELF header.
      */
-    fwrite("\177ELF\2\1\1", 7, 1, elffp);
-    fputc(elf_osabi, elffp);
-    fputc(elf_abiver, elffp);
-    fwritezero(7, elffp);
-    fwriteint16_t(ET_REL, elffp);      /* relocatable file */
-    fwriteint16_t(EM_X86_64, elffp);      /* processor ID */
-    fwriteint32_t(1L, elffp);      /* EV_CURRENT file format version */
-    fwriteint64_t(0L, elffp);      /* no entry point */
-    fwriteint64_t(0L, elffp);      /* no program header table */
-    fwriteint64_t(0x40L, elffp);   /* section headers straight after
+    fwrite("\177ELF\2\1\1", 7, 1, ofile);
+    fputc(elf_osabi, ofile);
+    fputc(elf_abiver, ofile);
+    fwritezero(7, ofile);
+    fwriteint16_t(ET_REL, ofile);      /* relocatable file */
+    fwriteint16_t(EM_X86_64, ofile);      /* processor ID */
+    fwriteint32_t(1L, ofile);      /* EV_CURRENT file format version */
+    fwriteint64_t(0L, ofile);      /* no entry point */
+    fwriteint64_t(0L, ofile);      /* no program header table */
+    fwriteint64_t(0x40L, ofile);   /* section headers straight after
                                  * ELF header plus alignment */
-    fwriteint32_t(0L, elffp);      /* 386 defines no special flags */
-    fwriteint16_t(0x40, elffp);   /* size of ELF header */
-    fwriteint16_t(0, elffp);      /* no program header table, again */
-    fwriteint16_t(0, elffp);      /* still no program header table */
-    fwriteint16_t(sizeof(Elf64_Shdr), elffp);   /* size of section header */
-    fwriteint16_t(nsections, elffp);      /* number of sections */
-    fwriteint16_t(sec_shstrtab, elffp);   /* string table section index for
+    fwriteint32_t(0L, ofile);      /* 386 defines no special flags */
+    fwriteint16_t(0x40, ofile);   /* size of ELF header */
+    fwriteint16_t(0, ofile);      /* no program header table, again */
+    fwriteint16_t(0, ofile);      /* still no program header table */
+    fwriteint16_t(sizeof(Elf64_Shdr), ofile);   /* size of section header */
+    fwriteint16_t(nsections, ofile);      /* number of sections */
+    fwriteint16_t(sec_shstrtab, ofile);   /* string table section index for
                                           * section header table */
 
     /*
@@ -1257,7 +1243,7 @@ static void elf_write(void)
                                loclen, 0, 0, 1, 0);
             p += strlen(p) + 1;
     }
-    fwritezero(align, elffp);
+    fwritezero(align, ofile);
 
     /*
      * Now output the sections.
@@ -1438,18 +1424,18 @@ static void elf_section_header(int name, int type, uint64_t flags,
     elf_sects[elf_nsect].is_saa = is_saa;
     elf_nsect++;
 
-    fwriteint32_t((int32_t)name, elffp);
-    fwriteint32_t((int32_t)type, elffp);
-    fwriteint64_t((int64_t)flags, elffp);
-    fwriteint64_t(0L, elffp);      /* no address, ever, in object files */
-    fwriteint64_t(type == 0 ? 0L : elf_foffs, elffp);
-    fwriteint64_t(datalen, elffp);
+    fwriteint32_t((int32_t)name, ofile);
+    fwriteint32_t((int32_t)type, ofile);
+    fwriteint64_t((int64_t)flags, ofile);
+    fwriteint64_t(0L, ofile);      /* no address, ever, in object files */
+    fwriteint64_t(type == 0 ? 0L : elf_foffs, ofile);
+    fwriteint64_t(datalen, ofile);
     if (data)
         elf_foffs += (datalen + SEG_ALIGN_1) & ~SEG_ALIGN_1;
-    fwriteint32_t((int32_t)link, elffp);
-    fwriteint32_t((int32_t)info, elffp);
-    fwriteint64_t((int64_t)align, elffp);
-    fwriteint64_t((int64_t)eltsize, elffp);
+    fwriteint32_t((int32_t)link, ofile);
+    fwriteint32_t((int32_t)info, ofile);
+    fwriteint64_t((int64_t)align, ofile);
+    fwriteint64_t((int64_t)eltsize, ofile);
 }
 
 static void elf_write_sections(void)
@@ -1461,10 +1447,10 @@ static void elf_write_sections(void)
             int32_t reallen = (len + SEG_ALIGN_1) & ~SEG_ALIGN_1;
             int32_t align = reallen - len;
             if (elf_sects[i].is_saa)
-                saa_fpwrite(elf_sects[i].data, elffp);
+                saa_fpwrite(elf_sects[i].data, ofile);
             else
-                fwrite(elf_sects[i].data, len, 1, elffp);
-            fwritezero(align, elffp);
+                fwrite(elf_sects[i].data, len, 1, ofile);
+            fwritezero(align, ofile);
         }
 }
 
@@ -1484,23 +1470,24 @@ static int32_t elf_segbase(int32_t segment)
     return segment;
 }
 
-static int elf_directive(char *directive, char *value, int pass)
+static int elf_directive(enum directives directive, char *value, int pass)
 {
     bool err;
     int64_t n;
     char *p;
 
-    if (!strcmp(directive, "osabi")) {
+    switch (directive) {
+    case D_OSABI:
        if (pass == 2)
            return 1;           /* ignore in pass 2 */
 
        n = readnum(value, &err);
        if (err) {
-           error(ERR_NONFATAL, "`osabi' directive requires a parameter");
+           nasm_error(ERR_NONFATAL, "`osabi' directive requires a parameter");
            return 1;
        }
        if (n < 0 || n > 255) {
-           error(ERR_NONFATAL, "valid osabi numbers are 0 to 255");
+           nasm_error(ERR_NONFATAL, "valid osabi numbers are 0 to 255");
            return 1;
        }
        elf_osabi  = n;
@@ -1511,21 +1498,22 @@ static int elf_directive(char *directive, char *value, int pass)
 
        n = readnum(p+1, &err);
        if (err || n < 0 || n > 255) {
-           error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)");
+           nasm_error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)");
            return 1;
        }
        
        elf_abiver = n;
        return 1;
+
+    default:
+       return 0;
     }
-       
-    return 0;
 }
 
-static void elf_filename(char *inname, char *outname, efunc error)
+static void elf_filename(char *inname, char *outname)
 {
     strcpy(elf_module, inname);
-    standard_extension(inname, outname, ".o", error);
+    standard_extension(inname, outname, ".o");
 }
 
 extern macros_t elf_stdmac[];
@@ -1882,13 +1870,8 @@ static void stabs64_cleanup(void)
         nasm_free(stabstrbuf);
 }
 /* dwarf routines */
-static void dwarf64_init(struct ofmt *of, void *id, FILE * fp, efunc error)
+static void dwarf64_init(void)
 {
-    (void)of;
-    (void)id;
-    (void)fp;
-    (void)error;
-
     ndebugs = 3;               /* 3 debug symbols */
 }
 
index f8cdca8..fa30986 100644 (file)
 #define BUILD_DRIVERS_ARRAY
 #include "output/outform.h"
 
-static int ndrivers = 0;
-
 struct ofmt *ofmt_find(char *name)
 {                               /* find driver */
-    int i;
-
-    for (i = 0; i < ndrivers; i++)
-        if (!strcmp(name, drivers[i]->shortname))
-            return drivers[i];
+    struct ofmt **ofp, *of;
 
+    for (ofp = drivers; (of = *ofp); ofp++) {
+        if (!nasm_stricmp(name, of->shortname))
+            return of;
+    }
     return NULL;
 }
+
 struct dfmt *dfmt_find(struct ofmt *ofmt, char *name)
 {                               /* find driver */
-    struct dfmt **dfmt = ofmt->debug_formats;
-    while (*dfmt) {
-        if (!strcmp(name, (*dfmt)->shortname))
-            return (*dfmt);
-        dfmt++;
+    struct dfmt **dfp, *df;
+
+    for (dfp = ofmt->debug_formats; (df = *dfp); dfp++) {
+        if (!nasm_stricmp(name, df->shortname))
+            return df;
     }
     return NULL;
 }
 
 void ofmt_list(struct ofmt *deffmt, FILE * fp)
 {
-    int i;
-    for (i = 0; i < ndrivers; i++)
-        fprintf(fp, "  %c %-10s%s\n",
-                drivers[i] == deffmt ? '*' : ' ',
-                drivers[i]->shortname, drivers[i]->fullname);
-}
-void dfmt_list(struct ofmt *ofmt, FILE * fp)
-{
-    struct dfmt **drivers = ofmt->debug_formats;
-    while (*drivers) {
+    struct ofmt **ofp, *of;
+
+    for (ofp = drivers; (of = *ofp); ofp++) {
         fprintf(fp, "  %c %-10s%s\n",
-                drivers[0] == ofmt->current_dfmt ? '*' : ' ',
-                drivers[0]->shortname, drivers[0]->fullname);
-        drivers++;
+                of == deffmt ? '*' : ' ',
+                of->shortname, of->fullname);
     }
 }
-struct ofmt *ofmt_register(efunc error)
+
+void dfmt_list(struct ofmt *ofmt, FILE *fp)
 {
-    for (ndrivers = 0; drivers[ndrivers] != NULL; ndrivers++) ;
+    struct dfmt **dfp, *df;
 
-    if (ndrivers == 0) {
-        error(ERR_PANIC | ERR_NOFILE,
-              "No output drivers given at compile time");
+    for (dfp = ofmt->debug_formats; (df = *dfp); dfp++) {
+        fprintf(fp, "  %c %-10s%s\n",
+                df == ofmt->current_dfmt ? '*' : ' ',
+                df->shortname, df->fullname);
     }
-
-    return (&OF_DEFAULT);
 }
index 391aabe..74522ed 100644 (file)
 #define OF_DEFAULT of_bin
 #endif
 
-#ifdef BUILD_DRIVERS_ARRAY      /* only if included from outform.c */
-
-/* pull in the externs for the different formats, then make the *drivers
- * array based on the above defines */
-
 extern struct ofmt of_bin;
 extern struct ofmt of_ith;
 extern struct ofmt of_srec;
@@ -278,7 +273,12 @@ extern struct ofmt of_macho;
 extern struct ofmt of_macho64;
 extern struct ofmt of_dbg;
 
-struct ofmt *drivers[] = {
+#ifdef BUILD_DRIVERS_ARRAY      /* only if included from outform.c */
+
+/* pull in the externs for the different formats, then make the *drivers
+ * array based on the above defines */
+
+static struct ofmt *drivers[] = {
 #ifdef OF_BIN
     &of_bin,
     &of_ith,
index d587d4c..900d1e3 100644 (file)
@@ -87,9 +87,6 @@
 static char ieee_infile[FILENAME_MAX];
 static int ieee_uppercase;
 
-static efunc error;
-static ldfunc deflabel;
-static FILE *ofp;
 static bool any_segs;
 static int arrindex;
 
@@ -207,12 +204,8 @@ static void ieee_unqualified_name(char *, char *);
 /*
  * pup init
  */
-static void ieee_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void ieee_init(void)
 {
-    (void)eval;
-    ofp = fp;
-    error = errfunc;
-    deflabel = ldef;
     any_segs = false;
     fpubhead = NULL;
     fpubtail = &fpubhead;
@@ -243,7 +236,6 @@ static void ieee_cleanup(int debuginfo)
 {
     ieee_write_file(debuginfo);
     of_ieee.current_dfmt->cleanup();
-    fclose(ofp);
     while (seghead) {
         struct ieeeSection *segtmp = seghead;
         seghead = seghead->next;
@@ -307,7 +299,7 @@ static void ieee_deflabel(char *name, int32_t segment,
     int i;
 
     if (special) {
-        error(ERR_NONFATAL, "unrecognised symbol type `%s'", special);
+        nasm_error(ERR_NONFATAL, "unrecognised symbol type `%s'", special);
     }
     /*
      * First check for the double-period, signifying something
@@ -415,7 +407,7 @@ static void ieee_out(int32_t segto, const void *data,
      */
     if (segto == NO_SEG) {
         if (type != OUT_RESERVE)
-            error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
+            nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
                   " space");
         return;
     }
@@ -427,7 +419,7 @@ static void ieee_out(int32_t segto, const void *data,
     if (!any_segs) {
         int tempint;            /* ignored */
         if (segto != ieee_segment("__NASMDEFSEG", 2, &tempint))
-            error(ERR_PANIC, "strange segment conditions in IEEE driver");
+            nasm_error(ERR_PANIC, "strange segment conditions in IEEE driver");
     }
 
     /*
@@ -437,7 +429,7 @@ static void ieee_out(int32_t segto, const void *data,
         if (seg->index == segto)
             break;
     if (!seg)
-        error(ERR_PANIC, "code directed to nonexistent segment?");
+        nasm_error(ERR_PANIC, "code directed to nonexistent segment?");
 
     if (type == OUT_RAWDATA) {
         ucdata = data;
@@ -446,7 +438,7 @@ static void ieee_out(int32_t segto, const void *data,
     } else if (type == OUT_ADDRESS || type == OUT_REL2ADR ||
                type == OUT_REL4ADR) {
         if (segment == NO_SEG && type != OUT_ADDRESS)
-            error(ERR_NONFATAL, "relative call to absolute address not"
+            nasm_error(ERR_NONFATAL, "relative call to absolute address not"
                   " supported by IEEE format");
         ldata = *(int64_t *)data;
         if (type == OUT_REL2ADR)
@@ -536,15 +528,15 @@ static void ieee_write_fixup(int32_t segment, int32_t wrt,
                             s.addend = 0;
                             s.id2 = eb->index[i];
                         } else
-                            error(ERR_NONFATAL,
+                            nasm_error(ERR_NONFATAL,
                                   "Source of WRT must be an offset");
                     }
 
                 } else
-                    error(ERR_PANIC,
+                    nasm_error(ERR_PANIC,
                           "unrecognised WRT value in ieee_write_fixup");
             } else
-                error(ERR_NONFATAL, "target of WRT must be a section ");
+                nasm_error(ERR_NONFATAL, "target of WRT must be a section ");
         }
         s.size = size;
         ieee_install_fixup(segto, &s);
@@ -583,7 +575,7 @@ static void ieee_write_fixup(int32_t segment, int32_t wrt,
                  */
                 if (eb) {
                     if (realtype == OUT_REL2ADR || realtype == OUT_REL4ADR) {
-                        error(ERR_PANIC,
+                        nasm_error(ERR_PANIC,
                               "Segment of a rel not supported in ieee_write_fixup");
                     } else {
                         /* If we want the segment */
@@ -594,7 +586,7 @@ static void ieee_write_fixup(int32_t segment, int32_t wrt,
 
                 } else
                     /* If we get here the seg value doesn't make sense */
-                    error(ERR_PANIC,
+                    nasm_error(ERR_PANIC,
                           "unrecognised segment value in ieee_write_fixup");
             }
 
@@ -649,12 +641,12 @@ static void ieee_write_fixup(int32_t segment, int32_t wrt,
 
                 } else
                     /* If we get here the seg value doesn't make sense */
-                    error(ERR_PANIC,
+                    nasm_error(ERR_PANIC,
                           "unrecognised segment value in ieee_write_fixup");
             }
         }
         if (size != 2 && s.ftype == FT_SEG)
-            error(ERR_NONFATAL, "IEEE format can only handle 2-byte"
+            nasm_error(ERR_NONFATAL, "IEEE format can only handle 2-byte"
                   " segment base references");
         s.size = size;
         ieee_install_fixup(segto, &s);
@@ -732,7 +724,7 @@ static int32_t ieee_segment(char *name, int pass, int *bits)
             ieee_idx++;
             if (!strcmp(seg->name, name)) {
                 if (attrs > 0 && pass == 1)
-                    error(ERR_WARNING, "segment attributes specified on"
+                    nasm_error(ERR_WARNING, "segment attributes specified on"
                           " redeclaration of segment: ignoring");
                 if (seg->use32)
                     *bits = 32;
@@ -788,7 +780,7 @@ static int32_t ieee_segment(char *name, int pass, int *bits)
                     seg->align = 1;
                 if (rn_error) {
                     seg->align = 1;
-                    error(ERR_NONFATAL, "segment alignment should be"
+                    nasm_error(ERR_NONFATAL, "segment alignment should be"
                           " numeric");
                 }
                 switch ((int)seg->align) {
@@ -803,7 +795,7 @@ static int32_t ieee_segment(char *name, int pass, int *bits)
                 case 128:
                     break;
                 default:
-                    error(ERR_NONFATAL, "invalid alignment value %d",
+                    nasm_error(ERR_NONFATAL, "invalid alignment value %d",
                           seg->align);
                     seg->align = 1;
                     break;
@@ -811,18 +803,17 @@ static int32_t ieee_segment(char *name, int pass, int *bits)
             } else if (!nasm_strnicmp(p, "absolute=", 9)) {
                 seg->align = SEG_ABS + readnum(p + 9, &rn_error);
                 if (rn_error)
-                    error(ERR_NONFATAL, "argument to `absolute' segment"
+                    nasm_error(ERR_NONFATAL, "argument to `absolute' segment"
                           " attribute should be numeric");
             }
         }
 
         ieee_seg_needs_update = seg;
         if (seg->align >= SEG_ABS)
-            deflabel(name, NO_SEG, seg->align - SEG_ABS,
-                     NULL, false, false, &of_ieee, error);
+            define_label(name, NO_SEG, seg->align - SEG_ABS,
+                        NULL, false, false);
         else
-            deflabel(name, seg->index + 1, 0L,
-                     NULL, false, false, &of_ieee, error);
+            define_label(name, seg->index + 1, 0L, NULL, false, false);
         ieee_seg_needs_update = NULL;
 
         if (seg->use32)
@@ -836,16 +827,20 @@ static int32_t ieee_segment(char *name, int pass, int *bits)
 /*
  * directives supported
  */
-static int ieee_directive(char *directive, char *value, int pass)
+static int ieee_directive(enum directives directive, char *value, int pass)
 {
 
     (void)value;
     (void)pass;
-    if (!strcmp(directive, "uppercase")) {
+
+    switch (directive) {
+    case D_UPPERCASE:
         ieee_uppercase = true;
         return 1;
+       
+    default:
+       return 0;
     }
-    return 0;
 }
 
 /*
@@ -874,10 +869,10 @@ static int32_t ieee_segbase(int32_t segment)
 /*
  * filename
  */
-static void ieee_filename(char *inname, char *outname, efunc error)
+static void ieee_filename(char *inname, char *outname)
 {
     strcpy(ieee_infile, inname);
-    standard_extension(inname, outname, ".o", error);
+    standard_extension(inname, outname, ".o");
 }
 
 static void ieee_write_file(int debuginfo)
@@ -975,7 +970,7 @@ static void ieee_write_file(int debuginfo)
             if (seg->index == ieee_entry_seg)
                 break;
         if (!seg)
-            error(ERR_PANIC, "Start address records are incorrect");
+            nasm_error(ERR_PANIC, "Start address records are incorrect");
         else
             ieee_putascii("ASG,R%X,%lX,+.\n", seg->ieee_index,
                           ieee_entry_ofs);
@@ -1157,7 +1152,7 @@ static void ieee_putascii(char *format, ...)
         if ((uint8_t)buffer[i] > 31)
             checksum += buffer[i];
     va_end(ap);
-    fprintf(ofp, buffer);
+    fprintf(ofile, buffer);
 }
 
 /*
@@ -1280,13 +1275,9 @@ static void ieee_unqualified_name(char *dest, char *source)
     } else
         strcpy(dest, source);
 }
-void dbgls_init(struct ofmt *of, void *id, FILE * fp, efunc error)
+void dbgls_init(void)
 {
     int tempint;
-    (void)of;
-    (void)id;
-    (void)fp;
-    (void)error;
 
     fnhead = NULL;
     fntail = &fnhead;
@@ -1342,7 +1333,7 @@ static void dbgls_linnum(const char *lnfname, int32_t lineno, int32_t segto)
     if (!any_segs) {
         int tempint;            /* ignored */
         if (segto != ieee_segment("__NASMDEFSEG", 2, &tempint))
-            error(ERR_PANIC, "strange segment conditions in OBJ driver");
+            nasm_error(ERR_PANIC, "strange segment conditions in OBJ driver");
     }
 
     /*
@@ -1352,7 +1343,7 @@ static void dbgls_linnum(const char *lnfname, int32_t lineno, int32_t segto)
         if (seg->index == segto)
             break;
     if (!seg)
-        error(ERR_PANIC, "lineno directed to nonexistent segment?");
+        nasm_error(ERR_PANIC, "lineno directed to nonexistent segment?");
 
     for (fn = fnhead; fn; fn = fn->next) {
         if (!nasm_stricmp(lnfname, fn->name))
index 964da5c..babe1d0 100644 (file)
 
 uint64_t realsize(enum out_type type, uint64_t size);
 
+/* Do-nothing versions of some output routines */
+int null_setinfo(enum geninfo type, char **string);
+int null_directive(enum directives directive, char *value, int pass);
+
 /* Do-nothing versions of all the debug routines */
 struct ofmt;
-void null_debug_init(struct ofmt *of, void *id, FILE * fp, efunc error);
+void null_debug_init(void);
 void null_debug_linenum(const char *filename, int32_t linenumber,
                        int32_t segto);
 void null_debug_deflabel(char *name, int32_t segment, int64_t offset,
index c9e4365..234cf28 100644 (file)
@@ -51,6 +51,7 @@
 #include "nasmlib.h"
 #include "saa.h"
 #include "raa.h"
+#include "eval.h"
 #include "output/outform.h"
 #include "output/outlib.h"
 
@@ -207,9 +208,7 @@ static struct RAA *extsyms;
 static struct SAA *strs;
 static uint32_t strslen;
 
-static FILE *machofp;
 static efunc error;
-static evalfunc evaluate;
 
 extern struct ofmt of_macho;
 
@@ -328,17 +327,10 @@ static uint8_t get_section_fileindex_by_index(const int32_t index)
     return NO_SECT;
 }
 
-static void macho_init(FILE * fp, efunc errfunc, ldfunc ldef,
-                       evalfunc eval)
+static void macho_init(void)
 {
     char zero = 0;
 
-    machofp = fp;
-    error = errfunc;
-    evaluate = eval;
-
-    (void)ldef;                 /* placate optimisers */
-
     sects = NULL;
     sectstail = &sects;
 
@@ -357,13 +349,6 @@ static void macho_init(FILE * fp, efunc errfunc, ldfunc ldef,
     strslen = 1;
 }
 
-static int macho_setinfo(enum geninfo type, char **val)
-{
-    (void)type;
-    (void)val;
-    return 0;
-}
-
 static void sect_write(struct section *sect,
                        const uint8_t *data, uint32_t len)
 {
@@ -720,17 +705,9 @@ static int32_t macho_segbase(int32_t section)
     return section;
 }
 
-static int macho_directive(char *directive, char *value, int pass)
+static void macho_filename(char *inname, char *outname)
 {
-    (void)directive;
-    (void)value;
-    (void)pass;
-    return 0;
-}
-
-static void macho_filename(char *inname, char *outname, efunc error)
-{
-    standard_extension(inname, outname, ".o", error);
+    standard_extension(inname, outname, ".o");
 }
 
 extern macros_t macho_stdmac[];
@@ -884,13 +861,13 @@ static void macho_calculate_sizes (void)
 
 static void macho_write_header (void)
 {
-    fwriteint32_t(MH_MAGIC, machofp);  /* magic */
-    fwriteint32_t(CPU_TYPE_I386, machofp);     /* CPU type */
-    fwriteint32_t(CPU_SUBTYPE_I386_ALL, machofp);      /* CPU subtype */
-    fwriteint32_t(MH_OBJECT, machofp); /* Mach-O file type */
-    fwriteint32_t(head_ncmds, machofp);        /* number of load commands */
-    fwriteint32_t(head_sizeofcmds, machofp);   /* size of load commands */
-    fwriteint32_t(0, machofp); /* no flags */
+    fwriteint32_t(MH_MAGIC, ofile);    /* magic */
+    fwriteint32_t(CPU_TYPE_I386, ofile);       /* CPU type */
+    fwriteint32_t(CPU_SUBTYPE_I386_ALL, ofile);        /* CPU subtype */
+    fwriteint32_t(MH_OBJECT, ofile);   /* Mach-O file type */
+    fwriteint32_t(head_ncmds, ofile);  /* number of load commands */
+    fwriteint32_t(head_sizeofcmds, ofile);     /* size of load commands */
+    fwriteint32_t(0, ofile);   /* no flags */
 }
 
 /* Write out the segment load command at offset.  */
@@ -901,56 +878,56 @@ static uint32_t macho_write_segment (uint32_t offset)
     uint32_t s_reloff = 0;
     struct section *s;
 
-    fwriteint32_t(LC_SEGMENT, machofp);        /* cmd == LC_SEGMENT */
+    fwriteint32_t(LC_SEGMENT, ofile);        /* cmd == LC_SEGMENT */
 
     /* size of load command including section load commands */
     fwriteint32_t(MACHO_SEGCMD_SIZE + seg_nsects *
-              MACHO_SECTCMD_SIZE, machofp);
+              MACHO_SECTCMD_SIZE, ofile);
 
     /* in an MH_OBJECT file all sections are in one unnamed (name
     ** all zeros) segment */
-    fwritezero(16, machofp);
-    fwriteint32_t(0, machofp); /* in-memory offset */
-    fwriteint32_t(seg_vmsize, machofp);        /* in-memory size */
-    fwriteint32_t(offset, machofp);    /* in-file offset to data */
-    fwriteint32_t(seg_filesize, machofp);      /* in-file size */
-    fwriteint32_t(VM_PROT_DEFAULT, machofp);   /* maximum vm protection */
-    fwriteint32_t(VM_PROT_DEFAULT, machofp);   /* initial vm protection */
-    fwriteint32_t(seg_nsects, machofp);        /* number of sections */
-    fwriteint32_t(0, machofp); /* no flags */
+    fwritezero(16, ofile);
+    fwriteint32_t(0, ofile); /* in-memory offset */
+    fwriteint32_t(seg_vmsize, ofile);        /* in-memory size */
+    fwriteint32_t(offset, ofile);    /* in-file offset to data */
+    fwriteint32_t(seg_filesize, ofile);      /* in-file size */
+    fwriteint32_t(VM_PROT_DEFAULT, ofile);   /* maximum vm protection */
+    fwriteint32_t(VM_PROT_DEFAULT, ofile);   /* initial vm protection */
+    fwriteint32_t(seg_nsects, ofile);        /* number of sections */
+    fwriteint32_t(0, ofile); /* no flags */
 
     /* emit section headers */
     for (s = sects; s != NULL; s = s->next) {
-       fwrite(s->sectname, sizeof(s->sectname), 1, machofp);
-       fwrite(s->segname, sizeof(s->segname), 1, machofp);
-       fwriteint32_t(s->addr, machofp);
-       fwriteint32_t(s->size, machofp);
+       fwrite(s->sectname, sizeof(s->sectname), 1, ofile);
+       fwrite(s->segname, sizeof(s->segname), 1, ofile);
+       fwriteint32_t(s->addr, ofile);
+       fwriteint32_t(s->size, ofile);
 
        /* dummy data for zerofill sections or proper values */
        if ((s->flags & SECTION_TYPE) != S_ZEROFILL) {
-           fwriteint32_t(offset, machofp);
+           fwriteint32_t(offset, ofile);
            /* Write out section alignment, as a power of two.
               e.g. 32-bit word alignment would be 2 (2^^2 = 4).  */
            if (s->align == -1)
                s->align = DEFAULT_SECTION_ALIGNMENT;
-           fwriteint32_t(s->align, machofp);
+           fwriteint32_t(s->align, ofile);
            /* To be compatible with cctools as we emit
               a zero reloff if we have no relocations.  */
-           fwriteint32_t(s->nreloc ? rel_base + s_reloff : 0, machofp);
-           fwriteint32_t(s->nreloc, machofp);
+           fwriteint32_t(s->nreloc ? rel_base + s_reloff : 0, ofile);
+           fwriteint32_t(s->nreloc, ofile);
 
            offset += s->size;
            s_reloff += s->nreloc * MACHO_RELINFO_SIZE;
        } else {
-           fwriteint32_t(0, machofp);
-           fwriteint32_t(0, machofp);
-           fwriteint32_t(0, machofp);
-           fwriteint32_t(0, machofp);
+           fwriteint32_t(0, ofile);
+           fwriteint32_t(0, ofile);
+           fwriteint32_t(0, ofile);
+           fwriteint32_t(0, ofile);
        }
 
-       fwriteint32_t(s->flags, machofp);      /* flags */
-       fwriteint32_t(0, machofp);     /* reserved */
-       fwriteint32_t(0, machofp);     /* reserved */
+       fwriteint32_t(s->flags, ofile);      /* flags */
+       fwriteint32_t(0, ofile);     /* reserved */
+       fwriteint32_t(0, ofile);     /* reserved */
     }
 
     rel_padcnt = rel_base - offset;
@@ -967,14 +944,14 @@ static void macho_write_relocs (struct reloc *r)
     while (r) {
        uint32_t word2;
 
-       fwriteint32_t(r->addr, machofp); /* reloc offset */
+       fwriteint32_t(r->addr, ofile); /* reloc offset */
 
        word2 = r->snum;
        word2 |= r->pcrel << 24;
        word2 |= r->length << 25;
        word2 |= r->ext << 27;
        word2 |= r->type << 28;
-       fwriteint32_t(word2, machofp); /* reloc data */
+       fwriteint32_t(word2, ofile); /* reloc data */
 
        r = r->next;
     }
@@ -1041,11 +1018,11 @@ static void macho_write_section (void)
        }
 
        /* dump the section data to file */
-       saa_fpwrite(s->data, machofp);
+       saa_fpwrite(s->data, ofile);
     }
 
     /* pad last section up to reloc entries on int32_t boundary */
-    fwritezero(rel_padcnt, machofp);
+    fwritezero(rel_padcnt, ofile);
 
     /* emit relocation entries */
     for (s = sects; s != NULL; s = s->next)
@@ -1065,10 +1042,10 @@ static void macho_write_symtab (void)
 
     for (sym = syms; sym != NULL; sym = sym->next) {
        if ((sym->type & N_EXT) == 0) {
-           fwriteint32_t(sym->strx, machofp);          /* string table entry number */
-           fwrite(&sym->type, 1, 1, machofp);  /* symbol type */
-           fwrite(&sym->sect, 1, 1, machofp);  /* section */
-           fwriteint16_t(sym->desc, machofp);  /* description */
+           fwriteint32_t(sym->strx, ofile);            /* string table entry number */
+           fwrite(&sym->type, 1, 1, ofile);    /* symbol type */
+           fwrite(&sym->sect, 1, 1, ofile);    /* section */
+           fwriteint16_t(sym->desc, ofile);    /* description */
 
            /* Fix up the symbol value now that we know the final section
               sizes.  */
@@ -1078,16 +1055,16 @@ static void macho_write_symtab (void)
                    sym->value += s->size;
            }
 
-           fwriteint32_t(sym->value, machofp); /* value (i.e. offset) */
+           fwriteint32_t(sym->value, ofile);   /* value (i.e. offset) */
        }
     }
 
     for (i = 0; i < nextdefsym; i++) {
        sym = extdefsyms[i];
-       fwriteint32_t(sym->strx, machofp);
-       fwrite(&sym->type, 1, 1, machofp);      /* symbol type */
-       fwrite(&sym->sect, 1, 1, machofp);      /* section */
-       fwriteint16_t(sym->desc, machofp);      /* description */
+       fwriteint32_t(sym->strx, ofile);
+       fwrite(&sym->type, 1, 1, ofile);        /* symbol type */
+       fwrite(&sym->sect, 1, 1, ofile);        /* section */
+       fwriteint16_t(sym->desc, ofile);        /* description */
 
        /* Fix up the symbol value now that we know the final section
           sizes.  */
@@ -1097,15 +1074,15 @@ static void macho_write_symtab (void)
                sym->value += s->size;
        }
 
-       fwriteint32_t(sym->value, machofp);     /* value (i.e. offset) */
+       fwriteint32_t(sym->value, ofile);       /* value (i.e. offset) */
     }
 
      for (i = 0; i < nundefsym; i++) {
         sym = undefsyms[i];
-        fwriteint32_t(sym->strx, machofp);
-        fwrite(&sym->type, 1, 1, machofp);     /* symbol type */
-        fwrite(&sym->sect, 1, 1, machofp);     /* section */
-        fwriteint16_t(sym->desc, machofp);     /* description */
+        fwriteint32_t(sym->strx, ofile);
+        fwrite(&sym->type, 1, 1, ofile);       /* symbol type */
+        fwrite(&sym->sect, 1, 1, ofile);       /* section */
+        fwriteint16_t(sym->desc, ofile);       /* description */
 
         /* Fix up the symbol value now that we know the final section
            sizes.  */
@@ -1115,7 +1092,7 @@ static void macho_write_symtab (void)
                 sym->value += s->size;
         }
 
-        fwriteint32_t(sym->value, machofp);    /* value (i.e. offset) */
+        fwriteint32_t(sym->value, ofile);      /* value (i.e. offset) */
      }
 }
 
@@ -1232,15 +1209,15 @@ static void macho_write (void)
 
     if (nsyms > 0) {
         /* write out symbol command */
-        fwriteint32_t(LC_SYMTAB, machofp); /* cmd == LC_SYMTAB */
-        fwriteint32_t(MACHO_SYMCMD_SIZE, machofp); /* size of load command */
-        fwriteint32_t(offset, machofp);    /* symbol table offset */
-        fwriteint32_t(nsyms, machofp);     /* number of symbol
+        fwriteint32_t(LC_SYMTAB, ofile); /* cmd == LC_SYMTAB */
+        fwriteint32_t(MACHO_SYMCMD_SIZE, ofile); /* size of load command */
+        fwriteint32_t(offset, ofile);    /* symbol table offset */
+        fwriteint32_t(nsyms, ofile);     /* number of symbol
                                          ** table entries */
 
         offset += nsyms * MACHO_NLIST_SIZE;
-        fwriteint32_t(offset, machofp);    /* string table offset */
-        fwriteint32_t(strslen, machofp);   /* string table size */
+        fwriteint32_t(offset, ofile);    /* string table offset */
+        fwriteint32_t(strslen, ofile);   /* string table size */
     }
 
     /* emit section data */
@@ -1254,7 +1231,7 @@ static void macho_write (void)
     /* we don't need to pad here since MACHO_NLIST_SIZE == 12 */
 
     /* emit string table */
-    saa_fpwrite(strs, machofp);
+    saa_fpwrite(strs, ofile);
 }
 /* We do quite a bit here, starting with finalizing all of the data
    for the object file, writing, and then freeing all of the data from
@@ -1280,9 +1257,6 @@ static void macho_cleanup(int debuginfo)
     macho_calculate_sizes();
     macho_write();
 
-    /* done - yay! */
-    fclose(machofp);
-
     /* free up everything */
     while (sects->next) {
         s = sects;
@@ -1343,12 +1317,12 @@ struct ofmt of_macho32 = {
     &null_debug_form,
     macho_stdmac,
     macho_init,
-    macho_setinfo,
+    null_setinfo,
     macho_output,
     macho_symdef,
     macho_section,
     macho_segbase,
-    macho_directive,
+    null_directive,
     macho_filename,
     macho_cleanup
 };
@@ -1361,12 +1335,12 @@ struct ofmt of_macho = {
     &null_debug_form,
     macho_stdmac,
     macho_init,
-    macho_setinfo,
+    null_setinfo,
     macho_output,
     macho_symdef,
     macho_section,
     macho_segbase,
-    macho_directive,
+    null_directive,
     macho_filename,
     macho_cleanup
 };
index cad399d..a0da134 100644 (file)
@@ -209,10 +209,6 @@ static struct RAA *extsyms;
 static struct SAA *strs;
 static uint32_t strslen;
 
-static FILE *machofp;
-static efunc error;
-static evalfunc evaluate;
-
 extern struct ofmt of_macho64;
 
 /* Global file information. This should be cleaned up into either
@@ -327,7 +323,7 @@ static uint8_t get_section_fileindex_by_index(const int32_t index)
             return i;
 
     if (i == MAX_SECT)
-        error(ERR_WARNING,
+        nasm_error(ERR_WARNING,
               "too many sections (>255) - clipped by fileindex");
 
     return NO_SECT;
@@ -355,17 +351,11 @@ static struct symbol *get_closest_section_symbol_by_offset(uint8_t fileindex, in
  */
 static int32_t macho_gotpcrel_sect;
 
-static void macho_init(FILE * fp, efunc errfunc, ldfunc ldef,
-                       evalfunc eval)
+static void macho_init(void)
 {
     char zero = 0;
 
-       maxbits = 64;
-    machofp = fp;
-    error = errfunc;
-    evaluate = eval;
-
-    (void)ldef;                 /* placate optimizers */
+    maxbits = 64;
 
     sects = NULL;
     sectstail = &sects;
@@ -383,18 +373,11 @@ static void macho_init(FILE * fp, efunc errfunc, ldfunc ldef,
     /* string table starts with a zero byte - don't ask why */
     saa_wbytes(strs, &zero, sizeof(char));
     strslen = 1;
-       
-       /* add special symbol for ..gotpcrel */
-       macho_gotpcrel_sect = seg_alloc();
-       macho_gotpcrel_sect ++;
-       ldef("..gotpcrel", macho_gotpcrel_sect, 0L, NULL, false, false, &of_macho64, error);
-}
 
-static int macho_setinfo(enum geninfo type, char **val)
-{
-    (void)type;
-    (void)val;
-    return 0;
+    /* add special symbol for ..gotpcrel */
+    macho_gotpcrel_sect = seg_alloc();
+    macho_gotpcrel_sect++;
+    define_label("..gotpcrel", macho_gotpcrel_sect, 0L, NULL, false, false);
 }
 
 static void sect_write(struct section *sect,
@@ -408,9 +391,9 @@ static int32_t add_reloc(struct section *sect, int32_t section,
                       int pcrel, int bytes, int64_t reloff)
 {
     struct reloc *r;
-       struct symbol *sym;
+    struct symbol *sym;
     int32_t fi;
-       int32_t adjustment = 0;
+    int32_t adjustment = 0;
 
     /* NeXT as puts relocs in reversed order (address-wise) into the
      ** files, so we do the same, doesn't seem to make much of a
@@ -528,7 +511,7 @@ static void macho_output(int32_t secto, const void *data,
 
     if (secto == NO_SEG) {
         if (type != OUT_RESERVE)
-            error(ERR_NONFATAL, "attempt to assemble code in "
+            nasm_error(ERR_NONFATAL, "attempt to assemble code in "
                   "[ABSOLUTE] space");
 
         return;
@@ -537,19 +520,19 @@ static void macho_output(int32_t secto, const void *data,
     s = get_section_by_index(secto);
 
     if (s == NULL) {
-        error(ERR_WARNING, "attempt to assemble code in"
+        nasm_error(ERR_WARNING, "attempt to assemble code in"
               " section %d: defaulting to `.text'", secto);
         s = get_section_by_name("__TEXT", "__text");
 
         /* should never happen */
         if (s == NULL)
-            error(ERR_PANIC, "text section not found");
+            nasm_error(ERR_PANIC, "text section not found");
     }
 
     sbss = get_section_by_name("__DATA", "__bss");
 
     if (s == sbss && type != OUT_RESERVE) {
-        error(ERR_WARNING, "attempt to initialize memory in the"
+        nasm_error(ERR_WARNING, "attempt to initialize memory in the"
               " BSS section: ignored");
         s->size += realsize(type, size);
         return;
@@ -558,7 +541,7 @@ static void macho_output(int32_t secto, const void *data,
     switch (type) {
     case OUT_RESERVE:
         if (s != sbss) {
-            error(ERR_WARNING, "uninitialized space declared in"
+            nasm_error(ERR_WARNING, "uninitialized space declared in"
                   " %s section: zeroing",
                   get_section_name_by_index(secto));
 
@@ -570,7 +553,7 @@ static void macho_output(int32_t secto, const void *data,
 
     case OUT_RAWDATA:
         if (section != NO_SEG)
-            error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
+            nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
 
         sect_write(s, data, size);
         break;
@@ -579,12 +562,12 @@ static void macho_output(int32_t secto, const void *data,
         addr = *(int64_t *)data;
         if (section != NO_SEG) {
             if (section % 2) {
-                error(ERR_NONFATAL, "Mach-O format does not support"
+                nasm_error(ERR_NONFATAL, "Mach-O format does not support"
                       " section base references");
             } else {
                                if (wrt == NO_SEG) {
                                        if (size < 8) {
-                                               error(ERR_NONFATAL, "Mach-O 64-bit format does not support"
+                                               nasm_error(ERR_NONFATAL, "Mach-O 64-bit format does not support"
                                                        " 32-bit absolute addresses");
                                        /*
                                         Seemingly, Mach-O's X86_64_RELOC_SUBTRACTOR would require
@@ -595,7 +578,7 @@ static void macho_output(int32_t secto, const void *data,
                                                addr -= add_reloc(s, section, 0, size, addr);                                   // X86_64_RELOC_UNSIGNED
                                        }
                                } else {
-                                       error(ERR_NONFATAL, "Mach-O format does not support"
+                                       nasm_error(ERR_NONFATAL, "Mach-O format does not support"
                                                " this use of WRT");
                                }
                        }
@@ -611,15 +594,15 @@ static void macho_output(int32_t secto, const void *data,
         WRITESHORT(p, *(int64_t *)data);
 
         if (section == secto)
-            error(ERR_PANIC, "intra-section OUT_REL2ADR");
+            nasm_error(ERR_PANIC, "intra-section OUT_REL2ADR");
 
                if (section == NO_SEG) {
                        /* Do nothing */
         } else if (section % 2) {
-            error(ERR_NONFATAL, "Mach-O format does not support"
+            nasm_error(ERR_NONFATAL, "Mach-O format does not support"
                   " section base references");
         } else {
-                       error(ERR_NONFATAL, "Unsupported non-32-bit"
+                       nasm_error(ERR_NONFATAL, "Unsupported non-32-bit"
                                  " Macho-O relocation [2]");
                }
 
@@ -631,10 +614,10 @@ static void macho_output(int32_t secto, const void *data,
                WRITELONG(p, *(int64_t *)data);
 
         if (section == secto)
-            error(ERR_PANIC, "intra-section OUT_REL4ADR");
+            nasm_error(ERR_PANIC, "intra-section OUT_REL4ADR");
 
         if (section != NO_SEG && section % 2) {
-            error(ERR_NONFATAL, "Mach-O format does not support"
+            nasm_error(ERR_NONFATAL, "Mach-O format does not support"
                   " section base references");
         } else {
                        if (wrt == NO_SEG) {
@@ -651,7 +634,7 @@ static void macho_output(int32_t secto, const void *data,
                                        *mydata -= add_reloc(s, section, 3, 4, (int64_t)*mydata);                       // X86_64_GOT
                                }
                        } else {
-                               error(ERR_NONFATAL, "Mach-O format does not support"
+                               nasm_error(ERR_NONFATAL, "Mach-O format does not support"
                                    " this use of WRT");
                                wrt = NO_SEG;   /* we can at least _try_ to continue */
                        }
@@ -661,7 +644,7 @@ static void macho_output(int32_t secto, const void *data,
         break;
 
     default:
-        error(ERR_PANIC, "unknown output type?");
+        nasm_error(ERR_PANIC, "unknown output type?");
         break;
     }
 }
@@ -727,14 +710,14 @@ static int32_t macho_section(char *name, int pass, int *bits)
                         newAlignment = exact_log2(value);
 
                         if (0 != *end) {
-                            error(ERR_PANIC,
+                            nasm_error(ERR_PANIC,
                                   "unknown or missing alignment value \"%s\" "
                                       "specified for section \"%s\"",
                                   currentAttribute + 6,
                                   name);
                             return NO_SEG;
                         } else if (0 > newAlignment) {
-                            error(ERR_PANIC,
+                            nasm_error(ERR_PANIC,
                                   "alignment of %d (for section \"%s\") is not "
                                       "a power of two",
                                   value,
@@ -745,7 +728,7 @@ static int32_t macho_section(char *name, int pass, int *bits)
                         if ((-1 != originalIndex)
                             && (s->align != newAlignment)
                            && (s->align != -1)) {
-                            error(ERR_PANIC,
+                            nasm_error(ERR_PANIC,
                                   "section \"%s\" has already been specified "
                                       "with alignment %d, conflicts with new "
                                       "alignment of %d",
@@ -759,7 +742,7 @@ static int32_t macho_section(char *name, int pass, int *bits)
                     } else if (!nasm_stricmp("data", currentAttribute)) {
                         /* Do nothing; 'data' is implicit */
                     } else {
-                        error(ERR_PANIC,
+                        nasm_error(ERR_PANIC,
                               "unknown section attribute %s for section %s",
                               currentAttribute,
                               name);
@@ -772,7 +755,7 @@ static int32_t macho_section(char *name, int pass, int *bits)
         }
     }
 
-    error(ERR_PANIC, "invalid section name %s", name);
+    nasm_error(ERR_PANIC, "invalid section name %s", name);
     return NO_SEG;
 }
 
@@ -782,13 +765,13 @@ static void macho_symdef(char *name, int32_t section, int64_t offset,
     struct symbol *sym;
 
     if (special) {
-        error(ERR_NONFATAL, "The Mach-O output format does "
+        nasm_error(ERR_NONFATAL, "The Mach-O output format does "
               "not support any special symbol types");
         return;
     }
 
     if (is_global == 3) {
-        error(ERR_NONFATAL, "The Mach-O format does not "
+        nasm_error(ERR_NONFATAL, "The Mach-O format does not "
               "(yet) support forward reference fixups.");
         return;
     }
@@ -800,7 +783,7 @@ static void macho_symdef(char *name, int32_t section, int64_t offset,
          * _isn't_ a valid one, we should barf immediately.
          */
         if (strcmp(name, "..gotpcrel"))
-            error(ERR_NONFATAL, "unrecognized special symbol `%s'", name);
+            nasm_error(ERR_NONFATAL, "unrecognized special symbol `%s'", name);
          return;
     }
 
@@ -854,7 +837,7 @@ static void macho_symdef(char *name, int32_t section, int64_t offset,
                 /* give an error on unfound section if it's not an
                  ** external or common symbol (assemble_file() does a
                  ** seg_alloc() on every call for them) */
-                error(ERR_PANIC, "in-file index for section %d not found",
+                nasm_error(ERR_PANIC, "in-file index for section %d not found",
                       section);
             }
         }
@@ -867,17 +850,9 @@ static int32_t macho_segbase(int32_t section)
     return section;
 }
 
-static int macho_directive(char *directive, char *value, int pass)
-{
-    (void)directive;
-    (void)value;
-    (void)pass;
-    return 0;
-}
-
-static void macho_filename(char *inname, char *outname, efunc error)
+static void macho_filename(char *inname, char *outname)
 {
-    standard_extension(inname, outname, ".o", error);
+    standard_extension(inname, outname, ".o");
 }
 
 extern macros_t macho_stdmac[];
@@ -1033,14 +1008,14 @@ static void macho_calculate_sizes (void)
 
 static void macho_write_header (void)
 {
-    fwriteint32_t(MH_MAGIC_64, machofp);       /* magic */
-    fwriteint32_t(CPU_TYPE_X86_64, machofp);   /* CPU type */
-    fwriteint32_t(CPU_SUBTYPE_I386_ALL, machofp);      /* CPU subtype */
-    fwriteint32_t(MH_OBJECT, machofp); /* Mach-O file type */
-    fwriteint32_t(head_ncmds64, machofp);      /* number of load commands */
-    fwriteint32_t(head_sizeofcmds64, machofp); /* size of load commands */
-    fwriteint32_t(0, machofp); /* no flags */
-       fwriteint32_t(0, machofp); /* reserved for future use */
+    fwriteint32_t(MH_MAGIC_64, ofile); /* magic */
+    fwriteint32_t(CPU_TYPE_X86_64, ofile);     /* CPU type */
+    fwriteint32_t(CPU_SUBTYPE_I386_ALL, ofile);        /* CPU subtype */
+    fwriteint32_t(MH_OBJECT, ofile);   /* Mach-O file type */
+    fwriteint32_t(head_ncmds64, ofile);        /* number of load commands */
+    fwriteint32_t(head_sizeofcmds64, ofile);   /* size of load commands */
+    fwriteint32_t(0, ofile);   /* no flags */
+       fwriteint32_t(0, ofile); /* reserved for future use */
 }
 
 /* Write out the segment load command at offset.  */
@@ -1051,51 +1026,51 @@ static uint32_t macho_write_segment (uint64_t offset)
     uint32_t s_reloff = 0;
     struct section *s;
 
-    fwriteint32_t(LC_SEGMENT_64, machofp);        /* cmd == LC_SEGMENT_64 */
+    fwriteint32_t(LC_SEGMENT_64, ofile);        /* cmd == LC_SEGMENT_64 */
 
     /* size of load command including section load commands */
     fwriteint32_t(MACHO_SEGCMD64_SIZE + seg_nsects64 *
-              MACHO_SECTCMD64_SIZE, machofp);
+              MACHO_SECTCMD64_SIZE, ofile);
 
     /* in an MH_OBJECT file all sections are in one unnamed (name
     ** all zeros) segment */
-    fwritezero(16, machofp);
-    fwriteint64_t(0, machofp); /* in-memory offset */
-    fwriteint64_t(seg_vmsize64, machofp);        /* in-memory size */
-    fwriteint64_t(offset, machofp);    /* in-file offset to data */
-    fwriteint64_t(seg_filesize64, machofp);      /* in-file size */
-    fwriteint32_t(VM_PROT_DEFAULT, machofp);   /* maximum vm protection */
-    fwriteint32_t(VM_PROT_DEFAULT, machofp);   /* initial vm protection */
-    fwriteint32_t(seg_nsects64, machofp);        /* number of sections */
-    fwriteint32_t(0, machofp); /* no flags */
+    fwritezero(16, ofile);
+    fwriteint64_t(0, ofile); /* in-memory offset */
+    fwriteint64_t(seg_vmsize64, ofile);        /* in-memory size */
+    fwriteint64_t(offset, ofile);    /* in-file offset to data */
+    fwriteint64_t(seg_filesize64, ofile);      /* in-file size */
+    fwriteint32_t(VM_PROT_DEFAULT, ofile);   /* maximum vm protection */
+    fwriteint32_t(VM_PROT_DEFAULT, ofile);   /* initial vm protection */
+    fwriteint32_t(seg_nsects64, ofile);        /* number of sections */
+    fwriteint32_t(0, ofile); /* no flags */
 
     /* emit section headers */
     for (s = sects; s != NULL; s = s->next) {
-        fwrite(s->sectname, sizeof(s->sectname), 1, machofp);
-        fwrite(s->segname, sizeof(s->segname), 1, machofp);
-        fwriteint64_t(s->addr, machofp);
-        fwriteint64_t(s->size, machofp);
+        fwrite(s->sectname, sizeof(s->sectname), 1, ofile);
+        fwrite(s->segname, sizeof(s->segname), 1, ofile);
+        fwriteint64_t(s->addr, ofile);
+        fwriteint64_t(s->size, ofile);
 
         /* dummy data for zerofill sections or proper values */
         if ((s->flags & SECTION_TYPE) != S_ZEROFILL) {
-            fwriteint32_t(offset, machofp);
+            fwriteint32_t(offset, ofile);
             /* Write out section alignment, as a power of two.
             e.g. 32-bit word alignment would be 2 (2^2 = 4).  */
             if (s->align == -1)
                 s->align = DEFAULT_SECTION_ALIGNMENT;
-            fwriteint32_t(s->align, machofp);
+            fwriteint32_t(s->align, ofile);
             /* To be compatible with cctools as we emit
             a zero reloff if we have no relocations.  */
-            fwriteint32_t(s->nreloc ? rel_base + s_reloff : 0, machofp);
-            fwriteint32_t(s->nreloc, machofp);
+            fwriteint32_t(s->nreloc ? rel_base + s_reloff : 0, ofile);
+            fwriteint32_t(s->nreloc, ofile);
 
             offset += s->size;
             s_reloff += s->nreloc * MACHO_RELINFO64_SIZE;
         } else {
-            fwriteint32_t(0, machofp);
-            fwriteint32_t(0, machofp);
-            fwriteint32_t(0, machofp);
-            fwriteint32_t(0, machofp);
+            fwriteint32_t(0, ofile);
+            fwriteint32_t(0, ofile);
+            fwriteint32_t(0, ofile);
+            fwriteint32_t(0, ofile);
         }
                
                if (s->nreloc) {
@@ -1104,11 +1079,11 @@ static uint32_t macho_write_segment (uint64_t offset)
                                s->flags |= S_ATTR_EXT_RELOC;
                }
 
-        fwriteint32_t(s->flags, machofp);      /* flags */
-        fwriteint32_t(0, machofp);     /* reserved */
-        fwriteint32_t(0, machofp);     /* reserved */
+        fwriteint32_t(s->flags, ofile);      /* flags */
+        fwriteint32_t(0, ofile);     /* reserved */
+        fwriteint32_t(0, ofile);     /* reserved */
                
-               fwriteint32_t(0, machofp);     /* align */
+               fwriteint32_t(0, ofile);     /* align */
     }
 
     rel_padcnt64 = rel_base - offset;
@@ -1125,14 +1100,14 @@ static void macho_write_relocs (struct reloc *r)
     while (r) {
        uint32_t word2;
 
-       fwriteint32_t(r->addr, machofp); /* reloc offset */
+       fwriteint32_t(r->addr, ofile); /* reloc offset */
 
        word2 = r->snum;
        word2 |= r->pcrel << 24;
        word2 |= r->length << 25;
        word2 |= r->ext << 27;
        word2 |= r->type << 28;
-       fwriteint32_t(word2, machofp); /* reloc data */
+       fwriteint32_t(word2, ofile); /* reloc data */
        r = r->next;
     }
 }
@@ -1212,11 +1187,11 @@ static void macho_write_section (void)
        }
 
        /* dump the section data to file */
-       saa_fpwrite(s->data, machofp);
+       saa_fpwrite(s->data, ofile);
     }
 
     /* pad last section up to reloc entries on int64_t boundary */
-    fwritezero(rel_padcnt64, machofp);
+    fwritezero(rel_padcnt64, ofile);
 
     /* emit relocation entries */
     for (s = sects; s != NULL; s = s->next)
@@ -1236,10 +1211,10 @@ static void macho_write_symtab (void)
 
     for (sym = syms; sym != NULL; sym = sym->next) {
        if ((sym->type & N_EXT) == 0) {
-           fwriteint32_t(sym->strx, machofp);          /* string table entry number */
-           fwrite(&sym->type, 1, 1, machofp);  /* symbol type */
-           fwrite(&sym->sect, 1, 1, machofp);  /* section */
-           fwriteint16_t(sym->desc, machofp);  /* description */
+           fwriteint32_t(sym->strx, ofile);            /* string table entry number */
+           fwrite(&sym->type, 1, 1, ofile);    /* symbol type */
+           fwrite(&sym->sect, 1, 1, ofile);    /* section */
+           fwriteint16_t(sym->desc, ofile);    /* description */
 
            /* Fix up the symbol value now that we know the final section
               sizes.  */
@@ -1249,16 +1224,16 @@ static void macho_write_symtab (void)
                    sym->value += s->size;
            }
 
-           fwriteint64_t(sym->value, machofp); /* value (i.e. offset) */
+           fwriteint64_t(sym->value, ofile);   /* value (i.e. offset) */
        }
     }
 
     for (i = 0; i < nextdefsym; i++) {
        sym = extdefsyms[i];
-       fwriteint32_t(sym->strx, machofp);
-       fwrite(&sym->type, 1, 1, machofp);      /* symbol type */
-       fwrite(&sym->sect, 1, 1, machofp);      /* section */
-       fwriteint16_t(sym->desc, machofp);      /* description */
+       fwriteint32_t(sym->strx, ofile);
+       fwrite(&sym->type, 1, 1, ofile);        /* symbol type */
+       fwrite(&sym->sect, 1, 1, ofile);        /* section */
+       fwriteint16_t(sym->desc, ofile);        /* description */
 
        /* Fix up the symbol value now that we know the final section
           sizes.  */
@@ -1268,15 +1243,15 @@ static void macho_write_symtab (void)
                sym->value += s->size;
        }
 
-       fwriteint64_t(sym->value, machofp);     /* value (i.e. offset) */
+       fwriteint64_t(sym->value, ofile);       /* value (i.e. offset) */
     }
 
      for (i = 0; i < nundefsym; i++) {
         sym = undefsyms[i];
-        fwriteint32_t(sym->strx, machofp);
-        fwrite(&sym->type, 1, 1, machofp);     /* symbol type */
-        fwrite(&sym->sect, 1, 1, machofp);     /* section */
-        fwriteint16_t(sym->desc, machofp);     /* description */
+        fwriteint32_t(sym->strx, ofile);
+        fwrite(&sym->type, 1, 1, ofile);       /* symbol type */
+        fwrite(&sym->sect, 1, 1, ofile);       /* section */
+        fwriteint16_t(sym->desc, ofile);       /* description */
 
         // Fix up the symbol value now that we know the final section sizes.
         if (((sym->type & N_TYPE) == N_SECT) && (sym->sect != NO_SECT)) {
@@ -1285,7 +1260,7 @@ static void macho_write_symtab (void)
                 sym->value += s->size;
         }
 
-        fwriteint64_t(sym->value, machofp);    // value (i.e. offset)
+        fwriteint64_t(sym->value, ofile);      // value (i.e. offset)
      }
 
 }
@@ -1397,19 +1372,19 @@ static void macho_write (void)
     if (seg_nsects64 > 0)
        offset = macho_write_segment (offset);
     else
-        error(ERR_WARNING, "no sections?");
+        nasm_error(ERR_WARNING, "no sections?");
 
     if (nsyms > 0) {
         /* write out symbol command */
-        fwriteint32_t(LC_SYMTAB, machofp); /* cmd == LC_SYMTAB */
-        fwriteint32_t(MACHO_SYMCMD_SIZE, machofp); /* size of load command */
-        fwriteint32_t(offset, machofp);    /* symbol table offset */
-        fwriteint32_t(nsyms, machofp);     /* number of symbol
+        fwriteint32_t(LC_SYMTAB, ofile); /* cmd == LC_SYMTAB */
+        fwriteint32_t(MACHO_SYMCMD_SIZE, ofile); /* size of load command */
+        fwriteint32_t(offset, ofile);    /* symbol table offset */
+        fwriteint32_t(nsyms, ofile);     /* number of symbol
                                          ** table entries */
 
         offset += nsyms * MACHO_NLIST64_SIZE;
-        fwriteint32_t(offset, machofp);    /* string table offset */
-        fwriteint32_t(strslen, machofp);   /* string table size */
+        fwriteint32_t(offset, ofile);    /* string table offset */
+        fwriteint32_t(strslen, ofile);   /* string table size */
     }
 
     /* emit section data */
@@ -1423,7 +1398,7 @@ static void macho_write (void)
     /* we don't need to pad here since MACHO_NLIST64_SIZE == 16 */
 
     /* emit string table */
-    saa_fpwrite(strs, machofp);
+    saa_fpwrite(strs, ofile);
 }
 /* We do quite a bit here, starting with finalizing all of the data
    for the object file, writing, and then freeing all of the data from
@@ -1449,9 +1424,6 @@ static void macho_cleanup(int debuginfo)
     macho_calculate_sizes();
     macho_write();
 
-    /* done - yay! */
-    fclose(machofp);
-
     /* free up everything */
     while (sects->next) {
         s = sects;
@@ -1512,12 +1484,12 @@ struct ofmt of_macho64 = {
     &null_debug_form,
     macho_stdmac,
     macho_init,
-    macho_setinfo,
+    null_setinfo,
     macho_output,
     macho_symdef,
     macho_section,
     macho_segbase,
-    macho_directive,
+    null_directive,
     macho_filename,
     macho_cleanup
 };
index 73bec3c..89156b2 100644 (file)
@@ -47,6 +47,7 @@
 #include "nasm.h"
 #include "nasmlib.h"
 #include "stdscan.h"
+#include "eval.h"
 #include "output/outform.h"
 #include "output/outlib.h"
 
@@ -497,10 +498,6 @@ static void ori_null(ObjRecord * orp)
 
 static char obj_infile[FILENAME_MAX];
 
-static efunc error;
-static evalfunc evaluate;
-static ldfunc deflabel;
-static FILE *ofp;
 static int32_t first_seg;
 static bool any_segs;
 static int passtwo;
@@ -633,14 +630,10 @@ static struct Segment *current_seg;
 
 static int32_t obj_segment(char *, int, int *);
 static void obj_write_file(int debuginfo);
-static int obj_directive(char *, char *, int);
+static int obj_directive(enum directives, char *, int);
 
-static void obj_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void obj_init(void)
 {
-    ofp = fp;
-    error = errfunc;
-    evaluate = eval;
-    deflabel = ldef;
     first_seg = seg_alloc();
     any_segs = false;
     fpubhead = NULL;
@@ -677,7 +670,6 @@ static void obj_cleanup(int debuginfo)
 {
     obj_write_file(debuginfo);
     of_obj.current_dfmt->cleanup();
-    fclose(ofp);
     while (seghead) {
         struct Segment *segtmp = seghead;
         seghead = seghead->next;
@@ -803,7 +795,7 @@ static void obj_deflabel(char *name, int32_t segment,
             obj_entry_ofs = offset;
             return;
         }
-        error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
+        nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
     }
 
     /*
@@ -834,7 +826,7 @@ static void obj_deflabel(char *name, int32_t segment,
             pub->segment = (segment == NO_SEG ? 0 : segment & ~SEG_ABS);
         }
         if (special)
-            error(ERR_NONFATAL, "OBJ supports no special symbol features"
+            nasm_error(ERR_NONFATAL, "OBJ supports no special symbol features"
                   " for this symbol type");
         return;
     }
@@ -847,7 +839,7 @@ static void obj_deflabel(char *name, int32_t segment,
     if (!any_segs && segment == first_seg) {
         int tempint;            /* ignored */
         if (segment != obj_segment("__NASMDEFSEG", 2, &tempint))
-            error(ERR_PANIC, "strange segment conditions in OBJ driver");
+            nasm_error(ERR_PANIC, "strange segment conditions in OBJ driver");
     }
 
     for (seg = seghead; seg && is_global; seg = seg->next)
@@ -863,7 +855,7 @@ static void obj_deflabel(char *name, int32_t segment,
             loc->offset = offset;
 
             if (special)
-                error(ERR_NONFATAL,
+                nasm_error(ERR_NONFATAL,
                       "OBJ supports no special symbol features"
                       " for this symbol type");
             return;
@@ -930,7 +922,7 @@ static void obj_deflabel(char *name, int32_t segment,
             obj_ext_set_defwrt(ext, p);
             special += len;
             if (*special && *special != ':')
-                error(ERR_NONFATAL, "`:' expected in special symbol"
+                nasm_error(ERR_NONFATAL, "`:' expected in special symbol"
                       " text for `%s'", ext->name);
             else if (*special == ':')
                 special++;
@@ -944,7 +936,7 @@ static void obj_deflabel(char *name, int32_t segment,
             if (ext->commonsize)
                 ext->commonelem = 1;
             else
-                error(ERR_NONFATAL,
+                nasm_error(ERR_NONFATAL,
                       "`%s': `far' keyword may only be applied"
                       " to common variables\n", ext->name);
             special += 3;
@@ -953,7 +945,7 @@ static void obj_deflabel(char *name, int32_t segment,
             if (ext->commonsize)
                 ext->commonelem = 0;
             else
-                error(ERR_NONFATAL,
+                nasm_error(ERR_NONFATAL,
                       "`%s': `far' keyword may only be applied"
                       " to common variables\n", ext->name);
             special += 4;
@@ -976,17 +968,17 @@ static void obj_deflabel(char *name, int32_t segment,
                 stdscan_reset();
                 stdscan_bufptr = special;
                 tokval.t_type = TOKEN_INVALID;
-                e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL);
+                e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
                 if (e) {
                     if (!is_simple(e))
-                        error(ERR_NONFATAL, "cannot use relocatable"
+                        nasm_error(ERR_NONFATAL, "cannot use relocatable"
                               " expression as common-variable element size");
                     else
                         ext->commonelem = reloc_value(e);
                 }
                 special = stdscan_bufptr;
             } else {
-                error(ERR_NONFATAL,
+                nasm_error(ERR_NONFATAL,
                       "`%s': element-size specifications only"
                       " apply to common variables", ext->name);
                 while (*special && *special != ':')
@@ -1018,7 +1010,7 @@ static void obj_deflabel(char *name, int32_t segment,
     ext->index = ++externals;
 
     if (special && !used_special)
-        error(ERR_NONFATAL, "OBJ supports no special symbol features"
+        nasm_error(ERR_NONFATAL, "OBJ supports no special symbol features"
               " for this symbol type");
 }
 
@@ -1041,7 +1033,7 @@ static void obj_out(int32_t segto, const void *data,
      */
     if (segto == NO_SEG) {
         if (type != OUT_RESERVE)
-            error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
+            nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
                   " space");
         return;
     }
@@ -1053,7 +1045,7 @@ static void obj_out(int32_t segto, const void *data,
     if (!any_segs) {
         int tempint;            /* ignored */
         if (segto != obj_segment("__NASMDEFSEG", 2, &tempint))
-            error(ERR_PANIC, "strange segment conditions in OBJ driver");
+            nasm_error(ERR_PANIC, "strange segment conditions in OBJ driver");
     }
 
     /*
@@ -1063,7 +1055,7 @@ static void obj_out(int32_t segto, const void *data,
         if (seg->index == segto)
             break;
     if (!seg)
-        error(ERR_PANIC, "code directed to nonexistent segment?");
+        nasm_error(ERR_PANIC, "code directed to nonexistent segment?");
 
     orp = seg->orp;
     orp->parm[0] = seg->currentpos;
@@ -1087,10 +1079,10 @@ static void obj_out(int32_t segto, const void *data,
         int rsize;
 
         if (segment == NO_SEG && type != OUT_ADDRESS)
-            error(ERR_NONFATAL, "relative call to absolute address not"
+            nasm_error(ERR_NONFATAL, "relative call to absolute address not"
                   " supported by OBJ format");
         if (segment >= SEG_ABS)
-            error(ERR_NONFATAL, "far-absolute relocations not supported"
+            nasm_error(ERR_NONFATAL, "far-absolute relocations not supported"
                   " by OBJ format");
         ldata = *(int64_t *)data;
         if (type == OUT_REL2ADR) {
@@ -1116,7 +1108,7 @@ static void obj_out(int32_t segto, const void *data,
              */
             rsize = 2;
             if (ldata & 0xFFFF)
-                error(ERR_NONFATAL, "OBJ format cannot handle complex"
+                nasm_error(ERR_NONFATAL, "OBJ format cannot handle complex"
                       " dword-size segment base references");
         }
         if (segment != NO_SEG)
@@ -1146,7 +1138,7 @@ static void obj_write_fixup(ObjRecord * orp, int bytes,
     ObjRecord *forp;
 
     if (bytes == 1) {
-        error(ERR_NONFATAL, "`obj' output driver does not support"
+        nasm_error(ERR_NONFATAL, "`obj' output driver does not support"
               " one-byte relocations");
         return;
     }
@@ -1168,7 +1160,7 @@ static void obj_write_fixup(ObjRecord * orp, int bytes,
         locat = FIX_16_SELECTOR;
         seg--;
         if (bytes != 2)
-            error(ERR_PANIC, "OBJ: 4-byte segment base fixup got"
+            nasm_error(ERR_PANIC, "OBJ: 4-byte segment base fixup got"
                   " through sanity check");
     } else {
         base = false;
@@ -1214,7 +1206,7 @@ static void obj_write_fixup(ObjRecord * orp, int bytes,
             if (eb)
                 method = 6, e = eb->exts[i], tidx = e->index;
             else
-                error(ERR_PANIC,
+                nasm_error(ERR_PANIC,
                       "unrecognised segment value in obj_write_fixup");
         }
     }
@@ -1238,7 +1230,7 @@ static void obj_write_fixup(ObjRecord * orp, int bytes,
             else if (e->defwrt_type == DEFWRT_GROUP)
                 method |= 0x10, fidx = e->defwrt_ptr.grp->obj_index;
             else {
-                error(ERR_NONFATAL, "default WRT specification for"
+                nasm_error(ERR_NONFATAL, "default WRT specification for"
                       " external `%s' unresolved", e->name);
                 method |= 0x50, fidx = -1;      /* got to do _something_ */
             }
@@ -1273,7 +1265,7 @@ static void obj_write_fixup(ObjRecord * orp, int bytes,
                 if (eb)
                     method |= 0x20, fidx = eb->exts[i]->index;
                 else
-                    error(ERR_PANIC,
+                    nasm_error(ERR_PANIC,
                           "unrecognised WRT value in obj_write_fixup");
             }
         }
@@ -1342,7 +1334,7 @@ static int32_t obj_segment(char *name, int pass, int *bits)
             obj_idx++;
             if (!strcmp(seg->name, name)) {
                 if (attrs > 0 && pass == 1)
-                    error(ERR_WARNING, "segment attributes specified on"
+                    nasm_error(ERR_WARNING, "segment attributes specified on"
                           " redeclaration of segment: ignoring");
                 if (seg->use32)
                     *bits = 32;
@@ -1417,12 +1409,12 @@ static int32_t obj_segment(char *name, int pass, int *bits)
                     if (!strcmp(grp->name, "FLAT"))
                         break;
                 if (!grp) {
-                    obj_directive("group", "FLAT", 1);
+                    obj_directive(D_GROUP, "FLAT", 1);
                     for (grp = grphead; grp; grp = grp->next)
                         if (!strcmp(grp->name, "FLAT"))
                             break;
                     if (!grp)
-                        error(ERR_PANIC, "failure to define FLAT?!");
+                        nasm_error(ERR_PANIC, "failure to define FLAT?!");
                 }
                 seg->grp = grp;
             } else if (!nasm_strnicmp(p, "class=", 6))
@@ -1433,7 +1425,7 @@ static int32_t obj_segment(char *name, int pass, int *bits)
                 seg->align = readnum(p + 6, &rn_error);
                 if (rn_error) {
                     seg->align = 1;
-                    error(ERR_NONFATAL, "segment alignment should be"
+                    nasm_error(ERR_NONFATAL, "segment alignment should be"
                           " numeric");
                 }
                 switch ((int)seg->align) {
@@ -1445,7 +1437,7 @@ static int32_t obj_segment(char *name, int pass, int *bits)
                 case 4096:     /* PharLap extension */
                     break;
                 case 8:
-                    error(ERR_WARNING,
+                    nasm_error(ERR_WARNING,
                           "OBJ format does not support alignment"
                           " of 8: rounding up to 16");
                     seg->align = 16;
@@ -1453,7 +1445,7 @@ static int32_t obj_segment(char *name, int pass, int *bits)
                 case 32:
                 case 64:
                 case 128:
-                    error(ERR_WARNING,
+                    nasm_error(ERR_WARNING,
                           "OBJ format does not support alignment"
                           " of %d: rounding up to 256", seg->align);
                     seg->align = 256;
@@ -1461,13 +1453,13 @@ static int32_t obj_segment(char *name, int pass, int *bits)
                 case 512:
                 case 1024:
                 case 2048:
-                    error(ERR_WARNING,
+                    nasm_error(ERR_WARNING,
                           "OBJ format does not support alignment"
                           " of %d: rounding up to 4096", seg->align);
                     seg->align = 4096;
                     break;
                 default:
-                    error(ERR_NONFATAL, "invalid alignment value %d",
+                    nasm_error(ERR_NONFATAL, "invalid alignment value %d",
                           seg->align);
                     seg->align = 1;
                     break;
@@ -1475,7 +1467,7 @@ static int32_t obj_segment(char *name, int pass, int *bits)
             } else if (!nasm_strnicmp(p, "absolute=", 9)) {
                 seg->align = SEG_ABS + readnum(p + 9, &rn_error);
                 if (rn_error)
-                    error(ERR_NONFATAL, "argument to `absolute' segment"
+                    nasm_error(ERR_NONFATAL, "argument to `absolute' segment"
                           " attribute should be numeric");
             }
         }
@@ -1485,11 +1477,11 @@ static int32_t obj_segment(char *name, int pass, int *bits)
 
         obj_seg_needs_update = seg;
         if (seg->align >= SEG_ABS)
-            deflabel(name, NO_SEG, seg->align - SEG_ABS,
-                     NULL, false, false, &of_obj, error);
+            define_label(name, NO_SEG, seg->align - SEG_ABS,
+                        NULL, false, false);
         else
-            deflabel(name, seg->index + 1, 0L,
-                     NULL, false, false, &of_obj, error);
+            define_label(name, seg->index + 1, 0L,
+                        NULL, false, false);
         obj_seg_needs_update = NULL;
 
         /*
@@ -1502,10 +1494,10 @@ static int32_t obj_segment(char *name, int pass, int *bits)
                     grp->segs[i] = grp->segs[grp->nindices];
                     grp->segs[grp->nindices++].index = seg->obj_index;
                     if (seg->grp)
-                        error(ERR_WARNING,
-                              "segment `%s' is already part of"
-                              " a group: first one takes precedence",
-                              seg->name);
+                        nasm_error(ERR_WARNING,
+                                  "segment `%s' is already part of"
+                                  " a group: first one takes precedence",
+                                  seg->name);
                     else
                         seg->grp = grp;
                 }
@@ -1538,9 +1530,11 @@ static int32_t obj_segment(char *name, int pass, int *bits)
     }
 }
 
-static int obj_directive(char *directive, char *value, int pass)
+static int obj_directive(enum directives directive, char *value, int pass)
 {
-    if (!strcmp(directive, "group")) {
+    switch (directive) {
+    case D_GROUP:
+    {
         char *p, *q, *v;
         if (pass == 1) {
             struct Group *grp;
@@ -1566,7 +1560,7 @@ static int obj_directive(char *directive, char *value, int pass)
              * practice, so the sanity check has been removed.
              *
              * if (!*q) {
-             *     error(ERR_NONFATAL,"GROUP directive contains no segments");
+             *     nasm_error(ERR_NONFATAL,"GROUP directive contains no segments");
              *     return 1;
              * }
              */
@@ -1575,7 +1569,7 @@ static int obj_directive(char *directive, char *value, int pass)
             for (grp = grphead; grp; grp = grp->next) {
                 obj_idx++;
                 if (!strcmp(grp->name, v)) {
-                    error(ERR_NONFATAL, "group `%s' defined twice", v);
+                    nasm_error(ERR_NONFATAL, "group `%s' defined twice", v);
                     return 1;
                 }
             }
@@ -1589,8 +1583,7 @@ static int obj_directive(char *directive, char *value, int pass)
             grp->name = NULL;
 
             obj_grp_needs_update = grp;
-            deflabel(v, grp->index + 1, 0L,
-                     NULL, false, false, &of_obj, error);
+            define_label(v, grp->index + 1, 0L, NULL, false, false);
             obj_grp_needs_update = NULL;
 
             while (*q) {
@@ -1616,7 +1609,7 @@ static int obj_directive(char *directive, char *value, int pass)
                     grp->segs[grp->nentries++] = grp->segs[grp->nindices];
                     grp->segs[grp->nindices++].index = seg->obj_index;
                     if (seg->grp)
-                        error(ERR_WARNING,
+                        nasm_error(ERR_WARNING,
                               "segment `%s' is already part of"
                               " a group: first one takes precedence",
                               seg->name);
@@ -1650,11 +1643,12 @@ static int obj_directive(char *directive, char *value, int pass)
         }
         return 1;
     }
-    if (!strcmp(directive, "uppercase")) {
+    case D_UPPERCASE:
         obj_uppercase = true;
         return 1;
-    }
-    if (!strcmp(directive, "import")) {
+
+    case D_IMPORT:
+    {
         char *q, *extname, *libname, *impname;
 
         if (pass == 2)
@@ -1680,7 +1674,7 @@ static int obj_directive(char *directive, char *value, int pass)
         impname = q;
 
         if (!*extname || !*libname)
-            error(ERR_NONFATAL, "`import' directive requires symbol name"
+            nasm_error(ERR_NONFATAL, "`import' directive requires symbol name"
                   " and library name");
         else {
             struct ImpDef *imp;
@@ -1700,7 +1694,8 @@ static int obj_directive(char *directive, char *value, int pass)
 
         return 1;
     }
-    if (!strcmp(directive, "export")) {
+    case D_EXPORT:
+    {
         char *q, *extname, *intname, *v;
         struct ExpDef *export;
         int flags = 0;
@@ -1727,7 +1722,7 @@ static int obj_directive(char *directive, char *value, int pass)
         }
 
         if (!*intname) {
-            error(ERR_NONFATAL, "`export' directive requires export name");
+            nasm_error(ERR_NONFATAL, "`export' directive requires export name");
             return 1;
         }
         if (!*extname) {
@@ -1751,7 +1746,7 @@ static int obj_directive(char *directive, char *value, int pass)
                 bool err = false;
                 flags |= EXPDEF_MASK_PARMCNT & readnum(v + 5, &err);
                 if (err) {
-                    error(ERR_NONFATAL,
+                    nasm_error(ERR_NONFATAL,
                           "value `%s' for `parm' is non-numeric", v + 5);
                     return 1;
                 }
@@ -1759,7 +1754,7 @@ static int obj_directive(char *directive, char *value, int pass)
                 bool err = false;
                 ordinal = readnum(v, &err);
                 if (err) {
-                    error(ERR_NONFATAL,
+                    nasm_error(ERR_NONFATAL,
                           "unrecognised export qualifier `%s'", v);
                     return 1;
                 }
@@ -1777,7 +1772,9 @@ static int obj_directive(char *directive, char *value, int pass)
 
         return 1;
     }
-    return 0;
+    default:
+       return 0;
+    }
 }
 
 static int32_t obj_segbase(int32_t segment)
@@ -1837,10 +1834,10 @@ static int32_t obj_segbase(int32_t segment)
     return segment;             /* no special treatment */
 }
 
-static void obj_filename(char *inname, char *outname, efunc lerror)
+static void obj_filename(char *inname, char *outname)
 {
     strcpy(obj_infile, inname);
-    standard_extension(inname, outname, ".obj", lerror);
+    standard_extension(inname, outname, ".obj");
 }
 
 static void obj_write_file(int debuginfo)
@@ -1963,7 +1960,7 @@ static void obj_write_file(int debuginfo)
             /* acbp |= 0x00 */ ;
         else if (seg->align >= 4096) {
             if (seg->align > 4096)
-                error(ERR_NONFATAL, "segment `%s' requires more alignment"
+                nasm_error(ERR_NONFATAL, "segment `%s' requires more alignment"
                       " than OBJ format supports", seg->name);
             acbp |= 0xC0;       /* PharLap extension */
         } else if (seg->align >= 256) {
@@ -1998,7 +1995,7 @@ static void obj_write_file(int debuginfo)
 
         if (grp->nindices != grp->nentries) {
             for (i = grp->nindices; i < grp->nentries; i++) {
-                error(ERR_NONFATAL, "group `%s' contains undefined segment"
+                nasm_error(ERR_NONFATAL, "group `%s' contains undefined segment"
                       " `%s'", grp->name, grp->segs[i].name);
                 nasm_free(grp->segs[i].name);
                 grp->segs[i].name = NULL;
@@ -2232,7 +2229,7 @@ static void obj_write_file(int debuginfo)
             }
         }
         if (!seg)
-            error(ERR_NONFATAL, "entry point is not in this module");
+            nasm_error(ERR_NONFATAL, "entry point is not in this module");
     }
 
     /*
@@ -2319,25 +2316,20 @@ static void obj_fwrite(ObjRecord * orp)
     cksum = orp->type;
     if (orp->x_size == 32)
         cksum |= 1;
-    fputc(cksum, ofp);
+    fputc(cksum, ofile);
     len = orp->committed + 1;
     cksum += (len & 0xFF) + ((len >> 8) & 0xFF);
-    fwriteint16_t(len, ofp);
-    fwrite(orp->buf, 1, len - 1, ofp);
+    fwriteint16_t(len, ofile);
+    fwrite(orp->buf, 1, len - 1, ofile);
     for (ptr = orp->buf; --len; ptr++)
         cksum += *ptr;
-    fputc((-cksum) & 0xFF, ofp);
+    fputc((-cksum) & 0xFF, ofile);
 }
 
 extern macros_t obj_stdmac[];
 
-void dbgbi_init(struct ofmt *of, void *id, FILE * fp, efunc error)
+void dbgbi_init(void)
 {
-    (void)of;
-    (void)id;
-    (void)fp;
-    (void)error;
-
     fnhead = NULL;
     fntail = &fnhead;
     arrindex = ARRAYBOT;
@@ -2389,7 +2381,7 @@ static void dbgbi_linnum(const char *lnfname, int32_t lineno, int32_t segto)
     if (!any_segs) {
         int tempint;            /* ignored */
         if (segto != obj_segment("__NASMDEFSEG", 2, &tempint))
-            error(ERR_PANIC, "strange segment conditions in OBJ driver");
+            nasm_error(ERR_PANIC, "strange segment conditions in OBJ driver");
     }
 
     /*
@@ -2399,7 +2391,7 @@ static void dbgbi_linnum(const char *lnfname, int32_t lineno, int32_t segto)
         if (seg->index == segto)
             break;
     if (!seg)
-        error(ERR_PANIC, "lineno directed to nonexistent segment?");
+        nasm_error(ERR_PANIC, "lineno directed to nonexistent segment?");
 
 /*    for (fn = fnhead; fn; fn = fnhead->next) */
     for (fn = fnhead; fn; fn = fn->next)        /* fbk - Austin Lunnen - John Fine */
index fef18fb..6649c16 100644 (file)
@@ -509,7 +509,6 @@ static void rdf_cleanup(int debuginfo)
     freemembuf(header);
     freemembuf(seg[0]);
     freemembuf(seg[1]);
-    fclose(ofile);
 }
 
 static int32_t rdf_segbase(int32_t segment)
index 578c923..6d95803 100644 (file)
@@ -97,10 +97,6 @@ static int segmenttypenumbers[COUNT_SEGTYPES] = {
 static struct SAA *seg[RDF_MAXSEGS];    /* seg 0 = code, seg 1 = data */
 static struct SAA *header;      /* relocation/import/export records */
 
-static FILE *ofile;
-
-static efunc error;
-
 static struct seginfo {
     char *segname;
     int segnumber;
@@ -114,13 +110,10 @@ static int nsegments;
 static int32_t bsslength;
 static int32_t headerlength;
 
-static void rdf2_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void rdf2_init(void)
 {
     int segtext, segdata, segbss;
 
-    (void)ldef;
-    (void)eval;
-
     maxbits = 64;
 
     /* set up the initial segments */
@@ -144,9 +137,6 @@ static void rdf2_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
 
     nsegments = 3;
 
-    ofile = fp;
-    error = errfunc;
-
     seg[0] = saa_init(1L);
     seg[1] = saa_init(1L);
     seg[2] = NULL;              /* special case! */
@@ -157,7 +147,7 @@ static void rdf2_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
     segdata = seg_alloc();
     segbss = seg_alloc();
     if (segtext != 0 || segdata != 2 || segbss != 4)
-        error(ERR_PANIC,
+        nasm_error(ERR_PANIC,
               "rdf segment numbers not allocated as expected (%d,%d,%d)",
               segtext, segdata, segbss);
     bsslength = 0;
@@ -200,7 +190,7 @@ static int32_t rdf2_section_names(char *name, int pass, int *bits)
 
             reserved = readnum(q, &err);
             if (err) {
-                error(ERR_NONFATAL,
+                nasm_error(ERR_NONFATAL,
                       "value following comma must be numeric");
                 reserved = 0;
             }
@@ -217,7 +207,7 @@ static int32_t rdf2_section_names(char *name, int pass, int *bits)
         if (code == -1) {       /* didn't find anything */
             code = readnum(p, &err);
             if (err) {
-                error(ERR_NONFATAL, "unrecognised RDF segment type (%s)",
+                nasm_error(ERR_NONFATAL, "unrecognised RDF segment type (%s)",
                       p);
                 code = 3;
             }
@@ -226,7 +216,7 @@ static int32_t rdf2_section_names(char *name, int pass, int *bits)
     for (i = 0; i < nsegments; i++) {
         if (!strcmp(name, segments[i].segname)) {
             if (code != -1 || reserved != 0)
-                error(ERR_NONFATAL, "segment attributes specified on"
+                nasm_error(ERR_NONFATAL, "segment attributes specified on"
                       " redeclaration of segment");
             return segments[i].segnumber * 2;
         }
@@ -235,11 +225,11 @@ static int32_t rdf2_section_names(char *name, int pass, int *bits)
     /* declaring a new segment! */
 
     if (code == -1) {
-        error(ERR_NONFATAL, "new segment declared without type code");
+        nasm_error(ERR_NONFATAL, "new segment declared without type code");
         code = 3;
     }
     if (nsegments == RDF_MAXSEGS) {
-        error(ERR_FATAL, "reached compiled-in maximum segment limit (%d)",
+        nasm_error(ERR_FATAL, "reached compiled-in maximum segment limit (%d)",
               RDF_MAXSEGS);
         return NO_SEG;
     }
@@ -247,7 +237,7 @@ static int32_t rdf2_section_names(char *name, int pass, int *bits)
     segments[nsegments].segname = nasm_strdup(name);
     i = seg_alloc();
     if (i % 2 != 0)
-        error(ERR_PANIC, "seg_alloc() returned odd number");
+        nasm_error(ERR_PANIC, "seg_alloc() returned odd number");
     segments[nsegments].segnumber = i >> 1;
     segments[nsegments].segtype = code;
     segments[nsegments].segreserved = reserved;
@@ -396,11 +386,11 @@ static void rdf2_deflabel(char *name, int32_t segment, int64_t offset,
 
     /* Check if the label length is OK */
     if ((len = strlen(name)) >= EXIM_LABEL_MAX) {
-        error(ERR_NONFATAL, "label size exceeds %d bytes", EXIM_LABEL_MAX);
+        nasm_error(ERR_NONFATAL, "label size exceeds %d bytes", EXIM_LABEL_MAX);
         return;
     }
     if (!len) {
-        error(ERR_NONFATAL, "zero-length label");
+        nasm_error(ERR_NONFATAL, "zero-length label");
         return;
     }
 
@@ -421,10 +411,10 @@ static void rdf2_deflabel(char *name, int32_t segment, int64_t offset,
             bool err;
             ci.align = readnum(special, &err);
             if (err)
-                error(ERR_NONFATAL, "alignment constraint `%s' is not a"
+                nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a"
                       " valid number", special);
             else if ((ci.align | (ci.align - 1)) != 2 * ci.align - 1)
-                error(ERR_NONFATAL, "alignment constraint `%s' is not a"
+                nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a"
                       " power of two", special);
         }
         write_common_rec(&ci);
@@ -460,13 +450,13 @@ static void rdf2_deflabel(char *name, int32_t segment, int64_t offset,
                        !nasm_stricmp(special, "object")) {
                 symflags |= SYM_DATA;
             } else
-                error(ERR_NONFATAL, "unrecognised symbol type `%s'",
+                nasm_error(ERR_NONFATAL, "unrecognised symbol type `%s'",
                       special);
         }
     }
 
     if (name[0] == '.' && name[1] == '.' && name[2] != '@') {
-        error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
+        nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
         return;
     }
 
@@ -478,7 +468,7 @@ static void rdf2_deflabel(char *name, int32_t segment, int64_t offset,
     if (i >= nsegments) {       /* EXTERN declaration */
         ri.type = farsym ? RDFREC_FARIMPORT : RDFREC_IMPORT;
         if (symflags & SYM_GLOBAL)
-            error(ERR_NONFATAL,
+            nasm_error(ERR_NONFATAL,
                   "symbol type conflict - EXTERN cannot be EXPORT");
         ri.flags = symflags;
         ri.segment = segment;
@@ -488,7 +478,7 @@ static void rdf2_deflabel(char *name, int32_t segment, int64_t offset,
     } else if (is_global) {
         r.type = RDFREC_GLOBAL; /* GLOBAL declaration */
         if (symflags & SYM_IMPORT)
-            error(ERR_NONFATAL,
+            nasm_error(ERR_NONFATAL,
                   "symbol type conflict - GLOBAL cannot be IMPORT");
         r.flags = symflags;
         r.segment = segment;
@@ -509,7 +499,7 @@ static void membufwrite(int segment, const void *data, int bytes)
             break;
     }
     if (i == nsegments)
-        error(ERR_PANIC, "can't find segment %d", segment);
+        nasm_error(ERR_PANIC, "can't find segment %d", segment);
 
     if (bytes < 0) {
         b = buf;
@@ -532,7 +522,7 @@ static int getsegmentlength(int segment)
             break;
     }
     if (i == nsegments)
-        error(ERR_PANIC, "can't find segment %d", segment);
+        nasm_error(ERR_PANIC, "can't find segment %d", segment);
 
     return segments[i].seglength;
 }
@@ -547,7 +537,7 @@ static void rdf2_out(int32_t segto, const void *data,
 
     if (segto == NO_SEG) {
         if (type != OUT_RESERVE)
-            error(ERR_NONFATAL,
+            nasm_error(ERR_NONFATAL,
                   "attempt to assemble code in ABSOLUTE space");
         return;
     }
@@ -559,18 +549,18 @@ static void rdf2_out(int32_t segto, const void *data,
             break;
     }
     if (seg >= nsegments) {
-        error(ERR_NONFATAL,
+        nasm_error(ERR_NONFATAL,
               "specified segment not supported by rdf output format");
         return;
     }
 
     if (wrt != NO_SEG) {
         wrt = NO_SEG;           /* continue to do _something_ */
-        error(ERR_NONFATAL, "WRT not supported by rdf output format");
+        nasm_error(ERR_NONFATAL, "WRT not supported by rdf output format");
     }
 
     if (segto == 2 && type != OUT_RESERVE) {
-        error(ERR_NONFATAL, "BSS segments may not be initialized");
+        nasm_error(ERR_NONFATAL, "BSS segments may not be initialized");
 
         /* just reserve the space for now... */
 
@@ -589,7 +579,7 @@ static void rdf2_out(int32_t segto, const void *data,
                 membufwrite(segto, databuf, 1);
     } else if (type == OUT_RAWDATA) {
         if (segment != NO_SEG)
-            error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
+            nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
 
         membufwrite(segto, data, size);
     } else if (type == OUT_ADDRESS) {
@@ -617,7 +607,7 @@ static void rdf2_out(int32_t segto, const void *data,
         membufwrite(segto, databuf, size);
     } else if (type == OUT_REL2ADR) {
         if (segment == segto)
-            error(ERR_PANIC, "intra-segment OUT_REL2ADR");
+            nasm_error(ERR_PANIC, "intra-segment OUT_REL2ADR");
 
         rr.reclen = 8;
         rr.offset = getsegmentlength(segto);    /* current offset */
@@ -649,9 +639,9 @@ static void rdf2_out(int32_t segto, const void *data,
         membufwrite(segto, &rr.offset, -2);
     } else if (type == OUT_REL4ADR) {
         if ((segment == segto) && (globalbits != 64))
-            error(ERR_PANIC, "intra-segment OUT_REL4ADR");
+            nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR");
         if (segment != NO_SEG && segment % 2) {
-            error(ERR_PANIC, "erm... 4 byte segment base ref?");
+            nasm_error(ERR_PANIC, "erm... 4 byte segment base ref?");
         }
 
         rr.type = RDFREC_RELOC; /* type signature */
@@ -723,8 +713,6 @@ static void rdf2_cleanup(int debuginfo)
     fwriteint32_t(0, ofile);
     fwriteint32_t(0, ofile);
     fwriteint16_t(0, ofile);
-
-    fclose(ofile);
 }
 
 static int32_t rdf2_segbase(int32_t segment)
@@ -735,17 +723,17 @@ static int32_t rdf2_segbase(int32_t segment)
 /*
  * Handle RDOFF2 specific directives
  */
-static int rdf2_directive(char *directive, char *value, int pass)
+static int rdf2_directive(enum directives directive, char *value, int pass)
 {
-    int n;
-
-    /* Check if the name length is OK */
-    if ((n = strlen(value)) >= MODLIB_NAME_MAX) {
-        error(ERR_NONFATAL, "name size exceeds %d bytes", MODLIB_NAME_MAX);
-        return 0;
-    }
-
-    if (!strcmp(directive, "library")) {
+    size_t n;
+
+    switch (directive) {
+    case D_LIBRARY:
+       n = strlen(value);
+       if (n >= MODLIB_NAME_MAX) {
+           nasm_error(ERR_NONFATAL, "name size exceeds %d bytes", MODLIB_NAME_MAX);
+           return 1;
+       }
         if (pass == 1) {
             struct DLLRec r;
             r.type = RDFREC_DLL;
@@ -754,9 +742,12 @@ static int rdf2_directive(char *directive, char *value, int pass)
             write_dll_rec(&r);
         }
         return 1;
-    }
-
-    if (!strcmp(directive, "module")) {
+       
+    case D_MODULE:
+       if ((n = strlen(value)) >= MODLIB_NAME_MAX) {
+           nasm_error(ERR_NONFATAL, "name size exceeds %d bytes", MODLIB_NAME_MAX);
+           return 1;
+       }
         if (pass == 1) {
             struct ModRec r;
             r.type = RDFREC_MODNAME;
@@ -765,14 +756,15 @@ static int rdf2_directive(char *directive, char *value, int pass)
             write_modname_rec(&r);
         }
         return 1;
-    }
 
-    return 0;
+    default:
+       return 0;
+    }
 }
 
-static void rdf2_filename(char *inname, char *outname, efunc error)
+static void rdf2_filename(char *inname, char *outname)
 {
-    standard_extension(inname, outname, ".rdf", error);
+    standard_extension(inname, outname, ".rdf");
 }
 
 extern macros_t rdf2_stdmac[];
index 79da372..2ff6e36 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -48,6 +48,7 @@
 #include "insns.h"
 #include "nasmlib.h"
 #include "stdscan.h"
+#include "eval.h"
 #include "parser.h"
 #include "float.h"
 #include "tables.h"
@@ -60,13 +61,10 @@ static int is_comma_next(void);
 
 static int i;
 static struct tokenval tokval;
-static efunc error;
-static struct ofmt *outfmt;     /* Structure of addresses of output routines */
 static struct location *location;         /* Pointer to current line's segment,offset */
 
-void parser_global_info(struct ofmt *output, struct location * locp)
+void parser_global_info(struct location * locp)
 {
-    outfmt = output;
     location = locp;
 }
 
@@ -100,7 +98,7 @@ static int prefix_slot(enum prefixes prefix)
     case P_ASP:
        return PPS_ASIZE;
     default:
-       error(ERR_PANIC, "Invalid value %d passed to prefix_slot()", prefix);
+       nasm_error(ERR_PANIC, "Invalid value %d passed to prefix_slot()", prefix);
        return -1;
     }
 }
@@ -141,7 +139,7 @@ static void process_size_override(insn * result, int operand)
            result->oprs[operand].type |= BITS128;
            break;
        default:
-           error(ERR_NONFATAL,
+           nasm_error(ERR_NONFATAL,
                  "invalid operand size specification");
            break;
        }
@@ -166,7 +164,7 @@ static void process_size_override(insn * result, int operand)
        case P_A64:
            if (result->prefixes[PPS_ASIZE] &&
                result->prefixes[PPS_ASIZE] != tokval.t_integer)
-               error(ERR_NONFATAL,
+               nasm_error(ERR_NONFATAL,
                      "conflicting address size specifications");
            else
                result->prefixes[PPS_ASIZE] = tokval.t_integer;
@@ -185,15 +183,14 @@ static void process_size_override(insn * result, int operand)
            result->oprs[operand].eaflags |= EAF_WORDOFFS;
            break;
        default:
-           error(ERR_NONFATAL, "invalid size specification in"
+           nasm_error(ERR_NONFATAL, "invalid size specification in"
                  " effective address");
            break;
        }
     }
 }
 
-insn *parse_line(int pass, char *buffer, insn * result,
-                 efunc errfunc, evalfunc evaluate, ldfunc ldef)
+insn *parse_line(int pass, char *buffer, insn *result, ldfunc ldef)
 {
     int operand;
     int critical;
@@ -206,7 +203,6 @@ insn *parse_line(int pass, char *buffer, insn * result,
 restart_parse:
     first = true;
     result->forw_ref = false;
-    error = errfunc;
 
     stdscan_reset();
     stdscan_bufptr = buffer;
@@ -222,7 +218,7 @@ restart_parse:
     }
     if (i != TOKEN_ID && i != TOKEN_INSN && i != TOKEN_PREFIX &&
         (i != TOKEN_REG || (REG_SREG & ~nasm_reg_flags[tokval.t_integer]))) {
-        error(ERR_NONFATAL, "label or instruction expected"
+        nasm_error(ERR_NONFATAL, "label or instruction expected"
               " at start of line");
         result->opcode = -1;
         return result;
@@ -236,7 +232,7 @@ restart_parse:
         if (i == ':') {         /* skip over the optional colon */
             i = stdscan(NULL, &tokval);
         } else if (i == 0) {
-            error(ERR_WARNING | ERR_WARN_OL | ERR_PASS1,
+            nasm_error(ERR_WARNING | ERR_WARN_OL | ERR_PASS1,
                   "label alone on a line without a colon might be in error");
         }
         if (i != TOKEN_INSN || tokval.t_integer != I_EQU) {
@@ -248,7 +244,7 @@ restart_parse:
              * am still not certain.
              */
             ldef(result->label, in_abs_seg ? abs_seg : location->segment,
-                 location->offset, NULL, true, false, outfmt, errfunc);
+                 location->offset, NULL, true, false);
         }
     }
 
@@ -274,20 +270,20 @@ restart_parse:
 
             i = stdscan(NULL, &tokval);
             value =
-                evaluate(stdscan, NULL, &tokval, NULL, pass0, error, NULL);
+                evaluate(stdscan, NULL, &tokval, NULL, pass0, nasm_error, NULL);
             i = tokval.t_type;
             if (!value) {       /* but, error in evaluator */
                 result->opcode = -1;    /* unrecoverable parse error: */
                 return result;  /* ignore this instruction */
             }
             if (!is_simple(value)) {
-                error(ERR_NONFATAL,
+                nasm_error(ERR_NONFATAL,
                       "non-constant argument supplied to TIMES");
                 result->times = 1L;
             } else {
                 result->times = value->value;
                 if (value->value < 0 && pass0 == 2) {
-                    error(ERR_NONFATAL, "TIMES value %d is negative",
+                    nasm_error(ERR_NONFATAL, "TIMES value %d is negative",
                           value->value);
                     result->times = 0;
                 }
@@ -296,10 +292,10 @@ restart_parse:
            int slot = prefix_slot(tokval.t_integer);
            if (result->prefixes[slot]) {
                if (result->prefixes[slot] == tokval.t_integer)
-                   error(ERR_WARNING,
+                   nasm_error(ERR_WARNING,
                      "instruction has redundant prefixes");
                else
-                   error(ERR_NONFATAL,
+                   nasm_error(ERR_NONFATAL,
                      "instruction has conflicting prefixes");
            }
            result->prefixes[slot] = tokval.t_integer;
@@ -328,7 +324,7 @@ restart_parse:
             result->oprs[0].segment = result->oprs[0].wrt = NO_SEG;
             return result;
         } else {
-            error(ERR_NONFATAL, "parser: instruction expected");
+            nasm_error(ERR_NONFATAL, "parser: instruction expected");
             result->opcode = -1;
             return result;
         }
@@ -397,7 +393,7 @@ restart_parse:
                    i = stdscan(NULL, &tokval);
                }
                if (i != TOKEN_STR) {
-                   error(ERR_NONFATAL,
+                   nasm_error(ERR_NONFATAL,
                          "%s must be followed by a string constant",
                          funcname);
                        eop->type = EOT_NOTHING;
@@ -407,14 +403,14 @@ restart_parse:
                        string_transform(tokval.t_charptr, tokval.t_inttwo,
                                         &eop->stringval, func);
                    if (eop->stringlen == (size_t)-1) {
-                       error(ERR_NONFATAL, "invalid string for transform");
+                       nasm_error(ERR_NONFATAL, "invalid string for transform");
                        eop->type = EOT_NOTHING;
                    }
                }
                if (parens && i && i != ')') {
                    i = stdscan(NULL, &tokval);
                    if (i != ')') {
-                       error(ERR_NONFATAL, "unterminated %s function",
+                       nasm_error(ERR_NONFATAL, "unterminated %s function",
                              funcname);
                    }
                }
@@ -456,12 +452,12 @@ restart_parse:
                    eop->stringlen = 16;
                    break;
                case I_DY:
-                   error(ERR_NONFATAL, "floating-point constant"
+                   nasm_error(ERR_NONFATAL, "floating-point constant"
                          " encountered in DY instruction");
                    eop->stringlen = 0;
                    break;
                default:
-                   error(ERR_NONFATAL, "floating-point constant"
+                   nasm_error(ERR_NONFATAL, "floating-point constant"
                          " encountered in unknown instruction");
                    /*
                     * fix suggested by Pedro Gimeno... original line
@@ -478,7 +474,7 @@ restart_parse:
                if (!eop->stringlen ||
                    !float_const(tokval.t_charptr, sign,
                                 (uint8_t *)eop->stringval,
-                                eop->stringlen, error))
+                                eop->stringlen, nasm_error))
                    eop->type = EOT_NOTHING;
                i = stdscan(NULL, &tokval); /* eat the comma */
            } else {
@@ -487,7 +483,7 @@ restart_parse:
 
            is_expression:
                 value = evaluate(stdscan, NULL, &tokval, NULL,
-                                 critical, error, NULL);
+                                 critical, nasm_error, NULL);
                 i = tokval.t_type;
                 if (!value) {   /* error in evaluator */
                     result->opcode = -1;        /* unrecoverable parse error: */
@@ -503,7 +499,7 @@ restart_parse:
                     eop->segment = reloc_seg(value);
                     eop->wrt = reloc_wrt(value);
                 } else {
-                    error(ERR_NONFATAL,
+                    nasm_error(ERR_NONFATAL,
                           "operand %d: expression is not simple"
                           " or relocatable", oper_num);
                 }
@@ -518,7 +514,7 @@ restart_parse:
             if (i == 0)         /* also could be EOL */
                 break;
             if (i != ',') {
-                error(ERR_NONFATAL, "comma expected after operand %d",
+                nasm_error(ERR_NONFATAL, "comma expected after operand %d",
                       oper_num);
                 result->opcode = -1;    /* unrecoverable parse error: */
                 return result;  /* ignore this instruction */
@@ -532,18 +528,18 @@ restart_parse:
              * operands.
              */
             if (!result->eops || result->eops->type != EOT_DB_STRING)
-                error(ERR_NONFATAL, "`incbin' expects a file name");
+                nasm_error(ERR_NONFATAL, "`incbin' expects a file name");
             else if (result->eops->next &&
                      result->eops->next->type != EOT_DB_NUMBER)
-                error(ERR_NONFATAL, "`incbin': second parameter is",
+                nasm_error(ERR_NONFATAL, "`incbin': second parameter is",
                       " non-numeric");
             else if (result->eops->next && result->eops->next->next &&
                      result->eops->next->next->type != EOT_DB_NUMBER)
-                error(ERR_NONFATAL, "`incbin': third parameter is",
+                nasm_error(ERR_NONFATAL, "`incbin': third parameter is",
                       " non-numeric");
             else if (result->eops->next && result->eops->next->next &&
                      result->eops->next->next->next)
-                error(ERR_NONFATAL,
+                nasm_error(ERR_NONFATAL,
                       "`incbin': more than three parameters");
             else
                 return result;
@@ -554,7 +550,7 @@ restart_parse:
             result->opcode = -1;
             return result;
         } else /* DB ... */ if (oper_num == 0)
-            error(ERR_WARNING | ERR_PASS1,
+            nasm_error(ERR_WARNING | ERR_PASS1,
                   "no operand for data declaration");
         else
             result->operands = oper_num;
@@ -638,7 +634,7 @@ restart_parse:
                 result->oprs[operand].type |= SHORT;
                 break;
             default:
-                error(ERR_NONFATAL, "invalid operand size specification");
+                nasm_error(ERR_NONFATAL, "invalid operand size specification");
             }
             i = stdscan(NULL, &tokval);
         }
@@ -658,17 +654,17 @@ restart_parse:
 
         if ((result->oprs[operand].type & FAR) && !mref &&
             result->opcode != I_JMP && result->opcode != I_CALL) {
-            error(ERR_NONFATAL, "invalid use of FAR operand specifier");
+            nasm_error(ERR_NONFATAL, "invalid use of FAR operand specifier");
         }
 
         value = evaluate(stdscan, NULL, &tokval,
                          &result->oprs[operand].opflags,
-                         critical, error, &hints);
+                         critical, nasm_error, &hints);
         i = tokval.t_type;
         if (result->oprs[operand].opflags & OPFLAG_FORWARD) {
             result->forw_ref = true;
         }
-        if (!value) {           /* error in evaluator */
+        if (!value) {           /* nasm_error in evaluator */
             result->opcode = -1;        /* unrecoverable parse error: */
             return result;      /* ignore this instruction */
         }
@@ -678,9 +674,9 @@ restart_parse:
              */
             if (value[1].type != 0 || value->value != 1 ||
                 REG_SREG & ~nasm_reg_flags[value->type])
-                error(ERR_NONFATAL, "invalid segment override");
+                nasm_error(ERR_NONFATAL, "invalid segment override");
             else if (result->prefixes[PPS_SEG])
-                error(ERR_NONFATAL,
+                nasm_error(ERR_NONFATAL,
                       "instruction has conflicting segment overrides");
             else {
                result->prefixes[PPS_SEG] = value->type;
@@ -695,7 +691,7 @@ restart_parse:
             }
             value = evaluate(stdscan, NULL, &tokval,
                              &result->oprs[operand].opflags,
-                             critical, error, &hints);
+                             critical, nasm_error, &hints);
             i = tokval.t_type;
             if (result->oprs[operand].opflags & OPFLAG_FORWARD) {
                 result->forw_ref = true;
@@ -710,18 +706,18 @@ restart_parse:
         recover = false;
         if (mref && bracket) {  /* find ] at the end */
             if (i != ']') {
-                error(ERR_NONFATAL, "parser: expecting ]");
+                nasm_error(ERR_NONFATAL, "parser: expecting ]");
                 recover = true;
             } else {            /* we got the required ] */
                 i = stdscan(NULL, &tokval);
                 if (i != 0 && i != ',') {
-                    error(ERR_NONFATAL, "comma or end of line expected");
+                    nasm_error(ERR_NONFATAL, "comma or end of line expected");
                     recover = true;
                 }
             }
         } else {                /* immediate operand */
             if (i != 0 && i != ',' && i != ':') {
-                error(ERR_NONFATAL, "comma, colon or end of line expected");
+                nasm_error(ERR_NONFATAL, "comma, colon or end of line expected");
                 recover = true;
             } else if (i == ':') {
                 result->oprs[operand].type |= COLON;
@@ -757,7 +753,7 @@ restart_parse:
                     i = e->type, s = e->value;  /* second has to be indexreg */
 
                 else if (e->value != 1) {       /* If both want to be index */
-                    error(ERR_NONFATAL,
+                    nasm_error(ERR_NONFATAL,
                           "beroset-p-592-invalid effective address");
                     result->opcode = -1;
                     return result;
@@ -767,7 +763,7 @@ restart_parse:
             }
             if (e->type != 0) { /* is there an offset? */
                 if (e->type <= EXPR_REG_END) {  /* in fact, is there an error? */
-                    error(ERR_NONFATAL,
+                    nasm_error(ERR_NONFATAL,
                           "beroset-p-603-invalid effective address");
                     result->opcode = -1;
                     return result;
@@ -793,7 +789,7 @@ restart_parse:
                          * Look for a segment base type.
                          */
                         if (e->type && e->type < EXPR_SEGBASE) {
-                            error(ERR_NONFATAL,
+                            nasm_error(ERR_NONFATAL,
                                   "beroset-p-630-invalid effective address");
                             result->opcode = -1;
                             return result;
@@ -801,7 +797,7 @@ restart_parse:
                         while (e->type && e->value == 0)
                             e++;
                         if (e->type && e->value != 1) {
-                            error(ERR_NONFATAL,
+                            nasm_error(ERR_NONFATAL,
                                   "beroset-p-637-invalid effective address");
                             result->opcode = -1;
                             return result;
@@ -815,7 +811,7 @@ restart_parse:
                         while (e->type && e->value == 0)
                             e++;
                         if (e->type) {
-                            error(ERR_NONFATAL,
+                            nasm_error(ERR_NONFATAL,
                                   "beroset-p-650-invalid effective address");
                             result->opcode = -1;
                             return result;
@@ -829,7 +825,7 @@ restart_parse:
             }
 
             if (e->type != 0) { /* there'd better be nothing left! */
-                error(ERR_NONFATAL,
+                nasm_error(ERR_NONFATAL,
                       "beroset-p-663-invalid effective address");
                 result->opcode = -1;
                 return result;
@@ -890,7 +886,7 @@ restart_parse:
                unsigned int rs;
 
                 if (value->type >= EXPR_SIMPLE || value->value != 1) {
-                    error(ERR_NONFATAL, "invalid operand type");
+                    nasm_error(ERR_NONFATAL, "invalid operand type");
                     result->opcode = -1;
                     return result;
                 }
@@ -900,7 +896,7 @@ restart_parse:
                  */
                 for (i = 1; value[i].type; i++)
                     if (value[i].value) {
-                        error(ERR_NONFATAL, "invalid operand type");
+                        nasm_error(ERR_NONFATAL, "invalid operand type");
                         result->opcode = -1;
                         return result;
                     }
@@ -921,7 +917,7 @@ restart_parse:
                 result->oprs[operand].basereg = value->type;
 
                 if (rs && (result->oprs[operand].type & SIZE_MASK) != rs)
-                    error(ERR_WARNING | ERR_PASS1,
+                    nasm_error(ERR_WARNING | ERR_PASS1,
                           "register size specification ignored");
             }
         }
index 7e5a9f9..9b2b6d6 100644 (file)
--- a/parser.h
+++ b/parser.h
@@ -39,9 +39,8 @@
 #ifndef NASM_PARSER_H
 #define NASM_PARSER_H
 
-void parser_global_info(struct ofmt *output, struct location * locp);
-insn *parse_line(int pass, char *buffer, insn * result,
-                 efunc error, evalfunc evaluate, ldfunc ldef);
-void cleanup_insn(insn * instruction);
+void parser_global_info(struct location *locp);
+insn *parse_line(int pass, char *buffer, insn *result, ldfunc ldef);
+void cleanup_insn(insn *instruction);
 
 #endif
index 2dac63e..76ca360 100644 (file)
--- a/pptok.dat
+++ b/pptok.dat
@@ -51,6 +51,7 @@
 %clear
 %define
 %defstr
+%deftok
 %depend
 %elif*
 %else
 %endmacro
 %endrep
 %error
+%exitmacro
 %exitrep
 %fatal
 %iassign
 %idefine
 %idefstr
+%ideftok
 %if*
 %imacro
+%irmacro
 %include
 %ixdefine
 %line
@@ -76,6 +80,7 @@
 %push
 %rep
 %repl
+%rmacro
 %rotate
 %stacksize
 %strcat
index 357a1b5..736bbff 100644 (file)
--- a/preproc.c
+++ b/preproc.c
 #include "hashtbl.h"
 #include "quote.h"
 #include "stdscan.h"
+#include "eval.h"
 #include "tokens.h"
 #include "tables.h"
 
 typedef struct SMacro SMacro;
 typedef struct MMacro MMacro;
+typedef struct MMacroInvocation MMacroInvocation;
 typedef struct Context Context;
 typedef struct Token Token;
 typedef struct Blocks Blocks;
@@ -130,12 +132,14 @@ struct SMacro {
  */
 struct MMacro {
     MMacro *next;
+    MMacroInvocation *prev;      /* previous invocation */
     char *name;
     int nparam_min, nparam_max;
     bool casesense;
     bool plus;                   /* is the last parameter greedy? */
     bool nolist;                 /* is this macro listing-inhibited? */
-    int64_t in_progress;
+    int64_t in_progress;         /* is this macro currently being expanded? */
+    int32_t max_depth;           /* maximum number of recursive expansions allowed */
     Token *dlist;               /* All defaults as one list */
     Token **defaults;           /* Parameter default pointers */
     int ndefs;                  /* number of default parameters */
@@ -151,6 +155,20 @@ struct MMacro {
     int lineno;                 /* Current line number on expansion */
 };
 
+
+/* Store the definition of a multi-line macro, as defined in a
+ * previous recursive macro expansion.
+ */
+struct MMacroInvocation {
+    MMacroInvocation *prev;     /* previous invocation */
+    Token **params;             /* actual parameters */
+    Token *iline;               /* invocation line */
+    unsigned int nparam, rotate;
+    int *paramlen;
+    uint64_t unique;
+};
+
+
 /*
  * The context stack is composed of a linked list of these.
  */
@@ -301,6 +319,12 @@ enum {
 #define DIRECTIVE_FOUND            1
 
 /*
+ * This define sets the upper limit for smacro and recursive mmacro
+ * expansions
+ */
+#define DEADMAN_LIMIT (1 << 20)
+
+/*
  * Condition codes. Note that we use c_ prefix not C_ because C_ is
  * used in nasm.h for the "real" condition codes. At _this_ level,
  * we treat CXZ and ECXZ as condition codes, albeit non-invertible
@@ -357,9 +381,6 @@ static Context *cstk;
 static Include *istk;
 static IncPath *ipath = NULL;
 
-static efunc _error;            /* Pointer to client-provided error reporting function */
-static evalfunc evaluate;
-
 static int pass;                /* HACK: pass 0 = generate dependencies only */
 static StrList **dephead, **deptail; /* Dependency list */
 
@@ -1021,12 +1042,12 @@ static Token *tokenize(char *line)
 
         /* Handling unterminated string by UNV */
         /*if (type == -1)
-           {
-           *tail = t = new_Token(NULL, TOK_STRING, line, p-line+1);
-           t->text[p-line] = *line;
-           tail = &t->next;
-           }
-           else */
+         {
+         *tail = t = new_Token(NULL, TOK_STRING, line, p-line+1);
+         t->text[p-line] = *line;
+         tail = &t->next;
+         }
+         else */
         if (type != TOK_COMMENT) {
             *tail = t = new_Token(NULL, type, line, p - line);
             tail = &t->next;
@@ -1092,7 +1113,7 @@ static Token *new_Token(Token * next, enum pp_token_type type,
     Token *t;
     int i;
 
-    if (freeTokens == NULL) {
+    if (!freeTokens) {
         freeTokens = (Token *) new_Block(TOKEN_BLOCKSIZE * sizeof(Token));
         for (i = 0; i < TOKEN_BLOCKSIZE - 1; i++)
             freeTokens[i].next = &freeTokens[i + 1];
@@ -1103,7 +1124,7 @@ static Token *new_Token(Token * next, enum pp_token_type type,
     t->next = next;
     t->a.mac = NULL;
     t->type = type;
-    if (type == TOK_WHITESPACE || text == NULL) {
+    if (type == TOK_WHITESPACE || !text) {
         t->text = NULL;
     } else {
         if (txtlen == 0)
@@ -1662,82 +1683,83 @@ static bool if_condition(Token * tline, enum preproc_token ct)
        break;
 
     case PPC_IFMACRO:
-        {
-            bool found = false;
-            MMacro searching, *mmac;
+    {
+       bool found = false;
+       MMacro searching, *mmac;
 
-            skip_white_(tline);
-            tline = expand_id(tline);
-            if (!tok_type_(tline, TOK_ID)) {
-                error(ERR_NONFATAL,
-                      "`%s' expects a macro name", pp_directives[ct]);
-               goto fail;
-            }
-            searching.name = nasm_strdup(tline->text);
-            searching.casesense = true;
-            searching.plus = false;
-            searching.nolist = false;
-            searching.in_progress = 0;
-            searching.rep_nest = NULL;
-            searching.nparam_min = 0;
-            searching.nparam_max = INT_MAX;
-            tline = expand_smacro(tline->next);
-            skip_white_(tline);
-            if (!tline) {
-            } else if (!tok_type_(tline, TOK_NUMBER)) {
-                error(ERR_NONFATAL,
-                      "`%s' expects a parameter count or nothing",
-                      pp_directives[ct]);
-            } else {
-                searching.nparam_min = searching.nparam_max =
-                    readnum(tline->text, &j);
-                if (j)
-                    error(ERR_NONFATAL,
-                          "unable to parse parameter count `%s'",
-                          tline->text);
-            }
-            if (tline && tok_is_(tline->next, "-")) {
-                tline = tline->next->next;
-                if (tok_is_(tline, "*"))
-                    searching.nparam_max = INT_MAX;
-                else if (!tok_type_(tline, TOK_NUMBER))
-                    error(ERR_NONFATAL,
-                          "`%s' expects a parameter count after `-'",
-                          pp_directives[ct]);
-                else {
-                    searching.nparam_max = readnum(tline->text, &j);
-                    if (j)
-                        error(ERR_NONFATAL,
-                              "unable to parse parameter count `%s'",
-                              tline->text);
-                    if (searching.nparam_min > searching.nparam_max)
-                        error(ERR_NONFATAL,
-                              "minimum parameter count exceeds maximum");
-                }
-            }
-            if (tline && tok_is_(tline->next, "+")) {
-                tline = tline->next;
-                searching.plus = true;
-            }
-            mmac = (MMacro *) hash_findix(&mmacros, searching.name);
-           while (mmac) {
-               if (!strcmp(mmac->name, searching.name) &&
-                   (mmac->nparam_min <= searching.nparam_max
-                    || searching.plus)
-                   && (searching.nparam_min <= mmac->nparam_max
-                       || mmac->plus)) {
-                   found = true;
-                   break;
-               }
-               mmac = mmac->next;
+       skip_white_(tline);
+       tline = expand_id(tline);
+       if (!tok_type_(tline, TOK_ID)) {
+           error(ERR_NONFATAL,
+                 "`%s' expects a macro name", pp_directives[ct]);
+           goto fail;
+       }
+       searching.name = nasm_strdup(tline->text);
+       searching.casesense = true;
+       searching.plus = false;
+       searching.nolist = false;
+       searching.in_progress = 0;
+       searching.max_depth = 0;
+       searching.rep_nest = NULL;
+       searching.nparam_min = 0;
+       searching.nparam_max = INT_MAX;
+       tline = expand_smacro(tline->next);
+       skip_white_(tline);
+       if (!tline) {
+       } else if (!tok_type_(tline, TOK_NUMBER)) {
+           error(ERR_NONFATAL,
+                 "`%s' expects a parameter count or nothing",
+                 pp_directives[ct]);
+       } else {
+           searching.nparam_min = searching.nparam_max =
+               readnum(tline->text, &j);
+           if (j)
+               error(ERR_NONFATAL,
+                     "unable to parse parameter count `%s'",
+                     tline->text);
+       }
+       if (tline && tok_is_(tline->next, "-")) {
+           tline = tline->next->next;
+           if (tok_is_(tline, "*"))
+               searching.nparam_max = INT_MAX;
+           else if (!tok_type_(tline, TOK_NUMBER))
+               error(ERR_NONFATAL,
+                     "`%s' expects a parameter count after `-'",
+                     pp_directives[ct]);
+           else {
+               searching.nparam_max = readnum(tline->text, &j);
+               if (j)
+                   error(ERR_NONFATAL,
+                         "unable to parse parameter count `%s'",
+                         tline->text);
+               if (searching.nparam_min > searching.nparam_max)
+                   error(ERR_NONFATAL,
+                         "minimum parameter count exceeds maximum");
            }
-            if(tline && tline->next)
-                error(ERR_WARNING|ERR_PASS1,
-                     "trailing garbage after %%ifmacro ignored");
-            nasm_free(searching.name);
-           j = found;
-           break;
-        }
+       }
+       if (tline && tok_is_(tline->next, "+")) {
+           tline = tline->next;
+           searching.plus = true;
+       }
+       mmac = (MMacro *) hash_findix(&mmacros, searching.name);
+       while (mmac) {
+           if (!strcmp(mmac->name, searching.name) &&
+               (mmac->nparam_min <= searching.nparam_max
+                || searching.plus)
+               && (searching.nparam_min <= mmac->nparam_max
+                   || mmac->plus)) {
+               found = true;
+               break;
+           }
+           mmac = mmac->next;
+       }
+       if (tline && tline->next)
+           error(ERR_WARNING|ERR_PASS1,
+                 "trailing garbage after %%ifmacro ignored");
+       nasm_free(searching.name);
+       j = found;
+       break;
+    }
 
     case PPC_IFID:
        needtype = TOK_ID;
@@ -1905,6 +1927,7 @@ static bool parse_mmacro_spec(Token *tline, MMacro *def, const char *directive)
        return false;
     }
 
+    def->prev = NULL;
     def->name = nasm_strdup(tline->text);
     def->plus = false;
     def->nolist = false;
@@ -1951,7 +1974,7 @@ static bool parse_mmacro_spec(Token *tline, MMacro *def, const char *directive)
        tline = tline->next;
        def->nolist = true;
     }
-
+       
     /*
      * Handle default parameters.
      */
@@ -1965,11 +1988,10 @@ static bool parse_mmacro_spec(Token *tline, MMacro *def, const char *directive)
     }
     def->expansion = NULL;
 
-        if(def->defaults &&
-           def->ndefs > def->nparam_max - def->nparam_min &&
-           !def->plus)
-         error(ERR_WARNING|ERR_PASS1|ERR_WARN_MDP,
-              "too many default macro parameters");
+    if (def->defaults && def->ndefs > def->nparam_max - def->nparam_min &&
+       !def->plus)
+       error(ERR_WARNING|ERR_PASS1|ERR_WARN_MDP,
+             "too many default macro parameters");
 
     return true;
 }
@@ -1987,6 +2009,23 @@ static int parse_size(const char *str) {
     return sizes[bsii(str, size_names, elements(size_names))+1];
 }
 
+/*
+ * nasm_unquote with error if the string contains NUL characters.
+ * If the string contains NUL characters, issue an error and return
+ * the C len, i.e. truncate at the NUL.
+ */
+static size_t nasm_unquote_cstr(char *qstr, enum preproc_token directive)
+{
+    size_t len = nasm_unquote(qstr, NULL);
+    size_t clen = strlen(qstr);
+
+    if (len != clen)
+       error(ERR_NONFATAL, "NUL character in `%s' directive",
+             pp_directives[directive]);
+
+    return clen;
+}
+
 /**
  * find and process preprocessor directive in passed line
  * Find out if a line contains a preprocessor directive, and deal
@@ -2052,13 +2091,15 @@ static int do_directive(Token * tline)
      * If we're in a %rep block, another %rep nests, so should be let through.
      */
     if (defining && i != PP_MACRO && i != PP_IMACRO &&
+       i != PP_RMACRO &&  i != PP_IRMACRO &&
         i != PP_ENDMACRO && i != PP_ENDM &&
         (defining->name || (i != PP_ENDREP && i != PP_REP))) {
         return NO_DIRECTIVE_FOUND;
     }
 
     if (defining) {
-        if (i == PP_MACRO || i == PP_IMACRO) {
+        if (i == PP_MACRO || i == PP_IMACRO ||
+           i == PP_RMACRO || i == PP_IRMACRO) {
             nested_mac_count++;
             return NO_DIRECTIVE_FOUND;
         } else if (nested_mac_count > 0) {
@@ -2301,7 +2342,7 @@ static int do_directive(Token * tline)
        t = tline->next = expand_smacro(tline->next);
         skip_white_(t);
         if (!t || (t->type != TOK_STRING &&
-                       t->type != TOK_INTERNAL_STRING)) {
+                  t->type != TOK_INTERNAL_STRING)) {
             error(ERR_NONFATAL, "`%%depend' expects a file name");
             free_tlist(origline);
             return DIRECTIVE_FOUND;     /* but we did _something_ */
@@ -2311,7 +2352,7 @@ static int do_directive(Token * tline)
                   "trailing garbage after `%%depend' ignored");
        p = t->text;
         if (t->type != TOK_INTERNAL_STRING)
-           nasm_unquote(p, NULL);
+           nasm_unquote_cstr(p, i);
        if (dephead && !in_list(*dephead, p)) {
            StrList *sl = nasm_malloc(strlen(p)+1+sizeof sl->next);
            sl->next = NULL;
@@ -2327,7 +2368,7 @@ static int do_directive(Token * tline)
         skip_white_(t);
 
         if (!t || (t->type != TOK_STRING &&
-                       t->type != TOK_INTERNAL_STRING)) {
+                  t->type != TOK_INTERNAL_STRING)) {
             error(ERR_NONFATAL, "`%%include' expects a file name");
             free_tlist(origline);
             return DIRECTIVE_FOUND;     /* but we did _something_ */
@@ -2337,7 +2378,7 @@ static int do_directive(Token * tline)
                   "trailing garbage after `%%include' ignored");
        p = t->text;
         if (t->type != TOK_INTERNAL_STRING)
-           nasm_unquote(p, NULL);
+           nasm_unquote_cstr(p, i);
         inc = nasm_malloc(sizeof(Include));
         inc->next = istk;
         inc->conds = NULL;
@@ -2377,7 +2418,7 @@ static int do_directive(Token * tline)
             error(ERR_WARNING|ERR_PASS1,
                   "trailing garbage after `%%use' ignored");
        if (tline->type == TOK_STRING)
-           nasm_unquote(tline->text, NULL);
+           nasm_unquote_cstr(tline->text, i);
        use_pkg = nasm_stdmac_find_package(tline->text);
        if (!use_pkg)
            error(ERR_NONFATAL, "unknown `%%use' package: %s", tline->text);
@@ -2456,24 +2497,24 @@ static int do_directive(Token * tline)
        /* Only error out if this is the final pass */
        if (pass != 2 && i != PP_FATAL)
            return DIRECTIVE_FOUND;
-
-        tline->next = expand_smacro(tline->next);
-        tline = tline->next;
-        skip_white_(tline);
+       
+       tline->next = expand_smacro(tline->next);
+       tline = tline->next;
+       skip_white_(tline);
        t = tline ? tline->next : NULL;
        skip_white_(t);
-        if (tok_type_(tline, TOK_STRING) && !t) {
+       if (tok_type_(tline, TOK_STRING) && !t) {
            /* The line contains only a quoted string */
            p = tline->text;
-           nasm_unquote(p, NULL);
+           nasm_unquote(p, NULL); /* Ignore NUL character truncation */
            error(severity, "%s",  p);
        } else {
            /* Not a quoted string, or more than a quoted string */
-            p = detoken(tline, false);
+           p = detoken(tline, false);
            error(severity, "%s",  p);
            nasm_free(p);
        }
-        free_tlist(origline);
+       free_tlist(origline);
        return DIRECTIVE_FOUND;
     }
 
@@ -2496,35 +2537,35 @@ static int do_directive(Token * tline)
         if (!istk->conds)
             error(ERR_FATAL, "`%s': no matching `%%if'", pp_directives[i]);
         switch(istk->conds->state) {
-            case COND_IF_TRUE:
-                istk->conds->state = COND_DONE;
-                break;
+       case COND_IF_TRUE:
+           istk->conds->state = COND_DONE;
+           break;
 
-            case COND_DONE:
-            case COND_NEVER:
-                break;
+       case COND_DONE:
+       case COND_NEVER:
+           break;
 
-            case COND_ELSE_TRUE:
-            case COND_ELSE_FALSE:
-                error_precond(ERR_WARNING|ERR_PASS1,
-                             "`%%elif' after `%%else' ignored");
-                istk->conds->state = COND_NEVER;
-                break;
+       case COND_ELSE_TRUE:
+       case COND_ELSE_FALSE:
+           error_precond(ERR_WARNING|ERR_PASS1,
+                         "`%%elif' after `%%else' ignored");
+           istk->conds->state = COND_NEVER;
+           break;
 
-            case COND_IF_FALSE:
-                /*
-                 * IMPORTANT: In the case of %if, we will already have
-                 * called expand_mmac_params(); however, if we're
-                 * processing an %elif we must have been in a
-                 * non-emitting mode, which would have inhibited
-                 * the normal invocation of expand_mmac_params().
-                * Therefore, we have to do it explicitly here.
-                 */
-                j = if_condition(expand_mmac_params(tline->next), i);
-                tline->next = NULL; /* it got freed */
-                istk->conds->state =
-                    j < 0 ? COND_NEVER : j ? COND_IF_TRUE : COND_IF_FALSE;
-                break;
+       case COND_IF_FALSE:
+           /*
+            * IMPORTANT: In the case of %if, we will already have
+            * called expand_mmac_params(); however, if we're
+            * processing an %elif we must have been in a
+            * non-emitting mode, which would have inhibited
+            * the normal invocation of expand_mmac_params().
+            * Therefore, we have to do it explicitly here.
+            */
+           j = if_condition(expand_mmac_params(tline->next), i);
+           tline->next = NULL; /* it got freed */
+           istk->conds->state =
+               j < 0 ? COND_NEVER : j ? COND_IF_TRUE : COND_IF_FALSE;
+           break;
         }
        free_tlist(origline);
         return DIRECTIVE_FOUND;
@@ -2536,24 +2577,24 @@ static int do_directive(Token * tline)
         if (!istk->conds)
             error(ERR_FATAL, "`%%else': no matching `%%if'");
         switch(istk->conds->state) {
-            case COND_IF_TRUE:
-            case COND_DONE:
-                istk->conds->state = COND_ELSE_FALSE;
-                break;
+       case COND_IF_TRUE:
+       case COND_DONE:
+           istk->conds->state = COND_ELSE_FALSE;
+           break;
 
-            case COND_NEVER:
-                break;
+       case COND_NEVER:
+           break;
 
-            case COND_IF_FALSE:
-                istk->conds->state = COND_ELSE_TRUE;
-                break;
+       case COND_IF_FALSE:
+           istk->conds->state = COND_ELSE_TRUE;
+           break;
 
-            case COND_ELSE_TRUE:
-            case COND_ELSE_FALSE:
-                error_precond(ERR_WARNING|ERR_PASS1,
-                             "`%%else' after `%%else' ignored.");
-                istk->conds->state = COND_NEVER;
-                break;
+       case COND_ELSE_TRUE:
+       case COND_ELSE_FALSE:
+           error_precond(ERR_WARNING|ERR_PASS1,
+                         "`%%else' after `%%else' ignored.");
+           istk->conds->state = COND_NEVER;
+           break;
         }
         free_tlist(origline);
         return DIRECTIVE_FOUND;
@@ -2569,17 +2610,20 @@ static int do_directive(Token * tline)
         nasm_free(cond);
         free_tlist(origline);
         return DIRECTIVE_FOUND;
-
+               
+    case PP_RMACRO:
+    case PP_IRMACRO:
     case PP_MACRO:
     case PP_IMACRO:
         if (defining) {
-            error(ERR_FATAL,
-                  "`%%%smacro': already defining a macro",
-                  (i == PP_IMACRO ? "i" : ""));
+            error(ERR_FATAL, "`%s': already defining a macro",
+                 pp_directives[i]);
            return DIRECTIVE_FOUND;
        }
-        defining = nasm_malloc(sizeof(MMacro));
-       defining->casesense = (i == PP_MACRO);
+       defining = nasm_malloc(sizeof(MMacro));
+       defining->max_depth =
+           (i == PP_RMACRO) || (i == PP_IRMACRO) ? DEADMAN_LIMIT : 0;
+       defining->casesense = (i == PP_MACRO) || (i == PP_RMACRO);
        if (!parse_mmacro_spec(tline, defining, pp_directives[i])) {
            nasm_free(defining);
            defining = NULL;
@@ -2608,13 +2652,31 @@ static int do_directive(Token * tline)
             error(ERR_NONFATAL, "`%s': not defining a macro", tline->text);
             return DIRECTIVE_FOUND;
         }
-       mmhead = (MMacro **) hash_findi_add(&mmacros, defining->name);
+        mmhead = (MMacro **) hash_findi_add(&mmacros, defining->name);
         defining->next = *mmhead;
-       *mmhead = defining;
+        *mmhead = defining;
         defining = NULL;
         free_tlist(origline);
         return DIRECTIVE_FOUND;
 
+    case PP_EXITMACRO:
+        /*
+         * We must search along istk->expansion until we hit a
+         * macro-end marker for a macro with a name. Then we set
+         * its `in_progress' flag to 0.
+         */
+       for (l = istk->expansion; l; l = l->next)
+            if (l->finishes && l->finishes->name)
+               break;
+
+        if (l) {
+           l->finishes->in_progress = 0;
+        } else {
+            error(ERR_NONFATAL, "`%%exitmacro' not within `%%macro' block");
+       }
+        free_tlist(origline);
+        return DIRECTIVE_FOUND;
+
     case PP_UNMACRO:
     case PP_UNIMACRO:
     {
@@ -2647,7 +2709,7 @@ static int do_directive(Token * tline)
     case PP_ROTATE:
         if (tline->next && tline->next->type == TOK_WHITESPACE)
             tline = tline->next;
-        if (tline->next == NULL) {
+        if (!tline->next) {
             free_tlist(origline);
             error(ERR_NONFATAL, "`%%rotate' missing rotate count");
             return DIRECTIVE_FOUND;
@@ -2729,11 +2791,13 @@ static int do_directive(Token * tline)
 
         tmp_defining = defining;
         defining = nasm_malloc(sizeof(MMacro));
+       defining->prev = NULL;
         defining->name = NULL;  /* flags this macro as a %rep block */
         defining->casesense = false;
         defining->plus = false;
         defining->nolist = nolist;
         defining->in_progress = count;
+       defining->max_depth = 0;
         defining->nparam_min = defining->nparam_max = 0;
         defining->defaults = NULL;
         defining->dlist = NULL;
@@ -2946,6 +3010,53 @@ static int do_directive(Token * tline)
        define_smacro(ctx, mname, casesense, 0, macro_start);
         free_tlist(origline);
         return DIRECTIVE_FOUND;
+               
+    case PP_DEFTOK:
+    case PP_IDEFTOK:
+       casesense = (i == PP_DEFTOK);
+       
+        tline = tline->next;
+        skip_white_(tline);
+        tline = expand_id(tline);
+        if (!tline || (tline->type != TOK_ID &&
+                       (tline->type != TOK_PREPROC_ID ||
+                        tline->text[1] != '$'))) {
+            error(ERR_NONFATAL,
+                  "`%s' expects a macro identifier as first parameter",
+                 pp_directives[i]);
+            free_tlist(origline);
+            return DIRECTIVE_FOUND;
+        }
+        ctx = get_ctx(tline->text, &mname, false);
+        last = tline;
+        tline = expand_smacro(tline->next);
+        last->next = NULL;
+
+        t = tline;
+        while (tok_type_(t, TOK_WHITESPACE))
+            t = t->next;
+        /* t should now point to the string */
+        if (t->type != TOK_STRING) {
+            error(ERR_NONFATAL,
+                  "`%s` requires string as second parameter",
+                 pp_directives[i]);
+            free_tlist(tline);
+            free_tlist(origline);
+            return DIRECTIVE_FOUND;
+        }
+
+       nasm_unquote_cstr(t->text, i);
+       macro_start = tokenize(t->text);
+       
+        /*
+         * We now have a macro name, an implicit parameter count of
+         * zero, and a numeric token to use as an expansion. Create
+         * and store an SMacro.
+         */
+       define_smacro(ctx, mname, casesense, 0, macro_start);
+        free_tlist(tline);
+        free_tlist(origline);
+        return DIRECTIVE_FOUND;
 
     case PP_PATHSEARCH:
     {
@@ -3328,7 +3439,7 @@ static int find_cc(Token * t)
     int i, j, k, m;
 
     if (!t)
-           return -1;          /* Probably a %+ without a space */
+       return -1;              /* Probably a %+ without a space */
 
     skip_white_(t);
     if (t->type != TOK_ID)
@@ -3623,7 +3734,6 @@ static Token *expand_mmac_params(Token * tline)
  * Tokens from input to output a lot of the time, rather than
  * actually bothering to destroy and replicate.)
  */
-#define DEADMAN_LIMIT (1 << 20)
 
 static Token *expand_smacro(Token * tline)
 {
@@ -3728,7 +3838,7 @@ again:
                      * pain.
                      */
                     /*tline = tline->next;
-                       skip_white_(tline); */
+                     skip_white_(tline); */
                     do {
                         t = tline->next;
                         while (tok_type_(t, TOK_SMAC_END)) {
@@ -4060,14 +4170,15 @@ static MMacro *is_mmacro(Token * tline, Token *** params_array)
              * This one is right. Just check if cycle removal
              * prohibits us using it before we actually celebrate...
              */
-            if (m->in_progress) {
-#if 0
-                error(ERR_NONFATAL,
-                      "self-reference in multi-line macro `%s'", m->name);
-#endif
-                nasm_free(params);
-                return NULL;
-            }
+           if (m->in_progress > m->max_depth) {
+               if (m->max_depth > 0) {
+                   error(ERR_WARNING,
+                         "reached maximum recursion depth of %i",
+                         m->max_depth);
+               }
+               nasm_free(params);
+               return NULL;
+           }
             /*
              * It's right, and we can use it. Add its default
              * parameters to the end of our list if necessary.
@@ -4120,6 +4231,49 @@ static MMacro *is_mmacro(Token * tline, Token *** params_array)
     return NULL;
 }
 
+
+/*
+ * Save MMacro invocation specific fields in
+ * preparation for a recursive macro expansion
+ */
+static void push_mmacro(MMacro *m)
+{
+    MMacroInvocation *i;
+
+    i = nasm_malloc(sizeof(MMacroInvocation));
+    i->prev = m->prev;
+    i->params = m->params;
+    i->iline = m->iline;
+    i->nparam = m->nparam;
+    i->rotate = m->rotate;
+    i->paramlen = m->paramlen;
+    i->unique = m->unique;
+    m->prev = i;
+}
+
+
+/*
+ * Restore MMacro invocation specific fields that were
+ * saved during a previous recursive macro expansion
+ */
+static void pop_mmacro(MMacro *m)
+{
+    MMacroInvocation *i;
+
+    if (m->prev) {
+       i = m->prev;
+       m->prev = i->prev;
+       m->params = i->params;
+       m->iline = i->iline;
+       m->nparam = i->nparam;
+       m->rotate = i->rotate;
+       m->paramlen = i->paramlen;
+       m->unique = i->unique;
+       nasm_free(i);
+    }
+}
+
+
 /*
  * Expand the multi-line macro call made by the given line, if
  * there is one to be expanded. If there is, push the expansion on
@@ -4163,10 +4317,10 @@ static int expand_mmacro(Token * tline)
             if (tok_type_(t, TOK_WHITESPACE))
                 last = t, t = t->next;
         }
-        if (!tok_type_(t, TOK_ID) || (m = is_mmacro(t, &params)) == NULL)
+        if (!tok_type_(t, TOK_ID) || !(m = is_mmacro(t, &params)))
             return 0;
         last->next = NULL;
-       mname = t->text;
+        mname = t->text;
         tline = t;
     }
 
@@ -4219,8 +4373,15 @@ static int expand_mmacro(Token * tline)
     ll->finishes = m;
     ll->first = NULL;
     istk->expansion = ll;
+       
+    /*
+     * Save the previous MMacro expansion in the case of
+     * macro recursion
+     */
+    if (m->max_depth && m->in_progress)
+       push_mmacro(m);
 
-    m->in_progress = true;
+    m->in_progress ++;
     m->params = params;
     m->iline = tline;
     m->nparam = nparam;
@@ -4301,10 +4462,10 @@ static void verror(int severity, const char *fmt, va_list arg)
     vsnprintf(buff, sizeof(buff), fmt, arg);
 
     if (istk && istk->mstk && istk->mstk->name)
-        _error(severity, "(%s:%d) %s", istk->mstk->name,
+        nasm_error(severity, "(%s:%d) %s", istk->mstk->name,
                istk->mstk->lineno, buff);
     else
-        _error(severity, "%s", buff);
+        nasm_error(severity, "%s", buff);
 }
 
 /*
@@ -4344,12 +4505,10 @@ static void error_precond(int severity, const char *fmt, ...)
 }
 
 static void
-pp_reset(char *file, int apass, efunc errfunc, evalfunc eval,
-         ListGen * listgen, StrList **deplist)
+pp_reset(char *file, int apass, ListGen * listgen, StrList **deplist)
 {
     Token *t;
 
-    _error = errfunc;
     cstk = NULL;
     istk = nasm_malloc(sizeof(Include));
     istk->next = NULL;
@@ -4377,7 +4536,6 @@ pp_reset(char *file, int apass, efunc errfunc, evalfunc eval,
     any_extrastdmac = extrastdmac && *extrastdmac;
     do_predef = true;
     list = listgen;
-    evaluate = eval;
 
     /*
      * 0 for dependencies, 1 for preparatory passes, 2 for final pass.
@@ -4488,10 +4646,15 @@ static char *pp_getline(void)
                          * therefore the parameter information needs to
                          * be freed.
                          */
-                        nasm_free(m->params);
-                        free_tlist(m->iline);
-                        nasm_free(m->paramlen);
-                        l->finishes->in_progress = false;
+                       if (m->prev) {
+                           pop_mmacro(m);
+                           l->finishes->in_progress --;
+                       } else {
+                            nasm_free(m->params);
+                            free_tlist(m->iline);
+                           nasm_free(m->paramlen);
+                           l->finishes->in_progress = 0;
+                       }
                     } else
                         free_mmacro(m);
                 }
@@ -4619,7 +4782,7 @@ static char *pp_getline(void)
 static void pp_cleanup(int pass)
 {
     if (defining) {
-        if(defining->name) {
+        if (defining->name) {
             error(ERR_NONFATAL,
                   "end of file while still defining macro `%s'",
                   defining->name);
@@ -4663,9 +4826,9 @@ void pp_include_path(char *path)
     i->path = path ? nasm_strdup(path) : NULL;
     i->next = NULL;
 
-    if (ipath != NULL) {
+    if (ipath) {
         IncPath *j = ipath;
-        while (j->next != NULL)
+        while (j->next)
             j = j->next;
         j->next = i;
     } else {
@@ -4742,7 +4905,7 @@ void pp_runtime(char *definition)
     Token *def;
 
     def = tokenize(definition);
-    if(do_directive(def) == NO_DIRECTIVE_FOUND)
+    if (do_directive(def) == NO_DIRECTIVE_FOUND)
         free_tlist(def);
 
 }
diff --git a/raa.c b/raa.c
index 5d6c351..be912a4 100644 (file)
--- a/raa.c
+++ b/raa.c
@@ -92,8 +92,7 @@ struct RAA *raa_write(struct RAA *r, int32_t posn, int64_t value)
 {
     struct RAA *result;
 
-    if (posn < 0)
-        nasm_malloc_error(ERR_PANIC, "negative position in raa_write");
+    nasm_assert(posn >= 0);
 
     while ((UINT32_C(1) << (r->shift + LAYERSHIFT(r))) <= (uint32_t) posn) {
         /*
diff --git a/saa.c b/saa.c
index ed70755..157aba3 100644 (file)
--- a/saa.c
+++ b/saa.c
@@ -99,15 +99,10 @@ void *saa_wstruct(struct SAA *s)
 {
     void *p;
 
-    if (s->wpos % s->elem_len)
-        nasm_malloc_error(ERR_PANIC | ERR_NOFILE,
-                          "misaligned wpos in saa_wstruct");
+    nasm_assert((s->wpos % s->elem_len) == 0);
 
     if (s->wpos + s->elem_len > s->blk_len) {
-        if (s->wpos != s->blk_len)
-            nasm_malloc_error(ERR_PANIC | ERR_NOFILE,
-                              "unfilled block in saa_wstruct");
-
+        nasm_assert(s->wpos == s->blk_len);
         if (s->wptr + s->elem_len > s->length)
             saa_extend(s);
         s->wblk++;
@@ -167,9 +162,7 @@ void *saa_rstruct(struct SAA *s)
     if (s->rptr + s->elem_len > s->datalen)
         return NULL;
 
-    if (s->rpos % s->elem_len)
-        nasm_malloc_error(ERR_PANIC | ERR_NOFILE,
-                          "misaligned rpos in saa_rstruct");
+    nasm_assert((s->rpos % s->elem_len) == 0);
 
     if (s->rpos + s->elem_len > s->blk_len) {
         s->rblk++;
@@ -217,11 +210,7 @@ void saa_rnbytes(struct SAA *s, void *data, size_t len)
 {
     char *d = data;
 
-    if (s->rptr + len > s->datalen) {
-        nasm_malloc_error(ERR_PANIC | ERR_NOFILE,
-                          "overrun in saa_rnbytes");
-        return;
-    }
+    nasm_assert(s->rptr + len <= s->datalen);
 
     while (len) {
         size_t l;
@@ -241,10 +230,7 @@ void saa_fread(struct SAA *s, size_t posn, void *data, size_t len)
 {
     size_t ix;
 
-    if (posn + len > s->datalen) {
-        nasm_malloc_error(ERR_PANIC | ERR_NOFILE, "overrun in saa_fread");
-        return;
-    }
+    nasm_assert(posn + len <= s->datalen);
 
     if (likely(s->blk_len == SAA_BLKLEN)) {
         ix = posn >> SAA_BLKSHIFT;
@@ -264,11 +250,8 @@ void saa_fwrite(struct SAA *s, size_t posn, const void *data, size_t len)
 {
     size_t ix;
 
-    if (posn > s->datalen) {
-        /* Seek beyond the end of the existing array not supported */
-        nasm_malloc_error(ERR_PANIC | ERR_NOFILE, "overrun in saa_fwrite");
-        return;
-    }
+    /* Seek beyond the end of the existing array not supported */
+    nasm_assert(posn <= s->datalen);
 
     if (likely(s->blk_len == SAA_BLKLEN)) {
         ix = posn >> SAA_BLKSHIFT;