Native Python and Viper support for x64 and thumb all together.
This commit is contained in:
parent
3410be8035
commit
13ed3a658d
16
py/Makefile
16
py/Makefile
@ -1,5 +1,5 @@
|
||||
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 =
|
||||
|
||||
SRC = \
|
||||
@ -16,8 +16,6 @@ SRC = \
|
||||
emitcpy.c \
|
||||
emitbc.c \
|
||||
asmx64.c \
|
||||
emitx64.c \
|
||||
emitthumb.c \
|
||||
asmthumb.c \
|
||||
emitinlinethumb.c \
|
||||
runtime.c \
|
||||
@ -26,7 +24,7 @@ SRC = \
|
||||
|
||||
SRC_ASM = \
|
||||
|
||||
OBJ = $(SRC:.c=.o) $(SRC_ASM:.s=.o)
|
||||
OBJ = $(SRC:.c=.o) $(SRC_ASM:.s=.o) emitnx64.o emitnthumb.o
|
||||
LIB =
|
||||
PROG = py
|
||||
|
||||
@ -36,15 +34,19 @@ $(PROG): $(OBJ)
|
||||
runtime.o: runtime.c
|
||||
$(CC) $(CFLAGS) -O3 -c -o $@ $<
|
||||
|
||||
bc.o: bc.c
|
||||
vm.o: vm.c
|
||||
$(CC) $(CFLAGS) -O3 -c -o $@ $<
|
||||
|
||||
parse.o: grammar.h
|
||||
compile.o: grammar.h
|
||||
emitcpy.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:
|
||||
/bin/rm $(OBJ)
|
||||
|
@ -2706,10 +2706,10 @@ void py_compile(py_parse_node_t pn) {
|
||||
case EMIT_OPT_NATIVE_PYTHON:
|
||||
case EMIT_OPT_VIPER:
|
||||
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_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);
|
||||
break;
|
||||
|
||||
|
10
py/emit.h
10
py/emit.h
@ -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_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;
|
||||
extern const emit_method_table_t emit_native_x64_method_table;
|
||||
extern const emit_method_table_t emit_native_thumb_method_table;
|
||||
|
||||
emit_t *emit_pass1_new(qstr qstr___class__);
|
||||
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);
|
||||
emit_t *emit_native_x64_new(uint max_num_labels);
|
||||
emit_t *emit_native_thumb_new(uint max_num_labels);
|
||||
|
||||
typedef struct _emit_inline_asm_t emit_inline_asm_t;
|
||||
|
||||
|
1179
py/emitnative.c
Normal file
1179
py/emitnative.c
Normal file
File diff suppressed because it is too large
Load Diff
60
py/emitx64.c
60
py/emitx64.c
@ -39,8 +39,8 @@
|
||||
|
||||
typedef enum {
|
||||
NEED_TO_PUSH_NOTHING,
|
||||
NEED_TO_PUSH_R64,
|
||||
NEED_TO_PUSH_I64,
|
||||
NEED_TO_PUSH_REG,
|
||||
NEED_TO_PUSH_IMM,
|
||||
} need_to_push_t;
|
||||
|
||||
typedef enum {
|
||||
@ -185,13 +185,13 @@ static void stack_settle(emit_t *emit) {
|
||||
case NEED_TO_PUSH_NOTHING:
|
||||
break;
|
||||
|
||||
case NEED_TO_PUSH_R64:
|
||||
case NEED_TO_PUSH_REG:
|
||||
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);
|
||||
adjust_stack(emit, 1);
|
||||
break;
|
||||
|
||||
case NEED_TO_PUSH_I64:
|
||||
case NEED_TO_PUSH_IMM:
|
||||
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_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) {
|
||||
case NEED_TO_PUSH_NOTHING:
|
||||
return emit->stack_vtype[emit->stack_size - 1];
|
||||
|
||||
case NEED_TO_PUSH_R64:
|
||||
case NEED_TO_PUSH_I64:
|
||||
case NEED_TO_PUSH_REG:
|
||||
case NEED_TO_PUSH_IMM:
|
||||
return emit->last_vtype;
|
||||
|
||||
default:
|
||||
@ -234,7 +234,7 @@ static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg) {
|
||||
emit_pre_raw(emit, -1);
|
||||
break;
|
||||
|
||||
case NEED_TO_PUSH_R64:
|
||||
case NEED_TO_PUSH_REG:
|
||||
emit_pre_raw(emit, 0);
|
||||
*vtype = emit->last_vtype;
|
||||
if (emit->last_reg != reg) {
|
||||
@ -242,7 +242,7 @@ static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg) {
|
||||
}
|
||||
break;
|
||||
|
||||
case NEED_TO_PUSH_I64:
|
||||
case NEED_TO_PUSH_IMM:
|
||||
emit_pre_raw(emit, 0);
|
||||
*vtype = emit->last_vtype;
|
||||
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) {
|
||||
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) {
|
||||
emit_pre_pop_reg(emit, vtypea, r64a);
|
||||
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, rega);
|
||||
*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);
|
||||
}
|
||||
|
||||
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) {
|
||||
emit_pre_pop_reg(emit, vtypea, r64a);
|
||||
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, rega);
|
||||
*vtypeb = emit->stack_vtype[emit->stack_size - 1];
|
||||
*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 - 2, r64c);
|
||||
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, regc);
|
||||
adjust_stack(emit, -2);
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
emit->need_to_push = NEED_TO_PUSH_R64;
|
||||
emit->need_to_push = NEED_TO_PUSH_REG;
|
||||
emit->last_vtype = vtype;
|
||||
emit->last_reg = reg;
|
||||
}
|
||||
|
||||
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_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;
|
||||
asm_x64_mov_r64_to_local(emit->as, r64a, emit->stack_start + emit->stack_size);
|
||||
emit->need_to_push = NEED_TO_PUSH_R64;
|
||||
asm_x64_mov_r64_to_local(emit->as, rega, emit->stack_start + emit->stack_size);
|
||||
emit->need_to_push = NEED_TO_PUSH_REG;
|
||||
emit->last_vtype = vtypeb;
|
||||
emit->last_reg = r64b;
|
||||
emit->last_reg = regb;
|
||||
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 + 1] = vtypeb;
|
||||
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, r64b, 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, rega, emit->stack_start + emit->stack_size);
|
||||
asm_x64_mov_r64_to_local(emit->as, regb, emit->stack_start + emit->stack_size + 1);
|
||||
asm_x64_mov_r64_to_local(emit->as, regc, emit->stack_start + emit->stack_size + 2);
|
||||
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 + 1] = vtypeb;
|
||||
emit->stack_vtype[emit->stack_size + 2] = vtypec;
|
||||
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, r64b, 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, r64d, emit->stack_start + emit->stack_size + 3);
|
||||
asm_x64_mov_r64_to_local(emit->as, rega, emit->stack_start + emit->stack_size);
|
||||
asm_x64_mov_r64_to_local(emit->as, regb, emit->stack_start + emit->stack_size + 1);
|
||||
asm_x64_mov_r64_to_local(emit->as, regc, emit->stack_start + emit->stack_size + 2);
|
||||
asm_x64_mov_r64_to_local(emit->as, regd, emit->stack_start + emit->stack_size + 3);
|
||||
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
|
||||
|
||||
if (fp_native != NULL) {
|
||||
fwrite(fun_data, len, 1, fp_native);
|
||||
fflush(fp_native);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user