Commit 13ed3a65 authored by Damien's avatar Damien
Browse files

Native Python and Viper support for x64 and thumb all together.

parent 3410be80
CC = gcc CC = gcc
CFLAGS = -Wall -ansi -std=gnu99 -Os -DEMIT_ENABLE_CPY -DEMIT_ENABLE_X64 -DEMIT_ENABLE_THUMB #-DNDEBUG CFLAGS = -Wall -ansi -std=gnu99 -Os -DEMIT_ENABLE_CPY -DEMIT_ENABLE_THUMB #-DNDEBUG
LDFLAGS = LDFLAGS =
SRC = \ SRC = \
...@@ -16,8 +16,6 @@ SRC = \ ...@@ -16,8 +16,6 @@ SRC = \
emitcpy.c \ emitcpy.c \
emitbc.c \ emitbc.c \
asmx64.c \ asmx64.c \
emitx64.c \
emitthumb.c \
asmthumb.c \ asmthumb.c \
emitinlinethumb.c \ emitinlinethumb.c \
runtime.c \ runtime.c \
...@@ -26,7 +24,7 @@ SRC = \ ...@@ -26,7 +24,7 @@ SRC = \
SRC_ASM = \ SRC_ASM = \
OBJ = $(SRC:.c=.o) $(SRC_ASM:.s=.o) OBJ = $(SRC:.c=.o) $(SRC_ASM:.s=.o) emitnx64.o emitnthumb.o
LIB = LIB =
PROG = py PROG = py
...@@ -36,15 +34,19 @@ $(PROG): $(OBJ) ...@@ -36,15 +34,19 @@ $(PROG): $(OBJ)
runtime.o: runtime.c runtime.o: runtime.c
$(CC) $(CFLAGS) -O3 -c -o $@ $< $(CC) $(CFLAGS) -O3 -c -o $@ $<
bc.o: bc.c vm.o: vm.c
$(CC) $(CFLAGS) -O3 -c -o $@ $< $(CC) $(CFLAGS) -O3 -c -o $@ $<
parse.o: grammar.h parse.o: grammar.h
compile.o: grammar.h compile.o: grammar.h
emitcpy.o: emit.h emitcpy.o: emit.h
emitbc.o: emit.h emitbc.o: emit.h
emitx64.o: emit.h
emitthumb.o: emit.h emitnx64.o: emitnative.c emit.h
$(CC) $(CFLAGS) -DN_X64 -c -o $@ $<
emitnthumb.o: emitnative.c emit.h
$(CC) $(CFLAGS) -DN_THUMB -c -o $@ $<
clean: clean:
/bin/rm $(OBJ) /bin/rm $(OBJ)
...@@ -2706,10 +2706,10 @@ void py_compile(py_parse_node_t pn) { ...@@ -2706,10 +2706,10 @@ void py_compile(py_parse_node_t pn) {
case EMIT_OPT_NATIVE_PYTHON: case EMIT_OPT_NATIVE_PYTHON:
case EMIT_OPT_VIPER: case EMIT_OPT_VIPER:
if (emit_native == NULL) { if (emit_native == NULL) {
emit_native = emit_x64_new(max_num_labels); emit_native = emit_native_x64_new(max_num_labels);
} }
comp->emit = emit_native; comp->emit = emit_native;
comp->emit_method_table = &emit_x64_method_table; comp->emit_method_table = &emit_native_x64_method_table;
comp->emit_method_table->set_native_types(comp->emit, s->emit_options == EMIT_OPT_VIPER); comp->emit_method_table->set_native_types(comp->emit, s->emit_options == EMIT_OPT_VIPER);
break; break;
......
...@@ -119,17 +119,15 @@ void emit_common_delete_id(emit_t *emit, const emit_method_table_t *emit_method_ ...@@ -119,17 +119,15 @@ void emit_common_delete_id(emit_t *emit, const emit_method_table_t *emit_method_
extern const emit_method_table_t emit_pass1_method_table; 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_cpython_method_table;
extern const emit_method_table_t emit_bc_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_native_x64_method_table;
extern const emit_method_table_t emit_viper_x64_method_table; extern const emit_method_table_t emit_native_thumb_method_table;
extern const emit_method_table_t emit_thumb_method_table;
emit_t *emit_pass1_new(qstr qstr___class__); emit_t *emit_pass1_new(qstr qstr___class__);
void emit_pass1_free(emit_t *emit); void emit_pass1_free(emit_t *emit);
emit_t *emit_cpython_new(uint max_num_labels); emit_t *emit_cpython_new(uint max_num_labels);
emit_t *emit_bc_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_native_x64_new(uint max_num_labels);
emit_t *emit_viper_x64_new(uint max_num_labels); emit_t *emit_native_thumb_new(uint max_num_labels);
emit_t *emit_thumb_new(uint max_num_labels);
typedef struct _emit_inline_asm_t emit_inline_asm_t; typedef struct _emit_inline_asm_t emit_inline_asm_t;
......
This diff is collapsed.
...@@ -39,8 +39,8 @@ ...@@ -39,8 +39,8 @@
typedef enum { typedef enum {
NEED_TO_PUSH_NOTHING, NEED_TO_PUSH_NOTHING,
NEED_TO_PUSH_R64, NEED_TO_PUSH_REG,
NEED_TO_PUSH_I64, NEED_TO_PUSH_IMM,
} need_to_push_t; } need_to_push_t;
typedef enum { typedef enum {
...@@ -185,13 +185,13 @@ static void stack_settle(emit_t *emit) { ...@@ -185,13 +185,13 @@ static void stack_settle(emit_t *emit) {
case NEED_TO_PUSH_NOTHING: case NEED_TO_PUSH_NOTHING:
break; break;
case NEED_TO_PUSH_R64: case NEED_TO_PUSH_REG:
emit->stack_vtype[emit->stack_size] = emit->last_vtype; emit->stack_vtype[emit->stack_size] = emit->last_vtype;
asm_x64_mov_r64_to_local(emit->as, emit->last_reg, emit->stack_start + emit->stack_size); asm_x64_mov_r64_to_local(emit->as, emit->last_reg, emit->stack_start + emit->stack_size);
adjust_stack(emit, 1); adjust_stack(emit, 1);
break; break;
case NEED_TO_PUSH_I64: case NEED_TO_PUSH_IMM:
emit->stack_vtype[emit->stack_size] = emit->last_vtype; emit->stack_vtype[emit->stack_size] = emit->last_vtype;
asm_x64_mov_i64_to_r64_optimised(emit->as, emit->last_imm, REG_RAX); asm_x64_mov_i64_to_r64_optimised(emit->as, emit->last_imm, REG_RAX);
asm_x64_mov_r64_to_local(emit->as, REG_RAX, emit->stack_start + emit->stack_size); asm_x64_mov_r64_to_local(emit->as, REG_RAX, emit->stack_start + emit->stack_size);
...@@ -216,8 +216,8 @@ static vtype_kind_t peek_vtype(emit_t *emit) { ...@@ -216,8 +216,8 @@ static vtype_kind_t peek_vtype(emit_t *emit) {
case NEED_TO_PUSH_NOTHING: case NEED_TO_PUSH_NOTHING:
return emit->stack_vtype[emit->stack_size - 1]; return emit->stack_vtype[emit->stack_size - 1];
case NEED_TO_PUSH_R64: case NEED_TO_PUSH_REG:
case NEED_TO_PUSH_I64: case NEED_TO_PUSH_IMM:
return emit->last_vtype; return emit->last_vtype;
default: default:
...@@ -234,7 +234,7 @@ static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg) { ...@@ -234,7 +234,7 @@ static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg) {
emit_pre_raw(emit, -1); emit_pre_raw(emit, -1);
break; break;
case NEED_TO_PUSH_R64: case NEED_TO_PUSH_REG:
emit_pre_raw(emit, 0); emit_pre_raw(emit, 0);
*vtype = emit->last_vtype; *vtype = emit->last_vtype;
if (emit->last_reg != reg) { if (emit->last_reg != reg) {
...@@ -242,7 +242,7 @@ static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg) { ...@@ -242,7 +242,7 @@ static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg) {
} }
break; break;
case NEED_TO_PUSH_I64: case NEED_TO_PUSH_IMM:
emit_pre_raw(emit, 0); emit_pre_raw(emit, 0);
*vtype = emit->last_vtype; *vtype = emit->last_vtype;
asm_x64_mov_i64_to_r64_optimised(emit->as, emit->last_imm, reg); asm_x64_mov_i64_to_r64_optimised(emit->as, emit->last_imm, reg);
...@@ -251,19 +251,19 @@ static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg) { ...@@ -251,19 +251,19 @@ static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg) {
emit->need_to_push = NEED_TO_PUSH_NOTHING; emit->need_to_push = NEED_TO_PUSH_NOTHING;
} }
static void emit_pre_pop_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int r64a, vtype_kind_t *vtypeb, int r64b) { static void emit_pre_pop_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb) {
emit_pre_pop_reg(emit, vtypea, r64a); emit_pre_pop_reg(emit, vtypea, rega);
*vtypeb = emit->stack_vtype[emit->stack_size - 1]; *vtypeb = emit->stack_vtype[emit->stack_size - 1];
asm_x64_mov_local_to_r64(emit->as, emit->stack_start + emit->stack_size - 1, r64b); asm_x64_mov_local_to_r64(emit->as, emit->stack_start + emit->stack_size - 1, regb);
adjust_stack(emit, -1); adjust_stack(emit, -1);
} }
static void emit_pre_pop_reg_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int r64a, vtype_kind_t *vtypeb, int r64b, vtype_kind_t *vtypec, int r64c) { static void emit_pre_pop_reg_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb, vtype_kind_t *vtypec, int regc) {
emit_pre_pop_reg(emit, vtypea, r64a); emit_pre_pop_reg(emit, vtypea, rega);
*vtypeb = emit->stack_vtype[emit->stack_size - 1]; *vtypeb = emit->stack_vtype[emit->stack_size - 1];
*vtypec = emit->stack_vtype[emit->stack_size - 2]; *vtypec = emit->stack_vtype[emit->stack_size - 2];
asm_x64_mov_local_to_r64(emit->as, emit->stack_start + emit->stack_size - 1, r64b); asm_x64_mov_local_to_r64(emit->as, emit->stack_start + emit->stack_size - 1, regb);
asm_x64_mov_local_to_r64(emit->as, emit->stack_start + emit->stack_size - 2, r64c); asm_x64_mov_local_to_r64(emit->as, emit->stack_start + emit->stack_size - 2, regc);
adjust_stack(emit, -2); adjust_stack(emit, -2);
} }
...@@ -271,45 +271,45 @@ static void emit_post(emit_t *emit) { ...@@ -271,45 +271,45 @@ static void emit_post(emit_t *emit) {
} }
static void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg) { static void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg) {
emit->need_to_push = NEED_TO_PUSH_R64; emit->need_to_push = NEED_TO_PUSH_REG;
emit->last_vtype = vtype; emit->last_vtype = vtype;
emit->last_reg = reg; emit->last_reg = reg;
} }
static void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, int64_t imm) { static void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, int64_t imm) {
emit->need_to_push = NEED_TO_PUSH_I64; emit->need_to_push = NEED_TO_PUSH_IMM;
emit->last_vtype = vtype; emit->last_vtype = vtype;
emit->last_imm = imm; emit->last_imm = imm;
} }
static void emit_post_push_reg_reg(emit_t *emit, vtype_kind_t vtypea, int r64a, vtype_kind_t vtypeb, int r64b) { static void emit_post_push_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb) {
emit->stack_vtype[emit->stack_size] = vtypea; emit->stack_vtype[emit->stack_size] = vtypea;
asm_x64_mov_r64_to_local(emit->as, r64a, emit->stack_start + emit->stack_size); asm_x64_mov_r64_to_local(emit->as, rega, emit->stack_start + emit->stack_size);
emit->need_to_push = NEED_TO_PUSH_R64; emit->need_to_push = NEED_TO_PUSH_REG;
emit->last_vtype = vtypeb; emit->last_vtype = vtypeb;
emit->last_reg = r64b; emit->last_reg = regb;
adjust_stack(emit, 1); adjust_stack(emit, 1);
} }
static void emit_post_push_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int r64a, vtype_kind_t vtypeb, int r64b, vtype_kind_t vtypec, int r64c) { static void emit_post_push_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb, vtype_kind_t vtypec, int regc) {
emit->stack_vtype[emit->stack_size] = vtypea; emit->stack_vtype[emit->stack_size] = vtypea;
emit->stack_vtype[emit->stack_size + 1] = vtypeb; emit->stack_vtype[emit->stack_size + 1] = vtypeb;
emit->stack_vtype[emit->stack_size + 2] = vtypec; emit->stack_vtype[emit->stack_size + 2] = vtypec;
asm_x64_mov_r64_to_local(emit->as, r64a, emit->stack_start + emit->stack_size); asm_x64_mov_r64_to_local(emit->as, rega, emit->stack_start + emit->stack_size);
asm_x64_mov_r64_to_local(emit->as, r64b, emit->stack_start + emit->stack_size + 1); asm_x64_mov_r64_to_local(emit->as, regb, emit->stack_start + emit->stack_size + 1);
asm_x64_mov_r64_to_local(emit->as, r64c, emit->stack_start + emit->stack_size + 2); asm_x64_mov_r64_to_local(emit->as, regc, emit->stack_start + emit->stack_size + 2);
adjust_stack(emit, 3); adjust_stack(emit, 3);
} }
static void emit_post_push_reg_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int r64a, vtype_kind_t vtypeb, int r64b, vtype_kind_t vtypec, int r64c, vtype_kind_t vtyped, int r64d) { static void emit_post_push_reg_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb, vtype_kind_t vtypec, int regc, vtype_kind_t vtyped, int regd) {
emit->stack_vtype[emit->stack_size] = vtypea; emit->stack_vtype[emit->stack_size] = vtypea;
emit->stack_vtype[emit->stack_size + 1] = vtypeb; emit->stack_vtype[emit->stack_size + 1] = vtypeb;
emit->stack_vtype[emit->stack_size + 2] = vtypec; emit->stack_vtype[emit->stack_size + 2] = vtypec;
emit->stack_vtype[emit->stack_size + 3] = vtyped; emit->stack_vtype[emit->stack_size + 3] = vtyped;
asm_x64_mov_r64_to_local(emit->as, r64a, emit->stack_start + emit->stack_size); asm_x64_mov_r64_to_local(emit->as, rega, emit->stack_start + emit->stack_size);
asm_x64_mov_r64_to_local(emit->as, r64b, emit->stack_start + emit->stack_size + 1); asm_x64_mov_r64_to_local(emit->as, regb, emit->stack_start + emit->stack_size + 1);
asm_x64_mov_r64_to_local(emit->as, r64c, emit->stack_start + emit->stack_size + 2); asm_x64_mov_r64_to_local(emit->as, regc, emit->stack_start + emit->stack_size + 2);
asm_x64_mov_r64_to_local(emit->as, r64d, emit->stack_start + emit->stack_size + 3); asm_x64_mov_r64_to_local(emit->as, regd, emit->stack_start + emit->stack_size + 3);
adjust_stack(emit, 4); adjust_stack(emit, 4);
} }
......
...@@ -419,6 +419,7 @@ void rt_assign_native_code(int unique_code_id, py_fun_t fun, uint len, int n_arg ...@@ -419,6 +419,7 @@ void rt_assign_native_code(int unique_code_id, py_fun_t fun, uint len, int n_arg
if (fp_native != NULL) { if (fp_native != NULL) {
fwrite(fun_data, len, 1, fp_native); fwrite(fun_data, len, 1, fp_native);
fflush(fp_native);
} }
} }
......
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