asm: fix compiler warnings
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
#include "assembler.h"
|
||||
|
||||
#include <ivy/asm/bin.h>
|
||||
#include <ivy/ident.h>
|
||||
#include <ivy/selector.h>
|
||||
#include <blue/core/hash.h>
|
||||
#include <blue/object/dict.h>
|
||||
#include <blue/object/number.h>
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/core/hash.h>
|
||||
#include <ivy/asm/bin.h>
|
||||
#include <ivy/ident.h>
|
||||
#include <ivy/selector.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -23,7 +23,8 @@ static enum ivy_status init_scope(
|
||||
|
||||
assembler_write_data(as, &header, sizeof header);
|
||||
|
||||
struct constpool_assembler_scope *c = (struct constpool_assembler_scope *)scope;
|
||||
struct constpool_assembler_scope *c
|
||||
= (struct constpool_assembler_scope *)scope;
|
||||
c->s_strings = b_dict_create();
|
||||
|
||||
return IVY_OK;
|
||||
@@ -49,7 +50,8 @@ static void put_cached_string(
|
||||
|
||||
static ivy_extended_data_key write_string(struct ivy_assembler *as, const char *s)
|
||||
{
|
||||
struct constpool_assembler_scope *scope = (struct constpool_assembler_scope *)assembler_get_scope(as);
|
||||
struct constpool_assembler_scope *scope
|
||||
= (struct constpool_assembler_scope *)assembler_get_scope(as);
|
||||
|
||||
ivy_extended_data_key key = get_cached_string(scope, s);
|
||||
if (key != IVY_EX_DATA_KEY_NULL) {
|
||||
@@ -58,10 +60,10 @@ static ivy_extended_data_key write_string(struct ivy_assembler *as, const char *
|
||||
|
||||
size_t len = strlen(s);
|
||||
|
||||
struct ivy_bin_string str = { 0 };
|
||||
struct ivy_bin_string str = {0};
|
||||
str.s_hash = b_i32_htob((uint32_t)b_hash_string(s));
|
||||
str.s_len = b_i32_htob((uint32_t)len);
|
||||
|
||||
|
||||
key = assembler_write_extended_data(as, &str, sizeof str);
|
||||
|
||||
/* include the trailing null terminator. */
|
||||
@@ -100,7 +102,8 @@ static ivy_extended_data_key write_selector(
|
||||
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &sel->sel_args) {
|
||||
struct ivy_selector_arg *arg = b_unbox(struct ivy_selector_arg, it.entry, arg_entry);
|
||||
struct ivy_selector_arg *arg
|
||||
= b_unbox(struct ivy_selector_arg, it.entry, arg_entry);
|
||||
arg_handles[i++] = write_string(as, arg->arg_label);
|
||||
}
|
||||
|
||||
@@ -128,15 +131,16 @@ static ivy_extended_data_key write_ident(
|
||||
= calloc(nr_parts, sizeof(ivy_extended_data_key));
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &id->id_parts) {
|
||||
struct ivy_ident_part *arg = b_unbox(struct ivy_ident_part, it.entry, p_entry);
|
||||
struct ivy_ident_part *arg
|
||||
= b_unbox(struct ivy_ident_part, it.entry, p_entry);
|
||||
part_handles[i++] = write_string(as, arg->p_str);
|
||||
}
|
||||
|
||||
dat.id_nr_parts = (uint8_t)nr_parts;
|
||||
|
||||
|
||||
ivy_extended_data_key ident_handle
|
||||
= assembler_write_extended_data(as, &dat, sizeof dat);
|
||||
|
||||
|
||||
for (i = 0; i < nr_parts; i++) {
|
||||
b_i32 part_handle = b_i32_htob(part_handles[i]);
|
||||
assembler_write_extended_data(as, &part_handle, sizeof part_handle);
|
||||
@@ -148,7 +152,8 @@ static ivy_extended_data_key write_ident(
|
||||
|
||||
static enum ivy_status put_pval(
|
||||
struct ivy_assembler *as, struct assembler_scope *scope,
|
||||
enum ivy_assembler_pval_type type, const void *val, ivy_extended_data_key *key)
|
||||
enum ivy_assembler_pval_type type, const void *val,
|
||||
ivy_extended_data_key *key)
|
||||
{
|
||||
struct ivy_bin_constpool_table_entry entry = {0};
|
||||
uintptr_t i = *(uintptr_t *)val;
|
||||
@@ -199,4 +204,4 @@ const struct assembler_scope_type constpool_scope_type = {
|
||||
.s_scope_size = sizeof(struct constpool_assembler_scope),
|
||||
.s_init_scope = init_scope,
|
||||
.s_put_pval = put_pval,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#include <ivy/status.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define IVY_ASM_INDEX_AUTO (-1)
|
||||
#define IVY_EX_DATA_KEY_NULL ((ivy_extended_data_key)0)
|
||||
#define IVY_ASM_INDEX_AUTO (-1)
|
||||
#define IVY_EX_DATA_KEY_NULL ((ivy_extended_data_key)0)
|
||||
|
||||
typedef uint32_t ivy_extended_data_key;
|
||||
|
||||
@@ -56,7 +56,10 @@ enum ivy_assembler_scope_type {
|
||||
|
||||
typedef unsigned long long ivy_assembler_attrib_table[__IVY_ASM_ATTRIB_COUNT];
|
||||
|
||||
IVY_API enum ivy_static ivy_assembler_create(FILE *out, struct ivy_assembler **as);
|
||||
#define IVY_ASSEMBLER_ATTRIB_TABLE_SIZE \
|
||||
(sizeof(unsigned long long) * __IVY_ASM_ATTRIB_COUNT)
|
||||
|
||||
IVY_API enum ivy_status ivy_assembler_create(FILE *out, struct ivy_assembler **as);
|
||||
IVY_API enum ivy_status ivy_assembler_finish(struct ivy_assembler *as);
|
||||
|
||||
IVY_API enum ivy_status ivy_assembler_begin_scope(
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
#include "parse.h"
|
||||
#include <ivy/ident.h>
|
||||
#include <ivy/asm/bin.h>
|
||||
|
||||
#include <ivy/asm/assembler.h>
|
||||
#include <ivy/asm/bin.h>
|
||||
#include <ivy/asm/lex.h>
|
||||
#include <ivy/ident.h>
|
||||
|
||||
struct atom_parser_state {
|
||||
struct parser_state s_base;
|
||||
unsigned int s_prev_token;
|
||||
|
||||
|
||||
struct ivy_asm_token *s_name;
|
||||
};
|
||||
|
||||
static enum ivy_status init_state(
|
||||
struct ivy_asm_parser *ctx, struct parser_state *s)
|
||||
static void init_state(struct ivy_asm_parser *ctx, struct parser_state *s)
|
||||
{
|
||||
struct atom_parser_state *state = (struct atom_parser_state *)s;
|
||||
state->s_prev_token = IVY_ASM_SYM_LEFT_PAREN;
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
static enum ivy_status parse_ident(
|
||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
||||
{
|
||||
struct atom_parser_state *state = (struct atom_parser_state *)asm_parser_get_state(ctx);
|
||||
struct atom_parser_state *state
|
||||
= (struct atom_parser_state *)asm_parser_get_state(ctx);
|
||||
if (state->s_prev_token != IVY_ASM_SYM_LEFT_PAREN) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
}
|
||||
@@ -40,7 +40,8 @@ static enum ivy_status parse_ident(
|
||||
static enum ivy_status parse_right_paren(
|
||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
||||
{
|
||||
struct atom_parser_state *state = (struct atom_parser_state *)asm_parser_get_state(ctx);
|
||||
struct atom_parser_state *state
|
||||
= (struct atom_parser_state *)asm_parser_get_state(ctx);
|
||||
|
||||
if (state->s_prev_token != IVY_ASM_TOK_IDENT) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
@@ -63,4 +64,4 @@ struct parser_state_type atom_parser_state_type = {
|
||||
.n_symbol_parsers = {
|
||||
SYM_PARSER(RIGHT_PAREN, parse_right_paren),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
#include "parse.h"
|
||||
|
||||
#include <blue/core/hash.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <ivy/asm/assembler.h>
|
||||
#include <ivy/asm/bin.h>
|
||||
#include <ivy/ident.h>
|
||||
#include <ivy/selector.h>
|
||||
#include <blue/core/hash.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define HASH_SELF 0x2d19e518d40792b7
|
||||
#define HASH_POOL 0x8c22f10da88b1083
|
||||
#define HASH_SP 0x08d93e07b5793c56
|
||||
#define HASH_BP 0x08a64407b54decef
|
||||
#define HASH_SELF 0x2d19e518d40792b7
|
||||
#define HASH_POOL 0x8c22f10da88b1083
|
||||
#define HASH_SP 0x08d93e07b5793c56
|
||||
#define HASH_BP 0x08a64407b54decef
|
||||
|
||||
#define REG_INDEX_INVALID ((unsigned long long)-1)
|
||||
|
||||
@@ -107,7 +107,7 @@ static unsigned long long get_register_index(struct ivy_asm_token *tok)
|
||||
static enum index_base get_index_base(struct ivy_asm_token *tok)
|
||||
{
|
||||
if (tok->t_type != IVY_ASM_TOK_IDENT) {
|
||||
return REG_INDEX_INVALID;
|
||||
return INDEX_NONE;
|
||||
}
|
||||
|
||||
const char *s = tok->t_str;
|
||||
@@ -148,7 +148,8 @@ static enum ivy_status write_instruction(struct block_parser_state *state)
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
static enum ivy_status push_const_arg(struct block_parser_state *state, struct ivy_asm_token *tok)
|
||||
static enum ivy_status push_const_arg(
|
||||
struct block_parser_state *state, struct ivy_asm_token *tok)
|
||||
{
|
||||
struct arg *arg = malloc(sizeof *arg);
|
||||
if (!arg) {
|
||||
@@ -165,7 +166,8 @@ static enum ivy_status push_const_arg(struct block_parser_state *state, struct i
|
||||
}
|
||||
|
||||
static enum ivy_status push_reg_arg(
|
||||
struct block_parser_state *state, struct ivy_asm_token *tok, unsigned long long reg_index)
|
||||
struct block_parser_state *state, struct ivy_asm_token *tok,
|
||||
unsigned long long reg_index)
|
||||
{
|
||||
struct arg *arg = malloc(sizeof *arg);
|
||||
if (!arg) {
|
||||
@@ -258,7 +260,6 @@ static enum ivy_status parse_ident(
|
||||
return IVY_OK;
|
||||
default:
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
|
||||
}
|
||||
|
||||
/* not sure what this is but we aren't expecting it. */
|
||||
@@ -299,7 +300,7 @@ static enum ivy_status parse_left_bracket(
|
||||
{
|
||||
struct block_parser_state *state
|
||||
= (struct block_parser_state *)asm_parser_get_state(ctx);
|
||||
|
||||
|
||||
switch (state->s_prev_component) {
|
||||
case INSTR_OPCODE:
|
||||
case INSTR_OPERAND_SEPARATOR:
|
||||
@@ -348,7 +349,7 @@ static enum ivy_status parse_end(
|
||||
}
|
||||
|
||||
asm_parser_pop_state(ctx, NULL);
|
||||
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
@@ -378,4 +379,4 @@ struct parser_state_type block_parser_state_type = {
|
||||
.n_keyword_parsers = {
|
||||
KW_PARSER(END, parse_end),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,29 +1,30 @@
|
||||
#include "parse.h"
|
||||
#include <ivy/ident.h>
|
||||
#include <ivy/asm/bin.h>
|
||||
|
||||
#include <ivy/asm/assembler.h>
|
||||
#include <ivy/asm/bin.h>
|
||||
#include <ivy/asm/lex.h>
|
||||
#include <ivy/ident.h>
|
||||
|
||||
struct ident_parser_state {
|
||||
struct parser_state s_base;
|
||||
unsigned int s_prev_token;
|
||||
|
||||
|
||||
b_queue s_parts;
|
||||
};
|
||||
|
||||
static enum ivy_status init_state(
|
||||
struct ivy_asm_parser *ctx, struct parser_state *s)
|
||||
static void init_state(struct ivy_asm_parser *ctx, struct parser_state *s)
|
||||
{
|
||||
struct ident_parser_state *state = (struct ident_parser_state *)s;
|
||||
state->s_prev_token = IVY_ASM_SYM_LEFT_PAREN;
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
static enum ivy_status parse_ident(
|
||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
||||
{
|
||||
struct ident_parser_state *state = (struct ident_parser_state *)asm_parser_get_state(ctx);
|
||||
if (state->s_prev_token != IVY_ASM_SYM_LEFT_PAREN && state->s_prev_token != IVY_ASM_SYM_DOT) {
|
||||
struct ident_parser_state *state
|
||||
= (struct ident_parser_state *)asm_parser_get_state(ctx);
|
||||
if (state->s_prev_token != IVY_ASM_SYM_LEFT_PAREN
|
||||
&& state->s_prev_token != IVY_ASM_SYM_DOT) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
@@ -36,21 +37,23 @@ static enum ivy_status parse_ident(
|
||||
static enum ivy_status parse_dot(
|
||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
||||
{
|
||||
struct ident_parser_state *state = (struct ident_parser_state *)asm_parser_get_state(ctx);
|
||||
|
||||
struct ident_parser_state *state
|
||||
= (struct ident_parser_state *)asm_parser_get_state(ctx);
|
||||
|
||||
if (state->s_prev_token != IVY_ASM_TOK_IDENT) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
state->s_prev_token = IVY_ASM_SYM_DOT;
|
||||
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
static enum ivy_status parse_right_paren(
|
||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
||||
{
|
||||
struct ident_parser_state *state = (struct ident_parser_state *)asm_parser_get_state(ctx);
|
||||
struct ident_parser_state *state
|
||||
= (struct ident_parser_state *)asm_parser_get_state(ctx);
|
||||
|
||||
if (state->s_prev_token != IVY_ASM_TOK_IDENT) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
@@ -61,7 +64,8 @@ static enum ivy_status parse_right_paren(
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_iterator_begin(&state->s_parts, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
struct ivy_asm_token *tok = b_unbox(struct ivy_asm_token, it.entry, t_entry);
|
||||
struct ivy_asm_token *tok
|
||||
= b_unbox(struct ivy_asm_token, it.entry, t_entry);
|
||||
b_queue_iterator_erase(&it);
|
||||
|
||||
ivy_ident_add_part(ident, tok->t_str);
|
||||
@@ -83,4 +87,4 @@ struct parser_state_type ident_parser_state_type = {
|
||||
SYM_PARSER(DOT, parse_dot),
|
||||
SYM_PARSER(RIGHT_PAREN, parse_right_paren),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#include <ivy/asm/parse.h>
|
||||
#include "parse.h"
|
||||
|
||||
#include <ivy/asm/lex.h>
|
||||
#include <ivy/asm/parse.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "parse.h"
|
||||
|
||||
extern struct parser_state_type unit_parser_state_type;
|
||||
extern struct parser_state_type constpool_parser_state_type;
|
||||
@@ -21,7 +22,8 @@ static const struct parser_state_type *parser_state_types[] = {
|
||||
[ASM_PARSER_IMPORT] = &import_parser_state_type,
|
||||
[ASM_PARSER_BLOCK] = &block_parser_state_type,
|
||||
};
|
||||
static const size_t nr_parser_state_types = sizeof parser_state_types / sizeof parser_state_types[0];
|
||||
static const size_t nr_parser_state_types
|
||||
= sizeof parser_state_types / sizeof parser_state_types[0];
|
||||
|
||||
enum ivy_status ivy_asm_parser_create(struct ivy_asm_parser **out)
|
||||
{
|
||||
@@ -44,13 +46,13 @@ void ivy_asm_parser_destroy(struct ivy_asm_parser *p)
|
||||
free(p);
|
||||
}
|
||||
|
||||
void ivy_asm_parser_set_assembler(
|
||||
struct ivy_asm_parser *p, struct ivy_assembler *as)
|
||||
void ivy_asm_parser_set_assembler(struct ivy_asm_parser *p, struct ivy_assembler *as)
|
||||
{
|
||||
p->p_assembler = as;
|
||||
}
|
||||
|
||||
static token_parse_function get_token_parser(struct parser_state *state, struct ivy_asm_token *tok)
|
||||
static token_parse_function get_token_parser(
|
||||
struct parser_state *state, struct ivy_asm_token *tok)
|
||||
{
|
||||
const struct parser_state_type *type = state->s_type;
|
||||
if (!type) {
|
||||
@@ -59,17 +61,23 @@ static token_parse_function get_token_parser(struct parser_state *state, struct
|
||||
|
||||
token_parse_function specific_parser = NULL;
|
||||
token_parse_function specific_fallback_parser = NULL;
|
||||
token_parse_function token_parser = type->n_token_parsers[__TOK_PARSER_INDEX(tok->t_type)];
|
||||
token_parse_function token_fallback_parser = type->n_token_parsers[__TOK_PARSER_FALLBACK_INDEX];
|
||||
token_parse_function token_parser
|
||||
= type->n_token_parsers[__TOK_PARSER_INDEX(tok->t_type)];
|
||||
token_parse_function token_fallback_parser
|
||||
= type->n_token_parsers[__TOK_PARSER_FALLBACK_INDEX];
|
||||
|
||||
switch (tok->t_type) {
|
||||
case IVY_ASM_TOK_SYMBOL:
|
||||
specific_parser = type->n_symbol_parsers[__SYM_PARSER_INDEX(tok->t_symbol)];
|
||||
specific_fallback_parser = type->n_symbol_parsers[__SYM_PARSER_FALLBACK_INDEX];
|
||||
specific_parser
|
||||
= type->n_symbol_parsers[__SYM_PARSER_INDEX(tok->t_symbol)];
|
||||
specific_fallback_parser
|
||||
= type->n_symbol_parsers[__SYM_PARSER_FALLBACK_INDEX];
|
||||
break;
|
||||
case IVY_ASM_TOK_KEYWORD:
|
||||
specific_parser = type->n_keyword_parsers[__KW_PARSER_INDEX(tok->t_keyword)];
|
||||
specific_fallback_parser = type->n_keyword_parsers[__KW_PARSER_FALLBACK_INDEX];
|
||||
specific_parser
|
||||
= type->n_keyword_parsers[__KW_PARSER_INDEX(tok->t_keyword)];
|
||||
specific_fallback_parser
|
||||
= type->n_keyword_parsers[__KW_PARSER_FALLBACK_INDEX];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -107,7 +115,8 @@ enum ivy_status ivy_asm_parser_push_token(
|
||||
return f(p, tok);
|
||||
}
|
||||
|
||||
static const struct parser_state_type *get_parser_state_type(enum parser_state_type_id type)
|
||||
static const struct parser_state_type *get_parser_state_type(
|
||||
enum parser_state_type_id type)
|
||||
{
|
||||
if (type < 0 || type >= nr_parser_state_types) {
|
||||
return NULL;
|
||||
@@ -137,7 +146,7 @@ struct parser_state *asm_parser_push_state(
|
||||
state->s_type = type_info;
|
||||
|
||||
if (attrib) {
|
||||
memcpy(state->s_attrib, attrib, sizeof attrib);
|
||||
memcpy(state->s_attrib, attrib, IVY_ASSEMBLER_ATTRIB_TABLE_SIZE);
|
||||
}
|
||||
|
||||
if (type_info->n_init_state) {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#ifndef _PARSE_PARSE_H_
|
||||
#define _PARSE_PARSE_H_
|
||||
|
||||
#include <blue/core/queue.h>
|
||||
#include <ivy/asm/assembler.h>
|
||||
#include <ivy/asm/lex.h>
|
||||
#include <blue/core/queue.h>
|
||||
|
||||
#define __TOK_PARSER_INDEX(x) ((x)-__IVY_ASM_TOK_INDEX_BASE)
|
||||
#define __SYM_PARSER_INDEX(x) ((x)-__IVY_ASM_SYM_INDEX_BASE)
|
||||
#define __KW_PARSER_INDEX(x) ((x)-__IVY_ASM_KW_INDEX_BASE)
|
||||
#define __TOK_PARSER_INDEX(x) ((x) - __IVY_ASM_TOK_INDEX_BASE)
|
||||
#define __SYM_PARSER_INDEX(x) ((x) - __IVY_ASM_SYM_INDEX_BASE)
|
||||
#define __KW_PARSER_INDEX(x) ((x) - __IVY_ASM_KW_INDEX_BASE)
|
||||
|
||||
#define __TOK_PARSER_FALLBACK_INDEX IVY_ASM_TOK_NONE
|
||||
#define __SYM_PARSER_FALLBACK_INDEX IVY_ASM_SYM_NONE
|
||||
@@ -22,29 +22,28 @@
|
||||
#define KW_PARSER_FALLBACK(func) [__KW_PARSER_FALLBACK_INDEX] = func
|
||||
|
||||
struct ivy_asm_parser;
|
||||
struct parser_state;
|
||||
|
||||
enum parser_state_type_id {
|
||||
ASM_PARSER_NONE = 0,
|
||||
ASM_PARSER_UNIT,
|
||||
ASM_PARSER_CLASS,
|
||||
ASM_PARSER_CONSTPOOL,
|
||||
ASM_PARSER_IMPORT,
|
||||
ASM_PARSER_NONE = 0,
|
||||
ASM_PARSER_UNIT,
|
||||
ASM_PARSER_CLASS,
|
||||
ASM_PARSER_CONSTPOOL,
|
||||
ASM_PARSER_IMPORT,
|
||||
ASM_PARSER_BLOCK,
|
||||
ASM_PARSER_SELECTOR,
|
||||
ASM_PARSER_IDENT,
|
||||
ASM_PARSER_ATOM,
|
||||
ASM_PARSER_SELECTOR,
|
||||
ASM_PARSER_IDENT,
|
||||
ASM_PARSER_ATOM,
|
||||
};
|
||||
|
||||
typedef enum ivy_status (*token_parse_function)(
|
||||
struct ivy_asm_parser *, struct ivy_asm_token *);
|
||||
struct ivy_asm_parser*, struct ivy_asm_token*);
|
||||
|
||||
struct parser_state_type {
|
||||
size_t n_state_size;
|
||||
size_t n_state_size;
|
||||
|
||||
void (*n_init_state)(struct ivy_asm_parser *, struct parser_state *);
|
||||
void (*n_finish_state)(struct ivy_asm_parser *, struct parser_state *);
|
||||
enum ivy_status (*n_add_child)(
|
||||
struct parser_state *, struct ivy_ast_node *);
|
||||
void (*n_init_state)(struct ivy_asm_parser*, struct parser_state*);
|
||||
void (*n_finish_state)(struct ivy_asm_parser*, struct parser_state*);
|
||||
|
||||
token_parse_function n_token_parsers[__TOK_PARSER_INDEX(__IVY_ASM_TOK_INDEX_LIMIT)];
|
||||
token_parse_function n_keyword_parsers[__KW_PARSER_INDEX(__IVY_ASM_KW_INDEX_LIMIT)];
|
||||
@@ -52,19 +51,19 @@ struct parser_state_type {
|
||||
};
|
||||
|
||||
struct parser_state {
|
||||
b_queue_entry s_entry;
|
||||
const struct parser_state_type *s_type;
|
||||
b_queue_entry s_entry;
|
||||
const struct parser_state_type* s_type;
|
||||
ivy_assembler_attrib_table s_attrib;
|
||||
void *s_previous_value;
|
||||
void* s_previous_value;
|
||||
};
|
||||
|
||||
struct ivy_asm_parser {
|
||||
struct ivy_assembler *p_assembler;
|
||||
b_queue p_state;
|
||||
struct ivy_assembler* p_assembler;
|
||||
b_queue p_state;
|
||||
};
|
||||
|
||||
extern struct parser_state* asm_parser_push_state(struct ivy_asm_parser* parser, enum parser_state_type_id type, const ivy_assembler_attrib_table attrib);
|
||||
extern void asm_parser_pop_state(struct ivy_asm_parser *parser, void *ret);
|
||||
extern struct parser_state *asm_parser_get_state(struct ivy_asm_parser *parser);
|
||||
extern void asm_parser_pop_state(struct ivy_asm_parser* parser, void* ret);
|
||||
extern struct parser_state* asm_parser_get_state(struct ivy_asm_parser* parser);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,40 +1,44 @@
|
||||
#include "parse.h"
|
||||
#include <ivy/selector.h>
|
||||
#include <ivy/asm/bin.h>
|
||||
|
||||
#include <ivy/asm/assembler.h>
|
||||
#include <ivy/asm/bin.h>
|
||||
#include <ivy/asm/lex.h>
|
||||
#include <ivy/selector.h>
|
||||
|
||||
struct selector_parser_state {
|
||||
struct parser_state s_base;
|
||||
unsigned int s_prev_token;
|
||||
|
||||
|
||||
unsigned int s_paren_depth;
|
||||
struct ivy_asm_token *s_prev_label;
|
||||
struct ivy_selector *s_sel;
|
||||
};
|
||||
|
||||
static enum ivy_status init_state(
|
||||
struct ivy_asm_parser *ctx, struct parser_state *s)
|
||||
static void init_state(struct ivy_asm_parser *ctx, struct parser_state *s)
|
||||
{
|
||||
struct selector_parser_state *state = (struct selector_parser_state *)s;
|
||||
state->s_prev_token = IVY_ASM_SYM_LEFT_PAREN;
|
||||
return ivy_selector_create(&state->s_sel);
|
||||
ivy_selector_create(&state->s_sel);
|
||||
}
|
||||
|
||||
static enum ivy_status parse_ident(
|
||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
||||
{
|
||||
struct selector_parser_state *state = (struct selector_parser_state *)asm_parser_get_state(ctx);
|
||||
struct selector_parser_state *state
|
||||
= (struct selector_parser_state *)asm_parser_get_state(ctx);
|
||||
if (state->s_prev_token == IVY_ASM_TOK_LABEL && state->s_prev_label) {
|
||||
ivy_selector_add_arg(state->s_sel, state->s_prev_label->t_str, tok->t_str);
|
||||
ivy_selector_add_arg(
|
||||
state->s_sel, state->s_prev_label->t_str, tok->t_str);
|
||||
ivy_asm_token_destroy(tok);
|
||||
ivy_asm_token_destroy(state->s_prev_label);
|
||||
state->s_prev_label = tok;
|
||||
state->s_prev_token = IVY_ASM_TOK_LABEL;
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
if (state->s_prev_token != IVY_ASM_SYM_LEFT_PAREN && state->s_prev_token != IVY_ASM_SYM_HYPHEN && state->s_prev_token != IVY_ASM_SYM_PLUS) {
|
||||
}
|
||||
|
||||
if (state->s_prev_token != IVY_ASM_SYM_LEFT_PAREN
|
||||
&& state->s_prev_token != IVY_ASM_SYM_HYPHEN
|
||||
&& state->s_prev_token != IVY_ASM_SYM_PLUS) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
@@ -48,11 +52,12 @@ static enum ivy_status parse_ident(
|
||||
static enum ivy_status parse_label(
|
||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
||||
{
|
||||
struct selector_parser_state *state = (struct selector_parser_state *)asm_parser_get_state(ctx);
|
||||
struct selector_parser_state *state
|
||||
= (struct selector_parser_state *)asm_parser_get_state(ctx);
|
||||
if (state->s_prev_token != IVY_ASM_SYM_LEFT_PAREN
|
||||
&& state->s_prev_token != IVY_ASM_TOK_LABEL
|
||||
&& state->s_prev_token != IVY_ASM_SYM_HYPHEN
|
||||
&& state->s_prev_token != IVY_ASM_SYM_PLUS) {
|
||||
&& state->s_prev_token != IVY_ASM_TOK_LABEL
|
||||
&& state->s_prev_token != IVY_ASM_SYM_HYPHEN
|
||||
&& state->s_prev_token != IVY_ASM_SYM_PLUS) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
@@ -71,37 +76,40 @@ static enum ivy_status parse_label(
|
||||
static enum ivy_status parse_hyphen(
|
||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
||||
{
|
||||
struct selector_parser_state *state = (struct selector_parser_state *)asm_parser_get_state(ctx);
|
||||
|
||||
struct selector_parser_state *state
|
||||
= (struct selector_parser_state *)asm_parser_get_state(ctx);
|
||||
|
||||
if (state->s_prev_token != IVY_ASM_SYM_LEFT_PAREN) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
ivy_selector_set_recipient(state->s_sel, IVY_SEL_OBJECT);
|
||||
state->s_prev_token = IVY_ASM_SYM_HYPHEN;
|
||||
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
static enum ivy_status parse_plus(
|
||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
||||
{
|
||||
struct selector_parser_state *state = (struct selector_parser_state *)asm_parser_get_state(ctx);
|
||||
|
||||
struct selector_parser_state *state
|
||||
= (struct selector_parser_state *)asm_parser_get_state(ctx);
|
||||
|
||||
if (state->s_prev_token != IVY_ASM_SYM_LEFT_PAREN) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
ivy_selector_set_recipient(state->s_sel, IVY_SEL_CLASS);
|
||||
state->s_prev_token = IVY_ASM_SYM_PLUS;
|
||||
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
static enum ivy_status parse_left_paren(
|
||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
||||
{
|
||||
struct selector_parser_state *state = (struct selector_parser_state *)asm_parser_get_state(ctx);
|
||||
struct selector_parser_state *state
|
||||
= (struct selector_parser_state *)asm_parser_get_state(ctx);
|
||||
|
||||
if (state->s_prev_token != IVY_ASM_TOK_IDENT) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
@@ -120,9 +128,12 @@ static enum ivy_status parse_left_paren(
|
||||
static enum ivy_status parse_right_paren(
|
||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
||||
{
|
||||
struct selector_parser_state *state = (struct selector_parser_state *)asm_parser_get_state(ctx);
|
||||
struct selector_parser_state *state
|
||||
= (struct selector_parser_state *)asm_parser_get_state(ctx);
|
||||
|
||||
if (state->s_prev_token != IVY_ASM_TOK_IDENT && state->s_prev_token != IVY_ASM_TOK_LABEL && state->s_prev_token != IVY_ASM_SYM_RIGHT_PAREN) {
|
||||
if (state->s_prev_token != IVY_ASM_TOK_IDENT
|
||||
&& state->s_prev_token != IVY_ASM_TOK_LABEL
|
||||
&& state->s_prev_token != IVY_ASM_SYM_RIGHT_PAREN) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
@@ -154,4 +165,4 @@ struct parser_state_type selector_parser_state_type = {
|
||||
SYM_PARSER(LEFT_PAREN, parse_left_paren),
|
||||
SYM_PARSER(RIGHT_PAREN, parse_right_paren),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user