+++ /dev/null
-# $IdPath$
-
-noinst_LIBRARIES=libcheck.a
-
-libcheck_a_SOURCES = \
- check.c \
- check_run.c \
- check.h \
- check_impl.h \
- check_msg.c \
- check_msg.h \
- check_log.c \
- check_log.h \
- check_print.c \
- check_print.h \
- error.c \
- error.h \
- list.c \
- list.h
-
-CFLAGS = @ANSI_CFLAGS@
-
-EXTRA_DIST = \
- NEWS \
- README
-AC_INIT(src/main.c)
-AM_CONFIG_HEADER(include/config.h)
+# Process this file with autoconf to produce a configure script.
+# $IdPath$
+
+# Minimum required perl version for development
+PERL_VERSION=5.004
+
+#
+# autoconf setup
+#
+AC_PREREQ(2.13)
+AC_INIT([src/main.c])
+AC_CONFIG_AUX_DIR(config)
+AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(yasm, 0.0.1)
-AC_PATH_PROGS(PERL, perl perl5.004 perl5.003 perl5.002 perl5.001 perl5)
+#
+# autoconf command-line options
+#
+AC_ARG_ENABLE(dev,
+[ --enable-dev Enable full development build capability],
+[case "${enableval}" in
+ yes) dev=true ;;
+ no) dev=false ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-dev]) ;;
+esac],[dev=false])
+AM_CONDITIONAL(DEV, test x$dev = xtrue)
-AC_PROG_CC
-AM_PROG_LEX
+AC_ARG_ENABLE(morewarn,
+[ --enable-morewarn Enable lots of extra GCC warnings],
+[case "${enableval}" in
+ yes) morewarn=true ;;
+ no) morewarn=false ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-morewarn]) ;;
+esac],[morewarn=false])
+
+AC_ARG_ENABLE(warnerror,
+[ --enable-warnerror Treat GCC warnings as errors],
+[case "${enableval}" in
+ yes) warnerror=true ;;
+ no) warnerror=false ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-warnerror]) ;;
+esac],[warnerror=false])
+
+AC_ARG_ENABLE(profiling,
+[ --enable-profiling Enable profiling (requires GCC)],
+[case "${enableval}" in
+ yes) profiling=true ;;
+ no) profiling=false ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-profiling]) ;;
+esac],[profiling=false])
+
+AC_ARG_ENABLE(dmalloc,
+[ --enable-dmalloc Enable debug malloc (requires dmalloc library)],
+[case "${enableval}" in
+ yes) dmalloc=true ;;
+ no) dmalloc=false ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-dmalloc]) ;;
+esac],[dmalloc=false])
+
+AC_ARG_ENABLE(check,
+[ --disable-check Disable building of test suite and make check],
+[case "${enableval}" in
+ yes) check=true ;;
+ no) check=false ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-check]) ;;
+esac],[check=true])
+AM_CONDITIONAL(CHECK, test x$check = xtrue)
+
+#
+# Check for gettext() and other i18n/l10n things.
+#
+ALL_LINGUAS=""
+AM_GNU_GETTEXT
+# autoheader templates for AM_GNU_GETTEXT checks.
+AH_TEMPLATE([ENABLE_NLS], [])
+AH_TEMPLATE([HAVE_CATGETS], [])
+AH_TEMPLATE([HAVE_GETTEXT], [])
+AH_TEMPLATE([HAVE_LC_MESSAGES], [])
+AH_TEMPLATE([HAVE_STPCPY], [])
+
+#
+# Checks for programs.
+#
+# lex and yacc are only required for development.
AC_PROG_YACC
+AM_PROG_CC_STDC
AC_PROG_INSTALL
+AC_PROG_LN_S
+AM_PROG_LEX
+AC_PROG_RANLIB
+
+# REQUIRE a standard (ANSI/ISO) C compiler
+if test "$ac_cv_prog_cc_stdc" = no; then
+ AC_MSG_ERROR([A standard (ANSI/ISO C89) C compiler is required.])
+fi
+
+# Check for Perl (for gen_instr.pl and the like, needed only for development)
+AC_PATH_PROGS(PERL, $PERL perl5 perl)
+# Check for groff (for rendering manpages, needed only for development)
+AC_PATH_PROGS(GROFF, $GROFF groff)
+# Check for compiler output filename suffixes.
+AC_OBJEXT
+AC_EXEEXT
+
+#
+# Checks for libraries.
+#
+
+# dmalloc library (optional)
+AC_CHECK_LIB(dmalloc, main)
+
+#
+# Checks for header files.
+#
AC_HEADER_STDC
+AC_HEADER_SYS_WAIT
+AC_CHECK_HEADERS([alloca.h dmalloc.h limits.h sys/cdefs.h sys/ipc.h sys/msg.h sys/param.h sys/types.h sys/queue.h unistd.h])
+
+# REQUIRE standard C headers
+if test "$ac_cv_header_stdc" != yes; then
+ AC_MSG_ERROR([Standard (ANSI/ISO C89) header files are required.])
+fi
+#
+# Checks for typedefs, structures, and compiler characteristics.
+#
AC_C_CONST
+AC_C_INLINE
+# PID_T is used by the test suite (not required).
+AC_TYPE_PID_T
AC_TYPE_SIZE_T
+#
+# Checks for library functions.
+#
AC_FUNC_VPRINTF
-AC_CHECK_FUNCS(memcpy toascii)
-AC_REPLACE_FUNCS(strdup strtoul)
+AC_CHECK_FUNCS([abort memcpy memmove strrchr toascii])
+# 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([fork msgctl msgget msgrcv msgsnd strerror snprintf wait])
+AC_REPLACE_FUNCS([strsep mergesort])
+
+# Check for GNU C Library
+AH_TEMPLATE([HAVE_GNU_C_LIBRARY], [Define if you have the GNU C Library])
+AC_CACHE_CHECK([for GNU C Library], yasm_cv_header_gnulib,
+ AC_EGREP_CPP(gnulib,
+ [#include <features.h>
+ #ifdef __GNU_LIBRARY__
+ gnulib
+ #endif
+ ], yasm_cv_header_gnulib=yes, yasm_cv_header_gnulib=no))
+if test "$yasm_cv_header_gnulib" = yes; then
+ AC_DEFINE([HAVE_GNU_C_LIBRARY])
+fi
+
+# Force x86 architecture only for now.
+ARCH=x86
+AC_SUBST([ARCH])
+
+# Require things for --enable-dmalloc option.
+DMALLOCFLAGS=
+if ${dmalloc}; then
+ if test "$ac_cv_header_dmalloc_h" != yes ||
+ test "$ac_cv_lib_dmalloc_main" != yes; then
+ AC_MSG_ERROR([dmalloc required for --enable-dmalloc.])
+ else
+ AC_DEFINE([DDMALLOC], 1, [Enable dmalloc library debugging.])
+ fi
+else
+ if ${morewarn}; then
+ DMALLOCFLAGS="-Wredundant-decls"
+ fi
+fi
+
+# Require things for --enable-dev option.
+if ${dev}; then
+ # Require Perl
+ if test -z "$PERL" || test "$PERL" = ":"; then
+ AC_MSG_ERROR([Perl not found in \$PATH])
+ fi
+
+ # Require Perl >= PERL_VERSION
+ AC_MSG_CHECKING([for minimum required perl version >= $PERL_VERSION])
+ _perl_version=`PERL_VERSION=$PERL_VERSION $PERL -e 'print "$]"; if ($] >= $ENV{PERL_VERSION}) { exit(0); } else { exit(1); }' 2>&5`
+ _perl_res=$?
+ AC_MSG_RESULT([$_perl_version])
+
+ if test "$_perl_res" != 0; then
+ AC_MSG_ERROR([Perl $PERL_VERSION or higher is required.])
+ fi
+
+ # Require groff
+ if test -z "$GROFF" || test "$GROFF" = ":"; then
+ AC_MSG_ERROR([groff not found in \$PATH])
+ fi
+fi
+
+#
+# Add some more CFLAGS for various options.
+#
+
+# "Check" tests can use fork/wait/msg* if ALL are available.
+AH_TEMPLATE([USE_FORKWAITMSG], [Combined test for fork/wait/msg*])
+if ${check}; then
+ if test "$ac_cv_func_fork" = yes &&
+ test "$ac_cv_func_wait" = yes &&
+ test "$ac_cv_func_msgctl" = yes &&
+ test "$ac_cv_func_msgget" = yes &&
+ test "$ac_cv_func_msgrcv" = yes &&
+ test "$ac_cv_func_msgsnd" = yes; then
+ AC_DEFINE([USE_FORKWAITMSG])
+ AC_DEFINE([_GNU_SOURCE], 1,
+ [Make sure we see all GNU extensions.])
+ AC_DEFINE([_SVID_SOURCE], 1,
+ [Make sure we see all SVID extensions.])
+ fi
+fi
+
+# Enable debugging if --enable-dev, otherwise optimize
+if ${dev}; then
+ DEVFLAGS=" -g"
+else
+ DEVFLAGS=" -O"
+fi
+
+# More warnings to help write clean code
+if ${morewarn}; then
+ MOREWARNFLAGS="-Wbad-function-cast -Wcast-align -Wcast-qual -Wchar-subscripts -Winline -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings"
+fi
+
+# Turn warnings into errors
+if ${warnerror}; then
+ WARNERRORFLAGS="-Werror"
+fi
+
+# Enable output of profiling information
+if ${profiling}; then
+ PROFILINGFLAGS="-pg"
+fi
+
+# If we're using GCC, then we can enable the above CFLAGS as well as turn on
+# -ansi -pedantic -Wall.
+if test "$GCC" = yes; then
+ ANSI_CFLAGS="-ansi -pedantic -Wall $MOREWARNFLAGS $WARNERRORFLAGS $DEVFLAGS $PROFILINGFLAGS $DMALLOCFLAGS"
+else
+ ANSI_CFLAGS=""
+fi
+AC_SUBST(ANSI_CFLAGS)
+
+# Check for target-specific bogus sys/queue.h
+AH_TEMPLATE([HAVE_BOGUS_SYS_QUEUE_H],
+ [Workaround for bad <sys/queue.h> implementations.])
+case "$host" in
+*-*-sunos4*)
+ AC_DEFINE([HAVE_BOGUS_SYS_QUEUE_H])
+ ;;
+*-sni-sysv*)
+ AC_DEFINE([HAVE_BOGUS_SYS_QUEUE_H])
+ ;;
+*-*-sco3.2v4*)
+ AC_DEFINE([HAVE_BOGUS_SYS_QUEUE_H])
+ ;;
+*-*-sco3.2v5*)
+ AC_DEFINE([HAVE_BOGUS_SYS_QUEUE_H])
+ ;;
+*-*-linux*)
+ AC_DEFINE([HAVE_BOGUS_SYS_QUEUE_H])
+ ;;
+esac
-AC_OUTPUT(Makefile src/Makefile include/Makefile)
+AC_OUTPUT(Makefile
+ intl/Makefile
+ po/Makefile.in
+ doc/Makefile
+ doc/user/Makefile
+ doc/programmer/Makefile
+ doc/programmer/queue/Makefile
+ doc/programmer/bitvect/Makefile
+)
esac
AC_OUTPUT(Makefile
- check/Makefile
intl/Makefile
po/Makefile.in
- src/Makefile
- src/arch/Makefile
- src/arch/x86/Makefile
- src/parsers/Makefile
- src/parsers/nasm/Makefile
- src/preprocs/Makefile
- src/preprocs/raw/Makefile
- src/optimizers/Makefile
- src/optimizers/basic/Makefile
- src/objfmts/Makefile
- src/objfmts/dbg/Makefile
- src/tests/Makefile
doc/Makefile
doc/user/Makefile
doc/programmer/Makefile
doc/programmer/queue/Makefile
doc/programmer/bitvect/Makefile
- tests/Makefile
)
+++ /dev/null
-# $IdPath$
-
-CFLAGS = @ANSI_CFLAGS@
-
-if CHECK
-TESTS = \
- bitvect_test \
- bytecode_test \
- floatnum_test \
- memexpr_test
-
-noinst_PROGRAMS = \
- bitvect_test \
- bytecode_test \
- floatnum_test \
- memexpr_test
-
-else
-TESTS =
-noinst_PROGRAMS =
-endif
-
-LDADD = \
- $(top_builddir)/src/libyasm.a \
- $(top_builddir)/check/libcheck.a \
- $(top_builddir)/src/parsers/nasm/libparser.a \
- $(top_builddir)/src/preprocs/raw/libpreproc.a \
- $(top_builddir)/src/optimizers/basic/liboptimizer.a \
- $(top_builddir)/src/objfmts/dbg/libobjfmt.a \
- $(top_builddir)/src/arch/@ARCH@/libarch.a \
- $(top_builddir)/src/libyasm.a \
- $(INTLLIBS)
-
-bitvect_test_SOURCES = \
- bitvect_test.c
-
-bitvect_test_LDADD = \
- $(top_builddir)/src/errwarn.o \
- $(LDADD)
-
-bytecode_test_SOURCES = \
- bytecode_test.c
-
-bytecode_test_LDADD = \
- $(top_builddir)/src/errwarn.o \
- $(LDADD)
-
-floatnum_test_SOURCES = \
- floatnum_test.c
-
-floatnum_test_LDADD = \
- $(top_builddir)/src/errwarn.o \
- $(LDADD)
-
-memexpr_test_SOURCES = \
- memexpr_test.c
-
-INCLUDES= -I$(top_srcdir) -I$(top_srcdir)/src -I$(top_srcdir)/check \
- -I$(top_srcdir)/src/arch/@ARCH@ -I$(top_builddir)/intl
-
--- /dev/null
+# $IdPath$
+
+TESTS += \
+ bitvect_test \
+ floatnum_test
+
+noinst_PROGRAMS += \
+ bitvect_test \
+ floatnum_test
+
+bitvect_test_SOURCES = \
+ src/tests/bitvect_test.c \
+ src/errwarn.c \
+ $(YASMBASEFILES) \
+ $(YASMPARSERFILES) \
+ $(YASMPREPROCFILES) \
+ $(YASMOPTIMIZERFILES) \
+ $(YASMOBJFMTFILES) \
+ $(YASMARCHFILES) \
+ $(CHECKFILES)
+bitvect_test_LDADD = $(INTLLIBS)
+
+#bytecode_test_SOURCES = \
+# src/tests/bytecode_test.c \
+# src/errwarn.c \
+# $(YASMBASEFILES) \
+# $(YASMPARSERFILES) \
+# $(YASMPREPROCFILES) \
+# $(YASMOPTIMIZERFILES) \
+# $(YASMOBJFMTFILES) \
+# $(YASMARCHFILES) \
+# $(CHECKFILES)
+#bytecode_test_LDADD = $(INTLLIBS)
+
+floatnum_test_SOURCES = \
+ src/tests/floatnum_test.c \
+ src/errwarn.c \
+ src/globals.c \
+ src/hamt.c \
+ src/bitvect.c \
+ src/xmalloc.c \
+ src/xstrdup.c \
+ $(CHECKFILES)
+floatnum_test_LDADD = $(INTLLIBS)
+
+#memexpr_test_SOURCES = \
+# src/tests/memexpr_test.c \
+# src/errwarn.c \
+# $(YASMBASEFILES) \
+# $(YASMPARSERFILES) \
+# $(YASMPREPROCFILES) \
+# $(YASMOPTIMIZERFILES) \
+# $(YASMOBJFMTFILES) \
+# $(YASMARCHFILES) \
+# $(CHECKFILES)
+#memexpr_test_LDADD = $(INTLLIBS)
+++ /dev/null
-# $IdPath$
-
-SUBDIRS = x86
+++ /dev/null
-# $IdPath$
-
-noinst_LIBRARIES = libarch.a
-
-libarch_a_SOURCES = \
- x86arch.h \
- x86-int.h \
- arch.c \
- bytecode.c \
- expr.c
-
-INCLUDES = \
- -I$(top_srcdir)/src \
- -I$(top_builddir)/intl
-
-CFLAGS = @ANSI_CFLAGS@
-
-EXTRA_DIST = \
- README \
- instrs.dat
+++ /dev/null
-/*
- * x86 architecture description
- *
- * Copyright (C) 2001 Peter Johnson
- *
- * This file is part of YASM.
- *
- * YASM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * YASM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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"
-/*@unused@*/ RCSID("$IdPath$");
-
-#include "bytecode.h"
-#include "arch.h"
-
-#include "x86-int.h"
-
-
-unsigned char x86_mode_bits = 0;
-
-/* Define arch structure -- see arch.h for details */
-arch x86_arch = {
- "x86 (IA-32, x86-64)",
- "x86",
- {
- X86_BYTECODE_TYPE_MAX,
- x86_bc_delete,
- x86_bc_print,
- x86_bc_calc_len
- }
-};
+++ /dev/null
-/*
- * x86 bytecode utility functions
- *
- * Copyright (C) 2001 Peter Johnson
- *
- * This file is part of YASM.
- *
- * YASM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * YASM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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"
-/*@unused@*/ RCSID("$IdPath$");
-
-#include "globals.h"
-#include "errwarn.h"
-#include "intnum.h"
-#include "expr.h"
-
-#include "bytecode.h"
-#include "arch.h"
-
-#include "x86-int.h"
-
-#include "bc-int.h"
-
-
-/*@-compmempass -mustfree@*/
-bytecode *
-x86_bc_new_insn(x86_new_insn_data *d)
-{
- bytecode *bc;
- x86_insn *insn;
-
- bc = bc_new_common((bytecode_type)X86_BC_INSN, sizeof(x86_insn));
- insn = bc_get_data(bc);
-
- insn->ea = d->ea;
- if (d->ea) {
- x86_effaddr_data *ead = ea_get_data(d->ea);
- ead->modrm &= 0xC7; /* zero spare/reg bits */
- ead->modrm |= (d->spare << 3) & 0x38; /* plug in provided bits */
- }
-
- insn->imm = d->imm;
- if (d->imm) {
- insn->imm->f_len = d->im_len;
- insn->imm->f_sign = d->im_sign;
- }
-
- insn->opcode[0] = d->op[0];
- insn->opcode[1] = d->op[1];
- insn->opcode[2] = d->op[2];
- insn->opcode_len = d->op_len;
-
- insn->addrsize = 0;
- insn->opersize = d->opersize;
- insn->lockrep_pre = 0;
- insn->shift_op = 0;
-
- insn->mode_bits = x86_mode_bits;
-
- return bc;
-}
-/*@=compmempass =mustfree@*/
-
-/*@-compmempass -mustfree@*/
-bytecode *
-x86_bc_new_jmprel(x86_new_jmprel_data *d)
-{
- bytecode *bc;
- x86_jmprel *jmprel;
-
- bc = bc_new_common((bytecode_type)X86_BC_JMPREL, sizeof(x86_jmprel));
- jmprel = bc_get_data(bc);
-
- jmprel->target = d->target->val;
- jmprel->op_sel = d->target->op_sel;
-
- if ((d->target->op_sel == JR_SHORT_FORCED) && (d->near_op_len == 0))
- Error(_("no SHORT form of that jump instruction exists"));
- if ((d->target->op_sel == JR_NEAR_FORCED) && (d->short_op_len == 0))
- Error(_("no NEAR form of that jump instruction exists"));
-
- jmprel->shortop.opcode[0] = d->short_op[0];
- jmprel->shortop.opcode[1] = d->short_op[1];
- jmprel->shortop.opcode[2] = d->short_op[2];
- jmprel->shortop.opcode_len = d->short_op_len;
-
- jmprel->nearop.opcode[0] = d->near_op[0];
- jmprel->nearop.opcode[1] = d->near_op[1];
- jmprel->nearop.opcode[2] = d->near_op[2];
- jmprel->nearop.opcode_len = d->near_op_len;
-
- jmprel->addrsize = d->addrsize;
- jmprel->opersize = 0;
- jmprel->lockrep_pre = 0;
-
- jmprel->mode_bits = x86_mode_bits;
-
- return bc;
-}
-/*@=compmempass =mustfree@*/
-
-void
-x86_ea_set_segment(effaddr *ea, unsigned char segment)
-{
- x86_effaddr_data *ead;
-
- if (!ea)
- return;
-
- ead = ea_get_data(ea);
-
- if (segment != 0 && ead->segment != 0)
- Warning(_("multiple segment overrides, using leftmost"));
-
- ead->segment = segment;
-}
-
-effaddr *
-x86_ea_new_reg(unsigned char reg)
-{
- effaddr *ea = xmalloc(sizeof(effaddr)+sizeof(x86_effaddr_data));
- x86_effaddr_data *ead = ea_get_data(ea);
-
- ea->disp = (expr *)NULL;
- ea->len = 0;
- ea->nosplit = 0;
- ead->segment = 0;
- ead->modrm = 0xC0 | (reg & 0x07); /* Mod=11, R/M=Reg, Reg=0 */
- ead->valid_modrm = 1;
- ead->need_modrm = 1;
- ead->valid_sib = 0;
- ead->need_sib = 0;
-
- return ea;
-}
-
-effaddr *
-x86_ea_new_expr(expr *e)
-{
- effaddr *ea = xmalloc(sizeof(effaddr)+sizeof(x86_effaddr_data));
- x86_effaddr_data *ead = ea_get_data(ea);
-
- ea->disp = e;
- ea->len = 0;
- ea->nosplit = 0;
- ead->segment = 0;
- ead->modrm = 0;
- ead->valid_modrm = 0;
- ead->need_modrm = 1;
- ead->valid_sib = 0;
- ead->need_sib = 0xff; /* we won't know until we know more about expr and
- the BITS/address override setting */
-
- return ea;
-}
-
-/*@-compmempass@*/
-effaddr *
-x86_ea_new_imm(immval *imm, unsigned char im_len)
-{
- effaddr *ea = xmalloc(sizeof(effaddr)+sizeof(x86_effaddr_data));
- x86_effaddr_data *ead = ea_get_data(ea);
-
- ea->disp = imm->val;
- ea->len = im_len;
- ea->nosplit = 0;
- ead->segment = 0;
- ead->modrm = 0;
- ead->valid_modrm = 0;
- ead->need_modrm = 0;
- ead->valid_sib = 0;
- ead->need_sib = 0;
-
- return ea;
-}
-/*@=compmempass@*/
-
-effaddr *
-x86_bc_insn_get_ea(bytecode *bc)
-{
- x86_insn *insn = bc_get_data(bc);
-
- if (!bc)
- return NULL;
-
- if ((x86_bytecode_type)bc->type != X86_BC_INSN)
- InternalError(_("Trying to get EA of non-instruction"));
-
- return insn->ea;
-}
-
-void
-x86_bc_insn_opersize_override(bytecode *bc, unsigned char opersize)
-{
- x86_insn *insn;
- x86_jmprel *jmprel;
-
- if (!bc)
- return;
-
- switch ((x86_bytecode_type)bc->type) {
- case X86_BC_INSN:
- insn = bc_get_data(bc);
- insn->opersize = opersize;
- break;
- case X86_BC_JMPREL:
- jmprel = bc_get_data(bc);
- jmprel->opersize = opersize;
- break;
- default:
- InternalError(_("OperSize override applied to non-instruction"));
- }
-}
-
-void
-x86_bc_insn_addrsize_override(bytecode *bc, unsigned char addrsize)
-{
- x86_insn *insn;
- x86_jmprel *jmprel;
-
- if (!bc)
- return;
-
- switch ((x86_bytecode_type)bc->type) {
- case X86_BC_INSN:
- insn = bc_get_data(bc);
- insn->addrsize = addrsize;
- break;
- case X86_BC_JMPREL:
- jmprel = bc_get_data(bc);
- jmprel->addrsize = addrsize;
- break;
- default:
- InternalError(_("AddrSize override applied to non-instruction"));
- }
-}
-
-void
-x86_bc_insn_set_lockrep_prefix(bytecode *bc, unsigned char prefix)
-{
- x86_insn *insn;
- x86_jmprel *jmprel;
- unsigned char *lockrep_pre = (unsigned char *)NULL;
-
- if (!bc)
- return;
-
- switch ((x86_bytecode_type)bc->type) {
- case X86_BC_INSN:
- insn = bc_get_data(bc);
- lockrep_pre = &insn->lockrep_pre;
- break;
- case X86_BC_JMPREL:
- jmprel = bc_get_data(bc);
- lockrep_pre = &jmprel->lockrep_pre;
- break;
- default:
- InternalError(_("LockRep prefix applied to non-instruction"));
- }
-
- if (*lockrep_pre != 0)
- Warning(_("multiple LOCK or REP prefixes, using leftmost"));
-
- *lockrep_pre = prefix;
-}
-
-void
-x86_bc_insn_set_shift_flag(bytecode *bc)
-{
- x86_insn *insn;
-
- if (!bc)
- return;
-
- if ((x86_bytecode_type)bc->type != X86_BC_INSN)
- InternalError(_("Attempted to set shift flag on non-instruction"));
-
- insn = bc_get_data(bc);
-
- insn->shift_op = 1;
-}
-
-void
-x86_set_jmprel_opcode_sel(x86_jmprel_opcode_sel *old_sel,
- x86_jmprel_opcode_sel new_sel)
-{
- if (!old_sel)
- return;
-
- if (new_sel != JR_NONE && ((*old_sel == JR_SHORT_FORCED) ||
- (*old_sel == JR_NEAR_FORCED)))
- Warning(_("multiple SHORT or NEAR specifiers, using leftmost"));
- *old_sel = new_sel;
-}
-
-void
-x86_bc_delete(bytecode *bc)
-{
- x86_insn *insn;
- x86_jmprel *jmprel;
-
- switch ((x86_bytecode_type)bc->type) {
- case X86_BC_INSN:
- insn = bc_get_data(bc);
- if (insn->ea) {
- expr_delete(insn->ea->disp);
- xfree(insn->ea);
- }
- if (insn->imm) {
- expr_delete(insn->imm->val);
- xfree(insn->imm);
- }
- break;
- case X86_BC_JMPREL:
- jmprel = bc_get_data(bc);
- expr_delete(jmprel->target);
- break;
- }
-}
-
-void
-x86_bc_print(FILE *f, const bytecode *bc)
-{
- const x86_insn *insn;
- const x86_jmprel *jmprel;
- x86_effaddr_data *ead;
-
- switch ((x86_bytecode_type)bc->type) {
- case X86_BC_INSN:
- insn = bc_get_const_data(bc);
- fprintf(f, "%*s_Instruction_\n", indent_level, "");
- fprintf(f, "%*sEffective Address:", indent_level, "");
- if (!insn->ea)
- fprintf(f, " (nil)\n");
- else {
- indent_level++;
- fprintf(f, "\n%*sDisp=", indent_level, "");
- expr_print(f, insn->ea->disp);
- fprintf(f, "\n");
- ead = ea_get_data(insn->ea);
- fprintf(f, "%*sLen=%u SegmentOv=%02x NoSplit=%u\n",
- indent_level, "", (unsigned int)insn->ea->len,
- (unsigned int)ead->segment,
- (unsigned int)insn->ea->nosplit);
- fprintf(f, "%*sModRM=%03o ValidRM=%u NeedRM=%u\n",
- indent_level, "", (unsigned int)ead->modrm,
- (unsigned int)ead->valid_modrm,
- (unsigned int)ead->need_modrm);
- fprintf(f, "%*sSIB=%03o ValidSIB=%u NeedSIB=%u\n",
- indent_level, "", (unsigned int)ead->sib,
- (unsigned int)ead->valid_sib,
- (unsigned int)ead->need_sib);
- indent_level--;
- }
- fprintf(f, "%*sImmediate Value:", indent_level, "");
- if (!insn->imm)
- fprintf(f, " (nil)\n");
- else {
- indent_level++;
- fprintf(f, "\n%*sVal=", indent_level, "");
- if (insn->imm->val)
- expr_print(f, insn->imm->val);
- else
- fprintf(f, "(nil-SHOULDN'T HAPPEN)");
- fprintf(f, "\n");
- fprintf(f, "%*sLen=%u, IsNeg=%u\n", indent_level, "",
- (unsigned int)insn->imm->len,
- (unsigned int)insn->imm->isneg);
- fprintf(f, "%*sFLen=%u, FSign=%u\n", indent_level, "",
- (unsigned int)insn->imm->f_len,
- (unsigned int)insn->imm->f_sign);
- indent_level--;
- }
- fprintf(f, "%*sOpcode: %02x %02x %02x OpLen=%u\n", indent_level,
- "", (unsigned int)insn->opcode[0],
- (unsigned int)insn->opcode[1],
- (unsigned int)insn->opcode[2],
- (unsigned int)insn->opcode_len);
- fprintf(f,
- "%*sAddrSize=%u OperSize=%u LockRepPre=%02x ShiftOp=%u\n",
- indent_level, "",
- (unsigned int)insn->addrsize,
- (unsigned int)insn->opersize,
- (unsigned int)insn->lockrep_pre,
- (unsigned int)insn->shift_op);
- fprintf(f, "%*sBITS=%u\n", indent_level, "",
- (unsigned int)insn->mode_bits);
- break;
- case X86_BC_JMPREL:
- jmprel = bc_get_const_data(bc);
- fprintf(f, "%*s_Relative Jump_\n", indent_level, "");
- fprintf(f, "%*sTarget=", indent_level, "");
- expr_print(f, jmprel->target);
- fprintf(f, "\n%*sShort Form:\n", indent_level, "");
- indent_level++;
- if (jmprel->shortop.opcode_len == 0)
- fprintf(f, "%*sNone\n", indent_level, "");
- else
- fprintf(f, "%*sOpcode: %02x %02x %02x OpLen=%u\n",
- indent_level, "",
- (unsigned int)jmprel->shortop.opcode[0],
- (unsigned int)jmprel->shortop.opcode[1],
- (unsigned int)jmprel->shortop.opcode[2],
- (unsigned int)jmprel->shortop.opcode_len);
- indent_level--;
- fprintf(f, "%*sNear Form:\n", indent_level, "");
- indent_level++;
- if (jmprel->nearop.opcode_len == 0)
- fprintf(f, "%*sNone\n", indent_level, "");
- else
- fprintf(f, "%*sOpcode: %02x %02x %02x OpLen=%u\n",
- indent_level, "",
- (unsigned int)jmprel->nearop.opcode[0],
- (unsigned int)jmprel->nearop.opcode[1],
- (unsigned int)jmprel->nearop.opcode[2],
- (unsigned int)jmprel->nearop.opcode_len);
- indent_level--;
- fprintf(f, "%*sOpSel=", indent_level, "");
- switch (jmprel->op_sel) {
- case JR_NONE:
- fprintf(f, "None");
- break;
- case JR_SHORT:
- fprintf(f, "Short");
- break;
- case JR_NEAR:
- fprintf(f, "Near");
- break;
- case JR_SHORT_FORCED:
- fprintf(f, "Forced Short");
- break;
- case JR_NEAR_FORCED:
- fprintf(f, "Forced Near");
- break;
- default:
- fprintf(f, "UNKNOWN!!");
- break;
- }
- fprintf(f, "\n%*sAddrSize=%u OperSize=%u LockRepPre=%02x\n",
- indent_level, "",
- (unsigned int)jmprel->addrsize,
- (unsigned int)jmprel->opersize,
- (unsigned int)jmprel->lockrep_pre);
- fprintf(f, "%*sBITS=%u\n", indent_level, "",
- (unsigned int)jmprel->mode_bits);
- break;
- }
-}
-
-static int
-x86_bc_calc_len_insn(x86_insn *insn, /*@only@*/ /*@null@*/
- intnum *(*resolve_label) (section *sect,
- /*@null@*/ bytecode *bc))
-{
- effaddr *ea = insn->ea;
- x86_effaddr_data *ead = ea_get_data(ea);
- immval *imm = insn->imm;
-
- if (ea) {
- if ((ea->disp) && ((!ead->valid_sib && ead->need_sib) ||
- (!ead->valid_modrm && ead->need_modrm))) {
- /* First expand equ's */
- expr_expand_equ(ea->disp);
-
- /* Check validity of effective address and calc R/M bits of
- * Mod/RM byte and SIB byte. We won't know the Mod field
- * of the Mod/RM byte until we know more about the
- * displacement.
- */
- if (!x86_expr_checkea(&ea->disp, &insn->addrsize, insn->mode_bits,
- ea->nosplit, &ea->len, &ead->modrm,
- &ead->valid_modrm, &ead->need_modrm,
- &ead->sib, &ead->valid_sib, &ead->need_sib))
- return 0; /* failed, don't bother checking rest of insn */
- }
- }
-
- if (imm) {
- const intnum *num;
-
- if (imm->val) {
- expr_expand_equ(imm->val);
- imm->val = expr_simplify(imm->val);
- }
- /* TODO: check imm f_len vs. len? */
-
- /* Handle shift_op special-casing */
- /*@-nullstate@*/
- if (insn->shift_op && (num = expr_get_intnum(&imm->val))) {
- /*@=nullstate@*/
- if (num) {
- if (intnum_get_uint(num) == 1) {
- /* Use ,1 form: first copy ,1 opcode. */
- insn->opcode[0] = insn->opcode[1];
- /* Delete Imm, as it's not needed */
- expr_delete(imm->val);
- xfree(imm);
- insn->imm = (immval *)NULL;
- }
- insn->shift_op = 0;
- }
- }
- }
-
- return 0;
-}
-
-int
-x86_bc_calc_len(bytecode *bc,
- intnum *(*resolve_label) (section *sect,
- /*@null@*/ bytecode *bc))
-{
- x86_insn *insn;
-
- switch ((x86_bytecode_type)bc->type) {
- case X86_BC_INSN:
- insn = bc_get_data(bc);
- return x86_bc_calc_len_insn(insn, resolve_label);
- default:
- break;
- }
- return 0;
-}
-
+++ /dev/null
-/*
- * x86 expression handling
- *
- * Copyright (C) 2001 Peter Johnson
- *
- * This file is part of YASM.
- *
- * YASM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * YASM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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"
-/*@unused@*/ RCSID("$IdPath$");
-
-#include "bitvect.h"
-
-#include "globals.h"
-#include "errwarn.h"
-#include "intnum.h"
-#include "floatnum.h"
-#include "expr.h"
-
-#include "bytecode.h"
-#include "arch.h"
-
-#include "x86-int.h"
-
-#include "expr-int.h"
-
-
-/* Only works if ei->type == EXPR_REG (doesn't check).
- * Overwrites ei with intnum of 0 (to eliminate regs from the final expr).
- */
-static /*@null@*/ /*@dependent@*/ int *
-x86_expr_checkea_get_reg32(ExprItem *ei, /*returned*/ void *d)
-{
- int *data = d;
- int *ret;
-
- /* don't allow 16-bit registers */
- if (ei->data.reg.size != 32)
- return 0;
-
- ret = &data[ei->data.reg.num & 7]; /* & 7 for sanity check */
-
- /* overwrite with 0 to eliminate register from displacement expr */
- ei->type = EXPR_INT;
- ei->data.intn = intnum_new_int(0);
-
- /* we're okay */
- return ret;
-}
-
-typedef struct x86_checkea_reg16_data {
- int bx, si, di, bp; /* total multiplier for each reg */
-} x86_checkea_reg16_data;
-
-/* Only works if ei->type == EXPR_REG (doesn't check).
- * Overwrites ei with intnum of 0 (to eliminate regs from the final expr).
- */
-static /*@null@*/ int *
-x86_expr_checkea_get_reg16(ExprItem *ei, void *d)
-{
- x86_checkea_reg16_data *data = d;
- /* in order: ax,cx,dx,bx,sp,bp,si,di */
- /*@-nullassign@*/
- static int *reg16[8] = {0,0,0,0,0,0,0,0};
- /*@=nullassign@*/
- int *ret;
-
- reg16[3] = &data->bx;
- reg16[5] = &data->bp;
- reg16[6] = &data->si;
- reg16[7] = &data->di;
-
- /* don't allow 32-bit registers */
- if (ei->data.reg.size != 16)
- return 0;
-
- ret = reg16[ei->data.reg.num & 7]; /* & 7 for sanity check */
-
- /* only allow BX, SI, DI, BP */
- if (!ret)
- return 0;
-
- /* overwrite with 0 to eliminate register from displacement expr */
- ei->type = EXPR_INT;
- ei->data.intn = intnum_new_int(0);
-
- /* we're okay */
- return ret;
-}
-
-/* Distribute over registers to help bring them to the topmost level of e.
- * Also check for illegal operations against registers.
- * Returns 0 if something was illegal, 1 if legal and nothing in e changed,
- * and 2 if legal and e needs to be simplified.
- *
- * Only half joking: Someday make this/checkea able to accept crazy things
- * like: (bx+di)*(bx+di)-bx*bx-2*bx*di-di*di+di? Probably not: NASM never
- * accepted such things, and it's doubtful such an expn is valid anyway
- * (even though the above one is). But even macros would be hard-pressed
- * to generate something like this.
- *
- * e must already have been simplified for this function to work properly
- * (as it doesn't think things like SUB are valid).
- *
- * IMPLEMENTATION NOTE: About the only thing this function really needs to
- * "distribute" is: (non-float-expn or intnum) * (sum expn of registers).
- *
- * TODO: Clean up this code, make it easier to understand.
- */
-static int
-x86_expr_checkea_distcheck_reg(expr **ep)
-{
- expr *e = *ep;
- int i;
- int havereg = -1, havereg_expr = -1;
- int retval = 1; /* default to legal, no changes */
-
- for (i=0; i<e->numterms; i++) {
- switch (e->terms[i].type) {
- case EXPR_REG:
- /* Check op to make sure it's valid to use w/register. */
- if (e->op != EXPR_ADD && e->op != EXPR_MUL &&
- e->op != EXPR_IDENT)
- return 0;
- /* Check for reg*reg */
- if (e->op == EXPR_MUL && havereg != -1)
- return 0;
- havereg = i;
- break;
- case EXPR_FLOAT:
- /* Floats not allowed. */
- return 0;
- case EXPR_EXPR:
- if (expr_contains(e->terms[i].data.expn, EXPR_REG)) {
- int ret2;
-
- /* Check op to make sure it's valid to use w/register. */
- if (e->op != EXPR_ADD && e->op != EXPR_MUL)
- return 0;
- /* Check for reg*reg */
- if (e->op == EXPR_MUL && havereg != -1)
- return 0;
- havereg = i;
- havereg_expr = i;
- /* Recurse to check lower levels */
- ret2 =
- x86_expr_checkea_distcheck_reg(&e->terms[i].data.expn);
- if (ret2 == 0)
- return 0;
- if (ret2 == 2)
- retval = 2;
- } else if (expr_contains(e->terms[i].data.expn, EXPR_FLOAT))
- return 0; /* Disallow floats */
- break;
- default:
- break;
- }
- }
-
- /* just exit if no registers were used */
- if (havereg == -1)
- return retval;
-
- /* Distribute */
- if (e->op == EXPR_MUL && havereg_expr != -1) {
- expr *ne;
-
- retval = 2; /* we're going to change it */
-
- /* The reg expn *must* be EXPR_ADD at this point. Sanity check. */
- if (e->terms[havereg_expr].type != EXPR_EXPR ||
- e->terms[havereg_expr].data.expn->op != EXPR_ADD)
- InternalError(_("Register expression not ADD or EXPN"));
-
- /* Iterate over each term in reg expn */
- for (i=0; i<e->terms[havereg_expr].data.expn->numterms; i++) {
- /* Copy everything EXCEPT havereg_expr term into new expression */
- ne = expr_copy_except(e, havereg_expr);
- assert(ne != NULL);
- /* Copy reg expr term into uncopied (empty) term in new expn */
- ne->terms[havereg_expr] =
- e->terms[havereg_expr].data.expn->terms[i]; /* struct copy */
- /* Overwrite old reg expr term with new expn */
- e->terms[havereg_expr].data.expn->terms[i].type = EXPR_EXPR;
- e->terms[havereg_expr].data.expn->terms[i].data.expn = ne;
- }
-
- /* Replace e with expanded reg expn */
- ne = e->terms[havereg_expr].data.expn;
- e->terms[havereg_expr].type = EXPR_NONE; /* don't delete it! */
- expr_delete(e); /* but everything else */
- e = ne;
- /*@-onlytrans@*/
- *ep = ne;
- /*@=onlytrans@*/
- }
-
- return retval;
-}
-
-/* Simplify and determine if expression is superficially valid:
- * Valid expr should be [(int-equiv expn)]+[reg*(int-equiv expn)+...]
- * where the [...] parts are optional.
- *
- * Don't simplify out constant identities if we're looking for an indexreg: we
- * may need the multiplier for determining what the indexreg is!
- *
- * Returns 0 if invalid register usage, 1 if unable to determine all values,
- * and 2 if all values successfully determined and saved in data.
- */
-static int
-x86_expr_checkea_getregusage(expr **ep, /*@null@*/ int *indexreg, void *data,
- int *(*get_reg)(ExprItem *ei, void *d))
-{
- int i;
- int *reg;
- expr *e;
-
- /*@-unqualifiedtrans@*/
- *ep = expr_xform_neg_tree(*ep);
- *ep = expr_level_tree(*ep, 1, indexreg == 0);
- /*@=unqualifiedtrans@*/
- assert(*ep != NULL);
- e = *ep;
- switch (x86_expr_checkea_distcheck_reg(ep)) {
- case 0:
- return 0;
- case 2:
- /* Need to simplify again */
- *ep = expr_xform_neg_tree(*ep);
- *ep = expr_level_tree(*ep, 1, indexreg == 0);
- e = *ep;
- break;
- default:
- break;
- }
-
- switch (e->op) {
- case EXPR_ADD:
- /* Prescan for non-int multipliers.
- * This is because if any of the terms is a more complex
- * expr (eg, undetermined value), we don't want to try to
- * figure out *any* of the expression, because each register
- * lookup overwrites the register with a 0 value! And storing
- * the state of this routine from one excution to the next
- * would be a major chore.
- */
- for (i=0; i<e->numterms; i++)
- if (e->terms[i].type == EXPR_EXPR) {
- if (e->terms[i].data.expn->numterms > 2)
- return 1;
- expr_order_terms(e->terms[i].data.expn);
- if (e->terms[i].data.expn->terms[1].type != EXPR_INT)
- return 1;
- }
-
- /*@fallthrough@*/
- case EXPR_IDENT:
- /* Check each term for register (and possible multiplier). */
- for (i=0; i<e->numterms; i++) {
- if (e->terms[i].type == EXPR_REG) {
- reg = get_reg(&e->terms[i], data);
- if (!reg)
- return 0;
- (*reg)++;
- if (indexreg)
- *indexreg = reg-(int *)data;
- } else if (e->terms[i].type == EXPR_EXPR) {
- /* Already ordered from ADD above, just grab the value.
- * Sanity check for EXPR_INT.
- */
- if (e->terms[i].data.expn->terms[0].type != EXPR_REG)
- InternalError(_("Register not found in reg expn"));
- if (e->terms[i].data.expn->terms[1].type != EXPR_INT)
- InternalError(_("Non-integer value in reg expn"));
- reg = get_reg(&e->terms[i].data.expn->terms[0], data);
- if (!reg)
- return 0;
- (*reg) +=
- intnum_get_int(e->terms[i].data.expn->terms[1].data.intn);
- if (indexreg)
- *indexreg = reg-(int *)data;
- }
- }
- break;
- case EXPR_MUL:
- /* Here, too, check for non-int multipliers. */
- if (e->numterms > 2)
- return 1;
- expr_order_terms(e);
- if (e->terms[1].type != EXPR_INT)
- return 1;
- reg = get_reg(&e->terms[0], data);
- if (!reg)
- return 0;
- (*reg) += intnum_get_int(e->terms[1].data.intn);
- if (indexreg)
- *indexreg = reg-(int *)data;
- break;
- default:
- /* Should never get here! */
- break;
- }
-
- /* Simplify expr, which is now really just the displacement. This
- * should get rid of the 0's we put in for registers in the callback.
- */
- *ep = expr_simplify(*ep);
- /* e = *ep; */
-
- return 2;
-}
-
-/* Calculate the displacement length, if possible.
- * Takes several extra inputs so it can be used by both 32-bit and 16-bit
- * expressions:
- * wordsize=2 for 16-bit, =4 for 32-bit.
- * noreg=1 if the *ModRM byte* has no registers used.
- * isbpreg=1 if BP/EBP is the *only* register used within the *ModRM byte*.
- */
-/*@-nullstate@*/
-static int
-x86_checkea_calc_displen(expr **ep, unsigned int wordsize, int noreg,
- int isbpreg, unsigned char *displen,
- unsigned char *modrm, unsigned char *v_modrm)
-{
- expr *e = *ep;
- const intnum *intn;
- long dispval;
-
- *v_modrm = 0; /* default to not yet valid */
-
- switch (*displen) {
- case 0:
- /* the displacement length hasn't been forced, try to
- * determine what it is.
- */
- if (noreg) {
- /* no register in ModRM expression, so it must be disp16/32,
- * and as the Mod bits are set to 0 by the caller, we're done
- * with the ModRM byte.
- */
- *displen = wordsize;
- *v_modrm = 1;
- } else if (isbpreg) {
- /* for BP/EBP, there *must* be a displacement value, but we
- * may not know the size (8 or 16/32) for sure right now.
- * We can't leave displen at 0, because that just means
- * unknown displacement, including none.
- */
- *displen = 0xff;
- }
-
- intn = expr_get_intnum(ep);
- if (!intn)
- break; /* expr still has unknown values */
-
- /* make sure the displacement will fit in 16/32 bits if unsigned,
- * and 8 bits if signed.
- */
- if (!intnum_check_size(intn, (size_t)wordsize, 0) &&
- !intnum_check_size(intn, 1, 1)) {
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- }
-
- /* don't try to find out what size displacement we have if
- * displen is known.
- */
- if (*displen != 0 && *displen != 0xff)
- break;
-
- /* Don't worry about overflows here (it's already guaranteed
- * to be 16/32 or 8 bits).
- */
- dispval = intnum_get_int(intn);
-
- /* Figure out what size displacement we will have. */
- if (*displen != 0xff && dispval == 0) {
- /* if we know that the displacement is 0 right now,
- * go ahead and delete the expr (making it so no
- * displacement value is included in the output).
- * The Mod bits of ModRM are set to 0 above, and
- * we're done with the ModRM byte!
- *
- * Don't do this if we came from isbpreg check above, so
- * check *displen.
- */
- expr_delete(e);
- *ep = (expr *)NULL;
- } else if (dispval >= -128 && dispval <= 127) {
- /* It fits into a signed byte */
- *displen = 1;
- *modrm |= 0100;
- } else {
- /* It's a 16/32-bit displacement */
- *displen = wordsize;
- *modrm |= 0200;
- }
- *v_modrm = 1; /* We're done with ModRM */
-
- break;
-
- /* If not 0, the displacement length was forced; set the Mod bits
- * appropriately and we're done with the ModRM byte. We assume
- * that the user knows what they're doing if they do an explicit
- * override, so we don't check for overflow (we'll just truncate
- * when we output).
- */
- case 1:
- /* TODO: Add optional warning here about byte not being valid
- * override in noreg case.
- */
- if (!noreg)
- *modrm |= 0100;
- *v_modrm = 1;
- break;
- case 2:
- case 4:
- if (wordsize != *displen) {
- ErrorAt(e->filename, e->line,
- _("invalid effective address (displacement size)"));
- return 0;
- }
- /* TODO: Add optional warning here about 2/4 not being valid
- * override in noreg case.
- */
- if (!noreg)
- *modrm |= 0200;
- *v_modrm = 1;
- break;
- default:
- /* we shouldn't ever get any other size! */
- InternalError(_("strange EA displacement size"));
- }
-
- return 1;
-}
-/*@=nullstate@*/
-
-static int
-x86_expr_checkea_getregsize_callback(ExprItem *ei, void *d)
-{
- unsigned char *addrsize = (unsigned char *)d;
-
- if (ei->type == EXPR_REG) {
- *addrsize = ei->data.reg.size;
- return 1;
- } else
- return 0;
-}
-
-int
-x86_expr_checkea(expr **ep, unsigned char *addrsize, unsigned char bits,
- unsigned char nosplit, unsigned char *displen,
- unsigned char *modrm, unsigned char *v_modrm,
- unsigned char *n_modrm, unsigned char *sib,
- unsigned char *v_sib, unsigned char *n_sib)
-{
- expr *e = *ep;
-
- if (*addrsize == 0) {
- /* we need to figure out the address size from what we know about:
- * - the displacement length
- * - what registers are used in the expression
- * - the bits setting
- */
- switch (*displen) {
- case 4:
- /* must be 32-bit */
- *addrsize = 32;
- break;
- case 2:
- /* must be 16-bit */
- *addrsize = 16;
- break;
- default:
- /* check for use of 16 or 32-bit registers; if none are used
- * default to bits setting.
- */
- if (!expr_traverse_leaves_in(e, addrsize,
- x86_expr_checkea_getregsize_callback))
- *addrsize = bits;
- /* TODO: Add optional warning here if switched address size
- * from bits setting just by register use.. eg [ax] in
- * 32-bit mode would generate a warning.
- */
- }
- }
-
- if (*addrsize == 32 && ((*n_modrm && !*v_modrm) || (*n_sib && !*v_sib))) {
- int i;
- typedef enum {
- REG32_NONE = -1,
- REG32_EAX = 0,
- REG32_ECX = 1,
- REG32_EDX = 2,
- REG32_EBX = 3,
- REG32_ESP = 4,
- REG32_EBP = 5,
- REG32_ESI = 6,
- REG32_EDI = 7
- } reg32type;
- int reg32mult[8] = {0, 0, 0, 0, 0, 0, 0, 0};
- int basereg = REG32_NONE; /* "base" register (for SIB) */
- int indexreg = REG32_NONE; /* "index" register (for SIB) */
-
- switch (x86_expr_checkea_getregusage(ep, &indexreg, reg32mult,
- x86_expr_checkea_get_reg32)) {
- case 0:
- e = *ep;
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- case 1:
- return 1;
- default:
- e = *ep;
- break;
- }
-
- /* If indexreg mult is 0, discard it.
- * This is possible because of the way indexreg is found in
- * expr_checkea_getregusage().
- */
- if (indexreg != REG32_NONE && reg32mult[indexreg] == 0)
- indexreg = REG32_NONE;
-
- /* Find a basereg (*1, but not indexreg), if there is one.
- * Also, if an indexreg hasn't been assigned, try to find one.
- * Meanwhile, check to make sure there's no negative register mults.
- */
- for (i=0; i<8; i++) {
- if (reg32mult[i] < 0) {
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- }
- if (i != indexreg && reg32mult[i] == 1)
- basereg = i;
- else if (indexreg == REG32_NONE && reg32mult[i] > 0)
- indexreg = i;
- }
-
- /* Handle certain special cases of indexreg mults when basereg is
- * empty.
- */
- if (indexreg != REG32_NONE && basereg == REG32_NONE)
- switch (reg32mult[indexreg]) {
- case 1:
- /* Only optimize this way if nosplit wasn't specified */
- if (!nosplit) {
- basereg = indexreg;
- indexreg = -1;
- }
- break;
- case 2:
- /* Only split if nosplit wasn't specified */
- if (!nosplit) {
- basereg = indexreg;
- reg32mult[indexreg] = 1;
- }
- break;
- case 3:
- case 5:
- case 9:
- basereg = indexreg;
- reg32mult[indexreg]--;
- break;
- }
-
- /* Make sure there's no other registers than the basereg and indexreg
- * we just found.
- */
- for (i=0; i<8; i++)
- if (i != basereg && i != indexreg && reg32mult[i] != 0) {
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- }
-
- /* Check the index multiplier value for validity if present. */
- if (indexreg != REG32_NONE && reg32mult[indexreg] != 1 &&
- reg32mult[indexreg] != 2 && reg32mult[indexreg] != 4 &&
- reg32mult[indexreg] != 8) {
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- }
-
- /* ESP is not a legal indexreg. */
- if (indexreg == REG32_ESP) {
- /* If mult>1 or basereg is ESP also, there's no way to make it
- * legal.
- */
- if (reg32mult[REG32_ESP] > 1 || basereg == REG32_ESP) {
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- }
- /* If mult==1 and basereg is not ESP, swap indexreg w/basereg. */
- indexreg = basereg;
- basereg = REG32_ESP;
- }
-
- /* At this point, we know the base and index registers and that the
- * memory expression is (essentially) valid. Now build the ModRM and
- * (optional) SIB bytes.
- */
-
- /* First determine R/M (Mod is later determined from disp size) */
- *n_modrm = 1; /* we always need ModRM */
- if (basereg == REG32_NONE) {
- /* disp32[index] */
- *modrm |= 5;
- /* we must have a SIB */
- *n_sib = 1;
- } else if (indexreg == REG32_NONE) {
- /* basereg only */
- *modrm |= basereg;
- /* we don't need an SIB *unless* basereg is ESP */
- if (basereg == REG32_ESP)
- *n_sib = 1;
- else {
- *sib = 0;
- *v_sib = 0;
- *n_sib = 0;
- }
- } else {
- /* both base AND index */
- *modrm |= 4;
- *n_sib = 1;
- }
-
- /* Determine SIB if needed */
- if (*n_sib == 1) {
- *sib = 0; /* start with 0 */
-
- /* Special case: no basereg (only happens in disp32[index] case) */
- if (basereg == REG32_NONE)
- *sib |= 5;
- else
- *sib |= basereg & 7; /* &7 to sanity check */
-
- /* Put in indexreg, checking for none case */
- if (indexreg == REG32_NONE)
- *sib |= 040;
- /* Any scale field is valid, just leave at 0. */
- else {
- *sib |= ((unsigned int)indexreg & 7) << 3;
- /* Set scale field, 1 case -> 0, so don't bother. */
- switch (reg32mult[indexreg]) {
- case 2:
- *sib |= 0100;
- break;
- case 4:
- *sib |= 0200;
- break;
- case 8:
- *sib |= 0300;
- break;
- }
- }
-
- *v_sib = 1; /* Done with SIB */
- }
-
- /* Calculate displacement length (if possible) */
- return x86_checkea_calc_displen(ep, 4, basereg == REG32_NONE,
- basereg == REG32_EBP &&
- indexreg == REG32_NONE, displen,
- modrm, v_modrm);
- } else if (*addrsize == 16 && *n_modrm && !*v_modrm) {
- static const unsigned char modrm16[16] = {
- 0006 /* disp16 */, 0007 /* [BX] */, 0004 /* [SI] */,
- 0000 /* [BX+SI] */, 0005 /* [DI] */, 0001 /* [BX+DI] */,
- 0377 /* invalid */, 0377 /* invalid */, 0006 /* [BP]+d */,
- 0377 /* invalid */, 0002 /* [BP+SI] */, 0377 /* invalid */,
- 0003 /* [BP+DI] */, 0377 /* invalid */, 0377 /* invalid */,
- 0377 /* invalid */
- };
- x86_checkea_reg16_data reg16mult = {0, 0, 0, 0};
- enum {
- HAVE_NONE = 0,
- HAVE_BX = 1<<0,
- HAVE_SI = 1<<1,
- HAVE_DI = 1<<2,
- HAVE_BP = 1<<3
- } havereg = HAVE_NONE;
-
- /* 16-bit cannot have SIB */
- *sib = 0;
- *v_sib = 0;
- *n_sib = 0;
-
- switch (x86_expr_checkea_getregusage(ep, (int *)NULL, ®16mult,
- x86_expr_checkea_get_reg16)) {
- case 0:
- e = *ep;
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- case 1:
- return 1;
- default:
- e = *ep;
- break;
- }
-
- /* reg multipliers not 0 or 1 are illegal. */
- if (reg16mult.bx & ~1 || reg16mult.si & ~1 || reg16mult.di & ~1 ||
- reg16mult.bp & ~1) {
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- }
-
- /* Set havereg appropriately */
- if (reg16mult.bx > 0)
- havereg |= HAVE_BX;
- if (reg16mult.si > 0)
- havereg |= HAVE_SI;
- if (reg16mult.di > 0)
- havereg |= HAVE_DI;
- if (reg16mult.bp > 0)
- havereg |= HAVE_BP;
-
- /* Check the modrm value for invalid combinations. */
- if (modrm16[havereg] & 0070) {
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- }
-
- /* Set ModRM byte for registers */
- *modrm |= modrm16[havereg];
-
- /* Calculate displacement length (if possible) */
- return x86_checkea_calc_displen(ep, 2, havereg == HAVE_NONE,
- havereg == HAVE_BP, displen, modrm,
- v_modrm);
- }
- return 1;
-}
+++ /dev/null
-# $IdPath$
-
-SUBDIRS = dbg
+++ /dev/null
-# $IdPath$
-
-noinst_LIBRARIES = libobjfmt.a
-
-libobjfmt_a_SOURCES = \
- objfmt.c
-
-INCLUDES = \
- -I$(top_srcdir)/src \
- -I$(top_builddir)/intl
-
-CFLAGS = @ANSI_CFLAGS@
+++ /dev/null
-/*
- * Debugging object format (used to debug object format module interface)
- *
- * Copyright (C) 2001 Peter Johnson
- *
- * This file is part of YASM.
- *
- * YASM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * YASM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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"
-/*@unused@*/ RCSID("$IdPath$");
-
-#include "globals.h"
-#include "expr.h"
-#include "symrec.h"
-
-#include "section.h"
-#include "objfmt.h"
-
-
-/*@dependent@*/ FILE *dbg_f;
-
-static void
-dbg_objfmt_initialize(/*@dependent@*/ FILE *f)
-{
- dbg_f = f;
- fprintf(dbg_f, "%*sinitialize(f)\n", indent_level, "");
-}
-
-static void
-dbg_objfmt_finalize(void)
-{
- fprintf(dbg_f, "%*sfinalize()\n", indent_level, "");
-}
-
-static /*@dependent@*/ /*@null@*/ section *
-dbg_objfmt_sections_switch(sectionhead *headp, valparamhead *valparams,
- /*@unused@*/ /*@null@*/
- valparamhead *objext_valparams)
-{
- valparam *vp;
- section *retval;
- int isnew;
-
- fprintf(dbg_f, "%*ssections_switch(headp, ", indent_level, "");
- vps_print(dbg_f, valparams);
- fprintf(dbg_f, ", ");
- vps_print(dbg_f, objext_valparams);
- fprintf(dbg_f, "), returning ");
-
- if ((vp = vps_first(valparams)) && !vp->param && vp->val != NULL) {
- retval = sections_switch_general(headp, vp->val, NULL, 0, &isnew);
- if (isnew) {
- fprintf(dbg_f, "(new) ");
- symrec_define_label(vp->val, retval, (bytecode *)NULL, 1);
- }
- fprintf(dbg_f, "\"%s\" section\n", vp->val);
- return retval;
- } else {
- fprintf(dbg_f, "NULL\n");
- return NULL;
- }
-}
-
-static void
-dbg_objfmt_section_data_delete(/*@only@*/ void *data)
-{
- fprintf(dbg_f, "%*ssection_data_delete(%p)\n", indent_level, "", data);
- xfree(data);
-}
-
-static void
-dbg_objfmt_section_data_print(FILE *f, /*@null@*/ void *data)
-{
- if (data)
- fprintf(f, "%*s%p\n", indent_level, "", data);
- else
- fprintf(f, "%*s(none)\n", indent_level, "");
-}
-
-static /*@null@*/ void *
-dbg_objfmt_extern_data_new(const char *name, /*@unused@*/ /*@null@*/
- valparamhead *objext_valparams)
-{
- fprintf(dbg_f, "%*sextern_data_new(\"%s\", ", indent_level, "", name);
- vps_print(dbg_f, objext_valparams);
- fprintf(dbg_f, "), returning NULL\n");
- return NULL;
-}
-
-static /*@null@*/ void *
-dbg_objfmt_global_data_new(const char *name, /*@unused@*/ /*@null@*/
- valparamhead *objext_valparams)
-{
- fprintf(dbg_f, "%*sglobal_data_new(\"%s\", ", indent_level, "", name);
- vps_print(dbg_f, objext_valparams);
- fprintf(dbg_f, "), returning NULL\n");
- return NULL;
-}
-
-static /*@null@*/ void *
-dbg_objfmt_common_data_new(const char *name, /*@only@*/ expr *size,
- /*@unused@*/ /*@null@*/
- valparamhead *objext_valparams)
-{
- fprintf(dbg_f, "%*scommon_data_new(\"%s\", ", indent_level, "", name);
- expr_print(dbg_f, size);
- fprintf(dbg_f, ", ");
- vps_print(dbg_f, objext_valparams);
- fprintf(dbg_f, "), returning ");
- expr_print(dbg_f, size);
- fprintf(dbg_f, "\n");
- return size;
-}
-
-static void
-dbg_objfmt_declare_data_delete(SymVisibility vis, /*@only@*/ void *data)
-{
- fprintf(dbg_f, "%*sdeclare_data_delete(", indent_level, "");
- switch (vis) {
- case SYM_LOCAL:
- fprintf(dbg_f, "Local, ");
- break;
- case SYM_GLOBAL:
- fprintf(dbg_f, "Global, ");
- break;
- case SYM_COMMON:
- fprintf(dbg_f, "Common, ");
- break;
- case SYM_EXTERN:
- fprintf(dbg_f, "Extern, ");
- break;
- }
- if (vis == SYM_COMMON) {
- expr_print(dbg_f, data);
- expr_delete(data);
- } else {
- fprintf(dbg_f, "%p", data);
- xfree(data);
- }
- fprintf(dbg_f, ")\n");
-}
-
-static void
-dbg_objfmt_declare_data_print(FILE *f, SymVisibility vis,
- /*@null@*/ void *data)
-{
- if (vis == SYM_COMMON) {
- fprintf(f, "%*sSize=", indent_level, "");
- expr_print(f, data);
- fprintf(f, "\n");
- } else {
- fprintf(f, "%*s(none)\n", indent_level, "");
- }
-}
-
-static int
-dbg_objfmt_directive(const char *name, valparamhead *valparams,
- /*@null@*/ valparamhead *objext_valparams)
-{
- fprintf(dbg_f, "%*sdirective(\"%s\", ", indent_level, "", name);
- vps_print(dbg_f, valparams);
- fprintf(dbg_f, ", ");
- vps_print(dbg_f, objext_valparams);
- fprintf(dbg_f, "), returning 0 (recognized)\n");
- return 0; /* dbg format "recognizes" all directives */
-}
-
-/* Define objfmt structure -- see objfmt.h for details */
-objfmt dbg_objfmt = {
- "Trace of all info passed to object format module",
- "dbg",
- "dbg",
- ".text",
- 32,
- dbg_objfmt_initialize,
- dbg_objfmt_finalize,
- dbg_objfmt_sections_switch,
- dbg_objfmt_section_data_delete,
- dbg_objfmt_section_data_print,
- dbg_objfmt_extern_data_new,
- dbg_objfmt_global_data_new,
- dbg_objfmt_common_data_new,
- dbg_objfmt_declare_data_delete,
- dbg_objfmt_declare_data_print,
- dbg_objfmt_directive
-};
+++ /dev/null
-# $IdPath$
-
-SUBDIRS = basic
+++ /dev/null
-# $IdPath$
-
-noinst_LIBRARIES = liboptimizer.a
-
-liboptimizer_a_SOURCES = \
- optimizer.c
-
-INCLUDES = \
- -I$(top_srcdir)/src \
- -I$(top_builddir)/intl
-
-CFLAGS = @ANSI_CFLAGS@
--- /dev/null
+# $IdPath$
+
+YASMOPTIMIZERFILES += \
+ src/optimizers/basic/basic-optimizer.c
+++ /dev/null
-/*
- * Basic optimizer (equivalent to the NASM 2-pass 'no optimizer' design)
- *
- * Copyright (C) 2001 Peter Johnson
- *
- * This file is part of YASM.
- *
- * YASM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * YASM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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"
-RCSID("$IdPath$");
-
-#include "bytecode.h"
-#include "section.h"
-
-#include "bc-int.h"
-
-#include "optimizer.h"
-
-
-#define SECTFLAG_NONE 0
-#define SECTFLAG_INPROGRESS (1<<0)
-#define SECTFLAG_DONE (1<<1)
-
-#define BCFLAG_NONE 0
-#define BCFLAG_INPROGRESS (1<<0)
-#define BCFLAG_DONE (1<<1)
-
-static /*@only@*/ /*@null@*/ intnum *
-basic_optimize_resolve_label(section *sect, bytecode *bc)
-{
- unsigned long flags;
-
- flags = section_get_opt_flags(sect);
-
- return NULL;
-}
-
-static int
-basic_optimize_bytecode(bytecode *bc, /*@unused@*/ /*@null@*/ void *d)
-{
- bc->opt_flags = BCFLAG_INPROGRESS;
-
- bc_calc_len(bc, basic_optimize_resolve_label);
-
- bc->opt_flags = BCFLAG_DONE;
-
- return 1;
-}
-
-static int
-basic_optimize_section(section *sect, /*@unused@*/ /*@null@*/ void *d)
-{
- section_set_opt_flags(sect, SECTFLAG_INPROGRESS);
-
- bcs_traverse(section_get_bytecodes(sect), NULL, basic_optimize_bytecode);
-
- section_set_opt_flags(sect, SECTFLAG_DONE);
-
- return 1;
-}
-
-static sectionhead *
-basic_optimize(sectionhead *sections)
-{
- /* Optimization process: (essentially NASM's pass 1)
- * Determine the size of all bytecodes.
- * Check "critical" expressions (must be computable on the first pass,
- * i.e. depend only on symbols before it).
- * Differences from NASM:
- * - right-hand side of EQU is /not/ a critical expr (as the entire file
- * has already been parsed, we know all their values at this point).
- * - not strictly top->bottom scanning; we scan through a section and
- * hop to other sections as necessary.
- */
- sections_traverse(sections, NULL, basic_optimize_section);
-
- /* NASM's pass 2 is output, so we just return. */
- return sections;
-}
-
-/* Define optimizer structure -- see optimizer.h for details */
-optimizer basic_optimizer = {
- "Only the most basic optimizations",
- "basic",
- basic_optimize
-};
+++ /dev/null
-# $IdPath$
-
-SUBDIRS = nasm
--- /dev/null
+# $IdPath$
+
+EXTRA_DIST += \
+ src/parsers/nasm/Makefile.inc
+
+YASMPARSERFILES =
+include src/parsers/nasm/Makefile.inc
+yasm_SOURCES += $(YASMPARSERFILES)
+++ /dev/null
-# $IdPath$
-
-noinst_LIBRARIES = libparser.a
-
-if DEV
-libparser_a_SOURCES = \
- parser.c \
- bison.y \
- token.l
-else
-libparser_a_SOURCES = \
- parser.c \
- bison.c \
- token.c
-
-bison.c: bison.y
- @echo "Run configure with --enable-dev before making changes here."
- @exit 1
-
-token.c: token.l
- @echo "Run configure with --enable-dev before making changes here."
- @exit 1
-endif
-
-noinst_SCRIPTS = gen_instr.pl
-
-AM_YFLAGS = -d --name-prefix=nasm_parser_
-AM_LFLAGS = -Pnasm_parser_ -olex.yy.c
-
-INCLUDES = \
- -I$(top_srcdir)/src \
- -I$(top_builddir)/intl
-
-CFLAGS = @ANSI_CFLAGS@
-
-token.l bison.y: $(top_srcdir)/src/arch/@ARCH@/instrs.dat token.l.in bison.y.in gen_instr.pl
-if DEV
- $(PERL) gen_instr.pl -i $(top_srcdir)/src/arch/@ARCH@/instrs.dat -t token.l -g bison.y
-else
- @echo "Run configure with --enable-dev before making changes here."
- @exit 1
-endif
-
-BUILT_SOURCES = token.l bison.y
-
-EXTRA_DIST = \
- token.l \
- token.l.in \
- bison.y \
- bison.y.in \
- bison.h \
- gen_instr.pl
--- /dev/null
+# $IdPath$
+
+YASMPARSERFILES += \
+ src/parsers/nasm/nasm-parser.c \
+ nasm-bison.y \
+ nasm-bison.h \
+ nasm-token.l
+
+if DEV
+
+nasm-token.l nasm-bison.y: $(srcdir)/src/arch/x86/instrs.dat $(srcdir)/src/parsers/nasm/token.l.in $(srcdir)/src/parsers/nasm/bison.y.in $(srcdir)/src/parsers/nasm/gen_instr.pl
+ $(PERL) $(srcdir)/src/parsers/nasm/gen_instr.pl -i $(srcdir)/src/arch/x86/instrs.dat --sourcetoken $(srcdir)/src/parsers/nasm/token.l.in -t nasm-token.l --sourcegrammar $(srcdir)/src/parsers/nasm/bison.y.in -g nasm-bison.y
+
+else
+
+nasm-token.l: $(srcdir)/nasm-token.l
+ @echo Warning: Not generating nasm-token.l from nasm-token.l.in.
+ @echo Run configure with --enable-dev to enable generation.
+ cp $(srcdir)/nasm-token.l .
+nasm-token.c: $(srcdir)/nasm-token.c
+ @echo Warning: Not generating nasm-token.c from nasm-token.l.
+ @echo Run configure with --enable-dev to enable generation.
+ cp $(srcdir)/nasm-token.c .
+nasm-bison.y: $(srcdir)/nasm-bison.y
+ @echo Warning: Not generating nasm-bison.y from nasm-bison.y.in.
+ @echo Run configure with --enable-dev to enable generation.
+ cp $(srcdir)/nasm-bison.y .
+nasm-bison.c: $(srcdir)/nasm-bison.c
+ @echo Warning: Not generating nasm-bison.c from nasm-bison.y.
+ @echo Run configure with --enable-dev to enable generation.
+ cp $(srcdir)/nasm-bison.c .
+nasm-bison.h: $(srcdir)/nasm-bison.h
+ @echo Warning: Not generating nasm-bison.h from nasm-bison.y.
+ @echo Run configure with --enable-dev to enable generation.
+ cp $(srcdir)/nasm-bison.h .
+
+endif
+
+noinst_SCRIPTS = src/parsers/nasm/gen_instr.pl
+
+AM_YFLAGS = -d --name-prefix=nasm_parser_
+AM_LFLAGS = -Pnasm_parser_ -olex.yy.c
+
+BUILT_SOURCES += \
+ nasm-bison.y \
+ nasm-bison.c \
+ nasm-bison.h \
+ nasm-token.l \
+ nasm-token.c
+
+CLEANFILES += \
+ nasm-bison.y \
+ nasm-bison.c \
+ nasm-bison.h \
+ nasm-token.l \
+ nasm-token.c
+
+EXTRA_DIST += \
+ src/parsers/nasm/token.l.in \
+ src/parsers/nasm/bison.y.in \
+ src/parsers/nasm/gen_instr.pl
+++ /dev/null
-/*
- * NASM-compatible parser
- *
- * Copyright (C) 2001 Peter Johnson
- *
- * This file is part of YASM.
- *
- * YASM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * YASM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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"
-/*@unused@*/ RCSID("$IdPath$");
-
-#include "errwarn.h"
-
-#include "section.h"
-#include "objfmt.h"
-#include "preproc.h"
-#include "parser.h"
-
-
-extern FILE *nasm_parser_in;
-extern int nasm_parser_debug;
-
-extern int nasm_parser_parse(void);
-
-size_t (*nasm_parser_yyinput) (char *buf, size_t max_size);
-
-sectionhead nasm_parser_sections;
-/*@dependent@*/ section *nasm_parser_cur_section;
-
-extern /*@only@*/ char *nasm_parser_locallabel_base;
-
-static /*@dependent@*/ sectionhead *
-nasm_parser_do_parse(parser *p, FILE *f)
- /*@globals killed nasm_parser_locallabel_base @*/
-{
- p->current_pp->initialize(f);
- nasm_parser_in = f;
- nasm_parser_yyinput = p->current_pp->input;
-
- /* Initialize section list */
- nasm_parser_cur_section = sections_initialize(&nasm_parser_sections);
-
- /* yacc debugging, needs YYDEBUG set in bison.y.in to work */
- /* nasm_parser_debug = 1; */
-
- nasm_parser_parse();
-
- /* Free locallabel base if necessary */
- if (nasm_parser_locallabel_base)
- xfree(nasm_parser_locallabel_base);
-
- return &nasm_parser_sections;
-}
-
-/* Define valid preprocessors to use with this parser */
-/*@-nullassign@*/
-static preproc *nasm_parser_preprocs[] = {
- &raw_preproc,
- NULL
-};
-/*@=nullassign@*/
-
-/* Define parser structure -- see parser.h for details */
-parser nasm_parser = {
- "NASM-compatible parser",
- "nasm",
- nasm_parser_preprocs,
- &raw_preproc,
- nasm_parser_do_parse
-};
#include "arch.h"
-#include "bison.h"
+#include "nasm-bison.h"
#define YY_NEVER_INTERACTIVE 1
+++ /dev/null
-# $IdPath$
-
-SUBDIRS = raw
--- /dev/null
+# $IdPath$
+
+EXTRA_DIST += \
+ src/preprocs/raw/Makefile.inc
+
+YASMPREPROCFILES =
+include src/preprocs/raw/Makefile.inc
+yasm_SOURCES += $(YASMPREPROCFILES)
+++ /dev/null
-# $IdPath$
-
-noinst_LIBRARIES = libpreproc.a
-
-libpreproc_a_SOURCES = \
- preproc.c
-
-INCLUDES = \
- -I$(top_srcdir)/src \
- -I$(top_builddir)/intl
-
-CFLAGS = @ANSI_CFLAGS@
--- /dev/null
+# $IdPath$
+
+YASMPREPROCFILES += \
+ src/preprocs/raw/raw-preproc.c
+++ /dev/null
-/*
- * Raw preprocessor (preforms NO preprocessing)
- *
- * Copyright (C) 2001 Peter Johnson
- *
- * This file is part of YASM.
- *
- * YASM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * YASM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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"
-/*@unused@*/ RCSID("$IdPath$");
-
-#include "errwarn.h"
-
-#include "preproc.h"
-
-
-static int is_interactive;
-static FILE *in;
-
-int isatty(int);
-
-static void
-raw_preproc_initialize(FILE *f)
-{
- in = f;
- /*@-unrecog@*/
- is_interactive = f ? (isatty(fileno(f)) > 0) : 0;
- /*@=unrecog@*/
-}
-
-static size_t
-raw_preproc_input(char *buf, size_t max_size)
-{
- int c = '*';
- size_t n;
-
- if (is_interactive) {
- for (n = 0; n < max_size && (c = getc(in)) != EOF && c != '\n'; n++)
- buf[n] = (char)c;
- if (c == '\n')
- buf[n++] = (char)c;
- if (c == EOF && ferror(in))
- Error(_("error when reading from file"));
- } else if (((n = fread(buf, 1, max_size, in)) == 0) && ferror(in))
- Error(_("error when reading from file"));
-
- return n;
-}
-
-/* Define preproc structure -- see preproc.h for details */
-preproc raw_preproc = {
- "Disable preprocessing",
- "raw",
- raw_preproc_initialize,
- raw_preproc_input
-};
+++ /dev/null
-# $IdPath$
-
-SUBDIRS = arch parsers preprocs optimizers objfmts . tests
-
-INCLUDES = -I$(top_builddir)/intl
-
-bin_PROGRAMS = yasm
-
-yasm_SOURCES = \
- main.c \
- errwarn.c \
- errwarn.h
-
-yasm_LDADD = \
- libyasm.a \
- arch/@ARCH@/libarch.a \
- parsers/nasm/libparser.a \
- preprocs/raw/libpreproc.a \
- optimizers/basic/liboptimizer.a \
- objfmts/dbg/libobjfmt.a \
- libyasm.a \
- $(INTLLIBS)
-
-noinst_LIBRARIES = libyasm.a
-
-libyasm_a_SOURCES = \
- bytecode.c \
- bytecode.h \
- bc-int.h \
- expr.c \
- expr.h \
- expr-int.h \
- symrec.c \
- symrec.h \
- globals.c \
- globals.h \
- util.h \
- coretype.h \
- file.c \
- file.h \
- section.c \
- section.h \
- arch.c \
- arch.h \
- objfmt.c \
- objfmt.h \
- options.h \
- options.c \
- preproc.h \
- parser.c \
- parser.h \
- optimizer.h \
- intnum.c \
- intnum.h \
- floatnum.c \
- floatnum.h \
- hamt.c \
- hamt.h \
- bitvect.c \
- bitvect.h \
- valparam.c \
- valparam.h \
- xmalloc.c \
- xstrdup.c \
- strcasecmp.c
-
-libyasm_a_LIBADD = \
- @LIBOBJS@
-
-CFLAGS = @ANSI_CFLAGS@
-
-EXTRA_DIST = \
- strsep.c \
- mergesort.c \
- compat-queue.h \
- lclint.sh
+++ /dev/null
-# $IdPath$
-
-SUBDIRS = x86
+++ /dev/null
-# $IdPath$
-
-noinst_LIBRARIES = libarch.a
-
-libarch_a_SOURCES = \
- x86arch.h \
- x86-int.h \
- arch.c \
- bytecode.c \
- expr.c
-
-INCLUDES = \
- -I$(top_srcdir)/src \
- -I$(top_builddir)/intl
-
-CFLAGS = @ANSI_CFLAGS@
-
-EXTRA_DIST = \
- README \
- instrs.dat
+++ /dev/null
-/*
- * x86 architecture description
- *
- * Copyright (C) 2001 Peter Johnson
- *
- * This file is part of YASM.
- *
- * YASM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * YASM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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"
-/*@unused@*/ RCSID("$IdPath$");
-
-#include "bytecode.h"
-#include "arch.h"
-
-#include "x86-int.h"
-
-
-unsigned char x86_mode_bits = 0;
-
-/* Define arch structure -- see arch.h for details */
-arch x86_arch = {
- "x86 (IA-32, x86-64)",
- "x86",
- {
- X86_BYTECODE_TYPE_MAX,
- x86_bc_delete,
- x86_bc_print,
- x86_bc_calc_len
- }
-};
+++ /dev/null
-/*
- * x86 bytecode utility functions
- *
- * Copyright (C) 2001 Peter Johnson
- *
- * This file is part of YASM.
- *
- * YASM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * YASM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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"
-/*@unused@*/ RCSID("$IdPath$");
-
-#include "globals.h"
-#include "errwarn.h"
-#include "intnum.h"
-#include "expr.h"
-
-#include "bytecode.h"
-#include "arch.h"
-
-#include "x86-int.h"
-
-#include "bc-int.h"
-
-
-/*@-compmempass -mustfree@*/
-bytecode *
-x86_bc_new_insn(x86_new_insn_data *d)
-{
- bytecode *bc;
- x86_insn *insn;
-
- bc = bc_new_common((bytecode_type)X86_BC_INSN, sizeof(x86_insn));
- insn = bc_get_data(bc);
-
- insn->ea = d->ea;
- if (d->ea) {
- x86_effaddr_data *ead = ea_get_data(d->ea);
- ead->modrm &= 0xC7; /* zero spare/reg bits */
- ead->modrm |= (d->spare << 3) & 0x38; /* plug in provided bits */
- }
-
- insn->imm = d->imm;
- if (d->imm) {
- insn->imm->f_len = d->im_len;
- insn->imm->f_sign = d->im_sign;
- }
-
- insn->opcode[0] = d->op[0];
- insn->opcode[1] = d->op[1];
- insn->opcode[2] = d->op[2];
- insn->opcode_len = d->op_len;
-
- insn->addrsize = 0;
- insn->opersize = d->opersize;
- insn->lockrep_pre = 0;
- insn->shift_op = 0;
-
- insn->mode_bits = x86_mode_bits;
-
- return bc;
-}
-/*@=compmempass =mustfree@*/
-
-/*@-compmempass -mustfree@*/
-bytecode *
-x86_bc_new_jmprel(x86_new_jmprel_data *d)
-{
- bytecode *bc;
- x86_jmprel *jmprel;
-
- bc = bc_new_common((bytecode_type)X86_BC_JMPREL, sizeof(x86_jmprel));
- jmprel = bc_get_data(bc);
-
- jmprel->target = d->target->val;
- jmprel->op_sel = d->target->op_sel;
-
- if ((d->target->op_sel == JR_SHORT_FORCED) && (d->near_op_len == 0))
- Error(_("no SHORT form of that jump instruction exists"));
- if ((d->target->op_sel == JR_NEAR_FORCED) && (d->short_op_len == 0))
- Error(_("no NEAR form of that jump instruction exists"));
-
- jmprel->shortop.opcode[0] = d->short_op[0];
- jmprel->shortop.opcode[1] = d->short_op[1];
- jmprel->shortop.opcode[2] = d->short_op[2];
- jmprel->shortop.opcode_len = d->short_op_len;
-
- jmprel->nearop.opcode[0] = d->near_op[0];
- jmprel->nearop.opcode[1] = d->near_op[1];
- jmprel->nearop.opcode[2] = d->near_op[2];
- jmprel->nearop.opcode_len = d->near_op_len;
-
- jmprel->addrsize = d->addrsize;
- jmprel->opersize = 0;
- jmprel->lockrep_pre = 0;
-
- jmprel->mode_bits = x86_mode_bits;
-
- return bc;
-}
-/*@=compmempass =mustfree@*/
-
-void
-x86_ea_set_segment(effaddr *ea, unsigned char segment)
-{
- x86_effaddr_data *ead;
-
- if (!ea)
- return;
-
- ead = ea_get_data(ea);
-
- if (segment != 0 && ead->segment != 0)
- Warning(_("multiple segment overrides, using leftmost"));
-
- ead->segment = segment;
-}
-
-effaddr *
-x86_ea_new_reg(unsigned char reg)
-{
- effaddr *ea = xmalloc(sizeof(effaddr)+sizeof(x86_effaddr_data));
- x86_effaddr_data *ead = ea_get_data(ea);
-
- ea->disp = (expr *)NULL;
- ea->len = 0;
- ea->nosplit = 0;
- ead->segment = 0;
- ead->modrm = 0xC0 | (reg & 0x07); /* Mod=11, R/M=Reg, Reg=0 */
- ead->valid_modrm = 1;
- ead->need_modrm = 1;
- ead->valid_sib = 0;
- ead->need_sib = 0;
-
- return ea;
-}
-
-effaddr *
-x86_ea_new_expr(expr *e)
-{
- effaddr *ea = xmalloc(sizeof(effaddr)+sizeof(x86_effaddr_data));
- x86_effaddr_data *ead = ea_get_data(ea);
-
- ea->disp = e;
- ea->len = 0;
- ea->nosplit = 0;
- ead->segment = 0;
- ead->modrm = 0;
- ead->valid_modrm = 0;
- ead->need_modrm = 1;
- ead->valid_sib = 0;
- ead->need_sib = 0xff; /* we won't know until we know more about expr and
- the BITS/address override setting */
-
- return ea;
-}
-
-/*@-compmempass@*/
-effaddr *
-x86_ea_new_imm(immval *imm, unsigned char im_len)
-{
- effaddr *ea = xmalloc(sizeof(effaddr)+sizeof(x86_effaddr_data));
- x86_effaddr_data *ead = ea_get_data(ea);
-
- ea->disp = imm->val;
- ea->len = im_len;
- ea->nosplit = 0;
- ead->segment = 0;
- ead->modrm = 0;
- ead->valid_modrm = 0;
- ead->need_modrm = 0;
- ead->valid_sib = 0;
- ead->need_sib = 0;
-
- return ea;
-}
-/*@=compmempass@*/
-
-effaddr *
-x86_bc_insn_get_ea(bytecode *bc)
-{
- x86_insn *insn = bc_get_data(bc);
-
- if (!bc)
- return NULL;
-
- if ((x86_bytecode_type)bc->type != X86_BC_INSN)
- InternalError(_("Trying to get EA of non-instruction"));
-
- return insn->ea;
-}
-
-void
-x86_bc_insn_opersize_override(bytecode *bc, unsigned char opersize)
-{
- x86_insn *insn;
- x86_jmprel *jmprel;
-
- if (!bc)
- return;
-
- switch ((x86_bytecode_type)bc->type) {
- case X86_BC_INSN:
- insn = bc_get_data(bc);
- insn->opersize = opersize;
- break;
- case X86_BC_JMPREL:
- jmprel = bc_get_data(bc);
- jmprel->opersize = opersize;
- break;
- default:
- InternalError(_("OperSize override applied to non-instruction"));
- }
-}
-
-void
-x86_bc_insn_addrsize_override(bytecode *bc, unsigned char addrsize)
-{
- x86_insn *insn;
- x86_jmprel *jmprel;
-
- if (!bc)
- return;
-
- switch ((x86_bytecode_type)bc->type) {
- case X86_BC_INSN:
- insn = bc_get_data(bc);
- insn->addrsize = addrsize;
- break;
- case X86_BC_JMPREL:
- jmprel = bc_get_data(bc);
- jmprel->addrsize = addrsize;
- break;
- default:
- InternalError(_("AddrSize override applied to non-instruction"));
- }
-}
-
-void
-x86_bc_insn_set_lockrep_prefix(bytecode *bc, unsigned char prefix)
-{
- x86_insn *insn;
- x86_jmprel *jmprel;
- unsigned char *lockrep_pre = (unsigned char *)NULL;
-
- if (!bc)
- return;
-
- switch ((x86_bytecode_type)bc->type) {
- case X86_BC_INSN:
- insn = bc_get_data(bc);
- lockrep_pre = &insn->lockrep_pre;
- break;
- case X86_BC_JMPREL:
- jmprel = bc_get_data(bc);
- lockrep_pre = &jmprel->lockrep_pre;
- break;
- default:
- InternalError(_("LockRep prefix applied to non-instruction"));
- }
-
- if (*lockrep_pre != 0)
- Warning(_("multiple LOCK or REP prefixes, using leftmost"));
-
- *lockrep_pre = prefix;
-}
-
-void
-x86_bc_insn_set_shift_flag(bytecode *bc)
-{
- x86_insn *insn;
-
- if (!bc)
- return;
-
- if ((x86_bytecode_type)bc->type != X86_BC_INSN)
- InternalError(_("Attempted to set shift flag on non-instruction"));
-
- insn = bc_get_data(bc);
-
- insn->shift_op = 1;
-}
-
-void
-x86_set_jmprel_opcode_sel(x86_jmprel_opcode_sel *old_sel,
- x86_jmprel_opcode_sel new_sel)
-{
- if (!old_sel)
- return;
-
- if (new_sel != JR_NONE && ((*old_sel == JR_SHORT_FORCED) ||
- (*old_sel == JR_NEAR_FORCED)))
- Warning(_("multiple SHORT or NEAR specifiers, using leftmost"));
- *old_sel = new_sel;
-}
-
-void
-x86_bc_delete(bytecode *bc)
-{
- x86_insn *insn;
- x86_jmprel *jmprel;
-
- switch ((x86_bytecode_type)bc->type) {
- case X86_BC_INSN:
- insn = bc_get_data(bc);
- if (insn->ea) {
- expr_delete(insn->ea->disp);
- xfree(insn->ea);
- }
- if (insn->imm) {
- expr_delete(insn->imm->val);
- xfree(insn->imm);
- }
- break;
- case X86_BC_JMPREL:
- jmprel = bc_get_data(bc);
- expr_delete(jmprel->target);
- break;
- }
-}
-
-void
-x86_bc_print(FILE *f, const bytecode *bc)
-{
- const x86_insn *insn;
- const x86_jmprel *jmprel;
- x86_effaddr_data *ead;
-
- switch ((x86_bytecode_type)bc->type) {
- case X86_BC_INSN:
- insn = bc_get_const_data(bc);
- fprintf(f, "%*s_Instruction_\n", indent_level, "");
- fprintf(f, "%*sEffective Address:", indent_level, "");
- if (!insn->ea)
- fprintf(f, " (nil)\n");
- else {
- indent_level++;
- fprintf(f, "\n%*sDisp=", indent_level, "");
- expr_print(f, insn->ea->disp);
- fprintf(f, "\n");
- ead = ea_get_data(insn->ea);
- fprintf(f, "%*sLen=%u SegmentOv=%02x NoSplit=%u\n",
- indent_level, "", (unsigned int)insn->ea->len,
- (unsigned int)ead->segment,
- (unsigned int)insn->ea->nosplit);
- fprintf(f, "%*sModRM=%03o ValidRM=%u NeedRM=%u\n",
- indent_level, "", (unsigned int)ead->modrm,
- (unsigned int)ead->valid_modrm,
- (unsigned int)ead->need_modrm);
- fprintf(f, "%*sSIB=%03o ValidSIB=%u NeedSIB=%u\n",
- indent_level, "", (unsigned int)ead->sib,
- (unsigned int)ead->valid_sib,
- (unsigned int)ead->need_sib);
- indent_level--;
- }
- fprintf(f, "%*sImmediate Value:", indent_level, "");
- if (!insn->imm)
- fprintf(f, " (nil)\n");
- else {
- indent_level++;
- fprintf(f, "\n%*sVal=", indent_level, "");
- if (insn->imm->val)
- expr_print(f, insn->imm->val);
- else
- fprintf(f, "(nil-SHOULDN'T HAPPEN)");
- fprintf(f, "\n");
- fprintf(f, "%*sLen=%u, IsNeg=%u\n", indent_level, "",
- (unsigned int)insn->imm->len,
- (unsigned int)insn->imm->isneg);
- fprintf(f, "%*sFLen=%u, FSign=%u\n", indent_level, "",
- (unsigned int)insn->imm->f_len,
- (unsigned int)insn->imm->f_sign);
- indent_level--;
- }
- fprintf(f, "%*sOpcode: %02x %02x %02x OpLen=%u\n", indent_level,
- "", (unsigned int)insn->opcode[0],
- (unsigned int)insn->opcode[1],
- (unsigned int)insn->opcode[2],
- (unsigned int)insn->opcode_len);
- fprintf(f,
- "%*sAddrSize=%u OperSize=%u LockRepPre=%02x ShiftOp=%u\n",
- indent_level, "",
- (unsigned int)insn->addrsize,
- (unsigned int)insn->opersize,
- (unsigned int)insn->lockrep_pre,
- (unsigned int)insn->shift_op);
- fprintf(f, "%*sBITS=%u\n", indent_level, "",
- (unsigned int)insn->mode_bits);
- break;
- case X86_BC_JMPREL:
- jmprel = bc_get_const_data(bc);
- fprintf(f, "%*s_Relative Jump_\n", indent_level, "");
- fprintf(f, "%*sTarget=", indent_level, "");
- expr_print(f, jmprel->target);
- fprintf(f, "\n%*sShort Form:\n", indent_level, "");
- indent_level++;
- if (jmprel->shortop.opcode_len == 0)
- fprintf(f, "%*sNone\n", indent_level, "");
- else
- fprintf(f, "%*sOpcode: %02x %02x %02x OpLen=%u\n",
- indent_level, "",
- (unsigned int)jmprel->shortop.opcode[0],
- (unsigned int)jmprel->shortop.opcode[1],
- (unsigned int)jmprel->shortop.opcode[2],
- (unsigned int)jmprel->shortop.opcode_len);
- indent_level--;
- fprintf(f, "%*sNear Form:\n", indent_level, "");
- indent_level++;
- if (jmprel->nearop.opcode_len == 0)
- fprintf(f, "%*sNone\n", indent_level, "");
- else
- fprintf(f, "%*sOpcode: %02x %02x %02x OpLen=%u\n",
- indent_level, "",
- (unsigned int)jmprel->nearop.opcode[0],
- (unsigned int)jmprel->nearop.opcode[1],
- (unsigned int)jmprel->nearop.opcode[2],
- (unsigned int)jmprel->nearop.opcode_len);
- indent_level--;
- fprintf(f, "%*sOpSel=", indent_level, "");
- switch (jmprel->op_sel) {
- case JR_NONE:
- fprintf(f, "None");
- break;
- case JR_SHORT:
- fprintf(f, "Short");
- break;
- case JR_NEAR:
- fprintf(f, "Near");
- break;
- case JR_SHORT_FORCED:
- fprintf(f, "Forced Short");
- break;
- case JR_NEAR_FORCED:
- fprintf(f, "Forced Near");
- break;
- default:
- fprintf(f, "UNKNOWN!!");
- break;
- }
- fprintf(f, "\n%*sAddrSize=%u OperSize=%u LockRepPre=%02x\n",
- indent_level, "",
- (unsigned int)jmprel->addrsize,
- (unsigned int)jmprel->opersize,
- (unsigned int)jmprel->lockrep_pre);
- fprintf(f, "%*sBITS=%u\n", indent_level, "",
- (unsigned int)jmprel->mode_bits);
- break;
- }
-}
-
-static int
-x86_bc_calc_len_insn(x86_insn *insn, /*@only@*/ /*@null@*/
- intnum *(*resolve_label) (section *sect,
- /*@null@*/ bytecode *bc))
-{
- effaddr *ea = insn->ea;
- x86_effaddr_data *ead = ea_get_data(ea);
- immval *imm = insn->imm;
-
- if (ea) {
- if ((ea->disp) && ((!ead->valid_sib && ead->need_sib) ||
- (!ead->valid_modrm && ead->need_modrm))) {
- /* First expand equ's */
- expr_expand_equ(ea->disp);
-
- /* Check validity of effective address and calc R/M bits of
- * Mod/RM byte and SIB byte. We won't know the Mod field
- * of the Mod/RM byte until we know more about the
- * displacement.
- */
- if (!x86_expr_checkea(&ea->disp, &insn->addrsize, insn->mode_bits,
- ea->nosplit, &ea->len, &ead->modrm,
- &ead->valid_modrm, &ead->need_modrm,
- &ead->sib, &ead->valid_sib, &ead->need_sib))
- return 0; /* failed, don't bother checking rest of insn */
- }
- }
-
- if (imm) {
- const intnum *num;
-
- if (imm->val) {
- expr_expand_equ(imm->val);
- imm->val = expr_simplify(imm->val);
- }
- /* TODO: check imm f_len vs. len? */
-
- /* Handle shift_op special-casing */
- /*@-nullstate@*/
- if (insn->shift_op && (num = expr_get_intnum(&imm->val))) {
- /*@=nullstate@*/
- if (num) {
- if (intnum_get_uint(num) == 1) {
- /* Use ,1 form: first copy ,1 opcode. */
- insn->opcode[0] = insn->opcode[1];
- /* Delete Imm, as it's not needed */
- expr_delete(imm->val);
- xfree(imm);
- insn->imm = (immval *)NULL;
- }
- insn->shift_op = 0;
- }
- }
- }
-
- return 0;
-}
-
-int
-x86_bc_calc_len(bytecode *bc,
- intnum *(*resolve_label) (section *sect,
- /*@null@*/ bytecode *bc))
-{
- x86_insn *insn;
-
- switch ((x86_bytecode_type)bc->type) {
- case X86_BC_INSN:
- insn = bc_get_data(bc);
- return x86_bc_calc_len_insn(insn, resolve_label);
- default:
- break;
- }
- return 0;
-}
-
+++ /dev/null
-/*
- * x86 expression handling
- *
- * Copyright (C) 2001 Peter Johnson
- *
- * This file is part of YASM.
- *
- * YASM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * YASM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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"
-/*@unused@*/ RCSID("$IdPath$");
-
-#include "bitvect.h"
-
-#include "globals.h"
-#include "errwarn.h"
-#include "intnum.h"
-#include "floatnum.h"
-#include "expr.h"
-
-#include "bytecode.h"
-#include "arch.h"
-
-#include "x86-int.h"
-
-#include "expr-int.h"
-
-
-/* Only works if ei->type == EXPR_REG (doesn't check).
- * Overwrites ei with intnum of 0 (to eliminate regs from the final expr).
- */
-static /*@null@*/ /*@dependent@*/ int *
-x86_expr_checkea_get_reg32(ExprItem *ei, /*returned*/ void *d)
-{
- int *data = d;
- int *ret;
-
- /* don't allow 16-bit registers */
- if (ei->data.reg.size != 32)
- return 0;
-
- ret = &data[ei->data.reg.num & 7]; /* & 7 for sanity check */
-
- /* overwrite with 0 to eliminate register from displacement expr */
- ei->type = EXPR_INT;
- ei->data.intn = intnum_new_int(0);
-
- /* we're okay */
- return ret;
-}
-
-typedef struct x86_checkea_reg16_data {
- int bx, si, di, bp; /* total multiplier for each reg */
-} x86_checkea_reg16_data;
-
-/* Only works if ei->type == EXPR_REG (doesn't check).
- * Overwrites ei with intnum of 0 (to eliminate regs from the final expr).
- */
-static /*@null@*/ int *
-x86_expr_checkea_get_reg16(ExprItem *ei, void *d)
-{
- x86_checkea_reg16_data *data = d;
- /* in order: ax,cx,dx,bx,sp,bp,si,di */
- /*@-nullassign@*/
- static int *reg16[8] = {0,0,0,0,0,0,0,0};
- /*@=nullassign@*/
- int *ret;
-
- reg16[3] = &data->bx;
- reg16[5] = &data->bp;
- reg16[6] = &data->si;
- reg16[7] = &data->di;
-
- /* don't allow 32-bit registers */
- if (ei->data.reg.size != 16)
- return 0;
-
- ret = reg16[ei->data.reg.num & 7]; /* & 7 for sanity check */
-
- /* only allow BX, SI, DI, BP */
- if (!ret)
- return 0;
-
- /* overwrite with 0 to eliminate register from displacement expr */
- ei->type = EXPR_INT;
- ei->data.intn = intnum_new_int(0);
-
- /* we're okay */
- return ret;
-}
-
-/* Distribute over registers to help bring them to the topmost level of e.
- * Also check for illegal operations against registers.
- * Returns 0 if something was illegal, 1 if legal and nothing in e changed,
- * and 2 if legal and e needs to be simplified.
- *
- * Only half joking: Someday make this/checkea able to accept crazy things
- * like: (bx+di)*(bx+di)-bx*bx-2*bx*di-di*di+di? Probably not: NASM never
- * accepted such things, and it's doubtful such an expn is valid anyway
- * (even though the above one is). But even macros would be hard-pressed
- * to generate something like this.
- *
- * e must already have been simplified for this function to work properly
- * (as it doesn't think things like SUB are valid).
- *
- * IMPLEMENTATION NOTE: About the only thing this function really needs to
- * "distribute" is: (non-float-expn or intnum) * (sum expn of registers).
- *
- * TODO: Clean up this code, make it easier to understand.
- */
-static int
-x86_expr_checkea_distcheck_reg(expr **ep)
-{
- expr *e = *ep;
- int i;
- int havereg = -1, havereg_expr = -1;
- int retval = 1; /* default to legal, no changes */
-
- for (i=0; i<e->numterms; i++) {
- switch (e->terms[i].type) {
- case EXPR_REG:
- /* Check op to make sure it's valid to use w/register. */
- if (e->op != EXPR_ADD && e->op != EXPR_MUL &&
- e->op != EXPR_IDENT)
- return 0;
- /* Check for reg*reg */
- if (e->op == EXPR_MUL && havereg != -1)
- return 0;
- havereg = i;
- break;
- case EXPR_FLOAT:
- /* Floats not allowed. */
- return 0;
- case EXPR_EXPR:
- if (expr_contains(e->terms[i].data.expn, EXPR_REG)) {
- int ret2;
-
- /* Check op to make sure it's valid to use w/register. */
- if (e->op != EXPR_ADD && e->op != EXPR_MUL)
- return 0;
- /* Check for reg*reg */
- if (e->op == EXPR_MUL && havereg != -1)
- return 0;
- havereg = i;
- havereg_expr = i;
- /* Recurse to check lower levels */
- ret2 =
- x86_expr_checkea_distcheck_reg(&e->terms[i].data.expn);
- if (ret2 == 0)
- return 0;
- if (ret2 == 2)
- retval = 2;
- } else if (expr_contains(e->terms[i].data.expn, EXPR_FLOAT))
- return 0; /* Disallow floats */
- break;
- default:
- break;
- }
- }
-
- /* just exit if no registers were used */
- if (havereg == -1)
- return retval;
-
- /* Distribute */
- if (e->op == EXPR_MUL && havereg_expr != -1) {
- expr *ne;
-
- retval = 2; /* we're going to change it */
-
- /* The reg expn *must* be EXPR_ADD at this point. Sanity check. */
- if (e->terms[havereg_expr].type != EXPR_EXPR ||
- e->terms[havereg_expr].data.expn->op != EXPR_ADD)
- InternalError(_("Register expression not ADD or EXPN"));
-
- /* Iterate over each term in reg expn */
- for (i=0; i<e->terms[havereg_expr].data.expn->numterms; i++) {
- /* Copy everything EXCEPT havereg_expr term into new expression */
- ne = expr_copy_except(e, havereg_expr);
- assert(ne != NULL);
- /* Copy reg expr term into uncopied (empty) term in new expn */
- ne->terms[havereg_expr] =
- e->terms[havereg_expr].data.expn->terms[i]; /* struct copy */
- /* Overwrite old reg expr term with new expn */
- e->terms[havereg_expr].data.expn->terms[i].type = EXPR_EXPR;
- e->terms[havereg_expr].data.expn->terms[i].data.expn = ne;
- }
-
- /* Replace e with expanded reg expn */
- ne = e->terms[havereg_expr].data.expn;
- e->terms[havereg_expr].type = EXPR_NONE; /* don't delete it! */
- expr_delete(e); /* but everything else */
- e = ne;
- /*@-onlytrans@*/
- *ep = ne;
- /*@=onlytrans@*/
- }
-
- return retval;
-}
-
-/* Simplify and determine if expression is superficially valid:
- * Valid expr should be [(int-equiv expn)]+[reg*(int-equiv expn)+...]
- * where the [...] parts are optional.
- *
- * Don't simplify out constant identities if we're looking for an indexreg: we
- * may need the multiplier for determining what the indexreg is!
- *
- * Returns 0 if invalid register usage, 1 if unable to determine all values,
- * and 2 if all values successfully determined and saved in data.
- */
-static int
-x86_expr_checkea_getregusage(expr **ep, /*@null@*/ int *indexreg, void *data,
- int *(*get_reg)(ExprItem *ei, void *d))
-{
- int i;
- int *reg;
- expr *e;
-
- /*@-unqualifiedtrans@*/
- *ep = expr_xform_neg_tree(*ep);
- *ep = expr_level_tree(*ep, 1, indexreg == 0);
- /*@=unqualifiedtrans@*/
- assert(*ep != NULL);
- e = *ep;
- switch (x86_expr_checkea_distcheck_reg(ep)) {
- case 0:
- return 0;
- case 2:
- /* Need to simplify again */
- *ep = expr_xform_neg_tree(*ep);
- *ep = expr_level_tree(*ep, 1, indexreg == 0);
- e = *ep;
- break;
- default:
- break;
- }
-
- switch (e->op) {
- case EXPR_ADD:
- /* Prescan for non-int multipliers.
- * This is because if any of the terms is a more complex
- * expr (eg, undetermined value), we don't want to try to
- * figure out *any* of the expression, because each register
- * lookup overwrites the register with a 0 value! And storing
- * the state of this routine from one excution to the next
- * would be a major chore.
- */
- for (i=0; i<e->numterms; i++)
- if (e->terms[i].type == EXPR_EXPR) {
- if (e->terms[i].data.expn->numterms > 2)
- return 1;
- expr_order_terms(e->terms[i].data.expn);
- if (e->terms[i].data.expn->terms[1].type != EXPR_INT)
- return 1;
- }
-
- /*@fallthrough@*/
- case EXPR_IDENT:
- /* Check each term for register (and possible multiplier). */
- for (i=0; i<e->numterms; i++) {
- if (e->terms[i].type == EXPR_REG) {
- reg = get_reg(&e->terms[i], data);
- if (!reg)
- return 0;
- (*reg)++;
- if (indexreg)
- *indexreg = reg-(int *)data;
- } else if (e->terms[i].type == EXPR_EXPR) {
- /* Already ordered from ADD above, just grab the value.
- * Sanity check for EXPR_INT.
- */
- if (e->terms[i].data.expn->terms[0].type != EXPR_REG)
- InternalError(_("Register not found in reg expn"));
- if (e->terms[i].data.expn->terms[1].type != EXPR_INT)
- InternalError(_("Non-integer value in reg expn"));
- reg = get_reg(&e->terms[i].data.expn->terms[0], data);
- if (!reg)
- return 0;
- (*reg) +=
- intnum_get_int(e->terms[i].data.expn->terms[1].data.intn);
- if (indexreg)
- *indexreg = reg-(int *)data;
- }
- }
- break;
- case EXPR_MUL:
- /* Here, too, check for non-int multipliers. */
- if (e->numterms > 2)
- return 1;
- expr_order_terms(e);
- if (e->terms[1].type != EXPR_INT)
- return 1;
- reg = get_reg(&e->terms[0], data);
- if (!reg)
- return 0;
- (*reg) += intnum_get_int(e->terms[1].data.intn);
- if (indexreg)
- *indexreg = reg-(int *)data;
- break;
- default:
- /* Should never get here! */
- break;
- }
-
- /* Simplify expr, which is now really just the displacement. This
- * should get rid of the 0's we put in for registers in the callback.
- */
- *ep = expr_simplify(*ep);
- /* e = *ep; */
-
- return 2;
-}
-
-/* Calculate the displacement length, if possible.
- * Takes several extra inputs so it can be used by both 32-bit and 16-bit
- * expressions:
- * wordsize=2 for 16-bit, =4 for 32-bit.
- * noreg=1 if the *ModRM byte* has no registers used.
- * isbpreg=1 if BP/EBP is the *only* register used within the *ModRM byte*.
- */
-/*@-nullstate@*/
-static int
-x86_checkea_calc_displen(expr **ep, unsigned int wordsize, int noreg,
- int isbpreg, unsigned char *displen,
- unsigned char *modrm, unsigned char *v_modrm)
-{
- expr *e = *ep;
- const intnum *intn;
- long dispval;
-
- *v_modrm = 0; /* default to not yet valid */
-
- switch (*displen) {
- case 0:
- /* the displacement length hasn't been forced, try to
- * determine what it is.
- */
- if (noreg) {
- /* no register in ModRM expression, so it must be disp16/32,
- * and as the Mod bits are set to 0 by the caller, we're done
- * with the ModRM byte.
- */
- *displen = wordsize;
- *v_modrm = 1;
- } else if (isbpreg) {
- /* for BP/EBP, there *must* be a displacement value, but we
- * may not know the size (8 or 16/32) for sure right now.
- * We can't leave displen at 0, because that just means
- * unknown displacement, including none.
- */
- *displen = 0xff;
- }
-
- intn = expr_get_intnum(ep);
- if (!intn)
- break; /* expr still has unknown values */
-
- /* make sure the displacement will fit in 16/32 bits if unsigned,
- * and 8 bits if signed.
- */
- if (!intnum_check_size(intn, (size_t)wordsize, 0) &&
- !intnum_check_size(intn, 1, 1)) {
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- }
-
- /* don't try to find out what size displacement we have if
- * displen is known.
- */
- if (*displen != 0 && *displen != 0xff)
- break;
-
- /* Don't worry about overflows here (it's already guaranteed
- * to be 16/32 or 8 bits).
- */
- dispval = intnum_get_int(intn);
-
- /* Figure out what size displacement we will have. */
- if (*displen != 0xff && dispval == 0) {
- /* if we know that the displacement is 0 right now,
- * go ahead and delete the expr (making it so no
- * displacement value is included in the output).
- * The Mod bits of ModRM are set to 0 above, and
- * we're done with the ModRM byte!
- *
- * Don't do this if we came from isbpreg check above, so
- * check *displen.
- */
- expr_delete(e);
- *ep = (expr *)NULL;
- } else if (dispval >= -128 && dispval <= 127) {
- /* It fits into a signed byte */
- *displen = 1;
- *modrm |= 0100;
- } else {
- /* It's a 16/32-bit displacement */
- *displen = wordsize;
- *modrm |= 0200;
- }
- *v_modrm = 1; /* We're done with ModRM */
-
- break;
-
- /* If not 0, the displacement length was forced; set the Mod bits
- * appropriately and we're done with the ModRM byte. We assume
- * that the user knows what they're doing if they do an explicit
- * override, so we don't check for overflow (we'll just truncate
- * when we output).
- */
- case 1:
- /* TODO: Add optional warning here about byte not being valid
- * override in noreg case.
- */
- if (!noreg)
- *modrm |= 0100;
- *v_modrm = 1;
- break;
- case 2:
- case 4:
- if (wordsize != *displen) {
- ErrorAt(e->filename, e->line,
- _("invalid effective address (displacement size)"));
- return 0;
- }
- /* TODO: Add optional warning here about 2/4 not being valid
- * override in noreg case.
- */
- if (!noreg)
- *modrm |= 0200;
- *v_modrm = 1;
- break;
- default:
- /* we shouldn't ever get any other size! */
- InternalError(_("strange EA displacement size"));
- }
-
- return 1;
-}
-/*@=nullstate@*/
-
-static int
-x86_expr_checkea_getregsize_callback(ExprItem *ei, void *d)
-{
- unsigned char *addrsize = (unsigned char *)d;
-
- if (ei->type == EXPR_REG) {
- *addrsize = ei->data.reg.size;
- return 1;
- } else
- return 0;
-}
-
-int
-x86_expr_checkea(expr **ep, unsigned char *addrsize, unsigned char bits,
- unsigned char nosplit, unsigned char *displen,
- unsigned char *modrm, unsigned char *v_modrm,
- unsigned char *n_modrm, unsigned char *sib,
- unsigned char *v_sib, unsigned char *n_sib)
-{
- expr *e = *ep;
-
- if (*addrsize == 0) {
- /* we need to figure out the address size from what we know about:
- * - the displacement length
- * - what registers are used in the expression
- * - the bits setting
- */
- switch (*displen) {
- case 4:
- /* must be 32-bit */
- *addrsize = 32;
- break;
- case 2:
- /* must be 16-bit */
- *addrsize = 16;
- break;
- default:
- /* check for use of 16 or 32-bit registers; if none are used
- * default to bits setting.
- */
- if (!expr_traverse_leaves_in(e, addrsize,
- x86_expr_checkea_getregsize_callback))
- *addrsize = bits;
- /* TODO: Add optional warning here if switched address size
- * from bits setting just by register use.. eg [ax] in
- * 32-bit mode would generate a warning.
- */
- }
- }
-
- if (*addrsize == 32 && ((*n_modrm && !*v_modrm) || (*n_sib && !*v_sib))) {
- int i;
- typedef enum {
- REG32_NONE = -1,
- REG32_EAX = 0,
- REG32_ECX = 1,
- REG32_EDX = 2,
- REG32_EBX = 3,
- REG32_ESP = 4,
- REG32_EBP = 5,
- REG32_ESI = 6,
- REG32_EDI = 7
- } reg32type;
- int reg32mult[8] = {0, 0, 0, 0, 0, 0, 0, 0};
- int basereg = REG32_NONE; /* "base" register (for SIB) */
- int indexreg = REG32_NONE; /* "index" register (for SIB) */
-
- switch (x86_expr_checkea_getregusage(ep, &indexreg, reg32mult,
- x86_expr_checkea_get_reg32)) {
- case 0:
- e = *ep;
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- case 1:
- return 1;
- default:
- e = *ep;
- break;
- }
-
- /* If indexreg mult is 0, discard it.
- * This is possible because of the way indexreg is found in
- * expr_checkea_getregusage().
- */
- if (indexreg != REG32_NONE && reg32mult[indexreg] == 0)
- indexreg = REG32_NONE;
-
- /* Find a basereg (*1, but not indexreg), if there is one.
- * Also, if an indexreg hasn't been assigned, try to find one.
- * Meanwhile, check to make sure there's no negative register mults.
- */
- for (i=0; i<8; i++) {
- if (reg32mult[i] < 0) {
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- }
- if (i != indexreg && reg32mult[i] == 1)
- basereg = i;
- else if (indexreg == REG32_NONE && reg32mult[i] > 0)
- indexreg = i;
- }
-
- /* Handle certain special cases of indexreg mults when basereg is
- * empty.
- */
- if (indexreg != REG32_NONE && basereg == REG32_NONE)
- switch (reg32mult[indexreg]) {
- case 1:
- /* Only optimize this way if nosplit wasn't specified */
- if (!nosplit) {
- basereg = indexreg;
- indexreg = -1;
- }
- break;
- case 2:
- /* Only split if nosplit wasn't specified */
- if (!nosplit) {
- basereg = indexreg;
- reg32mult[indexreg] = 1;
- }
- break;
- case 3:
- case 5:
- case 9:
- basereg = indexreg;
- reg32mult[indexreg]--;
- break;
- }
-
- /* Make sure there's no other registers than the basereg and indexreg
- * we just found.
- */
- for (i=0; i<8; i++)
- if (i != basereg && i != indexreg && reg32mult[i] != 0) {
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- }
-
- /* Check the index multiplier value for validity if present. */
- if (indexreg != REG32_NONE && reg32mult[indexreg] != 1 &&
- reg32mult[indexreg] != 2 && reg32mult[indexreg] != 4 &&
- reg32mult[indexreg] != 8) {
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- }
-
- /* ESP is not a legal indexreg. */
- if (indexreg == REG32_ESP) {
- /* If mult>1 or basereg is ESP also, there's no way to make it
- * legal.
- */
- if (reg32mult[REG32_ESP] > 1 || basereg == REG32_ESP) {
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- }
- /* If mult==1 and basereg is not ESP, swap indexreg w/basereg. */
- indexreg = basereg;
- basereg = REG32_ESP;
- }
-
- /* At this point, we know the base and index registers and that the
- * memory expression is (essentially) valid. Now build the ModRM and
- * (optional) SIB bytes.
- */
-
- /* First determine R/M (Mod is later determined from disp size) */
- *n_modrm = 1; /* we always need ModRM */
- if (basereg == REG32_NONE) {
- /* disp32[index] */
- *modrm |= 5;
- /* we must have a SIB */
- *n_sib = 1;
- } else if (indexreg == REG32_NONE) {
- /* basereg only */
- *modrm |= basereg;
- /* we don't need an SIB *unless* basereg is ESP */
- if (basereg == REG32_ESP)
- *n_sib = 1;
- else {
- *sib = 0;
- *v_sib = 0;
- *n_sib = 0;
- }
- } else {
- /* both base AND index */
- *modrm |= 4;
- *n_sib = 1;
- }
-
- /* Determine SIB if needed */
- if (*n_sib == 1) {
- *sib = 0; /* start with 0 */
-
- /* Special case: no basereg (only happens in disp32[index] case) */
- if (basereg == REG32_NONE)
- *sib |= 5;
- else
- *sib |= basereg & 7; /* &7 to sanity check */
-
- /* Put in indexreg, checking for none case */
- if (indexreg == REG32_NONE)
- *sib |= 040;
- /* Any scale field is valid, just leave at 0. */
- else {
- *sib |= ((unsigned int)indexreg & 7) << 3;
- /* Set scale field, 1 case -> 0, so don't bother. */
- switch (reg32mult[indexreg]) {
- case 2:
- *sib |= 0100;
- break;
- case 4:
- *sib |= 0200;
- break;
- case 8:
- *sib |= 0300;
- break;
- }
- }
-
- *v_sib = 1; /* Done with SIB */
- }
-
- /* Calculate displacement length (if possible) */
- return x86_checkea_calc_displen(ep, 4, basereg == REG32_NONE,
- basereg == REG32_EBP &&
- indexreg == REG32_NONE, displen,
- modrm, v_modrm);
- } else if (*addrsize == 16 && *n_modrm && !*v_modrm) {
- static const unsigned char modrm16[16] = {
- 0006 /* disp16 */, 0007 /* [BX] */, 0004 /* [SI] */,
- 0000 /* [BX+SI] */, 0005 /* [DI] */, 0001 /* [BX+DI] */,
- 0377 /* invalid */, 0377 /* invalid */, 0006 /* [BP]+d */,
- 0377 /* invalid */, 0002 /* [BP+SI] */, 0377 /* invalid */,
- 0003 /* [BP+DI] */, 0377 /* invalid */, 0377 /* invalid */,
- 0377 /* invalid */
- };
- x86_checkea_reg16_data reg16mult = {0, 0, 0, 0};
- enum {
- HAVE_NONE = 0,
- HAVE_BX = 1<<0,
- HAVE_SI = 1<<1,
- HAVE_DI = 1<<2,
- HAVE_BP = 1<<3
- } havereg = HAVE_NONE;
-
- /* 16-bit cannot have SIB */
- *sib = 0;
- *v_sib = 0;
- *n_sib = 0;
-
- switch (x86_expr_checkea_getregusage(ep, (int *)NULL, ®16mult,
- x86_expr_checkea_get_reg16)) {
- case 0:
- e = *ep;
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- case 1:
- return 1;
- default:
- e = *ep;
- break;
- }
-
- /* reg multipliers not 0 or 1 are illegal. */
- if (reg16mult.bx & ~1 || reg16mult.si & ~1 || reg16mult.di & ~1 ||
- reg16mult.bp & ~1) {
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- }
-
- /* Set havereg appropriately */
- if (reg16mult.bx > 0)
- havereg |= HAVE_BX;
- if (reg16mult.si > 0)
- havereg |= HAVE_SI;
- if (reg16mult.di > 0)
- havereg |= HAVE_DI;
- if (reg16mult.bp > 0)
- havereg |= HAVE_BP;
-
- /* Check the modrm value for invalid combinations. */
- if (modrm16[havereg] & 0070) {
- ErrorAt(e->filename, e->line, _("invalid effective address"));
- return 0;
- }
-
- /* Set ModRM byte for registers */
- *modrm |= modrm16[havereg];
-
- /* Calculate displacement length (if possible) */
- return x86_checkea_calc_displen(ep, 2, havereg == HAVE_NONE,
- havereg == HAVE_BP, displen, modrm,
- v_modrm);
- }
- return 1;
-}
+++ /dev/null
-# $IdPath$
-
-SUBDIRS = dbg
+++ /dev/null
-# $IdPath$
-
-noinst_LIBRARIES = libobjfmt.a
-
-libobjfmt_a_SOURCES = \
- objfmt.c
-
-INCLUDES = \
- -I$(top_srcdir)/src \
- -I$(top_builddir)/intl
-
-CFLAGS = @ANSI_CFLAGS@
+++ /dev/null
-/*
- * Debugging object format (used to debug object format module interface)
- *
- * Copyright (C) 2001 Peter Johnson
- *
- * This file is part of YASM.
- *
- * YASM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * YASM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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"
-/*@unused@*/ RCSID("$IdPath$");
-
-#include "globals.h"
-#include "expr.h"
-#include "symrec.h"
-
-#include "section.h"
-#include "objfmt.h"
-
-
-/*@dependent@*/ FILE *dbg_f;
-
-static void
-dbg_objfmt_initialize(/*@dependent@*/ FILE *f)
-{
- dbg_f = f;
- fprintf(dbg_f, "%*sinitialize(f)\n", indent_level, "");
-}
-
-static void
-dbg_objfmt_finalize(void)
-{
- fprintf(dbg_f, "%*sfinalize()\n", indent_level, "");
-}
-
-static /*@dependent@*/ /*@null@*/ section *
-dbg_objfmt_sections_switch(sectionhead *headp, valparamhead *valparams,
- /*@unused@*/ /*@null@*/
- valparamhead *objext_valparams)
-{
- valparam *vp;
- section *retval;
- int isnew;
-
- fprintf(dbg_f, "%*ssections_switch(headp, ", indent_level, "");
- vps_print(dbg_f, valparams);
- fprintf(dbg_f, ", ");
- vps_print(dbg_f, objext_valparams);
- fprintf(dbg_f, "), returning ");
-
- if ((vp = vps_first(valparams)) && !vp->param && vp->val != NULL) {
- retval = sections_switch_general(headp, vp->val, NULL, 0, &isnew);
- if (isnew) {
- fprintf(dbg_f, "(new) ");
- symrec_define_label(vp->val, retval, (bytecode *)NULL, 1);
- }
- fprintf(dbg_f, "\"%s\" section\n", vp->val);
- return retval;
- } else {
- fprintf(dbg_f, "NULL\n");
- return NULL;
- }
-}
-
-static void
-dbg_objfmt_section_data_delete(/*@only@*/ void *data)
-{
- fprintf(dbg_f, "%*ssection_data_delete(%p)\n", indent_level, "", data);
- xfree(data);
-}
-
-static void
-dbg_objfmt_section_data_print(FILE *f, /*@null@*/ void *data)
-{
- if (data)
- fprintf(f, "%*s%p\n", indent_level, "", data);
- else
- fprintf(f, "%*s(none)\n", indent_level, "");
-}
-
-static /*@null@*/ void *
-dbg_objfmt_extern_data_new(const char *name, /*@unused@*/ /*@null@*/
- valparamhead *objext_valparams)
-{
- fprintf(dbg_f, "%*sextern_data_new(\"%s\", ", indent_level, "", name);
- vps_print(dbg_f, objext_valparams);
- fprintf(dbg_f, "), returning NULL\n");
- return NULL;
-}
-
-static /*@null@*/ void *
-dbg_objfmt_global_data_new(const char *name, /*@unused@*/ /*@null@*/
- valparamhead *objext_valparams)
-{
- fprintf(dbg_f, "%*sglobal_data_new(\"%s\", ", indent_level, "", name);
- vps_print(dbg_f, objext_valparams);
- fprintf(dbg_f, "), returning NULL\n");
- return NULL;
-}
-
-static /*@null@*/ void *
-dbg_objfmt_common_data_new(const char *name, /*@only@*/ expr *size,
- /*@unused@*/ /*@null@*/
- valparamhead *objext_valparams)
-{
- fprintf(dbg_f, "%*scommon_data_new(\"%s\", ", indent_level, "", name);
- expr_print(dbg_f, size);
- fprintf(dbg_f, ", ");
- vps_print(dbg_f, objext_valparams);
- fprintf(dbg_f, "), returning ");
- expr_print(dbg_f, size);
- fprintf(dbg_f, "\n");
- return size;
-}
-
-static void
-dbg_objfmt_declare_data_delete(SymVisibility vis, /*@only@*/ void *data)
-{
- fprintf(dbg_f, "%*sdeclare_data_delete(", indent_level, "");
- switch (vis) {
- case SYM_LOCAL:
- fprintf(dbg_f, "Local, ");
- break;
- case SYM_GLOBAL:
- fprintf(dbg_f, "Global, ");
- break;
- case SYM_COMMON:
- fprintf(dbg_f, "Common, ");
- break;
- case SYM_EXTERN:
- fprintf(dbg_f, "Extern, ");
- break;
- }
- if (vis == SYM_COMMON) {
- expr_print(dbg_f, data);
- expr_delete(data);
- } else {
- fprintf(dbg_f, "%p", data);
- xfree(data);
- }
- fprintf(dbg_f, ")\n");
-}
-
-static void
-dbg_objfmt_declare_data_print(FILE *f, SymVisibility vis,
- /*@null@*/ void *data)
-{
- if (vis == SYM_COMMON) {
- fprintf(f, "%*sSize=", indent_level, "");
- expr_print(f, data);
- fprintf(f, "\n");
- } else {
- fprintf(f, "%*s(none)\n", indent_level, "");
- }
-}
-
-static int
-dbg_objfmt_directive(const char *name, valparamhead *valparams,
- /*@null@*/ valparamhead *objext_valparams)
-{
- fprintf(dbg_f, "%*sdirective(\"%s\", ", indent_level, "", name);
- vps_print(dbg_f, valparams);
- fprintf(dbg_f, ", ");
- vps_print(dbg_f, objext_valparams);
- fprintf(dbg_f, "), returning 0 (recognized)\n");
- return 0; /* dbg format "recognizes" all directives */
-}
-
-/* Define objfmt structure -- see objfmt.h for details */
-objfmt dbg_objfmt = {
- "Trace of all info passed to object format module",
- "dbg",
- "dbg",
- ".text",
- 32,
- dbg_objfmt_initialize,
- dbg_objfmt_finalize,
- dbg_objfmt_sections_switch,
- dbg_objfmt_section_data_delete,
- dbg_objfmt_section_data_print,
- dbg_objfmt_extern_data_new,
- dbg_objfmt_global_data_new,
- dbg_objfmt_common_data_new,
- dbg_objfmt_declare_data_delete,
- dbg_objfmt_declare_data_print,
- dbg_objfmt_directive
-};
+++ /dev/null
-# $IdPath$
-
-SUBDIRS = basic
+++ /dev/null
-# $IdPath$
-
-noinst_LIBRARIES = liboptimizer.a
-
-liboptimizer_a_SOURCES = \
- optimizer.c
-
-INCLUDES = \
- -I$(top_srcdir)/src \
- -I$(top_builddir)/intl
-
-CFLAGS = @ANSI_CFLAGS@
--- /dev/null
+# $IdPath$
+
+YASMOPTIMIZERFILES += \
+ src/optimizers/basic/basic-optimizer.c
+++ /dev/null
-/*
- * Basic optimizer (equivalent to the NASM 2-pass 'no optimizer' design)
- *
- * Copyright (C) 2001 Peter Johnson
- *
- * This file is part of YASM.
- *
- * YASM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * YASM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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"
-RCSID("$IdPath$");
-
-#include "bytecode.h"
-#include "section.h"
-
-#include "bc-int.h"
-
-#include "optimizer.h"
-
-
-#define SECTFLAG_NONE 0
-#define SECTFLAG_INPROGRESS (1<<0)
-#define SECTFLAG_DONE (1<<1)
-
-#define BCFLAG_NONE 0
-#define BCFLAG_INPROGRESS (1<<0)
-#define BCFLAG_DONE (1<<1)
-
-static /*@only@*/ /*@null@*/ intnum *
-basic_optimize_resolve_label(section *sect, bytecode *bc)
-{
- unsigned long flags;
-
- flags = section_get_opt_flags(sect);
-
- return NULL;
-}
-
-static int
-basic_optimize_bytecode(bytecode *bc, /*@unused@*/ /*@null@*/ void *d)
-{
- bc->opt_flags = BCFLAG_INPROGRESS;
-
- bc_calc_len(bc, basic_optimize_resolve_label);
-
- bc->opt_flags = BCFLAG_DONE;
-
- return 1;
-}
-
-static int
-basic_optimize_section(section *sect, /*@unused@*/ /*@null@*/ void *d)
-{
- section_set_opt_flags(sect, SECTFLAG_INPROGRESS);
-
- bcs_traverse(section_get_bytecodes(sect), NULL, basic_optimize_bytecode);
-
- section_set_opt_flags(sect, SECTFLAG_DONE);
-
- return 1;
-}
-
-static sectionhead *
-basic_optimize(sectionhead *sections)
-{
- /* Optimization process: (essentially NASM's pass 1)
- * Determine the size of all bytecodes.
- * Check "critical" expressions (must be computable on the first pass,
- * i.e. depend only on symbols before it).
- * Differences from NASM:
- * - right-hand side of EQU is /not/ a critical expr (as the entire file
- * has already been parsed, we know all their values at this point).
- * - not strictly top->bottom scanning; we scan through a section and
- * hop to other sections as necessary.
- */
- sections_traverse(sections, NULL, basic_optimize_section);
-
- /* NASM's pass 2 is output, so we just return. */
- return sections;
-}
-
-/* Define optimizer structure -- see optimizer.h for details */
-optimizer basic_optimizer = {
- "Only the most basic optimizations",
- "basic",
- basic_optimize
-};
+++ /dev/null
-# $IdPath$
-
-SUBDIRS = nasm
--- /dev/null
+# $IdPath$
+
+EXTRA_DIST += \
+ src/parsers/nasm/Makefile.inc
+
+YASMPARSERFILES =
+include src/parsers/nasm/Makefile.inc
+yasm_SOURCES += $(YASMPARSERFILES)
+++ /dev/null
-# $IdPath$
-
-noinst_LIBRARIES = libparser.a
-
-if DEV
-libparser_a_SOURCES = \
- parser.c \
- bison.y \
- token.l
-else
-libparser_a_SOURCES = \
- parser.c \
- bison.c \
- token.c
-
-bison.c: bison.y
- @echo "Run configure with --enable-dev before making changes here."
- @exit 1
-
-token.c: token.l
- @echo "Run configure with --enable-dev before making changes here."
- @exit 1
-endif
-
-noinst_SCRIPTS = gen_instr.pl
-
-AM_YFLAGS = -d --name-prefix=nasm_parser_
-AM_LFLAGS = -Pnasm_parser_ -olex.yy.c
-
-INCLUDES = \
- -I$(top_srcdir)/src \
- -I$(top_builddir)/intl
-
-CFLAGS = @ANSI_CFLAGS@
-
-token.l bison.y: $(top_srcdir)/src/arch/@ARCH@/instrs.dat token.l.in bison.y.in gen_instr.pl
-if DEV
- $(PERL) gen_instr.pl -i $(top_srcdir)/src/arch/@ARCH@/instrs.dat -t token.l -g bison.y
-else
- @echo "Run configure with --enable-dev before making changes here."
- @exit 1
-endif
-
-BUILT_SOURCES = token.l bison.y
-
-EXTRA_DIST = \
- token.l \
- token.l.in \
- bison.y \
- bison.y.in \
- bison.h \
- gen_instr.pl
--- /dev/null
+# $IdPath$
+
+YASMPARSERFILES += \
+ src/parsers/nasm/nasm-parser.c \
+ nasm-bison.y \
+ nasm-bison.h \
+ nasm-token.l
+
+if DEV
+
+nasm-token.l nasm-bison.y: $(srcdir)/src/arch/x86/instrs.dat $(srcdir)/src/parsers/nasm/token.l.in $(srcdir)/src/parsers/nasm/bison.y.in $(srcdir)/src/parsers/nasm/gen_instr.pl
+ $(PERL) $(srcdir)/src/parsers/nasm/gen_instr.pl -i $(srcdir)/src/arch/x86/instrs.dat --sourcetoken $(srcdir)/src/parsers/nasm/token.l.in -t nasm-token.l --sourcegrammar $(srcdir)/src/parsers/nasm/bison.y.in -g nasm-bison.y
+
+else
+
+nasm-token.l: $(srcdir)/nasm-token.l
+ @echo Warning: Not generating nasm-token.l from nasm-token.l.in.
+ @echo Run configure with --enable-dev to enable generation.
+ cp $(srcdir)/nasm-token.l .
+nasm-token.c: $(srcdir)/nasm-token.c
+ @echo Warning: Not generating nasm-token.c from nasm-token.l.
+ @echo Run configure with --enable-dev to enable generation.
+ cp $(srcdir)/nasm-token.c .
+nasm-bison.y: $(srcdir)/nasm-bison.y
+ @echo Warning: Not generating nasm-bison.y from nasm-bison.y.in.
+ @echo Run configure with --enable-dev to enable generation.
+ cp $(srcdir)/nasm-bison.y .
+nasm-bison.c: $(srcdir)/nasm-bison.c
+ @echo Warning: Not generating nasm-bison.c from nasm-bison.y.
+ @echo Run configure with --enable-dev to enable generation.
+ cp $(srcdir)/nasm-bison.c .
+nasm-bison.h: $(srcdir)/nasm-bison.h
+ @echo Warning: Not generating nasm-bison.h from nasm-bison.y.
+ @echo Run configure with --enable-dev to enable generation.
+ cp $(srcdir)/nasm-bison.h .
+
+endif
+
+noinst_SCRIPTS = src/parsers/nasm/gen_instr.pl
+
+AM_YFLAGS = -d --name-prefix=nasm_parser_
+AM_LFLAGS = -Pnasm_parser_ -olex.yy.c
+
+BUILT_SOURCES += \
+ nasm-bison.y \
+ nasm-bison.c \
+ nasm-bison.h \
+ nasm-token.l \
+ nasm-token.c
+
+CLEANFILES += \
+ nasm-bison.y \
+ nasm-bison.c \
+ nasm-bison.h \
+ nasm-token.l \
+ nasm-token.c
+
+EXTRA_DIST += \
+ src/parsers/nasm/token.l.in \
+ src/parsers/nasm/bison.y.in \
+ src/parsers/nasm/gen_instr.pl
+++ /dev/null
-/*
- * NASM-compatible parser
- *
- * Copyright (C) 2001 Peter Johnson
- *
- * This file is part of YASM.
- *
- * YASM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * YASM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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"
-/*@unused@*/ RCSID("$IdPath$");
-
-#include "errwarn.h"
-
-#include "section.h"
-#include "objfmt.h"
-#include "preproc.h"
-#include "parser.h"
-
-
-extern FILE *nasm_parser_in;
-extern int nasm_parser_debug;
-
-extern int nasm_parser_parse(void);
-
-size_t (*nasm_parser_yyinput) (char *buf, size_t max_size);
-
-sectionhead nasm_parser_sections;
-/*@dependent@*/ section *nasm_parser_cur_section;
-
-extern /*@only@*/ char *nasm_parser_locallabel_base;
-
-static /*@dependent@*/ sectionhead *
-nasm_parser_do_parse(parser *p, FILE *f)
- /*@globals killed nasm_parser_locallabel_base @*/
-{
- p->current_pp->initialize(f);
- nasm_parser_in = f;
- nasm_parser_yyinput = p->current_pp->input;
-
- /* Initialize section list */
- nasm_parser_cur_section = sections_initialize(&nasm_parser_sections);
-
- /* yacc debugging, needs YYDEBUG set in bison.y.in to work */
- /* nasm_parser_debug = 1; */
-
- nasm_parser_parse();
-
- /* Free locallabel base if necessary */
- if (nasm_parser_locallabel_base)
- xfree(nasm_parser_locallabel_base);
-
- return &nasm_parser_sections;
-}
-
-/* Define valid preprocessors to use with this parser */
-/*@-nullassign@*/
-static preproc *nasm_parser_preprocs[] = {
- &raw_preproc,
- NULL
-};
-/*@=nullassign@*/
-
-/* Define parser structure -- see parser.h for details */
-parser nasm_parser = {
- "NASM-compatible parser",
- "nasm",
- nasm_parser_preprocs,
- &raw_preproc,
- nasm_parser_do_parse
-};
#include "arch.h"
-#include "bison.h"
+#include "nasm-bison.h"
#define YY_NEVER_INTERACTIVE 1
+++ /dev/null
-# $IdPath$
-
-SUBDIRS = raw
--- /dev/null
+# $IdPath$
+
+EXTRA_DIST += \
+ src/preprocs/raw/Makefile.inc
+
+YASMPREPROCFILES =
+include src/preprocs/raw/Makefile.inc
+yasm_SOURCES += $(YASMPREPROCFILES)
+++ /dev/null
-# $IdPath$
-
-noinst_LIBRARIES = libpreproc.a
-
-libpreproc_a_SOURCES = \
- preproc.c
-
-INCLUDES = \
- -I$(top_srcdir)/src \
- -I$(top_builddir)/intl
-
-CFLAGS = @ANSI_CFLAGS@
--- /dev/null
+# $IdPath$
+
+YASMPREPROCFILES += \
+ src/preprocs/raw/raw-preproc.c
+++ /dev/null
-/*
- * Raw preprocessor (preforms NO preprocessing)
- *
- * Copyright (C) 2001 Peter Johnson
- *
- * This file is part of YASM.
- *
- * YASM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * YASM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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"
-/*@unused@*/ RCSID("$IdPath$");
-
-#include "errwarn.h"
-
-#include "preproc.h"
-
-
-static int is_interactive;
-static FILE *in;
-
-int isatty(int);
-
-static void
-raw_preproc_initialize(FILE *f)
-{
- in = f;
- /*@-unrecog@*/
- is_interactive = f ? (isatty(fileno(f)) > 0) : 0;
- /*@=unrecog@*/
-}
-
-static size_t
-raw_preproc_input(char *buf, size_t max_size)
-{
- int c = '*';
- size_t n;
-
- if (is_interactive) {
- for (n = 0; n < max_size && (c = getc(in)) != EOF && c != '\n'; n++)
- buf[n] = (char)c;
- if (c == '\n')
- buf[n++] = (char)c;
- if (c == EOF && ferror(in))
- Error(_("error when reading from file"));
- } else if (((n = fread(buf, 1, max_size, in)) == 0) && ferror(in))
- Error(_("error when reading from file"));
-
- return n;
-}
-
-/* Define preproc structure -- see preproc.h for details */
-preproc raw_preproc = {
- "Disable preprocessing",
- "raw",
- raw_preproc_initialize,
- raw_preproc_input
-};
+++ /dev/null
-# $IdPath$
-
-CFLAGS = @ANSI_CFLAGS@
-
-if CHECK
-TESTS = \
- bitvect_test \
- bytecode_test \
- floatnum_test \
- memexpr_test
-
-noinst_PROGRAMS = \
- bitvect_test \
- bytecode_test \
- floatnum_test \
- memexpr_test
-
-else
-TESTS =
-noinst_PROGRAMS =
-endif
-
-LDADD = \
- $(top_builddir)/src/libyasm.a \
- $(top_builddir)/check/libcheck.a \
- $(top_builddir)/src/parsers/nasm/libparser.a \
- $(top_builddir)/src/preprocs/raw/libpreproc.a \
- $(top_builddir)/src/optimizers/basic/liboptimizer.a \
- $(top_builddir)/src/objfmts/dbg/libobjfmt.a \
- $(top_builddir)/src/arch/@ARCH@/libarch.a \
- $(top_builddir)/src/libyasm.a \
- $(INTLLIBS)
-
-bitvect_test_SOURCES = \
- bitvect_test.c
-
-bitvect_test_LDADD = \
- $(top_builddir)/src/errwarn.o \
- $(LDADD)
-
-bytecode_test_SOURCES = \
- bytecode_test.c
-
-bytecode_test_LDADD = \
- $(top_builddir)/src/errwarn.o \
- $(LDADD)
-
-floatnum_test_SOURCES = \
- floatnum_test.c
-
-floatnum_test_LDADD = \
- $(top_builddir)/src/errwarn.o \
- $(LDADD)
-
-memexpr_test_SOURCES = \
- memexpr_test.c
-
-INCLUDES= -I$(top_srcdir) -I$(top_srcdir)/src -I$(top_srcdir)/check \
- -I$(top_srcdir)/src/arch/@ARCH@ -I$(top_builddir)/intl
-
--- /dev/null
+# $IdPath$
+
+TESTS += \
+ bitvect_test \
+ floatnum_test
+
+noinst_PROGRAMS += \
+ bitvect_test \
+ floatnum_test
+
+bitvect_test_SOURCES = \
+ src/tests/bitvect_test.c \
+ src/errwarn.c \
+ $(YASMBASEFILES) \
+ $(YASMPARSERFILES) \
+ $(YASMPREPROCFILES) \
+ $(YASMOPTIMIZERFILES) \
+ $(YASMOBJFMTFILES) \
+ $(YASMARCHFILES) \
+ $(CHECKFILES)
+bitvect_test_LDADD = $(INTLLIBS)
+
+#bytecode_test_SOURCES = \
+# src/tests/bytecode_test.c \
+# src/errwarn.c \
+# $(YASMBASEFILES) \
+# $(YASMPARSERFILES) \
+# $(YASMPREPROCFILES) \
+# $(YASMOPTIMIZERFILES) \
+# $(YASMOBJFMTFILES) \
+# $(YASMARCHFILES) \
+# $(CHECKFILES)
+#bytecode_test_LDADD = $(INTLLIBS)
+
+floatnum_test_SOURCES = \
+ src/tests/floatnum_test.c \
+ src/errwarn.c \
+ src/globals.c \
+ src/hamt.c \
+ src/bitvect.c \
+ src/xmalloc.c \
+ src/xstrdup.c \
+ $(CHECKFILES)
+floatnum_test_LDADD = $(INTLLIBS)
+
+#memexpr_test_SOURCES = \
+# src/tests/memexpr_test.c \
+# src/errwarn.c \
+# $(YASMBASEFILES) \
+# $(YASMPARSERFILES) \
+# $(YASMPREPROCFILES) \
+# $(YASMOPTIMIZERFILES) \
+# $(YASMOBJFMTFILES) \
+# $(YASMARCHFILES) \
+# $(CHECKFILES)
+#memexpr_test_LDADD = $(INTLLIBS)
+++ /dev/null
-# $IdPath$
-
-CFLAGS = @ANSI_CFLAGS@
-
-if CHECK
-#TESTS = \
-
-#noinst_PROGRAMS = \
-else
-#TESTS =
-#noinst_PROGRAMS =
-endif
-
-INCLUDES= -I$(top_srcdir) -I$(top_srcdir)/src -I$(top_srcdir)/check
-LDADD = \
- $(top_builddir)/check/libcheck.a \
- $(top_builddir)/src/parsers/nasm/libparser.a \
- $(top_builddir)/src/preprocs/raw/libpreproc.a \
- $(top_builddir)/src/optimizers/dbg/liboptimizer.a \
- $(top_builddir)/src/objfmts/dbg/libobjfmt.a \
- $(top_builddir)/src/libyasm.a \
- $(INTLLIBS)
-