diff options
author | H. Peter Anvin <hpa@zytor.com> | 2008-06-09 17:40:16 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2008-06-09 17:40:16 -0700 |
commit | fcb8909749b2a159ba7f32fec7df8e465a974f77 (patch) | |
tree | 59a257a1d223ca0ed0f3e410830b0cc8544804d0 | |
parent | 35d620d2fdd6bfb1502c7db60ad8331edf74354e (diff) | |
download | nasm-fcb8909749b2a159ba7f32fec7df8e465a974f77.tar.gz nasm-fcb8909749b2a159ba7f32fec7df8e465a974f77.tar.bz2 nasm-fcb8909749b2a159ba7f32fec7df8e465a974f77.zip |
Move all the RAA code out of nasmlib
The RAA code doesn't have to be in nasmlib; it is only used by nasm
itself, and is better handled in a separate module.
-rw-r--r-- | Makefile.in | 17 | ||||
-rw-r--r-- | Mkfiles/msvc.mak | 17 | ||||
-rw-r--r-- | Mkfiles/netware.mak | 17 | ||||
-rw-r--r-- | Mkfiles/openwcom.mak | 17 | ||||
-rw-r--r-- | Mkfiles/owlinux.mak | 17 | ||||
-rw-r--r-- | nasm.c | 1 | ||||
-rw-r--r-- | nasmlib.c | 93 | ||||
-rw-r--r-- | nasmlib.h | 50 | ||||
-rw-r--r-- | output/outaout.c | 1 | ||||
-rw-r--r-- | output/outas86.c | 1 | ||||
-rw-r--r-- | output/outcoff.c | 1 | ||||
-rw-r--r-- | output/outelf32.c | 3 | ||||
-rw-r--r-- | output/outelf64.c | 3 | ||||
-rw-r--r-- | output/outmacho.c | 1 | ||||
-rw-r--r-- | raa.c | 95 | ||||
-rw-r--r-- | raa.h | 56 |
16 files changed, 205 insertions, 185 deletions
diff --git a/Makefile.in b/Makefile.in index 3b22abb..d207acc 100644 --- a/Makefile.in +++ b/Makefile.in @@ -58,7 +58,7 @@ X = @EXEEXT@ .1.man: $(NROFF) -man $< > $@ -NASM = nasm.$(O) nasmlib.$(O) saa.$(O) \ +NASM = nasm.$(O) nasmlib.$(O) raa.$(O) saa.$(O) \ float.$(O) insnsa.$(O) insnsb.$(O) \ assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \ outform.$(O) output/outbin.$(O) \ @@ -261,7 +261,7 @@ listing.$(O): listing.c compiler.h config.h insnsi.h listing.h nasm.h \ macros.$(O): macros.c compiler.h config.h insnsi.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 regs.h stdscan.h tokens.h version.h + preproc.h raa.h regs.h saa.h stdscan.h tokens.h version.h nasmlib.$(O): nasmlib.c compiler.h config.h insns.h insnsi.h nasm.h \ nasmlib.h regs.h tokens.h version.h ndisasm.$(O): ndisasm.c compiler.h config.h disasm.h insns.h insnsi.h nasm.h \ @@ -269,23 +269,23 @@ ndisasm.$(O): ndisasm.c compiler.h config.h disasm.h insns.h insnsi.h nasm.h \ outform.$(O): outform.c compiler.h config.h insnsi.h nasm.h nasmlib.h \ outform.h regs.h version.h output/outaout.$(O): output/outaout.c compiler.h config.h insnsi.h nasm.h \ - nasmlib.h outform.h regs.h saa.h stdscan.h version.h + nasmlib.h outform.h raa.h regs.h saa.h stdscan.h version.h output/outas86.$(O): output/outas86.c compiler.h config.h insnsi.h nasm.h \ - nasmlib.h outform.h regs.h saa.h version.h + nasmlib.h outform.h raa.h regs.h saa.h version.h output/outbin.$(O): output/outbin.c compiler.h config.h eval.h insnsi.h \ labels.h nasm.h nasmlib.h outform.h regs.h saa.h stdscan.h version.h output/outcoff.$(O): output/outcoff.c compiler.h config.h insnsi.h nasm.h \ - nasmlib.h outform.h regs.h saa.h version.h + nasmlib.h outform.h raa.h regs.h saa.h version.h output/outdbg.$(O): output/outdbg.c compiler.h config.h insnsi.h nasm.h \ nasmlib.h outform.h regs.h version.h output/outelf32.$(O): output/outelf32.c compiler.h config.h insnsi.h nasm.h \ - nasmlib.h outform.h regs.h saa.h stdscan.h version.h + nasmlib.h outform.h raa.h regs.h saa.h stdscan.h version.h output/outelf64.$(O): output/outelf64.c compiler.h config.h insnsi.h nasm.h \ - nasmlib.h outform.h regs.h saa.h stdscan.h version.h + nasmlib.h outform.h raa.h regs.h saa.h stdscan.h version.h output/outieee.$(O): output/outieee.c compiler.h config.h insnsi.h nasm.h \ nasmlib.h outform.h regs.h version.h output/outmacho.$(O): output/outmacho.c compiler.h config.h insnsi.h nasm.h \ - nasmlib.h outform.h regs.h saa.h version.h + nasmlib.h outform.h raa.h regs.h saa.h version.h output/outobj.$(O): output/outobj.c compiler.h config.h insnsi.h nasm.h \ nasmlib.h outform.h regs.h stdscan.h version.h output/outrdf.$(O): output/outrdf.c compiler.h config.h insnsi.h nasm.h \ @@ -300,6 +300,7 @@ 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 \ version.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 regdis.$(O): regdis.c regdis.h regs.h regflags.$(O): regflags.c compiler.h config.h insnsi.h nasm.h nasmlib.h \ regs.h tables.h version.h diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index 7397780..c2904d8 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -32,7 +32,7 @@ X = .exe .c.obj: $(CC) /c $(ALL_CFLAGS) /Fo$@ $< -NASM = nasm.$(O) nasmlib.$(O) saa.$(O) \ +NASM = nasm.$(O) nasmlib.$(O) raa.$(O) saa.$(O) \ float.$(O) insnsa.$(O) insnsb.$(O) \ assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \ outform.$(O) output/outbin.$(O) \ @@ -207,7 +207,7 @@ listing.$(O): listing.c compiler.h insnsi.h listing.h nasm.h nasmlib.h \ macros.$(O): macros.c compiler.h insnsi.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 outform.h parser.h pptok.h preproc.h \ - regs.h stdscan.h tokens.h version.h + raa.h regs.h saa.h stdscan.h tokens.h version.h nasmlib.$(O): nasmlib.c compiler.h insns.h insnsi.h nasm.h nasmlib.h regs.h \ tokens.h version.h ndisasm.$(O): ndisasm.c compiler.h disasm.h insns.h insnsi.h nasm.h \ @@ -215,23 +215,23 @@ ndisasm.$(O): ndisasm.c compiler.h disasm.h insns.h insnsi.h nasm.h \ outform.$(O): outform.c compiler.h insnsi.h nasm.h nasmlib.h outform.h \ regs.h version.h output/outaout.$(O): output/outaout.c compiler.h insnsi.h nasm.h nasmlib.h \ - outform.h regs.h saa.h stdscan.h version.h + outform.h raa.h regs.h saa.h stdscan.h version.h output/outas86.$(O): output/outas86.c compiler.h insnsi.h nasm.h nasmlib.h \ - outform.h regs.h saa.h version.h + outform.h raa.h regs.h saa.h version.h output/outbin.$(O): output/outbin.c compiler.h eval.h insnsi.h labels.h \ nasm.h nasmlib.h outform.h regs.h saa.h stdscan.h version.h output/outcoff.$(O): output/outcoff.c compiler.h insnsi.h nasm.h nasmlib.h \ - outform.h regs.h saa.h version.h + outform.h raa.h regs.h saa.h version.h output/outdbg.$(O): output/outdbg.c compiler.h insnsi.h nasm.h nasmlib.h \ outform.h regs.h version.h output/outelf32.$(O): output/outelf32.c compiler.h insnsi.h nasm.h nasmlib.h \ - outform.h regs.h saa.h stdscan.h version.h + outform.h raa.h regs.h saa.h stdscan.h version.h output/outelf64.$(O): output/outelf64.c compiler.h insnsi.h nasm.h nasmlib.h \ - outform.h regs.h saa.h stdscan.h version.h + outform.h raa.h regs.h saa.h stdscan.h version.h output/outieee.$(O): output/outieee.c compiler.h insnsi.h nasm.h nasmlib.h \ outform.h regs.h version.h output/outmacho.$(O): output/outmacho.c compiler.h insnsi.h nasm.h nasmlib.h \ - outform.h regs.h saa.h version.h + outform.h raa.h regs.h saa.h version.h output/outobj.$(O): output/outobj.c compiler.h insnsi.h nasm.h nasmlib.h \ outform.h regs.h stdscan.h version.h output/outrdf.$(O): output/outrdf.c compiler.h insnsi.h nasm.h nasmlib.h \ @@ -244,6 +244,7 @@ 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 version.h quote.$(O): quote.c compiler.h nasmlib.h quote.h +raa.$(O): raa.c compiler.h nasmlib.h raa.h regdis.$(O): regdis.c regdis.h regs.h regflags.$(O): regflags.c compiler.h insnsi.h nasm.h nasmlib.h regs.h \ tables.h version.h diff --git a/Mkfiles/netware.mak b/Mkfiles/netware.mak index f2d76b5..f4ec46b 100644 --- a/Mkfiles/netware.mak +++ b/Mkfiles/netware.mak @@ -28,7 +28,7 @@ LDFLAGS+=-s O = o -NASM = nasm.$(O) nasmlib.$(O) saa.$(O) \ +NASM = nasm.$(O) nasmlib.$(O) raa.$(O) saa.$(O) \ float.$(O) insnsa.$(O) insnsb.$(O) \ assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \ outform.$(O) output/outbin.$(O) \ @@ -147,7 +147,7 @@ listing.o: listing.c compiler.h config.h insnsi.h listing.h nasm.h nasmlib.h \ macros.o: macros.c compiler.h config.h insnsi.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 regs.h stdscan.h tokens.h version.h + preproc.h raa.h regs.h saa.h stdscan.h tokens.h version.h nasmlib.o: nasmlib.c compiler.h config.h insns.h insnsi.h nasm.h nasmlib.h \ regs.h tokens.h version.h ndisasm.o: ndisasm.c compiler.h config.h disasm.h insns.h insnsi.h nasm.h \ @@ -155,23 +155,23 @@ ndisasm.o: ndisasm.c compiler.h config.h disasm.h insns.h insnsi.h nasm.h \ outform.o: outform.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \ regs.h version.h outaout.o: outaout.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \ - regs.h saa.h stdscan.h version.h + raa.h regs.h saa.h stdscan.h version.h outas86.o: outas86.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \ - regs.h saa.h version.h + raa.h regs.h saa.h version.h outbin.o: outbin.c compiler.h config.h eval.h insnsi.h labels.h nasm.h \ nasmlib.h outform.h regs.h saa.h stdscan.h version.h outcoff.o: outcoff.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \ - regs.h saa.h version.h + raa.h regs.h saa.h version.h outdbg.o: outdbg.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \ regs.h version.h outelf32.o: outelf32.c compiler.h config.h insnsi.h nasm.h nasmlib.h \ - outform.h regs.h saa.h stdscan.h version.h + outform.h raa.h regs.h saa.h stdscan.h version.h outelf64.o: outelf64.c compiler.h config.h insnsi.h nasm.h nasmlib.h \ - outform.h regs.h saa.h stdscan.h version.h + outform.h raa.h regs.h saa.h stdscan.h version.h outieee.o: outieee.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \ regs.h version.h outmacho.o: outmacho.c compiler.h config.h insnsi.h nasm.h nasmlib.h \ - outform.h regs.h saa.h version.h + outform.h raa.h regs.h saa.h version.h outobj.o: outobj.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \ regs.h stdscan.h version.h outrdf.o: outrdf.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \ @@ -184,6 +184,7 @@ 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 version.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 regdis.o: regdis.c regdis.h regs.h regflags.o: regflags.c compiler.h config.h insnsi.h nasm.h nasmlib.h regs.h \ tables.h version.h diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak index fe2e46d..fb95f57 100644 --- a/Mkfiles/openwcom.mak +++ b/Mkfiles/openwcom.mak @@ -44,7 +44,7 @@ X = .exe $(CC) -c $(ALL_CFLAGS) -fo=$^@ $[@ # Note: wcl386 is broken if forward slashes are used as path separators. -NASM = nasm.$(O) nasmlib.$(O) saa.$(O) & +NASM = nasm.$(O) nasmlib.$(O) raa.$(O) saa.$(O) & float.$(O) insnsa.$(O) insnsb.$(O) & assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) & outform.$(O) output\outbin.$(O) & @@ -236,7 +236,7 @@ listing.$(O): listing.c compiler.h insnsi.h listing.h nasm.h nasmlib.h & macros.$(O): macros.c compiler.h insnsi.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 outform.h parser.h pptok.h preproc.h & - regs.h stdscan.h tokens.h version.h + raa.h regs.h saa.h stdscan.h tokens.h version.h nasmlib.$(O): nasmlib.c compiler.h insns.h insnsi.h nasm.h nasmlib.h regs.h & tokens.h version.h ndisasm.$(O): ndisasm.c compiler.h disasm.h insns.h insnsi.h nasm.h & @@ -244,23 +244,23 @@ ndisasm.$(O): ndisasm.c compiler.h disasm.h insns.h insnsi.h nasm.h & outform.$(O): outform.c compiler.h insnsi.h nasm.h nasmlib.h outform.h & regs.h version.h output\outaout.$(O): output\outaout.c compiler.h insnsi.h nasm.h nasmlib.h & - outform.h regs.h saa.h stdscan.h version.h + outform.h raa.h regs.h saa.h stdscan.h version.h output\outas86.$(O): output\outas86.c compiler.h insnsi.h nasm.h nasmlib.h & - outform.h regs.h saa.h version.h + outform.h raa.h regs.h saa.h version.h output\outbin.$(O): output\outbin.c compiler.h eval.h insnsi.h labels.h & nasm.h nasmlib.h outform.h regs.h saa.h stdscan.h version.h output\outcoff.$(O): output\outcoff.c compiler.h insnsi.h nasm.h nasmlib.h & - outform.h regs.h saa.h version.h + outform.h raa.h regs.h saa.h version.h output\outdbg.$(O): output\outdbg.c compiler.h insnsi.h nasm.h nasmlib.h & outform.h regs.h version.h output\outelf32.$(O): output\outelf32.c compiler.h insnsi.h nasm.h nasmlib.h & - outform.h regs.h saa.h stdscan.h version.h + outform.h raa.h regs.h saa.h stdscan.h version.h output\outelf64.$(O): output\outelf64.c compiler.h insnsi.h nasm.h nasmlib.h & - outform.h regs.h saa.h stdscan.h version.h + outform.h raa.h regs.h saa.h stdscan.h version.h output\outieee.$(O): output\outieee.c compiler.h insnsi.h nasm.h nasmlib.h & outform.h regs.h version.h output\outmacho.$(O): output\outmacho.c compiler.h insnsi.h nasm.h nasmlib.h & - outform.h regs.h saa.h version.h + outform.h raa.h regs.h saa.h version.h output\outobj.$(O): output\outobj.c compiler.h insnsi.h nasm.h nasmlib.h & outform.h regs.h stdscan.h version.h output\outrdf.$(O): output\outrdf.c compiler.h insnsi.h nasm.h nasmlib.h & @@ -273,6 +273,7 @@ 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 version.h quote.$(O): quote.c compiler.h nasmlib.h quote.h +raa.$(O): raa.c compiler.h nasmlib.h raa.h regdis.$(O): regdis.c regdis.h regs.h regflags.$(O): regflags.c compiler.h insnsi.h nasm.h nasmlib.h regs.h & tables.h version.h diff --git a/Mkfiles/owlinux.mak b/Mkfiles/owlinux.mak index 7045d52..bb10d9e 100644 --- a/Mkfiles/owlinux.mak +++ b/Mkfiles/owlinux.mak @@ -55,7 +55,7 @@ X = .exe .c.$(O): $(CC) -c $(ALL_CFLAGS) -fo=$@ $< -NASM = nasm.$(O) nasmlib.$(O) saa.$(O) \ +NASM = nasm.$(O) nasmlib.$(O) raa.$(O) saa.$(O) \ float.$(O) insnsa.$(O) insnsb.$(O) \ assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \ outform.$(O) output/outbin.$(O) \ @@ -246,7 +246,7 @@ listing.$(O): listing.c compiler.h insnsi.h listing.h nasm.h nasmlib.h \ macros.$(O): macros.c compiler.h insnsi.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 outform.h parser.h pptok.h preproc.h \ - regs.h stdscan.h tokens.h version.h + raa.h regs.h saa.h stdscan.h tokens.h version.h nasmlib.$(O): nasmlib.c compiler.h insns.h insnsi.h nasm.h nasmlib.h regs.h \ tokens.h version.h ndisasm.$(O): ndisasm.c compiler.h disasm.h insns.h insnsi.h nasm.h \ @@ -254,23 +254,23 @@ ndisasm.$(O): ndisasm.c compiler.h disasm.h insns.h insnsi.h nasm.h \ outform.$(O): outform.c compiler.h insnsi.h nasm.h nasmlib.h outform.h \ regs.h version.h output/outaout.$(O): output/outaout.c compiler.h insnsi.h nasm.h nasmlib.h \ - outform.h regs.h saa.h stdscan.h version.h + outform.h raa.h regs.h saa.h stdscan.h version.h output/outas86.$(O): output/outas86.c compiler.h insnsi.h nasm.h nasmlib.h \ - outform.h regs.h saa.h version.h + outform.h raa.h regs.h saa.h version.h output/outbin.$(O): output/outbin.c compiler.h eval.h insnsi.h labels.h \ nasm.h nasmlib.h outform.h regs.h saa.h stdscan.h version.h output/outcoff.$(O): output/outcoff.c compiler.h insnsi.h nasm.h nasmlib.h \ - outform.h regs.h saa.h version.h + outform.h raa.h regs.h saa.h version.h output/outdbg.$(O): output/outdbg.c compiler.h insnsi.h nasm.h nasmlib.h \ outform.h regs.h version.h output/outelf32.$(O): output/outelf32.c compiler.h insnsi.h nasm.h nasmlib.h \ - outform.h regs.h saa.h stdscan.h version.h + outform.h raa.h regs.h saa.h stdscan.h version.h output/outelf64.$(O): output/outelf64.c compiler.h insnsi.h nasm.h nasmlib.h \ - outform.h regs.h saa.h stdscan.h version.h + outform.h raa.h regs.h saa.h stdscan.h version.h output/outieee.$(O): output/outieee.c compiler.h insnsi.h nasm.h nasmlib.h \ outform.h regs.h version.h output/outmacho.$(O): output/outmacho.c compiler.h insnsi.h nasm.h nasmlib.h \ - outform.h regs.h saa.h version.h + outform.h raa.h regs.h saa.h version.h output/outobj.$(O): output/outobj.c compiler.h insnsi.h nasm.h nasmlib.h \ outform.h regs.h stdscan.h version.h output/outrdf.$(O): output/outrdf.c compiler.h insnsi.h nasm.h nasmlib.h \ @@ -283,6 +283,7 @@ 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 version.h quote.$(O): quote.c compiler.h nasmlib.h quote.h +raa.$(O): raa.c compiler.h nasmlib.h raa.h regdis.$(O): regdis.c regdis.h regs.h regflags.$(O): regflags.c compiler.h insnsi.h nasm.h nasmlib.h regs.h \ tables.h version.h @@ -20,6 +20,7 @@ #include "nasm.h" #include "nasmlib.h" #include "saa.h" +#include "raa.h" #include "float.h" #include "stdscan.h" #include "insns.h" @@ -469,99 +469,6 @@ void standard_extension(char *inname, char *outname, char *extension, strcpy(p, extension); } -#define LEAFSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_LEAF)) -#define BRANCHSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_BRANCH)) - -#define LAYERSHIFT(r) ( (r)->layers==0 ? RAA_BLKSHIFT : RAA_LAYERSHIFT ) - -static struct RAA *real_raa_init(int layers) -{ - struct RAA *r; - int i; - - if (layers == 0) { - r = nasm_zalloc(LEAFSIZ); - r->shift = 0; - } else { - r = nasm_malloc(BRANCHSIZ); - r->layers = layers; - for (i = 0; i < RAA_LAYERSIZE; i++) - r->u.b.data[i] = NULL; - r->shift = (RAA_BLKSHIFT-RAA_LAYERSHIFT) + layers*RAA_LAYERSHIFT; - } - return r; -} - -struct RAA *raa_init(void) -{ - return real_raa_init(0); -} - -void raa_free(struct RAA *r) -{ - if (r->layers) { - struct RAA **p; - for (p = r->u.b.data; p - r->u.b.data < RAA_LAYERSIZE; p++) - if (*p) - raa_free(*p); - } - nasm_free(r); -} - -int64_t raa_read(struct RAA *r, int32_t posn) -{ - if ((uint32_t)posn >= (UINT32_C(1) << (r->shift + LAYERSHIFT(r)))) - return 0; /* Return 0 for undefined entries */ - while (r->layers > 0) { - int32_t l = posn >> r->shift; - posn &= (UINT32_C(1) << r->shift)-1; - r = r->u.b.data[l]; - if (!r) - return 0; /* Return 0 for undefined entries */ - } - return r->u.l.data[posn]; -} - -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"); - - while ((UINT32_C(1) << (r->shift+LAYERSHIFT(r))) <= (uint32_t)posn) { - /* - * Must add a layer. - */ - struct RAA *s; - int i; - - s = nasm_malloc(BRANCHSIZ); - for (i = 0; i < RAA_LAYERSIZE; i++) - s->u.b.data[i] = NULL; - s->layers = r->layers + 1; - s->shift = LAYERSHIFT(r) + r->shift; - s->u.b.data[0] = r; - r = s; - } - - result = r; - - while (r->layers > 0) { - struct RAA **s; - int32_t l = posn >> r->shift; - posn &= (UINT32_C(1) << r->shift)-1; - s = &r->u.b.data[l]; - if (!*s) - *s = real_raa_init(r->layers - 1); - r = *s; - } - - r->u.l.data[posn] = value; - - return result; -} - /* * Common list of prefix names */ @@ -281,56 +281,6 @@ void fwriteint64_t(uint64_t data, FILE * fp); void fwriteaddr(uint64_t data, int size, FILE * fp); /* - * Routines to manage a dynamic random access array of int64_ts which - * may grow in size to be more than the largest single malloc'able - * chunk. - */ - -#define RAA_BLKSHIFT 15 /* 2**this many longs allocated at once */ -#define RAA_BLKSIZE (1 << RAA_BLKSHIFT) -#define RAA_LAYERSHIFT 15 /* 2**this many _pointers_ allocated */ -#define RAA_LAYERSIZE (1 << RAA_LAYERSHIFT) - -typedef struct RAA RAA; -typedef union RAA_UNION RAA_UNION; -typedef struct RAA_LEAF RAA_LEAF; -typedef struct RAA_BRANCH RAA_BRANCH; - -struct RAA { - /* - * Number of layers below this one to get to the real data. 0 - * means this structure is a leaf, holding RAA_BLKSIZE real - * data items; 1 and above mean it's a branch, holding - * RAA_LAYERSIZE pointers to the next level branch or leaf - * structures. - */ - int layers; - - /* - * Number of real data items spanned by one position in the - * `data' array at this level. This number is 0 trivially, for - * a leaf (level 0): for a level 1 branch it should be - * RAA_BLKSHIFT, and for a level 2 branch it's - * RAA_LAYERSHIFT+RAA_BLKSHIFT. - */ - int shift; - - union RAA_UNION { - struct RAA_LEAF { - int64_t data[RAA_BLKSIZE]; - } l; - struct RAA_BRANCH { - struct RAA *data[RAA_LAYERSIZE]; - } b; - } u; -}; - -struct RAA *raa_init(void); -void raa_free(struct RAA *); -int64_t raa_read(struct RAA *, int32_t); -struct RAA *raa_write(struct RAA *r, int32_t posn, int64_t value); - -/* * Binary search routine. Returns index into `array' of an entry * matching `string', or <0 if no match. `array' is taken to * contain `size' elements. diff --git a/output/outaout.c b/output/outaout.c index d0f29a6..20658ac 100644 --- a/output/outaout.c +++ b/output/outaout.c @@ -18,6 +18,7 @@ #include "nasm.h" #include "nasmlib.h" #include "saa.h" +#include "raa.h" #include "stdscan.h" #include "outform.h" diff --git a/output/outas86.c b/output/outas86.c index f4d7bed..9eb6847 100644 --- a/output/outas86.c +++ b/output/outas86.c @@ -18,6 +18,7 @@ #include "nasm.h" #include "nasmlib.h" #include "saa.h" +#include "raa.h" #include "outform.h" #ifdef OF_AS86 diff --git a/output/outcoff.c b/output/outcoff.c index d8a9c8e..bbd0b57 100644 --- a/output/outcoff.c +++ b/output/outcoff.c @@ -19,6 +19,7 @@ #include "nasm.h" #include "nasmlib.h" #include "saa.h" +#include "raa.h" #include "outform.h" #if defined(OF_COFF) || defined(OF_WIN32) || defined(OF_WIN64) diff --git a/output/outelf32.c b/output/outelf32.c index 2ae387b..aae2d0d 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -17,9 +17,10 @@ #include "nasm.h" #include "nasmlib.h" +#include "saa.h" +#include "raa.h" #include "stdscan.h" #include "outform.h" -#include "saa.h" #ifdef OF_ELF32 diff --git a/output/outelf64.c b/output/outelf64.c index cd568c1..9393e7a 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -16,9 +16,10 @@ #include "nasm.h" #include "nasmlib.h" +#include "saa.h" +#include "raa.h" #include "stdscan.h" #include "outform.h" -#include "saa.h" /* Definitions in lieu of elf.h */ #define SHT_NULL 0 /* Inactive section header */ diff --git a/output/outmacho.c b/output/outmacho.c index 50cd0b4..5ac2878 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -21,6 +21,7 @@ #include "nasm.h" #include "nasmlib.h" #include "saa.h" +#include "raa.h" #include "outform.h" #include "compiler.h" @@ -0,0 +1,95 @@ +#include "nasmlib.h" +#include "raa.h" + +#define LEAFSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_LEAF)) +#define BRANCHSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_BRANCH)) + +#define LAYERSHIFT(r) ( (r)->layers==0 ? RAA_BLKSHIFT : RAA_LAYERSHIFT ) + +static struct RAA *real_raa_init(int layers) +{ + struct RAA *r; + int i; + + if (layers == 0) { + r = nasm_zalloc(LEAFSIZ); + r->shift = 0; + } else { + r = nasm_malloc(BRANCHSIZ); + r->layers = layers; + for (i = 0; i < RAA_LAYERSIZE; i++) + r->u.b.data[i] = NULL; + r->shift = (RAA_BLKSHIFT-RAA_LAYERSHIFT) + layers*RAA_LAYERSHIFT; + } + return r; +} + +struct RAA *raa_init(void) +{ + return real_raa_init(0); +} + +void raa_free(struct RAA *r) +{ + if (r->layers) { + struct RAA **p; + for (p = r->u.b.data; p - r->u.b.data < RAA_LAYERSIZE; p++) + if (*p) + raa_free(*p); + } + nasm_free(r); +} + +int64_t raa_read(struct RAA *r, int32_t posn) +{ + if ((uint32_t)posn >= (UINT32_C(1) << (r->shift + LAYERSHIFT(r)))) + return 0; /* Return 0 for undefined entries */ + while (r->layers > 0) { + int32_t l = posn >> r->shift; + posn &= (UINT32_C(1) << r->shift)-1; + r = r->u.b.data[l]; + if (!r) + return 0; /* Return 0 for undefined entries */ + } + return r->u.l.data[posn]; +} + +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"); + + while ((UINT32_C(1) << (r->shift+LAYERSHIFT(r))) <= (uint32_t)posn) { + /* + * Must add a layer. + */ + struct RAA *s; + int i; + + s = nasm_malloc(BRANCHSIZ); + for (i = 0; i < RAA_LAYERSIZE; i++) + s->u.b.data[i] = NULL; + s->layers = r->layers + 1; + s->shift = LAYERSHIFT(r) + r->shift; + s->u.b.data[0] = r; + r = s; + } + + result = r; + + while (r->layers > 0) { + struct RAA **s; + int32_t l = posn >> r->shift; + posn &= (UINT32_C(1) << r->shift)-1; + s = &r->u.b.data[l]; + if (!*s) + *s = real_raa_init(r->layers - 1); + r = *s; + } + + r->u.l.data[posn] = value; + + return result; +} @@ -0,0 +1,56 @@ +#ifndef NASM_RAA_H +#define NASM_RAA_H 1 + +#include "compiler.h" + +/* + * Routines to manage a dynamic random access array of int64_ts which + * may grow in size to be more than the largest single malloc'able + * chunk. + */ + +#define RAA_BLKSHIFT 15 /* 2**this many longs allocated at once */ +#define RAA_BLKSIZE (1 << RAA_BLKSHIFT) +#define RAA_LAYERSHIFT 15 /* 2**this many _pointers_ allocated */ +#define RAA_LAYERSIZE (1 << RAA_LAYERSHIFT) + +typedef struct RAA RAA; +typedef union RAA_UNION RAA_UNION; +typedef struct RAA_LEAF RAA_LEAF; +typedef struct RAA_BRANCH RAA_BRANCH; + +struct RAA { + /* + * Number of layers below this one to get to the real data. 0 + * means this structure is a leaf, holding RAA_BLKSIZE real + * data items; 1 and above mean it's a branch, holding + * RAA_LAYERSIZE pointers to the next level branch or leaf + * structures. + */ + int layers; + + /* + * Number of real data items spanned by one position in the + * `data' array at this level. This number is 0 trivially, for + * a leaf (level 0): for a level 1 branch it should be + * RAA_BLKSHIFT, and for a level 2 branch it's + * RAA_LAYERSHIFT+RAA_BLKSHIFT. + */ + int shift; + + union RAA_UNION { + struct RAA_LEAF { + int64_t data[RAA_BLKSIZE]; + } l; + struct RAA_BRANCH { + struct RAA *data[RAA_LAYERSIZE]; + } b; + } u; +}; + +struct RAA *raa_init(void); +void raa_free(struct RAA *); +int64_t raa_read(struct RAA *, int32_t); +struct RAA *raa_write(struct RAA *r, int32_t posn, int64_t value); + +#endif /* NASM_RAA_H */ |