meta: replace bluelib with fx
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
#include "cmd.h"
|
||||
#include "mie/select/builder.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <blue/core/error.h>
|
||||
#include <blue/term.h>
|
||||
#include <fx/cmd.h>
|
||||
#include <fx/core/error.h>
|
||||
#include <fx/term.h>
|
||||
#include <errno.h>
|
||||
#include <ivy/asm/mie.h>
|
||||
#include <ivy/diag.h>
|
||||
@@ -68,19 +68,19 @@ static enum ivy_status node_codegen(
|
||||
return ivy_codegen_push_node(ctx->codegen, node, node->n_it.it_depth);
|
||||
}
|
||||
|
||||
static b_result compile_ctx_init(struct compile_ctx *ctx, const b_arglist *args)
|
||||
static fx_result compile_ctx_init(struct compile_ctx *ctx, const fx_arglist *args)
|
||||
{
|
||||
memset(ctx, 0x0, sizeof *ctx);
|
||||
|
||||
b_arglist_get_count(args, OPT_SHOW_LEX_TOKENS, B_COMMAND_INVALID_ID)
|
||||
fx_arglist_get_count(args, OPT_SHOW_LEX_TOKENS, FX_COMMAND_INVALID_ID)
|
||||
&& (ctx->flags |= FLAG_SHOW_LEX_TOKENS);
|
||||
b_arglist_get_count(args, OPT_SHOW_AST_NODES, B_COMMAND_INVALID_ID)
|
||||
fx_arglist_get_count(args, OPT_SHOW_AST_NODES, FX_COMMAND_INVALID_ID)
|
||||
&& (ctx->flags |= FLAG_SHOW_AST_NODES);
|
||||
b_arglist_get_count(args, OPT_SHOW_IR, B_COMMAND_INVALID_ID)
|
||||
fx_arglist_get_count(args, OPT_SHOW_IR, FX_COMMAND_INVALID_ID)
|
||||
&& (ctx->flags |= FLAG_SHOW_IR);
|
||||
b_arglist_get_count(args, OPT_SHOW_ISEL_PRE, B_COMMAND_INVALID_ID)
|
||||
fx_arglist_get_count(args, OPT_SHOW_ISEL_PRE, FX_COMMAND_INVALID_ID)
|
||||
&& (ctx->flags |= FLAG_SHOW_PRE_SELECT_GRAPH);
|
||||
b_arglist_get_count(args, OPT_SHOW_ISEL_POST, B_COMMAND_INVALID_ID)
|
||||
fx_arglist_get_count(args, OPT_SHOW_ISEL_POST, FX_COMMAND_INVALID_ID)
|
||||
&& (ctx->flags |= FLAG_SHOW_POST_SELECT_GRAPH);
|
||||
|
||||
enum mie_status mie_status = MIE_SUCCESS;
|
||||
@@ -96,14 +96,14 @@ static b_result compile_ctx_init(struct compile_ctx *ctx, const b_arglist *args)
|
||||
= mie_select_builder_create(ctx->mie_ctx, ivy_asm_mie_target());
|
||||
|
||||
ivy_lang_diag_ctx_init(ctx->diag);
|
||||
ivy_diag_stream_init_tty(&ctx->diag_stream, b_stdtty);
|
||||
ivy_diag_stream_init_tty(&ctx->diag_stream, fx_stdtty);
|
||||
ivy_lexer_set_diag_ctx(ctx->lex, ctx->diag);
|
||||
ivy_parser_set_diag_ctx(ctx->parser, ctx->diag);
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result compile_ctx_cleanup(struct compile_ctx *ctx)
|
||||
static fx_result compile_ctx_cleanup(struct compile_ctx *ctx)
|
||||
{
|
||||
if (ctx->mod) {
|
||||
mie_value_destroy(MIE_VALUE(ctx->mod));
|
||||
@@ -139,10 +139,10 @@ static b_result compile_ctx_cleanup(struct compile_ctx *ctx)
|
||||
mie_ctx_destroy(ctx->mie_ctx);
|
||||
}
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result open_file(struct compile_ctx *ctx, const char *path)
|
||||
static fx_result open_file(struct compile_ctx *ctx, const char *path)
|
||||
{
|
||||
enum ivy_status status = ivy_file_open(path, &ctx->src);
|
||||
|
||||
@@ -151,10 +151,10 @@ static b_result open_file(struct compile_ctx *ctx, const char *path)
|
||||
|
||||
ctx->src_path = path;
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result parse_file_tokens(struct compile_ctx *ctx)
|
||||
static fx_result parse_file_tokens(struct compile_ctx *ctx)
|
||||
{
|
||||
enum ivy_status status = IVY_OK;
|
||||
|
||||
@@ -166,7 +166,7 @@ static b_result parse_file_tokens(struct compile_ctx *ctx)
|
||||
ivy_diag_ctx_write(
|
||||
ctx->diag, IVY_DIAG_FORMAT_PRETTY,
|
||||
&ctx->diag_stream);
|
||||
return b_error_with_code(
|
||||
return fx_error_with_code(
|
||||
IVY_ERROR_VENDOR, IVY_ERR_BAD_SYNTAX);
|
||||
}
|
||||
|
||||
@@ -181,12 +181,12 @@ static b_result parse_file_tokens(struct compile_ctx *ctx)
|
||||
ctx->diag, IVY_DIAG_FORMAT_PRETTY,
|
||||
&ctx->diag_stream);
|
||||
ivy_token_destroy(tok);
|
||||
return b_error_with_code(
|
||||
return fx_error_with_code(
|
||||
IVY_ERROR_VENDOR, IVY_ERR_BAD_SYNTAX);
|
||||
}
|
||||
|
||||
if (status != IVY_OK) {
|
||||
return b_error_caused_by_code(
|
||||
return fx_error_caused_by_code(
|
||||
IVY_ERROR_VENDOR, IVY_ERR_PARSE_FAILURE,
|
||||
IVY_ERROR_VENDOR, status);
|
||||
}
|
||||
@@ -196,10 +196,10 @@ static b_result parse_file_tokens(struct compile_ctx *ctx)
|
||||
}
|
||||
}
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result generate_mie_ir(struct compile_ctx *ctx)
|
||||
static fx_result generate_mie_ir(struct compile_ctx *ctx)
|
||||
{
|
||||
ivy_codegen_start_module(ctx->codegen);
|
||||
|
||||
@@ -209,45 +209,45 @@ static b_result generate_mie_ir(struct compile_ctx *ctx)
|
||||
enum ivy_status status
|
||||
= ivy_ast_node_iterate(node, &it, node_codegen, ctx);
|
||||
if (status != IVY_OK) {
|
||||
return b_error_caused_by_code(
|
||||
return fx_error_caused_by_code(
|
||||
IVY_ERROR_VENDOR, IVY_ERR_CODEGEN_FAILURE,
|
||||
IVY_ERROR_VENDOR, status);
|
||||
}
|
||||
|
||||
status = ivy_codegen_push_eof(ctx->codegen);
|
||||
if (status != IVY_OK) {
|
||||
return b_error_caused_by_code(
|
||||
return fx_error_caused_by_code(
|
||||
IVY_ERROR_VENDOR, IVY_ERR_CODEGEN_FAILURE,
|
||||
IVY_ERROR_VENDOR, status);
|
||||
}
|
||||
|
||||
ivy_codegen_end_module(ctx->codegen, &ctx->mod);
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result build_block_isel_graph(
|
||||
static fx_result build_block_isel_graph(
|
||||
struct compile_ctx *ctx, struct mie_func *func, struct mie_block *block)
|
||||
{
|
||||
printf("selecting %s.%s...\n", func->f_base.v_name.n_str,
|
||||
block->b_base.v_name.n_str);
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&block->b_phi);
|
||||
fx_queue_entry *entry = fx_queue_first(&block->b_phi);
|
||||
while (entry) {
|
||||
struct mie_value *instr_v
|
||||
= b_unbox(struct mie_value, entry, v_entry);
|
||||
= fx_unbox(struct mie_value, entry, v_entry);
|
||||
mie_select_builder_push_instr(
|
||||
ctx->select, (struct mie_instr *)instr_v);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
entry = b_queue_first(&block->b_instr);
|
||||
entry = fx_queue_first(&block->b_instr);
|
||||
while (entry) {
|
||||
struct mie_value *instr_v
|
||||
= b_unbox(struct mie_value, entry, v_entry);
|
||||
= fx_unbox(struct mie_value, entry, v_entry);
|
||||
mie_select_builder_push_instr(
|
||||
ctx->select, (struct mie_instr *)instr_v);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
if (block->b_terminator) {
|
||||
@@ -267,48 +267,48 @@ static b_result build_block_isel_graph(
|
||||
mie_select_graph_destroy(graph);
|
||||
}
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result build_func_isel_graph(struct compile_ctx *ctx, struct mie_func *func)
|
||||
static fx_result build_func_isel_graph(struct compile_ctx *ctx, struct mie_func *func)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&func->f_blocks);
|
||||
fx_queue_entry *entry = fx_queue_first(&func->f_blocks);
|
||||
while (entry) {
|
||||
struct mie_value *block_v
|
||||
= b_unbox(struct mie_value, entry, v_entry);
|
||||
= fx_unbox(struct mie_value, entry, v_entry);
|
||||
struct mie_block *block = (struct mie_block *)block_v;
|
||||
|
||||
b_result result = build_block_isel_graph(ctx, func, block);
|
||||
if (b_result_is_error(result)) {
|
||||
return b_result_propagate(result);
|
||||
fx_result result = build_block_isel_graph(ctx, func, block);
|
||||
if (fx_result_is_error(result)) {
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result build_isel_graph(struct compile_ctx *ctx)
|
||||
static fx_result build_isel_graph(struct compile_ctx *ctx)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&ctx->mod->m_func);
|
||||
fx_queue_entry *entry = fx_queue_first(&ctx->mod->m_func);
|
||||
while (entry) {
|
||||
struct mie_value *func_v
|
||||
= b_unbox(struct mie_value, entry, v_entry);
|
||||
= fx_unbox(struct mie_value, entry, v_entry);
|
||||
struct mie_func *func = (struct mie_func *)func_v;
|
||||
|
||||
b_result result = build_func_isel_graph(ctx, func);
|
||||
if (b_result_is_error(result)) {
|
||||
return b_result_propagate(result);
|
||||
fx_result result = build_func_isel_graph(ctx, func);
|
||||
if (fx_result_is_error(result)) {
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result dump_ast(struct compile_ctx *ctx)
|
||||
static fx_result dump_ast(struct compile_ctx *ctx)
|
||||
{
|
||||
struct ivy_ast_node *node = ivy_parser_root_node(ctx->parser);
|
||||
struct ivy_ast_node_iterator it = {0};
|
||||
@@ -318,10 +318,10 @@ static b_result dump_ast(struct compile_ctx *ctx)
|
||||
|
||||
ivy_ast_node_iterate(node, &it, print_ast_node, &args);
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result dump_ir(struct compile_ctx *ctx)
|
||||
static fx_result dump_ir(struct compile_ctx *ctx)
|
||||
{
|
||||
struct mie_ir_converter *convert
|
||||
= mie_ir_converter_create(ctx->mie_ctx, MIE_IR_MEM, MIE_IR_TEXT);
|
||||
@@ -331,24 +331,24 @@ static b_result dump_ir(struct compile_ctx *ctx)
|
||||
|
||||
mie_ir_converter_destroy(convert);
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static int compile_file(const char *path, const b_arglist *args)
|
||||
static int compile_file(const char *path, const fx_arglist *args)
|
||||
{
|
||||
#define THROW_AND_RETURN(result, error_code) \
|
||||
do { \
|
||||
if (b_result_is(result, IVY_ERROR_VENDOR, IVY_ERR_BAD_SYNTAX)) { \
|
||||
if (fx_result_is(result, IVY_ERROR_VENDOR, IVY_ERR_BAD_SYNTAX)) { \
|
||||
return error_code; \
|
||||
} \
|
||||
if (b_result_is_error(result)) { \
|
||||
b_throw(result); \
|
||||
if (fx_result_is_error(result)) { \
|
||||
fx_throw(result); \
|
||||
return error_code; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
struct compile_ctx ctx;
|
||||
b_result result = compile_ctx_init(&ctx, args);
|
||||
fx_result result = compile_ctx_init(&ctx, args);
|
||||
THROW_AND_RETURN(result, -1);
|
||||
|
||||
int progress = 0;
|
||||
@@ -397,13 +397,13 @@ end:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int compile(const b_command *cmd, const b_arglist *args, const b_array *_)
|
||||
static int compile(const fx_command *cmd, const fx_arglist *args, const fx_array *_)
|
||||
{
|
||||
b_arglist_iterator it;
|
||||
b_arglist_foreach_filtered(&it, args, B_COMMAND_INVALID_ID, ARG_SOURCE_FILE)
|
||||
fx_arglist_iterator it;
|
||||
fx_arglist_foreach_filtered(&it, args, FX_COMMAND_INVALID_ID, ARG_SOURCE_FILE)
|
||||
{
|
||||
b_arglist_value *path = it.value;
|
||||
if (path->val_type != B_COMMAND_ARG_STRING) {
|
||||
fx_arglist_value *path = it.value;
|
||||
if (path->val_type != FX_COMMAND_ARG_STRING) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -418,64 +418,64 @@ static int compile(const b_command *cmd, const b_arglist *args, const b_array *_
|
||||
|
||||
B_COMMAND(CMD_COMPILE, CMD_ROOT)
|
||||
{
|
||||
B_COMMAND_NAME("compile");
|
||||
B_COMMAND_SHORT_NAME('C');
|
||||
B_COMMAND_DESC(
|
||||
FX_COMMAND_NAME("compile");
|
||||
FX_COMMAND_SHORT_NAME('C');
|
||||
FX_COMMAND_DESC(
|
||||
"compile one or more Ivy source files into Ivy object files.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(compile);
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(compile);
|
||||
|
||||
B_COMMAND_OPTION(OPT_SHOW_LEX_TOKENS)
|
||||
FX_COMMAND_OPTION(OPT_SHOW_LEX_TOKENS)
|
||||
{
|
||||
B_OPTION_LONG_NAME("show-lex");
|
||||
B_OPTION_SHORT_NAME('l');
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_LONG_NAME("show-lex");
|
||||
FX_OPTION_SHORT_NAME('l');
|
||||
FX_OPTION_DESC(
|
||||
"print the lexical tokens generated from the input "
|
||||
"files.");
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_SHOW_AST_NODES)
|
||||
FX_COMMAND_OPTION(OPT_SHOW_AST_NODES)
|
||||
{
|
||||
B_OPTION_LONG_NAME("show-ast");
|
||||
B_OPTION_SHORT_NAME('a');
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_LONG_NAME("show-ast");
|
||||
FX_OPTION_SHORT_NAME('a');
|
||||
FX_OPTION_DESC(
|
||||
"print the abstract syntax tree generated from the "
|
||||
"input files.");
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_SHOW_IR)
|
||||
FX_COMMAND_OPTION(OPT_SHOW_IR)
|
||||
{
|
||||
B_OPTION_LONG_NAME("show-ir");
|
||||
B_OPTION_SHORT_NAME('i');
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_LONG_NAME("show-ir");
|
||||
FX_OPTION_SHORT_NAME('i');
|
||||
FX_OPTION_DESC(
|
||||
"print the Mie IR generated from the "
|
||||
"input files.");
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_SHOW_ISEL_PRE)
|
||||
FX_COMMAND_OPTION(OPT_SHOW_ISEL_PRE)
|
||||
{
|
||||
B_OPTION_LONG_NAME("show-isel-pre");
|
||||
B_OPTION_SHORT_NAME('s');
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_LONG_NAME("show-isel-pre");
|
||||
FX_OPTION_SHORT_NAME('s');
|
||||
FX_OPTION_DESC(
|
||||
"print the instruction selection graph before "
|
||||
"selection has taken place.");
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_SHOW_ISEL_POST)
|
||||
FX_COMMAND_OPTION(OPT_SHOW_ISEL_POST)
|
||||
{
|
||||
B_OPTION_LONG_NAME("show-isel-post");
|
||||
B_OPTION_SHORT_NAME('m');
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_LONG_NAME("show-isel-post");
|
||||
FX_OPTION_SHORT_NAME('m');
|
||||
FX_OPTION_DESC(
|
||||
"print the instruction selection graph after "
|
||||
"selection has taken place.");
|
||||
}
|
||||
|
||||
B_COMMAND_ARG(ARG_SOURCE_FILE)
|
||||
FX_COMMAND_ARG(ARG_SOURCE_FILE)
|
||||
{
|
||||
B_ARG_NAME("source file");
|
||||
B_ARG_DESC("the .im source files to compile.");
|
||||
B_ARG_NR_VALUES(B_ARG_1_OR_MORE_VALUES);
|
||||
FX_ARG_NAME("source file");
|
||||
FX_ARG_DESC("the .im source files to compile.");
|
||||
FX_ARG_NR_VALUES(FX_ARG_1_OR_MORE_VALUES);
|
||||
}
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user