paul@0 | 1 | #!/usr/bin/env python |
paul@0 | 2 | |
paul@0 | 3 | import micropython |
paul@0 | 4 | import sys |
paul@4 | 5 | |
paul@77 | 6 | code = None |
paul@77 | 7 | |
paul@62 | 8 | def show(importer, with_builtins=0, optimisations=None): |
paul@62 | 9 | optimisations = optimisations or requested_optimisations |
paul@77 | 10 | global code |
paul@77 | 11 | code = importer.get_image(with_builtins, optimisations) |
paul@77 | 12 | for i, x in enumerate(code): |
paul@22 | 13 | print i, x |
paul@22 | 14 | |
paul@52 | 15 | def attrs(obj): |
paul@52 | 16 | for name, attr in obj.items(): |
paul@52 | 17 | print name, attr |
paul@52 | 18 | |
paul@62 | 19 | if __name__ == "__main__": |
paul@63 | 20 | args = sys.argv[2:] |
paul@63 | 21 | i = micropython.Importer(sys.path, "-v" in args) |
paul@62 | 22 | |
paul@63 | 23 | if "-omax" in args: |
paul@63 | 24 | requested_optimisations = i.supported_optimisations |
paul@63 | 25 | else: |
paul@63 | 26 | requested_optimisations = [] |
paul@63 | 27 | for arg in args: |
paul@63 | 28 | if arg.startswith("-o"): |
paul@63 | 29 | requested_optimisations.append(arg[2:]) |
paul@63 | 30 | |
paul@62 | 31 | try: |
paul@62 | 32 | builtins = i.load_from_file("lib/builtins.py", "__builtins__") |
paul@62 | 33 | if len(sys.argv) < 2: |
paul@62 | 34 | m = i.load("micropython") |
paul@62 | 35 | #m = i.load_from_file("micropython/__init__.py") |
paul@62 | 36 | else: |
paul@62 | 37 | m = i.load_from_file(sys.argv[1]) |
paul@62 | 38 | except micropython.ProcessingError, exc: |
paul@62 | 39 | print repr(exc) |
paul@37 | 40 | else: |
paul@62 | 41 | i.vacuum() |
paul@62 | 42 | ot = i.get_object_table() |
paul@62 | 43 | pt = i.get_parameter_table() |
paul@0 | 44 | |
paul@0 | 45 | # vim: tabstop=4 expandtab shiftwidth=4 |