Support variadic function with floating-point parameters

This commit is contained in:
Rui Ueyama 2020-05-01 17:36:12 +09:00
parent 8b14859f63
commit e452cf7215
2 changed files with 11 additions and 4 deletions

View File

@ -786,14 +786,19 @@ static void emit_text(Obj *prog) {
// Save arg registers if function is variadic
if (fn->va_area) {
int gp = 0;
for (Obj *var = fn->params; var; var = var->next)
gp++;
int gp = 0, fp = 0;
for (Obj *var = fn->params; var; var = var->next) {
if (is_flonum(var->ty))
fp++;
else
gp++;
}
int off = fn->va_area->offset;
// va_elem
println(" movl $%d, %d(%%rbp)", gp * 8, off);
println(" movl $0, %d(%%rbp)", off + 4);
println(" movl $%d, %d(%%rbp)", fp * 8 + 48, off + 4);
println(" movq %%rbp, %d(%%rbp)", off + 16);
println(" addq $%d, %d(%%rbp)", off + 24, off + 16);

View File

@ -176,6 +176,8 @@ int main() {
ASSERT(0, ({ char buf[100]; sprintf(buf, "%.1f", (float)3.5); strcmp(buf, "3.5"); }));
ASSERT(0, ({ char buf[100]; fmt(buf, "%.1f", (float)3.5); strcmp(buf, "3.5"); }));
printf("OK\n");
return 0;
}