Commit 7af3d19a authored by Damien's avatar Damien
Browse files

Implement crude viper emit stage.

parent e4af64f3
......@@ -17,6 +17,7 @@ SRC = \
emitbc.c \
asmx64.c \
emitx64.c \
emitviperx64.c \
emitthumb.c \
asmthumb.c \
emitinlinethumb.c \
......
......@@ -441,6 +441,9 @@ void asm_x64_cmp_i32_with_r32(asm_x64_t* as, int src_i32, int src_r32) {
}
void asm_x64_test_r8_with_r8(asm_x64_t* as, int src_r64_a, int src_r64_b) {
// TODO implement for other registers
assert(src_r64_a == REG_RAX);
assert(src_r64_b == REG_RAX);
asm_x64_write_byte_2(as, OPCODE_TEST_R8_WITH_RM8, MODRM_R64(src_r64_a) | MODRM_RM_REG | MODRM_RM_R64(src_r64_b));
}
......
......@@ -31,7 +31,8 @@ typedef enum {
#define EMIT_OPT_NONE (0)
#define EMIT_OPT_BYTE_CODE (1)
#define EMIT_OPT_NATIVE_PYTHON (2)
#define EMIT_OPT_ASM_THUMB (3)
#define EMIT_OPT_VIPER (3)
#define EMIT_OPT_ASM_THUMB (4)
typedef struct _compiler_t {
qstr qstr___class__;
......@@ -43,6 +44,7 @@ typedef struct _compiler_t {
qstr qstr_assertion_error;
qstr qstr_micropython;
qstr qstr_native;
qstr qstr_viper;
qstr qstr_asm_thumb;
pass_kind_t pass;
......@@ -764,6 +766,8 @@ static bool compile_built_in_decorator(compiler_t *comp, int name_len, py_parse_
qstr attr = PY_PARSE_NODE_LEAF_ARG(name_nodes[1]);
if (attr == comp->qstr_native) {
*emit_options = EMIT_OPT_NATIVE_PYTHON;
} else if (attr == comp->qstr_viper) {
*emit_options = EMIT_OPT_VIPER;
} else if (attr == comp->qstr_asm_thumb) {
*emit_options = EMIT_OPT_ASM_THUMB;
} else {
......@@ -2640,6 +2644,7 @@ void py_compile(py_parse_node_t pn) {
comp->qstr_assertion_error = qstr_from_str_static("AssertionError");
comp->qstr_micropython = qstr_from_str_static("micropython");
comp->qstr_native = qstr_from_str_static("native");
comp->qstr_viper = qstr_from_str_static("viper");
comp->qstr_asm_thumb = qstr_from_str_static("asm_thumb");
comp->break_label = 0;
......@@ -2684,6 +2689,7 @@ void py_compile(py_parse_node_t pn) {
// compile pass 2 and 3
emit_t *emit_bc = NULL;
emit_t *emit_native = NULL;
emit_t *emit_viper = NULL;
emit_inline_asm_t *emit_inline_thumb = NULL;
for (scope_t *s = comp->scope_head; s != NULL; s = s->next) {
if (s->emit_options == EMIT_OPT_ASM_THUMB) {
......@@ -2706,6 +2712,14 @@ void py_compile(py_parse_node_t pn) {
comp->emit_method_table = &emit_x64_method_table;
break;
case EMIT_OPT_VIPER:
if (emit_viper == NULL) {
emit_viper = emit_viper_x64_new(max_num_labels);
}
comp->emit = emit_viper;
comp->emit_method_table = &emit_viper_x64_method_table;
break;
default:
if (emit_bc == NULL) {
emit_bc = emit_bc_new(max_num_labels);
......@@ -2714,6 +2728,8 @@ void py_compile(py_parse_node_t pn) {
comp->emit_method_table = &emit_bc_method_table;
break;
}
//comp->emit = emit_cpython_new(max_num_labels);
//comp->emit_method_table = &emit_cpython_method_table;
compile_scope(comp, s, PASS_2);
compile_scope(comp, s, PASS_3);
}
......
......@@ -120,6 +120,7 @@ extern const emit_method_table_t emit_pass1_method_table;
extern const emit_method_table_t emit_cpython_method_table;
extern const emit_method_table_t emit_bc_method_table;
extern const emit_method_table_t emit_x64_method_table;
extern const emit_method_table_t emit_viper_x64_method_table;
extern const emit_method_table_t emit_thumb_method_table;
emit_t *emit_pass1_new(qstr qstr___class__);
......@@ -127,6 +128,7 @@ void emit_pass1_free(emit_t *emit);
emit_t *emit_cpython_new(uint max_num_labels);
emit_t *emit_bc_new(uint max_num_labels);
emit_t *emit_x64_new(uint max_num_labels);
emit_t *emit_viper_x64_new(uint max_num_labels);
emit_t *emit_thumb_new(uint max_num_labels);
typedef struct _emit_inline_asm_t emit_inline_asm_t;
......
This diff is collapsed.
......@@ -130,18 +130,6 @@ static void emit_x64_set_stack_size(emit_t *emit, int size) {
emit->stack_size = size;
}
static void emit_x64_load_id(emit_t *emit, qstr qstr) {
emit_common_load_id(emit, &emit_x64_method_table, emit->scope, qstr);
}
static void emit_x64_store_id(emit_t *emit, qstr qstr) {
emit_common_store_id(emit, &emit_x64_method_table, emit->scope, qstr);
}
static void emit_x64_delete_id(emit_t *emit, qstr qstr) {
emit_common_delete_id(emit, &emit_x64_method_table, emit->scope, qstr);
}
static void adjust_stack(emit_t *emit, int stack_size_delta) {
emit->stack_size += stack_size_delta;
assert(emit->stack_size >= 0);
......@@ -268,6 +256,18 @@ static void emit_call_with_i64_arg(emit_t *emit, void *fun, int64_t arg_val, int
asm_x64_call_ind(emit->as, fun, REG_RAX);
}
static void emit_x64_load_id(emit_t *emit, qstr qstr) {
emit_common_load_id(emit, &emit_x64_method_table, emit->scope, qstr);
}
static void emit_x64_store_id(emit_t *emit, qstr qstr) {
emit_common_store_id(emit, &emit_x64_method_table, emit->scope, qstr);
}
static void emit_x64_delete_id(emit_t *emit, qstr qstr) {
emit_common_delete_id(emit, &emit_x64_method_table, emit->scope, qstr);
}
static void emit_x64_label_assign(emit_t *emit, int l) {
asm_x64_label_assign(emit->as, l);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment