2 static char rcsid[] = "$Id: move.c,v 0.6 1994/06/24 13:27:40 ceriel Exp $";
15 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
16 * See the copyright notice in the ACK home directory, in the file "Copyright".
18 * Author: Hans van Staveren
21 move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
24 register struct reginfo *rp;
31 if (tp2->t_token == -1) {
32 if (tp1->t_token == -1) {
33 if (eqtoken(&machregs[tp1->t_att[0].ar].r_contents,
34 &machregs[tp2->t_att[0].ar].r_contents) &&
35 machregs[tp1->t_att[0].ar].r_contents.t_token!=0)
38 if (eqtoken(&machregs[tp2->t_att[0].ar].r_contents,tp1))
41 erasereg(tp2->t_att[0].ar);
42 } else if (tp1->t_token == -1) {
43 if (eqtoken(tp2,&machregs[tp1->t_att[0].ar].r_contents))
47 * If we arrive here the move must really be executed
49 for (mp=moves;mp->m_set1>=0;mp++) {
50 if (!match(tp1,&machsets[mp->m_set1],mp->m_expr1))
52 if (match(tp2,&machsets[mp->m_set2],mp->m_expr2))
55 * Correct move rule is found
58 assert(mp->m_set1>=0);
60 * To get correct interpretation of things like %[1]
61 * in move code we stack tp2 and tp1. This little trick
62 * saves a lot of testing in other places.
65 fakestack[stackheight] = *tp2;
66 fakestack[stackheight+1] = *tp1;
69 t = codegen(&coderules[mp->m_cindex],ply,toplevel,maxcost,0);
72 if (tp2->t_token == -1) {
73 rp = &machregs[tp2->t_att[0].ar];
74 if (tp1->t_token == -1) {
76 machregs[tp1->t_att[0].ar].r_contents ;
78 else rp->r_contents = *tp1;
79 if (rp->r_contents.t_token > 0) {
80 tdpb = &(tokens[rp->r_contents.t_token].t_type[0]);
81 for (i=0;i<TOKENSIZE;i++)
82 if (*tdpb++ == EV_REG &&
83 clash(rp->r_contents.t_att[i].ar,tp2->t_att[0].ar)) {
84 rp->r_contents.t_token = 0;
85 for (i = 0; i < TOKENSIZE; i++)
86 rp->r_contents.t_att[i].aw = 0;
91 else if (tp1->t_token == -1)
92 machregs[tp1->t_att[0].ar].r_contents = *tp2;
96 #define cocoreg machregs[0].r_contents
98 setcc(tp) token_p tp; {
103 test(tp,ply,toplevel,maxcost) token_p tp; unsigned maxcost; {
108 if (cocoreg.t_token!=0) {
109 if (eqtoken(tp,&cocoreg))
111 if (tp->t_token == -1) {
112 if (eqtoken(&machregs[tp->t_att[0].ar].r_contents,&cocoreg))
117 * If we arrive here the test must really be executed
119 for (mp=tests;mp->t_set>=0;mp++) {
120 if (match(tp,&machsets[mp->t_set],mp->t_expr))
123 * Correct move rule is found
126 assert(mp->t_set>=0);
128 * To get correct interpretation of things like %[1]
129 * in test code we stack tp. This little trick
130 * saves a lot of testing in other places.
133 fakestack[stackheight] = *tp;
136 t = codegen(&coderules[mp->t_cindex],ply,toplevel,maxcost,0);