int main(int argc, char **argv) { install("one", "1"); install("thirty-two", "32"); printdef(); undef("one"); printdef(); return; }
void printbitfield (struct rnnbitfield *bf, int shift) { if (bf->varinfo.dead) return; if (bf->typeinfo.type == RNN_TTYPE_BOOLEAN) { printdef (bf->fullname, 0, 0, bf->mask << shift, bf->file); } else { printdef (bf->fullname, "MASK", 0, bf->mask << shift, bf->file); printdef (bf->fullname, "SHIFT", 1, bf->low + shift, bf->file); } printtypeinfo (&bf->typeinfo, bf->fullname, bf->low + shift, bf->file); }
void printtypeinfo (struct rnntypeinfo *ti, char *prefix, int shift, char *file) { if (ti->shr) printdef (prefix, "SHR", 1, ti->shr, file); if (ti->minvalid) printdef (prefix, "MIN", 0, ti->min, file); if (ti->maxvalid) printdef (prefix, "MAX", 0, ti->max, file); if (ti->alignvalid) printdef (prefix, "ALIGN", 0, ti->align, file); int i; for (i = 0; i < ti->valsnum; i++) printvalue(ti->vals[i], shift); for (i = 0; i < ti->bitfieldsnum; i++) printbitfield(ti->bitfields[i], shift); }
void printdelem (struct rnndelem *elem, uint64_t offset) { if (elem->varinfo.dead) return; if (elem->length != 1) ADDARRAY(strides, elem->stride); if (elem->name) { if (stridesnum) { int len, total; FILE *dst = findfout(elem->file); fprintf (dst, "#define %s(%n", elem->fullname, &total); int i; for (i = 0; i < stridesnum; i++) { if (i) { fprintf(dst, ", "); total += 2; } fprintf (dst, "i%d%n", i, &len); total += len; } fprintf (dst, ")"); total++; seekcol (dst, total, startcol-1); fprintf (dst, "(0x%08"PRIx64"", offset + elem->offset); for (i = 0; i < stridesnum; i++) fprintf (dst, " + %#" PRIx64 "*(i%d)", strides[i], i); fprintf (dst, ")\n"); } else printdef (elem->fullname, 0, 0, offset + elem->offset, elem->file); if (elem->stride) printdef (elem->fullname, "ESIZE", 0, elem->stride, elem->file); if (elem->length != 1) printdef (elem->fullname, "LEN", 0, elem->length, elem->file); printtypeinfo (&elem->typeinfo, elem->fullname, 0, elem->file); } fprintf (findfout(elem->file), "\n"); int j; for (j = 0; j < elem->subelemsnum; j++) { printdelem(elem->subelems[j], offset + elem->offset); } if (elem->length != 1) stridesnum--; }
int main(int argc, char **argv) { struct rnndb *db; int i, j; if (argc < 2) { fprintf(stderr, "Usage:\n\theadergen database-file\n"); exit(1); } rnn_init(); db = rnn_newdb(); rnn_parsefile (db, argv[1]); rnn_prepdb (db); for(i = 0; i < db->filesnum; ++i) { char *dstname = malloc(strlen(db->files[i]) + 3); char *pretty; strcpy(dstname, db->files[i]); strcat(dstname, ".h"); struct fout f = { db->files[i], fopen(dstname, "w") }; if (!f.file) { perror(dstname); exit(1); } free(dstname); pretty = strrchr(f.name, '/'); if (pretty) pretty += 1; else pretty = f.name; f.guard = strdup(pretty); for (j = 0; j < strlen(f.guard); j++) if (isalnum(f.guard[j])) f.guard[j] = toupper(f.guard[j]); else f.guard[j] = '_'; ADDARRAY(fouts, f); printhead(f, db); } for (i = 0; i < db->enumsnum; i++) { if (db->enums[i]->isinline) continue; int j; for (j = 0; j < db->enums[i]->valsnum; j++) printvalue (db->enums[i]->vals[j], 0); } for (i = 0; i < db->bitsetsnum; i++) { if (db->bitsets[i]->isinline) continue; int j; for (j = 0; j < db->bitsets[i]->bitfieldsnum; j++) printbitfield (db->bitsets[i]->bitfields[j], 0); } for (i = 0; i < db->domainsnum; i++) { if (db->domains[i]->size) printdef (db->domains[i]->fullname, "SIZE", 0, db->domains[i]->size, db->domains[i]->file); int j; for (j = 0; j < db->domains[i]->subelemsnum; j++) { printdelem(db->domains[i]->subelems[j], 0); } } for(i = 0; i < foutsnum; ++i) { fprintf (fouts[i].file, "\n#endif /* %s */\n", fouts[i].guard); } return db->estatus; }
void printvalue (struct rnnvalue *val, int shift) { if (val->varinfo.dead) return; if (val->valvalid) printdef (val->fullname, 0, 0, val->value << shift, val->file); }