mirror of https://github.com/rui314/chibicc
Support variadic function with floating-point parameters
This commit is contained in:
parent
8b14859f63
commit
e452cf7215
13
codegen.c
13
codegen.c
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue