Beispiel #1
0
node* readModule(FILE *hatFile, unsigned long offset)
{
    node *newNode = (node *)malloc(sizeof(node));
    char tag;
    
    newNode->nodeType = Module;
    newNode->offset = offset;
    
    setFilePos(hatFile, offset);
    tag = readByte(hatFile);
    newNode->params.module.name = readString(hatFile);
    newNode->params.module.filename = readString(hatFile);
    newNode->params.module.wasTraced = tracedModule(tag);
    
    return newNode;
}
Beispiel #2
0
void
nextnode (void)
{
  FileOffset offset = nextoffset;
  char b;
  int marked, err;
  err = fread(&b,sizeof(char),1,f); nextoffset+=1;
  if (err!=1) return;
  if (rmode || xmode) {
    marked = ismarked(b);
    if (marked) {
      cleartag(&b);
      newtagat(&b, offset);
    }
    if (amode) printf("%s", (marked ? "=> " : "   "));
  }
  {
    int k = lo5(b);
    if ((ExpDoStmt<k && k<AtomVariable) || k>ListCons) {
      fprintf(stderr, "strange tag %d at byte offset 0x%x\n",
                      k, offset);
      exit(1);
    } else if (smode) {
      count[k]++;
      if (rmode && marked) reachcount[k]++;
    }
    switch (k) {
    case ListCons:
	if (gmode) printf("%d [label=\"0x%x ListCons\"]\n", offset, offset);
        if (amode) printf("0x%x:  %-20s\t", offset, tag2str(k));
	if (amode) printf("elem=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "e");
	if (amode) printf(" tail=");
        dopointer(MAYBEZERO, ListCons, readpointer(), k, offset, "t");
      break;
    case Module:
      if (amode) {
        if (tracedModule(b))
             printf("0x%x:  Module (suspect) \t", offset);
        else printf("0x%x:  Module (trusted) \t", offset);
      }
      { char *s = readstring(); if (amode) printf("%s\t", s); }
      { char *s = readstring(); if (amode) printf("\"%s\"", s); }
      break;
    case SrcPos:
      if (amode) printf("0x%x:  SrcPos\t\t\t", offset);
      dopointer(NONZERO, Module, readpointer(), k, offset, "");
      { char *p = readposn(); if (amode) printf(" %s", p); }
      break;
    case AtomVariable:
      if (amode) {
        if (localDef(b))
             printf("0x%x:  AtomVariable (local)\t", offset);
        else printf("0x%x:  AtomVariable (toplevel)\t", offset);
      }
      if (gmode) printf("%d [label=\"0x%x AtomVariable", offset, offset);
      dopointer(NONZERO, Module, readpointer(), k, offset, "");
      { char *p = readposn(); if (amode) printf(" %s", p); }
      { char *fp = readfixpri(); if (*fp!='\0' && amode) printf("%s ", fp); }
      { unsigned int a = readarity();
        if (amode || gmode) printf(amode ? " arity=%u," : " %u", a); }
      { char *n = readstring(); if (amode || gmode) printf(" %s", n); }
      if (gmode) printf("\"]\n");
      break;
    case AtomConstructor:
      if (amode) printf("0x%x:  %-20s\t", offset, tag2str(k));
      if (gmode) printf("%d [label=\"0x%x AtomConstructor", offset, offset);
      dopointer(NONZERO, Module, readpointer(), k, offset, "");
      { char *p = readposn(); if (amode) printf(" %s", p); }
      { char *fp = readfixpri(); if (*fp!='\0' && amode) printf("%s", fp); }
      { unsigned int a = readarity();
        if (amode || gmode) printf(amode ? " arity=%u," : " %u", a);
        { char *n = readstring(); if (amode || gmode) printf(" %s", n); }
        if (gmode) printf("\"]\n");
        if hasFields(b) {
	  int i;
          if (amode) printf(" fields:");
          for (i=1; i<=a; i++) {
            dopointer(NONZERO, AtomVariable, readpointer(), k, offset,
	      (gmode ? (sprintf(stringbuf,"%d",i), stringbuf) : "")
	    );
          }
        }
      }
      break;
    case AtomAbstract:
      if (amode) printf("0x%x:  %-20s\t", offset, tag2str(k));
      if (gmode) printf("%d [label=\"0x%x AtomAbstract ", offset, offset);
      { char *s = readstring(); if (amode || gmode) printf("%s", s); }
      if (gmode) printf("\"]\n");
      break;
    default: {
      if (amode) printf("0x%x:  %-20s\t", offset, tag2str(k));
      if (hasSrcPos(b)) {
	  if (amode) printf("use=");
          dopointer(NONZERO, SrcPos, readpointer(), k, offset, "");
	  if (amode) printf(" ");
      }
   // if (amode && (ExpChar <= k) && (k <= ExpConstUse)) {
   //     printf("(");
   //     if (!isEntered(b)) printf("not ");
   //     printf("entered) ");
   // }
      switch (k) {
      case ExpApp:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" result=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "r");
	if (amode) printf(" fun=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "f");
        if (gmode) printf("%d [label=\"0x%x ExpApp", offset, offset);
        { unsigned int a = readarity();
	  int i;
	  if (amode || gmode)
	    printf(amode ? " arity=%u, args " : " %u\"]\n",a);
	  for (i=1; i<=a; i++)
	    dopointer(NONZERO, ANYEXP, readpointer(), k, offset,
	      (gmode ? (sprintf(stringbuf,"%d",i), stringbuf) : "")
	    );
	}
	break;
      case ExpValueApp:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" fun=");
        dopointer(NONZERO, ANYATOM, readpointer(), k, offset, "f");
        if (gmode) printf("%d [label=\"0x%x ExpValueApp", offset, offset);
        { unsigned int a = readarity();
	  int i;
	  if (amode || gmode)
	    printf(amode ? " arity=%u, args " : " %u\"]\n",a);
	  for (i=1; i<=a; i++)
	    dopointer(NONZERO, ANYEXP, readpointer(), k, offset,
	      (gmode ? (sprintf(stringbuf,"%d",i), stringbuf) : "")
	    );
	}
	break;
      case ExpChar:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { char c = nextbyte();
	  if (gmode) printf("%d [label=\"ExpChar", offset);
	  if (amode || gmode) printf(" '%c'", c);
	  if (gmode) printf("\"]\n");
	}
	break;
      case ExpInt:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { int i; i = readfourbytes();
	  if (gmode) printf("%d [label=\"ExpInt", offset);
	  if (amode || gmode) printf(" %d", i);
	  if (gmode) printf("\"]\n");
	}
	break;
      case ExpInteger:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { char* i; i = readinteger();
	  if (gmode) printf("%d [label=\"ExpInteger", offset);
	  if (amode || gmode) printf(" %s", i);
	  if (gmode) printf("\"]\n");
	}
	break;
      case ExpRat:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { int n,d; n=readfourbytes(); d=readfourbytes();
	  if (gmode) printf("%d [label=\"ExpRat", offset);
          if (amode || gmode) printf(" %d%%%d", n,d);
	  if (gmode) printf("\"]\n");
        }
	break;
      case ExpRational:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { char* r = readrational();
	  if (gmode) printf("%d [label=\"ExpRational", offset);
	  if (amode || gmode) printf(" %s", r);
	  if (gmode) printf("\"]\n");
        }
	break;
      case ExpFloat:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { float f = readfloat();
	  if (gmode) printf("%d [label=\"ExpFloat", offset);
	  if (amode || gmode) printf(" %f", f);
	  if (gmode) printf("\"]\n");
        }
	break;
      case ExpDouble:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { double d = readdouble();
	  if (gmode) printf("%d [label=\"ExpDouble", offset);
	  if (amode || gmode) printf(" %f", d);
	  if (gmode) printf("\"]\n");
        }
	break;
      case ExpValueUse:
	if (gmode) printf("%d [label=\"0x%x ExpValueUse\"]\n", offset, offset);
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" value=");
        dopointer(MAYBELAMBDA, ANYATOM, readpointer(), ExpValueUse, offset,"v");
	break;
      case ExpConstUse:
	if (gmode) printf("%d [label=\"0x%x ExpConstUse\"]\n", offset, offset);
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" const=");
        dopointer(NONZERO, ExpConstDef, readpointer(), k, offset, "c");
	break;
      case ExpConstDef:
	if (gmode) printf("%d [label=\"0x%x ExpConstDef\"]\n", offset, offset);
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" result=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "r");
	if (amode) printf(" var=");
        dopointer(NONZERO, AtomVariable, readpointer(), k, offset, "v");
	break;
      case ExpGuard:
      case ExpCase:
      case ExpIf:
	if (gmode) printf("%d [label=\"0x%x %s\"]\n", offset, offset,
                  k==ExpGuard ? "ExpGuard" : k==ExpCase ? "ExpCase" : "ExpIf");
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" result=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "r");
	if (amode) printf(" cond=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "c");
	break;
      case ExpFieldUpdate:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" result=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "r");
	if (amode) printf(" arg=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "a");
        { unsigned int i, arity = readarity();
	  if (gmode) printf("%d [label=\"0x%x ExpFieldUpdate %u\"]\n", offset, offset, arity);
	  if (amode) printf(" arity=%u, binders ",arity);
          for (i=0; i<arity; i++) {
            dopointer(NONZERO, AtomVariable, readpointer(), k, offset, "");
          }
	  if (amode) printf(", bindees ",arity);
          for (i=0; i<arity; i++) {
            dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "");
          }
        }
	break;
      case ExpProjection:
	if (gmode) printf("%d [label=\"0x%x ExpProjection\"]\n", offset, offset);
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" exp=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "e");
	break;
      case ExpHidden:
	if (gmode) printf("%d [label=\"0x%x ExpHidden\"]\n", offset, offset);
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" result=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "r");
	if (amode) printf(" children=");
	dopointer(MAYBEZERO, ListCons, readpointer(), k, offset, "c");
	break;
      case ExpForward:
	if (gmode) printf("%d [label=\"0x%x ExpForward\"]\n", offset, offset);
	if (amode) printf("result=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "r");
	break;
      case ExpDoStmt:
	if (gmode) printf("%d [label=\"0x%x ExpDoStmt\"]\n", offset, offset);
	if (amode) printf("stmt=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "s");
	break;
      }
    }}
    if (amode) printf("\n");
    if (smode) space[k] += nextoffset - offset;
  }
}