]> granicus.if.org Git - yasm/commitdiff
tasm (tweaked nasm) preproc fixes:
authorPeter Johnson <peter@tortall.net>
Fri, 17 Apr 2009 03:25:08 +0000 (03:25 -0000)
committerPeter Johnson <peter@tortall.net>
Fri, 17 Apr 2009 03:25:08 +0000 (03:25 -0000)
 - comments stripped before tokenization caused strings containing ';'
   to generate warnings (unterminated string) and incorrect output.
 - assume directive parsing did not properly handle ';' as end of line

Also add tests for the above.

Reported by: Rugxulo <rugxulo@gmail.com>

svn path=/trunk/yasm/; revision=2197

modules/preprocs/Makefile.inc
modules/preprocs/nasm/nasm-pp.c
modules/preprocs/tasm/Makefile.inc [new file with mode: 0644]
modules/preprocs/tasm/tests/Makefile.inc [new file with mode: 0644]
modules/preprocs/tasm/tests/tasm-assume-comment.asm [new file with mode: 0644]
modules/preprocs/tasm/tests/tasm-assume-comment.hex [new file with mode: 0644]
modules/preprocs/tasm/tests/tasm-comment-instr.asm [new file with mode: 0644]
modules/preprocs/tasm/tests/tasm-comment-instr.hex [new file with mode: 0644]
modules/preprocs/tasm/tests/tasmpp_test.sh [new file with mode: 0755]

index 8d3f7cfd9a3a4f9ca2f98f16c367abed64f9cedc..aee9accd73267533e88713488bf1ac81609145d9 100644 (file)
@@ -1,9 +1,11 @@
 # $Id$
 
+EXTRA_DIST += modules/preprocs/tasm/Makefile.inc
 EXTRA_DIST += modules/preprocs/nasm/Makefile.inc
 EXTRA_DIST += modules/preprocs/raw/Makefile.inc
 EXTRA_DIST += modules/preprocs/cpp/Makefile.inc
 
+include modules/preprocs/tasm/Makefile.inc
 include modules/preprocs/nasm/Makefile.inc
 include modules/preprocs/raw/Makefile.inc
 include modules/preprocs/cpp/Makefile.inc
index 0bbb0f3aca665be85a2eadbb58c169cd912b1730..647335577311268744989c0d46046c963ea59c50 100644 (file)
@@ -538,13 +538,10 @@ check_tasm_directive(char *line)
     char *p, *oldline, oldchar, *q, oldchar2;
     TMEndItem *end;
 
-    if ((p = strchr(line, ';')))
-        *p = '\0';
-
     p = line;
 
     /* Skip whitespace */
-    while (isspace(*p) && *p != 0)
+    while (isspace(*p) && *p != 0 && *p != ';')
         p++;
 
     /* Ignore nasm directives */
@@ -553,7 +550,7 @@ check_tasm_directive(char *line)
 
     /* Binary search for the directive name */
     len = 0;
-    while (!isspace(p[len]) && p[len] != 0)
+    while (!isspace(p[len]) && p[len] != 0 && p[len] != ';')
         len++;
     if (!len)
         return line;
@@ -871,10 +868,10 @@ check_tasm_directive(char *line)
         /* Skip whitespaces */
         while (isspace(*q) && *q)
             q++;
