Skip to content

Commit c025ebb

Browse files
committed
Separate out mpy core and unix version.
1 parent a56f292 commit c025ebb

19 files changed

Lines changed: 146 additions & 104 deletions

py/.gitignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

py/Makefile

Lines changed: 0 additions & 52 deletions
This file was deleted.

py/asmthumb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <string.h>
55

66
#include "misc.h"
7-
#include "machine.h"
7+
#include "mpyconfig.h"
88
#include "asmthumb.h"
99

1010
#define UNSIGNED_FIT8(x) (((x) & 0xffffff00) == 0)

py/compile.c

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include <assert.h>
77

88
#include "misc.h"
9+
#include "mpyconfig.h"
910
#include "lexer.h"
10-
#include "machine.h"
1111
#include "parse.h"
1212
#include "scope.h"
1313
#include "compile.h"
@@ -768,8 +768,10 @@ static bool compile_built_in_decorator(compiler_t *comp, int name_len, py_parse_
768768
*emit_options = EMIT_OPT_NATIVE_PYTHON;
769769
} else if (attr == comp->qstr_viper) {
770770
*emit_options = EMIT_OPT_VIPER;
771+
#if defined(MICROPY_EMIT_ENABLE_INLINE_THUMB)
771772
} else if (attr == comp->qstr_asm_thumb) {
772773
*emit_options = EMIT_OPT_ASM_THUMB;
774+
#endif
773775
} else {
774776
printf("SyntaxError: invalid micropython decorator\n");
775777
}
@@ -2673,8 +2675,11 @@ void py_compile(py_parse_node_t pn) {
26732675
comp->emit_inline_asm_method_table = NULL;
26742676
uint max_num_labels = 0;
26752677
for (scope_t *s = comp->scope_head; s != NULL; s = s->next) {
2676-
if (s->emit_options == EMIT_OPT_ASM_THUMB) {
2678+
if (false) {
2679+
#ifdef MICROPY_EMIT_ENABLE_INLINE_THUMB
2680+
} else if (s->emit_options == EMIT_OPT_ASM_THUMB) {
26772681
compile_scope_inline_asm(comp, s, PASS_1);
2682+
#endif
26782683
} else {
26792684
compile_scope(comp, s, PASS_1);
26802685
}
@@ -2694,11 +2699,20 @@ void py_compile(py_parse_node_t pn) {
26942699
emit_pass1_free(comp->emit);
26952700

26962701
// compile pass 2 and 3
2702+
#if !defined(MICROPY_EMIT_ENABLE_CPYTHON)
26972703
emit_t *emit_bc = NULL;
26982704
emit_t *emit_native = NULL;
2705+
#endif
2706+
#if defined(MICROPY_EMIT_ENABLE_INLINE_THUMB)
26992707
emit_inline_asm_t *emit_inline_thumb = NULL;
2708+
#endif
27002709
for (scope_t *s = comp->scope_head; s != NULL; s = s->next) {
2701-
if (s->emit_options == EMIT_OPT_ASM_THUMB) {
2710+
if (false) {
2711+
// dummy
2712+
2713+
#if defined(MICROPY_EMIT_ENABLE_INLINE_THUMB)
2714+
} else if (s->emit_options == EMIT_OPT_ASM_THUMB) {
2715+
// inline assembly for thumb
27022716
if (emit_inline_thumb == NULL) {
27032717
emit_inline_thumb = emit_inline_thumb_new(max_num_labels);
27042718
}
@@ -2708,15 +2722,31 @@ void py_compile(py_parse_node_t pn) {
27082722
comp->emit_inline_asm_method_table = &emit_inline_thumb_method_table;
27092723
compile_scope_inline_asm(comp, s, PASS_2);
27102724
compile_scope_inline_asm(comp, s, PASS_3);
2725+
#endif
2726+
27112727
} else {
2728+
2729+
// choose the emit type
2730+
2731+
#if defined(MICROPY_EMIT_ENABLE_CPYTHON)
2732+
comp->emit = emit_cpython_new(max_num_labels);
2733+
comp->emit_method_table = &emit_cpython_method_table;
2734+
#else
27122735
switch (s->emit_options) {
27132736
case EMIT_OPT_NATIVE_PYTHON:
27142737
case EMIT_OPT_VIPER:
2738+
#if defined(MICROPY_EMIT_ENABLE_X64)
27152739
if (emit_native == NULL) {
27162740
emit_native = emit_native_x64_new(max_num_labels);
27172741
}
2718-
comp->emit = emit_native;
27192742
comp->emit_method_table = &emit_native_x64_method_table;
2743+
#elif defined(MICROPY_EMIT_ENABLE_THUMB)
2744+
if (emit_native == NULL) {
2745+
emit_native = emit_native_thumb_new(max_num_labels);
2746+
}
2747+
comp->emit_method_table = &emit_native_thumb_method_table;
2748+
#endif
2749+
comp->emit = emit_native;
27202750
comp->emit_method_table->set_native_types(comp->emit, s->emit_options == EMIT_OPT_VIPER);
27212751
break;
27222752

@@ -2728,8 +2758,9 @@ void py_compile(py_parse_node_t pn) {
27282758
comp->emit_method_table = &emit_bc_method_table;
27292759
break;
27302760
}
2731-
//comp->emit = emit_cpython_new(max_num_labels);
2732-
//comp->emit_method_table = &emit_cpython_method_table;
2761+
#endif
2762+
2763+
// compile pass 2 and pass 3
27332764
compile_scope(comp, s, PASS_2);
27342765
compile_scope(comp, s, PASS_3);
27352766
}

py/emitbc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include <assert.h>
77

88
#include "misc.h"
9+
#include "mpyconfig.h"
910
#include "lexer.h"
10-
#include "machine.h"
1111
#include "parse.h"
1212
#include "compile.h"
1313
#include "scope.h"

py/emitcommon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include <assert.h>
66

77
#include "misc.h"
8+
#include "mpyconfig.h"
89
#include "lexer.h"
9-
#include "machine.h"
1010
#include "parse.h"
1111
#include "scope.h"
1212
#include "runtime.h"

py/emitcpy.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
#include <assert.h>
77

88
#include "misc.h"
9+
#include "mpyconfig.h"
910
#include "lexer.h"
10-
#include "machine.h"
1111
#include "parse.h"
1212
#include "compile.h"
1313
#include "scope.h"
1414
#include "runtime.h"
1515
#include "emit.h"
1616

17-
#ifdef EMIT_ENABLE_CPY
17+
#ifdef MICROPY_EMIT_ENABLE_CPYTHON
1818

1919
struct _emit_t {
2020
int pass;
@@ -925,4 +925,4 @@ const emit_method_table_t emit_cpython_method_table = {
925925
emit_cpy_yield_from,
926926
};
927927

928-
#endif // EMIT_ENABLE_CPY
928+
#endif // MICROPY_EMIT_ENABLE_CPYTHON

py/emitinlinethumb.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
#include <assert.h>
77

88
#include "misc.h"
9+
#include "mpyconfig.h"
910
#include "lexer.h"
10-
#include "machine.h"
1111
#include "parse.h"
1212
#include "scope.h"
1313
#include "runtime.h"
1414
#include "emit.h"
1515
#include "asmthumb.h"
1616

17-
#ifdef EMIT_ENABLE_THUMB
17+
#ifdef MICROPY_EMIT_ENABLE_INLINE_THUMB
1818

1919
struct _emit_inline_asm_t {
2020
int pass;
@@ -204,4 +204,4 @@ const emit_inline_asm_method_table_t emit_inline_thumb_method_table = {
204204
emit_inline_thumb_op,
205205
};
206206

207-
#endif // EMIT_ENABLE_THUMB
207+
#endif // MICROPY_EMIT_ENABLE_INLINE_THUMB

py/emitnative.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,13 @@
2424
#include <assert.h>
2525

2626
#include "misc.h"
27+
#include "mpyconfig.h"
2728
#include "lexer.h"
28-
#include "machine.h"
2929
#include "parse.h"
3030
#include "scope.h"
3131
#include "runtime.h"
3232
#include "emit.h"
3333

34-
// select a machine architecture
35-
#if 0
36-
#if defined(EMIT_ENABLE_NATIVE_X64)
37-
#define N_X64
38-
#elif defined(EMIT_ENABLE_NATIVE_THUMB)
39-
#define N_THUMB
40-
#endif
41-
#endif
42-
4334
// wrapper around everything in this file
4435
#if defined(N_X64) || defined(N_THUMB)
4536

py/emitpass1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include <assert.h>
77

88
#include "misc.h"
9+
#include "mpyconfig.h"
910
#include "lexer.h"
10-
#include "machine.h"
1111
#include "parse.h"
1212
#include "compile.h"
1313
#include "scope.h"

0 commit comments

Comments
 (0)