Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 4c95526

Browse files
geza-pycomiwahdan88
authored and
iwahdan88
committed
Updating mpy-cross folder
1 parent 150d353 commit 4c95526

File tree

5 files changed

+50
-21
lines changed

5 files changed

+50
-21
lines changed

mpy-cross/Makefile

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ ifneq ($(findstring undefine,$(.FEATURES)),)
55
override undefine COPT
66
override undefine CFLAGS_EXTRA
77
override undefine LDFLAGS_EXTRA
8+
override undefine MICROPY_FORCE_32BIT
9+
override undefine CROSS_COMPILE
810
override undefine FROZEN_DIR
911
override undefine FROZEN_MPY_DIR
12+
override undefine USER_C_MODULES
13+
override undefine SRC_MOD
1014
override undefine BUILD
1115
override undefine PROG
1216
endif
@@ -25,9 +29,9 @@ UNAME_S := $(shell uname -s)
2529
# include py core make definitions
2630
include $(TOP)/py/py.mk
2731

28-
INC += -I.
29-
INC += -I$(TOP)
32+
INC += -I.
3033
INC += -I$(BUILD)
34+
INC += -I$(TOP)
3135

3236
# compiler settings
3337
CWARN = -Wall -Werror
@@ -68,7 +72,7 @@ ifneq (,$(findstring mingw,$(COMPILER_TARGET)))
6872
SRC_C += ports/windows/fmode.c
6973
endif
7074

71-
OBJ = $(PY_O)
75+
OBJ = $(PY_CORE_O)
7276
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
7377

7478
include $(TOP)/py/mkrules.mk

mpy-cross/gccollect.c

-3
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,6 @@ void gc_collect(void) {
143143
// GC stack (and regs because we captured them)
144144
void **regs_ptr = (void**)(void*)&regs;
145145
gc_collect_root(regs_ptr, ((mp_uint_t)MP_STATE_THREAD(stack_top) - (mp_uint_t)&regs) / sizeof(mp_uint_t));
146-
#if MICROPY_EMIT_NATIVE
147-
mp_unix_mark_exec();
148-
#endif
149146
gc_collect_end();
150147
}
151148

mpy-cross/main.c

+32-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "py/runtime.h"
3535
#include "py/gc.h"
3636
#include "py/stackctrl.h"
37+
#include "genhdr/mpversion.h"
3738
#ifdef _WIN32
3839
#include "ports/windows/fmode.h"
3940
#endif
@@ -67,9 +68,7 @@ STATIC int compile_and_save(const char *file, const char *output_file, const cha
6768
}
6869

6970
#if MICROPY_PY___FILE__
70-
if (input_kind == MP_PARSE_FILE_INPUT) {
71-
mp_store_global(MP_QSTR___file__, MP_OBJ_NEW_QSTR(source_name));
72-
}
71+
mp_store_global(MP_QSTR___file__, MP_OBJ_NEW_QSTR(source_name));
7372
#endif
7473

