kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

type.h (2746B)


      1 #ifndef KIT_CG_TYPE_H
      2 #define KIT_CG_TYPE_H
      3 
      4 #include <kit/cg.h>
      5 
      6 #include "core/core.h"
      7 
      8 typedef struct CgTypeField {
      9   KitSym name;
     10   KitCgTypeId type;
     11   u64 offset;
     12   u32 align_override;
     13   u32 max_align;
     14   u32 flags;
     15   u16 bit_width;
     16   u16 bit_offset;
     17   u32 bit_storage_size;
     18   int bit_signed;
     19 } CgTypeField;
     20 
     21 typedef struct CgType {
     22   KitCgTypeKind kind;
     23   u64 size;
     24   u32 align;
     25   u32 pad;
     26   union {
     27     struct {
     28       u32 width;
     29     } integer;
     30     struct {
     31       u32 width;
     32     } fp;
     33     struct {
     34       KitCgTypeId pointee;
     35       u32 address_space;
     36     } ptr;
     37     struct {
     38       KitCgTypeId elem;
     39       u64 count;
     40     } array;
     41     struct {
     42       KitCgFuncResult result; /* result.type == KIT_CG_TYPE_NONE == void */
     43       KitCgFuncParam* params;
     44       u32 nparams;
     45       KitCgCallConv call_conv;
     46       int abi_variadic;
     47     } func;
     48     struct {
     49       KitSym tag;
     50       CgTypeField* fields;
     51       u32 nfields;
     52       int is_union;
     53       u32 align_override;
     54       u32 flags;
     55     } record;
     56     struct {
     57       KitSym tag;
     58       KitCgTypeId base;
     59       KitCgEnumValue* values;
     60       u32 nvalues;
     61     } enum_;
     62     struct {
     63       KitSym name;
     64       KitCgTypeId base;
     65     } alias;
     66   };
     67 } CgType;
     68 
     69 const CgType* cg_type_get(Compiler*, KitCgTypeId);
     70 uint64_t cg_type_size(Compiler*, KitCgTypeId);
     71 uint32_t cg_type_align(Compiler*, KitCgTypeId);
     72 int cg_type_is_int(Compiler*, KitCgTypeId);
     73 int cg_type_is_float(Compiler*, KitCgTypeId);
     74 int cg_type_is_ptr(Compiler*, KitCgTypeId);
     75 int cg_type_is_record(Compiler*, KitCgTypeId);
     76 
     77 enum {
     78   CG_API_TYPE_SEG_SHIFT = 6,
     79   CG_API_TYPE_SEG_SIZE = 1u << CG_API_TYPE_SEG_SHIFT,
     80   CG_API_TYPE_SEG_MASK = CG_API_TYPE_SEG_SIZE - 1u,
     81   CG_API_TYPE_BUILTIN_SEG = 1u,
     82   CG_API_TYPE_USER_SEG_BIAS = 2u,
     83 };
     84 
     85 KitCgTypeId builtin_id(KitCgBuiltinType);
     86 KitCgTypeId resolve_type(Compiler*, KitCgTypeId);
     87 KitCgTypeId api_unalias_type(Compiler*, KitCgTypeId);
     88 int cg_type_is_void(Compiler*, KitCgTypeId);
     89 int cg_type_is_aggregate(Compiler*, KitCgTypeId);
     90 KitCgTypeId cg_type_ptr_to(Compiler*, KitCgTypeId);
     91 KitCgTypeId cg_type_pointee(Compiler*, KitCgTypeId);
     92 /* The function's result type, or the VOID builtin when it returns nothing. */
     93 KitCgTypeId cg_type_func_ret_id(Compiler*, KitCgTypeId);
     94 /* The function's raw result type, or KIT_CG_TYPE_NONE when it returns nothing
     95  * (the "has a result" predicate; cg_type_func_ret_id maps none -> VOID). */
     96 KitCgTypeId cg_type_func_result_id(Compiler*, KitCgTypeId);
     97 /* First-result type (or VOID) given a resolved KIT_CG_TYPE_FUNC CgType. For
     98  * the single-result/void consumers (ABI classification, source backends) that
     99  * already hold the CgType. */
    100 KitCgTypeId cg_func_ret_type(const CgType* fnty);
    101 KitCgTypeId cg_type_func_param_id(Compiler*, KitCgTypeId, uint32_t);
    102 
    103 #endif