/* assembles the genome at a fixed origin and writes it as a c header */ #include #include #include #define ORG 48000 static char tok[30000][99]; static int lab[30000], nt, img[17536], n; static char *ops = "q@!$_~cjzr,?.+-*&|^><"; static int val(char *s) { int j; char *e; long v; for (j = nt; j--;) if (tok[j][0] == ':' && !strcmp(tok[j] + 1, s)) return lab[j]; v = strtol(s, &e, 0); if (!*s || *e) { fprintf(stderr, "unknown label %s\n", s); exit(1); } return (int)v; } static void put(int w) { if (n >= 17536) exit(1); img[n++] = w; } int main(void) { int pass, i; char *q, *c; while (nt < 30000 && scanf("%98s", tok[nt]) == 1) nt++; for (pass = 0; pass < 2; pass++) for (n = i = 0; i < nt; i++) { q = tok[i]; if (*q == '"') while (*++q) put(*q); else if (*q == ':') lab[i] = ORG + n; else if (!q[1] && (c = strchr(ops, *q))) put((c - ops) * 2); else if (*q == '#') put(pass ? val(q + 1) : 0); else put(pass ? val(q) * 2 + 1 : 1); } printf("#define GORG %d\n#define GLEN %d\nstatic const int genome[] = {", ORG, n); for (i = 0; i < n; i++) printf("%s%d", !i ? "\n" : i % 16 ? "," : ",\n", img[i]); printf("\n};\n"); return 0; }