34
34
#include "py/runtime.h"
35
35
#include "py/gc.h"
36
36
#include "py/stackctrl.h"
37
+ #include "genhdr/mpversion.h"
37
38
#ifdef _WIN32
38
39
#include "ports/windows/fmode.h"
39
40
#endif
@@ -67,9 +68,7 @@ STATIC int compile_and_save(const char *file, const char *output_file, const cha
67
68
}
68
69
69
70
#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 ));
73
72
#endif
74
73
75
74
mp_parse_tree_t parse_tree = mp_parse (lex , MP_PARSE_FILE_INPUT );
@@ -100,6 +99,7 @@ STATIC int usage(char **argv) {
100
99
printf (
101
100
"usage: %s [<opts>] [-X <implopt>] <input filename>\n"
102
101
"Options:\n"
102
+ "--version : show version information\n"
103
103
"-o : output file for compiled bytecode (defaults to input with .mpy extension)\n"
104
104
"-s : source filename to embed in the compiled bytecode (defaults to input file)\n"
105
105
"-v : verbose (trace various operations); can be multiple\n"
@@ -109,6 +109,7 @@ STATIC int usage(char **argv) {
109
109
"-msmall-int-bits=number : set the maximum bits used to encode a small-int\n"
110
110
"-mno-unicode : don't support unicode in compiled strings\n"
111
111
"-mcache-lookup-bc : cache map lookups in the bytecode\n"
112
+ "-march=<arch> : set architecture for native emitter; x86, x64, armv6, armv7m, xtensa\n"
112
113
"\n"
113
114
"Implementation specific options:\n" , argv [0 ]
114
115
);
@@ -193,6 +194,15 @@ MP_NOINLINE int main_(int argc, char **argv) {
193
194
mp_dynamic_compiler .small_int_bits = 31 ;
194
195
mp_dynamic_compiler .opt_cache_map_lookup_in_bytecode = 0 ;
195
196
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
196
206
197
207
const char * input_file = NULL ;
198
208
const char * output_file = NULL ;
@@ -203,6 +213,10 @@ MP_NOINLINE int main_(int argc, char **argv) {
203
213
if (argv [a ][0 ] == '-' ) {
204
214
if (strcmp (argv [a ], "-X" ) == 0 ) {
205
215
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 ;
206
220
} else if (strcmp (argv [a ], "-v" ) == 0 ) {
207
221
mp_verbose_flag ++ ;
208
222
} else if (strncmp (argv [a ], "-O" , 2 ) == 0 ) {
@@ -240,6 +254,21 @@ MP_NOINLINE int main_(int argc, char **argv) {
240
254
mp_dynamic_compiler .py_builtins_str_unicode = 0 ;
241
255
} else if (strcmp (argv [a ], "-municode" ) == 0 ) {
242
256
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
+ }
243
272
} else {
244
273
return usage (argv );
245
274
}
0 commit comments