Ejemplo n.º 1
0
def get_combined_translation_config(other_optdescr=None,
                                    existing_config=None,
                                    overrides=None,
                                    translating=False):
    if overrides is None:
        overrides = {}
    d = BoolOption("translating",
                   "indicates whether we are translating currently",
                   default=False,
                   cmdline=None)
    if other_optdescr is None:
        children = []
        newname = ""
    else:
        children = [other_optdescr]
        newname = other_optdescr._name
    if existing_config is None:
        children += [d, translation_optiondescription]
    else:
        children += [
            child for child in existing_config._cfgimpl_descr._children
            if child._name != newname
        ]
    descr = OptionDescription("pypy", "all options", children)
    config = Config(descr, **overrides)
    if translating:
        config.translating = True
    if existing_config is not None:
        for child in existing_config._cfgimpl_descr._children:
            if child._name == newname:
                continue
            value = getattr(existing_config, child._name)
            config._cfgimpl_values[child._name] = value
    return config
Ejemplo n.º 2
0
pypy_optiondescription = OptionDescription(
    "objspace",
    "Object Space Options",
    [
        ChoiceOption("name",
                     "Object Space name",
                     ["std", "flow", "thunk", "dump", "taint", "reflective"],
                     "std",
                     requires={
                         "reflective":
                         [("objspace.disable_call_speedhacks", True)]
                     },
                     cmdline='--objspace -o'),
        ChoiceOption("parser",
                     "which parser to use for app-level code",
                     ["pypy", "cpython"],
                     "pypy",
                     cmdline='--parser'),
        ChoiceOption("compiler",
                     "which compiler to use for app-level code",
                     ["cpython", "ast"],
                     "ast",
                     cmdline='--compiler'),
        ChoiceOption("pyversion",
                     "which grammar to use for app-level code",
                     ["2.3", "2.4", "2.5a"],
                     "2.4",
                     cmdline='--pyversion'),
        OptionDescription("opcodes", "opcodes to enable in the interpreter", [
            BoolOption(
                "CALL_LIKELY_BUILTIN",
                "emit a special bytecode for likely calls to builtin functions",
                default=False,
                requires=[("objspace.std.withmultidict", True),
                          ("translation.stackless", False)]),
            BoolOption("CALL_METHOD",
                       "emit a special bytecode for expr.name()",
                       default=False),
        ]),
        BoolOption("nofaking",
                   "disallow faking in the object space",
                   default=False,
                   requires=[("objspace.usemodules.posix", True),
                             ("objspace.usemodules.time", True),
                             ("objspace.usemodules.errno", True)],
                   cmdline='--nofaking'),
        OptionDescription("usemodules", "Which Modules should be used", [
            BoolOption(modname,
                       "use module %s" % (modname, ),
                       default=modname in default_modules,
                       cmdline="--withmod-%s" % (modname, ),
                       requires=module_dependencies.get(modname, []),
                       suggests=module_suggests.get(modname, []),
                       negation=modname not in essential_modules,
                       validator=get_module_validator(modname))
            for modname in all_modules
        ]),
        BoolOption(
            "allworkingmodules",
            "use as many working modules as possible",
            # NB. defaults to True, but in py.py this is overridden by
            # a False suggestion because it takes a while to start up.
            # Actual module enabling only occurs if
            # enable_allworkingmodules() is called, and it depends
            # on the selected backend.
            default=True,
            cmdline="--allworkingmodules",
            negation=True),
        BoolOption("geninterp",
                   "specify whether geninterp should be used",
                   cmdline=None,
                   default=True),
        BoolOption(
            "logbytecodes", "keep track of bytecode usage", default=False),
        BoolOption("usepycfiles",
                   "Write and read pyc files when importing",
                   default=True),
        BoolOption("lonepycfiles",
                   "Import pyc files with no matching py file",
                   default=False,
                   requires=[("objspace.usepycfiles", True)]),
        BoolOption("honor__builtins__",
                   "Honor the __builtins__ key of a module dictionary",
                   default=False),
        BoolOption("disable_call_speedhacks",
                   "make sure that all calls go through space.call_args",
                   default=False),
        OptionDescription(
            "std",
            "Standard Object Space Options",
            [
                BoolOption(
                    "withtproxy", "support transparent proxies", default=True),
                BoolOption("withsmallint",
                           "use tagged integers",
                           default=False,
                           requires=[("translation.gc", "boehm"),
                                     ("objspace.std.withprebuiltint", False)]),
                BoolOption("withprebuiltint",
                           "prebuild commonly used int objects",
                           default=False),
                IntOption("prebuiltintfrom",
                          "lowest integer which is prebuilt",
                          default=-5,
                          cmdline="--prebuiltintfrom"),
                IntOption("prebuiltintto",
                          "highest integer which is prebuilt",
                          default=100,
                          cmdline="--prebuiltintto"),
                BoolOption("withstrjoin",
                           "use strings optimized for addition",
                           default=False),
                BoolOption("withstrslice",
                           "use strings optimized for slicing",
                           default=False),
                BoolOption("withprebuiltchar",
                           "use prebuilt single-character string objects",
                           default=False),
                BoolOption(
                    "sharesmallstr",
                    "always reuse the prebuilt string objects "
                    "(the empty string and potentially single-char strings)",
                    default=False),
                BoolOption("withrope",
                           "use ropes as the string implementation",
                           default=False,
                           requires=[("objspace.std.withstrslice", False),
                                     ("objspace.std.withstrjoin", False)],
                           suggests=[("objspace.std.withprebuiltchar", True),
                                     ("objspace.std.sharesmallstr", True)]),
                BoolOption("withropeunicode",
                           "use ropes for the unicode implementation",
                           default=False,
                           requires=[("objspace.std.withrope", True)]),
                BoolOption("withmultidict",
                           "use dictionaries optimized for flexibility",
                           default=False),
                BoolOption("withsharingdict",
                           "use dictionaries that share the keys part",
                           default=False,
                           requires=[("objspace.std.withmultidict", True)]),
                BoolOption("withdictmeasurement",
                           "create huge files with masses of information "
                           "about dictionaries",
                           default=False,
                           requires=[("objspace.std.withmultidict", True)]),
                BoolOption("withbucketdict",
                           "use dictionaries with chained hash tables "
                           "(default is open addressing)",
                           default=False,
                           requires=[("objspace.std.withmultidict", True)]),
                BoolOption("withsmalldicts",
                           "handle small dictionaries differently",
                           default=False,
                           requires=[("objspace.std.withmultidict", True)]),
                BoolOption(
                    "withrangelist",
                    "enable special range list implementation that does not "
                    "actually create the full list until the resulting "
                    "list is mutated",
                    default=False),
                BoolOption(
                    "withtypeversion",
                    "version type objects when changing them",
                    cmdline=None,
                    default=False,
                    # weakrefs needed, because of get_subclasses()
                    requires=[("translation.rweakref", True)]),
                BoolOption("withshadowtracking",
                           "track whether an instance attribute shadows a type"
                           " attribute",
                           default=False,
                           requires=[("objspace.std.withmultidict", True),
                                     ("objspace.std.withtypeversion", True),
                                     ("translation.rweakref", True)]),
                BoolOption("withmethodcache",
                           "try to cache method lookups",
                           default=False,
                           requires=[("objspace.std.withtypeversion", True),
                                     ("translation.rweakref", True)]),
                BoolOption(
                    "withmethodcachecounter",
                    "try to cache methods and provide a counter in __pypy__. "
                    "for testing purposes only.",
                    default=False,
                    requires=[("objspace.std.withmethodcache", True)]),
                IntOption(
                    "methodcachesizeexp",
                    " 2 ** methodcachesizeexp is the size of the of the method cache ",
                    default=11),
                BoolOption("withmultilist",
                           "use lists optimized for flexibility",
                           default=False,
                           requires=[("objspace.std.withrangelist", False),
                                     ("objspace.name", "std"),
                                     ("objspace.std.withtproxy", False)]),
                BoolOption("withfastslice",
                           "make list slicing lazy",
                           default=False,
                           requires=[("objspace.std.withmultilist", True)]),
                BoolOption(
                    "withchunklist",
                    "introducing a new nesting level to slow down list operations",
                    default=False,
                    requires=[("objspace.std.withmultilist", True)]),
                BoolOption("withsmartresizablelist",
                           "only overallocate O(sqrt(n)) elements for lists",
                           default=False,
                           requires=[("objspace.std.withmultilist", True)]),
                BoolOption("withblist",
                           "good asymptotic performance for very large lists",
                           default=False,
                           requires=[("objspace.std.withmultilist", True)]),
                BoolOption(
                    "optimized_int_add",
                    "special case the addition of two integers in BINARY_ADD",
                    default=False),
                BoolOption("optimized_comparison_op",
                           "special case the comparison of integers",
                           default=False),
                BoolOption("optimized_list_getitem",
                           "special case the 'list[integer]' expressions",
                           default=False),
                BoolOption("builtinshortcut",
                           "a shortcut for operations between built-in types",
                           default=False),
                BoolOption("getattributeshortcut",
                           "track types that override __getattribute__",
                           default=False),
                BoolOption(
                    "logspaceoptypes",
                    "a instrumentation option: before exit, print the types seen by "
                    "certain simpler bytecodes",
                    default=False),
                ChoiceOption("multimethods",
                             "the multimethod implementation to use",
                             ["doubledispatch", "mrd"],
                             default="mrd"),
            ]),
    ])
