harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 40ea5a9032b91a52003aaae30f02381d89faa4f4
parent 6b506fe9fe1333efa974b2206a307d7647c47735
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat,  3 Jul 2021 11:04:33 -0400

gen: implement struct/union copy

Just based on memcpy for now, more efficient version to come later.

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Msrc/gen.c | 23+++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -157,6 +157,21 @@ gen_copy_array(struct gen_context *ctx, gen_copy_memcpy(ctx, dest, src); } +static void +gen_copy_struct(struct gen_context *ctx, + const struct gen_temp *dest, + const struct gen_temp *src) +{ + const struct type *stype = type_dealias(dest->type); + assert(stype->storage == STORAGE_STRUCT); + if (stype->size > 32) { + gen_copy_memcpy(ctx, dest, src); + return; + } + // TODO: Generate more efficient approach + gen_copy_memcpy(ctx, dest, src); +} + // Generates a copy operation from one gen temporary to another. For primitive // types this is a load+store operation; for aggregate types this may emit more // complex code or a memcpy. @@ -193,12 +208,16 @@ gen_copy(struct gen_context *ctx, case STORAGE_ARRAY: gen_copy_array(ctx, dest, src); return; + case STORAGE_STRUCT: + gen_copy_struct(ctx, dest, src); + return; + case STORAGE_UNION: + gen_copy_memcpy(ctx, dest, src); + return; case STORAGE_SLICE: case STORAGE_STRING: - case STORAGE_STRUCT: case STORAGE_TAGGED: case STORAGE_TUPLE: - case STORAGE_UNION: assert(0); // TODO case STORAGE_ALIAS: case STORAGE_FCONST: