1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-26 02:07:19 +00:00
janet/src/core/regalloc.h

68 lines
2.6 KiB
C
Raw Normal View History

2018-07-01 15:52:15 +00:00
/*
* Copyright (c) 2018 Calvin Rose
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
/* Implements a simple first fit register allocator for the compiler. */
2018-09-06 02:18:42 +00:00
#ifndef JANET_REGALLOC_H
#define JANET_REGALLOC_H
2018-07-01 15:52:15 +00:00
#include <stdint.h>
/* Placeholder for allocating temporary registers */
typedef enum {
2018-09-06 02:18:42 +00:00
JANETC_REGTEMP_0,
JANETC_REGTEMP_1,
JANETC_REGTEMP_2,
JANETC_REGTEMP_3,
JANETC_REGTEMP_4,
JANETC_REGTEMP_5,
JANETC_REGTEMP_6,
JANETC_REGTEMP_7
} JanetcRegisterTemp;
2018-07-01 15:52:15 +00:00
typedef struct {
uint32_t *chunks;
int32_t count; /* number of chunks in chunks */
int32_t capacity; /* amount allocated for chunks */
int32_t max; /* The maximum allocated register so far */
2018-07-01 19:49:33 +00:00
int32_t regtemps; /* Hold which tempregistered are alloced. */
2018-09-06 02:18:42 +00:00
} JanetcRegisterAllocator;
2018-07-01 15:52:15 +00:00
2018-09-06 02:18:42 +00:00
void janetc_regalloc_init(JanetcRegisterAllocator *ra);
void janetc_regalloc_deinit(JanetcRegisterAllocator *ra);
2018-07-01 15:52:15 +00:00
2018-09-06 02:18:42 +00:00
int32_t janetc_regalloc_1(JanetcRegisterAllocator *ra);
void janetc_regalloc_free(JanetcRegisterAllocator *ra, int32_t reg);
int32_t janetc_regalloc_temp(JanetcRegisterAllocator *ra, JanetcRegisterTemp nth);
void janetc_regalloc_freetemp(JanetcRegisterAllocator *ra, int32_t reg, JanetcRegisterTemp nth);
void janetc_regalloc_clone(JanetcRegisterAllocator *dest, JanetcRegisterAllocator *src);
void janetc_regalloc_touch(JanetcRegisterAllocator *ra, int32_t reg);
2018-07-01 15:52:15 +00:00
2018-07-01 19:49:33 +00:00
/* Mutli-slot allocation disabled */
2018-07-01 15:52:15 +00:00
/*
2018-09-06 02:18:42 +00:00
int32_t janetc_regalloc_n(JanetcRegisterAllocator *ra, int32_t n);
int32_t janetc_regalloc_call(JanetcRegisterAllocator *ra, int32_t callee, int32_t nargs);
void janetc_regalloc_freerange(JanetcRegisterAllocator *ra, int32_t regstart, int32_t n);
2018-07-01 15:52:15 +00:00
*/
#endif