#define KIDKID_VAL(A,B) bnode->kids[A]->kids[B]->val
#define KIDKIDKID_VAL(A,B,C) bnode->kids[A]->kids[B]->kids[C]->val
+#define KID_PARM(A) bnode->kids[A]->param_index
+#define KIDKID_PARM(A,B) bnode->kids[A]->kids[B]->param_index
+#define KIDKIDKID_PARM(A,B,C) bnode->kids[A]->kids[B]->kids[C]->param_index
+
/* macros zum zugriff des aktuellen knotens */
#define BN_REG bnode->reg
#define BN_VAL bnode->val
void gen_e_eno(struct treenode *bnode, char *instr)
{
- printf("\t//gen_e_eno(%s)\n", instr);
+ printf("\t#gen_e_eno(%s)\n", instr);
+#if 0
KIDREG2ID(0);
KIDREG2PARM(1);
- printf("\t%s %%%s, %%%s\n", instr, KID_REG(1), KID_REG(0));
+ printf("\t%s %s, %s\n", instr, KID_REG(1), KID_REG(0));
+#else
+ KIDREG2PARM(0);
+ KIDREG2PARM(1);
+ printf("\t%s %s,%s,%s\n", instr, BN_REG, KID_REG(1), KID_REG(0));
+#endif
}
void gen_id_eno(struct treenode *bnode)
{
- printf("\t//gen_id_eno\n");
+ printf("\t#gen_id_eno\n");
KIDKIDREG2PARM(1,0);
KIDKIDREG2PARM(1,1);
KIDREG2PARM(0);
move(KID_REG(0), BN_REG);
- printf("\tsubq %%%s, %%%s\n", KIDKID_REG(1,1), BN_REG);
- printf("\tsubq %%%s, %%%s\n", KIDKID_REG(1,0), BN_REG);
+ printf("\tsubf %%%s, %%%s\n", KIDKID_REG(1,1), BN_REG);
+ printf("\tsubf %%%s, %%%s\n", KIDKID_REG(1,0), BN_REG);
}
void gen_e_field(struct treenode *bnode, char *instr)
{
- printf("\t//gen_e_field(%s)\n", instr);
+ printf("\t#gen_e_field(%s)\n", instr);
KIDREG2ID(0);
KIDKIDREG2PARM(1,0);
printf("\t%s %d(%%%s), %%%s\n", instr, bnode->kids[1]->soffset * 8, KIDKID_REG(1,0), KID_REG(0));
void gen_field_imm(struct treenode *bnode)
{
- printf("\t//gen_field_imm\n");
+ printf("\t#gen_field_imm\n");
KIDKIDREG2PARM(0,0);
KIDREG2ID(1);
printf("\timulq $%d, %d(%%%s), %%%s\n", KID_VAL(1), bnode->kids[0]->soffset * 8, KIDKID_REG(0, 0), BN_REG);
void gen_e_imm(struct treenode *bnode, char *instr)
{
- printf("\t//gen_e_imm(%s)\n", instr);
+ printf("\t#gen_e_imm(%s)\n", instr);
KIDREG2PARM(0);
KIDREG2ID(1);
/* man kann sich ein move der konstante bei der multiplikation ersparen */
if(strcmp(instr, "imulq") == 0) {
if(KID_VAL(1) == 1 && strcmp(KID_REG(0), BN_REG) == 0) {
- printf("\t//multiplikation mit 1 wegoptimiert\n");
+ printf("\t#multiplikation mit 1 wegoptimiert\n");
} else {
printf("\timulq $%d, %%%s, %%%s\n", KID_VAL(1), KID_REG(0), BN_REG);
}
} else {
- if(strcmp(instr, "subq") == 0 && KID_VAL(1) == 0) {
- printf("\t//subtraktion mit 0 wegoptimiert\n");
+ if(strcmp(instr, "subf") == 0 && KID_VAL(1) == 0) {
+ printf("\t#subtraktion mit 0 wegoptimiert\n");
move(KID_REG(0), BN_REG);
} else {
move(KID_REG(0), BN_REG);
void gen_imm_field(struct treenode *bnode)
{
- printf("\t//gen_imm_field\n");
+ printf("\t#gen_imm_field\n");
KIDREG2ID(0);
KIDKIDREG2PARM(1, 0);
moveimm(KID_VAL(0), BN_REG);
- printf("\tsubq %d(%%%s), %%%s\n", bnode->kids[1]->soffset * 8, KIDKID_REG(1, 0), BN_REG);
+ printf("\tsubf %d(%%%s), %%%s\n", bnode->kids[1]->soffset * 8, KIDKID_REG(1, 0), BN_REG);
}
void gen_imm_eno(struct treenode *bnode, char *instr)
{
- printf("\t//gen_imm_eno(%s)\n", instr);
+ printf("\t#gen_imm_eno(%s)\n", instr);
KIDREG2ID(0);
KIDREG2PARM(1);
/* man kann sich ein move der konstante bei der multiplikation ersparen */
if(strcmp(instr, "imulq") == 0) {
if(KID_VAL(0) == 1 && strcmp(KID_REG(1), BN_REG) == 0) {
- printf("\t//multiplikation mit 1 wegoptimiert\n");
+ printf("\t#multiplikation mit 1 wegoptimiert\n");
} else {
printf("\timulq $%d, %%%s, %%%s\n", KID_VAL(0), KID_REG(1), BN_REG);
}
void gen_eqless(struct treenode *bnode, char *op, short e0, short e1, short deep)
{
- printf("\t//gen_eqless_%i%i @ %i\n", e0, e1, deep);
+ printf("\t#gen_eqless_%i%i @ %i\n", e0, e1, deep);
if(e0) { KIDREG2PARM(0); } else { KIDREG2ID(0); }
if(e1) { KIDREG2PARM(1); } else { KIDREG2ID(1); }
void gen_lea(struct treenode *bnode, short e)
{
- printf("\t//gen_lea(e= %i)\n", e);
+ printf("\t#gen_lea(e= %i)\n", e);
KIDREG2PARM(0);
if(e) {
KIDKIDREG2PARM(1,0);
void gen_subspecial(struct treenode *bnode, short e)
{
/* tritt z.b. bei snafu_05.0 auf */
- printf("\t//gen_subspecial(%i)\n", e);
+ printf("\t#gen_subspecial(%i)\n", e);
KIDREG2ID(0);
KIDKIDREG2PARM(1,0);
if(e) {
if(KIDKID_VAL(1,0) != 0) {
- printf("\tsubq $%d, %%%s\n", KIDKID_VAL(1,0), BN_REG);
+ printf("\tsubf $%d, %%%s\n", KIDKID_VAL(1,0), BN_REG);
}
} else {
- printf("\tsubq %%%s, %%%s\n", KIDKID_REG(1,0), BN_REG);
+ printf("\tsubf %%%s, %%%s\n", KIDKID_REG(1,0), BN_REG);
}
if(e) KIDKIDREG2PARM(1,1);
printf("\taddq %%%s, %%%s\n", KIDKID_REG(1,1), BN_REG);
void make_call(struct treenode *bnode)
{
int j;
- printf("\t//params pushen\n");
+ printf("\t#params pushen\n");
for(j = 0; j < bnode->soffset; j++) {
printf("\txchg %%%s, %d(%%rsp)\n", param_reg(j), j*8);
}
- printf("\t//vars pushen\n");
- for(j = bnode->soffset; j < bnode->soffset + bnode->vars; j++) {
+ printf("\t#vars pushen\n");
+ for(j = VARBEGIN; j > VARBEGIN - bnode->vars; j--) {
printf("\tpushq %%%s\n", param_reg(j));
}
/* TODO: schoener machen... */
if(strcmp(BN_REG, "rax")!=0) {
- printf("\t//tmp register pushen\n");
+ printf("\t#tmp register pushen\n");
printf("\tpushq %%rax\n");
if(strcmp(BN_REG, "r10")!=0) {
printf("\tpushq %%r10\n");
}
/* vars poppen */
- for(j = bnode->soffset + bnode->vars - 1; j > bnode->soffset - 1; j--) {
+ for(j = VARBEGIN+1 - bnode->vars; j < VARBEGIN+1; j++) {
printf("\tpopq %%%s\n", param_reg(j));
}
void prep_arg(struct treenode *bnode, int moveit)
{
- printf("\t//args-nr-> %i (%%%s) [moveit= %i]\n", bnode->soffset, param_reg(bnode->soffset), moveit);
+ printf("\t#args-nr-> %i (%%%s) [moveit= %i]\n", bnode->soffset, param_reg(bnode->soffset), moveit);
if(moveit) { /* expr */
if((BN_REG == (char *) NULL) || (bnode->kids[1] != TREENULL && bnode->kids[1]->op == O_ID && bnode->kids[1]->kids[0] == TREENULL && bnode->kids[1]->kids[1] == TREENULL)) {
if(bnode->kids[1]->name != (char *) NULL && strcmp(bnode->kids[1]->name,"this")!=0) {
void gen_sub_field(struct treenode *bnode)
{
/* siehe intelli_03.0 @ gesamt */
- printf("\t//gen_sub_field\n");
+ printf("\t#gen_sub_field\n");
KIDKIDREG2PARM(1,0);
if(!(strcmp(bnode->kids[0]->kids[0]->kids[0]->name, bnode->kids[1]->kids[0]->name) == 0 &&
bnode->kids[0]->kids[0]->soffset == bnode->kids[1]->soffset)) {
ifstat: O_IF(O_BOOL(expr)) # 1 # /* dann braucht man kein test */
-ret: O_RET(retexpr) # 2 # printf("\t//o_ret(expr)\n"); move(BN_REG, "rax");
+ret: O_RET(retexpr) # 2 # printf("\t/*o_ret(expr)*/\n"); move(BN_REG, "3");
ret: O_EXPR(expr) # 0 #
-retexpr: O_ID # 1 # printf("\t//retexpr\n"); if(bnode->param_index > -1) move(param_reg(bnode->param_index), BN_REG);
+retexpr: O_ID # 1 # printf("\t/*retexpr*/\n"); if(bnode->param_index > -1) move(param_reg(bnode->param_index), BN_REG);
retexpr: expr
expr: O_ARG(O_ID,expr) # 1 # prep_arg(bnode, 0);
expr: O_NOTHING # 0 #
-expr: O_SUB(expr,expr) # 2 # gen_e_eno(bnode, "subq");
-expr: O_SUB(expr,O_FIELD(expr)) # 2 # gen_e_field(bnode, "subq");
-expr: O_SUB(expr,imm) # 1 # gen_e_imm(bnode, "subq");
+expr: O_SUB(expr,expr) # 2 # gen_e_eno(bnode, "subf");
+expr: O_SUB(expr,O_FIELD(expr)) # 2 # gen_e_field(bnode, "subf");
+expr: O_SUB(expr,imm) # 1 # gen_e_imm(bnode, "subf");
expr: O_SUB(expr,O_SUB(O_ID,expr)) # 2 # gen_subspecial(bnode, 0);
expr: O_SUB(expr,O_SUB(imm,expr)) # 2 # gen_subspecial(bnode, 1);
expr: O_EQ(O_EQ(O_EQ(expr,O_NULL),O_NULL),O_NULL) # 3 # gen_eqless(bnode, "e", 1, 0, 2);
-expr: O_FIELD(expr) # 1 # printf("\t//field(expr)\n"); KIDREG2PARM(0); printf("\tmovq %d(%%%s), %%%s\n", bnode->soffset * 8, KID_REG(0), BN_REG);
-expr: O_FIELD(imm) # 1 # printf("\t//field(imm)\n"); printf("\tmovq %d, %%%s\n", KID_VAL(0) + (bnode->soffset * 8), BN_REG);
+expr: O_FIELD(expr) # 1 # printf("\t/* field(expr)*/\n"); KIDREG2PARM(0); printf("\tmovq %d(%%%s), %%%s\n", bnode->soffset * 8, KID_REG(0), BN_REG);
+expr: O_FIELD(imm) # 1 # printf("\t/* field(imm)*/\n"); printf("\tmovq %d, %%%s\n", KID_VAL(0) + (bnode->soffset * 8), BN_REG);
imm: O_ADD(imm,imm) # 0 # BN_VAL = KID_VAL(0) + KID_VAL(1);