removed checks for setting literal operands
[dcpu16] / as-dcpu16.c
index 2d131d7a40a167c37ee5115543aba21f9f73e8f6..820b8376cf2b0f1365fc5212d4a888a050debe72 100644 (file)
@@ -2,6 +2,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <string.h>
+#include <strings.h>
 #include <errno.h>
 #include <sysexits.h>
 #include <assert.h>
@@ -597,13 +598,9 @@ int tokenize_line_(char *line, struct instruction_ **next_instr) {
             struct operand_ *new_operand;
             char *y;
 
-            DEBUG_PRINTF("considering operand '%s'\n", x);
-
             /* trim whitespaces */
             x += strspn(x, whitespace);
 
-            DEBUG_PRINTF("considering ftrim operand '%s'\n", x);
-
             if (*x) {
                 for (y = x + strlen(x) - 1; *y; y--) {
                     if (strchr(whitespace, *y)) {
@@ -613,11 +610,11 @@ int tokenize_line_(char *line, struct instruction_ **next_instr) {
             }
             /* nothing left? */
             if (*x == '\0') {
-                fprintf(stderr, "ignoring null operand in line %zu\n", instr->src_line);
-                continue;
+                fprintf(stderr, "null operand encountered\n");
+                return -1;
             }
 
-            DEBUG_PRINTF("found operand '%s'\n", x);
+            DEBUG_PRINTF("tokenized operand '%s'\n", x);
 
             new_operand = malloc(sizeof *new_operand);
             if (new_operand == NULL) {
@@ -644,7 +641,7 @@ int tokenize_line_(char *line, struct instruction_ **next_instr) {
         }
     }
 
-    DEBUG_PRINTF("allocating instruction with room for %zu bytes\n", instr_words_needed);
+    DEBUG_PRINTF("allocating new instruction with room for %zu bytes\n", instr_words_needed);
 
     instr = calloc(1, (instr_words_needed * sizeof *instr->instr_words) + sizeof *instr);
     if (instr == NULL) {
@@ -1092,9 +1089,9 @@ int main(int argc, char *argv[]) {
 
             VERBOSE_PRINTF("assembling '%s'...\n", filename);
             c = parse_stream_(f, filename, instructionps_, labels_, allow_short_labels);
+            fclose(f);
             if (c)
                 break;
-            fclose(f);
         }
     } else {
         VERBOSE_PRINTF("assembling '%s'...\n", "stdin");