asm: implement assembler output file writing
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#ifndef IVY_ASM_ASSEMBLER_H_
|
||||
#define IVY_ASM_ASSEMBLER_H_
|
||||
|
||||
#include <ivy/asm/bin.h>
|
||||
#include <ivy/misc.h>
|
||||
#include <ivy/status.h>
|
||||
#include <stdio.h>
|
||||
@@ -12,31 +13,60 @@ struct ivy_instr;
|
||||
|
||||
struct ivy_assembler;
|
||||
|
||||
enum ivy_assembler_attrib {
|
||||
IVY_ASM_ATTRIB_NONE = 0,
|
||||
IVY_ASM_ATTRIB_IDENT,
|
||||
IVY_ASM_ATTRIB_INDEX,
|
||||
IVY_ASM_ATTRIB_RECIPIENT,
|
||||
IVY_ASM_ATTRIB_SELECTOR,
|
||||
IVY_ASM_ATTRIB_GET,
|
||||
IVY_ASM_ATTRIB_SET,
|
||||
IVY_ASM_ATTRIB_PACKAGE,
|
||||
__IVY_ASM_ATTRIB_COUNT,
|
||||
};
|
||||
|
||||
enum ivy_assembler_pval_type {
|
||||
IVY_ASM_PVAL_NONE = 0,
|
||||
IVY_ASM_PVAL_STRING,
|
||||
IVY_ASM_PVAL_IDENT,
|
||||
IVY_ASM_PVAL_ATOM,
|
||||
IVY_ASM_PVAL_SINT,
|
||||
IVY_ASM_PVAL_UINT,
|
||||
IVY_ASM_PVAL_SELECTOR,
|
||||
};
|
||||
|
||||
enum ivy_assembler_xval_type {
|
||||
IVY_ASM_XVAL_NONE = 0,
|
||||
IVY_ASM_XVAL_PROPERTY,
|
||||
IVY_ASM_XVAL_MEMBER_VAR,
|
||||
IVY_ASM_XVAL_PACKAGE_REF,
|
||||
};
|
||||
|
||||
enum ivy_assembler_scope_type {
|
||||
IVY_ASM_SCOPE_NONE = 0,
|
||||
IVY_ASM_SCOPE_CLASS,
|
||||
IVY_ASM_SCOPE_LAMBDA,
|
||||
IVY_ASM_SCOPE_MSGH,
|
||||
IVY_ASM_SCOPE_CONSTPOOL,
|
||||
IVY_ASM_SCOPE_IMPORT,
|
||||
};
|
||||
|
||||
typedef unsigned int ivy_assembler_attrib_table[__IVY_ASM_ATTRIB_COUNT];
|
||||
|
||||
IVY_API enum ivy_static ivy_assembler_create(FILE *out, struct ivy_assembler **as);
|
||||
IVY_API void ivy_assembler_destroy(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(
|
||||
struct ivy_assembler *as, enum ivy_assembler_scope_type type);
|
||||
struct ivy_assembler *as, enum ivy_assembler_scope_type type,
|
||||
const ivy_assembler_attrib_table attrib);
|
||||
IVY_API enum ivy_status ivy_assembler_end_scope(struct ivy_assembler *as);
|
||||
|
||||
IVY_API enum ivy_status ivy_assembler_put_string(
|
||||
struct ivy_assembler *as, int index, const char *s);
|
||||
IVY_API enum ivy_status ivy_assembler_put_ident(
|
||||
struct ivy_assembler *as, int index, const char *s);
|
||||
IVY_API enum ivy_status ivy_assembler_put_atom(
|
||||
struct ivy_assembler *as, int index, const char *s);
|
||||
IVY_API enum ivy_status ivy_assembler_put_selector(
|
||||
struct ivy_assembler *as, int index, struct ivy_selector *sel);
|
||||
IVY_API enum ivy_status ivy_assembler_put_mvar(
|
||||
struct ivy_assembler *as, int index, const char *name);
|
||||
IVY_API enum ivy_status ivy_assembler_put_pval(
|
||||
struct ivy_assembler *as, enum ivy_assembler_pval_type type,
|
||||
unsigned long index, const void *val);
|
||||
IVY_API enum ivy_status ivy_assembler_put_xval(
|
||||
struct ivy_assembler *as, enum ivy_assembler_xval_type type,
|
||||
const ivy_assembler_attrib_table attrib);
|
||||
IVY_API enum ivy_status ivy_assembler_put_instr(
|
||||
struct ivy_assembler *as, const struct ivy_instr *i);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef IVY_ASM_BIN_H_
|
||||
#define IVY_ASM_BIN_H_
|
||||
|
||||
#include <blue/core/endian.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define IVY_BIN_MAGIC 0x2E495659u
|
||||
@@ -10,7 +11,7 @@
|
||||
#define IVY_TABLE_LAMBDA 0x4C424441u
|
||||
#define IVY_TABLE_MSGH 0x4D534748u
|
||||
#define IVY_TABLE_POOL 0x504F4F4Cu
|
||||
#define IVY_TABLE_XDAT 0x53544142u
|
||||
#define IVY_TABLE_XDAT 0x58444154u
|
||||
|
||||
#define IVY_CLASS_TABLE_MVAR 0x4D564152u
|
||||
#define IVY_CLASS_TABLE_PROP 0x50524F50u
|
||||
@@ -31,61 +32,61 @@
|
||||
typedef uint32_t ivy_bin_data_handle;
|
||||
|
||||
struct ivy_bin_header {
|
||||
uint32_t h_magic;
|
||||
uint16_t h_table_len;
|
||||
b_i32 h_magic;
|
||||
b_i16 h_table_len;
|
||||
uint8_t h_reserved[2];
|
||||
uint64_t h_table_offset;
|
||||
b_i64 h_table_offset;
|
||||
};
|
||||
|
||||
struct ivy_bin_table_entry {
|
||||
uint32_t e_type;
|
||||
uint32_t e_size;
|
||||
uint64_t e_offset;
|
||||
b_i32 e_type;
|
||||
b_i32 e_size;
|
||||
b_i64 e_offset;
|
||||
};
|
||||
|
||||
struct ivy_bin_class_table_entry {
|
||||
uint32_t e_type;
|
||||
b_i32 e_type;
|
||||
union {
|
||||
struct {
|
||||
ivy_bin_data_handle p_ident;
|
||||
ivy_bin_data_handle p_get;
|
||||
ivy_bin_data_handle p_set;
|
||||
uint32_t p_reserved;
|
||||
b_i32 p_ident;
|
||||
b_i32 p_get;
|
||||
b_i32 p_set;
|
||||
b_i32 p_reserved;
|
||||
} e_property;
|
||||
|
||||
struct {
|
||||
uint32_t m_index;
|
||||
ivy_bin_data_handle m_ident;
|
||||
uint8_t m_reserved[16];
|
||||
b_i32 m_index;
|
||||
b_i32 m_ident;
|
||||
uint8_t m_reserved[8];
|
||||
} e_mvar;
|
||||
};
|
||||
};
|
||||
|
||||
struct ivy_bin_class {
|
||||
uint32_t c_ident;
|
||||
b_i32 c_ident;
|
||||
struct ivy_bin_class_table_entry c_table[];
|
||||
};
|
||||
|
||||
struct ivy_bin_lambda {
|
||||
ivy_bin_data_handle l_ident;
|
||||
uint32_t l_instr[];
|
||||
b_i32 l_instr[];
|
||||
};
|
||||
|
||||
struct ivy_bin_msgh {
|
||||
ivy_bin_data_handle msg_recipient;
|
||||
ivy_bin_data_handle msg_selector;
|
||||
uint32_t msg_instr[];
|
||||
b_i32 msg_recipient;
|
||||
b_i32 msg_selector;
|
||||
b_i32 msg_instr[];
|
||||
};
|
||||
|
||||
struct ivy_bin_constpool_header {
|
||||
uint32_t c_nr_table_entries;
|
||||
b_i32 c_nr_table_entries;
|
||||
uint8_t c_reserved[4];
|
||||
uint64_t c_table_offset;
|
||||
b_i64 c_table_offset;
|
||||
};
|
||||
|
||||
struct ivy_bin_string {
|
||||
uint32_t s_hash;
|
||||
uint32_t s_len;
|
||||
b_i32 s_hash;
|
||||
b_i32 s_len;
|
||||
char s_chars[];
|
||||
};
|
||||
|
||||
@@ -93,26 +94,25 @@ struct ivy_bin_selector {
|
||||
uint8_t sel_flags;
|
||||
uint8_t sel_nr_args;
|
||||
uint8_t sel_reserved[2];
|
||||
uint32_t sel_hash;
|
||||
b_i32 sel_hash;
|
||||
ivy_bin_data_handle sel_name;
|
||||
ivy_bin_data_handle sel_args[];
|
||||
};
|
||||
|
||||
struct ivy_bin_ident {
|
||||
uint32_t id_hash;
|
||||
b_i32 id_hash;
|
||||
uint8_t id_nr_parts;
|
||||
uint8_t id_reserved[3];
|
||||
ivy_bin_data_handle id_parts[];
|
||||
};
|
||||
|
||||
struct ivy_bin_constpool_table_entry {
|
||||
uint32_t e_type;
|
||||
uint32_t e_reserved;
|
||||
b_i32 e_type;
|
||||
b_i32 e_reserved;
|
||||
|
||||
union {
|
||||
ivy_bin_data_handle e_handle;
|
||||
int64_t e_sint;
|
||||
uint64_t e_uint;
|
||||
b_i32 e_handle;
|
||||
b_i64 e_int;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user