2 * Copyright (C) 2024 Mikulas Patocka
4 * This file is part of Ajla.
6 * Ajla is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, either version 3 of the License, or (at your option) any later
11 * Ajla is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * Ajla. If not, see <https://www.gnu.org/licenses/>.
19 static const struct type *get_type_of_local(struct codegen_context *ctx, frame_t pos)
22 const struct data *function = ctx->fn;
23 t = da(function,function)->local_variables[pos].type;
25 TYPE_TAG_VALIDATE(t->tag);
29 static unsigned real_type_to_op_size(unsigned real_type)
32 case 0: return OP_SIZE_2;
33 case 1: return OP_SIZE_4;
34 case 2: return OP_SIZE_8;
35 case 3: return OP_SIZE_10;
36 case 4: return OP_SIZE_16;
38 internal(file_line, "real_type_to_op_size: invalid type %u", real_type);
43 static unsigned spill_size(const struct type *t)
45 if (TYPE_TAG_IS_REAL(t->tag)) {
46 return real_type_to_op_size(TYPE_TAG_IDX_REAL(t->tag));
48 return log_2(t->size);
52 static bool attr_w gen_frame_load_raw(struct codegen_context *ctx, unsigned size, enum extend ex, frame_t slot, int64_t offset, unsigned reg);
53 static bool attr_w gen_frame_store_raw(struct codegen_context *ctx, unsigned size, frame_t slot, int64_t offset, unsigned reg);
55 static bool attr_w spill(struct codegen_context *ctx, frame_t v)
57 const struct type *t = get_type_of_local(ctx, v);
58 g(gen_frame_store_raw(ctx, spill_size(t), v, 0, ctx->registers[v]));
62 static bool attr_w unspill(struct codegen_context *ctx, frame_t v)
64 const struct type *t = get_type_of_local(ctx, v);
65 g(gen_frame_load_raw(ctx, spill_size(t), garbage, v, 0, ctx->registers[v]));