asm: implement asembly lexer
This commit is contained in:
@@ -2,5 +2,5 @@ file(GLOB_RECURSE asm_sources *.c *.h include/ivy/asm/*.h)
|
|||||||
|
|
||||||
add_library(ivy-asm SHARED ${asm_sources})
|
add_library(ivy-asm SHARED ${asm_sources})
|
||||||
target_include_directories(ivy-asm PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)
|
target_include_directories(ivy-asm PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)
|
||||||
target_link_libraries(ivy-asm ivy-common)
|
target_link_libraries(ivy-asm ivy-common Bluelib::Core Bluelib::Object)
|
||||||
target_compile_definitions(ivy-asm PRIVATE IVY_EXPORT=1)
|
target_compile_definitions(ivy-asm PRIVATE IVY_EXPORT=1)
|
||||||
@@ -1,8 +1,89 @@
|
|||||||
#ifndef IVY_ASM_LEX_H_
|
#ifndef IVY_ASM_LEX_H_
|
||||||
#define IVY_ASM_LEX_H_
|
#define IVY_ASM_LEX_H_
|
||||||
|
|
||||||
|
#include <ivy/line-source.h>
|
||||||
#include <ivy/misc.h>
|
#include <ivy/misc.h>
|
||||||
|
#include <ivy/status.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
IVY_API void placeholder12(void);
|
enum ivy_asm_token_type {
|
||||||
|
IVY_ASM_TOK_NONE = 0,
|
||||||
|
IVY_ASM_TOK_KEYWORD,
|
||||||
|
IVY_ASM_TOK_SYMBOL,
|
||||||
|
IVY_ASM_TOK_INT,
|
||||||
|
IVY_ASM_TOK_DOUBLE,
|
||||||
|
IVY_ASM_TOK_LABEL,
|
||||||
|
IVY_ASM_TOK_IDENT,
|
||||||
|
IVY_ASM_TOK_STRING,
|
||||||
|
IVY_ASM_TOK_LINEFEED,
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
enum ivy_asm_keyword {
|
||||||
|
IVY_ASM_KW_NONE = 0,
|
||||||
|
IVY_ASM_KW_USE,
|
||||||
|
IVY_ASM_KW_IDENT,
|
||||||
|
IVY_ASM_KW_SELECTOR,
|
||||||
|
IVY_ASM_KW_ATOM,
|
||||||
|
IVY_ASM_KW_LAMBDA,
|
||||||
|
IVY_ASM_KW_CONSTPOOL,
|
||||||
|
IVY_ASM_KW_CLASS,
|
||||||
|
IVY_ASM_KW_MSGH,
|
||||||
|
IVY_ASM_KW_END,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ivy_asm_symbol {
|
||||||
|
IVY_ASM_SYM_NONE = 0,
|
||||||
|
IVY_ASM_SYM_DOT,
|
||||||
|
IVY_ASM_SYM_COMMA,
|
||||||
|
IVY_ASM_SYM_LEFT_PAREN,
|
||||||
|
IVY_ASM_SYM_RIGHT_PAREN,
|
||||||
|
IVY_ASM_SYM_LEFT_BRACKET,
|
||||||
|
IVY_ASM_SYM_RIGHT_BRACKET,
|
||||||
|
IVY_ASM_SYM_COLON,
|
||||||
|
IVY_ASM_SYM_SEMICOLON,
|
||||||
|
IVY_ASM_SYM_DOLLAR,
|
||||||
|
IVY_ASM_SYM_HYPHEN,
|
||||||
|
IVY_ASM_SYM_SQUOTE,
|
||||||
|
IVY_ASM_SYM_DQUOTE,
|
||||||
|
IVY_ASM_SYM_FORWARD_SLASH_ASTERISK,
|
||||||
|
IVY_ASM_SYM_ASTERISK_FORWARD_SLASH,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ivy_asm_token {
|
||||||
|
enum ivy_asm_token_type t_type;
|
||||||
|
struct ivy_asm_token *t_next;
|
||||||
|
|
||||||
|
union {
|
||||||
|
enum ivy_asm_keyword t_keyword;
|
||||||
|
enum ivy_asm_symbol t_symbol;
|
||||||
|
struct {
|
||||||
|
long long v;
|
||||||
|
unsigned long long uv;
|
||||||
|
bool sign;
|
||||||
|
} t_int;
|
||||||
|
double t_double;
|
||||||
|
char *t_str;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ivy_asm_lexer_symbol_node;
|
||||||
|
struct ivy_asm_lexer_state;
|
||||||
|
struct ivy_asm_lexer;
|
||||||
|
|
||||||
|
IVY_API enum ivy_status ivy_asm_lexer_create(struct ivy_asm_lexer **lex);
|
||||||
|
IVY_API void ivy_asm_lexer_destroy(struct ivy_asm_lexer *lex);
|
||||||
|
|
||||||
|
IVY_API void ivy_asm_lexer_set_source(
|
||||||
|
struct ivy_asm_lexer *lex, struct ivy_line_source *src);
|
||||||
|
IVY_API enum ivy_status ivy_asm_lexer_get_status(struct ivy_asm_lexer *lex);
|
||||||
|
|
||||||
|
IVY_API struct ivy_asm_token *ivy_asm_lexer_peek(struct ivy_asm_lexer *lex);
|
||||||
|
IVY_API struct ivy_asm_token *ivy_asm_lexer_read(struct ivy_asm_lexer *lex);
|
||||||
|
|
||||||
|
IVY_API void ivy_asm_token_destroy(struct ivy_asm_token *tok);
|
||||||
|
|
||||||
|
IVY_API const char *ivy_asm_token_type_to_string(enum ivy_asm_token_type type);
|
||||||
|
IVY_API const char *ivy_asm_keyword_to_string(enum ivy_asm_keyword keyword);
|
||||||
|
IVY_API const char *ivy_asm_symbol_to_string(enum ivy_asm_symbol sym);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
53
asm/lex.h
Normal file
53
asm/lex.h
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#ifndef _LEX_H_
|
||||||
|
#define _LEX_H_
|
||||||
|
|
||||||
|
#include <blue/core/queue.h>
|
||||||
|
#include <blue/object/string.h>
|
||||||
|
#include <blue/object/dict.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
enum lexer_state_type {
|
||||||
|
STATE_NORMAL,
|
||||||
|
STATE_STRING,
|
||||||
|
STATE_DSTRING,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct lexer_state {
|
||||||
|
enum lexer_state_type s_type;
|
||||||
|
b_queue_entry s_entry;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ivy_asm_lexer_symbol_node {
|
||||||
|
char s_char;
|
||||||
|
enum ivy_symbol s_id;
|
||||||
|
|
||||||
|
b_queue_entry s_entry;
|
||||||
|
b_queue s_children;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct lex_token_def {
|
||||||
|
int id;
|
||||||
|
const char *name;
|
||||||
|
uint64_t name_hash;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ivy_asm_lexer {
|
||||||
|
struct ivy_asm_lexer_symbol_node *lex_sym_tree;
|
||||||
|
struct ivy_line_source *lex_source;
|
||||||
|
b_dict *lex_keywords;
|
||||||
|
enum ivy_status lex_status;
|
||||||
|
|
||||||
|
struct ivy_asm_token *lex_queue;
|
||||||
|
enum ivy_asm_token_type lex_prev_token;
|
||||||
|
|
||||||
|
b_string *lex_temp;
|
||||||
|
b_queue lex_state;
|
||||||
|
unsigned int lex_brace_depth;
|
||||||
|
|
||||||
|
char *lex_linebuf;
|
||||||
|
size_t lex_linebuf_len;
|
||||||
|
size_t lex_linebuf_cap;
|
||||||
|
size_t lex_linebuf_ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user