Ejemplo n.º 3
0
translation_optiondescription = OptionDescription(
    "translation",
    "Translation Options",
    [
        BoolOption("continuation",
                   "enable single-shot continuations",
                   default=False,
                   cmdline="--continuation",
                   requires=[("translation.type_system", "lltype")]),
        ChoiceOption(
            "type_system",
            "Type system to use when RTyping",
            ["lltype", "ootype"],
            cmdline=None,
            default="lltype",
            requires={
                "ootype": [
                    ("translation.backendopt.constfold", False),
                    ("translation.backendopt.clever_malloc_removal", False),
                    (
                        "translation.gc", "boehm"
                    ),  # it's not really used, but some jit code expects a value here
                ]
            }),
        ChoiceOption("backend",
                     "Backend to use for code generation", ["c", "cli", "jvm"],
                     default="c",
                     requires={
                         "c": [("translation.type_system", "lltype")],
                         "cli": [("translation.type_system", "ootype")],
                         "jvm": [("translation.type_system", "ootype")],
                     },
                     cmdline="-b --backend"),
        BoolOption("shared",
                   "Build as a shared library",
                   default=False,
                   cmdline="--shared"),
        BoolOption("log",
                   "Include debug prints in the translation (PYPYLOG=...)",
                   default=True,
                   cmdline="--log"),

        # gc
        ChoiceOption(
            "gc",
            "Garbage Collection Strategy",
            [
                "boehm", "ref", "marksweep", "semispace", "statistics",
                "generation", "hybrid", "markcompact", "minimark", "none"
            ],
            "ref",
            requires={
                "ref": [
                    ("translation.rweakref", False),  # XXX
                    ("translation.gctransformer", "ref")
                ],
                "none": [
                    ("translation.rweakref", False),  # XXX
                    ("translation.gctransformer", "none")
                ],
                "semispace": [("translation.gctransformer", "framework")],
                "marksweep": [("translation.gctransformer", "framework")],
                "statistics": [("translation.gctransformer", "framework")],
                "generation": [("translation.gctransformer", "framework")],
                "hybrid": [("translation.gctransformer", "framework")],
                "boehm": [
                    ("translation.continuation", False),  # breaks
                    ("translation.gctransformer", "boehm")
                ],
                "markcompact": [("translation.gctransformer", "framework")],
                "minimark": [("translation.gctransformer", "framework")],
            },
            cmdline="--gc"),
        ChoiceOption("gctransformer",
                     "GC transformer that is used - internal",
                     ["boehm", "ref", "framework", "none"],
                     default="ref",
                     cmdline=None,
                     requires={
                         "boehm": [("translation.gcrootfinder", "n/a"),
                                   ("translation.gcremovetypeptr", False)],
                         "ref": [("translation.gcrootfinder", "n/a"),
                                 ("translation.gcremovetypeptr", False)],
                         "none": [("translation.gcrootfinder", "n/a"),
                                  ("translation.gcremovetypeptr", False)],
                     }),
        BoolOption("gcremovetypeptr",
                   "Remove the typeptr from every object",
                   default=IS_64_BITS,
                   cmdline="--gcremovetypeptr"),
        ChoiceOption("gcrootfinder",
                     "Strategy for finding GC Roots (framework GCs only)",
                     ["n/a", "shadowstack", "asmgcc"],
                     "shadowstack",
                     cmdline="--gcrootfinder",
                     requires={
                         "shadowstack":
                         [("translation.gctransformer", "framework")],
                         "asmgcc": [("translation.gctransformer", "framework"),
                                    ("translation.backend", "c")],
                     }),

        # other noticeable options
        BoolOption("thread",
                   "enable use of threading primitives",
                   default=False,
                   cmdline="--thread"),
        BoolOption("sandbox",
                   "Produce a fully-sandboxed executable",
                   default=False,
                   cmdline="--sandbox",
                   requires=[("translation.thread", False)],
                   suggests=[("translation.gc", "generation")]),
        BoolOption("rweakref",
                   "The backend supports RPython-level weakrefs",
                   default=True),

        # JIT generation: use -Ojit to enable it
        BoolOption(
            "jit",
            "generate a JIT",
            default=False,
            suggests=[("translation.gc", DEFL_GC),
                      ("translation.gcrootfinder", DEFL_ROOTFINDER_WITHJIT),
                      ("translation.list_comprehension_operations", True)]),
        ChoiceOption("jit_backend",
                     "choose the backend for the JIT",
                     ["auto", "x86", "x86-without-sse2", "llvm"],
                     default="auto",
                     cmdline="--jit-backend"),
        ChoiceOption("jit_profiler",
                     "integrate profiler support into the JIT",
                     ["off", "oprofile"],
                     default="off"),
        # jit_ffi is automatically turned on by withmod-_ffi (which is enabled by default)
        BoolOption(
            "jit_ffi", "optimize libffi calls", default=False, cmdline=None),

        # misc
        BoolOption("verbose", "Print extra information", default=False),
        BoolOption("debug",
                   "Record extra annotation information",
                   cmdline="-d --debug",
                   default=True),
        BoolOption("insist",
                   "Try hard to go on RTyping",
                   default=False,
                   cmdline="--insist"),
        StrOption("cc",
                  "Specify compiler to use for compiling generated C",
                  cmdline="--cc"),
        StrOption("profopt",
                  "Specify profile based optimization script",
                  cmdline="--profopt"),
        BoolOption("noprofopt",
                   "Don't use profile based optimization",
                   default=False,
                   cmdline="--no-profopt",
                   negation=False),
        BoolOption("instrument",
                   "internal: turn instrumentation on",
                   default=False,
                   cmdline=None),
        BoolOption("countmallocs",
                   "Count mallocs and frees",
                   default=False,
                   cmdline=None),
        ChoiceOption("fork_before",
                     "(UNIX) Create restartable checkpoint before step", [
                         "annotate", "rtype", "backendopt", "database",
                         "source", "pyjitpl"
                     ],
                     default=None,
                     cmdline="--fork-before"),
        BoolOption(
            "dont_write_c_files",
            "Make the C backend write everyting to /dev/null. " +
            "Useful for benchmarking, so you don't actually involve the disk",
            default=False,
            cmdline="--dont-write-c-files"),
        ArbitraryOption("instrumentctl", "internal", default=None),
        StrOption("output", "Output file name", cmdline="--output"),
        StrOption(
            "secondaryentrypoints",
            "Comma separated list of keys choosing secondary entrypoints",
            cmdline="--entrypoints",
            default=""),
        BoolOption("dump_static_data_info",
                   "Dump static data info",
                   cmdline="--dump_static_data_info",
                   default=False,
                   requires=[("translation.backend", "c")]),

        # portability options
        BoolOption("vanilla",
                   "Try to be as portable as possible, which is not much",
                   default=False,
                   cmdline="--vanilla",
                   requires=[("translation.no__thread", True)]),
        BoolOption("no__thread",
                   "don't use __thread for implementing TLS",
                   default=False,
                   cmdline="--no__thread",
                   negation=False),
        StrOption("compilerflags",
                  "Specify flags for the C compiler",
                  cmdline="--cflags"),
        StrOption("linkerflags",
                  "Specify flags for the linker (C backend only)",
                  cmdline="--ldflags"),
        IntOption("make_jobs", "Specify -j argument to make for compilation"
                  " (C backend only)",
                  cmdline="--make-jobs",
                  default=detect_number_of_processors()),

        # Flags of the TranslationContext:
        BoolOption("simplifying", "Simplify flow graphs", default=True),
        BoolOption("builtins_can_raise_exceptions",
                   "When true, assume any call to a 'simple' builtin such as "
                   "'hex' can raise an arbitrary exception",
                   default=False,
                   cmdline=None),
        BoolOption("list_comprehension_operations",
                   "When true, look for and special-case the sequence of "
                   "operations that results from a list comprehension and "
                   "attempt to pre-allocate the list",
                   default=False,
                   cmdline='--listcompr'),
        IntOption(
            "withsmallfuncsets",
            "Represent groups of less funtions than this as indices into an array",
            default=0),
        BoolOption("taggedpointers",
                   "When true, enable the use of tagged pointers. "
                   "If false, use normal boxing",
                   default=False),

        # options for ootype
        OptionDescription("ootype", "Object Oriented Typesystem options", [
            BoolOption("mangle", "Mangle names of class members",
                       default=True),
        ]),
        OptionDescription(
            "backendopt",
            "Backend Optimization Options",
            [
                # control inlining
                BoolOption("inline",
                           "Do basic inlining and malloc removal",
                           default=True),
                FloatOption("inline_threshold",
                            "Threshold when to inline functions",
                            default=DEFL_INLINE_THRESHOLD,
                            cmdline="--inline-threshold"),
                StrOption(
                    "inline_heuristic", "Dotted name of an heuristic function "
                    "for inlining",
                    default=
                    "pypy.translator.backendopt.inline.inlining_heuristic",
                    cmdline="--inline-heuristic"),
                BoolOption("print_statistics",
                           "Print statistics while optimizing",
                           default=False),
                BoolOption("merge_if_blocks",
                           "Merge if ... elif chains",
                           cmdline="--if-block-merge",
                           default=True),
                BoolOption("raisingop2direct_call",
                           "Transform operations that can implicitly raise an "
                           "exception into calls to functions that explicitly "
                           "raise exceptions",
                           default=False,
                           cmdline="--raisingop2direct_call"),
                BoolOption("mallocs", "Remove mallocs", default=True),
                BoolOption("constfold", "Constant propagation", default=True),
                # control profile based inlining
                StrOption(
                    "profile_based_inline",
                    "Use call count profiling to drive inlining"
                    ", specify arguments",
                    default=None),  # cmdline="--prof-based-inline" fix me
                FloatOption(
                    "profile_based_inline_threshold",
                    "Threshold when to inline functions "
                    "for profile based inlining",
                    default=DEFL_PROF_BASED_INLINE_THRESHOLD,
                ),  # cmdline="--prof-based-inline-threshold" fix me
                StrOption(
                    "profile_based_inline_heuristic",
                    "Dotted name of an heuristic function "
                    "for profile based inlining",
                    default=
                    "pypy.translator.backendopt.inline.inlining_heuristic",
                ),  # cmdline="--prof-based-inline-heuristic" fix me
                # control clever malloc removal
                BoolOption("clever_malloc_removal",
                           "Drives inlining to remove mallocs in a clever way",
                           default=False,
                           cmdline="--clever-malloc-removal"),
                FloatOption(
                    "clever_malloc_removal_threshold",
                    "Threshold when to inline functions in "
                    "clever malloc removal",
                    default=DEFL_CLEVER_MALLOC_REMOVAL_INLINE_THRESHOLD,
                    cmdline="--clever-malloc-removal-threshold"),
                StrOption(
                    "clever_malloc_removal_heuristic",
                    "Dotted name of an heuristic function "
                    "for inlining in clever malloc removal",
                    default=
                    "pypy.translator.backendopt.inline.inlining_heuristic",
                    cmdline="--clever-malloc-removal-heuristic"),
                BoolOption(
                    "remove_asserts",
                    "Remove operations that look like 'raise AssertionError', "
                    "which lets the C optimizer remove the asserts",
                    default=False),
                BoolOption(
                    "really_remove_asserts",
                    "Really remove operations that look like 'raise AssertionError', "
                    "without relying on the C compiler",
                    default=False),
                BoolOption(
                    "stack_optimization",
                    "Tranform graphs in SSI form into graphs tailored for "
                    "stack based virtual machines (only for backends that support it)",
                    default=True),
                BoolOption("storesink", "Perform store sinking", default=True),
                BoolOption(
                    "none",
                    "Do not run any backend optimizations",
                    requires=[
                        ('translation.backendopt.inline', False),
                        ('translation.backendopt.inline_threshold', 0),
                        ('translation.backendopt.merge_if_blocks', False),
                        ('translation.backendopt.mallocs', False),
                        ('translation.backendopt.constfold', False)
                    ])
            ]),
        OptionDescription("cli", "GenCLI options", [
            BoolOption("trace_calls",
                       "Trace function calls",
                       default=False,
                       cmdline="--cli-trace-calls"),
            BoolOption("exception_transformer",
                       "Use exception transformer",
                       default=False),
        ]),
        ChoiceOption("platform",
                     "target platform", ['host'] + PLATFORMS,
                     default='host',
                     cmdline='--platform'),
    ])
