From 0786a7689541f832008e672283f038ddde44a905 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 15 Mar 2003 05:07:49 +0000 Subject: [PATCH] Make libyasm a "real" library, including installing header files. Start separating modules and frontends from libyasm internals. svn path=/trunk/yasm/; revision=849 --- .cvsignore | 2 +- Makefile.am | 6 +- configure.ac | 10 +- frontends/yasm/yasm-module.c | 5 +- frontends/yasm/yasm-options.c | 4 +- frontends/yasm/yasm.c | 23 +- libltdl/Makefile.am | 2 +- libyasm.h | 79 +++++ libyasm/.cvsignore | 2 + libyasm/Makefile.inc | 47 +-- libyasm/arch.c | 25 ++ libyasm/arch.h | 14 +- libyasm/bitvect.c | 1 + libyasm/bytecode.c | 25 ++ libyasm/bytecode.h | 20 +- libyasm/coretype.h | 9 +- libyasm/errwarn.c | 1 + libyasm/errwarn.h | 6 + libyasm/expr.c | 1 + libyasm/expr.h | 6 +- libyasm/file.c | 1 + libyasm/floatnum.c | 1 + libyasm/hamt.c | 1 + libyasm/intnum.c | 1 + libyasm/linemgr.c | 1 + libyasm/mergesort.c | 18 +- libyasm/section.c | 3 +- libyasm/section.h | 4 + libyasm/strcasecmp.c | 23 +- libyasm/strsep.c | 10 +- libyasm/symrec.c | 1 + libyasm/tests/Makefile.inc | 8 +- libyasm/tests/bitvect_test.c | 2 +- libyasm/tests/floatnum_test.c | 2 +- libyasm/util.h | 159 ++++++---- libyasm/valparam.c | 42 +++ libyasm/valparam.h | 34 +- libyasm/xmalloc.c | 10 +- libyasm/xstrdup.c | 6 +- mergesort.c | 350 --------------------- modules/arch/x86/x86arch.c | 14 +- modules/arch/x86/x86bc.c | 15 +- modules/arch/x86/x86expr.c | 16 +- modules/arch/x86/x86id.re | 19 +- modules/dbgfmts/null/null-dbgfmt.c | 5 +- modules/objfmts/bin/bin-objfmt.c | 22 +- modules/objfmts/coff/coff-objfmt.c | 22 +- modules/objfmts/dbg/dbg-objfmt.c | 13 +- modules/optimizers/basic/basic-optimizer.c | 16 +- modules/parsers/nasm/nasm-bison.y | 30 +- modules/parsers/nasm/nasm-parser.c | 10 +- modules/parsers/nasm/nasm-token.re | 16 +- modules/preprocs/nasm/nasm-eval.c | 3 +- modules/preprocs/nasm/nasm-pp.c | 3 +- modules/preprocs/nasm/nasm-preproc.c | 7 +- modules/preprocs/nasm/nasmlib.c | 3 +- modules/preprocs/raw/raw-preproc.c | 8 +- modules/preprocs/yapp/yapp-preproc.c | 8 +- modules/preprocs/yapp/yapp-token.l | 6 +- strsep.c | 78 ----- util.h | 159 ++++++---- 61 files changed, 587 insertions(+), 851 deletions(-) create mode 100644 libyasm.h create mode 100644 libyasm/.cvsignore delete mode 100644 mergesort.c delete mode 100644 strsep.c diff --git a/.cvsignore b/.cvsignore index 0ab2d20c..66c84256 100644 --- a/.cvsignore +++ b/.cvsignore @@ -2,6 +2,7 @@ autom4te.cache nasm-bison.c nasm-bison.h nasm-token.c +nasm-macros.c yapp-token.c x86id.c re2c-parser.c @@ -12,7 +13,6 @@ re2c configure configure.scan config.* -stamp-h* aclocal.m4 *.tar.gz *.la diff --git a/Makefile.am b/Makefile.am index 2f56f1fd..a9381313 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,7 +5,6 @@ SUBDIRS = libltdl m4 po . AM_YFLAGS = -d AM_CFLAGS = @MORE_CFLAGS@ AM_CPPFLAGS = \ - -I$(top_srcdir)/libyasm \ -I$(top_srcdir)/check \ @INCLTDL@ @@ -13,6 +12,8 @@ bin_PROGRAMS = TESTS = noinst_PROGRAMS = +include_HEADERS = libyasm.h + lib_LTLIBRARIES = YASM_MODULES = @@ -42,6 +43,9 @@ EXTRA_DIST += \ Mkfiles/Makefile.dj Mkfiles/dj/config.h \ Mkfiles/Makefile.vc Mkfiles/vc/config.h +# Until this gets fixed in automake +DISTCLEANFILES = libyasm/stamp-h libyasm/stamp-h[0-9]* + ACLOCAL_AMFLAGS = -I m4 distclean-local: diff --git a/configure.ac b/configure.ac index 84890fc8..0da96af6 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ AC_PREREQ(2.50) AC_INIT([yasm], `date "+%Y%m%d"`, [bug-yasm@tortall.net]) #AC_CONFIG_SRCDIR([src/main.c]) AC_CONFIG_AUX_DIR(config) -AM_CONFIG_HEADER([config.h]) +AM_CONFIG_HEADER([libyasm/config.h]) AM_INIT_AUTOMAKE(yasm, `date "+%Y%m%d"`) AM_MAINTAINER_MODE @@ -115,11 +115,11 @@ AC_FUNC_FORK AC_FUNC_MALLOC AC_FUNC_VPRINTF AC_CHECK_FUNCS([abort memcpy memmove strrchr toascii vsnprintf]) +AC_CHECK_FUNCS([strsep mergesort]) # Look for the case-insensitive comparison functions AC_CHECK_FUNCS([strcasecmp strncasecmp stricmp strcmpi]) # Check for stuff wanted by the test suite. None of this is required. AC_CHECK_FUNCS([msgctl msgget msgrcv msgsnd strerror snprintf wait]) -AC_REPLACE_FUNCS([strsep mergesort]) AC_LIB_LTDL # @@ -242,12 +242,6 @@ AC_SUBST(MORE_CFLAGS) AC_SUBST(INCLTDL) AC_SUBST(LIBLTDL) -# Create LTLIBOBJS -Xsed="sed -e s/^X//" -LTLIBOBJS=`echo X"$LIB@&t@OBJS"|\ - [$Xsed -e 's,\.[^.]* ,.lo ,g;s,\.[^.]*$,.lo,']` -AC_SUBST(LTLIBOBJS) - AC_CONFIG_FILES([Makefile libltdl/Makefile m4/Makefile diff --git a/frontends/yasm/yasm-module.c b/frontends/yasm/yasm-module.c index de2c3c5f..432b2358 100644 --- a/frontends/yasm/yasm-module.c +++ b/frontends/yasm/yasm-module.c @@ -24,14 +24,13 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#include "libyasm.h" /*@unused@*/ RCSID("$IdPath$"); #include "ltdl.h" #include "yasm-module.h" -#include "objfmt.h" -#include "parser.h" typedef struct module { diff --git a/frontends/yasm/yasm-options.c b/frontends/yasm/yasm-options.c index b8e18f33..fd8ba560 100644 --- a/frontends/yasm/yasm-options.c +++ b/frontends/yasm/yasm-options.c @@ -27,11 +27,11 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#include "libyasm.h" /*@unused@*/ RCSID("$IdPath$"); #include "yasm-options.h" -#include "errwarn.h" #ifdef __DEBUG__ diff --git a/frontends/yasm/yasm.c b/frontends/yasm/yasm.c index 308bea0a..2f45ac17 100644 --- a/frontends/yasm/yasm.c +++ b/frontends/yasm/yasm.c @@ -24,32 +24,13 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#include "libyasm.h" /*@unused@*/ RCSID("$IdPath$"); #include "ltdl.h" #include "yasm-module.h" - -#include "bitvect.h" -#include "file.h" - #include "yasm-options.h" -#include "linemgr.h" -#include "errwarn.h" -#include "intnum.h" -#include "floatnum.h" -#include "expr.h" -#include "symrec.h" - -#include "bytecode.h" -#include "section.h" -#include "objfmt.h" -#include "dbgfmt.h" -#include "preproc.h" -#include "parser.h" -#include "optimizer.h" - -#include "arch.h" /* Extra path to search for our modules. */ diff --git a/libltdl/Makefile.am b/libltdl/Makefile.am index 7f014e5a..c471a20e 100644 --- a/libltdl/Makefile.am +++ b/libltdl/Makefile.am @@ -25,7 +25,7 @@ libltdlc_la_SOURCES = ltdl.c libltdlc_la_LIBADD = $(LIBADD_DL) ## Because we do not have automatic dependency tracking: -ltdl.lo: ltdl.h ../config.h +ltdl.lo: ltdl.h ../libyasm/config.h $(OBJECTS): libtool libtool: $(LIBTOOL_DEPS) diff --git a/libyasm.h b/libyasm.h new file mode 100644 index 00000000..9206f279 --- /dev/null +++ b/libyasm.h @@ -0,0 +1,79 @@ +/* $IdPath$ + * Libyasm interface primary header file. + * + * Copyright (C) 2003 Peter Johnson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 AUTHOR AND OTHER 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 AUTHOR OR OTHER 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. + */ +#ifndef YASM_LIB_H +#define YASM_LIB_H + +/* Define YASM_INTERNAL to include many internal function and variable defs. + * This includes compat-queue.h, bitvect.h, hamt.h, and util.h, which violate + * the yasm_* namespace (see individual files for details)! + * + * Additional parts may be included via YASM_*_INTERNAL inclusion flags: + * YASM_BC_INTERNAL: reveal bytecode internal structures via bc-int.h inclusion + * YASM_EXPR_INTERNAL: reveal expr internal structures via expr-int.h inclusion + * YASM_AUTOCONF_INTERNAL: include parts of util.h that depend on certain + * autoconfig settings.. see util.h for more details + * YASM_LIB_AC_INTERNAL: include libyasm/config.h if HAVE_CONFIG_H is defined + * YASM_GETTEXT_INTERNAL: define typical gettext _() and N_(). Requires + * YASM_AUTOCONF_INTERNAL define. + * + * YASM_LIB_INTERNAL: defines YASM_INTERNAL, YASM_AUTOCONF_INTERNAL, + * YASM_LIB_AC_INTERNAL, and YASM_GETTEXT_INTERNAL + * (used when compiling the library itself) + */ + +#include "libyasm/util.h" +#include "libyasm/linemgr.h" + +#include "libyasm/errwarn.h" +#include "libyasm/intnum.h" +#include "libyasm/floatnum.h" +#include "libyasm/expr.h" +#include "libyasm/symrec.h" + +#include "libyasm/bytecode.h" +#include "libyasm/section.h" + +#include "libyasm/arch.h" +#include "libyasm/dbgfmt.h" +#include "libyasm/objfmt.h" +#include "libyasm/optimizer.h" +#include "libyasm/parser.h" +#include "libyasm/preproc.h" + +#ifdef YASM_INTERNAL +#ifdef YASM_BC_INTERNAL +#include "libyasm/bc-int.h" +#endif +#ifdef YASM_EXPR_INTERNAL +#include "libyasm/expr-int.h" +#endif +#include "libyasm/file.h" +#include "libyasm/hamt.h" +#include "libyasm/bitvect.h" +#endif + +#endif diff --git a/libyasm/.cvsignore b/libyasm/.cvsignore new file mode 100644 index 00000000..aaf3458d --- /dev/null +++ b/libyasm/.cvsignore @@ -0,0 +1,2 @@ +stamp-h* +config.* diff --git a/libyasm/Makefile.inc b/libyasm/Makefile.inc index ffa7dac7..30254a2a 100644 --- a/libyasm/Makefile.inc +++ b/libyasm/Makefile.inc @@ -3,50 +3,55 @@ lib_LTLIBRARIES += libyasm.la libyasm_la_SOURCES = \ libyasm/bytecode.c \ + libyasm/expr.c \ + libyasm/symrec.c \ + libyasm/file.c \ + libyasm/section.c \ + libyasm/arch.c \ + libyasm/intnum.c \ + libyasm/floatnum.c \ + libyasm/hamt.c \ + libyasm/bitvect.c \ + libyasm/valparam.c \ + libyasm/errwarn.c \ + libyasm/linemgr.c \ + libyasm/xmalloc.c \ + libyasm/xstrdup.c \ + libyasm/strcasecmp.c \ + libyasm/mergesort.c \ + libyasm/strsep.c +libyasm_la_LDFLAGS = -no-undefined + +modincludedir = $(includedir)/libyasm +modinclude_HEADERS = \ + libyasm/util.h \ libyasm/bytecode.h \ libyasm/bc-int.h \ libyasm/errwarn.h \ - libyasm/expr.c \ libyasm/expr.h \ libyasm/expr-int.h \ - libyasm/symrec.c \ libyasm/symrec.h \ libyasm/linemgr.h \ - libyasm/util.h \ libyasm/coretype.h \ - libyasm/file.c \ libyasm/file.h \ - libyasm/section.c \ libyasm/section.h \ - libyasm/arch.c \ libyasm/arch.h \ libyasm/dbgfmt.h \ libyasm/objfmt.h \ libyasm/optimizer.h \ libyasm/parser.h \ libyasm/preproc.h \ - libyasm/intnum.c \ libyasm/intnum.h \ - libyasm/floatnum.c \ libyasm/floatnum.h \ - libyasm/hamt.c \ libyasm/hamt.h \ - libyasm/bitvect.c \ libyasm/bitvect.h \ - libyasm/valparam.c \ libyasm/valparam.h \ - libyasm/errwarn.c \ - libyasm/linemgr.c \ - libyasm/xmalloc.c \ - libyasm/xstrdup.c \ - libyasm/strcasecmp.c -libyasm_la_LIBADD = @LTLIBOBJS@ -libyasm_la_LDFLAGS = -no-undefined + libyasm/compat-queue.h + +# Generated at configure time, so must be DATA instead of HEADERS +modinclude_DATA = libyasm/config.h EXTRA_DIST += \ libyasm/tests/Makefile.inc include libyasm/tests/Makefile.inc - -EXTRA_libyasm_la_SOURCES = \ - libyasm/compat-queue.h diff --git a/libyasm/arch.c b/libyasm/arch.c index 03b96b85..b117b400 100644 --- a/libyasm/arch.c +++ b/libyasm/arch.c @@ -24,6 +24,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" /*@unused@*/ RCSID("$IdPath$"); @@ -174,3 +175,27 @@ yasm_ops_print(FILE *f, int indent_level, const yasm_insn_operandhead *headp) STAILQ_FOREACH (cur, headp, link) yasm_operand_print(f, indent_level, cur); } + +/* Non-macro yasm_ops_initialize() for non-YASM_INTERNAL users. */ +#undef yasm_ops_initialize +void +yasm_ops_initialize(yasm_insn_operandhead *headp) +{ + STAILQ_INIT(headp); +} + +/* Non-macro yasm_ops_first() for non-YASM_INTERNAL users. */ +#undef yasm_ops_first +yasm_insn_operand * +yasm_ops_first(yasm_insn_operandhead *headp) +{ + return STAILQ_FIRST(headp); +} + +/* Non-macro yasm_ops_next() for non-YASM_INTERNAL users. */ +#undef yasm_ops_next +yasm_insn_operand * +yasm_ops_next(yasm_insn_operand *cur) +{ + return STAILQ_NEXT(cur, link); +} diff --git a/libyasm/arch.h b/libyasm/arch.h index ad99f188..eecee190 100644 --- a/libyasm/arch.h +++ b/libyasm/arch.h @@ -36,10 +36,11 @@ typedef enum yasm_arch_check_id_retval { YASM_ARCH_CHECK_ID_TARGETMOD /* an target modifier (for jumps) */ } yasm_arch_check_id_retval; -typedef /*@reldef@*/ STAILQ_HEAD(yasm_insn_operandhead, yasm_insn_operand) - yasm_insn_operandhead; - typedef struct yasm_insn_operand yasm_insn_operand; +typedef struct yasm_insn_operandhead yasm_insn_operandhead; +#ifdef YASM_INTERNAL +/*@reldef@*/ STAILQ_HEAD(yasm_insn_operandhead, yasm_insn_operand); +#endif /* Different assemblers order instruction operands differently. Also, some * differ on how exactly various registers are specified. There's no great @@ -180,6 +181,7 @@ struct yasm_arch { void (*ea_data_print) (FILE *f, int indent_level, const yasm_effaddr *ea); }; +#ifdef YASM_INTERNAL struct yasm_insn_operand { /*@reldef@*/ STAILQ_ENTRY(yasm_insn_operand) link; @@ -201,6 +203,7 @@ struct yasm_insn_operand { /* Specified size of the operand, in bytes. 0 if not user-specified. */ unsigned int size; }; +#endif void yasm_arch_common_initialize(yasm_arch *a); @@ -215,9 +218,14 @@ yasm_insn_operand *yasm_operand_new_imm(/*@only@*/ yasm_expr *val); void yasm_operand_print(FILE *f, int indent_level, const yasm_insn_operand *op); +void yasm_ops_initialize(yasm_insn_operandhead *headp); +yasm_insn_operand *yasm_ops_first(yasm_insn_operandhead *headp); +yasm_insn_operand *yasm_ops_next(yasm_insn_operand *cur); +#ifdef YASM_INTERNAL #define yasm_ops_initialize(headp) STAILQ_INIT(headp) #define yasm_ops_first(headp) STAILQ_FIRST(headp) #define yasm_ops_next(cur) STAILQ_NEXT(cur, link) +#endif /* Deletes operands linked list. Deletes content of each operand if content i * nonzero. diff --git a/libyasm/bitvect.c b/libyasm/bitvect.c index bd2a85e7..533e68c5 100644 --- a/libyasm/bitvect.c +++ b/libyasm/bitvect.c @@ -1,3 +1,4 @@ +#define YASM_LIB_INTERNAL #include "util.h" RCSID("$IdPath$"); diff --git a/libyasm/bytecode.c b/libyasm/bytecode.c index aa1815a3..808677e7 100644 --- a/libyasm/bytecode.c +++ b/libyasm/bytecode.c @@ -24,6 +24,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" /*@unused@*/ RCSID("$IdPath$"); @@ -983,3 +984,27 @@ yasm_dvs_print(FILE *f, int indent_level, const yasm_datavalhead *head) } } } + +/* Non-macro yasm_bcs_initialize() for non-YASM_INTERNAL users. */ +#undef yasm_bcs_initialize +void +yasm_bcs_initialize(yasm_bytecodehead *headp) +{ + STAILQ_INIT(headp); +} + +/* Non-macro yasm_bcs_first() for non-YASM_INTERNAL users. */ +#undef yasm_bcs_first +yasm_bytecode * +yasm_bcs_first(yasm_bytecodehead *headp) +{ + return STAILQ_FIRST(headp); +} + +/* Non-macro yasm_dvs_initialize() for non-YASM_INTERNAL users. */ +#undef yasm_dvs_initialize +void +yasm_dvs_initialize(yasm_datavalhead *headp) +{ + STAILQ_INIT(headp); +} diff --git a/libyasm/bytecode.h b/libyasm/bytecode.h index 0e64920e..276633d5 100644 --- a/libyasm/bytecode.h +++ b/libyasm/bytecode.h @@ -29,9 +29,12 @@ typedef struct yasm_effaddr yasm_effaddr; typedef struct yasm_immval yasm_immval; -typedef /*@reldef@*/ STAILQ_HEAD(yasm_datavalhead, yasm_dataval) - yasm_datavalhead; typedef struct yasm_dataval yasm_dataval; +typedef struct yasm_datavalhead yasm_datavalhead; + +#ifdef YASM_INTERNAL +/*@reldef@*/ STAILQ_HEAD(yasm_bytecodehead, yasm_bytecode); +/*@reldef@*/ STAILQ_HEAD(yasm_datavalhead, yasm_dataval); /* Additional types may be architecture-defined starting at * YASM_BYTECODE_TYPE_BASE. @@ -45,6 +48,7 @@ typedef enum { YASM_BC__OBJFMT_DATA } yasm_bytecode_type; #define YASM_BYTECODE_TYPE_BASE YASM_BC__OBJFMT_DATA+1 +#endif void yasm_bc_initialize(yasm_arch *a); @@ -142,11 +146,15 @@ yasm_bc_resolve_flags yasm_bc_resolve(yasm_bytecode *bc, int save, /*@null@*/ yasm_output_bc_objfmt_data_func output_bc_objfmt_data) /*@sets *buf@*/; -/* void yasm_bcs_initialize(yasm_bytecodehead *headp); */ +void yasm_bcs_initialize(yasm_bytecodehead *headp); +#ifdef YASM_INTERNAL #define yasm_bcs_initialize(headp) STAILQ_INIT(headp) +#endif -/* yasm_bytecode *yasm_bcs_first(yasm_bytecodehead *headp); */ +yasm_bytecode *yasm_bcs_first(yasm_bytecodehead *headp); +#ifdef YASM_INTERNAL #define yasm_bcs_first(headp) STAILQ_FIRST(headp) +#endif /*@null@*/ yasm_bytecode *yasm_bcs_last(yasm_bytecodehead *headp); void yasm_bcs_delete(yasm_bytecodehead *headp); @@ -176,8 +184,10 @@ yasm_dataval *yasm_dv_new_expr(/*@keep@*/ yasm_expr *expn); yasm_dataval *yasm_dv_new_float(/*@keep@*/ yasm_floatnum *flt); yasm_dataval *yasm_dv_new_string(/*@keep@*/ char *str_val); -/* void yasm_dvs_initialize(yasm_datavalhead *headp); */ +void yasm_dvs_initialize(yasm_datavalhead *headp); +#ifdef YASM_INTERNAL #define yasm_dvs_initialize(headp) STAILQ_INIT(headp) +#endif void yasm_dvs_delete(yasm_datavalhead *headp); diff --git a/libyasm/coretype.h b/libyasm/coretype.h index 86ea58b4..75d9f88d 100644 --- a/libyasm/coretype.h +++ b/libyasm/coretype.h @@ -36,12 +36,10 @@ typedef struct yasm_objfmt yasm_objfmt; typedef struct yasm_dbgfmt yasm_dbgfmt; typedef struct yasm_bytecode yasm_bytecode; -typedef /*@reldef@*/ STAILQ_HEAD(yasm_bytecodehead, yasm_bytecode) - yasm_bytecodehead; +typedef struct yasm_bytecodehead yasm_bytecodehead; typedef struct yasm_section yasm_section; -typedef /*@reldef@*/ STAILQ_HEAD(yasm_sectionhead, yasm_section) - yasm_sectionhead; +typedef struct yasm_sectionhead yasm_sectionhead; typedef struct yasm_symrec yasm_symrec; @@ -51,6 +49,9 @@ typedef struct yasm_floatnum yasm_floatnum; typedef struct yasm_linemgr yasm_linemgr; +typedef struct yasm_valparam yasm_valparam; +typedef struct yasm_valparamhead yasm_valparamhead; + typedef enum { YASM_EXPR_ADD, YASM_EXPR_SUB, diff --git a/libyasm/errwarn.c b/libyasm/errwarn.c index 9909a403..ac30639c 100644 --- a/libyasm/errwarn.c +++ b/libyasm/errwarn.c @@ -24,6 +24,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" /*@unused@*/ RCSID("$IdPath$"); diff --git a/libyasm/errwarn.h b/libyasm/errwarn.h index 4e312522..dd46adc8 100644 --- a/libyasm/errwarn.h +++ b/libyasm/errwarn.h @@ -54,6 +54,8 @@ extern /*@exits@*/ void (*yasm_internal_error_) */ extern /*@exits@*/ void (*yasm_fatal) (const char *message); +#ifdef YASM_INTERNAL + /* va_list versions of the below two functions */ void yasm__error_va(unsigned long lindex, const char *, va_list va); void yasm__warning_va(yasm_warn_class, unsigned long lindex, const char *, @@ -68,6 +70,8 @@ void yasm__warning(yasm_warn_class, unsigned long lindex, const char *, ...) */ void yasm__parser_error(unsigned long lindex, const char *); +#endif + /* Enables/disables a class of warnings. */ void yasm_warn_enable(yasm_warn_class); void yasm_warn_disable(yasm_warn_class); @@ -85,8 +89,10 @@ void yasm_errwarn_output_all void (*print_warning) (const char *fn, unsigned long line, const char *msg)); +#ifdef YASM_INTERNAL /* Convert a possibly unprintable character into a printable string. */ char *yasm__conv_unprint(char ch); +#endif /* Map to gettext() if gettext is being used. */ extern const char * (*yasm_gettext_hook) (const char *msgid); diff --git a/libyasm/expr.c b/libyasm/expr.c index 7fd8c948..fe120100 100644 --- a/libyasm/expr.c +++ b/libyasm/expr.c @@ -24,6 +24,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" /*@unused@*/ RCSID("$IdPath$"); diff --git a/libyasm/expr.h b/libyasm/expr.h index b65cb043..674135da 100644 --- a/libyasm/expr.h +++ b/libyasm/expr.h @@ -62,7 +62,11 @@ void yasm_expr_delete(/*@only@*/ /*@null@*/ yasm_expr *e); typedef /*@only@*/ yasm_expr * (*yasm_expr_xform_func) (/*@returned@*/ /*@only@*/ yasm_expr *e, /*@null@*/ void *d); -typedef SLIST_HEAD(yasm__exprhead, yasm__exprentry) yasm__exprhead; +typedef struct yasm__exprhead yasm__exprhead; +#ifdef YASM_INTERNAL +SLIST_HEAD(yasm__exprhead, yasm__exprentry); +#endif + /* Level an entire expn tree. Call with eh = NULL */ /*@only@*/ /*@null@*/ yasm_expr *yasm_expr__level_tree (/*@returned@*/ /*@only@*/ /*@null@*/ yasm_expr *e, int fold_const, diff --git a/libyasm/file.c b/libyasm/file.c index 46906b22..162dcfdc 100644 --- a/libyasm/file.c +++ b/libyasm/file.c @@ -24,6 +24,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" /*@unused@*/ RCSID("$IdPath$"); diff --git a/libyasm/floatnum.c b/libyasm/floatnum.c index bb744e72..13f9d9fe 100644 --- a/libyasm/floatnum.c +++ b/libyasm/floatnum.c @@ -26,6 +26,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" /*@unused@*/ RCSID("$IdPath$"); diff --git a/libyasm/hamt.c b/libyasm/hamt.c index 69e142a9..e656af2c 100644 --- a/libyasm/hamt.c +++ b/libyasm/hamt.c @@ -29,6 +29,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" /*@unused@*/ RCSID("$IdPath$"); diff --git a/libyasm/intnum.c b/libyasm/intnum.c index ea97fcb3..26312a48 100644 --- a/libyasm/intnum.c +++ b/libyasm/intnum.c @@ -24,6 +24,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" /*@unused@*/ RCSID("$IdPath$"); diff --git a/libyasm/linemgr.c b/libyasm/linemgr.c index 02507849..df6beac2 100644 --- a/libyasm/linemgr.c +++ b/libyasm/linemgr.c @@ -24,6 +24,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" /*@unused@*/ RCSID("$IdPath$"); diff --git a/libyasm/mergesort.c b/libyasm/mergesort.c index 3ec4b80e..6014389b 100644 --- a/libyasm/mergesort.c +++ b/libyasm/mergesort.c @@ -31,6 +31,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" /*@unused@*/ RCSID("$IdPath$"); @@ -38,6 +39,11 @@ static char sccsid[] = "@(#)merge.c 8.2 (Berkeley) 2/14/94"; #endif /* LIBC_SCCS and not lint */ +#ifdef HAVE_MERGESORT +#undef yasm__mergesort +#endif + +#ifndef HAVE_MERGESORT /* * Hybrid exponential search/linear search merge sort with hybrid * natural/pairwise first pass. Requires about .3% more comparisons @@ -91,14 +97,18 @@ static void insertionsort(unsigned char *, size_t, size_t, #define EVAL(p) (unsigned char **) \ ((unsigned char *)0 + \ (((unsigned char *)p + PSIZE - 1 - (unsigned char *) 0) & ~(PSIZE - 1))) +#endif /*HAVE_MERGESORT*/ /* * Arguments are as for qsort. */ int -mergesort(void *base, size_t nmemb, size_t size, - int (*cmp)(const void *, const void *)) +yasm__mergesort(void *base, size_t nmemb, size_t size, + int (*cmp)(const void *, const void *)) { +#ifdef HAVE_MERGESORT + return mergesort(base, nmemb, size, cmp); +#else size_t i; int sense; int big, iflag; @@ -232,8 +242,11 @@ COPY: b = t; } xfree(list2); return (0); +#endif /*HAVE_MERGESORT*/ } +#ifndef HAVE_MERGESORT + #define swap(a, b) { \ s = b; \ i = size; \ @@ -348,3 +361,4 @@ insertionsort(unsigned char *a, size_t n, size_t size, swap(u, t); } } +#endif /*HAVE_MERGESORT*/ diff --git a/libyasm/section.c b/libyasm/section.c index 861eb045..d260671e 100644 --- a/libyasm/section.c +++ b/libyasm/section.c @@ -24,6 +24,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" /*@unused@*/ RCSID("$IdPath$"); @@ -73,7 +74,7 @@ yasm_sections_initialize(yasm_sectionhead *headp, yasm_objfmt *of) STAILQ_INIT(headp); /* Add an initial "default" section */ - yasm_vp_new(vp, yasm__xstrdup(of->default_section_name), NULL); + vp = yasm_vp_new(yasm__xstrdup(of->default_section_name), NULL); yasm_vps_initialize(&vps); yasm_vps_append(&vps, vp); s = of->sections_switch(headp, &vps, NULL, 0); diff --git a/libyasm/section.h b/libyasm/section.h index ffef79ee..7f351fb6 100644 --- a/libyasm/section.h +++ b/libyasm/section.h @@ -27,6 +27,10 @@ #ifndef YASM_SECTION_H #define YASM_SECTION_H +#ifdef YASM_INTERNAL +/*@reldef@*/ STAILQ_HEAD(yasm_sectionhead, yasm_section); +#endif + /*@dependent@*/ yasm_section *yasm_sections_initialize(yasm_sectionhead *headp, yasm_objfmt *of); diff --git a/libyasm/strcasecmp.c b/libyasm/strcasecmp.c index a7b2a927..7ef5df35 100644 --- a/libyasm/strcasecmp.c +++ b/libyasm/strcasecmp.c @@ -29,11 +29,15 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" /*@unused@*/ RCSID("$IdPath$"); -#ifdef USE_OUR_OWN_STRCASECMP +#ifndef USE_OUR_OWN_STRCASECMP +#undef yasm__strcasecmp +#undef yasm__strncasecmp +#endif #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; @@ -44,6 +48,13 @@ static char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; int yasm__strcasecmp(const char *s1, const char *s2) { +#ifdef HAVE_STRCASECMP + return strcasecmp(s1, s2); +#elif HAVE_STRICMP + return stricmp(s1, s2); +#elif HAVE_STRCMPI + return strcmpi(s1, s2); +#else const unsigned char *us1 = (const unsigned char *)s1, *us2 = (const unsigned char *)s2; @@ -52,11 +63,19 @@ yasm__strcasecmp(const char *s1, const char *s2) if (*us1++ == '\0') return (0); return (tolower(*us1) - tolower(*--us2)); +#endif } int yasm__strncasecmp(const char *s1, const char *s2, size_t n) { +#ifdef HAVE_STRCASECMP + return strncasecmp(s1, s2, n); +#elif HAVE_STRICMP + return strnicmp(s1, s2, n); +#elif HAVE_STRCMPI + return strncmpi(s1, s2, n); +#else const unsigned char *us1 = (const unsigned char *)s1, *us2 = (const unsigned char *)s2; @@ -70,5 +89,5 @@ yasm__strncasecmp(const char *s1, const char *s2, size_t n) } while (--n != 0); } return (0); -} #endif +} diff --git a/libyasm/strsep.c b/libyasm/strsep.c index 0e84acfc..f0dbc11f 100644 --- a/libyasm/strsep.c +++ b/libyasm/strsep.c @@ -28,6 +28,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" /*@unused@*/ RCSID("$IdPath$"); @@ -36,6 +37,9 @@ static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#ifdef HAVE_STRSEP +#undef yasm__strsep +#endif /* * Get next token from string *stringp, where tokens are possibly-empty @@ -50,8 +54,11 @@ static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93"; */ /*@-nullstate@*/ char * -strsep(char **stringp, const char *delim) +yasm__strsep(char **stringp, const char *delim) { +#ifdef HAVE_STRSEP + return strsep(stringp, delim); +#else register char *s; register const char *spanp; register int c, sc; @@ -74,5 +81,6 @@ strsep(char **stringp, const char *delim) } while (sc != 0); } /* NOTREACHED */ +#endif } /*@=nullstate@*/ diff --git a/libyasm/symrec.c b/libyasm/symrec.c index b6ceb1b8..dfadef3f 100644 --- a/libyasm/symrec.c +++ b/libyasm/symrec.c @@ -24,6 +24,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" /*@unused@*/ RCSID("$IdPath$"); diff --git a/libyasm/tests/Makefile.inc b/libyasm/tests/Makefile.inc index ac4b6125..fe0692e1 100644 --- a/libyasm/tests/Makefile.inc +++ b/libyasm/tests/Makefile.inc @@ -13,7 +13,7 @@ bitvect_test_SOURCES = \ libyasm/tests/bitvect_test.c \ $(CHECKFILES) bitvect_test_LDFLAGS = -bitvect_test_LDADD = libyasm.la @LIBLTDL@ @LIBOBJS@ $(INTLLIBS) @LIBADD_DL@ +bitvect_test_LDADD = libyasm.la @LIBLTDL@ $(INTLLIBS) @LIBADD_DL@ #bytecode_test_CFLAGS = #bytecode_test_SOURCES = \ @@ -25,14 +25,14 @@ bitvect_test_LDADD = libyasm.la @LIBLTDL@ @LIBOBJS@ $(INTLLIBS) @LIBADD_DL@ # $(YASMARCHFILES) \ # $(CHECKFILES) #bytecode_test_LDFLAGS = -#bytecode_test_LDADD = libyasm.la @LIBLTDL@ @LIBOBJS@ $(INTLLIBS) @LIBADD_DL@ +#bytecode_test_LDADD = libyasm.la @LIBLTDL@ $(INTLLIBS) @LIBADD_DL@ floatnum_test_CFLAGS = floatnum_test_SOURCES = \ libyasm/tests/floatnum_test.c \ $(CHECKFILES) floatnum_test_LDFLAGS = -floatnum_test_LDADD = libyasm.la @LIBLTDL@ @LIBOBJS@ $(INTLLIBS) @LIBADD_DL@ +floatnum_test_LDADD = libyasm.la @LIBLTDL@ $(INTLLIBS) @LIBADD_DL@ #memexpr_test_CFLAGS = #memexpr_test_SOURCES = \ @@ -44,4 +44,4 @@ floatnum_test_LDADD = libyasm.la @LIBLTDL@ @LIBOBJS@ $(INTLLIBS) @LIBADD_DL@ # $(YASMARCHFILES) \ # $(CHECKFILES) #memexpr_test_LDFLAGS = -#memexpr_test_LDADD = libyasm.la @LIBLTDL@ @LIBOBJS@ $(INTLLIBS) @LIBADD_DL@ +#memexpr_test_LDADD = libyasm.la @LIBLTDL@ $(INTLLIBS) @LIBADD_DL@ diff --git a/libyasm/tests/bitvect_test.c b/libyasm/tests/bitvect_test.c index 6ad5b430..afc15063 100644 --- a/libyasm/tests/bitvect_test.c +++ b/libyasm/tests/bitvect_test.c @@ -36,7 +36,7 @@ #include "check.h" -#include "bitvect.h" +#include "libyasm/bitvect.h" START_TEST(test_boot) { diff --git a/libyasm/tests/floatnum_test.c b/libyasm/tests/floatnum_test.c index bf18f93a..41875b14 100644 --- a/libyasm/tests/floatnum_test.c +++ b/libyasm/tests/floatnum_test.c @@ -36,7 +36,7 @@ #include "check.h" -#include "floatnum.c" +#include "libyasm/floatnum.c" /* constants describing parameters of internal floating point format. * (these should match those in src/floatnum.c !) diff --git a/libyasm/util.h b/libyasm/util.h index fc0113c7..ccdbfe32 100644 --- a/libyasm/util.h +++ b/libyasm/util.h @@ -29,86 +29,106 @@ #ifndef YASM_UTIL_H #define YASM_UTIL_H -#ifdef HAVE_CONFIG_H -# include +#include + +#ifdef YASM_LIB_INTERNAL +# define YASM_INTERNAL +# define YASM_AUTOCONF_INTERNAL +# define YASM_LIB_AC_INTERNAL +# define YASM_GETTEXT_INTERNAL #endif -#include +#ifdef YASM_INTERNAL +# include + +#if defined(YASM_LIB_AC_INTERNAL) && defined(HAVE_CONFIG_H) +# include "libyasm/config.h" +#endif #if !defined(lint) # define NDEBUG #endif -#ifdef STDC_HEADERS -# include -# include -# include -# include -# include -#endif +#ifdef YASM_AUTOCONF_INTERNAL -#if defined(lint) -#define _(String) String -#else -# ifdef HAVE_LOCALE_H -# include +# ifdef STDC_HEADERS +# include +# include +# include +# include # endif -# ifdef ENABLE_NLS -# include -# define _(String) gettext(String) -# else -# define gettext(Msgid) (Msgid) -# define dgettext(Domainname, Msgid) (Msgid) -# define dcgettext(Domainname, Msgid, Category) (Msgid) -# define textdomain(Domainname) while (0) /* nothing */ -# define bindtextdomain(Domainname, Dirname) while (0) /* nothing */ -# define _(String) (String) -# endif -#endif +# ifdef YASM_GETTEXT_INTERNAL +# if defined(lint) +# define _(String) String +# else +# ifdef HAVE_LOCALE_H +# include +# endif + +# ifdef ENABLE_NLS +# include +# define _(String) gettext(String) +# else +# define gettext(Msgid) (Msgid) +# define dgettext(Domainname, Msgid) (Msgid) +# define dcgettext(Domainname, Msgid, Category) (Msgid) +# define textdomain(Domainname) while (0) /* nothing */ +# define bindtextdomain(Domainname, Dirname) while (0) /* nothing */ +# define _(String) (String) +# endif +# endif -#ifdef gettext_noop -# define N_(String) gettext_noop(String) -#else -# define N_(String) (String) -#endif +# ifdef gettext_noop +# define N_(String) gettext_noop(String) +# else +# define N_(String) (String) +# endif -#if !defined(HAVE_MERGESORT) || defined(lint) -int mergesort(void *base, size_t nmemb, size_t size, - int (*compar)(const void *, const void *)); -#endif +# endif /*YASM_GETTEXT_INTERNAL*/ + +#endif /*YASM_AUTOCONF_INTERNAL*/ + +int yasm__mergesort(void *base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *)); -#if !defined(HAVE_STRSEP) || defined(lint) -/*@null@*/ char *strsep(char **stringp, const char *delim); +#if defined(YASM_AUTOCONF_INTERNAL) && defined(HAVE_MERGESORT) +#define yasm__mergesort(a, b, c, d) mergesort(a, b, c, d) #endif -#ifdef HAVE_STRCASECMP -# define yasm__strcasecmp(x, y) strcasecmp(x, y) -# define yasm__strncasecmp(x, y) strncasecmp(x, y) -#else -# ifdef HAVE_STRICMP -# define yasm__strcasecmp(x, y) stricmp(x, y) -# define yasm__strncasecmp(x, y) strnicmp(x, y) -# elif HAVE_STRCMPI -# define yasm__strcasecmp(x, y) strcmpi(x, y) -# define yasm__strncasecmp(x, y) strncmpi(x, y) -# else -# define USE_OUR_OWN_STRCASECMP -# endif +/*@null@*/ char *yasm__strsep(char **stringp, const char *delim); + +#if defined(YASM_AUTOCONF_INTERNAL) && defined(HAVE_STRSEP) +#define yasm__strsep(a, b) strsep(a, b) #endif -#if defined(USE_OUR_OWN_STRCASECMP) || defined(lint) int yasm__strcasecmp(const char *s1, const char *s2); int yasm__strncasecmp(const char *s1, const char *s2, size_t n); + +#ifdef YASM_AUTOCONF_INTERNAL + +#ifdef HAVE_STRCASECMP +# define yasm__strcasecmp(x, y) strcasecmp(x, y) +# define yasm__strncasecmp(x, y, n) strncasecmp(x, y, n) +#elif HAVE_STRICMP +# define yasm__strcasecmp(x, y) stricmp(x, y) +# define yasm__strncasecmp(x, y, n) strnicmp(x, y, n) +#elif HAVE_STRCMPI +# define yasm__strcasecmp(x, y) strcmpi(x, y) +# define yasm__strncasecmp(x, y, n) strncmpi(x, y, n) +#else +# define USE_OUR_OWN_STRCASECMP #endif #if !defined(HAVE_TOASCII) || defined(lint) # define toascii(c) ((c) & 0x7F) #endif -#include "compat-queue.h" +#endif /*YASM_AUTOCONF_INTERNAL*/ -#ifdef HAVE_SYS_CDEFS_H +#include "libyasm/compat-queue.h" + +#if defined(YASM_AUTOCONF_INTERNAL) && defined(HAVE_SYS_CDEFS_H) # include #endif @@ -126,18 +146,11 @@ int yasm__strncasecmp(const char *s1, const char *s2, size_t n); # endif #endif -#ifdef WITH_DMALLOC -# include - -#define yasm__xstrdup(str) xstrdup(str) -#define yasm_xmalloc(size) xmalloc(size) -#define yasm_xcalloc(count, size) xcalloc(count, size) -#define yasm_xrealloc(ptr, size) xrealloc(ptr, size) -#define yasm_xfree(ptr) xfree(ptr) - -#else /* strdup() implementation with error checking (using xmalloc). */ /*@only@*/ char *yasm__xstrdup(const char *str); +/*@only@*/ char *yasm__xstrndup(const char *str, size_t len); + +#endif /*YASM_INTERNAL*/ /* Error-checking memory allocation routines. Default implementations in * xmalloc.c. @@ -150,9 +163,17 @@ extern /*@only@*/ void * (*yasm_xrealloc) extern void (*yasm_xfree) (/*@only@*/ /*@out@*/ /*@null@*/ void *p) /*@modifies p@*/; -#endif +#ifdef YASM_INTERNAL -/*@only@*/ char *yasm__xstrndup(const char *str, size_t len); +#if defined(YASM_AUTOCONF_INTERNAL) && defined(WITH_DMALLOC) +# include + +#define yasm__xstrdup(str) xstrdup(str) +#define yasm_xmalloc(size) xmalloc(size) +#define yasm_xcalloc(count, size) xcalloc(count, size) +#define yasm_xrealloc(ptr, size) xrealloc(ptr, size) +#define yasm_xfree(ptr) xfree(ptr) +#endif /* Bit-counting: used primarily by HAMT but also in a few other places. */ #define SK5 0x55555555 @@ -172,8 +193,10 @@ extern void (*yasm_xfree) (/*@only@*/ /*@out@*/ /*@null@*/ void *p) #define NELEMS(array) (sizeof(array) / sizeof(array[0])) #endif -#include "coretype.h" +#endif /*YASM_INTERNAL*/ + +#include "libyasm/coretype.h" -#include "valparam.h" +#include "libyasm/valparam.h" #endif diff --git a/libyasm/valparam.c b/libyasm/valparam.c index 8126712b..4c27382b 100644 --- a/libyasm/valparam.c +++ b/libyasm/valparam.c @@ -24,12 +24,21 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" /*@unused@*/ RCSID("$IdPath$"); #include "expr.h" +yasm_valparam * +yasm_vp_new(/*@keep@*/ const char *v, /*@keep@*/ yasm_expr *p) +{ + yasm_valparam *r = yasm_xmalloc(sizeof(yasm_valparam)); + r->val = v; + r->param = p; +} + void yasm_vps_delete(yasm_valparamhead *headp) { @@ -72,3 +81,36 @@ yasm_vps_print(FILE *f, const yasm_valparamhead *headp) fprintf(f, ","); } } + +/* Non-macro yasm_vps_initialize() for non-YASM_INTERNAL users. */ +#undef yasm_vps_initialize +void +yasm_vps_initialize(/*@out@*/ yasm_valparamhead *headp) +{ + STAILQ_INIT(headp); +} + +/* Non-macro yasm_vps_append() for non-YASM_INTERNAL users. */ +#undef yasm_vps_append +void +yasm_vps_append(yasm_valparamhead *headp, /*@keep@*/ yasm_valparam *vp) +{ + if (vp) + STAILQ_INSERT_TAIL(headp, vp, link); +} + +/* Non-macro yasm_vps_first() for non-YASM_INTERNAL users. */ +#undef yasm_vps_first +/*@null@*/ /*@dependent@*/ yasm_valparam * +yasm_vps_first(yasm_valparamhead *headp) +{ + return STAILQ_FIRST(headp); +} + +/* Non-macro yasm_vps_next() for non-YASM_INTERNAL users. */ +#undef yasm_vps_next +/*@null@*/ /*@dependent@*/ yasm_valparam * +yasm_vps_next(yasm_valparam *cur) +{ + return STAILQ_NEXT(cur, link); +} diff --git a/libyasm/valparam.h b/libyasm/valparam.h index af7af9c1..0d5a2620 100644 --- a/libyasm/valparam.h +++ b/libyasm/valparam.h @@ -27,40 +27,42 @@ #ifndef YASM_VALPARAM_H #define YASM_VALPARAM_H -typedef struct yasm_valparam { +#ifdef YASM_INTERNAL +struct yasm_valparam { /*@reldef@*/ STAILQ_ENTRY(yasm_valparam) link; /*@owned@*/ /*@null@*/ char *val; /*@owned@*/ /*@null@*/ yasm_expr *param; -} yasm_valparam; -typedef /*@reldef@*/ STAILQ_HEAD(yasm_valparamhead, yasm_valparam) - yasm_valparamhead; +}; +/*@reldef@*/ STAILQ_HEAD(yasm_valparamhead, yasm_valparam); +#endif -void yasm_vp_new(/*@out@*/ yasm_valparam *r, /*@keep@*/ const char *v, - /*@keep@*/ yasm_expr *p); -#define yasm_vp_new(r, v, p) do { \ - r = yasm_xmalloc(sizeof(yasm_valparam)); \ - r->val = v; \ - r->param = p; \ - } while(0) +yasm_valparam *yasm_vp_new(/*@keep@*/ const char *v, /*@keep@*/ yasm_expr *p); -/* void yasm_vps_initialize(//@out@// yasm_valparamhead *headp); */ +void yasm_vps_initialize(/*@out@*/ yasm_valparamhead *headp); +#ifdef YASM_INTERNAL #define yasm_vps_initialize(headp) STAILQ_INIT(headp) +#endif void yasm_vps_delete(yasm_valparamhead *headp); void yasm_vps_append(yasm_valparamhead *headp, /*@keep@*/ yasm_valparam *vp); +#ifdef YASM_INTERNAL #define yasm_vps_append(headp, vp) do { \ if (vp) \ STAILQ_INSERT_TAIL(headp, vp, link); \ } while(0) +#endif -/* //@null@// //@dependent@// yasm_valparam *yasm_vps_first - (yasm_valparamhead *headp); */ +/*@null@*/ /*@dependent@*/ yasm_valparam *yasm_vps_first + (yasm_valparamhead *headp); +#ifdef YASM_INTERNAL #define yasm_vps_first(headp) STAILQ_FIRST(headp) +#endif -/* //@null@// //@dependent@// yasm_valparam *yasm_vps_next - (yasm_valparam *cur); */ +/*@null@*/ /*@dependent@*/ yasm_valparam *yasm_vps_next(yasm_valparam *cur); +#ifdef YASM_INTERNAL #define yasm_vps_next(cur) STAILQ_NEXT(cur, link) #define yasm_vps_foreach(iter, headp) STAILQ_FOREACH(iter, headp, link) +#endif void yasm_vps_print(FILE *f, /*@null@*/ const yasm_valparamhead *headp); diff --git a/libyasm/xmalloc.c b/libyasm/xmalloc.c index b8fbe013..188b5508 100644 --- a/libyasm/xmalloc.c +++ b/libyasm/xmalloc.c @@ -24,13 +24,19 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" RCSID("$IdPath$"); #include "errwarn.h" -#ifndef WITH_DMALLOC +#ifdef WITH_DMALLOC +#undef yasm_xmalloc +#undef yasm_xcalloc +#undef yasm_xrealloc +#undef yasm_xfree +#endif static /*@only@*/ /*@out@*/ void *def_xmalloc(size_t size); static /*@only@*/ void *def_xcalloc(size_t nelem, size_t elsize); @@ -103,5 +109,3 @@ def_xfree(void *p) return; free(p); } - -#endif diff --git a/libyasm/xstrdup.c b/libyasm/xstrdup.c index 473554fc..6395a351 100644 --- a/libyasm/xstrdup.c +++ b/libyasm/xstrdup.c @@ -28,6 +28,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ +#define YASM_LIB_INTERNAL #include "util.h" RCSID("$IdPath$"); @@ -47,7 +48,9 @@ void memcpy(void *, const void *, size_t); # endif #endif -#ifndef WITH_DMALLOC +#ifdef WITH_DMALLOC +#undef yasm__xstrdup +#endif char * yasm__xstrdup(const char *str) @@ -60,7 +63,6 @@ yasm__xstrdup(const char *str) memcpy(copy, str, len); return (copy); } -#endif char * yasm__xstrndup(const char *str, size_t len) diff --git a/mergesort.c b/mergesort.c deleted file mode 100644 index 3ec4b80e..00000000 --- a/mergesort.c +++ /dev/null @@ -1,350 +0,0 @@ -/* - * mergesort() implementation for systems that don't have it. - * - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 "util.h" -/*@unused@*/ RCSID("$IdPath$"); - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)merge.c 8.2 (Berkeley) 2/14/94"; -#endif /* LIBC_SCCS and not lint */ - -/* - * Hybrid exponential search/linear search merge sort with hybrid - * natural/pairwise first pass. Requires about .3% more comparisons - * for random data than LSMS with pairwise first pass alone. - * It works for objects as small as two bytes. - */ - -#define NATURAL -#define THRESHOLD 16 /* Best choice for natural merge cut-off. */ - -/* #define NATURAL to get hybrid natural merge. - * (The default is pairwise merging.) - */ - -#ifdef STDC_HEADERS -# include -# include -#endif - -static void setup(unsigned char *, unsigned char *, size_t, size_t, - int (*)(const void *, const void *)); -static void insertionsort(unsigned char *, size_t, size_t, - int (*)(const void *, const void *)); - -#define ISIZE sizeof(int) -#define PSIZE sizeof(unsigned char *) -#define ICOPY_LIST(src, dst, last) \ - do \ - *(int*)dst = *(int*)src, src += ISIZE, dst += ISIZE; \ - while(src < last) -#define ICOPY_ELT(src, dst, i) \ - do \ - *(int*) dst = *(int*) src, src += ISIZE, dst += ISIZE; \ - while (i -= ISIZE) - -#define CCOPY_LIST(src, dst, last) \ - do \ - *dst++ = *src++; \ - while (src < last) -#define CCOPY_ELT(src, dst, i) \ - do \ - *dst++ = *src++; \ - while (i -= 1) - -/* - * Find the next possible pointer head. (Trickery for forcing an array - * to do double duty as a linked list when objects do not align with word - * boundaries. - */ -/* Assumption: PSIZE is a power of 2. */ -#define EVAL(p) (unsigned char **) \ - ((unsigned char *)0 + \ - (((unsigned char *)p + PSIZE - 1 - (unsigned char *) 0) & ~(PSIZE - 1))) - -/* - * Arguments are as for qsort. - */ -int -mergesort(void *base, size_t nmemb, size_t size, - int (*cmp)(const void *, const void *)) -{ - size_t i; - int sense; - int big, iflag; - unsigned char *f1, *f2, *t, *b, *tp2, *q, *l1, *l2; - unsigned char *list2, *list1, *p2, *p, *last, **p1; - - if (size < PSIZE / 2) { /* Pointers must fit into 2 * size. */ -#ifdef EINVAL - errno = EINVAL; -#endif - return (-1); - } - - if (nmemb == 0) - return (0); - - /* - * XXX - * Stupid subtraction for the Cray. - */ - iflag = 0; - if (!(size % ISIZE) && !(((char *)base - (char *)0) % ISIZE)) - iflag = 1; - - if ((list2 = xmalloc(nmemb * size + PSIZE)) == NULL) - return (-1); - - list1 = base; - setup(list1, list2, nmemb, size, cmp); - last = list2 + nmemb * size; - i = 0; - big = 0; - while (*EVAL(list2) != last) { - l2 = list1; - p1 = EVAL(list1); - for (tp2 = p2 = list2; p2 != last; p1 = EVAL(l2)) { - p2 = *EVAL(p2); - f1 = l2; - f2 = l1 = list1 + (p2 - list2); - if (p2 != last) - p2 = *EVAL(p2); - l2 = list1 + (p2 - list2); - while (f1 < l1 && f2 < l2) { - if ((*cmp)(f1, f2) <= 0) { - q = f2; - b = f1, t = l1; - sense = -1; - } else { - q = f1; - b = f2, t = l2; - sense = 0; - } - if (!big) { /* here i = 0 */ - while ((b += size) < t && cmp(q, b) >sense) - if (++i == 6) { - big = 1; - goto EXPONENTIAL; - } - } else { -EXPONENTIAL: for (i = size; ; i <<= 1) - if ((p = (b + i)) >= t) { - if ((p = t - size) > b && - (*cmp)(q, p) <= sense) - t = p; - else - b = p; - break; - } else if ((*cmp)(q, p) <= sense) { - t = p; - if (i == size) - big = 0; - goto FASTCASE; - } else - b = p; - while (t > b+size) { - i = (((t - b) / size) >> 1) * size; - if ((*cmp)(q, p = b + i) <= sense) - t = p; - else - b = p; - } - goto COPY; -FASTCASE: while (i > size) - if ((*cmp)(q, - p = b + (i >>= 1)) <= sense) - t = p; - else - b = p; -COPY: b = t; - } - i = size; - if (q == f1) { - if (iflag) { - ICOPY_LIST(f2, tp2, b); - ICOPY_ELT(f1, tp2, i); - } else { - CCOPY_LIST(f2, tp2, b); - CCOPY_ELT(f1, tp2, i); - } - } else { - if (iflag) { - ICOPY_LIST(f1, tp2, b); - ICOPY_ELT(f2, tp2, i); - } else { - CCOPY_LIST(f1, tp2, b); - CCOPY_ELT(f2, tp2, i); - } - } - } - if (f2 < l2) { - if (iflag) - ICOPY_LIST(f2, tp2, l2); - else - CCOPY_LIST(f2, tp2, l2); - } else if (f1 < l1) { - if (iflag) - ICOPY_LIST(f1, tp2, l1); - else - CCOPY_LIST(f1, tp2, l1); - } - *p1 = l2; - } - tp2 = list1; /* swap list1, list2 */ - list1 = list2; - list2 = tp2; - last = list2 + nmemb*size; - } - if (base == list2) { - memmove(list2, list1, nmemb*size); - list2 = list1; - } - xfree(list2); - return (0); -} - -#define swap(a, b) { \ - s = b; \ - i = size; \ - do { \ - tmp = *a; *a++ = *s; *s++ = tmp; \ - } while (--i); \ - a -= size; \ - } -#define reverse(bot, top) { \ - s = top; \ - do { \ - i = size; \ - do { \ - tmp = *bot; *bot++ = *s; *s++ = tmp; \ - } while (--i); \ - s -= size2; \ - } while(bot < s); \ -} - -/* - * Optional hybrid natural/pairwise first pass. Eats up list1 in runs of - * increasing order, list2 in a corresponding linked list. Checks for runs - * when THRESHOLD/2 pairs compare with same sense. (Only used when NATURAL - * is defined. Otherwise simple pairwise merging is used.) - */ -void -setup(unsigned char *list1, unsigned char *list2, size_t n, size_t size, - int (*cmp)(const void *, const void *)) -{ - size_t i; - unsigned int tmp; - int length, size2, sense; - unsigned char *f1, *f2, *s, *l2, *last, *p2; - - size2 = size*2; - if (n <= 5) { - insertionsort(list1, n, size, cmp); - *EVAL(list2) = (unsigned char*) list2 + n*size; - return; - } - /* - * Avoid running pointers out of bounds; limit n to evens - * for simplicity. - */ - i = 4 + (n & 1); - insertionsort(list1 + (n - i) * size, i, size, cmp); - last = list1 + size * (n - i); - *EVAL(list2 + (last - list1)) = list2 + n * size; - -#ifdef NATURAL - p2 = list2; - f1 = list1; - sense = (cmp(f1, f1 + size) > 0); - for (; f1 < last; sense = !sense) { - length = 2; - /* Find pairs with same sense. */ - for (f2 = f1 + size2; f2 < last; f2 += size2) { - if ((cmp(f2, f2+ size) > 0) != sense) - break; - length += 2; - } - if (length < THRESHOLD) { /* Pairwise merge */ - do { - p2 = *EVAL(p2) = f1 + size2 - list1 + list2; - if (sense > 0) - swap (f1, f1 + size); - } while ((f1 += size2) < f2); - } else { /* Natural merge */ - l2 = f2; - for (f2 = f1 + size2; f2 < l2; f2 += size2) { - if ((cmp(f2-size, f2) > 0) != sense) { - p2 = *EVAL(p2) = f2 - list1 + list2; - if (sense > 0) - reverse(f1, f2-size); - f1 = f2; - } - } - if (sense > 0) - reverse (f1, f2-size); - f1 = f2; - if (f2 < last || cmp(f2 - size, f2) > 0) - p2 = *EVAL(p2) = f2 - list1 + list2; - else - p2 = *EVAL(p2) = list2 + n*size; - } - } -#else /* pairwise merge only. */ - for (f1 = list1, p2 = list2; f1 < last; f1 += size2) { - p2 = *EVAL(p2) = p2 + size2; - if (cmp (f1, f1 + size) > 0) - swap(f1, f1 + size); - } -#endif /* NATURAL */ -} - -/* - * This is to avoid out-of-bounds addresses in sorting the - * last 4 elements. - */ -static void -insertionsort(unsigned char *a, size_t n, size_t size, - int (*cmp)(const void *, const void *)) -{ - unsigned char *ai, *s, *t, *u, tmp; - size_t i; - - for (ai = a+size; --n >= 1; ai += size) - for (t = ai; t > a; t -= size) { - u = t - size; - if (cmp(u, t) <= 0) - break; - swap(u, t); - } -} diff --git a/modules/arch/x86/x86arch.c b/modules/arch/x86/x86arch.c index 8c600edb..5441b279 100644 --- a/modules/arch/x86/x86arch.c +++ b/modules/arch/x86/x86arch.c @@ -24,20 +24,10 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#include "libyasm.h" /*@unused@*/ RCSID("$IdPath$"); -#include "file.h" - -#include "errwarn.h" -#include "intnum.h" -#include "floatnum.h" -#include "expr.h" - -#include "bytecode.h" - -#include "arch.h" - #include "x86arch.h" diff --git a/modules/arch/x86/x86bc.c b/modules/arch/x86/x86bc.c index 27fcc75c..fd4cf461 100644 --- a/modules/arch/x86/x86bc.c +++ b/modules/arch/x86/x86bc.c @@ -24,22 +24,13 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#define YASM_BC_INTERNAL +#include "libyasm.h" /*@unused@*/ RCSID("$IdPath$"); -#include "file.h" - -#include "errwarn.h" -#include "intnum.h" -#include "expr.h" - -#include "bytecode.h" -#include "arch.h" - #include "x86arch.h" -#include "bc-int.h" - typedef struct x86_effaddr { yasm_effaddr ea; /* base structure */ diff --git a/modules/arch/x86/x86expr.c b/modules/arch/x86/x86expr.c index 06ff7bf0..972ff953 100644 --- a/modules/arch/x86/x86expr.c +++ b/modules/arch/x86/x86expr.c @@ -24,23 +24,13 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#define YASM_EXPR_INTERNAL +#include "libyasm.h" /*@unused@*/ RCSID("$IdPath$"); -#include "bitvect.h" - -#include "errwarn.h" -#include "intnum.h" -#include "floatnum.h" -#include "expr.h" - -#include "bytecode.h" -#include "arch.h" - #include "x86arch.h" -#include "expr-int.h" - typedef struct x86_checkea_reg3264_data { int *regs; /* total multiplier for each reg */ diff --git a/modules/arch/x86/x86id.re b/modules/arch/x86/x86id.re index becb9ddc..37d55564 100644 --- a/modules/arch/x86/x86id.re +++ b/modules/arch/x86/x86id.re @@ -24,25 +24,14 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#define YASM_BC_INTERNAL +#define YASM_EXPR_INTERNAL +#include "libyasm.h" RCSID("$IdPath$"); -#include "bitvect.h" - -#include "errwarn.h" -#include "intnum.h" -#include "floatnum.h" -#include "expr.h" -#include "symrec.h" - -#include "bytecode.h" - -#include "arch.h" #include "modules/arch/x86/x86arch.h" -#include "expr-int.h" -#include "bc-int.h" - /* Available CPU feature flags */ #define CPU_Any (0UL) /* Any old cpu will do */ diff --git a/modules/dbgfmts/null/null-dbgfmt.c b/modules/dbgfmts/null/null-dbgfmt.c index 74aa6e20..8cc9617f 100644 --- a/modules/dbgfmts/null/null-dbgfmt.c +++ b/modules/dbgfmts/null/null-dbgfmt.c @@ -24,11 +24,10 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#include "libyasm.h" /*@unused@*/ RCSID("$IdPath$"); -#include "dbgfmt.h" - /* Define preproc structure -- see preproc.h for details */ yasm_dbgfmt yasm_null_LTX_dbgfmt = { diff --git a/modules/objfmts/bin/bin-objfmt.c b/modules/objfmts/bin/bin-objfmt.c index 1549131b..adb9e307 100644 --- a/modules/objfmts/bin/bin-objfmt.c +++ b/modules/objfmts/bin/bin-objfmt.c @@ -24,26 +24,12 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#define YASM_BC_INTERNAL +#define YASM_EXPR_INTERNAL +#include "libyasm.h" /*@unused@*/ RCSID("$IdPath$"); -#include "file.h" - -#include "errwarn.h" -#include "intnum.h" -#include "floatnum.h" -#include "expr.h" -#include "symrec.h" - -#include "bytecode.h" -#include "section.h" - -#include "expr-int.h" -#include "bc-int.h" - -#include "arch.h" -#include "objfmt.h" - #define REGULAR_OUTBUF_SIZE 1024 diff --git a/modules/objfmts/coff/coff-objfmt.c b/modules/objfmts/coff/coff-objfmt.c index 4ccf66a6..cc26ca43 100644 --- a/modules/objfmts/coff/coff-objfmt.c +++ b/modules/objfmts/coff/coff-objfmt.c @@ -24,26 +24,12 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#define YASM_BC_INTERNAL +#define YASM_EXPR_INTERNAL +#include "libyasm.h" /*@unused@*/ RCSID("$IdPath$"); -#include "file.h" - -#include "errwarn.h" -#include "intnum.h" -#include "floatnum.h" -#include "expr.h" -#include "symrec.h" - -#include "bytecode.h" -#include "section.h" - -#include "expr-int.h" -#include "bc-int.h" - -#include "arch.h" -#include "objfmt.h" - #define REGULAR_OUTBUF_SIZE 1024 diff --git a/modules/objfmts/dbg/dbg-objfmt.c b/modules/objfmts/dbg/dbg-objfmt.c index f1134123..2cc1c13a 100644 --- a/modules/objfmts/dbg/dbg-objfmt.c +++ b/modules/objfmts/dbg/dbg-objfmt.c @@ -24,19 +24,10 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#include "libyasm.h" /*@unused@*/ RCSID("$IdPath$"); -#include "errwarn.h" -#include "expr.h" -#include "symrec.h" - -#include "bytecode.h" -#include "arch.h" -#include "section.h" -#include "objfmt.h" -#include "dbgfmt.h" - yasm_objfmt yasm_dbg_LTX_objfmt; diff --git a/modules/optimizers/basic/basic-optimizer.c b/modules/optimizers/basic/basic-optimizer.c index b7013f35..fea7f8fc 100644 --- a/modules/optimizers/basic/basic-optimizer.c +++ b/modules/optimizers/basic/basic-optimizer.c @@ -24,21 +24,11 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#define YASM_BC_INTERNAL +#include "libyasm.h" /*@unused@*/ RCSID("$IdPath$"); -#include "errwarn.h" -#include "intnum.h" -#include "expr.h" -#include "symrec.h" - -#include "bytecode.h" -#include "section.h" - -#include "bc-int.h" - -#include "optimizer.h" - #define SECTFLAG_NONE 0UL #define SECTFLAG_INPROGRESS (1UL<<0) diff --git a/modules/parsers/nasm/nasm-bison.y b/modules/parsers/nasm/nasm-bison.y index 7446e546..3032d501 100644 --- a/modules/parsers/nasm/nasm-bison.y +++ b/modules/parsers/nasm/nasm-bison.y @@ -25,29 +25,15 @@ * POSSIBILITY OF SUCH DAMAGE. */ %{ -#include "util.h" +#define YASM_LIB_INTERNAL +#define YASM_EXPR_INTERNAL +#include "libyasm.h" RCSID("$IdPath$"); #ifdef STDC_HEADERS # include #endif -#include "bitvect.h" - -#include "linemgr.h" -#include "errwarn.h" -#include "intnum.h" -#include "floatnum.h" -#include "expr.h" -#include "expr-int.h" -#include "symrec.h" - -#include "bytecode.h" -#include "section.h" -#include "objfmt.h" - -#include "arch.h" - #include "modules/parsers/nasm/nasm-parser.h" #include "modules/parsers/nasm/nasm-defs.h" @@ -304,18 +290,18 @@ directive_valparam: direxpr { */ const /*@null@*/ yasm_symrec *vp_symrec; if ((vp_symrec = yasm_expr_get_symrec(&$1, 0))) { - yasm_vp_new($$, yasm__xstrdup(yasm_symrec_get_name(vp_symrec)), - NULL); + $$ = yasm_vp_new(yasm__xstrdup(yasm_symrec_get_name(vp_symrec)), + NULL); yasm_expr_delete($1); } else { yasm_expr__traverse_leaves_in($1, NULL, fix_directive_symrec); - yasm_vp_new($$, NULL, $1); + $$ = yasm_vp_new(NULL, $1); } } - | STRING { yasm_vp_new($$, $1, NULL); } + | STRING { $$ = yasm_vp_new($1, NULL); } | ID '=' direxpr { yasm_expr__traverse_leaves_in($3, NULL, fix_directive_symrec); - yasm_vp_new($$, $1, $3); + $$ = yasm_vp_new($1, $3); } ; diff --git a/modules/parsers/nasm/nasm-parser.c b/modules/parsers/nasm/nasm-parser.c index 865e56a9..5f8edece 100644 --- a/modules/parsers/nasm/nasm-parser.c +++ b/modules/parsers/nasm/nasm-parser.c @@ -24,16 +24,10 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#include "libyasm.h" /*@unused@*/ RCSID("$IdPath$"); -#include "errwarn.h" - -#include "section.h" -#include "objfmt.h" -#include "preproc.h" -#include "parser.h" - #include "nasm-parser.h" diff --git a/modules/parsers/nasm/nasm-token.re b/modules/parsers/nasm/nasm-token.re index 6cd9725d..854ecc06 100644 --- a/modules/parsers/nasm/nasm-token.re +++ b/modules/parsers/nasm/nasm-token.re @@ -26,22 +26,10 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#include "libyasm.h" RCSID("$IdPath$"); -#include "bitvect.h" - -#include "linemgr.h" -#include "errwarn.h" -#include "intnum.h" -#include "floatnum.h" -#include "expr.h" -#include "symrec.h" - -#include "bytecode.h" - -#include "arch.h" - #include "modules/parsers/nasm/nasm-parser.h" #include "modules/parsers/nasm/nasm-defs.h" #include "nasm-bison.h" diff --git a/modules/preprocs/nasm/nasm-eval.c b/modules/preprocs/nasm/nasm-eval.c index 545f4256..1991a4d1 100644 --- a/modules/preprocs/nasm/nasm-eval.c +++ b/modules/preprocs/nasm/nasm-eval.c @@ -7,7 +7,8 @@ * * initial version 27/iii/95 by Simon Tatham */ -#include "util.h" +#define YASM_LIB_INTERNAL +#include "libyasm/util.h" #include #include "nasm.h" diff --git a/modules/preprocs/nasm/nasm-pp.c b/modules/preprocs/nasm/nasm-pp.c index d5095df0..9d8c30eb 100644 --- a/modules/preprocs/nasm/nasm-pp.c +++ b/modules/preprocs/nasm/nasm-pp.c @@ -33,7 +33,8 @@ * * detoken is used to convert the line back to text */ -#include "util.h" +#define YASM_LIB_INTERNAL +#include "libyasm/util.h" #include #include #include diff --git a/modules/preprocs/nasm/nasm-preproc.c b/modules/preprocs/nasm/nasm-preproc.c index e7a2b7e9..81f7fe88 100644 --- a/modules/preprocs/nasm/nasm-preproc.c +++ b/modules/preprocs/nasm/nasm-preproc.c @@ -24,13 +24,10 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#include "libyasm.h" /*@unused@*/ RCSID("$IdPath$"); -#include "errwarn.h" -#include "linemgr.h" - -#include "preproc.h" #include "nasm.h" #include "nasmlib.h" #include "nasm-pp.h" diff --git a/modules/preprocs/nasm/nasmlib.c b/modules/preprocs/nasm/nasmlib.c index 5eb2be1a..6b025dfd 100644 --- a/modules/preprocs/nasm/nasmlib.c +++ b/modules/preprocs/nasm/nasmlib.c @@ -5,7 +5,8 @@ * redistributable under the licence given in the file "Licence" * distributed in the NASM archive. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#include "libyasm/util.h" #include #include "nasm.h" diff --git a/modules/preprocs/raw/raw-preproc.c b/modules/preprocs/raw/raw-preproc.c index 49f6e8cf..ecf36319 100644 --- a/modules/preprocs/raw/raw-preproc.c +++ b/modules/preprocs/raw/raw-preproc.c @@ -24,14 +24,10 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "util.h" +#define YASM_LIB_INTERNAL +#include "libyasm.h" /*@unused@*/ RCSID("$IdPath$"); -#include "errwarn.h" -#include "linemgr.h" - -#include "preproc.h" - static int is_interactive; static FILE *in; diff --git a/modules/preprocs/yapp/yapp-preproc.c b/modules/preprocs/yapp/yapp-preproc.c index edd9bf30..59343729 100644 --- a/modules/preprocs/yapp/yapp-preproc.c +++ b/modules/preprocs/yapp/yapp-preproc.c @@ -19,14 +19,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "util.h" +#define YASM_LIB_INTERNAL +#include "libyasm.h" /*@unused@*/ RCSID("$IdPath$"); -#include "linemgr.h" -#include "errwarn.h" -#include "preproc.h" -#include "hamt.h" - #include "yapp-preproc.h" #include "yapp-token.h" diff --git a/modules/preprocs/yapp/yapp-token.l b/modules/preprocs/yapp/yapp-token.l index 6055a9a2..8423430e 100644 --- a/modules/preprocs/yapp/yapp-token.l +++ b/modules/preprocs/yapp/yapp-token.l @@ -20,14 +20,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ %{ -#include "util.h" +#define YASM_LIB_INTERNAL +#include "libyasm.h" /*@unused@*/ RCSID("$IdPath$"); #include -#include "linemgr.h" -#include "errwarn.h" - #include "modules/preprocs/yapp/yapp-preproc.h" #include "modules/preprocs/yapp/yapp-token.h" diff --git a/strsep.c b/strsep.c deleted file mode 100644 index 0e84acfc..00000000 --- a/strsep.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * strsep() implementation for systems that don't have it. - * - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 "util.h" -/*@unused@*/ RCSID("$IdPath$"); - - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - - -/* - * Get next token from string *stringp, where tokens are possibly-empty - * strings separated by characters from delim. - * - * Writes NULs into the string at *stringp to end tokens. - * delim need not remain constant from call to call. - * On return, *stringp points past the last NUL written (if there might - * be further tokens), or is NULL (if there are definitely no more tokens). - * - * If *stringp is NULL, strsep returns NULL. - */ -/*@-nullstate@*/ -char * -strsep(char **stringp, const char *delim) -{ - register char *s; - register const char *spanp; - register int c, sc; - char *tok; - - if ((s = *stringp) == NULL) - return (NULL); - for (tok = s;;) { - c = *s++; - spanp = delim; - do { - if ((sc = *spanp++) == c) { - if (c == 0) - s = NULL; - else - s[-1] = 0; - *stringp = s; - return (tok); - } - } while (sc != 0); - } - /* NOTREACHED */ -} -/*@=nullstate@*/ diff --git a/util.h b/util.h index fc0113c7..ccdbfe32 100644 --- a/util.h +++ b/util.h @@ -29,86 +29,106 @@ #ifndef YASM_UTIL_H #define YASM_UTIL_H -#ifdef HAVE_CONFIG_H -# include +#include + +#ifdef YASM_LIB_INTERNAL +# define YASM_INTERNAL +# define YASM_AUTOCONF_INTERNAL +# define YASM_LIB_AC_INTERNAL +# define YASM_GETTEXT_INTERNAL #endif -#include +#ifdef YASM_INTERNAL +# include + +#if defined(YASM_LIB_AC_INTERNAL) && defined(HAVE_CONFIG_H) +# include "libyasm/config.h" +#endif #if !defined(lint) # define NDEBUG #endif -#ifdef STDC_HEADERS -# include -# include -# include -# include -# include -#endif +#ifdef YASM_AUTOCONF_INTERNAL -#if defined(lint) -#define _(String) String -#else -# ifdef HAVE_LOCALE_H -# include +# ifdef STDC_HEADERS +# include +# include +# include +# include # endif -# ifdef ENABLE_NLS -# include -# define _(String) gettext(String) -# else -# define gettext(Msgid) (Msgid) -# define dgettext(Domainname, Msgid) (Msgid) -# define dcgettext(Domainname, Msgid, Category) (Msgid) -# define textdomain(Domainname) while (0) /* nothing */ -# define bindtextdomain(Domainname, Dirname) while (0) /* nothing */ -# define _(String) (String) -# endif -#endif +# ifdef YASM_GETTEXT_INTERNAL +# if defined(lint) +# define _(String) String +# else +# ifdef HAVE_LOCALE_H +# include +# endif + +# ifdef ENABLE_NLS +# include +# define _(String) gettext(String) +# else +# define gettext(Msgid) (Msgid) +# define dgettext(Domainname, Msgid) (Msgid) +# define dcgettext(Domainname, Msgid, Category) (Msgid) +# define textdomain(Domainname) while (0) /* nothing */ +# define bindtextdomain(Domainname, Dirname) while (0) /* nothing */ +# define _(String) (String) +# endif +# endif -#ifdef gettext_noop -# define N_(String) gettext_noop(String) -#else -# define N_(String) (String) -#endif +# ifdef gettext_noop +# define N_(String) gettext_noop(String) +# else +# define N_(String) (String) +# endif -#if !defined(HAVE_MERGESORT) || defined(lint) -int mergesort(void *base, size_t nmemb, size_t size, - int (*compar)(const void *, const void *)); -#endif +# endif /*YASM_GETTEXT_INTERNAL*/ + +#endif /*YASM_AUTOCONF_INTERNAL*/ + +int yasm__mergesort(void *base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *)); -#if !defined(HAVE_STRSEP) || defined(lint) -/*@null@*/ char *strsep(char **stringp, const char *delim); +#if defined(YASM_AUTOCONF_INTERNAL) && defined(HAVE_MERGESORT) +#define yasm__mergesort(a, b, c, d) mergesort(a, b, c, d) #endif -#ifdef HAVE_STRCASECMP -# define yasm__strcasecmp(x, y) strcasecmp(x, y) -# define yasm__strncasecmp(x, y) strncasecmp(x, y) -#else -# ifdef HAVE_STRICMP -# define yasm__strcasecmp(x, y) stricmp(x, y) -# define yasm__strncasecmp(x, y) strnicmp(x, y) -# elif HAVE_STRCMPI -# define yasm__strcasecmp(x, y) strcmpi(x, y) -# define yasm__strncasecmp(x, y) strncmpi(x, y) -# else -# define USE_OUR_OWN_STRCASECMP -# endif +/*@null@*/ char *yasm__strsep(char **stringp, const char *delim); + +#if defined(YASM_AUTOCONF_INTERNAL) && defined(HAVE_STRSEP) +#define yasm__strsep(a, b) strsep(a, b) #endif -#if defined(USE_OUR_OWN_STRCASECMP) || defined(lint) int yasm__strcasecmp(const char *s1, const char *s2); int yasm__strncasecmp(const char *s1, const char *s2, size_t n); + +#ifdef YASM_AUTOCONF_INTERNAL + +#ifdef HAVE_STRCASECMP +# define yasm__strcasecmp(x, y) strcasecmp(x, y) +# define yasm__strncasecmp(x, y, n) strncasecmp(x, y, n) +#elif HAVE_STRICMP +# define yasm__strcasecmp(x, y) stricmp(x, y) +# define yasm__strncasecmp(x, y, n) strnicmp(x, y, n) +#elif HAVE_STRCMPI +# define yasm__strcasecmp(x, y) strcmpi(x, y) +# define yasm__strncasecmp(x, y, n) strncmpi(x, y, n) +#else +# define USE_OUR_OWN_STRCASECMP #endif #if !defined(HAVE_TOASCII) || defined(lint) # define toascii(c) ((c) & 0x7F) #endif -#include "compat-queue.h" +#endif /*YASM_AUTOCONF_INTERNAL*/ -#ifdef HAVE_SYS_CDEFS_H +#include "libyasm/compat-queue.h" + +#if defined(YASM_AUTOCONF_INTERNAL) && defined(HAVE_SYS_CDEFS_H) # include #endif @@ -126,18 +146,11 @@ int yasm__strncasecmp(const char *s1, const char *s2, size_t n); # endif #endif -#ifdef WITH_DMALLOC -# include - -#define yasm__xstrdup(str) xstrdup(str) -#define yasm_xmalloc(size) xmalloc(size) -#define yasm_xcalloc(count, size) xcalloc(count, size) -#define yasm_xrealloc(ptr, size) xrealloc(ptr, size) -#define yasm_xfree(ptr) xfree(ptr) - -#else /* strdup() implementation with error checking (using xmalloc). */ /*@only@*/ char *yasm__xstrdup(const char *str); +/*@only@*/ char *yasm__xstrndup(const char *str, size_t len); + +#endif /*YASM_INTERNAL*/ /* Error-checking memory allocation routines. Default implementations in * xmalloc.c. @@ -150,9 +163,17 @@ extern /*@only@*/ void * (*yasm_xrealloc) extern void (*yasm_xfree) (/*@only@*/ /*@out@*/ /*@null@*/ void *p) /*@modifies p@*/; -#endif +#ifdef YASM_INTERNAL -/*@only@*/ char *yasm__xstrndup(const char *str, size_t len); +#if defined(YASM_AUTOCONF_INTERNAL) && defined(WITH_DMALLOC) +# include + +#define yasm__xstrdup(str) xstrdup(str) +#define yasm_xmalloc(size) xmalloc(size) +#define yasm_xcalloc(count, size) xcalloc(count, size) +#define yasm_xrealloc(ptr, size) xrealloc(ptr, size) +#define yasm_xfree(ptr) xfree(ptr) +#endif /* Bit-counting: used primarily by HAMT but also in a few other places. */ #define SK5 0x55555555 @@ -172,8 +193,10 @@ extern void (*yasm_xfree) (/*@only@*/ /*@out@*/ /*@null@*/ void *p) #define NELEMS(array) (sizeof(array) / sizeof(array[0])) #endif -#include "coretype.h" +#endif /*YASM_INTERNAL*/ + +#include "libyasm/coretype.h" -#include "valparam.h" +#include "libyasm/valparam.h" #endif -- 2.40.0