Example #1
0
/* reading, checking and/or writing header and node information
 */
void
markfromheader (FileOffset *buf)
{
  fseek(f,8L,SEEK_SET);
  fread(buf,sizeof(FileOffset),2,f);
  markfrom(getpointer(buf+1),buf+1);
  markfrom(getpointer(buf),  buf);
}
Example #2
0
/* reading, checking and/or writing header and node information
 */
void
markfromheader (uint32_t *buf)
{
  fseek(f,8L,SEEK_SET);
  fread(buf,sizeof(uint32_t),2,f);
  markfrom(getpointer(buf+1),buf+1);
  markfrom(getpointer(buf),  buf);
}
Example #3
0
void
markfromoutput (char *bridgefile, FileOffset *buf)
{
  FILE* bridge = fopen(bridgefile, "rb");
  if (bridge==(FILE*)0) return;
  for (;;) {
    int n = fread(buf,sizeof(FileOffset),1,bridge);
    if (n<1) return;
    markfrom(getpointer(buf),buf);
  }
  fclose(bridge);
}
Example #4
0
/* mark all the nodes in the hat file that are reachable
 * from the given root -- setting the highest bit in the
 * tag byte
 */
void
markfrom (FileOffset root, FileOffset *buf)
{
  char tag;
  if (root > 8 && root < filesize) {
    /* First read the tag byte.  If it is marked, return.
     * If it is not marked, then mark it now.
     */
    fseek(f,(long int)root,SEEK_SET);
    fread(&tag,sizeof(char),1,f);
    if (ismarked(tag)) return;
    marktag(&tag);
    fseek(f,(long int)root,SEEK_SET);
    fwrite(&tag,sizeof(char),1,f);
    cleartag(&tag);
    /* Examine the tag to determine the kind of node.
     * Read pointers from the node into buf, then
     * markfrom() these pointers recursively.  The buffer is
     * overwritten where possible to minimise the risk of overflow:
     * for this reason, pointers are recursively traced in
     * reverse order.
     */
    {
      int k = lo5(tag);
      if ((ExpDoStmt < k && k < AtomVariable) || k > ListCons) {
	fprintf(stderr, "strange tag %d at 0x%x\n",
                	k, root);
	exit(1);
      }
      switch (k) {
        case ListCons:
          fread(buf,sizeof(FileOffset),2,f);	/* two pointers */
          markfrom(getpointer(buf+1),buf+1);
          markfrom(getpointer(buf),buf);
	  break;
        case Module: break;
        case AtomAbstract: break;

        case SrcPos:
        case AtomVariable:
        case AtomConstructor: 	/* ignore fieldnames for now */
          fread(buf,sizeof(FileOffset),1,f);	/* points to module mode */
          markfrom(getpointer(buf),buf);
          break;

        default: {
          int pos = 0;
          if (hasSrcPos(tag)) {
            fread(buf+pos,sizeof(FileOffset),1,f);
            pos++;
          }
          fread(buf+pos,sizeof(FileOffset),1,f);	/* parent pointer */
          pos++;
          switch (k) {
            case ExpApp:
              fread(buf+pos,sizeof(FileOffset),2,f); /* result+fun */
              pos += 2;
              { unsigned char arity;
                fread(&arity,sizeof(unsigned char),1,f);
                fread(buf+pos,sizeof(FileOffset),(unsigned int)arity,f);
                pos += (int)arity;
              }
	      break;
            case ExpValueApp:
              fread(buf+pos,sizeof(FileOffset),1,f); /* fun */
              pos += 1;
              { unsigned char arity;
                fread(&arity,sizeof(unsigned char),1,f);
                fread(buf+pos,sizeof(FileOffset),(unsigned int)arity,f);
                pos += (int)arity;
              }
	      break;
            case ExpValueUse:
            case ExpConstUse:
            case ExpProjection:
              fread(buf+pos,sizeof(FileOffset),1,f);	/* one extra pointer */
              pos++;
	      break;
            case ExpHidden:
            case ExpConstDef:
            case ExpFieldUpdate:	/* ignore fieldnames for now */
            case ExpGuard:
            case ExpCase:
            case ExpIf:
              fread(buf+pos,sizeof(FileOffset),2,f);	/* two pointers */
              pos+=2;
	      break;
            default: break;				/* no pointers */
          }
	  for (;pos-->0;) markfrom(getpointer(buf+pos), buf+pos);
        } break;
      }
    }
  }
}