Ejemplo n.º 1
0
node_ptr declare_var(node_ptr tnode, node_ptr vnode, int islocal)
{
    if (vnode->ntype == E_AVAR || vnode->ntype == E_LVAR) {
	/* Declaring a new variable that will alias an existing one */
	vnode = new_ast_var(vnode->name);
    }
    if (vnode->ntype != E_VAR) {
	fprintf(ERRFILE,
		"Error (declare_var).  Expected node of type %s, got one of %s\n",
		node_type_name(E_VAR), node_type_name(vnode->ntype));
	exit(1);
    }
  vnode->wsize = tnode->wsize;
  vnode->dtype = tnode->dtype;
  vnode->ntype = islocal ? E_LVAR : E_AVAR;
  vnode->isdefined = zero();
  push_var(vnode);
  return new_node1(S_DECL, IOP_NONE, vnode);
}
Ejemplo n.º 2
0
/* Add new index on right of array reference */
node_ptr add_array_ref(node_ptr sofar, node_ptr indexval)
{
  node_ptr index = new_node2(E_ADIM, IOP_NONE, indexval, NULL);
  if (sofar->ntype == E_AREF) {
    /* Already constructed array reference.  Want to add new index to rightmost end */
    node_ptr last = sofar;
    while (last->children[1])
      last = last->children[1];
    last->children[1] = index;
    return sofar;
  } else if (sofar->ntype == E_LAVAR) {
    /* First element of array reference */
    node_ptr ref = new_node2(E_AREF, IOP_NONE, sofar, index);
    return ref;
  } else {
      fprintf(ERRFILE,
		"Error (add_array_ref).  Expected node of type %s or %s, got one of %s\n",
		node_type_name(E_LVAR), node_type_name(E_LAVAR), node_type_name(sofar->ntype));
	exit(1);
  }
}
Ejemplo n.º 3
0
/* Add new dimension to array */
void add_array_dim(node_ptr sofar, node_ptr dimval)
{
  node_ptr dim = new_node2(E_ADIM, IOP_NONE, dimval, NULL);
  if (sofar->ntype == E_LAVAR) {
    /* Already know that this is an array.  Want to add new dimension to rightmost end */
    node_ptr last = sofar->children[0];
    while (last->children[1]) {
      last = last->children[1];
    }
    last->children[1] = dim;
  } else if (sofar->ntype == E_LVAR) {
    /* Convert to array */
    sofar->ntype = E_LAVAR;
    sofar->degree = 1;
    sofar->children[0] = dim;
  } else {
      fprintf(ERRFILE,
		"Error (add_array_dim).  Expected node of type %s or %s, got one of %s\n",
		node_type_name(E_LVAR), node_type_name(E_LAVAR), node_type_name(sofar->ntype));
	exit(1);
  }
}
Ejemplo n.º 4
0
void check_ast_var(node_ptr vnode)
{
    if (vnode->ntype == E_VAR)
	yyserror("Invalid variable '%s'", vnode->name);
    if (vnode->ntype == E_AREF) {
      check_ast_var(vnode->children[0]);
      return;
    }
    if (vnode->ntype != E_LVAR && vnode->ntype != E_AVAR && vnode->ntype != E_LAVAR) {
      fprintf(ERRFILE, "Error (check_ast_var).  Expected variable.  Got node of type %s\n", node_type_name(vnode->ntype));
      exit(1);
    }
}
Ejemplo n.º 5
0
/* Flush declarations contained within block of code.  Append as S_UNDECL's to block */
node_ptr flush_decls(node_ptr snode)
{
    node_ptr vnode;
    /* First, must find first declaration within snode.  Get this by following left branches
       of S_SEQUENCE nodes until hit declaration */
    node_ptr dnode = snode;
    node_ptr unode = new_node0(S_NOP, IOP_NONE);
    int new_cnt;
    while (dnode->ntype == S_SEQUENCE)
	dnode = dnode->children[0];
    if (dnode->ntype != S_DECL)
	/* There are no active declarations in this block. */
	return snode;
    vnode = dnode->children[0];
    if (vnode->ntype != E_LVAR && vnode->ntype != E_AVAR && vnode->ntype != E_LAVAR) {
      fprintf(ERRFILE, "Error (flush_decls).  Expected variable, got node of type %s\n", node_type_name(vnode->ntype));
      exit(1);
    }

    /* Now see if vnode is on the stack (it might have already been deallocated */
    for (new_cnt = stack_cnt-1; new_cnt >= 0 && vnode != var_stack[new_cnt]; new_cnt--)
      ;
    if (new_cnt >= 0) {
      while (stack_cnt > new_cnt) {
	stack_cnt--;
	unode = sequence_node(new_node1(S_UNDECL, IOP_NONE, var_stack[stack_cnt]), unode);
      }
      return sequence_node(snode, unode);
    } else
      return snode;
}
Ejemplo n.º 6
0
void IR::Node::toJSON(JSONGenerator &json) const {
    json << json.indent << "\"Node_ID\" : " << id << "," << std::endl
         << json.indent << "\"Node_Type\" : " << node_type_name();
}
Ejemplo n.º 7
0
void IR::Node::traceVisit(const char* visitor) const
{ LOG3("Visiting " << visitor << " " << id << ":" << node_type_name()); }