commit 41e811569595232008a319c4131901b399d7549d
parent 97cfc1bcbb9bb4e73d23211e7983e99490da6164
Author: Drew DeVault <sir@cmpwn.com>
Date: Wed, 4 Aug 2021 12:52:22 +0200
gen: introduce gen_copy_aligned, refactor copy
Most composite types can share the same copy implementation with this
design, which streamlines things quite a bit. We still use memcpy for
unions, and tagged unions are to be addressed later.
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/src/gen.c b/src/gen.c
@@ -25,12 +25,10 @@ gen_copy_memcpy(struct gen_context *ctx,
}
static void
-gen_copy_struct(struct gen_context *ctx,
+gen_copy_aligned(struct gen_context *ctx,
struct gen_value dest, struct gen_value src)
{
- const struct type *stype = type_dealias(dest.type);
- assert(stype->storage == STORAGE_STRUCT);
- if (stype->size > 128) {
+ if (dest.type->size > 128) {
gen_copy_memcpy(ctx, dest, src);
return;
}
@@ -73,13 +71,11 @@ gen_store(struct gen_context *ctx,
case STORAGE_ARRAY:
case STORAGE_SLICE:
case STORAGE_STRING:
- gen_copy_memcpy(ctx, object, value); // TODO
- return;
case STORAGE_STRUCT:
- gen_copy_struct(ctx, object, value);
+ case STORAGE_TUPLE:
+ gen_copy_aligned(ctx, object, value);
return;
case STORAGE_TAGGED:
- case STORAGE_TUPLE:
assert(0); // TODO
case STORAGE_UNION:
gen_copy_memcpy(ctx, object, value);