Ejemplo n.º 4
0
cmdline_optiondescr = OptionDescription(
    "interactive", "the options of py.py", [
        BoolOption("verbose",
                   "show verbose interpreter-level traceback",
                   default=os.getenv("PYPY_TB"),
                   cmdline="-v"),
        BoolOption("interactive",
                   "inspect interactively after running script",
                   default=False,
                   cmdline="-i"),
        BoolOption("completer",
                   "use readline commandline completer",
                   default=False,
                   cmdline="-C"),
        BoolOption("optimize",
                   "dummy optimization flag for compatibility with CPython",
                   default=False,
                   cmdline="-O"),
        BoolOption("no_site_import",
                   "do not 'import site' on initialization",
                   default=False,
                   cmdline="-S"),
        StrOption(
            "runmodule",
            "library module to be run as a script (terminates option list)",
            default=None,
            cmdline="-m"),
        StrOption("runcommand",
                  "program passed in as CMD (terminates option list)",
                  default=None,
                  cmdline="-c"),
        StrOption(
            "warn",
            "warning control (arg is action:message:category:module:lineno)",
            default=None,
            cmdline="-W"),
    ])
Ejemplo n.º 5
0
translation_optiondescription = OptionDescription(
    "translation",
    "Translation Options",
    [
        BoolOption("stackless",
                   "enable stackless features during compilation",
                   default=False,
                   cmdline="--stackless",
                   requires=[("translation.type_system", "lltype")]),
        ChoiceOption(
            "type_system",
            "Type system to use when RTyping", ["lltype", "ootype"],
            cmdline=None,
            requires={
                "ootype": [
                    ("translation.backendopt.constfold", False),
                    ("translation.backendopt.heap2stack", False),
                    ("translation.backendopt.clever_malloc_removal", False),
                ]
            }),
        ChoiceOption(
            "backend",
            "Backend to use for code generation",
            ["c", "llvm", "cli", "jvm", "js"],
            requires={
                "c": [("translation.type_system", "lltype")],
                "llvm": [
                    ("translation.type_system", "lltype"),
                    ("translation.backendopt.raisingop2direct_call", True),
                ],
                "cli": [("translation.type_system", "ootype")],
                "jvm": [("translation.type_system", "ootype")],
                "js": [("translation.type_system", "ootype")],
            },
            cmdline="-b --backend"),
        BoolOption("llvm_via_c",
                   "compile llvm via C",
                   default=False,
                   cmdline="--llvm-via-c",
                   requires=[("translation.backend", "llvm")]),
        ChoiceOption(
            "gc",
            "Garbage Collection Strategy",
            [
                "boehm", "ref", "marksweep", "semispace", "statistics",
                "generation", "none"
            ],
            "ref",
            requires={
                "ref": [
                    ("translation.rweakref", False),  # XXX
                    ("translation.gctransformer", "ref")
                ],
                "none": [
                    ("translation.rweakref", False),  # XXX
                    ("translation.gctransformer", "none")
                ],
                "semispace": [("translation.gctransformer", "framework")],
                "marksweep": [("translation.gctransformer", "framework")],
                "statistics": [("translation.gctransformer", "framework")],
                "generation": [("translation.gctransformer", "framework")],
                "boehm": [("translation.gctransformer", "boehm")],
            },
            cmdline="--gc"),
        ChoiceOption("gctransformer",
                     "GC transformer that is used - internal",
                     ["boehm", "ref", "framework", "none"],
                     default="ref",
                     cmdline=None),
        ChoiceOption(
            "gcrootfinder",
            "Strategy for finding GC Roots",
            ["ref", "boehm", "shadowstack", "stackless", "llvmgc", "asmgcc"],
            "ref",
            cmdline="--gcrootfinder",
            requires={
                "ref": [("translation.gc", "ref")],
                "boehm": [("translation.gc", "boehm")],
                "shadowstack": [("translation.gctransformer", "framework")],
                "stackless": [("translation.gctransformer", "framework"),
                              ("translation.stackless", True)],
                "llvmgc": [("translation.gctransformer", "framework"),
                           ("translation.backend", "llvm")],
                "asmgcc": [("translation.gctransformer", "framework"),
                           ("translation.backend", "c")],
            },
            suggests={
                "shadowstack": [("translation.gc", "generation")],
                "stackless": [("translation.gc", "generation")],
                "llvmgc": [("translation.gc", "generation")],
                "asmgcc": [("translation.gc", "generation")],
            }),
        BoolOption("thread",
                   "enable use of threading primitives",
                   default=False,
                   cmdline="--thread",
                   requires=[("translation.gc", "boehm")]),
        BoolOption("verbose", "Print extra information", default=False),
        BoolOption("debug",
                   "Record extra annotation information",
                   cmdline="-d --debug",
                   default=False),
        BoolOption("insist",
                   "Try hard to go on RTyping",
                   default=False,
                   cmdline="--insist"),
        IntOption(
            "withsmallfuncsets",
            "Represent groups of less funtions than this as indices into an array",
            default=0),
        BoolOption("countmallocs",
                   "Count mallocs and frees",
                   default=False,
                   cmdline=None),
        BoolOption("sandbox",
                   "Produce a fully-sandboxed executable",
                   default=False,
                   cmdline="--sandbox",
                   requires=[("translation.thread", False)]),
        BoolOption("rweakref",
                   "The backend supports RPython-level weakrefs",
                   default=True),

        # misc
        StrOption("cc",
                  "Specify compiler to use for compiling generated C",
                  cmdline="--cc"),
        StrOption("profopt",
                  "Specify profile based optimization script",
                  cmdline="--profopt"),
        BoolOption("noprofopt",
                   "Don't use profile based optimization",
                   default=False,
                   cmdline="--no-profopt",
                   negation=False),
        BoolOption("instrument",
                   "internal: turn instrumentation on",
                   default=False,
                   cmdline=None),
        ArbitraryOption("instrumentctl", "internal", default=None),
        StrOption("output", "Output file name", cmdline="--output"),

        # portability options
        BoolOption("vanilla",
                   "Try to be as portable as possible, which is not much",
                   default=False,
                   cmdline="--vanilla",
                   requires=[("translation.no__thread", True)]),
        BoolOption("no__thread",
                   "don't use __thread for implementing TLS",
                   default=False,
                   cmdline="--no__thread",
                   negation=False),
        StrOption("compilerflags",
                  "Specify flags for the C compiler",
                  cmdline="--cflags"),
        StrOption("linkerflags",
                  "Specify flags for the linker (C backend only)",
                  cmdline="--ldflags"),

        # Flags of the TranslationContext:
        BoolOption("simplifying", "Simplify flow graphs", default=True),
        BoolOption("builtins_can_raise_exceptions",
                   "When true, assume any call to a 'simple' builtin such as "
                   "'hex' can raise an arbitrary exception",
                   default=False,
                   cmdline=None),
        BoolOption("list_comprehension_operations",
                   "When true, look for and special-case the sequence of "
                   "operations that results from a list comprehension and "
                   "attempt to pre-allocate the list",
                   default=False,
                   cmdline=None),
        ChoiceOption("fork_before",
                     "(UNIX) Create restartable checkpoint before step", [
                         "annotate", "rtype", "backendopt", "database",
                         "source", "hintannotate", "timeshift"
                     ],
                     default=None,
                     cmdline="--fork-before"),

        # options for ootype
        OptionDescription("ootype", "Object Oriented Typesystem options", [
            BoolOption("mangle", "Mangle names of class members",
                       default=True),
        ]),
        OptionDescription(
            "backendopt",
            "Backend Optimization Options",
            [
                # control inlining
                BoolOption("inline",
                           "Do basic inlining and malloc removal",
                           default=True),
                FloatOption("inline_threshold",
                            "Threshold when to inline functions",
                            default=DEFL_INLINE_THRESHOLD,
                            cmdline="--inline-threshold"),
                StrOption(
                    "inline_heuristic", "Dotted name of an heuristic function "
                    "for inlining",
                    default=
                    "pypy.translator.backendopt.inline.inlining_heuristic",
                    cmdline="--inline-heuristic"),
                BoolOption("print_statistics",
                           "Print statistics while optimizing",
                           default=False),
                BoolOption("merge_if_blocks",
                           "Merge if ... elif chains",
                           cmdline="--if-block-merge",
                           default=True),
                BoolOption("raisingop2direct_call",
                           "Transform operations that can implicitly raise an "
                           "exception into calls to functions that explicitly "
                           "raise exceptions",
                           default=False,
                           cmdline="--raisingop2direct_call"),
                BoolOption("mallocs", "Remove mallocs", default=True),
                BoolOption("constfold", "Constant propagation", default=True),
                BoolOption("heap2stack",
                           "Escape analysis and stack allocation",
                           default=False,
                           requires=[("translation.stackless", False)]),
                BoolOption("coalloc",
                           "Try to replace mallocs by coallocation",
                           default=False,
                           suggests=[("translation.gc", "generation")]),
                # control profile based inlining
                StrOption("profile_based_inline",
                          "Use call count profiling to drive inlining"
                          ", specify arguments",
                          default=None,
                          cmdline="--prof-based-inline"),
                FloatOption("profile_based_inline_threshold",
                            "Threshold when to inline functions "
                            "for profile based inlining",
                            default=DEFL_PROF_BASED_INLINE_THRESHOLD,
                            cmdline="--prof-based-inline-threshold"),
                StrOption(
                    "profile_based_inline_heuristic",
                    "Dotted name of an heuristic function "
                    "for profile based inlining",
                    default=
                    "pypy.translator.backendopt.inline.inlining_heuristic",
                    cmdline="--prof-based-inline-heuristic"),
                # control clever malloc removal
                BoolOption("clever_malloc_removal",
                           "Drives inlining to remove mallocs in a clever way",
                           default=False,
                           cmdline="--clever-malloc-removal"),
                FloatOption(
                    "clever_malloc_removal_threshold",
                    "Threshold when to inline functions in "
                    "clever malloc removal",
                    default=DEFL_CLEVER_MALLOC_REMOVAL_INLINE_THRESHOLD,
                    cmdline="--clever-malloc-removal-threshold"),
                StrOption(
                    "clever_malloc_removal_heuristic",
                    "Dotted name of an heuristic function "
                    "for inlining in clever malloc removal",
                    default=
                    "pypy.translator.backendopt.inline.inlining_heuristic",
                    cmdline="--clever-malloc-removal-heuristic"),
                BoolOption(
                    "remove_asserts",
                    "Remove operations that look like 'raise AssertionError', "
                    "which lets the C optimizer remove the asserts",
                    default=False),
                BoolOption(
                    "stack_optimization",
                    "Tranform graphs in SSI form into graphs tailored for "
                    "stack based virtual machines (only for backends that support it)",
                    default=True),
                BoolOption(
                    "none",
                    "Do not run any backend optimizations",
                    requires=[
                        ('translation.backendopt.inline', False),
                        ('translation.backendopt.inline_threshold', 0),
                        ('translation.backendopt.merge_if_blocks', False),
                        ('translation.backendopt.mallocs', False),
                        ('translation.backendopt.constfold', False)
                    ])
            ]),
        OptionDescription("llvm", "GenLLVM options", [
            BoolOption("debug",
                       "Include the llops in the source as comments",
                       default=False),
            BoolOption(
                "logging",
                "Log how long the various parts of llvm generation take",
                default=False),
            BoolOption("isolate", "Perform an isolated import", default=True),
            StrOption(
                "opt_options",
                "Options passed to opt (influences level of optimization in LLVM)",
                default="-std-compile-opts"),
        ]),
        OptionDescription("cli", "GenCLI options", [
            BoolOption("trace_calls",
                       "Trace function calls",
                       default=False,
                       cmdline="--cli-trace-calls"),
            BoolOption("exception_transformer",
                       "Use exception transformer",
                       default=False),
        ]),
    ])
