Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
13ed3a65
Commit
13ed3a65
authored
Oct 08, 2013
by
Damien
Browse files
Native Python and Viper support for x64 and thumb all together.
parent
3410be80
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
py/Makefile
View file @
13ed3a65
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)
py/compile.c
View file @
13ed3a65
...
...
@@ -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
;
...
...
py/emit.h
View file @
13ed3a65
...
...
@@ -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
;
...
...
py/emitnative.c
0 → 100644
View file @
13ed3a65
This diff is collapsed.
Click to expand it.
py/emitx64.c
View file @
13ed3a65
...
...
@@ -39,8 +39,8 @@
typedef
enum
{
NEED_TO_PUSH_NOTHING
,
NEED_TO_PUSH_R
64
,
NEED_TO_PUSH_I
64
,
NEED_TO_PUSH_R
EG
,
NEED_TO_PUSH_I
MM
,
}
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_R
64
:
case
NEED_TO_PUSH_R
EG
:
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_I
64
:
case
NEED_TO_PUSH_I
MM
:
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_R
64
:
case
NEED_TO_PUSH_I
64
:
case
NEED_TO_PUSH_R
EG
:
case
NEED_TO_PUSH_I
MM
:
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_R
64
:
case
NEED_TO_PUSH_R
EG
:
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_I
64
:
case
NEED_TO_PUSH_I
MM
:
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
r
64
a
,
vtype_kind_t
*
vtypeb
,
int
r
64
b
)
{
emit_pre_pop_reg
(
emit
,
vtypea
,
r
64
a
);
static
void
emit_pre_pop_reg_reg
(
emit_t
*
emit
,
vtype_kind_t
*
vtypea
,
int
r
eg
a
,
vtype_kind_t
*
vtypeb
,
int
r
eg
b
)
{
emit_pre_pop_reg
(
emit
,
vtypea
,
r
eg
a
);
*
vtypeb
=
emit
->
stack_vtype
[
emit
->
stack_size
-
1
];
asm_x64_mov_local_to_r64
(
emit
->
as
,
emit
->
stack_start
+
emit
->
stack_size
-
1
,
r
64
b
);
asm_x64_mov_local_to_r64
(
emit
->
as
,
emit
->
stack_start
+
emit
->
stack_size
-
1
,
r
eg
b
);
adjust_stack
(
emit
,
-
1
);
}
static
void
emit_pre_pop_reg_reg_reg
(
emit_t
*
emit
,
vtype_kind_t
*
vtypea
,
int
r
64
a
,
vtype_kind_t
*
vtypeb
,
int
r
64
b
,
vtype_kind_t
*
vtypec
,
int
r
64
c
)
{
emit_pre_pop_reg
(
emit
,
vtypea
,
r
64
a
);
static
void
emit_pre_pop_reg_reg_reg
(
emit_t
*
emit
,
vtype_kind_t
*
vtypea
,
int
r
eg
a
,
vtype_kind_t
*
vtypeb
,
int
r
eg
b
,
vtype_kind_t
*
vtypec
,
int
r
eg
c
)
{
emit_pre_pop_reg
(
emit
,
vtypea
,
r
eg
a
);
*
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
,
r
64
b
);
asm_x64_mov_local_to_r64
(
emit
->
as
,
emit
->
stack_start
+
emit
->
stack_size
-
2
,
r
64
c
);
asm_x64_mov_local_to_r64
(
emit
->
as
,
emit
->
stack_start
+
emit
->
stack_size
-
1
,
r
eg
b
);
asm_x64_mov_local_to_r64
(
emit
->
as
,
emit
->
stack_start
+
emit
->
stack_size
-
2
,
r
eg
c
);
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_R
64
;
emit
->
need_to_push
=
NEED_TO_PUSH_R
EG
;
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_I
64
;
emit
->
need_to_push
=
NEED_TO_PUSH_I
MM
;
emit
->
last_vtype
=
vtype
;
emit
->
last_imm
=
imm
;
}
static
void
emit_post_push_reg_reg
(
emit_t
*
emit
,
vtype_kind_t
vtypea
,
int
r
64
a
,
vtype_kind_t
vtypeb
,
int
r
64
b
)
{
static
void
emit_post_push_reg_reg
(
emit_t
*
emit
,
vtype_kind_t
vtypea
,
int
r
eg
a
,
vtype_kind_t
vtypeb
,
int
r
eg
b
)
{
emit
->
stack_vtype
[
emit
->
stack_size
]
=
vtypea
;
asm_x64_mov_r64_to_local
(
emit
->
as
,
r
64
a
,
emit
->
stack_start
+
emit
->
stack_size
);
emit
->
need_to_push
=
NEED_TO_PUSH_R
64
;
asm_x64_mov_r64_to_local
(
emit
->
as
,
r
eg
a
,
emit
->
stack_start
+
emit
->
stack_size
);
emit
->
need_to_push
=
NEED_TO_PUSH_R
EG
;
emit
->
last_vtype
=
vtypeb
;
emit
->
last_reg
=
r
64
b
;
emit
->
last_reg
=
r
eg
b
;
adjust_stack
(
emit
,
1
);
}
static
void
emit_post_push_reg_reg_reg
(
emit_t
*
emit
,
vtype_kind_t
vtypea
,
int
r
64
a
,
vtype_kind_t
vtypeb
,
int
r
64
b
,
vtype_kind_t
vtypec
,
int
r
64
c
)
{
static
void
emit_post_push_reg_reg_reg
(
emit_t
*
emit
,
vtype_kind_t
vtypea
,
int
r
eg
a
,
vtype_kind_t
vtypeb
,
int
r
eg
b
,
vtype_kind_t
vtypec
,
int
r
eg
c
)
{
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
,
r
64
a
,
emit
->
stack_start
+
emit
->
stack_size
);
asm_x64_mov_r64_to_local
(
emit
->
as
,
r
64
b
,
emit
->
stack_start
+
emit
->
stack_size
+
1
);
asm_x64_mov_r64_to_local
(
emit
->
as
,
r
64
c
,
emit
->
stack_start
+
emit
->
stack_size
+
2
);
asm_x64_mov_r64_to_local
(
emit
->
as
,
r
eg
a
,
emit
->
stack_start
+
emit
->
stack_size
);
asm_x64_mov_r64_to_local
(
emit
->
as
,
r
eg
b
,
emit
->
stack_start
+
emit
->
stack_size
+
1
);
asm_x64_mov_r64_to_local
(
emit
->
as
,
r
eg
c
,
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
r
64
a
,
vtype_kind_t
vtypeb
,
int
r
64
b
,
vtype_kind_t
vtypec
,
int
r
64
c
,
vtype_kind_t
vtyped
,
int
r
64
d
)
{
static
void
emit_post_push_reg_reg_reg_reg
(
emit_t
*
emit
,
vtype_kind_t
vtypea
,
int
r
eg
a
,
vtype_kind_t
vtypeb
,
int
r
eg
b
,
vtype_kind_t
vtypec
,
int
r
eg
c
,
vtype_kind_t
vtyped
,
int
r
eg
d
)
{
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
,
r
64
a
,
emit
->
stack_start
+
emit
->
stack_size
);
asm_x64_mov_r64_to_local
(
emit
->
as
,
r
64
b
,
emit
->
stack_start
+
emit
->
stack_size
+
1
);
asm_x64_mov_r64_to_local
(
emit
->
as
,
r
64
c
,
emit
->
stack_start
+
emit
->
stack_size
+
2
);
asm_x64_mov_r64_to_local
(
emit
->
as
,
r
64
d
,
emit
->
stack_start
+
emit
->
stack_size
+
3
);
asm_x64_mov_r64_to_local
(
emit
->
as
,
r
eg
a
,
emit
->
stack_start
+
emit
->
stack_size
);
asm_x64_mov_r64_to_local
(
emit
->
as
,
r
eg
b
,
emit
->
stack_start
+
emit
->
stack_size
+
1
);
asm_x64_mov_r64_to_local
(
emit
->
as
,
r
eg
c
,
emit
->
stack_start
+
emit
->
stack_size
+
2
);
asm_x64_mov_r64_to_local
(
emit
->
as
,
r
eg
d
,
emit
->
stack_start
+
emit
->
stack_size
+
3
);
adjust_stack
(
emit
,
4
);
}
...
...
py/runtime.c
View file @
13ed3a65
...
...
@@ -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
);
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment