pull request v2

View: New views
5 Messages — Rating Filter:   Alert me  

pull request v2

by Cyrill Gorcunov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Peter,

I've updated patches to eliminate is_REGISTER
and friends. Also renamed nasm_get_word to
nasm_skip_spaces. Didn't fix FPUREG yet,
will fix later.

Please take a look (the whole diff below).

        -- Cyrill
---
The following changes since commit 8d2c4edd229da337c6514df9854b9a9e27a7c9d9:
  H. Peter Anvin (1):
        assemble: when looking for a REGISTER operand, do an exclusive test

are available in the git repository at:

  git://repo.or.cz/nasm-cyr.git for-hpa

Cyrill Gorcunov (10):
      style cleanup
      use opflags_t type for operands
      nasm.h: introduce is_class macro helper
      assemble.c: use is_class helper
      introduce "overflow" helpers
      assemble.c: check constants for overflow
      nasmlib: introduce string helpers
      nasm.c: getkw -- use string helpers
      preproc.c: use string helpers
      nasm.c: use string helpers

 assemble.c |   52 ++++---
 float.c    |  542 ++++++++++++++++++++++++++++++------------------------------
 hashtbl.c  |  122 +++++++-------
 nasm.c     |   89 ++++------
 nasm.h     |    4 +-
 nasmlib.c  |   36 ++++
 nasmlib.h  |  238 +++++++++++++++------------
 preproc.c  |   15 +-
 8 files changed, 576 insertions(+), 522 deletions(-)

diff --git a/assemble.c b/assemble.c
index 8f13793..7ea5fb9 100644
--- a/assemble.c
+++ b/assemble.c
@@ -240,17 +240,26 @@ static const char *size_name(int size)
     }
 }
 