Ejemplo n.º 6
0
translate_optiondescr = OptionDescription(
    "translate",
    "XXX",
    [
        StrOption(
            "targetspec", "XXX", default='targetpypystandalone', cmdline=None),
        ChoiceOption("opt",
                     "optimization level",
                     OPT_LEVELS,
                     default=DEFAULT_OPT_LEVEL,
                     cmdline="--opt -O"),
        BoolOption("profile",
                   "cProfile (to debug the speed of the translation process)",
                   default=False,
                   cmdline="--profile"),
        BoolOption("pdb",
                   "Always run pdb even if the translation succeeds",
                   default=False,
                   cmdline="--pdb"),
        BoolOption("batch",
                   "Don't run interactive helpers",
                   default=False,
                   cmdline="--batch",
                   negation=False),
        IntOption("huge", "Threshold in the number of functions after which "
                  "a local call graph and not a full one is displayed",
                  default=100,
                  cmdline="--huge"),
        BoolOption("view",
                   "Start the pygame viewer",
                   default=False,
                   cmdline="--view",
                   negation=False),
        BoolOption("help",
                   "show this help message and exit",
                   default=False,
                   cmdline="-h --help",
                   negation=False),
        BoolOption("fullhelp",
                   "show full help message and exit",
                   default=False,
                   cmdline="--full-help",
                   negation=False),
        ArbitraryOption("goals", "XXX", defaultfactory=list),
        # xxx default goals ['annotate', 'rtype', 'backendopt', 'source', 'compile']
        ArbitraryOption("skipped_goals", "XXX",
                        defaultfactory=lambda: ['run']),
        OptionDescription("goal_options",
                          "Goals that should be reached during translation",
                          goal_options()),
    ])
