Esempio n. 1
0
static int
SaveHash(FILE *stream)
{
  CACHE_REGS
  UInt i;
  /* first, current opcodes */
  CHECK(save_tag(stream, QLY_START_X));
  save_UInt(stream, (UInt)&ARG1);
  CHECK(save_tag(stream, QLY_START_OPCODES));
  save_Int(stream, _std_top);
  for (i= 0; i <= _std_top; i++) {
    save_UInt(stream, (UInt)Yap_opcode(i));
  }
  CHECK(save_tag(stream, QLY_START_ATOMS));
  CHECK(save_UInt(stream, LOCAL_ExportAtomHashTableNum));
  for (i = 0; i < LOCAL_ExportAtomHashTableSize; i++) {
    export_atom_hash_entry_t *a = LOCAL_ExportAtomHashChain+i;
    if (a->val) {
      Atom at = a->val;
      CHECK(save_UInt(stream, (UInt)at));
	CHECK(save_tag(stream, QLY_ATOM));
	CHECK(save_UInt(stream, strlen((char *)RepAtom(at)->StrOfAE)));
	CHECK(save_bytes(stream, (char *)at->StrOfAE, (strlen((char *)at->StrOfAE)+1)*sizeof(char)));
    }
  }
  save_tag(stream, QLY_START_FUNCTORS);
  save_UInt(stream, LOCAL_ExportFunctorHashTableNum);
  for (i = 0; i < LOCAL_ExportFunctorHashTableSize; i++) {
    export_functor_hash_entry_t *f = LOCAL_ExportFunctorHashChain+i;
    if (!(f->val))
      continue;
    CHECK(save_UInt(stream, (UInt)(f->val)));
    CHECK(save_UInt(stream, f->arity));
    CHECK(save_UInt(stream, (CELL)(f->name)));
  }
  save_tag(stream, QLY_START_PRED_ENTRIES);
  save_UInt(stream, LOCAL_ExportPredEntryHashTableNum);
  for (i = 0; i < LOCAL_ExportPredEntryHashTableSize; i++) {
    export_pred_entry_hash_entry_t *p = LOCAL_ExportPredEntryHashChain+i;
    if (!(p->val))
      continue;
    CHECK(save_UInt(stream, (UInt)(p->val)));
    CHECK(save_UInt(stream, p->arity));
    CHECK(save_UInt(stream, (UInt)p->module));
    CHECK(save_UInt(stream, (UInt)p->u_af.f));
  }
  save_tag(stream, QLY_START_DBREFS);
  save_UInt(stream, LOCAL_ExportDBRefHashTableNum);
  for (i = 0; i < LOCAL_ExportDBRefHashTableSize; i++) {
    export_dbref_hash_entry_t *p = LOCAL_ExportDBRefHashChain+i;
    if (p->val) {
      CHECK(save_UInt(stream, (UInt)(p->val)));
      CHECK(save_UInt(stream, p->sz));
      CHECK(save_UInt(stream, p->refs));
    }
  }
  save_tag(stream, QLY_FAILCODE);
  save_UInt(stream, (UInt)FAILCODE);
  return 1;
}
Esempio n. 2
0
static size_t
save_clauses(FILE *stream, PredEntry *pp) {
  yamop        *FirstC, *LastC;

  FirstC = pp->cs.p_code.FirstClause;
  LastC = pp->cs.p_code.LastClause;
  if (FirstC == NULL && LastC == NULL) {
    return 1;
  }
  if (pp->PredFlags & LogUpdatePredFlag) {
    LogUpdClause *cl = ClauseCodeToLogUpdClause(FirstC);

    while (cl != NULL) {
      if (IN_BETWEEN(cl->ClTimeStart, pp->TimeStampOfPred, cl->ClTimeEnd)) {
	UInt size = cl->ClSize;
	CHECK(save_tag(stream, QLY_START_LU_CLAUSE));
	CHECK(save_UInt(stream, (UInt)cl));
	CHECK(save_UInt(stream, size));
	CHECK(save_bytes(stream, cl, size));
      }
      cl = cl->ClNext;
    }
    CHECK(save_tag(stream, QLY_END_LU_CLAUSES));
  } else if (pp->PredFlags & MegaClausePredFlag) {
    MegaClause *cl = ClauseCodeToMegaClause(FirstC);
    UInt size = cl->ClSize;

    CHECK(save_UInt(stream, (UInt)cl));
    CHECK(save_UInt(stream, (UInt)(cl->ClFlags)));
    CHECK(save_UInt(stream, size));
    CHECK(save_bytes(stream, cl, size));
  } else if (pp->PredFlags & DynamicPredFlag) {
    yamop *cl = FirstC;

    do {
      DynamicClause *dcl = ClauseCodeToDynamicClause(cl);
      UInt size = dcl->ClSize;

      CHECK(save_UInt(stream, (UInt)cl));
      CHECK(save_UInt(stream, size));
      CHECK(save_bytes(stream, dcl, size));
      if (cl == LastC) return 1;
      cl = NextDynamicClause(cl);
    } while (TRUE);
  } else {
    StaticClause *cl = ClauseCodeToStaticClause(FirstC);

    if (pp->PredFlags & SYSTEM_PRED_FLAGS) {
      return 1;
    }
    do {
      UInt size = cl->ClSize;

      CHECK(save_UInt(stream, (UInt)cl));
      CHECK(save_UInt(stream, size));
      CHECK(save_bytes(stream, cl, size));
      if (cl->ClCode == LastC) return 1;
      cl = cl->ClNext;
    } while (TRUE);
  }
  return 1;
}
Esempio n. 3
0
int com_save_tag(char* arg) {
  int res = save_tag(arg);
  if (res == 0)
    printf("Successfully wrote tag to: %s\n", arg);
  return 0;
}