7574
mp_parse_tree_t parse_tree = mp_parse(lex, MP_PARSE_FILE_INPUT);
@@ -100,6 +99,7 @@ STATIC int usage(char **argv) {
10099
printf(
101100
"usage: %s [<opts>] [-X <implopt>] <input filename>\n"
102101
"Options:\n"
102+
"--version : show version information\n"
103103
"-o : output file for compiled bytecode (defaults to input with .mpy extension)\n"
104104
"-s : source filename to embed in the compiled bytecode (defaults to input file)\n"
105105
"-v : verbose (trace various operations); can be multiple\n"
@@ -109,6 +109,7 @@ STATIC int usage(char **argv) {
109109
"-msmall-int-bits=number : set the maximum bits used to encode a small-int\n"
110110
"-mno-unicode : don't support unicode in compiled strings\n"
111111
"-mcache-lookup-bc : cache map lookups in the bytecode\n"
112+
"-march=<arch> : set architecture for native emitter; x86, x64, armv6, armv7m, xtensa\n"
112113
"\n"
113114
"Implementation specific options:\n", argv[0]
114115
);
@@ -193,6 +194,15 @@ MP_NOINLINE int main_(int argc, char **argv) {
193194
mp_dynamic_compiler.small_int_bits = 31;
194195
mp_dynamic_compiler.opt_cache_map_lookup_in_bytecode = 0;
195196
mp_dynamic_compiler.py_builtins_str_unicode = 1;
197+
#if defined(__i386__)
198+
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_X86;
199+
#elif defined(__x86_64__)
200+
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_X64;
201+
#elif defined(__arm__) && !defined(__thumb2__)
202+
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_ARMV6;
203+
#else
204+
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_NONE;
205+
#endif
196206

197207
const char *input_file = NULL;
198208
const char *output_file = NULL;
@@ -203,6 +213,10 @@ MP_NOINLINE int main_(int argc, char **argv) {
203213
if (argv[a][0] == '-') {
204214
if (strcmp(argv[a], "-X") == 0) {
205215
a += 1;
216+
} else if (strcmp(argv[a], "--version") == 0) {
217+
printf("MicroPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE
218+
"; mpy-cross emitting mpy v" MP_STRINGIFY(MPY_VERSION) "\n");
219+
return 0;
206220
} else if (strcmp(argv[a], "-v") == 0) {
207221
mp_verbose_flag++;
208222
} else if (strncmp(argv[a], "-O", 2) == 0) {
@@ -240,6 +254,21 @@ MP_NOINLINE int main_(int argc, char **argv) {
240254
mp_dynamic_compiler.py_builtins_str_unicode = 0;
241255
} else if (strcmp(argv[a], "-municode") == 0) {
242256
mp_dynamic_compiler.py_builtins_str_unicode = 1;
257+
} else if (strncmp(argv[a], "-march=", sizeof("-march=") - 1) == 0) {
258+
const char *arch = argv[a] + sizeof("-march=") - 1;
259+
if (strcmp(arch, "x86") == 0) {
260+
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_X86;
261+
} else if (strcmp(arch, "x64") == 0) {
262+
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_X64;
263+
} else if (strcmp(arch, "armv6") == 0) {
264+
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_ARMV6;
265+
} else if (strcmp(arch, "armv7m") == 0) {
266+
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_ARMV7M;
267+
} else if (strcmp(arch, "xtensa") == 0) {
268+
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_XTENSA;
269+
} else {
270+
return usage(argv);
271+
}
243272
} else {
244273
return usage(argv);
245274
}

mpy-cross/mpconfigport.h

+9-11
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
#define MICROPY_PERSISTENT_CODE_LOAD (0)
3131
#define MICROPY_PERSISTENT_CODE_SAVE (1)
3232

33-
#define MICROPY_EMIT_X64 (0)
34-
#define MICROPY_EMIT_X86 (0)
35-
#define MICROPY_EMIT_THUMB (0)
36-
#define MICROPY_EMIT_INLINE_THUMB (0)
37-
#define MICROPY_EMIT_INLINE_THUMB_ARMV7M (0)
38-
#define MICROPY_EMIT_INLINE_THUMB_FLOAT (0)
39-
#define MICROPY_EMIT_ARM (0)
33+
#define MICROPY_EMIT_X64 (1)
34+
#define MICROPY_EMIT_X86 (1)
35+
#define MICROPY_EMIT_THUMB (1)
36+
#define MICROPY_EMIT_INLINE_THUMB (1)
37+
#define MICROPY_EMIT_INLINE_THUMB_ARMV7M (1)
38+
#define MICROPY_EMIT_INLINE_THUMB_FLOAT (1)
39+
#define MICROPY_EMIT_ARM (1)
40+
#define MICROPY_EMIT_XTENSA (1)
41+
#define MICROPY_EMIT_INLINE_XTENSA (1)
4042

4143
#define MICROPY_DYNAMIC_COMPILER (1)
4244
#define MICROPY_COMP_CONST_FOLDING (1)
@@ -110,10 +112,6 @@ typedef long mp_off_t;
110112

111113
#define MP_PLAT_PRINT_STRN(str, len) (void)0
112114

113-
#ifndef MP_NOINLINE
114-
#define MP_NOINLINE __attribute__((noinline))
115-
#endif
116-
117115
// We need to provide a declaration/definition of alloca()
118116
#ifdef __FreeBSD__
119117
#include <stdlib.h>

mpy-cross/mphalport.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
// empty file
1+
// prevent including extmod/virtpin.h
2+
#define mp_hal_pin_obj_t

0 commit comments

Comments
 (0)