asm: fix compiler warnings
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
#include "assembler.h"
|
#include "assembler.h"
|
||||||
|
|
||||||
#include <ivy/asm/bin.h>
|
#include <blue/core/hash.h>
|
||||||
#include <ivy/ident.h>
|
|
||||||
#include <ivy/selector.h>
|
|
||||||
#include <blue/object/dict.h>
|
#include <blue/object/dict.h>
|
||||||
#include <blue/object/number.h>
|
#include <blue/object/number.h>
|
||||||
#include <blue/object/string.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 <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -23,7 +23,8 @@ static enum ivy_status init_scope(
|
|||||||
|
|
||||||
assembler_write_data(as, &header, sizeof header);
|
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();
|
c->s_strings = b_dict_create();
|
||||||
|
|
||||||
return IVY_OK;
|
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)
|
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);
|
ivy_extended_data_key key = get_cached_string(scope, s);
|
||||||
if (key != IVY_EX_DATA_KEY_NULL) {
|
if (key != IVY_EX_DATA_KEY_NULL) {
|
||||||
@@ -58,7 +60,7 @@ static ivy_extended_data_key write_string(struct ivy_assembler *as, const char *
|
|||||||
|
|
||||||
size_t len = strlen(s);
|
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_hash = b_i32_htob((uint32_t)b_hash_string(s));
|
||||||
str.s_len = b_i32_htob((uint32_t)len);
|
str.s_len = b_i32_htob((uint32_t)len);
|
||||||
|
|
||||||
@@ -100,7 +102,8 @@ static ivy_extended_data_key write_selector(
|
|||||||
|
|
||||||
b_queue_iterator it = {0};
|
b_queue_iterator it = {0};
|
||||||
b_queue_foreach (&it, &sel->sel_args) {
|
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);
|
arg_handles[i++] = write_string(as, arg->arg_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +131,8 @@ static ivy_extended_data_key write_ident(
|
|||||||
= calloc(nr_parts, sizeof(ivy_extended_data_key));
|
= calloc(nr_parts, sizeof(ivy_extended_data_key));
|
||||||
b_queue_iterator it = {0};
|
b_queue_iterator it = {0};
|
||||||
b_queue_foreach (&it, &id->id_parts) {
|
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);
|
part_handles[i++] = write_string(as, arg->p_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +152,8 @@ static ivy_extended_data_key write_ident(
|
|||||||
|
|
||||||
static enum ivy_status put_pval(
|
static enum ivy_status put_pval(
|
||||||
struct ivy_assembler *as, struct assembler_scope *scope,
|
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};
|
struct ivy_bin_constpool_table_entry entry = {0};
|
||||||
uintptr_t i = *(uintptr_t *)val;
|
uintptr_t i = *(uintptr_t *)val;
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
#include <ivy/status.h>
|
#include <ivy/status.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define IVY_ASM_INDEX_AUTO (-1)
|
#define IVY_ASM_INDEX_AUTO (-1)
|
||||||
#define IVY_EX_DATA_KEY_NULL ((ivy_extended_data_key)0)
|
#define IVY_EX_DATA_KEY_NULL ((ivy_extended_data_key)0)
|
||||||
|
|
||||||
typedef uint32_t ivy_extended_data_key;
|
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];
|
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_finish(struct ivy_assembler *as);
|
||||||
|
|
||||||
IVY_API enum ivy_status ivy_assembler_begin_scope(
|
IVY_API enum ivy_status ivy_assembler_begin_scope(
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
#include <ivy/ident.h>
|
|
||||||
#include <ivy/asm/bin.h>
|
|
||||||
#include <ivy/asm/assembler.h>
|
#include <ivy/asm/assembler.h>
|
||||||
|
#include <ivy/asm/bin.h>
|
||||||
#include <ivy/asm/lex.h>
|
#include <ivy/asm/lex.h>
|
||||||
|
#include <ivy/ident.h>
|
||||||
|
|
||||||
struct atom_parser_state {
|
struct atom_parser_state {
|
||||||
struct parser_state s_base;
|
struct parser_state s_base;
|
||||||
@@ -11,18 +12,17 @@ struct atom_parser_state {
|
|||||||
struct ivy_asm_token *s_name;
|
struct ivy_asm_token *s_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum ivy_status init_state(
|
static void init_state(struct ivy_asm_parser *ctx, struct parser_state *s)
|
||||||
struct ivy_asm_parser *ctx, struct parser_state *s)
|
|
||||||
{
|
{
|
||||||
struct atom_parser_state *state = (struct atom_parser_state *)s;
|
struct atom_parser_state *state = (struct atom_parser_state *)s;
|
||||||
state->s_prev_token = IVY_ASM_SYM_LEFT_PAREN;
|
state->s_prev_token = IVY_ASM_SYM_LEFT_PAREN;
|
||||||
return IVY_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum ivy_status parse_ident(
|
static enum ivy_status parse_ident(
|
||||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
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) {
|
if (state->s_prev_token != IVY_ASM_SYM_LEFT_PAREN) {
|
||||||
return IVY_ERR_BAD_SYNTAX;
|
return IVY_ERR_BAD_SYNTAX;
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,8 @@ static enum ivy_status parse_ident(
|
|||||||
static enum ivy_status parse_right_paren(
|
static enum ivy_status parse_right_paren(
|
||||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
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) {
|
if (state->s_prev_token != IVY_ASM_TOK_IDENT) {
|
||||||
return IVY_ERR_BAD_SYNTAX;
|
return IVY_ERR_BAD_SYNTAX;
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
|
|
||||||
|
#include <blue/core/hash.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <ivy/asm/assembler.h>
|
#include <ivy/asm/assembler.h>
|
||||||
#include <ivy/asm/bin.h>
|
#include <ivy/asm/bin.h>
|
||||||
#include <ivy/ident.h>
|
#include <ivy/ident.h>
|
||||||
#include <ivy/selector.h>
|
#include <ivy/selector.h>
|
||||||
#include <blue/core/hash.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define HASH_SELF 0x2d19e518d40792b7
|
#define HASH_SELF 0x2d19e518d40792b7
|
||||||
#define HASH_POOL 0x8c22f10da88b1083
|
#define HASH_POOL 0x8c22f10da88b1083
|
||||||
#define HASH_SP 0x08d93e07b5793c56
|
#define HASH_SP 0x08d93e07b5793c56
|
||||||
#define HASH_BP 0x08a64407b54decef
|
#define HASH_BP 0x08a64407b54decef
|
||||||
|
|
||||||
#define REG_INDEX_INVALID ((unsigned long long)-1)
|
#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)
|
static enum index_base get_index_base(struct ivy_asm_token *tok)
|
||||||
{
|
{
|
||||||
if (tok->t_type != IVY_ASM_TOK_IDENT) {
|
if (tok->t_type != IVY_ASM_TOK_IDENT) {
|
||||||
return REG_INDEX_INVALID;
|
return INDEX_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *s = tok->t_str;
|
const char *s = tok->t_str;
|
||||||
@@ -148,7 +148,8 @@ static enum ivy_status write_instruction(struct block_parser_state *state)
|
|||||||
return IVY_OK;
|
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);
|
struct arg *arg = malloc(sizeof *arg);
|
||||||
if (!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(
|
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);
|
struct arg *arg = malloc(sizeof *arg);
|
||||||
if (!arg) {
|
if (!arg) {
|
||||||
@@ -258,7 +260,6 @@ static enum ivy_status parse_ident(
|
|||||||
return IVY_OK;
|
return IVY_OK;
|
||||||
default:
|
default:
|
||||||
return IVY_ERR_BAD_SYNTAX;
|
return IVY_ERR_BAD_SYNTAX;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* not sure what this is but we aren't expecting it. */
|
/* not sure what this is but we aren't expecting it. */
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
#include <ivy/ident.h>
|
|
||||||
#include <ivy/asm/bin.h>
|
|
||||||
#include <ivy/asm/assembler.h>
|
#include <ivy/asm/assembler.h>
|
||||||
|
#include <ivy/asm/bin.h>
|
||||||
#include <ivy/asm/lex.h>
|
#include <ivy/asm/lex.h>
|
||||||
|
#include <ivy/ident.h>
|
||||||
|
|
||||||
struct ident_parser_state {
|
struct ident_parser_state {
|
||||||
struct parser_state s_base;
|
struct parser_state s_base;
|
||||||
@@ -11,19 +12,19 @@ struct ident_parser_state {
|
|||||||
b_queue s_parts;
|
b_queue s_parts;
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum ivy_status init_state(
|
static void init_state(struct ivy_asm_parser *ctx, struct parser_state *s)
|
||||||
struct ivy_asm_parser *ctx, struct parser_state *s)
|
|
||||||
{
|
{
|
||||||
struct ident_parser_state *state = (struct ident_parser_state *)s;
|
struct ident_parser_state *state = (struct ident_parser_state *)s;
|
||||||
state->s_prev_token = IVY_ASM_SYM_LEFT_PAREN;
|
state->s_prev_token = IVY_ASM_SYM_LEFT_PAREN;
|
||||||
return IVY_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum ivy_status parse_ident(
|
static enum ivy_status parse_ident(
|
||||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
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
|
||||||
if (state->s_prev_token != IVY_ASM_SYM_LEFT_PAREN && state->s_prev_token != IVY_ASM_SYM_DOT) {
|
= (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;
|
return IVY_ERR_BAD_SYNTAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +37,8 @@ static enum ivy_status parse_ident(
|
|||||||
static enum ivy_status parse_dot(
|
static enum ivy_status parse_dot(
|
||||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
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) {
|
if (state->s_prev_token != IVY_ASM_TOK_IDENT) {
|
||||||
return IVY_ERR_BAD_SYNTAX;
|
return IVY_ERR_BAD_SYNTAX;
|
||||||
@@ -50,7 +52,8 @@ static enum ivy_status parse_dot(
|
|||||||
static enum ivy_status parse_right_paren(
|
static enum ivy_status parse_right_paren(
|
||||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
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) {
|
if (state->s_prev_token != IVY_ASM_TOK_IDENT) {
|
||||||
return IVY_ERR_BAD_SYNTAX;
|
return IVY_ERR_BAD_SYNTAX;
|
||||||
@@ -61,7 +64,8 @@ static enum ivy_status parse_right_paren(
|
|||||||
b_queue_iterator it = {0};
|
b_queue_iterator it = {0};
|
||||||
b_queue_iterator_begin(&state->s_parts, &it);
|
b_queue_iterator_begin(&state->s_parts, &it);
|
||||||
while (b_queue_iterator_is_valid(&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);
|
b_queue_iterator_erase(&it);
|
||||||
|
|
||||||
ivy_ident_add_part(ident, tok->t_str);
|
ivy_ident_add_part(ident, tok->t_str);
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#include <ivy/asm/parse.h>
|
#include "parse.h"
|
||||||
|
|
||||||
#include <ivy/asm/lex.h>
|
#include <ivy/asm/lex.h>
|
||||||
|
#include <ivy/asm/parse.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "parse.h"
|
|
||||||
|
|
||||||
extern struct parser_state_type unit_parser_state_type;
|
extern struct parser_state_type unit_parser_state_type;
|
||||||
extern struct parser_state_type constpool_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_IMPORT] = &import_parser_state_type,
|
||||||
[ASM_PARSER_BLOCK] = &block_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)
|
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);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ivy_asm_parser_set_assembler(
|
void ivy_asm_parser_set_assembler(struct ivy_asm_parser *p, struct ivy_assembler *as)
|
||||||
struct ivy_asm_parser *p, struct ivy_assembler *as)
|
|
||||||
{
|
{
|
||||||
p->p_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;
|
const struct parser_state_type *type = state->s_type;
|
||||||
if (!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_parser = NULL;
|
||||||
token_parse_function specific_fallback_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_parser
|
||||||
token_parse_function token_fallback_parser = type->n_token_parsers[__TOK_PARSER_FALLBACK_INDEX];
|
= 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) {
|
switch (tok->t_type) {
|
||||||
case IVY_ASM_TOK_SYMBOL:
|
case IVY_ASM_TOK_SYMBOL:
|
||||||
specific_parser = type->n_symbol_parsers[__SYM_PARSER_INDEX(tok->t_symbol)];
|
specific_parser
|
||||||
specific_fallback_parser = type->n_symbol_parsers[__SYM_PARSER_FALLBACK_INDEX];
|
= type->n_symbol_parsers[__SYM_PARSER_INDEX(tok->t_symbol)];
|
||||||
|
specific_fallback_parser
|
||||||
|
= type->n_symbol_parsers[__SYM_PARSER_FALLBACK_INDEX];
|
||||||
break;
|
break;
|
||||||
case IVY_ASM_TOK_KEYWORD:
|
case IVY_ASM_TOK_KEYWORD:
|
||||||
specific_parser = type->n_keyword_parsers[__KW_PARSER_INDEX(tok->t_keyword)];
|
specific_parser
|
||||||
specific_fallback_parser = type->n_keyword_parsers[__KW_PARSER_FALLBACK_INDEX];
|
= type->n_keyword_parsers[__KW_PARSER_INDEX(tok->t_keyword)];
|
||||||
|
specific_fallback_parser
|
||||||
|
= type->n_keyword_parsers[__KW_PARSER_FALLBACK_INDEX];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -107,7 +115,8 @@ enum ivy_status ivy_asm_parser_push_token(
|
|||||||
return f(p, tok);
|
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) {
|
if (type < 0 || type >= nr_parser_state_types) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -137,7 +146,7 @@ struct parser_state *asm_parser_push_state(
|
|||||||
state->s_type = type_info;
|
state->s_type = type_info;
|
||||||
|
|
||||||
if (attrib) {
|
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) {
|
if (type_info->n_init_state) {
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
#ifndef _PARSE_PARSE_H_
|
#ifndef _PARSE_PARSE_H_
|
||||||
#define _PARSE_PARSE_H_
|
#define _PARSE_PARSE_H_
|
||||||
|
|
||||||
|
#include <blue/core/queue.h>
|
||||||
#include <ivy/asm/assembler.h>
|
#include <ivy/asm/assembler.h>
|
||||||
#include <ivy/asm/lex.h>
|
#include <ivy/asm/lex.h>
|
||||||
#include <blue/core/queue.h>
|
|
||||||
|
|
||||||
#define __TOK_PARSER_INDEX(x) ((x)-__IVY_ASM_TOK_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 __SYM_PARSER_INDEX(x) ((x) - __IVY_ASM_SYM_INDEX_BASE)
|
||||||
#define __KW_PARSER_INDEX(x) ((x)-__IVY_ASM_KW_INDEX_BASE)
|
#define __KW_PARSER_INDEX(x) ((x) - __IVY_ASM_KW_INDEX_BASE)
|
||||||
|
|
||||||
#define __TOK_PARSER_FALLBACK_INDEX IVY_ASM_TOK_NONE
|
#define __TOK_PARSER_FALLBACK_INDEX IVY_ASM_TOK_NONE
|
||||||
#define __SYM_PARSER_FALLBACK_INDEX IVY_ASM_SYM_NONE
|
#define __SYM_PARSER_FALLBACK_INDEX IVY_ASM_SYM_NONE
|
||||||
@@ -22,29 +22,28 @@
|
|||||||
#define KW_PARSER_FALLBACK(func) [__KW_PARSER_FALLBACK_INDEX] = func
|
#define KW_PARSER_FALLBACK(func) [__KW_PARSER_FALLBACK_INDEX] = func
|
||||||
|
|
||||||
struct ivy_asm_parser;
|
struct ivy_asm_parser;
|
||||||
|
struct parser_state;
|
||||||
|
|
||||||
enum parser_state_type_id {
|
enum parser_state_type_id {
|
||||||
ASM_PARSER_NONE = 0,
|
ASM_PARSER_NONE = 0,
|
||||||
ASM_PARSER_UNIT,
|
ASM_PARSER_UNIT,
|
||||||
ASM_PARSER_CLASS,
|
ASM_PARSER_CLASS,
|
||||||
ASM_PARSER_CONSTPOOL,
|
ASM_PARSER_CONSTPOOL,
|
||||||
ASM_PARSER_IMPORT,
|
ASM_PARSER_IMPORT,
|
||||||
ASM_PARSER_BLOCK,
|
ASM_PARSER_BLOCK,
|
||||||
ASM_PARSER_SELECTOR,
|
ASM_PARSER_SELECTOR,
|
||||||
ASM_PARSER_IDENT,
|
ASM_PARSER_IDENT,
|
||||||
ASM_PARSER_ATOM,
|
ASM_PARSER_ATOM,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum ivy_status (*token_parse_function)(
|
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 {
|
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_init_state)(struct ivy_asm_parser*, struct parser_state*);
|
||||||
void (*n_finish_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 *);
|
|
||||||
|
|
||||||
token_parse_function n_token_parsers[__TOK_PARSER_INDEX(__IVY_ASM_TOK_INDEX_LIMIT)];
|
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)];
|
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 {
|
struct parser_state {
|
||||||
b_queue_entry s_entry;
|
b_queue_entry s_entry;
|
||||||
const struct parser_state_type *s_type;
|
const struct parser_state_type* s_type;
|
||||||
ivy_assembler_attrib_table s_attrib;
|
ivy_assembler_attrib_table s_attrib;
|
||||||
void *s_previous_value;
|
void* s_previous_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ivy_asm_parser {
|
struct ivy_asm_parser {
|
||||||
struct ivy_assembler *p_assembler;
|
struct ivy_assembler* p_assembler;
|
||||||
b_queue p_state;
|
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 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 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 struct parser_state* asm_parser_get_state(struct ivy_asm_parser* parser);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
#include <ivy/selector.h>
|
|
||||||
#include <ivy/asm/bin.h>
|
|
||||||
#include <ivy/asm/assembler.h>
|
#include <ivy/asm/assembler.h>
|
||||||
|
#include <ivy/asm/bin.h>
|
||||||
#include <ivy/asm/lex.h>
|
#include <ivy/asm/lex.h>
|
||||||
|
#include <ivy/selector.h>
|
||||||
|
|
||||||
struct selector_parser_state {
|
struct selector_parser_state {
|
||||||
struct parser_state s_base;
|
struct parser_state s_base;
|
||||||
@@ -13,20 +14,21 @@ struct selector_parser_state {
|
|||||||
struct ivy_selector *s_sel;
|
struct ivy_selector *s_sel;
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum ivy_status init_state(
|
static void init_state(struct ivy_asm_parser *ctx, struct parser_state *s)
|
||||||
struct ivy_asm_parser *ctx, struct parser_state *s)
|
|
||||||
{
|
{
|
||||||
struct selector_parser_state *state = (struct selector_parser_state *)s;
|
struct selector_parser_state *state = (struct selector_parser_state *)s;
|
||||||
state->s_prev_token = IVY_ASM_SYM_LEFT_PAREN;
|
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(
|
static enum ivy_status parse_ident(
|
||||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
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) {
|
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(tok);
|
||||||
ivy_asm_token_destroy(state->s_prev_label);
|
ivy_asm_token_destroy(state->s_prev_label);
|
||||||
state->s_prev_label = tok;
|
state->s_prev_label = tok;
|
||||||
@@ -34,7 +36,9 @@ static enum ivy_status parse_ident(
|
|||||||
return IVY_OK;
|
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;
|
return IVY_ERR_BAD_SYNTAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,11 +52,12 @@ static enum ivy_status parse_ident(
|
|||||||
static enum ivy_status parse_label(
|
static enum ivy_status parse_label(
|
||||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
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
|
if (state->s_prev_token != IVY_ASM_SYM_LEFT_PAREN
|
||||||
&& state->s_prev_token != IVY_ASM_TOK_LABEL
|
&& state->s_prev_token != IVY_ASM_TOK_LABEL
|
||||||
&& state->s_prev_token != IVY_ASM_SYM_HYPHEN
|
&& state->s_prev_token != IVY_ASM_SYM_HYPHEN
|
||||||
&& state->s_prev_token != IVY_ASM_SYM_PLUS) {
|
&& state->s_prev_token != IVY_ASM_SYM_PLUS) {
|
||||||
return IVY_ERR_BAD_SYNTAX;
|
return IVY_ERR_BAD_SYNTAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +76,8 @@ static enum ivy_status parse_label(
|
|||||||
static enum ivy_status parse_hyphen(
|
static enum ivy_status parse_hyphen(
|
||||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
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) {
|
if (state->s_prev_token != IVY_ASM_SYM_LEFT_PAREN) {
|
||||||
return IVY_ERR_BAD_SYNTAX;
|
return IVY_ERR_BAD_SYNTAX;
|
||||||
@@ -86,7 +92,8 @@ static enum ivy_status parse_hyphen(
|
|||||||
static enum ivy_status parse_plus(
|
static enum ivy_status parse_plus(
|
||||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
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) {
|
if (state->s_prev_token != IVY_ASM_SYM_LEFT_PAREN) {
|
||||||
return IVY_ERR_BAD_SYNTAX;
|
return IVY_ERR_BAD_SYNTAX;
|
||||||
@@ -101,7 +108,8 @@ static enum ivy_status parse_plus(
|
|||||||
static enum ivy_status parse_left_paren(
|
static enum ivy_status parse_left_paren(
|
||||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
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) {
|
if (state->s_prev_token != IVY_ASM_TOK_IDENT) {
|
||||||
return IVY_ERR_BAD_SYNTAX;
|
return IVY_ERR_BAD_SYNTAX;
|
||||||
@@ -120,9 +128,12 @@ static enum ivy_status parse_left_paren(
|
|||||||
static enum ivy_status parse_right_paren(
|
static enum ivy_status parse_right_paren(
|
||||||
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
|
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;
|
return IVY_ERR_BAD_SYNTAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user