Example #1
0
struct burm_state *burm_alloc_state(NODEPTR u,int op,int arity)
{
  struct burm_state *p, **k;
  p = (struct burm_state *)ALLOC(sizeof *p);
  burm_assert(p, PANIC("1:ALLOC returned NULL in burm_alloc_state\n"));
    burm_np = u;
  p->op = op;
  p->node = u;
  if(arity){
    k=(struct burm_state **)ALLOC(arity*sizeof (struct burm_state *));
    burm_assert(k, PANIC("2:ALLOC returned NULL in burm_alloc_state\n"));
    p->kids=k;
  }else
    p->kids=0;
  p->rule.burm_stmt =
  p->rule.burm_reg =
  p->rule.burm_disp =
  p->rule.burm_rc =
  p->rule.burm_con =
  p->rule.burm__ =
    0;
  p->cost[1] =
  p->cost[2] =
  p->cost[3] =
  p->cost[4] =
  p->cost[5] =
  p->cost[6] =
    COST_INFINITY;
  return p;
}
Example #2
0
NODEPTR *burm_kids(NODEPTR p, int eruleno, NODEPTR kids[]) {
  burm_assert(p, PANIC("NULL tree in burm_kids\n"));
  burm_assert(kids, PANIC("NULL kids in burm_kids\n"));
  switch (eruleno) {
  case 0: /* stmt: BURP(_,_,_) */
    kids[0] = burm_child(p,0);
    kids[1] = burm_child(p,1);
    kids[2] = burm_child(p,2);
    break;
  case 7: /* disp: ADDI(reg,con) */
  case 3: /* reg: ADDI(reg,rc) */
  case 1: /* stmt: ASGNI(disp,reg) */
    kids[0] = burm_child(p,0);
    kids[1] = burm_child(p,1);
    break;
  case 10: /* rc: reg */
  case 9: /* rc: con */
  case 6: /* reg: disp */
  case 2: /* stmt: reg */
    kids[0] = p;
    break;
  case 4: /* reg: CVCI(INDIRC(disp)) */
    kids[0] = burm_child(burm_child(p,0),0);
    break;
  case 12: /* con: I0I */
  case 11: /* con: CNSTI */
  case 8: /* disp: ADDRLP */
  case 5: /* reg: I0I */
    break;
  default:
    burm_assert(0, PANIC("Bad external rule number %d in burm_kids\n", eruleno));
  }
  return kids;
}
Example #3
0
NODEPTR_TYPE *burm_kids(NODEPTR_TYPE p, int eruleno, NODEPTR_TYPE kids[]) {
	burm_assert(p, PANIC("NULL tree in burm_kids\n"));
	burm_assert(kids, PANIC("NULL kids in burm_kids\n"));
	switch (eruleno) {
	case 10: /* disp: ADDI(reg,con) */
	case 6: /* reg: ADDI(reg,rc) */
	case 4: /* stmt: ASGNI(disp,reg) */
		kids[0] = LEFT_CHILD(p);
		kids[1] = RIGHT_CHILD(p);
		break;
	case 13: /* rc: reg */
	case 12: /* rc: con */
	case 9: /* reg: disp */
	case 5: /* stmt: reg */
		kids[0] = p;
		break;
	case 7: /* reg: CVCI(INDIRC(disp)) */
		kids[0] = LEFT_CHILD(LEFT_CHILD(p));
		break;
	case 15: /* con: I0I */
	case 14: /* con: CNSTI */
	case 11: /* disp: ADDRLP */
	case 8: /* reg: I0I */
		break;
	default:
		burm_assert(0, PANIC("Bad external rule number %d in burm_kids\n", eruleno));
	}
	return kids;
}
Example #4
0
NODEPTR burm_child(NODEPTR p, int index) {
  NODEPTR *kids;
  burm_assert(p, PANIC("NULL tree in burm_child\n"));
  kids=GET_KIDS(p);
  burm_assert((0<=index && index<burm_arity[OP_LABEL(p)]),
    PANIC("Bad index %d in burm_child\n", index));

  return kids[index];
}
Example #5
0
NODEPTR_TYPE burm_child(NODEPTR_TYPE p, int index) {
	burm_assert(p, PANIC("NULL tree in burm_child\n"));
	switch (index) {
	case 0:	return LEFT_CHILD(p);
	case 1:	return RIGHT_CHILD(p);
	}
	burm_assert(0, PANIC("Bad index %d in burm_child\n", index));
	return 0;
}
Example #6
0
int burm_rule(STATE_TYPE state, int goalnt) {
	burm_assert(goalnt >= 1 && goalnt <= 5, PANIC("Bad goal nonterminal %d in burm_rule\n", goalnt));
	if (!state)
		return 0;
	switch (goalnt) {
	case burm_stmt_NT:	return burm_decode_stmt[((struct burm_state *)state)->rule.burm_stmt];
	case burm_disp_NT:	return burm_decode_disp[((struct burm_state *)state)->rule.burm_disp];
	case burm_reg_NT:	return burm_decode_reg[((struct burm_state *)state)->rule.burm_reg];
	case burm_rc_NT:	return burm_decode_rc[((struct burm_state *)state)->rule.burm_rc];
	case burm_con_NT:	return burm_decode_con[((struct burm_state *)state)->rule.burm_con];
	default:
		burm_assert(0, PANIC("Bad goal nonterminal %d in burm_rule\n", goalnt));
	}
	return 0;
}
Example #7
0
void burm_exec(struct burm_state *state, int nterm, ...) 
{
  va_list(ap);
  va_start(ap,nterm);

  burm_assert(nterm >= 1 && nterm <= 6,
        PANIC("Bad nonterminal %d in $exec\n", nterm));

  if (state)
    switch (nterm) {
    case burm_stmt_NT:
      stmt_action(state,va_arg(ap,int));
      break;
    case burm_reg_NT:
      reg_action(state,va_arg(ap,int));
      break;
    case burm_disp_NT:
      disp_action(state,va_arg(ap,int));
      break;
    case burm_rc_NT:
      rc_action(state,va_arg(ap,int));
      break;
    case burm_con_NT:
      con_action(state,va_arg(ap,int));
      break;
    default:
      PANIC("Bad nonterminal %d in $exec\n", nterm);
      break;
    }
  else
    PANIC("Bad state for $exec in nonterminal %d \n",nterm);
  va_end(ap);
}
Example #8
0
static void burm_label1(NODEPTR_TYPE p) {
	burm_assert(p, PANIC("NULL tree in burm_label\n"));
	switch (burm_arity[OP_LABEL(p)]) {
	case 0:
		STATE_LABEL(p) = burm_state(OP_LABEL(p), 0, 0);
		break;
	case 1:
		burm_label1(LEFT_CHILD(p));
		STATE_LABEL(p) = burm_state(OP_LABEL(p),
			STATE_LABEL(LEFT_CHILD(p)), 0);
		break;
	case 2:
		burm_label1(LEFT_CHILD(p));
		burm_label1(RIGHT_CHILD(p));
		STATE_LABEL(p) = burm_state(OP_LABEL(p),
			STATE_LABEL(LEFT_CHILD(p)),
			STATE_LABEL(RIGHT_CHILD(p)));
		break;
	}
}
Example #9
0
struct burm_state *burm_state_label(NODEPTR p) {
  burm_assert(p, PANIC("NULL tree in burm_state_label\n"));
  return STATE_LABEL(p);
}
Example #10
0
int burm_op_label(NODEPTR p) {
  burm_assert(p, PANIC("NULL tree in burm_op_label\n"));
  return OP_LABEL(p);
}
Example #11
0
struct burm_state *burm_label1(NODEPTR u) {
  int op, arity, i, immed_matched=0;
  COST c=COST_ZERO;
  struct burm_state *s,**k;
  NODEPTR *children;
  op=OP_LABEL(u);
  arity=burm_arity[op];
  switch(op){
  case 0:		/* BURP */
    s=burm_alloc_state(u,op,arity);
    SET_STATE(u,s);
    k=s->kids;
        /*immediate rule: stmt: BURP(_,_,_) */
    if(burm_cost_code(&c,0,s) && COST_LESS(c,s->cost[burm_stmt_NT])) {
burm_trace(burm_np, 0, c);       s->cost[burm_stmt_NT] = c ;
      s->rule.burm_stmt = 1;
      immed_matched=1;
    }
    if(immed_matched){
      for(i=0;i<arity;i++)k[i]=0;
      return s;
    }
    break;
  case 1:		/* ADDI */
    s=burm_alloc_state(u,op,arity);
    SET_STATE(u,s);
    k=s->kids;
    children=GET_KIDS(u);
    for(i=0;i<arity;i++)
      k[i]=burm_label1(children[i]);
    if (   /* disp: ADDI(reg,con) */
      k[0]->rule.burm_reg && 
      k[1]->rule.burm_con
    ) {
      if(burm_cost_code(&c,7,s) && COST_LESS(c,s->cost[burm_disp_NT])) {
burm_trace(burm_np, 7, c);         s->cost[burm_disp_NT] = c ;
        s->rule.burm_disp = 1;
        burm_closure_disp(s, c );
      }
    }
    if (   /* reg: ADDI(reg,rc) */
      k[0]->rule.burm_reg && 
      k[1]->rule.burm_rc
    ) {
      if(burm_cost_code(&c,3,s) && COST_LESS(c,s->cost[burm_reg_NT])) {
burm_trace(burm_np, 3, c);         s->cost[burm_reg_NT] = c ;
        s->rule.burm_reg = 1;
        burm_closure_reg(s, c );
      }
    }
    break;
  case 2:		/* ADDRLP */
#ifdef LEAF_TRAP
    if(s=LEAF_TRAP(u,op))
      return s;
#endif
    s=burm_alloc_state(u,op,arity);
    SET_STATE(u,s);
    k=0;
    {  		/* disp: ADDRLP */
      if(burm_cost_code(&c,8,s) && COST_LESS(c,s->cost[burm_disp_NT])) {
burm_trace(burm_np, 8, c);         s->cost[burm_disp_NT] = c ;
        s->rule.burm_disp = 2;
        burm_closure_disp(s, c );
      }
    }
    break;
  case 3:		/* ASGNI */
    s=burm_alloc_state(u,op,arity);
    SET_STATE(u,s);
    k=s->kids;
    children=GET_KIDS(u);
    for(i=0;i<arity;i++)
      k[i]=burm_label1(children[i]);
    if (   /* stmt: ASGNI(disp,reg) */
      k[0]->rule.burm_disp && 
      k[1]->rule.burm_reg
    ) {
      if(burm_cost_code(&c,1,s) && COST_LESS(c,s->cost[burm_stmt_NT])) {
burm_trace(burm_np, 1, c);         s->cost[burm_stmt_NT] = c ;
        s->rule.burm_stmt = 2;
      }
    }
    break;
  case 4:		/* CNSTI */
#ifdef LEAF_TRAP
    if(s=LEAF_TRAP(u,op))
      return s;
#endif
    s=burm_alloc_state(u,op,arity);
    SET_STATE(u,s);
    k=0;
    {  		/* con: CNSTI */
      if(burm_cost_code(&c,11,s) && COST_LESS(c,s->cost[burm_con_NT])) {
burm_trace(burm_np, 11, c);         s->cost[burm_con_NT] = c ;
        s->rule.burm_con = 1;
        burm_closure_con(s, c );
      }
    }
    break;
  case 5:		/* CVCI */
    s=burm_alloc_state(u,op,arity);
    SET_STATE(u,s);
    k=s->kids;
    children=GET_KIDS(u);
    for(i=0;i<arity;i++)
      k[i]=burm_label1(children[i]);
    if (   /* reg: CVCI(INDIRC(disp)) */
      k[0]->op == 7 && 	/* INDIRC */
      k[0]->kids[0]->rule.burm_disp
    ) {
      if(burm_cost_code(&c,4,s) && COST_LESS(c,s->cost[burm_reg_NT])) {
burm_trace(burm_np, 4, c);         s->cost[burm_reg_NT] = c ;
        s->rule.burm_reg = 2;
        burm_closure_reg(s, c );
      }
    }
    break;
  case 6:		/* I0I */
#ifdef LEAF_TRAP
    if(s=LEAF_TRAP(u,op))
      return s;
#endif
    s=burm_alloc_state(u,op,arity);
    SET_STATE(u,s);
    k=0;
    {  		/* con: I0I */
      if(burm_cost_code(&c,12,s) && COST_LESS(c,s->cost[burm_con_NT])) {
burm_trace(burm_np, 12, c);         s->cost[burm_con_NT] = c ;
        s->rule.burm_con = 2;
        burm_closure_con(s, c );
      }
    }
    {  		/* reg: I0I */
      if(burm_cost_code(&c,5,s) && COST_LESS(c,s->cost[burm_reg_NT])) {
burm_trace(burm_np, 5, c);         s->cost[burm_reg_NT] = c ;
        s->rule.burm_reg = 3;
        burm_closure_reg(s, c );
      }
    }
    break;
  case 7:		/* INDIRC */
    s=burm_alloc_state(u,op,arity);
    SET_STATE(u,s);
    k=s->kids;
    children=GET_KIDS(u);
    for(i=0;i<arity;i++)
      k[i]=burm_label1(children[i]);
    break;
  default:
    burm_assert(0, PANIC("Bad operator %d in burm_state\n", op));
  }
  return s;
}
Example #12
0
STATE_TYPE burm_state_label(NODEPTR_TYPE p) {
	burm_assert(p, PANIC("NULL tree in burm_state_label\n"));
	return STATE_LABEL(p);
}
Example #13
0
STATE_TYPE burm_state(int op, STATE_TYPE left, STATE_TYPE right) {
	int c;
	struct burm_state *p, *l = (struct burm_state *)left,
		*r = (struct burm_state *)right;

	assert(sizeof (STATE_TYPE) >= sizeof (void *));
	if (burm_arity[op] > 0) {
		p = ALLOC(sizeof *p);
		burm_assert(p, PANIC("ALLOC returned NULL in burm_state\n"));
		p->op = op;
		p->left = l;
		p->right = r;
		p->rule.burm_stmt = 0;
		p->cost[1] =
		p->cost[2] =
		p->cost[3] =
		p->cost[4] =
		p->cost[5] =
			32767;
	}
	switch (op) {
	case 21: /* CNSTI */
		{
			static struct burm_state z = { 21, 0, 0,
				{	0,
					32767,
					32767,
					32767,
					0,	/* rc: con */
					0,	/* con: CNSTI */
				},{
					0,
					0,
					0,
					1,	/* rc: con */
					1,	/* con: CNSTI */
				}
			};
			return (STATE_TYPE)&z;
		}
	case 53: /* ASGNI */
		assert(l && r);
		{	/* stmt: ASGNI(disp,reg) */
			c = l->cost[burm_disp_NT] + r->cost[burm_reg_NT] + 1;
			if (c + 0 < p->cost[burm_stmt_NT]) {
				p->cost[burm_stmt_NT] = c + 0;
				p->rule.burm_stmt = 1;
			}
		}
		break;
	case 67: /* INDIRC */
		assert(l);
		break;
	case 85: /* CVCI */
		assert(l);
		if (	/* reg: CVCI(INDIRC(disp)) */
			l->op == 67 /* INDIRC */
		) {
			c = l->left->cost[burm_disp_NT] + 1;
			if (c + 0 < p->cost[burm_reg_NT]) {
				p->cost[burm_reg_NT] = c + 0;
				p->rule.burm_reg = 2;
				burm_closure_reg(p, c + 0);
			}
		}
		break;
	case 295: /* ADDRLP */
		{
			static struct burm_state z = { 295, 0, 0,
				{	0,
					1,	/* stmt: reg */
					0,	/* disp: ADDRLP */
					1,	/* reg: disp */
					1,	/* rc: reg */
					32767,
				},{
					2,	/* stmt: reg */
					2,	/* disp: ADDRLP */
					4,	/* reg: disp */
					2,	/* rc: reg */
					0,
				}
			};
			return (STATE_TYPE)&z;
		}
	case 309: /* ADDI */
		assert(l && r);
		{	/* disp: ADDI(reg,con) */
			c = l->cost[burm_reg_NT] + r->cost[burm_con_NT] + 0;
			if (c + 0 < p->cost[burm_disp_NT]) {
				p->cost[burm_disp_NT] = c + 0;
				p->rule.burm_disp = 1;
				burm_closure_disp(p, c + 0);
			}
		}
		{	/* reg: ADDI(reg,rc) */
			c = l->cost[burm_reg_NT] + r->cost[burm_rc_NT] + 1;
			if (c + 0 < p->cost[burm_reg_NT]) {
				p->cost[burm_reg_NT] = c + 0;
				p->rule.burm_reg = 1;
				burm_closure_reg(p, c + 0);
			}
		}
		break;
	case 661: /* I0I */
		{
			static struct burm_state z = { 661, 0, 0,
				{	0,
					0,	/* stmt: reg */
					32767,
					0,	/* reg: I0I */
					0,	/* rc: con */
					0,	/* con: I0I */
				},{
					2,	/* stmt: reg */
					0,
					3,	/* reg: I0I */
					1,	/* rc: con */
					2,	/* con: I0I */
				}
			};
			return (STATE_TYPE)&z;
		}
	default:
		burm_assert(0, PANIC("Bad operator %d in burm_state\n", op));
	}
	return (STATE_TYPE)p;
}