diff options
| author | Michael Forney <mforney@mforney.org> | 2019-03-13 12:48:18 -0700 | 
|---|---|---|
| committer | Michael Forney <mforney@mforney.org> | 2019-03-13 12:48:18 -0700 | 
| commit | 9d3c8863100040175c56d7ba53ca98a9ad637e57 (patch) | |
| tree | 1d114f52a9990829b016d9e2c2ea07f9b00abd40 | |
| parent | b46de4e7fcf6bc519f2fc1dc7f5e8c2fc0db67d7 (diff) | |
| download | cproc-9d3c8863100040175c56d7ba53ca98a9ad637e57.tar.xz | |
Use instruction op for varargs call instead of "ellipsis" value
| -rw-r--r-- | ops.h | 1 | ||||
| -rw-r--r-- | qbe.c | 21 | 
2 files changed, 9 insertions, 13 deletions
| @@ -99,6 +99,7 @@ OP(ICOPY,    1, 1, "copy")  /* call */  OP(ICALL,    1, -1, "call") +OP(IVACALL,  1, -1, "call")  /* variadic */  OP(IVASTART, 0, 1, "vastart") @@ -35,7 +35,6 @@ struct value {  		VALCONST,  		VALLABEL,  		VALTEMP, -		VALELLIPSIS,  	} kind;  	struct representation *repr;  	union { @@ -579,7 +578,6 @@ extend(struct function *f, struct type *t, struct value *v)  struct value *  funcexpr(struct function *f, struct expression *e)  { -	static struct value ellipsis = {.kind = VALELLIPSIS};  	enum instructionkind op = INONE;  	struct declaration *d;  	struct value *l, *r, *v, *addr, **argvals, **argval; @@ -626,10 +624,9 @@ funcexpr(struct function *f, struct expression *e)  			emittype(arg->type);  			*argval = funcexpr(f, arg);  		} -		if (e->call.func->type->base->func.isvararg) -			*argval++ = &ellipsis;  		*argval = NULL; -		return funcinstn(f, ICALL, e->type == &typevoid ? NULL : e->type->repr, argvals); +		op = e->call.func->type->base->func.isvararg ? IVACALL : ICALL; +		return funcinstn(f, op, e->type == &typevoid ? NULL : e->type->repr, argvals);  		//if (e->call.func->type->base->func.isnoreturn)  		//	funcret(f, NULL);  	case EXPRUNARY: @@ -978,9 +975,6 @@ emitvalue(struct value *v)  		else  			printf("%" PRIu64, v->i);  		break; -	case VALELLIPSIS: -		fputs("...", stdout); -		break;  	default:  		if (v->kind >= LEN(sigil) || !sigil[v->kind])  			fatal("invalid value"); @@ -1053,24 +1047,25 @@ emitinst(struct instruction *inst)  	if (instdesc[inst->kind].ret && inst->res.kind) {  		emitvalue(&inst->res);  		fputs(" =", stdout); -		emitrepr(inst->res.repr, inst->kind == ICALL, false); +		emitrepr(inst->res.repr, inst->kind == ICALL || inst->kind == IVACALL, false);  		putchar(' ');  	}  	fputs(instdesc[inst->kind].str, stdout);  	switch (inst->kind) {  	case ICALL: +	case IVACALL:  		putchar(' ');  		emitvalue(inst->arg[0]);  		putchar('(');  		for (arg = &inst->arg[1]; *arg; ++arg) {  			if (arg != &inst->arg[1])  				fputs(", ", stdout); -			if ((*arg)->kind != VALELLIPSIS) { -				emitrepr((*arg)->repr, true, false); -				putchar(' '); -			} +			emitrepr((*arg)->repr, true, false); +			putchar(' ');  			emitvalue(*arg);  		} +		if (inst->kind == IVACALL) +			fputs(", ...", stdout);  		putchar(')');  		break;  	case IPHI: | 