Ejemplo n.º 7
0
pypy_optiondescription = OptionDescription(
    "objspace",
    "Object Space Options",
    [
        ChoiceOption("name",
                     "Object Space name", ["std", "flow", "thunk", "dump"],
                     "std",
                     cmdline='--objspace -o'),
        OptionDescription("opcodes", "opcodes to enable in the interpreter", [
            BoolOption("CALL_METHOD",
                       "emit a special bytecode for expr.name()",
                       default=False),
        ]),
        BoolOption("nofaking",
                   "disallow faking in the object space",
                   default=False,
                   requires=[("objspace.usemodules.posix", True),
                             ("objspace.usemodules.time", True),
                             ("objspace.usemodules.errno", True)],
                   cmdline='--nofaking'),
        OptionDescription("usemodules", "Which Modules should be used", [
            BoolOption(modname,
                       "use module %s" % (modname, ),
                       default=modname in default_modules,
                       cmdline="--withmod-%s" % (modname, ),
                       requires=module_dependencies.get(modname, []),
                       suggests=module_suggests.get(modname, []),
                       negation=modname not in essential_modules,
                       validator=get_module_validator(modname))
            for modname in all_modules
        ]),
        BoolOption(
            "allworkingmodules",
            "use as many working modules as possible",
            # NB. defaults to True, but in py.py this is overridden by
            # a False suggestion because it takes a while to start up.
            # Actual module enabling only occurs if
            # enable_allworkingmodules() is called, and it depends
            # on the selected backend.
            default=True,
            cmdline="--allworkingmodules",
            negation=True),
        StrOption("extmodules",
                  "Comma-separated list of third-party builtin modules",
                  cmdline="--ext",
                  default=None),
        BoolOption(
            "translationmodules",
            "use only those modules that are needed to run translate.py on pypy",
            default=False,
            cmdline="--translationmodules",
            suggests=[("objspace.allworkingmodules", False)]),
        BoolOption(
            "logbytecodes", "keep track of bytecode usage", default=False),
        BoolOption("usepycfiles",
                   "Write and read pyc files when importing",
                   default=True),
        BoolOption("lonepycfiles",
                   "Import pyc files with no matching py file",
                   default=False,
                   requires=[("objspace.usepycfiles", True)]),
        StrOption(
            "soabi",
            "Tag to differentiate extension modules built for different Python interpreters",
            cmdline="--soabi",
            default=None),
        BoolOption("honor__builtins__",
                   "Honor the __builtins__ key of a module dictionary",
                   default=False),
        BoolOption("disable_call_speedhacks",
                   "make sure that all calls go through space.call_args",
                   default=False),
        BoolOption(
            "timing",
            "timing of various parts of the interpreter (simple profiling)",
            default=False),
        OptionDescription(
            "std",
            "Standard Object Space Options",
            [
                BoolOption(
                    "withtproxy", "support transparent proxies", default=True),
                BoolOption("withsmallint",
                           "use tagged integers",
                           default=False,
                           requires=[("objspace.std.withprebuiltint", False),
                                     ("translation.taggedpointers", True)]),
                BoolOption("withprebuiltint",
                           "prebuild commonly used int objects",
                           default=False),
                IntOption("prebuiltintfrom",
                          "lowest integer which is prebuilt",
                          default=-5,
                          cmdline="--prebuiltintfrom"),
                IntOption("prebuiltintto",
                          "highest integer which is prebuilt",
                          default=100,
                          cmdline="--prebuiltintto"),
                BoolOption("withsmalllong",
                           "use a version of 'long' in a C long long",
                           default=False,
                           requires=[("objspace.std.withsmallint", False)]),
                #  ^^^ because of missing delegate_xx2yy
                BoolOption("withstrjoin",
                           "use strings optimized for addition",
                           default=False),
                BoolOption("withstrslice",
                           "use strings optimized for slicing",
                           default=False),
                BoolOption("withstrbuf",
                           "use strings optimized for addition (ver 2)",
                           default=False),
                BoolOption("withprebuiltchar",
                           "use prebuilt single-character string objects",
                           default=False),
                BoolOption(
                    "sharesmallstr",
                    "always reuse the prebuilt string objects "
                    "(the empty string and potentially single-char strings)",
                    default=False),
                BoolOption("withsmalltuple", "use small tuples",
                           default=False),
                BoolOption("withspecialisedtuple",
                           "use specialised tuples",
                           default=False),
                BoolOption("withrope",
                           "use ropes as the string implementation",
                           default=False,
                           requires=[("objspace.std.withstrslice", False),
                                     ("objspace.std.withstrjoin", False),
                                     ("objspace.std.withstrbuf", False)],
                           suggests=[("objspace.std.withprebuiltchar", True),
                                     ("objspace.std.sharesmallstr", True)]),
                BoolOption("withropeunicode",
                           "use ropes for the unicode implementation",
                           default=False,
                           requires=[("objspace.std.withrope", True)]),
                BoolOption(
                    "withcelldict",
                    "use dictionaries that are optimized for being used as module dicts",
                    default=False,
                    requires=[("objspace.honor__builtins__", False)]),
                BoolOption(
                    "withmapdict",
                    "make instances really small but slow without the JIT",
                    default=False,
                    requires=[
                        ("objspace.std.getattributeshortcut", True),
                        ("objspace.std.withmethodcache", True),
                    ]),
                BoolOption(
                    "withrangelist",
                    "enable special range list implementation that does not "
                    "actually create the full list until the resulting "
                    "list is mutated",
                    default=False),
                BoolOption(
                    "withliststrategies",
                    "enable optimized ways to store lists of primitives ",
                    default=True),
                BoolOption(
                    "withtypeversion",
                    "version type objects when changing them",
                    cmdline=None,
                    default=False,
                    # weakrefs needed, because of get_subclasses()
                    requires=[("translation.rweakref", True)]),
                BoolOption("withmethodcache",
                           "try to cache method lookups",
                           default=False,
                           requires=[("objspace.std.withtypeversion", True),
                                     ("translation.rweakref", True)]),
                BoolOption(
                    "withmethodcachecounter",
                    "try to cache methods and provide a counter in __pypy__. "
                    "for testing purposes only.",
                    default=False,
                    requires=[("objspace.std.withmethodcache", True)]),
                IntOption(
                    "methodcachesizeexp",
                    " 2 ** methodcachesizeexp is the size of the of the method cache ",
                    default=11),
                BoolOption(
                    "optimized_int_add",
                    "special case the addition of two integers in BINARY_ADD",
                    default=False),
                BoolOption("optimized_comparison_op",
                           "special case the comparison of integers",
                           default=False),
                BoolOption("optimized_list_getitem",
                           "special case the 'list[integer]' expressions",
                           default=False),
                BoolOption("builtinshortcut",
                           "a shortcut for operations between built-in types",
                           default=False),
                BoolOption(
                    "getattributeshortcut",
                    "track types that override __getattribute__",
                    default=False,
                    # weakrefs needed, because of get_subclasses()
                    requires=[("translation.rweakref", True)]),
                BoolOption(
                    "newshortcut",
                    "cache and shortcut calling __new__ from builtin types",
                    default=False,
                    # weakrefs needed, because of get_subclasses()
                    requires=[("translation.rweakref", True)]),
                BoolOption(
                    "logspaceoptypes",
                    "a instrumentation option: before exit, print the types seen by "
                    "certain simpler bytecodes",
                    default=False),
                ChoiceOption("multimethods",
                             "the multimethod implementation to use",
                             ["doubledispatch", "mrd"],
                             default="mrd"),
                BoolOption("mutable_builtintypes",
                           "Allow the changing of builtin types",
                           default=False,
                           requires=[("objspace.std.builtinshortcut", True)]),
                BoolOption(
                    "withidentitydict",
                    "track types that override __hash__, __eq__ or __cmp__ and use a special dict strategy for those which do not",
                    default=False,
                    # weakrefs needed, because of get_subclasses()
                    requires=[("translation.rweakref", True)]),
            ]),
    ])
Ejemplo n.º 8
0
#from pypy.translator.translator import TranslationContext
from pypy.translator.driver import TranslationDriver
from pypy.translator.js.js import JS
from pypy.tool.error import AnnotatorError, FlowingError, debug
from pypy.rlib.nonconst import NonConstant
from pypy.annotation.policy import AnnotatorPolicy
from py.compat import optparse
from pypy.config.config import OptionDescription, BoolOption, StrOption
from pypy.config.config import Config, to_optparse
import py
import sys

js_optiondescr = OptionDescription("jscompile", "", [
    BoolOption("view", "View flow graphs",
               default=False, cmdline="--view"),
    BoolOption("use_pdb", "Use debugger",
               default=False, cmdline="--pdb"),
    StrOption("output", "File to save results (default output.js)",
              default="output.js", cmdline="--output")])


class FunctionNotFound(Exception):
    pass

class BadSignature(Exception):
    pass

class JsPolicy(AnnotatorPolicy):
    allow_someobjects = False

def get_args(func_data):