Exemple #1
0
/*
 * allocate a quad8 function
     $$.quad = new_quad8( ']', $1.index, $3.quad, 0);
 */
QUAD *new_quad8( int operator, int index, QUAD *q1, QUAD *q2)
{
  // declare variables
  QUAD *newQuad;
  QUAD *multQuad;
  QUAD *last1 = end_quad_list( q1);
  char size[2];
  int  multIndex;

  // make new quad(s)
  if ( q2 == 0){
    size[0]  = (char)data.st[ index].specifier+48;
    size[1]  = 0;
    multIndex= install( TYPE_CONSTANT, size, 2, FORMAT_DECIMAL);
    multQuad = new_quad( '*', TYPE_TEMPORARY, next_temp(), last1->dst_type, last1->dst_index, TYPE_CONSTANT, multIndex);
    newQuad  = new_quad( operator, TYPE_TEMPORARY, next_temp(), data.st[ index].type, index, multQuad->dst_type, multQuad->dst_index);
  } else {
  }

  // link up new quad and old quads correctly
  last1->next    = multQuad;
  multQuad->next = newQuad;

  // return the head quad in the linked list
  return q1;
}
Exemple #2
0
/*
 *	allocate a quad1 function
		$$.quad = new_quad1( '+', $1.quad, $3.quad);
 */
QUAD	*new_quad1( int operator, QUAD *q1, QUAD *q2)
{
  QUAD *quad;

  // optimized attempt for both passed quads as ident/numbers
  if ( q1->operator == '=' 
    && q1->dst_type == TYPE_TEMPORARY 
    && ( q1->op1_type == TYPE_IDENTIFIER || q1->op1_type == TYPE_CONSTANT) 
    && q2->operator == '=' 
    && q2->dst_type == TYPE_TEMPORARY 
    && ( q2->op1_type == TYPE_IDENTIFIER || q2->op1_type == TYPE_CONSTANT))
  {
    data.temp--;
    data.temp--;
    quad = new_quad( operator, TYPE_TEMPORARY, next_temp(), q1->op1_type, q1->op1_index, q2->op1_type, q2->op1_index);
    free_quad( q1);
    free_quad( q2);
    return quad;
  }

  // another optimization attempt, for single passed quad as ident/number (q2)
  if ( q2->operator == '=' 
    && q2->dst_type == TYPE_TEMPORARY 
    && ( q2->op1_type == TYPE_IDENTIFIER || q2->op1_type == TYPE_CONSTANT))
  {
    data.temp--;
    QUAD *l1 = end_quad_list( q1);
    quad = new_quad( operator, TYPE_TEMPORARY, data.temp, l1->dst_type, l1->dst_index, q2->op1_type, q2->op1_index);
    free_quad( q2);
    l1->next = quad;
    return q1;
  }

  // another optimization attempt, for single passed quad as ident/number (q1)
  if ( q1->operator == '=' 
    && q1->dst_type == TYPE_TEMPORARY 
    && ( q1->op1_type == TYPE_IDENTIFIER || q1->op1_type == TYPE_CONSTANT))
  {
    data.temp--;
    QUAD *l2 = end_quad_list( q2);
    quad = new_quad( operator, TYPE_TEMPORARY, data.temp, q1->op1_type, q1->op1_index, l2->dst_type, l2->dst_index);
    free_quad( q1);
    l2->next = quad;
    return q2;
  }

  // previous, inefficient thing
  QUAD *last1 = end_quad_list( q1);
  QUAD *last2 = end_quad_list( q2);
  quad = new_quad( operator, TYPE_TEMPORARY, next_temp(), last1->dst_type, last1->dst_index, last2->dst_type, last2->dst_index);

  last1->next = q2;
  last2->next = quad;
	return q1;
}
Exemple #3
0
/*
 *	allocate a quad3 function
		$$.quad = new_quad3( '=', $1.index, $3.quad);
 */
QUAD	*new_quad3( int operator, int index, QUAD *q1)
{
  QUAD *quad;
  if ( q1 == 0){
	  quad = new_quad(operator, TYPE_TEMPORARY, next_temp(), data.st[ index].type, index, 0, 0);
    return quad;
  }
  else {
    QUAD *quad1 = end_quad_list( q1);

    // optimization attempt
    if (quad1->dst_type == TYPE_TEMPORARY){
      data.temp--;
      quad1->dst_type = data.st[ index].type;
      quad1->dst_index = index;
      return q1;
    }

    // normal quad-making
    quad = new_quad( operator, data.st[ index].type, index, quad1->dst_type, quad1->dst_index, 0, 0);
    quad1->next = quad;
  }

  return q1;
}
/*
 *	allocate a quad3 function
		$$.quad = new_quad3( '=', $1.index);
 */
QUAD	*new_quad3( int operator, int index)
{
	QUAD	*quad;

	quad = new_quad( operator, TYPE_TEMPORARY, next_temp(), find_symbol_table_index(index)->type, index, 0, 0);
	return quad;
}
/*
 *	allocate a quad2 function
		$$.quad = new_quad2( '~', $1.quad);
 */
QUAD	*new_quad2( int operator, QUAD *q1)
{
	QUAD	*quad1;

	quad1 = end_quad_list( q1);
	quad1->next = new_quad( operator, TYPE_TEMPORARY, next_temp(), quad1->dst_type, quad1->dst_index, 0, 0);
	return q1;
}
Exemple #6
0
/*
 *	allocate a quad1 function
		$$.quad = new_quad1( '+', $1.quad, $3.quad);
 */
QUAD	*new_quad1( int operator, QUAD *q1, QUAD *q2)
{
  QUAD *quad;
  QUAD *last1 = end_quad_list( q1);
  QUAD *last2 = end_quad_list( q2);
  quad = new_quad( operator, TYPE_TEMPORARY, next_temp(), last1->dst_type, last1->dst_index, last2->dst_type, last2->dst_index);

  last1->next = q2;
  last2->next = quad;
	return q1;
}
/*
 *	allocate a quad1 function
		$$.quad = new_quad1( '+', $1.quad, $3.quad);
 */
QUAD	*new_quad1( int operator, QUAD *q1, QUAD *q2)
{
	QUAD	*quad1;
	QUAD	*quad2;

	quad1 = end_quad_list( q1);
	quad1->next = q2;
	quad2 = end_quad_list( q2);
	quad2->next = new_quad( operator, TYPE_TEMPORARY, next_temp(), quad1->dst_type, quad1->dst_index, quad2->dst_type, quad2->dst_index);
	return q1;
}
Exemple #8
0
/*
 *	allocate a quad3 function
		$$.quad = new_quad3( '=', $1.index, $3.quad);
 */
QUAD	*new_quad3( int operator, int index, QUAD *q1)
{
  QUAD *quad;
  if ( q1 == 0){
	  quad = new_quad(operator, TYPE_TEMPORARY, next_temp(), data.st[ index].type, index, 0, 0);
    return quad;
  }
  else {
    QUAD *quad1 = end_quad_list( q1);
    quad = new_quad( operator, data.st[ index].type, index, quad1->dst_type, quad1->dst_index, 0, 0);
    quad1->next = quad;
  }

  return q1;
}