meta: replace bluelib with fx
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#include "cmd.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <blue/term.h>
|
||||
#include <fx/cmd.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/term.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
@@ -30,7 +30,7 @@ enum {
|
||||
OPT_CONSTPOOL,
|
||||
};
|
||||
|
||||
static void dump_instruction(b_i32 x)
|
||||
static void dump_instruction(fx_i32 x)
|
||||
{
|
||||
struct ivy_instr instr = {};
|
||||
enum ivy_status status = ivy_instr_decode(x, &instr);
|
||||
@@ -226,7 +226,7 @@ static enum ivy_status dump_class(
|
||||
}
|
||||
|
||||
status = ivy_asm_constpool_reader_read_value(
|
||||
pool, b_i32_btoh(class_header.c_ident), &class_ident);
|
||||
pool, fx_i32_btoh(class_header.c_ident), &class_ident);
|
||||
if (status != IVY_OK) {
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -262,13 +262,13 @@ static enum ivy_status dump_class(
|
||||
printf(" [%03zu] ", i);
|
||||
|
||||
char s[256];
|
||||
uint32_t type = b_i32_btoh(entry.e_type);
|
||||
uint32_t type = fx_i32_btoh(entry.e_type);
|
||||
switch (type) {
|
||||
case IVY_CLASS_TABLE_PROP: {
|
||||
printf("type:property\n");
|
||||
struct ivy_asm_constpool_value *prop_ident = NULL;
|
||||
status = ivy_asm_constpool_reader_read_value(
|
||||
pool, b_i32_btoh(entry.e_property.p_ident),
|
||||
pool, fx_i32_btoh(entry.e_property.p_ident),
|
||||
&prop_ident);
|
||||
if (status != IVY_OK) {
|
||||
break;
|
||||
@@ -279,8 +279,8 @@ static enum ivy_status dump_class(
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t get = b_i32_btoh(entry.e_property.p_get);
|
||||
uint32_t set = b_i32_btoh(entry.e_property.p_set);
|
||||
uint32_t get = fx_i32_btoh(entry.e_property.p_get);
|
||||
uint32_t set = fx_i32_btoh(entry.e_property.p_set);
|
||||
|
||||
ivy_ident_to_string(prop_ident->v_ident, s, sizeof s);
|
||||
ivy_asm_constpool_value_destroy(prop_ident);
|
||||
@@ -305,7 +305,7 @@ static enum ivy_status dump_class(
|
||||
printf("type:variable\n");
|
||||
struct ivy_asm_constpool_value *var_ident = NULL;
|
||||
status = ivy_asm_constpool_reader_read_value(
|
||||
pool, b_i32_btoh(entry.e_mvar.m_ident), &var_ident);
|
||||
pool, fx_i32_btoh(entry.e_mvar.m_ident), &var_ident);
|
||||
if (status != IVY_OK) {
|
||||
break;
|
||||
}
|
||||
@@ -315,7 +315,7 @@ static enum ivy_status dump_class(
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t index = b_i32_btoh(entry.e_mvar.m_index);
|
||||
uint32_t index = fx_i32_btoh(entry.e_mvar.m_index);
|
||||
ivy_ident_to_string(var_ident->v_ident, s, sizeof s);
|
||||
ivy_asm_constpool_value_destroy(var_ident);
|
||||
printf(" ident:%s, index:0x%" PRIx32
|
||||
@@ -328,7 +328,7 @@ static enum ivy_status dump_class(
|
||||
printf("type:method\n");
|
||||
struct ivy_asm_constpool_value *sel = NULL;
|
||||
status = ivy_asm_constpool_reader_read_value(
|
||||
pool, b_i32_btoh(entry.e_msgh.msg_selector), &sel);
|
||||
pool, fx_i32_btoh(entry.e_msgh.msg_selector), &sel);
|
||||
if (status != IVY_OK) {
|
||||
break;
|
||||
}
|
||||
@@ -338,7 +338,7 @@ static enum ivy_status dump_class(
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t block = b_i32_btoh(entry.e_msgh.msg_block);
|
||||
uint32_t block = fx_i32_btoh(entry.e_msgh.msg_block);
|
||||
ivy_selector_to_string(sel->v_sel, s, sizeof s);
|
||||
ivy_asm_constpool_value_destroy(sel);
|
||||
|
||||
@@ -399,7 +399,7 @@ static enum ivy_status dump_constpool(struct ivy_asm_reader *object)
|
||||
enum ivy_status status
|
||||
= ivy_asm_reader_open_constpool(object, 0, 0, &pool);
|
||||
if (status == IVY_ERR_NO_ENTRY) {
|
||||
b_err("object file has no constpool.\n");
|
||||
fx_err("object file has no constpool.\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -409,8 +409,8 @@ static enum ivy_status dump_constpool(struct ivy_asm_reader *object)
|
||||
struct ivy_asm_constpool_value *v;
|
||||
status = ivy_asm_constpool_reader_read_value(pool, i, &v);
|
||||
if (status != IVY_OK) {
|
||||
b_err("cannot read constpool value");
|
||||
b_i("reason: %s", ivy_status_to_string(status));
|
||||
fx_err("cannot read constpool value");
|
||||
fx_i("reason: %s", ivy_status_to_string(status));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -455,7 +455,7 @@ static enum ivy_status dump_constpool(struct ivy_asm_reader *object)
|
||||
return status;
|
||||
}
|
||||
|
||||
static void dump_instructions(b_i32 *x, size_t buffer_size)
|
||||
static void dump_instructions(fx_i32 *x, size_t buffer_size)
|
||||
{
|
||||
size_t nr_instr = buffer_size / sizeof *x;
|
||||
|
||||
@@ -503,7 +503,7 @@ static enum ivy_status dump_header(
|
||||
break;
|
||||
}
|
||||
|
||||
printf(" ident=0x%04x\n", b_i32_btoh(xcls.c_ident));
|
||||
printf(" ident=0x%04x\n", fx_i32_btoh(xcls.c_ident));
|
||||
*dump_offset = sizeof xcls;
|
||||
break;
|
||||
}
|
||||
@@ -520,7 +520,7 @@ static enum ivy_status dump_header(
|
||||
break;
|
||||
}
|
||||
|
||||
long index = b_i32_btoh(text.b_index);
|
||||
long index = fx_i32_btoh(text.b_index);
|
||||
printf(" index=0x%04lx [%ld]\n", index, index);
|
||||
*dump_offset = sizeof text;
|
||||
break;
|
||||
@@ -584,7 +584,7 @@ static enum ivy_status dump_section(
|
||||
printf(" | ");
|
||||
|
||||
if (flags & DUMP_INSTRUCTIONS) {
|
||||
dump_instructions((b_i32 *)x, buffer_size);
|
||||
dump_instructions((fx_i32 *)x, buffer_size);
|
||||
} else {
|
||||
dump_strings(x, buffer_size);
|
||||
}
|
||||
@@ -649,31 +649,31 @@ static enum ivy_status dump_section_table(struct ivy_asm_reader *reader, bool du
|
||||
}
|
||||
|
||||
static int disassemble(
|
||||
const b_command *cmd, const b_arglist *args, const b_array *_)
|
||||
const fx_command *cmd, const fx_arglist *args, const fx_array *_)
|
||||
{
|
||||
bool header = b_arglist_get_count(args, OPT_HEADER, B_COMMAND_INVALID_ID)
|
||||
bool header = fx_arglist_get_count(args, OPT_HEADER, FX_COMMAND_INVALID_ID)
|
||||
> 0;
|
||||
bool sections
|
||||
= b_arglist_get_count(args, OPT_SECTIONS, B_COMMAND_INVALID_ID) > 0;
|
||||
bool dump = b_arglist_get_count(args, OPT_DUMP, B_COMMAND_INVALID_ID) > 0;
|
||||
= fx_arglist_get_count(args, OPT_SECTIONS, FX_COMMAND_INVALID_ID) > 0;
|
||||
bool dump = fx_arglist_get_count(args, OPT_DUMP, FX_COMMAND_INVALID_ID) > 0;
|
||||
bool constpool
|
||||
= b_arglist_get_count(args, OPT_CONSTPOOL, B_COMMAND_INVALID_ID)
|
||||
= fx_arglist_get_count(args, OPT_CONSTPOOL, FX_COMMAND_INVALID_ID)
|
||||
> 0;
|
||||
bool classes
|
||||
= b_arglist_get_count(args, OPT_CLASSES, B_COMMAND_INVALID_ID) > 0;
|
||||
= fx_arglist_get_count(args, OPT_CLASSES, FX_COMMAND_INVALID_ID) > 0;
|
||||
|
||||
const char *in_path = NULL;
|
||||
|
||||
b_arglist_get_string(args, B_COMMAND_INVALID_ID, ARG_BIN_FILE, 0, &in_path);
|
||||
fx_arglist_get_string(args, FX_COMMAND_INVALID_ID, ARG_BIN_FILE, 0, &in_path);
|
||||
if (!in_path) {
|
||||
b_err("no input file specified.");
|
||||
fx_err("no input file specified.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
FILE *in = fopen(in_path, "rb");
|
||||
if (!in) {
|
||||
b_err("cannot open object file");
|
||||
b_i("reason: %s", strerror(errno));
|
||||
fx_err("cannot open object file");
|
||||
fx_i("reason: %s", strerror(errno));
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -682,8 +682,8 @@ static int disassemble(
|
||||
enum ivy_status status = ivy_asm_reader_open(in, &reader);
|
||||
|
||||
if (status != IVY_OK) {
|
||||
b_err("cannot open object file");
|
||||
b_i("reason: %s", ivy_status_to_string(status));
|
||||
fx_err("cannot open object file");
|
||||
fx_i("reason: %s", ivy_status_to_string(status));
|
||||
|
||||
fclose(in);
|
||||
return -1;
|
||||
@@ -719,59 +719,59 @@ static int disassemble(
|
||||
|
||||
B_COMMAND(CMD_DISASSEMBLE, CMD_ROOT)
|
||||
{
|
||||
B_COMMAND_NAME("disassemble");
|
||||
B_COMMAND_SHORT_NAME('D');
|
||||
B_COMMAND_DESC("disassemble an Ivy object file.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(disassemble);
|
||||
FX_COMMAND_NAME("disassemble");
|
||||
FX_COMMAND_SHORT_NAME('D');
|
||||
FX_COMMAND_DESC("disassemble an Ivy object file.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(disassemble);
|
||||
|
||||
B_COMMAND_ARG(ARG_BIN_FILE)
|
||||
FX_COMMAND_ARG(ARG_BIN_FILE)
|
||||
{
|
||||
B_ARG_NAME("input file");
|
||||
B_ARG_DESC("the Ivy object file to disassemble.");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("input file");
|
||||
FX_ARG_DESC("the Ivy object file to disassemble.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_HEADER)
|
||||
FX_COMMAND_OPTION(OPT_HEADER)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('h');
|
||||
B_OPTION_LONG_NAME("header");
|
||||
B_OPTION_DESC("print the object file header.");
|
||||
FX_OPTION_SHORT_NAME('h');
|
||||
FX_OPTION_LONG_NAME("header");
|
||||
FX_OPTION_DESC("print the object file header.");
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_SECTIONS)
|
||||
FX_COMMAND_OPTION(OPT_SECTIONS)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('s');
|
||||
B_OPTION_LONG_NAME("section-table");
|
||||
B_OPTION_DESC("print the object file section table.");
|
||||
FX_OPTION_SHORT_NAME('s');
|
||||
FX_OPTION_LONG_NAME("section-table");
|
||||
FX_OPTION_DESC("print the object file section table.");
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_DUMP)
|
||||
FX_COMMAND_OPTION(OPT_DUMP)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('d');
|
||||
B_OPTION_LONG_NAME("dump");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('d');
|
||||
FX_OPTION_LONG_NAME("dump");
|
||||
FX_OPTION_DESC(
|
||||
"decode and print the contents of each object "
|
||||
"section.");
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_CLASSES)
|
||||
FX_COMMAND_OPTION(OPT_CLASSES)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('c');
|
||||
B_OPTION_LONG_NAME("classes");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('c');
|
||||
FX_OPTION_LONG_NAME("classes");
|
||||
FX_OPTION_DESC(
|
||||
"print the classes contained in the object "
|
||||
"file.");
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_CONSTPOOL)
|
||||
FX_COMMAND_OPTION(OPT_CONSTPOOL)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('p');
|
||||
B_OPTION_LONG_NAME("pool-data");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('p');
|
||||
FX_OPTION_LONG_NAME("pool-data");
|
||||
FX_OPTION_DESC(
|
||||
"print the constant pool data in the object "
|
||||
"file.");
|
||||
}
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user