- /* just dump operands into words, I guess */
- fprintf(stderr, "FIXME unhandled raw data\n");
- /* count total length of data.. */
- /* realloc instruction */
- /* populate words */
+ DEBUG_PRINTF("processing DAT...\n");
+
+ i->length = 0;
+
+ for ( /* */ ; o; o = o->next) {
+ size_t j, dat_len;
+ char *x;
+ unsigned long l;
+
+ DEBUG_PRINTF("DAT operand:'%s' next:%p\n", o->operand, (void *)o->next);
+
+ /* is this a string? */
+ /* does it start with a quote, and end with the same quote? */
+ if ( (x = strchr("\"'`", o->operand[0])) ) {
+ dat_len = strlen(o->operand) - 1;
+ if (o->operand[dat_len] == *x) {
+ /* it is a string */
+ DEBUG_PRINTF("DAT string operand: %s\n", o->operand);
+
+ for (j = 0, x = o->operand + 1;
+ j < dat_len - 1;
+ j++, x++) {
+ i->instr_words[i->length] = *x;
+ i->length++;
+ }
+ /* Note that strings in DAT do not include their zero-terminators */
+ /* specify as 'DAT "string", 0' */
+ }
+ continue;
+ }
+
+ /* is this a number? */
+ char *ep;
+ errno = 0;
+ l = strtoul(o->operand, &ep, 0);
+ if (errno == 0
+ && (*o->operand && (*ep == '\0')) ) {
+ /* conversion succeeded */
+ if (l > 0xffff) {
+ fprintf(stderr, "value '%lu' out of range\n", l);
+ return -1;
+ }
+ i->instr_words[i->length] = l;
+ i->length++;
+ continue;
+ }
+
+ /* otherwise assume it's a label, even if we don't know what it is */
+ if (label_addr_(labels, o->operand, &i->instr_words[i->length])) {
+ DEBUG_PRINTF("(deferred label '%s' resolution)\n", o->operand);
+ incomplete = 1;
+ }
+ i->length++;
+ }
+
+ if (incomplete) {
+ DEBUG_PRINTF("pending label address\n");
+ } else {
+ i->ready = 1;
+ }
+