Esempio n. 1
0
void recurseExpressionList(c_tree tree, int *registerNo, int topLevel,
		int getAddress, const char *breakLabel, const char *continueLabel)
{
	if (tree)
	{
		recurseExpressionList(CHAIN_NEXT(tree), registerNo, topLevel,
				getAddress, breakLabel, continueLabel);
		c_tree argument = CHAIN_VALUE(tree);
		int functionArgumentReg = c_codegen_recurse(argument, registerNo,
				topLevel, getAddress, breakLabel, continueLabel);
		// push it on to stack
		ADDi(R6, R6, -1, "growing stack to push variable", NULL);
		STRi(functionArgumentReg, R6, 0, "pushing variable onto stack", NULL);
	}
}
Esempio n. 2
0
int callExprCodegen(c_tree tree, int *registerNo, int topLevel, int getAddress,
		const char *breakLabel, const char *continueLabel)
{
	c_tree fndecl = TREE_EXPR_OPERAND(tree,0);

	c_tree fnArguments = TREE_EXPR_OPERAND(tree,1);

	if (EXPR_LIST(fnArguments)->chain)
	{
		recurseExpressionList(EXPR_LIST(fnArguments)->chain, registerNo, FALSE,
				FALSE, breakLabel, continueLabel);
	}

	// call the function
	JSR(DECL_NAME_STRING(fndecl), "", "");

	// get the return value
	int returnValueReg = *registerNo;
	if (!topLevel)
	{
		returnValueReg = (*registerNo)++;
		LDRi(returnValueReg, R6, 0,
				"load the return value into register to return", NULL);
	}

	// unwind stack allocated for return and pushed variable
	int noOfArgs = 1;
	if (EXPR_LIST(fnArguments)->chain)
	{
		c_tree args = EXPR_LIST(fnArguments)->chain;
		while (args)
		{
			noOfArgs++;
			args = CHAIN_NEXT(args);
		}
	}
	ADDi(R6, R6, noOfArgs,
			"unwind stack allocated for return and pushed variable ", NULL);

	return returnValueReg;
}
Esempio n. 3
0
int c_codegen_recurse(c_tree tree, int *registerNo, int topLevel,
		int getAddress, const char *breakLabel, const char *continueLabel)
{
	if (tree == NULL)
		return *registerNo;

	switch (TREE_CODE(tree))
	{
		case TREE_INTEGER_CST :
			if (!topLevel)
			{
				SET(*registerNo, INTEGER_CST(tree)->val, "integer constant", "");
				return (*registerNo)++;
			}
			break;
		case TREE_IDENTIFIER :
			break;
		case TREE_CHAIN :
			while (tree)
			{
				c_codegen_recurse(CHAIN_VALUE(tree), registerNo, topLevel,
						getAddress, breakLabel, continueLabel);
				tree = CHAIN_NEXT(tree);
			}
			break;
		case TREE_EXPR :
			return exprCodeGen(tree, registerNo, topLevel, getAddress,
					breakLabel, continueLabel);
			break;
		case TREE_EXPR_LIST :
			if (EXPR_LIST(tree)->chain)
				c_codegen_recurse(EXPR_LIST(tree)->chain, registerNo, TRUE,
						getAddress, breakLabel, continueLabel);
			break;
		case TREE_WHILE :
			return whileCodeGen(tree, registerNo, topLevel, getAddress,
					breakLabel, continueLabel);
			break;
		case TREE_FOR :
			return forCodeGen(tree, registerNo, topLevel, getAddress,
					breakLabel, continueLabel);
			break;
		case TREE_IFELSE :
			return ifCodeGen(tree, registerNo, topLevel, getAddress,
					breakLabel, continueLabel);
			break;
		case TREE_EXPRSTMT :
			c_codegen_recurse(EXPR_STMT(tree)->expr, registerNo, topLevel,
					getAddress, breakLabel, continueLabel);
			break;
		case TREE_COMPOUND :
			if (COMPOUND_STMT(tree)->decllist)
				c_codegen_recurse(COMPOUND_STMT(tree)->decllist, registerNo,
						topLevel, getAddress, breakLabel, continueLabel);
			if (COMPOUND_STMT(tree)->stmtlist)
				c_codegen_recurse(COMPOUND_STMT(tree)->stmtlist, registerNo,
						topLevel, getAddress, breakLabel, continueLabel);
			break;
		case TREE_RETURN :
			return returnCodegen(tree, registerNo, getAddress, breakLabel,
					continueLabel);
			break;
		case TREE_DECL :
			return declCodeGen(tree, registerNo, topLevel, getAddress,
					breakLabel, continueLabel);
			break;
			//			}
			break;
		case TREE_STMT_LIST :
			if (STMT_LIST(tree)->head)
			{
				c_codegen_recurse(STMT_LIST(tree)->head, registerNo, topLevel,
						getAddress, breakLabel, continueLabel);
			}
			break;
		case TREE_BREAK :
			breakCodeGen(breakLabel);
			break;
		case TREE_CONTINUE :
			continueCodeGen(continueLabel);
			break;
		default :
			break;
	}

	return *registerNo;
}
Esempio n. 4
0
static int buildModel(int nolink, int nolap, int elim, int max_comp, int max_expn)
{ int        first, last;
  FILE      *input;
  DAZZ_READ *reads;

  LA   *local;
  Pile *pile;
  void *tbuffer;
  int  *panels, *plists;

  Overlap ovl;
  int64   novl;
  int     a, pos;
  int     omax, n, m;
  int64   smax, tlen;
  int     btip, etip;
  int     npan, nspl, nlas;

  reads = MODEL.db1->reads;
  input = MODEL.input;
  first = MODEL.first;
  last  = MODEL.last;

  rewind(input);
  fread(&novl,sizeof(int64),1,input);
  fread(&TRACE_SPACING,sizeof(int),1,input);
  if (TRACE_SPACING <= TRACE_XOVR && TRACE_SPACING != 0)
    TBYTES = sizeof(uint8);
  else
    TBYTES = sizeof(uint16);
  if (TRACE_SPACING > 0)
    PANEL_SIZE = ((PANEL_TARGET-1)/TRACE_SPACING+1)*TRACE_SPACING;
  else
    PANEL_SIZE = ((PANEL_TARGET-1)/100+1)*100;

  Read_Overlap(input,&ovl);
  if (ovl.aread >= first)
    MODEL.first = first = ovl.aread;
  else
    while (ovl.aread < first)
      { fseek(input,TBYTES*ovl.path.tlen,SEEK_CUR);
        Read_Overlap(input,&ovl);
        novl -= 1;
      }

  local = (LA *) Malloc(novl*sizeof(LA),"Allocating alignments");
  if (local == NULL)
    return (-1);
  pile  = (Pile *) Malloc(((last-first)+1)*sizeof(Pile),"Allocating piles");
  if (pile == NULL)
    { free(local);
      return (-1);
    }
  pile -= first;

  npan = nspl = nlas = 0;
  pos  = PILE_SPACING/2;
  a    = first-1;
  omax = m = n = 0;
  smax = 0;
  while (ovl.aread < last)
    { while (a < ovl.aread)
        { int j, b, e, p;

          if (a >= first)
            { if (reads[a].rlen < PANEL_FUDGE)
                p = 0;
              else
                p = ((reads[a].rlen-PANEL_FUDGE) / PANEL_SIZE);
              for (j = m; j < n; j++)
                { b = local[j].abpos / PANEL_SIZE;
                  e = (local[j].aepos-1) / PANEL_SIZE;
                  if (e > p)
                    e = p;
                  nlas += e-b;
                }
              nspl += 1;
              npan += p+1;
            }

          a += 1;
          pile[a].first  = n; 
          pile[a].where  = pos;
          pile[a].offset = ftello(input) - OvlIOSize;
          pile[a].panels = npan;
          if (n-m > omax)
            omax = n-m;
          m    = n;
          pos += reads[a].rlen + PILE_SPACING;
        }

      local[n].bread = (ovl.bread << 1);
      if (COMP(ovl.flags))
        local[n].bread |= 0x1;
      local[n].bbpos = ovl.path.bbpos;
      local[n].bepos = ovl.path.bepos;
      local[n].btip  = btip = tiplen(ovl.path.abpos,ovl.path.bbpos);
      local[n].etip  = etip = tiplen(reads[ovl.aread].rlen-ovl.path.aepos,
                                     MODEL.db2->reads[ovl.bread].rlen-ovl.path.bepos);
      local[n].abpos = ovl.path.abpos - btip;
      local[n].aepos = ovl.path.aepos + etip;
      local[n].toff  = ftell(input);
      if (CHAIN_START(ovl.flags))
        local[n].etip |= STRT_FLAG;
      if (CHAIN_NEXT(ovl.flags))
        local[n].etip |= SUCC_FLAG;
      if (ELIM(ovl.flags))
        local[n].etip |= ELIM_BIT;
   
      n += 1;

      tlen = TBYTES*ovl.path.tlen;
      if (smax < tlen)
        smax = tlen;
      fseeko(input,tlen,SEEK_CUR);

      if (feof(input))
        break;
      if (Read_Overlap(input,&ovl))
        break;
    }

  { int j, b, e, p;

    if (a < last-1)
      { MODEL.last = last = a+1;
        pile = (Pile *) Realloc(pile+first,((last-first)+1)*sizeof(Pile),"Reallocating piles");
        pile -= first;
      }

    if (a >= first)
      { if (reads[a].rlen < PANEL_FUDGE)
          p = 0;
        else
          p = ((reads[a].rlen-PANEL_FUDGE) / PANEL_SIZE);
        for (j = m; j < n; j++)
          { b = local[j].abpos / PANEL_SIZE;
            e = (local[j].aepos-1) / PANEL_SIZE;
            if (e > p)
              e = p;
            nlas += e-b;
          }
        nspl += 1;
        npan += p+1;
      }

    pile[last].first  = n;
    pile[last].where  = pos;
    pile[last].offset = ftello(input) - OvlIOSize;
    pile[last].panels = npan;
    if (n-m > omax)
      omax = n-m;
    pile[last].where  -= PILE_SPACING/2;
    pile[last].offset += OvlIOSize;

    if (n < novl)
      local = (LA *) Realloc(local,n*sizeof(LA),"Allocating alignments");
  }

  { LA   *temp;

    nlas = n + nlas;

    panels = (int *) Malloc((npan+1)*sizeof(int),"Panels");
    if (panels == NULL)
      goto error;

    plists = (int *) Malloc(nlas*sizeof(int),"Panel Lists");
    if (plists == NULL)
      goto error;

    temp = (LA *) Realloc(local,(n+1)*sizeof(LA),"Finalizing alignments");
    if (temp == NULL)
      goto error;
    local = temp;
    
    tbuffer = Malloc(smax,"Allocating trace buffer");
    if (tbuffer == NULL)
      goto error;
  }

  { int  a, k;
    int *manels;
    int *count;

    for (k = 0; k <= npan; k++)
      panels[k] = 0;

    manels = panels+1;
    for (a = first; a < last; a++)
      { int j, b, e, p;

        count = manels + pile[a].panels;
        if (reads[a].rlen < PANEL_FUDGE)
          p = 0;
        else
          p = ((reads[a].rlen-PANEL_FUDGE) / PANEL_SIZE);
        for (j = pile[a].first; j < pile[a+1].first; j++)
          { b = local[j].abpos / PANEL_SIZE;
            e = (local[j].aepos-1) / PANEL_SIZE;
            if (e > p)
              e = p;
            for (k = b; k <= e; k++)
              count[k] += 1;
          }
      }

    for (k = 2; k <= npan; k++)
      panels[k] += panels[k-1];

    for (a = first; a < last; a++)
      { int j, b, e, p;

        count = panels + pile[a].panels;
        if (reads[a].rlen < PANEL_FUDGE)
          p = 0;
        else
          p = ((reads[a].rlen-PANEL_FUDGE) / PANEL_SIZE);
        p = ((reads[a].rlen-PANEL_FUDGE) / PANEL_SIZE);
        for (j = pile[a].first; j < pile[a+1].first; j++)
          { b = local[j].abpos / PANEL_SIZE;
            e = (local[j].aepos-1) / PANEL_SIZE;
            if (e > p)
              e = p;
            for (k = b; k <= e; k++)
              plists[count[k]++] = j;
            local[j].abpos += local[j].btip;
            local[j].aepos -= (local[j].etip & DATA_ETIP);
          }
      }

    for (k = npan; k >= 1; k--)
      panels[k] = panels[k-1];
    panels[0] = 0;
  }

  MODEL.local  = local;
  MODEL.pile   = pile;
  MODEL.omax   = omax;
  MODEL.tbuf   = tbuffer;
  MODEL.tspace = TRACE_SPACING;
  MODEL.tbytes = TBYTES;
  MODEL.panels = panels;
  MODEL.plists = plists;

  UNDEFINED = 0;
  if (reLayoutModel(nolink,nolap,elim,max_comp,max_expn))
    { UNDEFINED = 1;
      goto error;
    }

  return (0);

error:
  free(local);
  free(pile+first);
  return (1);
}