printf("\tsub $%d, %%%s\n", KIDKID_VAL(0,1), KID_REG(1));
}
-/* ... dirty */
-static short sc[8] = {0};
void make_call(struct treenode *bnode)
{
- int j;
+ short *sc = bnode->sc;
+ int j, off = 0;
printf("\t//params pushen\n");
for(j = 0; j < bnode->soffset; j++) {
if(sc[j] == 1)
- printf("\txchg %%%s, %d(%%rsp)\n", param_reg(j), j*8);
- else if (sc[j] == 0)
- printf("\tpushq %%%s\n", param_reg(j));
+ printf("\txchg %%%s, %d(%%rsp)\n", param_reg(j), (j - off)*8);
+ else {
+ if (sc[j] == 0) {
+ printf("\tpushq %%%s\n", param_reg(j));
+ off++;
+ }
+ }
}
printf("\t//vars pushen\n");
for(j = bnode->soffset; j < bnode->soffset + bnode->vars; j++) {
printf("\tpopq %%rax\n");
}
- /* vars poppen */
+ printf("\t//vars poppen\n");
for(j = bnode->soffset + bnode->vars - 1; j > bnode->soffset - 1; j--) {
printf("\tpopq %%%s\n", param_reg(j));
}
- /* params poppen */
+ printf("\t//params poppen (sc == 0)\n");
for(j = bnode->soffset - 1; j >= 0; j--) {
if(sc[j] == 0)
printf("\tpopq %%%s\n", param_reg(j));
}
+ printf("\t//params poppen (sc != 0)\n");
for(j = 0; j < bnode->soffset; j++) {
if(sc[j] > 0)
printf("\tpopq %%%s\n", param_reg(j));
void prep_arg(struct treenode *bnode, int moveit)
{
+ short *sc = bnode->sc;
printf("\t//args-nr-> %i (%%%s) [moveit= %i]\n", bnode->soffset, param_reg(bnode->soffset), moveit);
sc[bnode->soffset] = 1;
- 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) {
- KIDREG2PARM(1);
- printf("\tpushq %%%s\n", KID_REG(1));
- } else {
- printf("\tpushq %%%s\n", param_reg(bnode->soffset));
- sc[bnode->soffset] = 2;
- }
+ if(moveit == 1) { /* expr */
+ if(( bnode->kids[0] != TREENULL && bnode->kids[0]->op == O_NOTHING &&
+ bnode->kids[0] != TREENULL && bnode->kids[0]->op == O_NOTHING)) {
+ printf("\tpushq %%%s\n", param_reg(bnode->soffset));
+ sc[bnode->soffset] = 2;
} else {
printf("\tpushq %%%s\n", BN_REG);
}
- } else { /* just O_ID */
+ } else if(moveit == 2) { /* O_ID right */
+ KIDREG2PARM(1);
+ printf("\tpushq %%%s\n", KID_REG(1));
+ } else if(moveit == 0) { /* O_ID left */
KIDREG2PARM(0);
printf("\tpushq %%%s\n", KID_REG(0));
}
expr: imm # 1 # moveimm(BN_VAL, BN_REG);
expr: O_BOOL(expr) # 0 #
-expr: O_CALL(expr) # 0 # make_call(bnode);
+expr: O_CALL(expr,expr) # 0 # make_call(bnode);
expr: O_ARG(expr,expr) # 1 # prep_arg(bnode, 1);
expr: O_ARG(O_ID,expr) # 1 # prep_arg(bnode, 0);
+expr: O_ARG(expr,O_ID) # 1 # prep_arg(bnode, 2);
expr: O_NOTHING # 0 #
expr: O_SUB(expr,expr) # 2 # gen_e_eno(bnode, "subq");
| IDENT '(' Exprs ')'
@{
@i {
- @Term.node@ = new_call(@IDENT.name@, new_arg(@Exprs.node@, new_nothing(), 0) /*this*/,
- TREENULL, @Term.gparamges@, @Term.vars_in@);
+ @Term.node@ = new_call(@IDENT.name@, @Exprs.node@, new_arg(new_nothing(), new_nothing(), 0) /*this*/,
+ @Term.gparamges@, @Term.vars_in@);
@Term.node@->soffset = MAX(@Exprs.paramcount@, @Term.gparamges@);
+ @Term.node@->sc = @Term.node@->kids[1]->sc = @Exprs.node@->sc;
}
@i @Exprs.cnt@ = 1;
@i @Term.imm@ = 0;
| Term '.' IDENT '(' Exprs ')'
@{
@i {
- @Term.node@ = new_call(@IDENT.name@, new_arg(@Exprs.node@, @Term.1.node@, 0) /*this*/,
- TREENULL, @Term.gparamges@, @Term.vars_in@);
+ @Term.node@ = new_call(@IDENT.name@, @Exprs.node@, new_arg(@Term.1.node@, new_nothing(), 0) /*this*/,
+ @Term.gparamges@, @Term.vars_in@);
@Term.node@->soffset = MAX(@Exprs.paramcount@, @Term.gparamges@);
+ @Term.node@->sc = @Term.node@->kids[1]->sc = @Exprs.node@->sc;
}
@i @Exprs.cnt@ = 1;
@i @Term.imm@ = 0;
@i @Term.call@ = 1;
- @reg @Exprs.node@->reg = @Term.1.node@->reg = @Term.node@->kids[0]->reg = @Term.node@->reg;
+ @reg @Exprs.node@->reg = @Term.1.node@->reg = @Term.node@->kids[1]->reg = @Term.node@->reg;
@}
;
Exprs:
Expr ',' Exprs
@{
- @i @Exprs.0.node@ = new_arg(@Expr.0.node@, @Exprs.1.node@, @Exprs.0.cnt@);
+ @i {
+ @Exprs.0.node@ = new_arg(@Exprs.1.node@, @Expr.0.node@, @Exprs.0.cnt@);
+ @Exprs.0.node@->sc = @Exprs.1.node@->sc;
+ }
@i @Exprs.0.paramcount@ = @Exprs.1.paramcount@;
@i @Exprs.1.cnt@ = @Exprs.0.cnt@ + 1;
@reg {
@}
| Expr
@{
- @i @Exprs.0.node@ = new_arg(@Expr.0.node@, new_nothing(), @Exprs.cnt@);
+ @i {
+ @Exprs.0.node@ = new_arg(@Expr.0.node@, new_nothing(), @Exprs.cnt@);
+ @Exprs.0.node@->sc = malloc(8 * sizeof(short));
+ }
@i @Exprs.paramcount@ = @Exprs.cnt@ + 1;
@reg @Expr.node@->reg = @Exprs.0.node@->reg;
@}
|
@{
- @i @Exprs.0.node@ = new_nothing();
+ @i {
+ @Exprs.0.node@ = new_nothing();
+ @Exprs.0.node@->sc = malloc(8 * sizeof(short));
+ }
@i @Exprs.paramcount@ = @Exprs.cnt@;
@}
;