asm: implement $-prefixed label references for branch instructions
This commit is contained in:
44
asm/lex.c
44
asm/lex.c
@@ -47,7 +47,6 @@ static struct lex_token_def symbols[] = {
|
||||
LEX_TOKEN_DEF(IVY_ASM_SYM_RIGHT_BRACE, "}"),
|
||||
LEX_TOKEN_DEF(IVY_ASM_SYM_COLON, ":"),
|
||||
LEX_TOKEN_DEF(IVY_ASM_SYM_SEMICOLON, ";"),
|
||||
LEX_TOKEN_DEF(IVY_ASM_SYM_DOLLAR, "$"),
|
||||
LEX_TOKEN_DEF(IVY_ASM_SYM_HYPHEN, "-"),
|
||||
LEX_TOKEN_DEF(IVY_ASM_SYM_SQUOTE, "'"),
|
||||
LEX_TOKEN_DEF(IVY_ASM_SYM_DQUOTE, "\""),
|
||||
@@ -853,6 +852,43 @@ static enum ivy_status read_keyword(struct ivy_asm_lexer *lex)
|
||||
return push_keyword(lex, keyword);
|
||||
}
|
||||
|
||||
static enum ivy_status read_label_ref(struct ivy_asm_lexer *lex)
|
||||
{
|
||||
advance(lex);
|
||||
|
||||
b_string *str = get_temp_string(lex);
|
||||
bool label = false;
|
||||
|
||||
while (true) {
|
||||
int c = peek(lex);
|
||||
|
||||
if (c < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (c == ':' && peek_next(lex) != ':') {
|
||||
advance(lex);
|
||||
label = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isalnum(c) && c != '_') {
|
||||
break;
|
||||
}
|
||||
|
||||
char s[2] = {c, 0};
|
||||
b_string_append_cstr(str, s);
|
||||
advance(lex);
|
||||
}
|
||||
|
||||
const char *s = b_string_ptr(str);
|
||||
|
||||
struct ivy_asm_token *tok = create_token(IVY_ASM_TOK_LABEL_REF);
|
||||
tok->t_str = b_string_steal(str);
|
||||
|
||||
return push_token(lex, tok);
|
||||
}
|
||||
|
||||
static enum ivy_status read_ident(struct ivy_asm_lexer *lex)
|
||||
{
|
||||
b_string *str = get_temp_string(lex);
|
||||
@@ -942,6 +978,10 @@ static enum ivy_status pump_tokens(struct ivy_asm_lexer *lex)
|
||||
return read_symbol(lex);
|
||||
}
|
||||
|
||||
if (c == '$') {
|
||||
return read_label_ref(lex);
|
||||
}
|
||||
|
||||
if (c == '@') {
|
||||
return read_keyword(lex);
|
||||
}
|
||||
@@ -1018,6 +1058,7 @@ const char *ivy_asm_token_type_to_string(enum ivy_asm_token_type type)
|
||||
ENUM_STR(IVY_ASM_TOK_INT);
|
||||
ENUM_STR(IVY_ASM_TOK_DOUBLE);
|
||||
ENUM_STR(IVY_ASM_TOK_LABEL);
|
||||
ENUM_STR(IVY_ASM_TOK_LABEL_REF);
|
||||
ENUM_STR(IVY_ASM_TOK_IDENT);
|
||||
ENUM_STR(IVY_ASM_TOK_STRING);
|
||||
ENUM_STR(IVY_ASM_TOK_LINEFEED);
|
||||
@@ -1064,7 +1105,6 @@ const char *ivy_asm_symbol_to_string(enum ivy_asm_symbol sym)
|
||||
ENUM_STR(IVY_ASM_SYM_HYPHEN);
|
||||
ENUM_STR(IVY_ASM_SYM_COMMA);
|
||||
ENUM_STR(IVY_ASM_SYM_SEMICOLON);
|
||||
ENUM_STR(IVY_ASM_SYM_DOLLAR);
|
||||
ENUM_STR(IVY_ASM_SYM_FORWARD_SLASH_ASTERISK);
|
||||
default:
|
||||
return "";
|
||||
|
||||
Reference in New Issue
Block a user