diff options
author | Jan Čapek <jan.capek@braiins.cz> | 2016-03-10 09:22:41 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-04-16 13:18:09 +0100 |
commit | d76c65f599b77aa275eda3d2248cde16f6be7e10 (patch) | |
tree | 4d5b53d2bd8189d8bbeb280fbdf7c55ef1c9cafc /py | |
parent | dbbf0827862d2e300827468020c6c558b7934276 (diff) | |
download | micropython-d76c65f599b77aa275eda3d2248cde16f6be7e10.tar.gz micropython-d76c65f599b77aa275eda3d2248cde16f6be7e10.zip |
py: Add rules for automated extraction of qstrs from sources.
- add template rule that converts a specified source file into a qstring file
- add special rule for generating a central header that contains all
extracted/autogenerated strings - defined by QSTR_DEFS_COLLECTED
variable. Each platform appends a list of sources that may contain
qstrings into a new build variable: SRC_QSTR. Any autogenerated
prerequisities are should be appened to SRC_QSTR_AUTO_DEPS variable.
- remove most qstrings from py/qstrdefs, keep only qstrings that
contain special characters - these cannot be easily detected in the
sources without additional annotations
- remove most manual qstrdefs, use qstrdef autogen for: py, cc3200,
stmhal, teensy, unix, windows, pic16bit:
- remove all micropython generic qstrdefs except for the special strings that contain special characters (e.g. /,+,<,> etc.)
- remove all port specific qstrdefs except for special strings
- append sources for qstr generation in platform makefiles (SRC_QSTR)
Diffstat (limited to 'py')
-rw-r--r-- | py/mkrules.mk | 28 | ||||
-rw-r--r-- | py/py.mk | 12 | ||||
-rw-r--r-- | py/qstrdefs.h | 762 |
3 files changed, 46 insertions, 756 deletions
diff --git a/py/mkrules.mk b/py/mkrules.mk index 9cbef1ac5a..eb4c48ecee 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -46,10 +46,30 @@ vpath %.c . $(TOP) $(BUILD)/%.o: %.c $(call compile_c) +# A empty qstrdefs header is needed to properly preprocess every file +EMPTY_QSTRDEFS_GENERATED_H = $(BUILD)/tmp/genhdr/qstrdefs.generated.h + +# List all native flags since the current build system doesn't have +# the micropython configuration available. However, these flags are +# needed to extract all qstrings +QSTR_GEN_EXTRA_CFLAGS += -DN_X64 -DN_X86 -DN_THUMB -DN_ARM +QSTR_GEN_EXTRA_CFLAGS += -I$(BUILD)/tmp + +vpath %.c . $(TOP) +$(HEADER_BUILD)/%.qstr: % | $(EMPTY_QSTRDEFS_GENERATED_H) $(HEADER_BUILD)/mpversion.h $(SRC_QSTR_AUTO_DEPS) + @mkdir -p $(dir $@); + $(Q)$(CPP) $(QSTR_GEN_EXTRA_CFLAGS) $(CFLAGS) $< -o - | $(PYTHON) $(PY_SRC)/makeqstrdefs.py -s -o $@ + + $(BUILD)/%.pp: %.c $(ECHO) "PreProcess $<" $(Q)$(CC) $(CFLAGS) -E -Wp,-C,-dD,-dI -o $@ $< +$(EMPTY_QSTRDEFS_GENERATED_H): + $(ECHO) "Generate empty $@ to satisfy qstr generator" + $(Q)mkdir -p $(dir $@) + $(Q)touch $@ + # The following rule uses | to create an order only prereuisite. Order only # prerequisites only get built if they don't exist. They don't cause timestamp # checking to be performed. @@ -61,6 +81,14 @@ $(BUILD)/%.pp: %.c # to get built before we try to compile any of them. $(OBJ): | $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/mpversion.h +# This rule joins all generated qstr files +$(QSTR_DEFS_COLLECTED): $(addprefix $(HEADER_BUILD)/,$(addsuffix .qstr,$(SRC_QSTR))) $(PY_SRC)/mpconfig.h + $(ECHO) "GEN $@" + $(Q)cat $^ > $@ + + +# + # $(sort $(var)) removes duplicates # # The net effect of this, is it causes the objects to depend on the @@ -7,6 +7,9 @@ HEADER_BUILD = $(BUILD)/genhdr # file containing qstr defs for the core Python bit PY_QSTR_DEFS = $(PY_SRC)/qstrdefs.h +# All collected qstr defs +QSTR_DEFS_COLLECTED = $(HEADER_BUILD)/qstrdefs.collected.h + # some code is performance bottleneck and compiled with other optimization options CSUPEROPT = -O3 @@ -184,6 +187,10 @@ PY_O_BASENAME = \ # prepend the build destination prefix to the py object files PY_O = $(addprefix $(PY_BUILD)/, $(PY_O_BASENAME)) +# Sources that may contain qstrings +SRC_QSTR_IGNORE = nlr% emitnx% emitnthumb% emitnarm% +SRC_QSTR = $(SRC_MOD) $(addprefix py/,$(filter-out $(SRC_QSTR_IGNORE),$(PY_O_BASENAME:.o=.c)) emitnative.c) + # Anything that depends on FORCE will be considered out-of-date FORCE: .PHONY: FORCE @@ -196,14 +203,13 @@ $(HEADER_BUILD)/mpversion.h: FORCE | $(HEADER_BUILD) MPCONFIGPORT_MK = $(wildcard mpconfigport.mk) # qstr data - # Adding an order only dependency on $(HEADER_BUILD) causes $(HEADER_BUILD) to get # created before we run the script to generate the .h # Note: we need to protect the qstr names from the preprocessor, so we wrap # the lines in "" and then unwrap after the preprocessor is finished. -$(HEADER_BUILD)/qstrdefs.generated.h: $(PY_QSTR_DEFS) $(QSTR_DEFS) $(PY_SRC)/makeqstrdata.py mpconfigport.h $(MPCONFIGPORT_MK) $(PY_SRC)/mpconfig.h | $(HEADER_BUILD) +$(HEADER_BUILD)/qstrdefs.generated.h: $(PY_QSTR_DEFS) $(QSTR_DEFS) $(QSTR_DEFS_COLLECTED) $(PY_SRC)/makeqstrdata.py mpconfigport.h $(MPCONFIGPORT_MK) $(PY_SRC)/mpconfig.h | $(HEADER_BUILD) $(ECHO) "GEN $@" - $(Q)cat $(PY_QSTR_DEFS) $(QSTR_DEFS) | $(SED) 's/^Q(.*)/"&"/' | $(CPP) $(CFLAGS) - | sed 's/^"\(Q(.*)\)"/\1/' > $(HEADER_BUILD)/qstrdefs.preprocessed.h + $(Q)cat $(PY_QSTR_DEFS) $(QSTR_DEFS) $(QSTR_DEFS_COLLECTED) | $(SED) 's/^Q(.*)/"&"/' | $(CPP) $(CFLAGS) - | sed 's/^"\(Q(.*)\)"/\1/' > $(HEADER_BUILD)/qstrdefs.preprocessed.h $(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ # emitters diff --git a/py/qstrdefs.h b/py/qstrdefs.h index a3b68832c6..c98a253a69 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -36,469 +36,11 @@ QCFG(BYTES_IN_HASH, MICROPY_QSTR_BYTES_IN_HASH) Q() Q(*) Q(_) -Q(__build_class__) -Q(__class__) -Q(__doc__) -Q(__import__) -Q(__init__) -Q(__new__) -Q(__locals__) -Q(__main__) -Q(__module__) -Q(__name__) -Q(__dict__) -Q(__hash__) -Q(__next__) -Q(__qualname__) -Q(__path__) -Q(__repl_print__) -#if MICROPY_PY___FILE__ -Q(__file__) -#endif - -Q(__bool__) -Q(__contains__) -Q(__enter__) -Q(__exit__) -Q(__len__) -Q(__iter__) -Q(__getitem__) -Q(__setitem__) -Q(__delitem__) -Q(__add__) -Q(__sub__) -Q(__repr__) -Q(__str__) -#if MICROPY_PY_DESCRIPTORS -Q(__get__) -Q(__set__) -Q(__delete__) -#endif -Q(__getattr__) -Q(__del__) -Q(__call__) -Q(__lt__) -Q(__gt__) -Q(__eq__) -Q(__le__) -Q(__ge__) -Q(__reversed__) -#if MICROPY_PY_ALL_SPECIAL_METHODS -Q(__mul__) -Q(__truediv__) -Q(__floordiv__) -Q(__iadd__) -Q(__isub__) -Q(__invert__) -Q(__neg__) -Q(__pos__) -#endif - -#if MICROPY_PY_ASYNC_AWAIT -Q(__aiter__) -Q(__anext__) -Q(__aenter__) -Q(__aexit__) -Q(StopAsyncIteration) -#endif - -Q(micropython) -Q(bytecode) -Q(const) - -#if MICROPY_EMIT_NATIVE -Q(native) -Q(viper) -Q(uint) -Q(ptr) -Q(ptr8) -Q(ptr16) -Q(ptr32) -#endif - -#if MICROPY_EMIT_INLINE_THUMB -Q(asm_thumb) -Q(label) -Q(align) -Q(data) -Q(uint) -Q(nop) -Q(mov) -Q(and_) -Q(cmp) -Q(add) -Q(sub) -Q(lsl) -Q(lsr) -Q(asr) -Q(ldr) -Q(ldrb) -Q(ldrh) -Q(str) -Q(strb) -Q(strh) -Q(b) -Q(bl) -Q(bx) -Q(push) -Q(pop) -Q(cpsid) -Q(cpsie) -Q(wfi) -Q(clz) -Q(rbit) -Q(movw) -Q(movt) -Q(movwt) -Q(mrs) -Q(sdiv) -Q(udiv) -Q(ldrex) -Q(strex) -#if MICROPY_EMIT_INLINE_THUMB_FLOAT -Q(vcmp) -Q(vneg) -Q(vcvt_f32_s32) -Q(vcvt_s32_f32) -Q(vsqrt) -Q(vmov) -Q(vmrs) -Q(vldr) -Q(vstr) -#endif -#endif - -Q(builtins) - -Q(Ellipsis) -Q(StopIteration) -#if MICROPY_PY_BUILTINS_NOTIMPLEMENTED -Q(NotImplemented) -#endif - -Q(BaseException) -Q(ArithmeticError) -Q(AssertionError) -Q(AttributeError) -Q(BufferError) -Q(EOFError) -Q(Exception) -Q(FileExistsError) -Q(FileNotFoundError) -Q(FloatingPointError) -Q(GeneratorExit) -Q(ImportError) -Q(IndentationError) -Q(IndexError) -Q(KeyboardInterrupt) -Q(KeyError) -Q(LookupError) -Q(MemoryError) -Q(NameError) -Q(NotImplementedError) -Q(OSError) -#if MICROPY_PY_BUILTINS_TIMEOUTERROR -Q(TimeoutError) -#endif -Q(OverflowError) -Q(RuntimeError) -Q(SyntaxError) -Q(SystemExit) -Q(TypeError) -Q(UnboundLocalError) -Q(ValueError) -#if MICROPY_EMIT_NATIVE -Q(ViperTypeError) -#endif -Q(ZeroDivisionError) -#if MICROPY_PY_BUILTINS_STR_UNICODE -Q(UnicodeError) -#endif - -Q(None) -Q(False) -Q(True) -Q(object) - -Q(NoneType) - -#if MICROPY_PY_COLLECTIONS_ORDEREDDICT -Q(OrderedDict) -#endif - -Q(abs) -Q(all) -Q(any) -Q(args) -#if MICROPY_PY_ARRAY -Q(array) -#endif -Q(bin) -Q({:#b}) -Q(bool) -#if MICROPY_PY_BUILTINS_BYTEARRAY -Q(bytearray) -#endif -#if MICROPY_PY_BUILTINS_MEMORYVIEW -Q(memoryview) -#endif -Q(bytes) -Q(callable) -Q(chr) -Q(classmethod) -Q(_collections) -#if MICROPY_PY_BUILTINS_COMPLEX -Q(complex) -Q(real) -Q(imag) -#endif -Q(dict) -Q(dir) -Q(divmod) -#if MICROPY_PY_BUILTINS_ENUMERATE -Q(enumerate) -#endif -Q(eval) -Q(exec) -#if MICROPY_PY_BUILTINS_EXECFILE -Q(execfile) -#endif -#if MICROPY_PY_BUILTINS_FILTER -Q(filter) -#endif -#if MICROPY_PY_BUILTINS_FLOAT -Q(float) -#endif -Q(from_bytes) -Q(getattr) -Q(setattr) -Q(globals) -Q(hasattr) -Q(hash) -Q(hex) -Q(%#x) -Q(id) -Q(int) -Q(isinstance) -Q(issubclass) -Q(iter) -Q(len) -Q(list) -Q(locals) -Q(map) -#if MICROPY_PY_BUILTINS_MIN_MAX -Q(max) -Q(min) -Q(default) -#endif -Q(namedtuple) -Q(next) -Q(oct) Q(%#o) -Q(open) -Q(ord) -Q(path) -Q(pow) -Q(print) -Q(range) -Q(read) -Q(repr) -Q(reversed) -Q(round) -Q(sorted) -Q(staticmethod) -Q(sum) -Q(super) -Q(str) -Q(sys) -Q(to_bytes) -Q(tuple) -Q(type) -Q(value) -Q(write) -Q(zip) - -#if MICROPY_PY_BUILTINS_COMPILE -Q(compile) -Q(code) -Q(single) -#endif - -Q(sep) -Q(end) - -#if MICROPY_PY_BUILTINS_RANGE_ATTRS -Q(step) -Q(stop) -#endif - -Q(clear) -Q(copy) -Q(fromkeys) -Q(get) -Q(items) -Q(keys) -Q(pop) -Q(popitem) -Q(setdefault) -Q(update) -Q(values) -Q(append) -Q(close) -Q(send) -Q(throw) -Q(count) -Q(extend) -Q(index) -Q(remove) -Q(insert) -Q(pop) -Q(sort) -Q(join) -Q(strip) -Q(lstrip) -Q(rstrip) -Q(format) -Q(key) -Q(reverse) -Q(add) -Q(clear) -Q(copy) -Q(pop) -Q(remove) -Q(find) -Q(rfind) -Q(rindex) -Q(split) -#if MICROPY_PY_BUILTINS_STR_SPLITLINES -Q(splitlines) -Q(keepends) +Q(%#x) +Q({:#b}) Q(\n) -#endif -Q(rsplit) -Q(startswith) -Q(endswith) -Q(replace) -Q(partition) -Q(rpartition) -Q(lower) -Q(upper) -Q(isspace) -Q(isalpha) -Q(isdigit) -Q(isupper) -Q(islower) -Q(iterable) -Q(start) - -Q(bound_method) -Q(closure) -Q(dict_view) -Q(function) -Q(generator) -Q(iterator) -Q(module) -Q(slice) - -#if MICROPY_PY_BUILTINS_SET -Q(discard) -Q(difference) -Q(difference_update) -Q(intersection) -Q(intersection_update) -Q(isdisjoint) -Q(issubset) -Q(issuperset) -Q(set) -Q(symmetric_difference) -Q(symmetric_difference_update) -Q(union) -Q(update) -#endif - -#if MICROPY_PY_BUILTINS_FROZENSET -Q(frozenset) -#endif - -#if MICROPY_PY_MATH || MICROPY_PY_CMATH -Q(math) -Q(e) -Q(pi) -Q(sqrt) -Q(pow) -Q(exp) -#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS -Q(expm1) -#endif -Q(log) -#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS -Q(log2) -Q(log10) -Q(cosh) -Q(sinh) -Q(tanh) -Q(acosh) -Q(asinh) -Q(atanh) -#endif -Q(cos) -Q(sin) -Q(tan) -Q(acos) -Q(asin) -Q(atan) -Q(atan2) -Q(ceil) -Q(copysign) -Q(fabs) -Q(fmod) -Q(floor) -Q(isfinite) -Q(isinf) -Q(isnan) -Q(trunc) -Q(modf) -Q(frexp) -Q(ldexp) -Q(degrees) -Q(radians) -#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS -Q(erf) -Q(erfc) -Q(gamma) -Q(lgamma) -#endif -#endif - -#if MICROPY_PY_CMATH -Q(cmath) -Q(phase) -Q(polar) -Q(rect) -#endif - -#if MICROPY_PY_MICROPYTHON_MEM_INFO -#if MICROPY_MEM_STATS -Q(mem_total) -Q(mem_current) -Q(mem_peak) -#endif -Q(mem_info) -Q(qstr_info) -#if MICROPY_STACK_CHECK -Q(stack_use) -#endif -#endif -#if MICROPY_ENABLE_GC -Q(heap_lock) -Q(heap_unlock) -#endif - -#if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF && (MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE == 0) -Q(alloc_emergency_exception_buf) -#endif Q(maximum recursion depth exceeded) - Q(<module>) Q(<lambda>) Q(<listcomp>) @@ -507,298 +49,12 @@ Q(<setcomp>) Q(<genexpr>) Q(<string>) Q(<stdin>) - -#if MICROPY_CPYTHON_COMPAT -Q(encode) -Q(decode) Q(utf-8) -#endif -#if MICROPY_PY_SYS -Q(argv) -Q(byteorder) -Q(big) -Q(exit) -Q(little) -#ifdef MICROPY_PY_SYS_PLATFORM -Q(platform) -#endif -Q(stdin) -Q(stdout) -Q(stderr) -#if MICROPY_PY_SYS_STDIO_BUFFER -Q(buffer) -#endif -Q(version) -Q(version_info) -#if MICROPY_PY_ATTRTUPLE -Q(name) -#endif -Q(implementation) -#if MICROPY_PY_SYS_MAXSIZE -Q(maxsize) -#endif -#if MICROPY_PY_SYS_MODULES -Q(modules) -#endif -#if MICROPY_PY_SYS_EXC_INFO -Q(exc_info) -#endif -Q(print_exception) -#endif - -#if MICROPY_PY_STRUCT -Q(struct) -Q(ustruct) -Q(pack) -Q(pack_into) -Q(unpack) -Q(unpack_from) -Q(calcsize) -#endif - -#if MICROPY_PY_UCTYPES -Q(uctypes) -Q(struct) -Q(sizeof) -Q(addressof) -Q(bytes_at) -Q(bytearray_at) - -Q(NATIVE) -Q(LITTLE_ENDIAN) -Q(BIG_ENDIAN) - -Q(VOID) - -Q(UINT8) -Q(INT8) -Q(UINT16) -Q(INT16) -Q(UINT32) -Q(INT32) -Q(UINT64) -Q(INT64) - -Q(BFUINT8) -Q(BFINT8) -Q(BFUINT16) -Q(BFINT16) -Q(BFUINT32) -Q(BFINT32) - -Q(FLOAT32) -Q(FLOAT64) - -Q(ARRAY) -Q(PTR) -//Q(BITFIELD) - -Q(BF_POS) -Q(BF_LEN) -#endif - -#if MICROPY_PY_IO -Q(_io) -Q(readall) -Q(readinto) -Q(readline) -Q(readlines) -Q(seek) -Q(tell) -Q(FileIO) -Q(TextIOWrapper) -Q(StringIO) -Q(BytesIO) -Q(getvalue) -Q(file) -Q(mode) -Q(r) -Q(encoding) -#if MICROPY_PY_IO_BUFFEREDWRITER -Q(BufferedWriter) -#endif -#endif - -#if MICROPY_PY_GC -Q(gc) -Q(collect) -Q(disable) -Q(enable) -Q(isenabled) -Q(mem_free) -Q(mem_alloc) -#endif - -#if MICROPY_PY_BUILTINS_PROPERTY -Q(property) -Q(getter) -Q(setter) -Q(deleter) -Q(doc) -#endif - -#if MICROPY_PY_UZLIB -Q(uzlib) -Q(decompress) -#endif - -#if MICROPY_PY_UJSON -Q(ujson) -Q(dumps) -Q(loads) -#endif - -#if MICROPY_PY_URE -Q(ure) -Q(compile) -Q(match) -Q(search) -Q(group) -Q(DEBUG) -#endif - -#if MICROPY_PY_UHEAPQ -Q(uheapq) -Q(heappush) -Q(heappop) -Q(heapify) -#endif - -#if MICROPY_PY_UHASHLIB -Q(uhashlib) -Q(update) -Q(digest) -Q(sha256) -Q(sha1) -#endif - -#if MICROPY_PY_UBINASCII -Q(ubinascii) -Q(hexlify) -Q(unhexlify) -Q(a2b_base64) -Q(b2a_base64) -#endif - -#if MICROPY_PY_MACHINE -Q(umachine) -Q(mem) -Q(mem8) -Q(mem16) -Q(mem32) -#endif - -#if MICROPY_PY_MACHINE_I2C -Q(I2C) -Q(init) -Q(scl) -Q(sda) -Q(freq) -Q(scan) -Q(start) -Q(stop) -Q(read) -Q(readinto) -Q(write) -Q(readfrom) -Q(readfrom_into) -Q(writeto) -Q(readfrom_mem) -Q(readfrom_mem_into) -Q(writeto_mem) -Q(addr) -Q(memaddr) -Q(n) -Q(buf) -#endif - -#if MICROPY_PY_USSL -Q(ussl) -Q(wrap_socket) -#endif - -#if MICROPY_PY_LWIP -// for lwip module -Q(lwip) -Q(reset) -Q(callback) -Q(socket) -Q(AF_INET) -Q(AF_INET6) -Q(SOCK_STREAM) -Q(SOCK_DGRAM) -Q(SOCK_RAW) -Q(SOL_SOCKET) -Q(SO_REUSEADDR) -// for lwip.socket -Q(close) -Q(bind) -Q(listen) -Q(accept) -Q(connect) -Q(send) -Q(recv) -Q(sendto) -Q(recvfrom) -Q(settimeout) -Q(setsockopt) -Q(makefile) -#if MICROPY_PY_LWIP_SLIP -// for lwip.slip -Q(slip) -Q(status) -#endif -#endif - -#if MICROPY_FSUSERMOUNT -// for user-mountable block devices -Q(mount) -Q(umount) -Q(readonly) -Q(mkfs) -Q(listdir) -Q(mkdir) -Q(remove) -Q(rename) -Q(readblocks) -Q(writeblocks) -Q(ioctl) -Q(sync) -Q(count) -#endif - -#if MICROPY_PY_OS_DUPTERM -Q(dupterm) -#endif - -#if MICROPY_PY_URANDOM -Q(urandom) -Q(getrandbits) -Q(seed) -#if MICROPY_PY_URANDOM_EXTRA_FUNCS -Q(randrange) -Q(randint) -Q(choice) -Q(random) -Q(uniform) -#endif -#endif - -#if MICROPY_VFS_FAT -Q(VfsFat) -Q(flush) -#endif - -#if MICROPY_PY_WEBSOCKET -Q(websocket) -#endif - -#if MICROPY_PY_FRAMEBUF -Q(framebuf) -Q(FrameBuffer1) -Q(fill) -Q(pixel) -Q(scroll) -Q(text) -#endif +// The following qstrings not referenced from anywhere in the sources +Q(__locals__) +Q(BufferError) +Q(FileExistsError) +Q(FileNotFoundError) +Q(FloatingPointError) +Q(UnboundLocalError) |