static node *queryorrule(prolog_obj_t *o) { node *x = new_node(o, QUERYORRULE); PDEBUG(x->type, "queryorrule"); while(o->sym != EOI){ if(o->sym == QUERY) { next_sym(o); x->o1 = pquery(o); } else { x->o1 = rule(o); } RETRY: next_sym(o); if(o->sym == PERIOD) goto RETRY; } return x; }
static node *program(prolog_obj_t *o) { node *x = new_node(o, PROG); PDEBUG(x->type, "program"); next_sym(o); x->o1 = queryorrule(o); if(o->sym != EOI) RECOVER(o, "expected EOI"); return x; }
static node *terms(prolog_obj_t *o) { node *x = new_node(o, TERMS), *t; PDEBUG(x->type, "terms"); t = x; while(o->sym != EOI && o->sym != PERIOD){ t->o2 = term(o); t = t->o2; next_sym(o); } return x; }
static node *rule(prolog_obj_t *o) { node *x = new_node(o, RULE); PDEBUG(x->type, "rule"); x->o1 = term(o); if(o->sym == PERIOD) return x; if(o->sym == ASSIGN) { next_sym(o); x->o2 = terms(o); if(o->sym != PERIOD) RECOVER(o, "expected '.'"); return x; } RECOVER(o, "expected ':-' or '.'"); return x; }
void nip::parse::Parser::parse(const std::vector<nip::Token_t>& tokens, const Token_Cache_t& tc) { token_caches = tc; start = tokens.begin(); current = start; end = tokens.end(); next_sym(); try { metadata_preprocessor(); // program(); } catch (Parse_Fatal_Error_t e) { errhdlr.print_errors(*opt.error_stream); return; } }
void migrate_implicit( void) { SYMBOL_ITER iter; SYMBOL *isym, *sym; for (isym = first_sym(&implicit_st, &iter); isym != NULL; isym = next_sym(&implicit_st, &iter)) { sym = lookup_sym(isym->label, &symbol_st); if (sym) { continue; // It's already in there. Great. } isym->flags |= SYMBOLFLAG_IMPLICIT_GLOBAL; sym = add_sym(isym->label, isym->value, isym->flags, isym->section, &symbol_st); // Just one other thing - migrate the stmtno sym->stmtno = isym->stmtno; } }
static int read_data(const ctf_header_t *hp, const ctf_data_t *cd) { /* LINTED - pointer alignment */ const ushort_t *idp = (ushort_t *)(cd->cd_ctfdata + hp->cth_objtoff); ulong_t n = (hp->cth_funcoff - hp->cth_objtoff) / sizeof (ushort_t); if (flags != F_STATS) print_line("- Data Objects "); if (hp->cth_objtoff & 1) WARN("cth_objtoff is not aligned properly\n"); if (hp->cth_objtoff >= cd->cd_ctflen) WARN("file is truncated or cth_objtoff is corrupt\n"); if (hp->cth_funcoff >= cd->cd_ctflen) WARN("file is truncated or cth_funcoff is corrupt\n"); if (hp->cth_objtoff > hp->cth_funcoff) WARN("file is corrupt -- cth_objtoff > cth_funcoff\n"); if (flags != F_STATS) { int symidx, len, i; char *name = NULL; for (symidx = -1, i = 0; i < n; i++) { int nextsym; if (cd->cd_symdata == NULL || (nextsym = next_sym(cd, symidx, STT_OBJECT, &name)) < 0) name = NULL; else symidx = nextsym; len = printf(" [%u] %u", i, *idp++); if (name != NULL) (void) printf("%*s%s (%u)", (15 - len), "", name, symidx); (void) putchar('\n'); } } stats.s_ndata = n; return (E_SUCCESS); }
static node *term(prolog_obj_t *o) { node *x = new_node(o, TERM); PDEBUG(x->type, "term"); next_sym(o); return x; }
static int read_funcs(const ctf_header_t *hp, const ctf_data_t *cd) { /* LINTED - pointer alignment */ const ushort_t *fp = (ushort_t *)(cd->cd_ctfdata + hp->cth_funcoff); /* LINTED - pointer alignment */ const ushort_t *end = (ushort_t *)(cd->cd_ctfdata + hp->cth_typeoff); ulong_t id; int symidx; if (flags != F_STATS) print_line("- Functions "); if (hp->cth_funcoff & 1) WARN("cth_funcoff is not aligned properly\n"); if (hp->cth_funcoff >= cd->cd_ctflen) WARN("file is truncated or cth_funcoff is corrupt\n"); if (hp->cth_typeoff >= cd->cd_ctflen) WARN("file is truncated or cth_typeoff is corrupt\n"); if (hp->cth_funcoff > hp->cth_typeoff) WARN("file is corrupt -- cth_funcoff > cth_typeoff\n"); for (symidx = -1, id = 0; fp < end; id++) { ushort_t info = *fp++; ushort_t kind = CTF_INFO_KIND(info); ushort_t n = CTF_INFO_VLEN(info); ushort_t i; int nextsym; char *name; if (cd->cd_symdata == NULL || (nextsym = next_sym(cd, symidx, STT_FUNC, &name)) < 0) name = NULL; else symidx = nextsym; if (kind == CTF_K_UNKNOWN && n == 0) continue; /* skip padding */ if (kind != CTF_K_FUNCTION) { (void) printf(" [%lu] unexpected kind -- %u\n", id, kind); return (E_ERROR); } if (fp + n > end) { (void) printf(" [%lu] vlen %u extends past section " "boundary\n", id, n); return (E_ERROR); } if (flags != F_STATS) { (void) printf(" [%lu] FUNC ", id); if (name != NULL) (void) printf("(%s) ", name); (void) printf("returns: %u args: (", *fp++); if (n != 0) { (void) printf("%u", *fp++); for (i = 1; i < n; i++) (void) printf(", %u", *fp++); } (void) printf(")\n"); } else fp += n + 1; /* skip to next function definition */ stats.s_nfunc++; stats.s_nargs += n; stats.s_argmax = MAX(stats.s_argmax, n); } return (E_SUCCESS); }
void write_globals( FILE *obj) { GSD gsd; SYMBOL *sym; SECTION *psect; SYMBOL_ITER sym_iter; int isect; if (obj == NULL) { for (isect = 0; isect < sector; isect++) { psect = sections[isect]; psect->sector = isect; /* Assign it a sector */ psect->pc = 0; /* Reset its PC for second pass */ } return; /* Nothing more to do if no OBJ file. */ } gsd_init(&gsd, obj); gsd_mod(&gsd, module_name); if (ident) gsd_ident(&gsd, ident); /* write out each PSECT with its global stuff */ /* Sections must be written out in the order that they appear in the assembly file. */ for (isect = 0; isect < sector; isect++) { psect = sections[isect]; gsd_psect(&gsd, psect->label, psect->flags, psect->size); psect->sector = isect; /* Assign it a sector */ psect->pc = 0; /* Reset its PC for second pass */ sym = first_sym(&symbol_st, &sym_iter); while (sym) { if ((sym->flags & SYMBOLFLAG_GLOBAL) && sym->section == psect) { gsd_global(&gsd, sym->label, (sym-> flags & SYMBOLFLAG_DEFINITION ? GLOBAL_DEF : 0) | ((sym-> flags & SYMBOLFLAG_WEAK) ? GLOBAL_WEAK : 0) | ((sym->section->flags & PSECT_REL) ? GLOBAL_REL : 0) | 0100, /* Looks undefined, but add it in anyway */ sym->value); } sym = next_sym(&symbol_st, &sym_iter); } } /* Now write out the transfer address */ if (xfer_address->type == EX_LIT) { gsd_xfer(&gsd, ". ABS.", xfer_address->data.lit); } else { SYMBOL *lsym; unsigned offset; if (!express_sym_offset(xfer_address, &lsym, &offset)) { report(NULL, "Illegal program transfer address\n"); } else { gsd_xfer(&gsd, lsym->section->label, lsym->value + offset); } } gsd_flush(&gsd); gsd_end(&gsd); }