-        while (*q) {
+        while (*q && *q != ';') {
             p = q;
-            for (; *q && *q != ':' && !isspace(*q); q++);
-            if (!*q)
+            for (; *q && *q != ';' && *q != ':' && !isspace(*q); q++);
+            if (!*q || *q == ';')
                 break;
             /* segment register name */
             for (assume = TAssumes; assume->segreg; assume++)
@@ -888,20 +885,22 @@ check_tasm_directive(char *line)
                 assume->segreg = nasm_strndup(p, q-p);
                 assume[1].segreg = NULL;
             }
-            for (; *q && *q != ':' && isspace(*q); q++);
+            for (; *q && *q != ';' && *q != ':' && isspace(*q); q++);
             if (*q != ':')
                 error(ERR_FATAL, "expected `:' instead of `%c'", *q);
             for (q++; *q && isspace(*q); q++);
 
             /* segment name */
             p = q;
-            for (; *q && *q != ',' && !isspace(*q); q++);
+            for (; *q && *q != ';' && *q != ',' && !isspace(*q); q++);
             assume->segment = nasm_strndup(p, q-p);
             for (; *q && isspace(*q); q++);
-            if (*q && *q != ',')
+            if (*q && *q != ';' && *q != ',')
                 error(ERR_FATAL, "expected `,' instead of `%c'", *q);
         
-            for (q++; *q && isspace(*q); q++);
+            if (*q && *q != ';')
+                q++;
+            for (; *q && isspace(*q); q++);
         }
         TAssumes[i].segreg = NULL;
         TAssumes = nasm_realloc(TAssumes, (i+1)*sizeof(*TAssumes));
diff --git a/modules/preprocs/tasm/Makefile.inc b/modules/preprocs/tasm/Makefile.inc
new file mode 100644 (file)
index 0000000..588a3e8
--- /dev/null
@@ -0,0 +1,5 @@
+# $Id$
+
+EXTRA_DIST += modules/preprocs/tasm/tests/Makefile.inc
+
+include modules/preprocs/tasm/tests/Makefile.inc
diff --git a/modules/preprocs/tasm/tests/Makefile.inc b/modules/preprocs/tasm/tests/Makefile.inc
new file mode 100644 (file)
index 0000000..23450b4
--- /dev/null
@@ -0,0 +1,9 @@
+# $Id$
+
+TESTS += modules/preprocs/tasm/tests/tasmpp_test.sh
+
+EXTRA_DIST += modules/preprocs/tasm/tests/tasmpp_test.sh
+EXTRA_DIST += modules/preprocs/nasm/tests/tasm-assume-comment.asm
+EXTRA_DIST += modules/preprocs/nasm/tests/tasm-assume-comment.hex
+EXTRA_DIST += modules/preprocs/nasm/tests/tasm-comment-instr.asm
+EXTRA_DIST += modules/preprocs/nasm/tests/tasm-comment-instr.hex
diff --git a/modules/preprocs/tasm/tests/tasm-assume-comment.asm b/modules/preprocs/tasm/tests/tasm-assume-comment.asm
new file mode 100644 (file)
index 0000000..6b7cc1b
--- /dev/null
@@ -0,0 +1,3 @@
+assume cs:code,ds:code,es:code         ; tiny model (CS=DS=ES)
+assume ds:code,es:code; close comment
+assume fs:code,gs:code
diff --git a/modules/preprocs/tasm/tests/tasm-assume-comment.hex b/modules/preprocs/tasm/tests/tasm-assume-comment.hex
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/modules/preprocs/tasm/tests/tasm-comment-instr.asm b/modules/preprocs/tasm/tests/tasm-comment-instr.asm
new file mode 100644 (file)
index 0000000..d93001b
--- /dev/null
@@ -0,0 +1 @@
+ansi_normal db 0x27,'[0;40;37m$'
diff --git a/modules/preprocs/tasm/tests/tasm-comment-instr.hex b/modules/preprocs/tasm/tests/tasm-comment-instr.hex
new file mode 100644 (file)
index 0000000..594d68f
--- /dev/null
@@ -0,0 +1,11 @@
+27 
+5b 
+30 
+3b 
+34 
+30 
+3b 
+33 
+37 
+6d 
+24 
diff --git a/modules/preprocs/tasm/tests/tasmpp_test.sh b/modules/preprocs/tasm/tests/tasmpp_test.sh
new file mode 100755 (executable)
index 0000000..e3155b5
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+# $Id$
+${srcdir}/out_test.sh tasmpp_test modules/preprocs/tasm/tests "tasm preproc" "-f bin -p tasm" ""
+exit $?