Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | * |
| 4 | * The MIT License (MIT) |
| 5 | * |
| 6 | * Copyright (c) 2013-2016 Damien P. George |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | * of this software and associated documentation files (the "Software"), to deal |
| 10 | * in the Software without restriction, including without limitation the rights |
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | * copies of the Software, and to permit persons to whom the Software is |
| 13 | * furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | * THE SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | #include <stdio.h> |
| 28 | #include <string.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <unistd.h> |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 31 | |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 32 | #include "py/compile.h" |
Damien George | 85ae17c | 2016-11-16 20:25:36 +1100 | [diff] [blame] | 33 | #include "py/persistentcode.h" |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 34 | #include "py/runtime.h" |
| 35 | #include "py/gc.h" |
| 36 | #include "py/stackctrl.h" |
Damien George | 7e90e22 | 2019-05-02 09:59:21 +1000 | [diff] [blame] | 37 | #include "genhdr/mpversion.h" |
stijn | 9bdb82e | 2016-07-22 11:54:26 +0200 | [diff] [blame] | 38 | #ifdef _WIN32 |
Damien George | 4a93801 | 2017-09-06 14:09:13 +1000 | [diff] [blame] | 39 | #include "ports/windows/fmode.h" |
stijn | 9bdb82e | 2016-07-22 11:54:26 +0200 | [diff] [blame] | 40 | #endif |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 41 | |
| 42 | // Command line options, with their defaults |
| 43 | STATIC uint emit_opt = MP_EMIT_OPT_NONE; |
| 44 | mp_uint_t mp_verbose_flag = 0; |
| 45 | |
| 46 | // Heap size of GC heap (if enabled) |
| 47 | // Make it larger on a 64 bit machine, because pointers are larger. |
Damien George | 69661f3 | 2020-02-27 15:36:53 +1100 | [diff] [blame^] | 48 | long heap_size = 1024 * 1024 * (sizeof(mp_uint_t) / 4); |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 49 | |
| 50 | STATIC void stderr_print_strn(void *env, const char *str, mp_uint_t len) { |
| 51 | (void)env; |
| 52 | ssize_t dummy = write(STDERR_FILENO, str, len); |
| 53 | (void)dummy; |
| 54 | } |
| 55 | |
| 56 | STATIC const mp_print_t mp_stderr_print = {NULL, stderr_print_strn}; |
| 57 | |
Damien George | 74fb4e7 | 2016-05-23 13:25:54 +0100 | [diff] [blame] | 58 | STATIC int compile_and_save(const char *file, const char *output_file, const char *source_file) { |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 59 | nlr_buf_t nlr; |
| 60 | if (nlr_push(&nlr) == 0) { |
Damien George | 9714200 | 2017-03-14 11:43:28 +1100 | [diff] [blame] | 61 | mp_lexer_t *lex = mp_lexer_new_from_file(file); |
| 62 | |
Damien George | 74fb4e7 | 2016-05-23 13:25:54 +0100 | [diff] [blame] | 63 | qstr source_name; |
| 64 | if (source_file == NULL) { |
| 65 | source_name = lex->source_name; |
| 66 | } else { |
| 67 | source_name = qstr_from_str(source_file); |
| 68 | } |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 69 | |
| 70 | #if MICROPY_PY___FILE__ |
Damien George | 1556af1 | 2019-03-26 18:19:21 +1100 | [diff] [blame] | 71 | mp_store_global(MP_QSTR___file__, MP_OBJ_NEW_QSTR(source_name)); |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 72 | #endif |
| 73 | |
| 74 | mp_parse_tree_t parse_tree = mp_parse(lex, MP_PARSE_FILE_INPUT); |
Damien George | af20c2e | 2019-08-23 11:20:50 +1000 | [diff] [blame] | 75 | mp_raw_code_t *rc = mp_compile_to_raw_code(&parse_tree, source_name, false); |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 76 | |
| 77 | vstr_t vstr; |
| 78 | vstr_init(&vstr, 16); |
| 79 | if (output_file == NULL) { |
| 80 | vstr_add_str(&vstr, file); |
| 81 | vstr_cut_tail_bytes(&vstr, 2); |
| 82 | vstr_add_str(&vstr, "mpy"); |
| 83 | } else { |
| 84 | vstr_add_str(&vstr, output_file); |
| 85 | } |
| 86 | mp_raw_code_save_file(rc, vstr_null_terminated_str(&vstr)); |
| 87 | vstr_clear(&vstr); |
| 88 | |
| 89 | nlr_pop(); |
| 90 | return 0; |
| 91 | } else { |
| 92 | // uncaught exception |
| 93 | mp_obj_print_exception(&mp_stderr_print, (mp_obj_t)nlr.ret_val); |
| 94 | return 1; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | STATIC int usage(char **argv) { |
| 99 | printf( |
Damien George | 69661f3 | 2020-02-27 15:36:53 +1100 | [diff] [blame^] | 100 | "usage: %s [<opts>] [-X <implopt>] <input filename>\n" |
| 101 | "Options:\n" |
| 102 | "--version : show version information\n" |
| 103 | "-o : output file for compiled bytecode (defaults to input with .mpy extension)\n" |
| 104 | "-s : source filename to embed in the compiled bytecode (defaults to input file)\n" |
| 105 | "-v : verbose (trace various operations); can be multiple\n" |
| 106 | "-O[N] : apply bytecode optimizations of level N\n" |
| 107 | "\n" |
| 108 | "Target specific options:\n" |
| 109 | "-msmall-int-bits=number : set the maximum bits used to encode a small-int\n" |
| 110 | "-mno-unicode : don't support unicode in compiled strings\n" |
| 111 | "-mcache-lookup-bc : cache map lookups in the bytecode\n" |
| 112 | "-march=<arch> : set architecture for native emitter; x86, x64, armv6, armv7m, armv7em, armv7emsp, armv7emdp, xtensa, xtensawin\n" |
| 113 | "\n" |
| 114 | "Implementation specific options:\n", argv[0] |
| 115 | ); |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 116 | int impl_opts_cnt = 0; |
| 117 | printf( |
Damien George | 69661f3 | 2020-02-27 15:36:53 +1100 | [diff] [blame^] | 118 | #if MICROPY_EMIT_NATIVE |
| 119 | " emit={bytecode,native,viper} -- set the default code emitter\n" |
| 120 | #else |
| 121 | " emit=bytecode -- set the default code emitter\n" |
| 122 | #endif |
| 123 | ); |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 124 | impl_opts_cnt++; |
| 125 | printf( |
Damien George | 69661f3 | 2020-02-27 15:36:53 +1100 | [diff] [blame^] | 126 | " heapsize=<n> -- set the heap size for the GC (default %ld)\n" |
| 127 | , heap_size); |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 128 | impl_opts_cnt++; |
| 129 | |
| 130 | if (impl_opts_cnt == 0) { |
| 131 | printf(" (none)\n"); |
| 132 | } |
| 133 | |
| 134 | return 1; |
| 135 | } |
| 136 | |
| 137 | // Process options which set interpreter init options |
| 138 | STATIC void pre_process_options(int argc, char **argv) { |
| 139 | for (int a = 1; a < argc; a++) { |
| 140 | if (argv[a][0] == '-') { |
| 141 | if (strcmp(argv[a], "-X") == 0) { |
| 142 | if (a + 1 >= argc) { |
| 143 | exit(usage(argv)); |
| 144 | } |
| 145 | if (strcmp(argv[a + 1], "emit=bytecode") == 0) { |
| 146 | emit_opt = MP_EMIT_OPT_BYTECODE; |
Damien George | 8e3e057 | 2019-08-23 11:09:34 +1000 | [diff] [blame] | 147 | #if MICROPY_EMIT_NATIVE |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 148 | } else if (strcmp(argv[a + 1], "emit=native") == 0) { |
| 149 | emit_opt = MP_EMIT_OPT_NATIVE_PYTHON; |
| 150 | } else if (strcmp(argv[a + 1], "emit=viper") == 0) { |
| 151 | emit_opt = MP_EMIT_OPT_VIPER; |
Damien George | 8e3e057 | 2019-08-23 11:09:34 +1000 | [diff] [blame] | 152 | #endif |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 153 | } else if (strncmp(argv[a + 1], "heapsize=", sizeof("heapsize=") - 1) == 0) { |
| 154 | char *end; |
| 155 | heap_size = strtol(argv[a + 1] + sizeof("heapsize=") - 1, &end, 0); |
| 156 | // Don't bring unneeded libc dependencies like tolower() |
| 157 | // If there's 'w' immediately after number, adjust it for |
| 158 | // target word size. Note that it should be *before* size |
| 159 | // suffix like K or M, to avoid confusion with kilowords, |
| 160 | // etc. the size is still in bytes, just can be adjusted |
| 161 | // for word size (taking 32bit as baseline). |
| 162 | bool word_adjust = false; |
| 163 | if ((*end | 0x20) == 'w') { |
| 164 | word_adjust = true; |
| 165 | end++; |
| 166 | } |
| 167 | if ((*end | 0x20) == 'k') { |
| 168 | heap_size *= 1024; |
| 169 | } else if ((*end | 0x20) == 'm') { |
| 170 | heap_size *= 1024 * 1024; |
| 171 | } |
| 172 | if (word_adjust) { |
| 173 | heap_size = heap_size * BYTES_PER_WORD / 4; |
| 174 | } |
| 175 | } else { |
| 176 | exit(usage(argv)); |
| 177 | } |
| 178 | a++; |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | MP_NOINLINE int main_(int argc, char **argv) { |
| 185 | mp_stack_set_limit(40000 * (BYTES_PER_WORD / 4)); |
| 186 | |
| 187 | pre_process_options(argc, argv); |
| 188 | |
| 189 | char *heap = malloc(heap_size); |
| 190 | gc_init(heap, heap + heap_size); |
| 191 | |
| 192 | mp_init(); |
Damien George | 69661f3 | 2020-02-27 15:36:53 +1100 | [diff] [blame^] | 193 | #ifdef _WIN32 |
stijn | 9bdb82e | 2016-07-22 11:54:26 +0200 | [diff] [blame] | 194 | set_fmode_binary(); |
Damien George | 69661f3 | 2020-02-27 15:36:53 +1100 | [diff] [blame^] | 195 | #endif |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 196 | mp_obj_list_init(mp_sys_path, 0); |
| 197 | mp_obj_list_init(mp_sys_argv, 0); |
| 198 | |
Damien George | af20c2e | 2019-08-23 11:20:50 +1000 | [diff] [blame] | 199 | #if MICROPY_EMIT_NATIVE |
| 200 | // Set default emitter options |
| 201 | MP_STATE_VM(default_emit_opt) = emit_opt; |
| 202 | #else |
| 203 | (void)emit_opt; |
| 204 | #endif |
| 205 | |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 206 | // set default compiler configuration |
| 207 | mp_dynamic_compiler.small_int_bits = 31; |
| 208 | mp_dynamic_compiler.opt_cache_map_lookup_in_bytecode = 0; |
| 209 | mp_dynamic_compiler.py_builtins_str_unicode = 1; |
Damien George | 9c9bc65 | 2019-03-09 10:59:57 +1100 | [diff] [blame] | 210 | #if defined(__i386__) |
| 211 | mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_X86; |
Damien George | b596638 | 2019-09-18 13:45:20 +1000 | [diff] [blame] | 212 | mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_X86; |
Damien George | 9c9bc65 | 2019-03-09 10:59:57 +1100 | [diff] [blame] | 213 | #elif defined(__x86_64__) |
| 214 | mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_X64; |
Damien George | b596638 | 2019-09-18 13:45:20 +1000 | [diff] [blame] | 215 | mp_dynamic_compiler.nlr_buf_num_regs = MAX(MICROPY_NLR_NUM_REGS_X64, MICROPY_NLR_NUM_REGS_X64_WIN); |
Damien George | e70c438 | 2019-05-01 15:31:00 +1000 | [diff] [blame] | 216 | #elif defined(__arm__) && !defined(__thumb2__) |
| 217 | mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_ARMV6; |
Damien George | b596638 | 2019-09-18 13:45:20 +1000 | [diff] [blame] | 218 | mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_ARM_THUMB_FP; |
Damien George | 9c9bc65 | 2019-03-09 10:59:57 +1100 | [diff] [blame] | 219 | #else |
| 220 | mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_NONE; |
Damien George | b596638 | 2019-09-18 13:45:20 +1000 | [diff] [blame] | 221 | mp_dynamic_compiler.nlr_buf_num_regs = 0; |
Damien George | 9c9bc65 | 2019-03-09 10:59:57 +1100 | [diff] [blame] | 222 | #endif |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 223 | |
| 224 | const char *input_file = NULL; |
| 225 | const char *output_file = NULL; |
Damien George | 74fb4e7 | 2016-05-23 13:25:54 +0100 | [diff] [blame] | 226 | const char *source_file = NULL; |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 227 | |
| 228 | // parse main options |
| 229 | for (int a = 1; a < argc; a++) { |
| 230 | if (argv[a][0] == '-') { |
| 231 | if (strcmp(argv[a], "-X") == 0) { |
| 232 | a += 1; |
Damien George | 7e90e22 | 2019-05-02 09:59:21 +1000 | [diff] [blame] | 233 | } else if (strcmp(argv[a], "--version") == 0) { |
| 234 | printf("MicroPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE |
| 235 | "; mpy-cross emitting mpy v" MP_STRINGIFY(MPY_VERSION) "\n"); |
| 236 | return 0; |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 237 | } else if (strcmp(argv[a], "-v") == 0) { |
| 238 | mp_verbose_flag++; |
| 239 | } else if (strncmp(argv[a], "-O", 2) == 0) { |
| 240 | if (unichar_isdigit(argv[a][2])) { |
| 241 | MP_STATE_VM(mp_optimise_value) = argv[a][2] & 0xf; |
| 242 | } else { |
| 243 | MP_STATE_VM(mp_optimise_value) = 0; |
Damien George | 69661f3 | 2020-02-27 15:36:53 +1100 | [diff] [blame^] | 244 | for (char *p = argv[a] + 1; *p && *p == 'O'; p++, MP_STATE_VM(mp_optimise_value)++) {; |
| 245 | } |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 246 | } |
| 247 | } else if (strcmp(argv[a], "-o") == 0) { |
| 248 | if (a + 1 >= argc) { |
| 249 | exit(usage(argv)); |
| 250 | } |
| 251 | a += 1; |
| 252 | output_file = argv[a]; |
Damien George | 74fb4e7 | 2016-05-23 13:25:54 +0100 | [diff] [blame] | 253 | } else if (strcmp(argv[a], "-s") == 0) { |
| 254 | if (a + 1 >= argc) { |
| 255 | exit(usage(argv)); |
| 256 | } |
| 257 | a += 1; |
| 258 | source_file = argv[a]; |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 259 | } else if (strncmp(argv[a], "-msmall-int-bits=", sizeof("-msmall-int-bits=") - 1) == 0) { |
| 260 | char *end; |
| 261 | mp_dynamic_compiler.small_int_bits = |
| 262 | strtol(argv[a] + sizeof("-msmall-int-bits=") - 1, &end, 0); |
| 263 | if (*end) { |
| 264 | return usage(argv); |
| 265 | } |
| 266 | // TODO check that small_int_bits is within range of host's capabilities |
| 267 | } else if (strcmp(argv[a], "-mno-cache-lookup-bc") == 0) { |
| 268 | mp_dynamic_compiler.opt_cache_map_lookup_in_bytecode = 0; |
| 269 | } else if (strcmp(argv[a], "-mcache-lookup-bc") == 0) { |
| 270 | mp_dynamic_compiler.opt_cache_map_lookup_in_bytecode = 1; |
| 271 | } else if (strcmp(argv[a], "-mno-unicode") == 0) { |
| 272 | mp_dynamic_compiler.py_builtins_str_unicode = 0; |
| 273 | } else if (strcmp(argv[a], "-municode") == 0) { |
| 274 | mp_dynamic_compiler.py_builtins_str_unicode = 1; |
Damien George | 9c9bc65 | 2019-03-09 10:59:57 +1100 | [diff] [blame] | 275 | } else if (strncmp(argv[a], "-march=", sizeof("-march=") - 1) == 0) { |
| 276 | const char *arch = argv[a] + sizeof("-march=") - 1; |
| 277 | if (strcmp(arch, "x86") == 0) { |
| 278 | mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_X86; |
Damien George | b596638 | 2019-09-18 13:45:20 +1000 | [diff] [blame] | 279 | mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_X86; |
Damien George | 9c9bc65 | 2019-03-09 10:59:57 +1100 | [diff] [blame] | 280 | } else if (strcmp(arch, "x64") == 0) { |
| 281 | mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_X64; |
Damien George | b596638 | 2019-09-18 13:45:20 +1000 | [diff] [blame] | 282 | mp_dynamic_compiler.nlr_buf_num_regs = MAX(MICROPY_NLR_NUM_REGS_X64, MICROPY_NLR_NUM_REGS_X64_WIN); |
Damien George | 9c9bc65 | 2019-03-09 10:59:57 +1100 | [diff] [blame] | 283 | } else if (strcmp(arch, "armv6") == 0) { |
| 284 | mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_ARMV6; |
Damien George | b596638 | 2019-09-18 13:45:20 +1000 | [diff] [blame] | 285 | mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_ARM_THUMB_FP; |
Damien George | 9c9bc65 | 2019-03-09 10:59:57 +1100 | [diff] [blame] | 286 | } else if (strcmp(arch, "armv7m") == 0) { |
| 287 | mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_ARMV7M; |
Damien George | b596638 | 2019-09-18 13:45:20 +1000 | [diff] [blame] | 288 | mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_ARM_THUMB_FP; |
Damien George | 82a19cb | 2019-12-03 12:32:29 +1100 | [diff] [blame] | 289 | } else if (strcmp(arch, "armv7em") == 0) { |
| 290 | mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_ARMV7EM; |
| 291 | mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_ARM_THUMB_FP; |
| 292 | } else if (strcmp(arch, "armv7emsp") == 0) { |
| 293 | mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_ARMV7EMSP; |
| 294 | mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_ARM_THUMB_FP; |
| 295 | } else if (strcmp(arch, "armv7emdp") == 0) { |
| 296 | mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_ARMV7EMDP; |
| 297 | mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_ARM_THUMB_FP; |
Damien George | 9c9bc65 | 2019-03-09 10:59:57 +1100 | [diff] [blame] | 298 | } else if (strcmp(arch, "xtensa") == 0) { |
| 299 | mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_XTENSA; |
Damien George | b596638 | 2019-09-18 13:45:20 +1000 | [diff] [blame] | 300 | mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_XTENSA; |
Damien George | 1d21b4e | 2019-09-13 13:16:00 +1000 | [diff] [blame] | 301 | } else if (strcmp(arch, "xtensawin") == 0) { |
| 302 | mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_XTENSAWIN; |
| 303 | mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_XTENSAWIN; |
Damien George | 9c9bc65 | 2019-03-09 10:59:57 +1100 | [diff] [blame] | 304 | } else { |
| 305 | return usage(argv); |
| 306 | } |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 307 | } else { |
| 308 | return usage(argv); |
| 309 | } |
| 310 | } else { |
| 311 | if (input_file != NULL) { |
| 312 | mp_printf(&mp_stderr_print, "multiple input files\n"); |
| 313 | exit(1); |
| 314 | } |
| 315 | input_file = argv[a]; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | if (input_file == NULL) { |
| 320 | mp_printf(&mp_stderr_print, "no input file\n"); |
| 321 | exit(1); |
| 322 | } |
| 323 | |
Damien George | 74fb4e7 | 2016-05-23 13:25:54 +0100 | [diff] [blame] | 324 | int ret = compile_and_save(input_file, output_file, source_file); |
Damien George | 56f76b8 | 2016-02-11 22:37:26 +0000 | [diff] [blame] | 325 | |
| 326 | #if MICROPY_PY_MICROPYTHON_MEM_INFO |
| 327 | if (mp_verbose_flag) { |
| 328 | mp_micropython_mem_info(0, NULL); |
| 329 | } |
| 330 | #endif |
| 331 | |
| 332 | mp_deinit(); |
| 333 | |
| 334 | return ret & 0xff; |
| 335 | } |
| 336 | |
| 337 | int main(int argc, char **argv) { |
| 338 | mp_stack_ctrl_init(); |
| 339 | return main_(argc, argv); |
| 340 | } |
| 341 | |
| 342 | uint mp_import_stat(const char *path) { |
| 343 | (void)path; |
| 344 | return MP_IMPORT_STAT_NO_EXIST; |
| 345 | } |
| 346 | |
| 347 | void nlr_jump_fail(void *val) { |
| 348 | printf("FATAL: uncaught NLR %p\n", val); |
| 349 | exit(1); |
| 350 | } |