-static void warn_overflow(int size, const struct operand *o)
+static void warn_overflow(int pass, int size)
 {
-    if (size < 8 && o->wrt == NO_SEG && o->segment == NO_SEG) {
- int64_t lim = ((int64_t)1 << (size*8))-1;
- int64_t data = o->offset;
+    errfunc(ERR_WARNING | pass | ERR_WARN_NOV,
+            "%s data exceeds bounds", size_name(size));
+}
+
+static void warn_overflow_const(int64_t data, int size)
+{
+    if (overflow_general(data, size))
+        warn_overflow(ERR_PASS1, size);
+}
 
- if (data < ~lim || data > lim)
-    errfunc(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV,
-    "%s data exceeds bounds", size_name(size));
+static void warn_overflow_opd(const struct operand *o, int size)
+{
+    if (size < 8 && o->wrt == NO_SEG && o->segment == NO_SEG) {
+        if (overflow_general(o->offset, size))
+            warn_overflow(ERR_PASS2, size);
     }
 }
+
 /*
  * This routine wrappers the real output format's output routine,
  * in order to pass a copy of the data off to the listing file
@@ -708,10 +717,11 @@ int64_t insn_size(int32_t segment, int64_t offset, int bits, uint32_t cp,
             int32_t align;
 
             osize = 0;
-            if (e->type == EOT_DB_NUMBER)
+            if (e->type == EOT_DB_NUMBER) {
                 osize = 1;
-            else if (e->type == EOT_DB_STRING ||
-     e->type == EOT_DB_STRING_FREE)
+                warn_overflow_const(e->offset, wsize);
+            } else if (e->type == EOT_DB_STRING ||
+                       e->type == EOT_DB_STRING_FREE)
                 osize = e->stringlen;
 
             align = (-osize) % wsize;
@@ -1343,7 +1353,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
             break;
 
  case4(030):
-    warn_overflow(2, opx);
+            warn_overflow_opd(opx, 2);
             data = opx->offset;
             out(offset, segment, &data, OUT_ADDRESS, 2,
                 opx->segment, opx->wrt);
@@ -1355,7 +1365,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
                 size = (opx->type & BITS16) ? 2 : 4;
             else
                 size = (bits == 16) ? 2 : 4;
-    warn_overflow(size, opx);
+            warn_overflow_opd(opx, size);
             data = opx->offset;
             out(offset, segment, &data, OUT_ADDRESS, size,
                 opx->segment, opx->wrt);
@@ -1363,7 +1373,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
             break;
 
  case4(040):
-    warn_overflow(4, opx);
+            warn_overflow_opd(opx, 4);
             data = opx->offset;
             out(offset, segment, &data, OUT_ADDRESS, 4,
                 opx->segment, opx->wrt);
@@ -1373,7 +1383,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
  case4(044):
             data = opx->offset;
             size = ins->addr_size >> 3;
-    warn_overflow(size, opx);
+            warn_overflow_opd(opx, size);
             out(offset, segment, &data, OUT_ADDRESS, size,
                 opx->segment, opx->wrt);
             offset += size;
@@ -1457,7 +1467,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
 
  case4(0140):
             data = opx->offset;
-    warn_overflow(2, opx);
+            warn_overflow_opd(opx, 2);
             if (is_sbyte16(opx)) {
                 bytes[0] = data;
                 out(offset, segment, bytes, OUT_RAWDATA, 1, NO_SEG,
@@ -1481,7 +1491,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
 
  case4(0150):
             data = opx->offset;
-    warn_overflow(4, opx);
+            warn_overflow_opd(opx, 4);
             if (is_sbyte32(opx)) {
                 bytes[0] = data;
                 out(offset, segment, bytes, OUT_RAWDATA, 1, NO_SEG,
@@ -1894,7 +1904,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
                 case 4:
                 case 8:
                     data = opy->offset;
-    warn_overflow(ea_data.bytes, opy);
+                    warn_overflow_opd(opy, ea_data.bytes);
                     s += ea_data.bytes;
     if (ea_data.rip) {
  if (opy->segment == segment) {
@@ -2027,7 +2037,7 @@ static enum match_result find_match(const struct itemplate **tempp,
  * never try to fuzzy-match on them.  This also resolves the case
  * when we have e.g. "xmmrm128" in two different positions.
  */
- if ((REGISTER & ~instruction->oprs[i].type) == 0)
+ if (is_class(REGISTER, instruction->oprs[i].type))
     continue;
 
  /* This tests if xsizeflags[i] has more than one bit set */
@@ -2141,7 +2151,7 @@ static enum match_result matches(const struct itemplate *itemp,
      * Check that the operand flags all match up
      */
     for (i = 0; i < itemp->operands; i++) {
- int32_t type = instruction->oprs[i].type;
+ opflags_t type = instruction->oprs[i].type;
  if (!(type & SIZE_MASK))
     type |= size[i];
 
@@ -2155,7 +2165,7 @@ static enum match_result matches(const struct itemplate *itemp,
              ((itemp->opd[i] ^ type) & SIZE_MASK))) {
             if ((itemp->opd[i] & ~type & ~SIZE_MASK) || (type & SIZE_MASK)) {
                 return MERR_INVALOP;
-    } else if ((REGISTER & type) != REGISTER) {
+    } else if (!is_class(REGISTER, type)) {
  /*
  * Note: we don't honor extrinsic operand sizes for registers,
  * so "missing operand size" for a register should be
@@ -2224,7 +2234,7 @@ static ea *process_ea(operand * input, ea * output, int bits,
     /* REX flags for the rfield operand */
     output->rex |= rexflags(rfield, rflags, REX_R|REX_P|REX_W|REX_H);
 
-    if (!(REGISTER & ~input->type)) {   /* register direct */
+    if (is_class(REGISTER, input->type)) {  /* register direct */
         int i;
  int32_t f;
 
diff --git a/float.c b/float.c
index 737a2c9..7a4f8cb 100644
--- a/float.c
+++ b/float.c
@@ -1,5 +1,5 @@
 /* ----------------------------------------------------------------------- *
- *  
+ *
  *   Copyright 1996-2009 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
@@ -14,7 +14,7 @@
  *     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 COPYRIGHT HOLDERS AND
  *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -65,12 +65,12 @@ static enum float_round rc = FLOAT_RC_NEAR;     /* rounding control */
 typedef uint32_t fp_limb;
 typedef uint64_t fp_2limb;
 
-#define LIMB_BITS 32
+#define LIMB_BITS       32
 #define LIMB_BYTES      (LIMB_BITS/8)
-#define LIMB_TOP_BIT ((fp_limb)1 << (LIMB_BITS-1))
-#define LIMB_MASK ((fp_limb)(~0))
-#define LIMB_ALL_BYTES ((fp_limb)0x01010101)
-#define LIMB_BYTE(x) ((x)*LIMB_ALL_BYTES)
+#define LIMB_TOP_BIT    ((fp_limb)1 << (LIMB_BITS-1))
+#define LIMB_MASK       ((fp_limb)(~0))
+#define LIMB_ALL_BYTES  ((fp_limb)0x01010101)
+#define LIMB_BYTE(x)    ((x)*LIMB_ALL_BYTES)
 
 /* 112 bits + 64 bits for accuracy + 16 bits for rounding */
 #define MANT_LIMBS 6
@@ -82,8 +82,8 @@ typedef uint64_t fp_2limb;
 #define MANT_FMT "%08x_%08x_%08x_%08x_%08x_%08x"
 #define MANT_ARG SOME_ARG(mant, 0)
 
-#define SOME_ARG(a,i) (a)[(i)+0], (a)[(i)+1], (a)[(i)+2], (a)[(i)+3], \
- (a)[(i)+4], (a)[(i)+5]
+#define SOME_ARG(a,i) (a)[(i)+0], (a)[(i)+1], (a)[(i)+2], \
+                      (a)[(i)+3], (a)[(i)+4], (a)[(i)+5]
 
 /*
  * ---------------------------------------------------------------------------
@@ -93,9 +93,9 @@ typedef uint64_t fp_2limb;
 
 #ifdef DEBUG_FLOAT
 #define dprintf(x) printf x
-#else                           /*  */
+#else
 #define dprintf(x) do { } while (0)
-#endif                          /*  */
+#endif
 
 /*
  * ---------------------------------------------------------------------------
@@ -159,36 +159,36 @@ static int32_t read_exponent(const char *string, int32_t max)
     bool neg = false;
 
     if (*string == '+') {
- string++;
+        string++;
     } else if (*string == '-') {
- neg = true;
- string++;
+        neg = true;
+        string++;
     }
     while (*string) {
- if (*string >= '0' && *string <= '9') {
-    i = (i * 10) + (*string - '0');
-
-    /*
-     * To ensure that underflows and overflows are
-     * handled properly we must avoid wraparounds of
-     * the signed integer value that is used to hold
-     * the exponent. Therefore we cap the exponent at
-     * +/-5000, which is slightly more/less than
-     * what's required for normal and denormal numbers
-     * in single, double, and extended precision, but
-     * sufficient to avoid signed integer wraparound.
-     */
-    if (i > max)
- i = max;
- } else if (*string == '_') {
-    /* do nothing */
- } else {
-    error(ERR_NONFATAL|ERR_PASS1,
-  "invalid character in floating-point constant %s: '%c'",
-  "exponent", *string);
-    return INT32_MAX;
- }
- string++;
+        if (*string >= '0' && *string <= '9') {
+            i = (i * 10) + (*string - '0');
+
+            /*
+             * To ensure that underflows and overflows are
+             * handled properly we must avoid wraparounds of
+             * the signed integer value that is used to hold
+             * the exponent. Therefore we cap the exponent at
+             * +/-5000, which is slightly more/less than
+             * what's required for normal and denormal numbers
+             * in single, double, and extended precision, but
+             * sufficient to avoid signed integer wraparound.
+             */
+            if (i > max)
+                i = max;
+        } else if (*string == '_') {
+            /* do nothing */
+        } else {
+            error(ERR_NONFATAL|ERR_PASS1,
+                  "invalid character in floating-point constant %s: '%c'",
+                  "exponent", *string);
+            return INT32_MAX;
+        }
+        string++;
     }
 
     return neg ? -i : i;
@@ -257,13 +257,13 @@ static bool ieee_flconvert(const char *string, fp_limb *mant,
     }
 
     if (*string) {
- int32_t e;
+        int32_t e;
 
         string++;               /* eat the E */
- e = read_exponent(string, 5000);
- if (e == INT32_MAX)
-    return false;
- tenpwr += e;
+        e = read_exponent(string, 5000);
+        if (e == INT32_MAX)
+            return false;
+        tenpwr += e;
     }
 
     /*
@@ -419,8 +419,8 @@ static bool is_zero(const fp_limb *mant)
     int i;
 
     for (i = 0; i < MANT_LIMBS; i++)
- if (mant[i])
-    return false;
+        if (mant[i])
+            return false;
 
     return true;
 }
@@ -431,29 +431,29 @@ static bool is_zero(const fp_limb *mant)
  * ---------------------------------------------------------------------------
  */
 
-#define ROUND_COLLECT_BITS \
-    do { \
- m = mant[i] & (2*bit-1); \
- for (j = i+1; j < MANT_LIMBS; j++) \
-    m = m | mant[j]; \
+#define ROUND_COLLECT_BITS                      \
+    do {                                        \
+        m = mant[i] & (2*bit-1);                \
+        for (j = i+1; j < MANT_LIMBS; j++)      \
+            m = m | mant[j];                    \
     } while (0)
 
-#define ROUND_ABS_DOWN \
-    do { \
- mant[i] &= ~(bit-1); \
- for (j = i+1; j < MANT_LIMBS; j++) \
-    mant[j] = 0; \
- return false; \
+#define ROUND_ABS_DOWN                          \
+    do {                                        \
+        mant[i] &= ~(bit-1);                    \
+        for (j = i+1; j < MANT_LIMBS; j++)      \
+            mant[j] = 0;                        \
+        return false;                           \
     } while (0)
 
-#define ROUND_ABS_UP \
-    do { \
- mant[i] = (mant[i] & ~(bit-1)) + bit; \
- for (j = i+1; j < MANT_LIMBS; j++) \
-    mant[j] = 0; \
- while (i > 0 && !mant[i]) \
-    ++mant[--i]; \
- return !mant[0]; \
+#define ROUND_ABS_UP                            \
+    do {                                        \
+        mant[i] = (mant[i] & ~(bit-1)) + bit;   \
+        for (j = i+1; j < MANT_LIMBS; j++)      \
+            mant[j] = 0;                        \
+        while (i > 0 && !mant[i])               \
+            ++mant[--i];                        \
+        return !mant[0];                        \
     } while (0)
 
 static bool ieee_round(bool minus, fp_limb *mant, int bits)
@@ -465,34 +465,34 @@ static bool ieee_round(bool minus, fp_limb *mant, int bits)
     fp_limb bit = LIMB_TOP_BIT >> p;
 
     if (rc == FLOAT_RC_NEAR) {
- if (mant[i] & bit) {
-    mant[i] &= ~bit;
-    ROUND_COLLECT_BITS;
-    mant[i] |= bit;
-    if (m) {
- ROUND_ABS_UP;
-    } else {
- if (test_bit(mant, bits-1)) {
-    ROUND_ABS_UP;
- } else {
-    ROUND_ABS_DOWN;
- }
-    }
- } else {
-    ROUND_ABS_DOWN;
- }
+        if (mant[i] & bit) {
+            mant[i] &= ~bit;
+            ROUND_COLLECT_BITS;
+            mant[i] |= bit;
+            if (m) {
+                ROUND_ABS_UP;
+            } else {
+                if (test_bit(mant, bits-1)) {
+                    ROUND_ABS_UP;
+                } else {
+                    ROUND_ABS_DOWN;
+                }
+            }
+        } else {
+            ROUND_ABS_DOWN;
+        }
     } else if (rc == FLOAT_RC_ZERO ||
-       rc == (minus ? FLOAT_RC_UP : FLOAT_RC_DOWN)) {
- ROUND_ABS_DOWN;
+               rc == (minus ? FLOAT_RC_UP : FLOAT_RC_DOWN)) {
+        ROUND_ABS_DOWN;
     } else {
- /* rc == (minus ? FLOAT_RC_DOWN : FLOAT_RC_UP) */
- /* Round toward +/- infinity */
- ROUND_COLLECT_BITS;
- if (m) {
-    ROUND_ABS_UP;
- } else {
-    ROUND_ABS_DOWN;
- }
+        /* rc == (minus ? FLOAT_RC_DOWN : FLOAT_RC_UP) */
+        /* Round toward +/- infinity */
+        ROUND_COLLECT_BITS;
+        if (m) {
+            ROUND_ABS_UP;
+        } else {
+            ROUND_ABS_DOWN;
+        }
     }
     return false;
 }
@@ -510,7 +510,7 @@ static unsigned int hexval(char c)
 
 /* Handle floating-point numbers with radix 2^bits and binary exponent */
 static bool ieee_flconvert_bin(const char *string, int bits,
-       fp_limb *mant, int32_t *exponent)
+                               fp_limb *mant, int32_t *exponent)
 {
     static const int log2tbl[16] =
         { -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3 };
@@ -567,14 +567,14 @@ static bool ieee_flconvert_bin(const char *string, int bits,
                     twopwr -= bits;
             }
         } else if (c == 'p' || c == 'P') {
-    int32_t e;
-    e = read_exponent(string, 20000);
-    if (e == INT32_MAX)
- return false;
-    twopwr += e;
+            int32_t e;
+            e = read_exponent(string, 20000);
+            if (e == INT32_MAX)
+                return false;
+            twopwr += e;
             break;
- } else if (c == '_') {
-    /* ignore */
+        } else if (c == '_') {
+            /* ignore */
         } else {
             error(ERR_NONFATAL|ERR_PASS1,
                   "floating-point constant: `%c' is invalid character", c);
@@ -606,20 +606,20 @@ static void ieee_shr(fp_limb *mant, int i)
     offs = i/LIMB_BITS;
 
     if (sr == 0) {
- if (offs)
-    for (j = MANT_LIMBS-1; j >= offs; j--)
- mant[j] = mant[j-offs];
+        if (offs)
+            for (j = MANT_LIMBS-1; j >= offs; j--)
+                mant[j] = mant[j-offs];
     } else {
- n = mant[MANT_LIMBS-1-offs] >> sr;
- for (j = MANT_LIMBS-1; j > offs; j--) {
-    m = mant[j-offs-1];
-    mant[j] = (m << sl) | n;
-    n = m >> sr;
- }
- mant[j--] = n;
+        n = mant[MANT_LIMBS-1-offs] >> sr;
+        for (j = MANT_LIMBS-1; j > offs; j--) {
+            m = mant[j-offs-1];
+            mant[j] = (m << sl) | n;
+            n = m >> sr;
+        }
+        mant[j--] = n;
     }
     while (j >= 0)
- mant[j--] = 0;
+        mant[j--] = 0;
 }
 
 /* Produce standard IEEE formats, with implicit or explicit integer
@@ -633,7 +633,7 @@ static void ieee_shr(fp_limb *mant, int i)
 struct ieee_format {
     int bytes;
     int mantissa;               /* Fractional bits in the mantissa */
-    int explicit; /* Explicit integer */
+    int explicit;               /* Explicit integer */
     int exponent;               /* Bits in the exponent */
 };
 
@@ -666,54 +666,54 @@ enum floats {
 };
 
 static int to_packed_bcd(const char *str, const char *p,
- int s, uint8_t *result,
- const struct ieee_format *fmt)
+                         int s, uint8_t *result,
+                         const struct ieee_format *fmt)
 {
     int n = 0;
     char c;
     int tv = -1;
 
     if (fmt != &ieee_80) {
- error(ERR_NONFATAL|ERR_PASS1,
-      "packed BCD requires an 80-bit format");
- return 0;
+        error(ERR_NONFATAL|ERR_PASS1,
+              "packed BCD requires an 80-bit format");
+        return 0;
     }
 
     while (p >= str) {
- c = *p--;
- if (c >= '0' && c <= '9') {
-    if (tv < 0) {
- if (n == 9) {
-    error(ERR_WARNING|ERR_PASS1,
-  "packed BCD truncated to 18 digits");
- }
- tv = c-'0';
-    } else {
- if (n < 9)
-    *result++ = tv + ((c-'0') << 4);
- n++;
- tv = -1;
-    }
- } else if (c == '_') {
-    /* do nothing */
- } else {
-    error(ERR_NONFATAL|ERR_PASS1,
-  "invalid character `%c' in packed BCD constant", c);
-    return 0;
- }
+        c = *p--;
+        if (c >= '0' && c <= '9') {
+            if (tv < 0) {
+                if (n == 9) {
+                    error(ERR_WARNING|ERR_PASS1,
+                          "packed BCD truncated to 18 digits");
+                }
+                tv = c-'0';
+            } else {
+                if (n < 9)
+                    *result++ = tv + ((c-'0') << 4);
+                n++;
+                tv = -1;
+            }
+        } else if (c == '_') {
+            /* do nothing */
+        } else {
+            error(ERR_NONFATAL|ERR_PASS1,
+                  "invalid character `%c' in packed BCD constant", c);
+            return 0;
+        }
     }
     if (tv >= 0) {
- if (n < 9)
-    *result++ = tv;
- n++;
+        if (n < 9)
+            *result++ = tv;
+        n++;
     }
     while (n < 9) {
- *result++ = 0;
- n++;
+        *result++ = 0;
+        n++;
     }
     *result = (s < 0) ? 0x80 : 0;
 
-    return 1; /* success */
+    return 1;                   /* success */
 }
 
 static int to_float(const char *str, int s, uint8_t *result,
@@ -723,7 +723,7 @@ static int to_float(const char *str, int s, uint8_t *result,
     int32_t exponent = 0;
     const int32_t expmax = 1 << (fmt->exponent - 1);
     fp_limb one_mask = LIMB_TOP_BIT >>
- ((fmt->exponent+fmt->explicit) % LIMB_BITS);
+        ((fmt->exponent+fmt->explicit) % LIMB_BITS);
     const int one_pos = (fmt->exponent+fmt->explicit)/LIMB_BITS;
     int i;
     int shift;
@@ -734,169 +734,169 @@ static int to_float(const char *str, int s, uint8_t *result,
     const char *strend;
 
     if (!str[0]) {
- error(ERR_PANIC,
-      "internal errror: empty string passed to float_const");
- return 0;
+        error(ERR_PANIC,
+              "internal errror: empty string passed to float_const");
+        return 0;
     }
 
     strend = strchr(str, '\0');
     if (strend[-1] == 'P' || strend[-1] == 'p')
- return to_packed_bcd(str, strend-2, s, result, fmt);
+        return to_packed_bcd(str, strend-2, s, result, fmt);
 
     if (str[0] == '_') {
- /* Special tokens */
+        /* Special tokens */
 
         switch (str[2]) {
         case 'n':              /* __nan__ */
         case 'N':
         case 'q':              /* __qnan__ */
         case 'Q':
-    type = FL_QNAN;
+            type = FL_QNAN;
             break;
         case 's':              /* __snan__ */
         case 'S':
-    type = FL_SNAN;
+            type = FL_SNAN;
             break;
         case 'i':              /* __infinity__ */
         case 'I':
-    type = FL_INFINITY;
+            type = FL_INFINITY;
+            break;
+        default:
+            error(ERR_NONFATAL|ERR_PASS1,
+                  "internal error: unknown FP constant token `%s'\n", str);
+            type = FL_QNAN;
             break;
- default:
-    error(ERR_NONFATAL|ERR_PASS1,
-  "internal error: unknown FP constant token `%s'\n", str);
-    type = FL_QNAN;
-    break;
         }
     } else {
         if (str[0] == '0') {
-    switch (str[1]) {
-    case 'x': case 'X':
-    case 'h': case 'H':
- ok = ieee_flconvert_bin(str+2, 4, mant, &exponent);
- break;
-    case 'o': case 'O':
-    case 'q': case 'Q':
- ok = ieee_flconvert_bin(str+2, 3, mant, &exponent);
- break;
-    case 'b': case 'B':
-    case 'y': case 'Y':
- ok = ieee_flconvert_bin(str+2, 1, mant, &exponent);
- break;
-    case 'd': case 'D':
-    case 't': case 'T':
- ok = ieee_flconvert(str+2, mant, &exponent);
- break;
-    case 'p': case 'P':
- return to_packed_bcd(str+2, strend-1, s, result, fmt);
-    default:
- /* Leading zero was just a zero? */
- ok = ieee_flconvert(str, mant, &exponent);
- break;
-    }
- } else if (str[0] == '$') {
-    ok = ieee_flconvert_bin(str+1, 4, mant, &exponent);
- } else {
+            switch (str[1]) {
+            case 'x': case 'X':
+            case 'h': case 'H':
+                ok = ieee_flconvert_bin(str+2, 4, mant, &exponent);
+                break;
+            case 'o': case 'O':
+            case 'q': case 'Q':
+                ok = ieee_flconvert_bin(str+2, 3, mant, &exponent);
+                break;
+            case 'b': case 'B':
+            case 'y': case 'Y':
+                ok = ieee_flconvert_bin(str+2, 1, mant, &exponent);
+                break;
+            case 'd': case 'D':
+            case 't': case 'T':
+                ok = ieee_flconvert(str+2, mant, &exponent);
+                break;
+            case 'p': case 'P':
+                return to_packed_bcd(str+2, strend-1, s, result, fmt);
+            default:
+                /* Leading zero was just a zero? */
+                ok = ieee_flconvert(str, mant, &exponent);
+                break;
+            }
+        } else if (str[0] == '$') {
+            ok = ieee_flconvert_bin(str+1, 4, mant, &exponent);
+        } else {
             ok = ieee_flconvert(str, mant, &exponent);
- }
+        }
 
- if (!ok) {
-    type = FL_QNAN;
- } else if (mant[0] & LIMB_TOP_BIT) {
+        if (!ok) {
+            type = FL_QNAN;
+        } else if (mant[0] & LIMB_TOP_BIT) {
             /*
              * Non-zero.
              */
             exponent--;
             if (exponent >= 2 - expmax && exponent <= expmax) {
- type = FL_NORMAL;
+                type = FL_NORMAL;
             } else if (exponent > 0) {
- if (pass0 == 1)
-    error(ERR_WARNING|ERR_WARN_FL_OVERFLOW|ERR_PASS1,
-  "overflow in floating-point constant");
- type = FL_INFINITY;
-    } else {
- /* underflow or denormal; the denormal code handles
-   actual underflow. */
- type = FL_DENORMAL;
-    }
- } else {
-    /* Zero */
-    type = FL_ZERO;
- }
+                if (pass0 == 1)
+                    error(ERR_WARNING|ERR_WARN_FL_OVERFLOW|ERR_PASS1,
+                          "overflow in floating-point constant");
+                type = FL_INFINITY;
+            } else {
+                /* underflow or denormal; the denormal code handles
+                   actual underflow. */
+                type = FL_DENORMAL;
+            }
+        } else {
+            /* Zero */
+            type = FL_ZERO;
+        }
     }
 
     switch (type) {
     case FL_ZERO:
     zero:
- memset(mant, 0, sizeof mant);
- break;
+        memset(mant, 0, sizeof mant);
+        break;
 
     case FL_DENORMAL:
     {
- shift = -(exponent + expmax - 2 - fmt->exponent)
-    + fmt->explicit;
- ieee_shr(mant, shift);
- ieee_round(minus, mant, bits);
- if (mant[one_pos] & one_mask) {
-    /* One's position is set, we rounded up into normal range */
-    exponent = 1;
-    if (!fmt->explicit)
- mant[one_pos] &= ~one_mask; /* remove explicit one */
-    mant[0] |= exponent << (LIMB_BITS-1 - fmt->exponent);
- } else {
-    if (daz || is_zero(mant)) {
- /* Flush denormals to zero */
- error(ERR_WARNING|ERR_WARN_FL_UNDERFLOW|ERR_PASS1,
-      "underflow in floating-point constant");
- goto zero;
-    } else {
- error(ERR_WARNING|ERR_WARN_FL_DENORM|ERR_PASS1,
-      "denormal floating-point constant");
-    }
- }
- break;
+        shift = -(exponent + expmax - 2 - fmt->exponent)
+            + fmt->explicit;
+        ieee_shr(mant, shift);
+        ieee_round(minus, mant, bits);
+        if (mant[one_pos] & one_mask) {
+            /* One's position is set, we rounded up into normal range */
+            exponent = 1;
+            if (!fmt->explicit)
+                mant[one_pos] &= ~one_mask;     /* remove explicit one */
+            mant[0] |= exponent << (LIMB_BITS-1 - fmt->exponent);
+        } else {
+            if (daz || is_zero(mant)) {
+                /* Flush denormals to zero */
+                error(ERR_WARNING|ERR_WARN_FL_UNDERFLOW|ERR_PASS1,
+                      "underflow in floating-point constant");
+                goto zero;
+            } else {
+                error(ERR_WARNING|ERR_WARN_FL_DENORM|ERR_PASS1,
+                      "denormal floating-point constant");
+            }
+        }
+        break;
     }
 
     case FL_NORMAL:
- exponent += expmax - 1;
- ieee_shr(mant, fmt->exponent+fmt->explicit);
- ieee_round(minus, mant, bits);
- /* did we scale up by one? */
- if (test_bit(mant, fmt->exponent+fmt->explicit-1)) {
-    ieee_shr(mant, 1);
-    exponent++;
-    if (exponent >= (expmax << 1)-1) {
-    error(ERR_WARNING|ERR_WARN_FL_OVERFLOW|ERR_PASS1,
-  "overflow in floating-point constant");
- type = FL_INFINITY;
- goto overflow;
-    }
- }
-
- if (!fmt->explicit)
-    mant[one_pos] &= ~one_mask; /* remove explicit one */
- mant[0] |= exponent << (LIMB_BITS-1 - fmt->exponent);
- break;
+        exponent += expmax - 1;
+        ieee_shr(mant, fmt->exponent+fmt->explicit);
+        ieee_round(minus, mant, bits);
+        /* did we scale up by one? */
+        if (test_bit(mant, fmt->exponent+fmt->explicit-1)) {
+            ieee_shr(mant, 1);
+            exponent++;
+            if (exponent >= (expmax << 1)-1) {
+                    error(ERR_WARNING|ERR_WARN_FL_OVERFLOW|ERR_PASS1,
+                          "overflow in floating-point constant");
+                type = FL_INFINITY;
+                goto overflow;
+            }
+        }
+
+        if (!fmt->explicit)
+            mant[one_pos] &= ~one_mask; /* remove explicit one */
+        mant[0] |= exponent << (LIMB_BITS-1 - fmt->exponent);
+        break;
 
     case FL_INFINITY:
     case FL_QNAN:
     case FL_SNAN:
     overflow:
- memset(mant, 0, sizeof mant);
- mant[0] = (((fp_limb)1 << fmt->exponent)-1)
-    << (LIMB_BITS-1 - fmt->exponent);
- if (fmt->explicit)
-    mant[one_pos] |= one_mask;
- if (type == FL_QNAN)
-    set_bit(mant, fmt->exponent+fmt->explicit+1);
- else if (type == FL_SNAN)
-    set_bit(mant, fmt->exponent+fmt->explicit+fmt->mantissa);
- break;
+        memset(mant, 0, sizeof mant);
+        mant[0] = (((fp_limb)1 << fmt->exponent)-1)
+            << (LIMB_BITS-1 - fmt->exponent);
+        if (fmt->explicit)
+            mant[one_pos] |= one_mask;
+        if (type == FL_QNAN)
+            set_bit(mant, fmt->exponent+fmt->explicit+1);
+        else if (type == FL_SNAN)
+            set_bit(mant, fmt->exponent+fmt->explicit+fmt->mantissa);
+        break;
     }
 
     mant[0] |= minus ? LIMB_TOP_BIT : 0;
 
     for (i = fmt->bytes - 1; i >= 0; i--)
- *result++ = mant[i/LIMB_BYTES] >> (((LIMB_BYTES-1)-(i%LIMB_BYTES))*8);
+        *result++ = mant[i/LIMB_BYTES] >> (((LIMB_BYTES-1)-(i%LIMB_BYTES))*8);
 
     return 1;                   /* success */
 }
@@ -929,28 +929,28 @@ int float_const(const char *number, int sign, uint8_t *result,
 int float_option(const char *option)
 {
     if (!nasm_stricmp(option, "daz")) {
- daz = true;
- return 0;
+        daz = true;
+        return 0;
     } else if (!nasm_stricmp(option, "nodaz")) {
- daz = false;
- return 0;
+        daz = false;
+        return 0;
     } else if (!nasm_stricmp(option, "near")) {
- rc = FLOAT_RC_NEAR;
- return 0;
+        rc = FLOAT_RC_NEAR;
+        return 0;
     } else if (!nasm_stricmp(option, "down")) {
- rc = FLOAT_RC_DOWN;
- return 0;
+        rc = FLOAT_RC_DOWN;
+        return 0;
     } else if (!nasm_stricmp(option, "up")) {
- rc = FLOAT_RC_UP;
- return 0;
+        rc = FLOAT_RC_UP;
+        return 0;
     } else if (!nasm_stricmp(option, "zero")) {
- rc = FLOAT_RC_ZERO;
- return 0;
+        rc = FLOAT_RC_ZERO;
+        return 0;
     } else if (!nasm_stricmp(option, "default")) {
- rc = FLOAT_RC_NEAR;
- daz = false;
- return 0;
+        rc = FLOAT_RC_NEAR;
+        daz = false;
+        return 0;
     } else {
- return -1; /* Unknown option */
+        return -1;              /* Unknown option */
     }
 }
diff --git a/hashtbl.c b/hashtbl.c
index fa95478..2b55755 100644
--- a/hashtbl.c
+++ b/hashtbl.c
@@ -1,5 +1,5 @@
 /* ----------------------------------------------------------------------- *
- *  
+ *
  *   Copyright 1996-2009 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
@@ -14,7 +14,7 @@
  *     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 COPYRIGHT HOLDERS AND
  *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -44,7 +44,7 @@
 #include "nasm.h"
 #include "hashtbl.h"
 
-#define HASH_MAX_LOAD 2 /* Higher = more memory-efficient, slower */
+#define HASH_MAX_LOAD   2 /* Higher = more memory-efficient, slower */
 
 static struct hash_tbl_node *alloc_table(size_t newsize)
 {
@@ -75,26 +75,26 @@ void hash_init(struct hash_table *head, size_t size)
  * structure.
  */
 void **hash_find(struct hash_table *head, const char *key,
- struct hash_insert *insert)
+                 struct hash_insert *insert)
 {
     struct hash_tbl_node *np;
     uint64_t hash = crc64(CRC64_INIT, key);
     struct hash_tbl_node *tbl = head->table;
     size_t mask = head->size-1;
     size_t pos  = hash & mask;
-    size_t inc  = ((hash >> 32) & mask) | 1; /* Always odd */
+    size_t inc  = ((hash >> 32) & mask) | 1;    /* Always odd */
 
     while ((np = &tbl[pos])->key) {
- if (hash == np->hash && !strcmp(key, np->key))
-    return &np->data;
- pos = (pos+inc) & mask;
+        if (hash == np->hash && !strcmp(key, np->key))
+            return &np->data;
+        pos = (pos+inc) & mask;
     }
 
     /* Not found.  Store info for insert if requested. */
     if (insert) {
- insert->head  = head;
- insert->hash  = hash;
- insert->where = np;
+        insert->head  = head;
+        insert->hash  = hash;
+        insert->where = np;
     }
     return NULL;
 }
@@ -103,26 +103,26 @@ void **hash_find(struct hash_table *head, const char *key,
  * Same as hash_find, but for case-insensitive hashing.
  */
 void **hash_findi(struct hash_table *head, const char *key,
-  struct hash_insert *insert)
+                  struct hash_insert *insert)
 {
     struct hash_tbl_node *np;
     uint64_t hash = crc64i(CRC64_INIT, key);
     struct hash_tbl_node *tbl = head->table;
     size_t mask = head->size-1;
     size_t pos  = hash & mask;
-    size_t inc  = ((hash >> 32) & mask) | 1; /* Always odd */
+    size_t inc  = ((hash >> 32) & mask) | 1;    /* Always odd */
 
     while ((np = &tbl[pos])->key) {
- if (hash == np->hash && !nasm_stricmp(key, np->key))
-    return &np->data;
- pos = (pos+inc) & mask;
+        if (hash == np->hash && !nasm_stricmp(key, np->key))
+            return &np->data;
+        pos = (pos+inc) & mask;
     }
 
     /* Not found.  Store info for insert if requested. */
     if (insert) {
- insert->head  = head;
- insert->hash  = hash;
- insert->where = np;
+        insert->head  = head;
+        insert->hash  = hash;
+        insert->where = np;
     }
     return NULL;
 }
@@ -143,35 +143,35 @@ void **hash_add(struct hash_insert *insert, const char *key, void *data)
     np->data = data;
 
     if (++head->load > head->max_load) {
- /* Need to expand the table */
- size_t newsize = head->size << 1;
- struct hash_tbl_node *newtbl = alloc_table(newsize);
- size_t mask = newsize-1;
-
- if (head->table) {
-    struct hash_tbl_node *op, *xp;
-    size_t i;
-
-    /* Rebalance all the entries */
-    for (i = 0, op = head->table; i < head->size; i++, op++) {
- if (op->key) {
-    size_t pos = op->hash & mask;
-    size_t inc = ((op->hash >> 32) & mask) | 1;
-
-    while ((xp = &newtbl[pos])->key)
- pos = (pos+inc) & mask;
-
-    *xp = *op;
-    if (op == np)
- np = xp;
- }
-    }
-    nasm_free(head->table);
- }
-
- head->table    = newtbl;
- head->size     = newsize;
- head->max_load = newsize*(HASH_MAX_LOAD-1)/HASH_MAX_LOAD;
+        /* Need to expand the table */
+        size_t newsize = head->size << 1;
+        struct hash_tbl_node *newtbl = alloc_table(newsize);
+        size_t mask = newsize-1;
+
+        if (head->table) {
+            struct hash_tbl_node *op, *xp;
+            size_t i;
+
+            /* Rebalance all the entries */
+            for (i = 0, op = head->table; i < head->size; i++, op++) {
+                if (op->key) {
+                    size_t pos = op->hash & mask;
+                    size_t inc = ((op->hash >> 32) & mask) | 1;
+
+                    while ((xp = &newtbl[pos])->key)
+                        pos = (pos+inc) & mask;
+
+                    *xp = *op;
+                    if (op == np)
+                        np = xp;
+                }
+            }
+            nasm_free(head->table);
+        }
+
+        head->table    = newtbl;
+        head->size     = newsize;
+        head->max_load = newsize*(HASH_MAX_LOAD-1)/HASH_MAX_LOAD;
     }
 
     return &np->data;
@@ -183,31 +183,31 @@ void **hash_add(struct hash_insert *insert, const char *key, void *data)
  * or NULL on failure.
  */
 void *hash_iterate(const struct hash_table *head,
-   struct hash_tbl_node **iterator,
-   const char **key)
+                   struct hash_tbl_node **iterator,
+                   const char **key)
 {
     struct hash_tbl_node *np = *iterator;
     struct hash_tbl_node *ep = head->table + head->size;
 
     if (!np) {
- np = head->table;
- if (!np)
-    return NULL; /* Uninitialized table */
+        np = head->table;
+        if (!np)
+            return NULL;        /* Uninitialized table */
     }
 
     while (np < ep) {
- if (np->key) {
-    *iterator = np+1;
-    if (key)
- *key = np->key;
-    return np->data;
- }
- np++;
+        if (np->key) {
+            *iterator = np+1;
+            if (key)
+                *key = np->key;
+            return np->data;
+        }
+        np++;
     }
 
     *iterator = NULL;
     if (key)
- *key = NULL;
+        *key = NULL;
     return NULL;
 }
 
diff --git a/nasm.c b/nasm.c
index 7bf7c57..ed0a2cb 100644
--- a/nasm.c
+++ b/nasm.c
@@ -497,12 +497,8 @@ int main(int argc, char **argv)
 static char *get_param(char *p, char *q, bool *advance)
 {
     *advance = false;
-    if (p[2]) {                 /* the parameter's in the option */
-        p += 2;
-        while (nasm_isspace(*p))
-            p++;
-        return p;
-    }
+    if (p[2]) /* the parameter's in the option */
+        return nasm_skip_spaces(p + 2);
     if (q && q[0]) {
         *advance = true;
         return q;
@@ -1023,9 +1019,7 @@ static void process_respfile(FILE * rfile)
         while (p > buffer && nasm_isspace(p[-1]))
             *--p = '\0';
 
-        p = buffer;
-        while (nasm_isspace(*p))
-            p++;
+        p = nasm_skip_spaces(buffer);
 
         if (process_arg(prevarg, p))
             *p = '\0';
@@ -1337,8 +1331,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
  break;
     }
     if (*p) {
- while (*p && nasm_isspace(*p))
-    *p++ = '\0';
+                        p = nasm_zap_spaces(p);
  q = p;
  while (*q && *q != ':')
     q++;
@@ -1426,16 +1419,13 @@ static void assemble_file(char *fname, StrList **depend_ptr)
    "DEBUG identifier too long");
  break;
     }
-                    while (*p && nasm_isspace(*p))
-                        p++;
+                    p = nasm_skip_spaces(p);
                     if (pass0 == 2)
                         dfmt->debug_directive(debugid, p);
                     break;
  }
                 case D_WARNING: /* [WARNING {+|-|*}warn-name] */
-    while (*value && nasm_isspace(*value))
- value++;
-
+                    value = nasm_skip_spaces(value);
     switch(*value) {
     case '-': validid = 0; value++; break;
     case '+': validid = 1; value++; break;
@@ -1467,9 +1457,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                     cpu = get_cpu(value);
                     break;
                 case D_LIST: /* [LIST {+|-}] */
-                    while (*value && nasm_isspace(*value))
-                        value++;
-
+                    value = nasm_skip_spaces(value);
                     if (*value == '+') {
                         user_nolist = 0;
                     } else {
@@ -1772,47 +1760,38 @@ static enum directives getkw(char **directive, char **value)
 {
     char *p, *q, *buf;
 
-    buf = *directive;
-
-    /*  allow leading spaces or tabs */
-    while (*buf == ' ' || *buf == '\t')
-        buf++;
+    buf = nasm_skip_spaces(*directive);
 
+    /* it should be enclosed in [ ] */
     if (*buf != '[')
-        return 0;
-
-    p = buf;
-
-    while (*p && *p != ']')
-        p++;
+        return D_NONE;
+    q = strchr(buf, ']');
+    if (!q)
+        return D_NONE;
+
+    /* stip off the comments */
+    p = strchr(buf, ';');
+    if (p) {
+        if (p < q) /* ouch! somwhere inside */
+            return D_NONE;
+        *p = '\0';
+    }
 
-    if (!*p)
-        return 0;
+    /* no brace, no trailing spaces */
+    *q = '\0';
+    nasm_zap_spaces_rev(--q);
 
-    q = p++;
+    /* directive */
+    p = nasm_skip_spaces(++buf);
+    q = nasm_skip_word(p);
+    if (!q)
+        return D_NONE; /* sigh... no value there */
+    *q = '\0';
+    *directive = p;
 
-    while (*p && *p != ';') {
-        if (!nasm_isspace(*p))
-            return 0;
-        p++;
-    }
-    q[1] = '\0';
-
-    *directive = p = buf + 1;
-    while (*buf && *buf != ' ' && *buf != ']' && *buf != '\t')
-        buf++;
-    if (*buf == ']') {
-        *buf = '\0';
-        *value = buf;
-    } else {
-        *buf++ = '\0';
-        while (nasm_isspace(*buf))
-            buf++;              /* beppu - skip leading whitespace */
-        *value = buf;
-        while (*buf != ']')
-            buf++;
-        *buf++ = '\0';
-    }
+    /* and value finally */
+    p = nasm_skip_spaces(++q);
+    *value = p;
 
     return find_directive(*directive);
 }
diff --git a/nasm.h b/nasm.h
index 9e233fc..2982101 100644
--- a/nasm.h
+++ b/nasm.h
@@ -539,6 +539,8 @@ typedef uint32_t opflags_t;
 #define MEMORY 0x0000c000U
 #define REGMEM 0x00008000U   /* for r/m, ie EA, operands */
 
+#define is_class(class, op)     (!((opflags_t)(class) & ~(opflags_t)(op)))
+
 /* Register classes */
 #define REG_EA 0x00009000U   /* 'normal' reg, qualifies as EA */
 #define RM_GPR 0x00208000U   /* integer operand */
@@ -682,7 +684,7 @@ enum eval_hint {                /* values for `hinttype' */
 };
 
 typedef struct operand { /* operand to an instruction */
-    int32_t type;               /* type of operand */
+    opflags_t type;             /* type of operand */
     int disp_size;              /* 0 means default; 16; 32; 64 */
     enum reg_enum basereg, indexreg; /* address registers */
     int scale; /* index scale */
diff --git a/nasmlib.c b/nasmlib.c
index 35aa505..79935ad 100644
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -653,3 +653,39 @@ char *nasm_strcat(const char *one, const char *two)
     strcpy(rslt + l1, two);
     return rslt;
 }
+
+/* skip leading spaces */
+char *nasm_skip_spaces(const char *p)
+{
+    if (p)
+        while (*p && nasm_isspace(*p))
+            p++;
+    return (char *)p;
+}
+
+/* skip leading non-spaces */
+char *nasm_skip_word(const char *p)
+{
+    if (p)
+        while (*p && !nasm_isspace(*p))
+            p++;
+    return (char *)p;
+}
+
+/* zap leading spaces with zero */
+char *nasm_zap_spaces(char *p)
+{
+    if (p)
+        while (*p && nasm_isspace(*p))
+            *p++ = 0x0;
+    return p;
+}
+
+/* zap spaces with zero in reverse order */
+char *nasm_zap_spaces_rev(char *p)
+{
+    if (p)
+        while (*p && nasm_isspace(*p))
+            *p-- = 0x0;
+    return p;
+}
diff --git a/nasmlib.h b/nasmlib.h
index c42c3fd..f3128b5 100644
--- a/nasmlib.h
+++ b/nasmlib.h
@@ -1,5 +1,5 @@
 /* ----------------------------------------------------------------------- *
- *  
+ *
  *   Copyright 1996-2009 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
@@ -14,7 +14,7 @@
  *     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 COPYRIGHT HOLDERS AND
  *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -31,8 +31,8 @@
  *
  * ----------------------------------------------------------------------- */
 
-/*
- * nasmlib.h header file for nasmlib.c
+/*
+ * nasmlib.h    header file for nasmlib.c
  */
 
 #ifndef NASM_NASMLIB_H
@@ -96,41 +96,41 @@ void nasm_set_verror(vefunc);
  * argument to an efunc.
  */
 
-#define ERR_DEBUG 0x00000008      /* put out debugging message */
-#define ERR_WARNING 0x00000000      /* warn only: no further action */
-#define ERR_NONFATAL 0x00000001      /* terminate assembly after phase */
-#define ERR_FATAL 0x00000002      /* instantly fatal: exit with error */
-#define ERR_PANIC 0x00000003      /* internal error: panic instantly
+#define ERR_DEBUG       0x00000008      /* put out debugging message */
+#define ERR_WARNING     0x00000000      /* warn only: no further action */
+#define ERR_NONFATAL    0x00000001      /* terminate assembly after phase */
+#define ERR_FATAL       0x00000002      /* instantly fatal: exit with error */
+#define ERR_PANIC       0x00000003      /* internal error: panic instantly
                                          * and dump core for reference */
-#define ERR_MASK 0x0000000F      /* mask off the above codes */
-#define ERR_NOFILE 0x00000010      /* don't give source file name/line */
-#define ERR_USAGE 0x00000020      /* print a usage message */
-#define ERR_PASS1 0x00000040      /* only print this error on pass one */
-#define ERR_PASS2 0x00000080
-#define ERR_NO_SEVERITY 0x00000100      /* suppress printing severity */
+#define ERR_MASK        0x0000000F      /* mask off the above codes */
+#define ERR_NOFILE      0x00000010      /* don't give source file name/line */
+#define ERR_USAGE       0x00000020      /* print a usage message */
+#define ERR_PASS1       0x00000040      /* only print this error on pass one */
+#define ERR_PASS2       0x00000080
+#define ERR_NO_SEVERITY 0x00000100      /* suppress printing severity */
 
 /*
  * These codes define specific types of suppressible warning.
  */
 
-#define ERR_WARN_MASK 0xFFFFF000      /* the mask for this feature */
-#define ERR_WARN_SHR 12               /* how far to shift right */
+#define ERR_WARN_MASK   0xFFFFF000      /* the mask for this feature */
+#define ERR_WARN_SHR    12              /* how far to shift right */
 
 #define WARN(x) ((x) << ERR_WARN_SHR)
 
-#define ERR_WARN_MNP WARN( 1) /* macro-num-parameters warning */
-#define ERR_WARN_MSR WARN( 2) /* macro self-reference */
-#define ERR_WARN_MDP WARN( 3) /* macro default parameters check */
-#define ERR_WARN_OL WARN( 4) /* orphan label (no colon, and
+#define ERR_WARN_MNP            WARN( 1) /* macro-num-parameters warning */
+#define ERR_WARN_MSR            WARN( 2) /* macro self-reference */
+#define ERR_WARN_MDP            WARN( 3) /* macro default parameters check */
+#define ERR_WARN_OL             WARN( 4) /* orphan label (no colon, and
                                           * alone on line) */
-#define ERR_WARN_NOV WARN( 5) /* numeric overflow */
-#define ERR_WARN_GNUELF WARN( 6) /* using GNU ELF extensions */
-#define ERR_WARN_FL_OVERFLOW WARN( 7) /* FP overflow */
-#define ERR_WARN_FL_DENORM WARN( 8) /* FP denormal */
-#define ERR_WARN_FL_UNDERFLOW WARN( 9) /* FP underflow */
-#define ERR_WARN_FL_TOOLONG WARN(10) /* FP too many digits */
-#define ERR_WARN_USER WARN(11) /* %warning directives */
-#define ERR_WARN_MAX 11 /* the highest numbered one */
+#define ERR_WARN_NOV            WARN( 5) /* numeric overflow */
+#define ERR_WARN_GNUELF         WARN( 6) /* using GNU ELF extensions */
+#define ERR_WARN_FL_OVERFLOW    WARN( 7) /* FP overflow */
+#define ERR_WARN_FL_DENORM      WARN( 8) /* FP denormal */
+#define ERR_WARN_FL_UNDERFLOW   WARN( 9) /* FP underflow */
+#define ERR_WARN_FL_TOOLONG     WARN(10) /* FP too many digits */
+#define ERR_WARN_USER           WARN(11) /* %warning directives */
+#define ERR_WARN_MAX            11       /* the highest numbered one */
 
 /*
  * Wrappers around malloc, realloc and free. nasm_malloc will
@@ -166,10 +166,10 @@ char *nasm_strndup_log(const char *, int, const char *, size_t);
  * NASM assert failure
  */
 no_return nasm_assert_failed(const char *, int, const char *);
-#define nasm_assert(x) \
-    do { \
- if (unlikely(!(x))) \
-    nasm_assert_failed(__FILE__,__LINE__,#x); \
+#define nasm_assert(x)                                          \
+    do {                                                        \
+        if (unlikely(!(x)))                                     \
+            nasm_assert_failed(__FILE__,__LINE__,#x);           \
     } while (0)
 
 /*
@@ -243,11 +243,11 @@ void standard_extension(char *inname, char *outname, char *extension);
  *  list_for_each - regular iterator over list
  *  list_for_each_safe - the same but safe against list items removal
  */
-#define list_for_each(pos, head) \
- for (pos = head; pos; pos = pos->next)
-#define list_for_each_safe(pos, n, head) \
- for (pos = head, n = (pos ? pos->next : NULL); pos; \
- pos = n, n = (n ? n->next : NULL))
+#define list_for_each(pos, head)                        \
+    for (pos = head; pos; pos = pos->next)
+#define list_for_each_safe(pos, n, head)                \
+    for (pos = head, n = (pos ? pos->next : NULL); pos; \
+        pos = n, n = (n ? n->next : NULL))
 
 /*
  * some handy macros that will probably be of use in more than one
@@ -257,90 +257,90 @@ void standard_extension(char *inname, char *outname, char *extension);
 
 #if X86_MEMORY
 
-#define WRITECHAR(p,v) \
-    do { \
- *(uint8_t *)(p) = (v); \
- (p) += 1; \
+#define WRITECHAR(p,v)                          \
+    do {                                        \
+        *(uint8_t *)(p) = (v);                  \
+        (p) += 1;                               \
     } while (0)
 
-#define WRITESHORT(p,v) \
-    do { \
- *(uint16_t *)(p) = (v); \
- (p) += 2; \
+#define WRITESHORT(p,v)                         \
+    do {                                        \
+        *(uint16_t *)(p) = (v);                 \
+        (p) += 2;                               \
     } while (0)
 
-#define WRITELONG(p,v) \
-    do { \
- *(uint32_t *)(p) = (v); \
- (p) += 4; \
+#define WRITELONG(p,v)                          \
+    do {                                        \
+        *(uint32_t *)(p) = (v);                 \
+        (p) += 4;                               \
     } while (0)
 
-#define WRITEDLONG(p,v) \
-    do { \
- *(uint64_t *)(p) = (v); \
- (p) += 8; \
+#define WRITEDLONG(p,v)                         \
+    do {                                        \
+        *(uint64_t *)(p) = (v);                 \
+        (p) += 8;                               \
     } while (0)
 
-#define WRITEADDR(p,v,s) \
-    do { \
- uint64_t _wa_v = (v); \
- memcpy((p), &_wa_v, (s)); \
- (p) += (s); \
+#define WRITEADDR(p,v,s)                        \
+    do {                                        \
+        uint64_t _wa_v = (v);                   \
+        memcpy((p), &_wa_v, (s));               \
+        (p) += (s);                             \
     } while (0)
 
 #else /* !X86_MEMORY */
 
-#define WRITECHAR(p,v) \
-    do { \
- uint8_t *_wc_p = (uint8_t *)(p); \
- uint8_t _wc_v = (v); \
- _wc_p[0] = _wc_v; \
- (p) = (void *)(_wc_p + 1); \
+#define WRITECHAR(p,v)                          \
+    do {                                        \
+        uint8_t *_wc_p = (uint8_t *)(p);        \
+        uint8_t _wc_v = (v);                    \
+        _wc_p[0] = _wc_v;                       \
+        (p) = (void *)(_wc_p + 1);              \
     } while (0)
 
-#define WRITESHORT(p,v) \
-    do { \
- uint8_t *_ws_p = (uint8_t *)(p); \
- uint16_t _ws_v = (v); \
- _ws_p[0] = _ws_v; \
- _ws_p[1] = _ws_v >> 8; \
- (p) = (void *)(_ws_p + 2); \
+#define WRITESHORT(p,v)                         \
+    do {                                        \
+        uint8_t *_ws_p = (uint8_t *)(p);        \
+        uint16_t _ws_v = (v);                   \
+        _ws_p[0] = _ws_v;                       \
+        _ws_p[1] = _ws_v >> 8;                  \
+        (p) = (void *)(_ws_p + 2);              \
     } while (0)
 
-#define WRITELONG(p,v) \
-    do { \
- uint8_t *_wl_p = (uint8_t *)(p); \
- uint32_t _wl_v = (v); \
- _wl_p[0] = _wl_v; \
- _wl_p[1] = _wl_v >> 8; \
- _wl_p[2] = _wl_v >> 16; \
- _wl_p[3] = _wl_v >> 24; \
- (p) = (void *)(_wl_p + 4); \
+#define WRITELONG(p,v)                          \
+    do {                                        \
+        uint8_t *_wl_p = (uint8_t *)(p);        \
+        uint32_t _wl_v = (v);                   \
+        _wl_p[0] = _wl_v;                       \
+        _wl_p[1] = _wl_v >> 8;                  \
+        _wl_p[2] = _wl_v >> 16;                 \
+        _wl_p[3] = _wl_v >> 24;                 \
+        (p) = (void *)(_wl_p + 4);              \
     } while (0)
 
-#define WRITEDLONG(p,v) \
-    do { \
- uint8_t *_wq_p = (uint8_t *)(p); \
- uint64_t _wq_v = (v); \
- _wq_p[0] = _wq_v; \
- _wq_p[1] = _wq_v >> 8; \
- _wq_p[2] = _wq_v >> 16; \
- _wq_p[3] = _wq_v >> 24; \
- _wq_p[4] = _wq_v >> 32; \
- _wq_p[5] = _wq_v >> 40; \
- _wq_p[6] = _wq_v >> 48; \
- _wq_p[7] = _wq_v >> 56; \
- (p) = (void *)(_wq_p + 8); \
+#define WRITEDLONG(p,v)                         \
+    do {                                        \
+        uint8_t *_wq_p = (uint8_t *)(p);        \
+        uint64_t _wq_v = (v);                   \
+        _wq_p[0] = _wq_v;                       \
+        _wq_p[1] = _wq_v >> 8;                  \
+        _wq_p[2] = _wq_v >> 16;                 \
+        _wq_p[3] = _wq_v >> 24;                 \
+        _wq_p[4] = _wq_v >> 32;                 \
+        _wq_p[5] = _wq_v >> 40;                 \
+        _wq_p[6] = _wq_v >> 48;                 \
+        _wq_p[7] = _wq_v >> 56;                 \
+        (p) = (void *)(_wq_p + 8);              \
     } while (0)
 
-#define WRITEADDR(p,v,s) \
-    do { \
- int _wa_s = (s); \
- uint64_t _wa_v = (v); \
- while (_wa_s--) { \
-    WRITECHAR(p,_wa_v); \
-    _wa_v >>= 8; \
- } \
+#define WRITEADDR(p,v,s)                        \
+    do {                                        \
+        int _wa_s = (s);                        \
+        uint64_t _wa_v = (v);                   \
+        while (_wa_s--) {                       \
+            WRITECHAR(p,_wa_v);                 \
+            _wa_v >>= 8;                        \
+        }                                       \
     } while(0)
 
 #endif
@@ -377,10 +377,42 @@ int src_get(int32_t *xline, char **xname);
 
 char *nasm_strcat(const char *one, const char *two);
 
+char *nasm_skip_spaces(const char *p);
+char *nasm_skip_word(const char *p);
+char *nasm_zap_spaces(char *p);
+char *nasm_zap_spaces_rev(char *p);
+
 const char *prefix_name(int);
 
-#define ZERO_BUF_SIZE 4096
+#define ZERO_BUF_SIZE 4096
 extern const uint8_t zero_buffer[ZERO_BUF_SIZE];
 size_t fwritezero(size_t bytes, FILE *fp);
 
+static inline bool overflow_general(int64_t value, int bytes)
+{
+    int sbit = (bytes << 3) - 1;
+    int64_t vmax =  ((int64_t)2 << sbit) - 1;
+    int64_t vmin = -((int64_t)1 << sbit);
+
+    return value < vmin || value > vmax;
+}
+
+static inline bool overflow_signed(int64_t value, int bytes)
+{
+    int sbit = (bytes << 3) - 1;
+    int64_t vmax =  ((int64_t)1 << sbit) - 1;
+    int64_t vmin = -((int64_t)1 << sbit);
+
+    return value < vmin || value > vmax;
+}
+
+static inline bool overflow_unsigned(int64_t value, int bytes)
+{
+    int sbit = (bytes << 3) - 1;
+    int64_t vmax = ((int64_t)2 << sbit) - 1;
+    int64_t vmin = 0;
+
+    return value < vmin || value > vmax;
+}
+
 #endif
diff --git a/preproc.c b/preproc.c
index feccc33..dab0b2a 100644
--- a/preproc.c
+++ b/preproc.c
@@ -473,18 +473,15 @@ static Token *delete_Token(Token * t);
 static char *check_tasm_directive(char *line)
 {
     int32_t i, j, k, m, len;
-    char *p = line, *oldline, oldchar;
+    char *p, *q, *oldline, oldchar;
 
-    /* Skip whitespace */
-    while (nasm_isspace(*p) && *p != 0)
-        p++;
+    p = nasm_skip_spaces(line);
 
     /* Binary search for the directive name */
     i = -1;
     j = elements(tasm_directives);
-    len = 0;
-    while (!nasm_isspace(p[len]) && p[len] != 0)
-        len++;
+    q = nasm_skip_word(p);
+    len = q - p;
     if (len) {
         oldchar = p[len];
         p[len] = 0;
@@ -999,9 +996,7 @@ static Token *tokenize(char *line)
     }
         } else if (nasm_isspace(*p)) {
             type = TOK_WHITESPACE;
-            p++;
-            while (*p && nasm_isspace(*p))
-                p++;
+            p = nasm_skip_spaces(p);
             /*
              * Whitespace just before end-of-line is discarded by
              * pretending it's a comment; whitespace just before a

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Nasm-devel mailing list
Nasm-devel@...
https://lists.sourceforge.net/lists/listinfo/nasm-devel

Re: pull request v2

by H. Peter Anvin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 10/13/2009 08:49 AM, Cyrill Gorcunov wrote:
> Hi Peter,
>
> I've updated patches to eliminate is_REGISTER
> and friends. Also renamed nasm_get_word to
> nasm_skip_spaces. Didn't fix FPUREG yet,
> will fix later.
>
> Please take a look (the whole diff below).
>

Pulled.  I also tagged this as 2.08rc1, since we need to start make
forward progress on a 2.08 release given the fact that real people are
getting bitten by the export crash bug in 2.07.

I would also greatly appreciate it if someone could find the time and
update doc/changes.src with everything that has happened since 2.07.

        -hpa

--
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Nasm-devel mailing list
Nasm-devel@...
https://lists.sourceforge.net/lists/listinfo/nasm-devel

Re: pull request v2

by Cyrill Gorcunov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

[H. Peter Anvin - Tue, Oct 13, 2009 at 12:06:53PM -0700]
| On 10/13/2009 08:49 AM, Cyrill Gorcunov wrote:
| > Hi Peter,
| >
| > I've updated patches to eliminate is_REGISTER
| > and friends. Also renamed nasm_get_word to
| > nasm_skip_spaces. Didn't fix FPUREG yet,
| > will fix later.
| >
| > Please take a look (the whole diff below).
| >
|
| Pulled.  I also tagged this as 2.08rc1, since we need to start make
| forward progress on a 2.08 release given the fact that real people are
| getting bitten by the export crash bug in 2.07.
|
| I would also greatly appreciate it if someone could find the time and
| update doc/changes.src with everything that has happened since 2.07.
|
| -hpa
|

Here what commits I found important enough to be mentioned in changes:

1) A number of fixes from Keith Kanios macros related (CC'ed).
2) Fuzzy opernad size logic introduced.
3) 7ad24562dccca867d9ba591ac7dd242456003c5b - BR 2827397: fix invalid C in
   outcoff AddExports()
4) 8bec2c788f3432f24788a2e7487486e20543e063 - fix stack overrun for [DEBUG id]
5) 69c4f63c25fb5ead8e8439fcfa112f0e8d68ec03 - elf,stabs: stabs32/64_generate --
   append ending token
6) New NSIS script which uses ModernUI approach (btw I've tried it on
   Windows 7 and it worked more/less correct, though there was no
   checking for user level but this depends on NSIS compiler itself).
7) Visual Studio 2008 NASM integration
8) 9ccabd2922788ee96be1c808050aefaa79c9490f - check constants for overflow

Thats all. Other changes look more "internal nasm stuff" on which users
mostly should not care.

        -- Cyrill

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Nasm-devel mailing list
Nasm-devel@...
https://lists.sourceforge.net/lists/listinfo/nasm-devel

Re: pull request v2

by H. Peter Anvin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 10/13/2009 12:46 PM, Cyrill Gorcunov wrote:
>
> Thats all. Other changes look more "internal nasm stuff" on which users
> mostly should not care.
>
> -- Cyrill

Sounds about right.  Could you check in a patch to doc/changes.src?

        -hpa

--
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Nasm-devel mailing list
Nasm-devel@...
https://lists.sourceforge.net/lists/listinfo/nasm-devel

Re: pull request v2

by Cyrill Gorcunov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

[H. Peter Anvin - Tue, Oct 13, 2009 at 12:48:26PM -0700]
| On 10/13/2009 12:46 PM, Cyrill Gorcunov wrote:
| >
| > Thats all. Other changes look more "internal nasm stuff" on which users
| > mostly should not care.
| >
| > -- Cyrill
|
| Sounds about right.  Could you check in a patch to doc/changes.src?
|
| -hpa
|

Peter, here is what I wrote. Please check and rephrase to more
"understandable" English if possible. My SOB if needed.

        -- Cyrill

Signed-off-by: Cyrill Gorcunov <gorcunov@...>
---
 doc/changes.src |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Index: nasm.git/doc/changes.src
=====================================================================
--- nasm.git.orig/doc/changes.src
+++ nasm.git/doc/changes.src
@@ -8,6 +8,26 @@ The NASM 2 series support x86-64, and is
 since 2007.
 
 
+\S{cl-2.08rc1} Version 2.08rc1
+
+\b A number of fixes/enhances on NASM preprocessor side
+
+\b Fuzzy opernad size logic introduced
+
+\b BR 2827397: fix invalid C in outcoff AddExports()
+
+\b Fix stack overrun for long identifiers in [DEBUG id]
+
+\b ELF files -- append ending tokens for STABS
+
+\b New installer script which uses ModernUI approach.
+
+\b Visual Studio 2008 NASM integration (rules file)
+
+\b The checking of constants for not overflow in storage
+  unit implemented. So user now warned if constant get
+  stripped.
+
 \S{cl-2.07} Version 2.07
 
 \b NASM is now under the 2-clause BSD license.  See \k{legal}.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Nasm-devel mailing list
Nasm-devel@...
https://lists.sourceforge.net/lists/listinfo/nasm-devel