* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* \endlicense
- *
- * Additional parts may be included via:
- * - YASM_EXPR_INTERNAL: reveal expr internal structures via expr-int.h
- * inclusion
*/
#ifndef YASM_LIB_H
#define YASM_LIB_H
#include <libyasm/file.h>
#include <libyasm/module.h>
-#ifdef YASM_EXPR_INTERNAL
-#include <libyasm/expr-int.h>
-#endif
#include <libyasm/hamt.h>
#include <libyasm/md5.h>
modinclude_HEADERS += libyasm/dbgfmt.h
modinclude_HEADERS += libyasm/errwarn.h
modinclude_HEADERS += libyasm/expr.h
-modinclude_HEADERS += libyasm/expr-int.h
modinclude_HEADERS += libyasm/file.h
modinclude_HEADERS += libyasm/floatnum.h
modinclude_HEADERS += libyasm/hamt.h
#include "bytecode.h"
-#include "expr-int.h"
-
typedef struct bytecode_reserve {
/*@only@*/ /*@null@*/ yasm_expr *numitems; /* number of items to reserve */
#include "bytecode.h"
-#include "expr-int.h"
-
void
yasm_bc_set_multiple(yasm_bytecode *bc, yasm_expr *e)
*/
typedef struct yasm_errwarns yasm_errwarns;
-/** Bytecode. \see bytecode.h for defails and related functions. */
+/** Bytecode. \see bytecode.h for details and related functions. */
typedef struct yasm_bytecode yasm_bytecode;
/** Object. \see section.h for details and related functions. */
/** Symbol record (opaque type). \see symrec.h for related functions. */
typedef struct yasm_symrec yasm_symrec;
-/** Expression (opaque type).
- * \see expr.h for related functions.
- * Define YASM_EXPR_INTERNAL to get visible internals.
- */
+/** Expression. \see expr.h for details and related functions. */
typedef struct yasm_expr yasm_expr;
/** Integer value (opaque type). \see intnum.h for related functions. */
typedef struct yasm_intnum yasm_intnum;
+++ /dev/null
-/* $Id$
- * Expressions internal structures header file
- *
- * Copyright (C) 2001-2007 Peter Johnson
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-#ifndef YASM_EXPR_INT_H
-#define YASM_EXPR_INT_H
-
-/* Types listed in canonical sorting order. See expr_order_terms().
- * Note precbc must be used carefully (in a-b pairs), as only symrecs can
- * become the relative term in a #yasm_value.
- */
-typedef enum yasm_expr__type {
- YASM_EXPR_NONE = 0,
- YASM_EXPR_REG = 1<<0,
- YASM_EXPR_INT = 1<<1,
- YASM_EXPR_SUBST = 1<<2,
- YASM_EXPR_FLOAT = 1<<3,
- YASM_EXPR_SYM = 1<<4,
- YASM_EXPR_PRECBC = 1<<5, /* direct bytecode ref (rather than via symrec) */
- YASM_EXPR_EXPR = 1<<6
-} yasm_expr__type;
-
-struct yasm_expr__item {
- yasm_expr__type type;
- union {
- yasm_bytecode *precbc;
- yasm_symrec *sym;
- yasm_expr *expn;
- yasm_intnum *intn;
- yasm_floatnum *flt;
- uintptr_t reg;
- unsigned int subst;
- } data;
-};
-
-/* Some operations may allow more than two operand terms:
- * ADD, MUL, OR, AND, XOR
- */
-struct yasm_expr {
- yasm_expr_op op;
- unsigned long line;
- int numterms;
- yasm_expr__item terms[2]; /* structure may be extended to include more */
-};
-
-/* Traverse over expression tree in order, calling func for each leaf
- * (non-operation). The data pointer d is passed to each func call.
- *
- * Stops early (and returns 1) if func returns 1. Otherwise returns 0.
- */
-int yasm_expr__traverse_leaves_in_const
- (const yasm_expr *e, /*@null@*/ void *d,
- int (*func) (/*@null@*/ const yasm_expr__item *ei, /*@null@*/ void *d));
-int yasm_expr__traverse_leaves_in
- (yasm_expr *e, /*@null@*/ void *d,
- int (*func) (/*@null@*/ yasm_expr__item *ei, /*@null@*/ void *d));
-
-/* Reorder terms of e into canonical order. Only reorders if reordering
- * doesn't change meaning of expression. (eg, doesn't reorder SUB).
- * Canonical order: REG, INT, FLOAT, SYM, EXPR.
- * Multiple terms of a single type are kept in the same order as in
- * the original expression.
- * NOTE: Only performs reordering on *one* level (no recursion).
- */
-void yasm_expr__order_terms(yasm_expr *e);
-
-/* Copy entire expression EXCEPT for index "except" at *top level only*. */
-yasm_expr *yasm_expr__copy_except(const yasm_expr *e, int except);
-
-int yasm_expr__contains(const yasm_expr *e, yasm_expr__type t);
-
-/** Transform symrec-symrec terms in expression into YASM_EXPR_SUBST items.
- * Calls the callback function for each symrec-symrec term.
- * \param ep expression (pointer to)
- * \param cbd callback data passed to callback function
- * \param callback callback function: given subst index for bytecode
- * pair, bytecode pair (bc2-bc1), and cbd (callback data)
- * \return Number of transformations made.
- */
-int yasm_expr__bc_dist_subst(yasm_expr **ep, void *cbd,
- void (*callback) (unsigned int subst,
- yasm_bytecode *precbc,
- yasm_bytecode *precbc2,
- void *cbd));
-
-/** Substitute items into expr YASM_EXPR_SUBST items (by index). Items are
- * copied, so caller is responsible for freeing array of items.
- * \param e expression
- * \param num_items number of items in items array
- * \param items items array
- * \return 1 on error (index out of range).
- */
-int yasm_expr__subst(yasm_expr *e, unsigned int num_items,
- const yasm_expr__item *items);
-
-#endif
#include "arch.h"
-#include "expr-int.h"
-
static int expr_traverse_nodes_post(/*@null@*/ yasm_expr *e,
/*@null@*/ void *d,
return n;
}
-yasm_expr *
-yasm_expr_copy(const yasm_expr *e)
-{
- return yasm_expr__copy_except(e, -1);
-}
-
static void
expr_delete_term(yasm_expr__item *term, int recurse)
{
#ifndef YASM_EXPR_H
#define YASM_EXPR_H
-/** Expression item (opaque type). \internal */
-typedef struct yasm_expr__item yasm_expr__item;
+/** Type of an expression item. Types are listed in canonical sorting order.
+ * See expr_order_terms().
+ * Note #YASM_EXPR_PRECBC must be used carefully (in a-b pairs), as only
+ * symrecs can become the relative term in a #yasm_value.
+ */
+typedef enum yasm_expr__type {
+ YASM_EXPR_NONE = 0, /**< Nothing */
+ YASM_EXPR_REG = 1<<0, /**< Register */
+ YASM_EXPR_INT = 1<<1, /**< Integer value */
+ YASM_EXPR_SUBST = 1<<2, /**< Substitution placeholder */
+ YASM_EXPR_FLOAT = 1<<3, /**< Floating point value */
+ YASM_EXPR_SYM = 1<<4, /**< Symbol */
+ YASM_EXPR_PRECBC = 1<<5,/**< Direct bytecode ref (rather than via sym) */
+ YASM_EXPR_EXPR = 1<<6 /**< Subexpression */
+} yasm_expr__type;
+
+/** Expression item. */
+typedef struct yasm_expr__item {
+ yasm_expr__type type; /**< Type */
+
+ /** Expression item data. Correct value depends on type. */
+ union {
+ yasm_bytecode *precbc; /**< Direct bytecode ref (#YASM_EXPR_PRECBC) */
+ yasm_symrec *sym; /**< Symbol (#YASM_EXPR_SYM) */
+ yasm_expr *expn; /**< Subexpression (#YASM_EXPR_EXPR) */
+ yasm_intnum *intn; /**< Integer value (#YASM_EXPR_INT) */
+ yasm_floatnum *flt; /**< Floating point value (#YASM_EXPR_FLOAT) */
+ uintptr_t reg; /**< Register (#YASM_EXPR_REG) */
+ unsigned int subst; /**< Subst placeholder (#YASM_EXPR_SUBST) */
+ } data;
+} yasm_expr__item;
+
+/** Expression. */
+struct yasm_expr {
+ yasm_expr_op op; /**< Operation. */
+ unsigned long line; /**< Line number where expression was defined. */
+ int numterms; /**< Number of terms in the expression. */
+
+ /** Terms of the expression. Structure may be extended to include more
+ * terms, as some operations may allow more than two operand terms
+ * (ADD, MUL, OR, AND, XOR).
+ */
+ yasm_expr__item terms[2];
+};
/** Create a new expression e=a op b.
* \param op operation
* \return Newly allocated expression identical to e.
*/
yasm_expr *yasm_expr_copy(const yasm_expr *e);
+#define yasm_expr_copy(e) yasm_expr__copy_except(e, -1)
/** Destroy (free allocated memory for) an expression.
* \param e expression
*/
void yasm_expr_print(/*@null@*/ const yasm_expr *e, FILE *f);
+/** Traverse over expression tree in order (const version).
+ * Calls func for each leaf (non-operation).
+ * \param e expression
+ * \param d data passed to each call to func
+ * \param func callback function
+ * \return Stops early (and returns 1) if func returns 1.
+ * Otherwise returns 0.
+ */
+int yasm_expr__traverse_leaves_in_const
+ (const yasm_expr *e, /*@null@*/ void *d,
+ int (*func) (/*@null@*/ const yasm_expr__item *ei, /*@null@*/ void *d));
+
+/** Traverse over expression tree in order.
+ * Calls func for each leaf (non-operation).
+ * \param e expression
+ * \param d data passed to each call to func
+ * \param func callback function
+ * \return Stops early (and returns 1) if func returns 1.
+ * Otherwise returns 0.
+ */
+int yasm_expr__traverse_leaves_in
+ (yasm_expr *e, /*@null@*/ void *d,
+ int (*func) (/*@null@*/ yasm_expr__item *ei, /*@null@*/ void *d));
+
+/** Reorder terms of e into canonical order. Only reorders if reordering
+ * doesn't change meaning of expression. (eg, doesn't reorder SUB).
+ * Canonical order: REG, INT, FLOAT, SYM, EXPR.
+ * Multiple terms of a single type are kept in the same order as in
+ * the original expression.
+ * \param e expression
+ * \note Only performs reordering on *one* level (no recursion).
+ */
+void yasm_expr__order_terms(yasm_expr *e);
+
+/** Copy entire expression EXCEPT for index "except" at *top level only*.
+ * \param e expression
+ * \param except term index not to copy; -1 to copy all terms
+ * \return Newly allocated copy of expression.
+ */
+yasm_expr *yasm_expr__copy_except(const yasm_expr *e, int except);
+
+/** Test if expression contains an item. Searches recursively into
+ * subexpressions.
+ * \param e expression
+ * \param t type of item to look for
+ * \return Nonzero if expression contains an item of type t, zero if not.
+ */
+int yasm_expr__contains(const yasm_expr *e, yasm_expr__type t);
+
+/** Transform symrec-symrec terms in expression into #YASM_EXPR_SUBST items.
+ * Calls the callback function for each symrec-symrec term.
+ * \param ep expression (pointer to)
+ * \param cbd callback data passed to callback function
+ * \param callback callback function: given subst index for bytecode
+ * pair, bytecode pair (bc2-bc1), and cbd (callback data)
+ * \return Number of transformations made.
+ */
+int yasm_expr__bc_dist_subst(yasm_expr **ep, void *cbd,
+ void (*callback) (unsigned int subst,
+ yasm_bytecode *precbc,
+ yasm_bytecode *precbc2,
+ void *cbd));
+
+/** Substitute items into expr YASM_EXPR_SUBST items (by index). Items are
+ * copied, so caller is responsible for freeing array of items.
+ * \param e expression
+ * \param num_items number of items in items array
+ * \param items items array
+ * \return 1 on error (index out of range).
+ */
+int yasm_expr__subst(yasm_expr *e, unsigned int num_items,
+ const yasm_expr__item *items);
+
#endif
#include "dbgfmt.h"
#include "objfmt.h"
-#include "expr-int.h"
-
#include "inttree.h"
#include "arch.h"
-#include "expr-int.h"
void
yasm_value_initialize(/*@out@*/ yasm_value *value,
#include <util.h>
RCSID("$Id$");
-#define YASM_EXPR_INTERNAL
#include <libyasm.h>
#include "modules/arch/lc3b/lc3barch.h"
#include <util.h>
/*@unused@*/ RCSID("$Id$");
-#define YASM_EXPR_INTERNAL
#include <libyasm.h>
#include "x86arch.h"
#include <util.h>
/*@unused@*/ RCSID("$Id$");
-#define YASM_EXPR_INTERNAL
#include <libyasm.h>
#include "x86arch.h"
#include <util.h>
RCSID("$Id$");
-#define YASM_EXPR_INTERNAL
#include <libyasm.h>
#include <libyasm/phash.h>
#include <util.h>
/*@unused@*/ RCSID("$Id$");
-#define YASM_EXPR_INTERNAL
#include <libyasm.h>
#include <time.h>
/*@unused@*/ RCSID("$Id$");
-#define YASM_EXPR_INTERNAL
#include <libyasm.h>
#include "coff-objfmt.h"
#include <util.h>
/*@unused@*/ RCSID("$Id$");
-#define YASM_EXPR_INTERNAL
#include <libyasm.h>
#include "coff-objfmt.h"
* Each Section is spatially disjoint, and has exactly one SHT entry.
*/
-#define YASM_EXPR_INTERNAL
#include <libyasm.h>
#include "elf.h"
#include <util.h>
/*@unused@*/ RCSID("$Id$");
-#define YASM_EXPR_INTERNAL
#include <libyasm.h>
#define YASM_OBJFMT_ELF_INTERNAL
#include "elf.h"
#include <util.h>
/*@unused@*/ RCSID("$Id$");
-#define YASM_EXPR_INTERNAL
#include <libyasm.h>
#define YASM_OBJFMT_ELF_INTERNAL
#include "elf.h"
#include <util.h>
/*@unused@*/ RCSID("$Id$");
-#define YASM_EXPR_INTERNAL
#include <libyasm.h>
#define YASM_OBJFMT_ELF_INTERNAL
#include "elf.h"
/* optional: automatically prefix underscores to global exported symbols */
/*#define AUTO_UNDERSCORE*/
-#define YASM_EXPR_INTERNAL
#include <libyasm.h>
/* MACH-O DEFINES */
#include <util.h>
/*@unused@*/ RCSID("$Id$");
-#define YASM_EXPR_INTERNAL
#include <libyasm.h>
#include <util.h>
/*@unused@*/ RCSID("$Id$");
-#define YASM_EXPR_INTERNAL
#include <libyasm.h>
#include <util.h>
RCSID("$Id$");
-#define YASM_EXPR_INTERNAL
#include <libyasm.h>
#include <limits.h>
#include <util.h>
RCSID("$Id$");
-#define YASM_EXPR_INTERNAL
#include <libyasm.h>
#include <math.h>