]> granicus.if.org Git - yasm/commitdiff
Add yasm_expr_extract_wrt() to separate portions of WRT expression.
authorPeter Johnson <peter@tortall.net>
Sun, 3 Aug 2003 21:06:15 +0000 (21:06 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 3 Aug 2003 21:06:15 +0000 (21:06 -0000)
svn path=/trunk/yasm/; revision=1031

libyasm/expr.c
libyasm/expr.h

index 52e538c92d6dddfc5dca8d7f8d13fc47bdd1103c..e46f39c5c6a46490c410a36202b5670f7a387753 100644 (file)
@@ -1058,6 +1058,34 @@ yasm_expr_extract_segment(yasm_expr **ep)
     return retval;
 }
 
+yasm_expr *
+yasm_expr_extract_wrt(yasm_expr **ep)
+{
+    yasm_expr *retval;
+    yasm_expr *e = *ep;
+
+    /* If not WRT, we can't do this transformation */
+    if (e->op != YASM_EXPR_WRT)
+       return NULL;
+
+    /* Extract the right side portion out to its own expression */
+    if (e->terms[1].type == YASM_EXPR_EXPR)
+       retval = e->terms[1].data.expn;
+    else {
+       /* Need to build IDENT expression to hold non-expression contents */
+       retval = yasm_xmalloc(sizeof(yasm_expr));
+       retval->op = YASM_EXPR_IDENT;
+       retval->numterms = 1;
+       retval->terms[0] = e->terms[1]; /* structure copy */
+    }
+
+    /* Delete the right side portion by changing the expr into an IDENT */
+    e->op = YASM_EXPR_IDENT;
+    e->numterms = 1;
+
+    return retval;
+}
+
 /*@-unqualifiedtrans -nullderef -nullstate -onlytrans@*/
 const yasm_intnum *
 yasm_expr_get_intnum(yasm_expr **ep, yasm_calc_bc_dist_func calc_bc_dist)
index 748261a31c3288719882ebdadc1f786965ac32e2..ed38729b0fbaf405218f1ceb3695aadce412b16a 100644 (file)
@@ -193,6 +193,16 @@ SLIST_HEAD(yasm__exprhead, yasm__exprentry);
  */
 /*@only@*/ /*@null@*/ yasm_expr *yasm_expr_extract_segment(yasm_expr **ep);
 
+/** Extract the right portion (y) of a x WRT y expression, leaving the left
+ * portion (x).
+ * \param ep           expression (pointer to)
+ * \return NULL if unable to extract (YASM_EXPR_WRT not the top-level
+ *         operator), otherwise the right side of the WRT expression.  The
+ *         input expression is modified such that on return, it's the left side
+ *         of the WRT expression.
+ */
+/*@only@*/ /*@null@*/ yasm_expr *yasm_expr_extract_wrt(yasm_expr **ep);
+
 /** Get the integer value of an expression if it's just an integer.
  * \param ep           expression (pointer to)
  * \param calc_bc_dist bytecode distance-calculation function