frontend: assemble: add assembler test
This commit is contained in:
@@ -6,12 +6,16 @@
|
||||
#include <errno.h>
|
||||
#include <ivy/file.h>
|
||||
#include <ivy/asm/lex.h>
|
||||
#include <ivy/asm/assembler.h>
|
||||
#include <stdio.h>
|
||||
|
||||
enum {
|
||||
ARG_SOURCE_FILE,
|
||||
OPT_OUT_FILE,
|
||||
ARG_OUT_FILE,
|
||||
};
|
||||
|
||||
#if 0
|
||||
static int assemble_file(const char *path)
|
||||
{
|
||||
FILE *fp = fopen(path, "r");
|
||||
@@ -54,9 +58,11 @@ static int assemble_file(const char *path)
|
||||
ivy_asm_lexer_destroy(lex);
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int assemble(const b_command *cmd, const b_arglist *args, const b_array *_)
|
||||
{
|
||||
#if 0
|
||||
b_arglist_iterator it;
|
||||
b_arglist_foreach_filtered(&it, args, B_COMMAND_INVALID_ID, ARG_SOURCE_FILE)
|
||||
{
|
||||
@@ -71,6 +77,40 @@ static int assemble(const b_command *cmd, const b_arglist *args, const b_array *
|
||||
return r;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
const char *path = NULL;
|
||||
b_arglist_get_string(args, OPT_OUT_FILE, ARG_OUT_FILE, 0, &path);
|
||||
|
||||
if (!path) {
|
||||
printf("no output path specified.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
FILE *out = fopen(path, "wb");
|
||||
struct ivy_assembler *as;
|
||||
enum ivy_status status = ivy_assembler_create(out, &as);
|
||||
|
||||
if (status != IVY_OK) {
|
||||
b_err("failed to initialise assembler");
|
||||
b_i("reason: ", ivy_status_to_string(status));
|
||||
fclose(out);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ivy_assembler_attrib_table attrib = {
|
||||
[IVY_ASM_ATTRIB_IDENT] = 32,
|
||||
};
|
||||
|
||||
ivy_assembler_begin_scope(as, IVY_ASM_SCOPE_CLASS, attrib);
|
||||
ivy_assembler_end_scope(as);
|
||||
|
||||
attrib[IVY_ASM_ATTRIB_IDENT] = 64;
|
||||
ivy_assembler_begin_scope(as, IVY_ASM_SCOPE_CLASS, attrib);
|
||||
ivy_assembler_end_scope(as);
|
||||
|
||||
ivy_assembler_finish(as);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -91,5 +131,16 @@ B_COMMAND(CMD_ASSEMBLE, CMD_ROOT)
|
||||
B_ARG_NR_VALUES(B_ARG_1_OR_MORE_VALUES);
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_OUT_FILE)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('o');
|
||||
B_OPTION_LONG_NAME("out");
|
||||
B_OPTION_DESC("the path to write the output binary file to.");
|
||||
B_OPTION_ARG(ARG_OUT_FILE) {
|
||||
B_ARG_NAME("path");
|
||||
B_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user