diff options
| author | 2025-11-23 15:26:55 +0100 | |
|---|---|---|
| committer | 2025-11-23 15:33:38 +0100 | |
| commit | a9e0174fb69f3ddc85cd9c510b68cec22b6ebf42 (patch) | |
| tree | c633c8c514bdcc8b729050685adef3e1c4b826f2 /c | |
| parent | 1f72464c6451fcff16180d00af537225acc9b83c (diff) | |
c: __builtin_va_copy
Diffstat (limited to 'c')
| -rw-r--r-- | c/builtin.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/c/builtin.c b/c/builtin.c index 23e1872..29a3191 100644 --- a/c/builtin.c +++ b/c/builtin.c @@ -24,11 +24,11 @@ callcheck(const struct span *span, int nparam, const union type *param, int narg return ok; } -#define DEF_FNLIKE_SEMA(name, retty, ...) \ - static bool \ - name##_sema(struct comp *cm, struct expr *ex) { \ - static union type par[] = { {{0}}, __VA_ARGS__ }; \ - ex->ty = retty; \ +#define DEF_FNLIKE_SEMA(name, retty, ...) \ + static bool \ + name##_sema(struct comp *cm, struct expr *ex) { \ + union type par[] = { {{0}}, __VA_ARGS__ }; \ + ex->ty = retty; \ return callcheck(&ex->span, arraylength(par)-1, par+1, ex->narg, ex->sub+1); \ } @@ -50,6 +50,8 @@ va_start_comp(struct function *fn, struct expr *ex, bool discard) return NOREF; } +DEF_FNLIKE_SEMA(trap, mktype(TYVOID), ) + static bool va_end_sema(struct comp *cm, struct expr *ex) { @@ -63,7 +65,19 @@ va_end_comp(struct function *fn, struct expr *ex, bool discard) return NOREF; } -DEF_FNLIKE_SEMA(trap, mktype(TYVOID), ) +DEF_FNLIKE_SEMA(va_copy, mktype(TYVOID), cvalistty, cvalistty) + +static union ref +va_copy_comp(struct function *fn, struct expr *ex, bool discard) +{ + union irtype typ = mkirtype(cvalistty.t == TYARRAY ? typechild(cvalistty) : cvalistty); + assert(ex->sub[1].ty.bits == cvalistty.bits); + assert(ex->sub[2].ty.bits == cvalistty.bits); + addinstr(fn, mkarginstr(typ, compileexpr(fn, &ex->sub[1], 0))); + addinstr(fn, mkarginstr(typ, compileexpr(fn, &ex->sub[2], 0))); + addinstr(fn, mkintrin(INstructcopy, 0, 2)); + return NOREF; +} static union ref trap_comp(struct function *fn, struct expr *ex, bool discard) @@ -81,8 +95,7 @@ builtin_va_arg_comp(struct function *fn, const struct expr *ex, bool discard) } #define LIST_BUILTINS(_) \ - _(va_start) \ - _(va_end) \ + _(va_start) _(va_copy) _(va_end) \ _(trap) static const struct { |