kit

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

asm_lex.h (2005B)


      1 #ifndef KIT_ASM_LEX_H
      2 #define KIT_ASM_LEX_H
      3 
      4 #include "core/core.h"
      5 
      6 typedef enum AsmTokKind {
      7   ASM_TOK_EOF = 0,
      8   ASM_TOK_IDENT,
      9   ASM_TOK_NUM,
     10   ASM_TOK_FLT,
     11   ASM_TOK_STR,
     12   ASM_TOK_CHR,
     13   ASM_TOK_PUNCT,
     14   ASM_TOK_HASH,
     15   ASM_TOK_HASH_HASH,
     16   ASM_TOK_NEWLINE,
     17 } AsmTokKind;
     18 
     19 typedef enum AsmTokFlag {
     20   ASM_TF_AT_BOL = 1u << 0,
     21   ASM_TF_HAS_SPACE = 1u << 1,
     22   ASM_TF_INT_U = 1u << 3,
     23   ASM_TF_INT_L = 1u << 4,
     24   ASM_TF_INT_LL = 1u << 5,
     25   ASM_TF_FLT_F = 1u << 6,
     26   ASM_TF_FLT_L = 1u << 7,
     27   ASM_TF_STR_WIDE = 1u << 8,
     28   ASM_TF_STR_U8 = 1u << 9,
     29   ASM_TF_STR_U16 = 1u << 10,
     30   ASM_TF_STR_U32 = 1u << 11,
     31   ASM_TF_LITERAL_BAD = 1u << 12,
     32 } AsmTokFlag;
     33 
     34 typedef enum AsmPunct {
     35   ASM_P_NONE = 0,
     36   ASM_P_ARROW = 256,
     37   ASM_P_INC,
     38   ASM_P_DEC,
     39   ASM_P_SHL,
     40   ASM_P_SHR,
     41   ASM_P_LE,
     42   ASM_P_GE,
     43   ASM_P_EQ,
     44   ASM_P_NE,
     45   ASM_P_AND,
     46   ASM_P_OR,
     47   ASM_P_ADD_ASSIGN,
     48   ASM_P_SUB_ASSIGN,
     49   ASM_P_MUL_ASSIGN,
     50   ASM_P_DIV_ASSIGN,
     51   ASM_P_MOD_ASSIGN,
     52   ASM_P_AND_ASSIGN,
     53   ASM_P_OR_ASSIGN,
     54   ASM_P_XOR_ASSIGN,
     55   ASM_P_SHL_ASSIGN,
     56   ASM_P_SHR_ASSIGN,
     57   ASM_P_ELLIPSIS,
     58   ASM_P_HASH_HASH,
     59 } AsmPunct;
     60 
     61 typedef u32 AsmLitId;
     62 #define ASM_LIT_NONE 0u
     63 
     64 typedef enum AsmLitKind {
     65   ASM_LIT_INT,
     66   ASM_LIT_FLOAT,
     67   ASM_LIT_STRING,
     68   ASM_LIT_CHAR,
     69 } AsmLitKind;
     70 
     71 typedef enum AsmLitEnc {
     72   ASM_LENC_ORDINARY,
     73   ASM_LENC_UTF8,
     74   ASM_LENC_WIDE,
     75   ASM_LENC_UTF16,
     76   ASM_LENC_UTF32,
     77 } AsmLitEnc;
     78 
     79 typedef struct AsmLitInfo {
     80   u8 kind;
     81   u8 enc;
     82   u16 flags;
     83   Sym spelling;
     84   BytesId bytes;
     85 } AsmLitInfo;
     86 
     87 typedef struct AsmTok {
     88   u16 kind;
     89   u16 flags;
     90   SrcLoc loc;
     91   Sym spelling;
     92   AsmLitId lit;
     93   union {
     94     Sym ident;
     95     Sym str;
     96     u32 punct;
     97   } v;
     98 } AsmTok;
     99 
    100 typedef struct AsmLexer AsmLexer;
    101 
    102 AsmLexer* asm_lex_open_mem(Compiler*, const char* name, const char* src,
    103                            size_t len);
    104 void asm_lex_close(AsmLexer*);
    105 
    106 AsmTok asm_lex_next(AsmLexer*);
    107 SrcLoc asm_lex_loc(const AsmLexer*);
    108 u32 asm_lex_file_id(const AsmLexer*);
    109 const AsmLitInfo* asm_lex_lit(const AsmLexer*, AsmLitId);
    110 
    111 #endif