Esempio n. 1
0
    def create_pipeline(self, pxd, py=False):
        from Visitor import PrintTree
        from ParseTreeTransforms import WithTransform, NormalizeTree, PostParse, PxdPostParse
        from ParseTreeTransforms import AnalyseDeclarationsTransform, AnalyseExpressionsTransform
        from ParseTreeTransforms import CreateClosureClasses, MarkClosureVisitor, DecoratorTransform
        from ParseTreeTransforms import InterpretCompilerDirectives, TransformBuiltinMethods
        from ParseTreeTransforms import ExpandInplaceOperators
        from TypeInference import MarkAssignments, MarkOverflowingArithmetic
        from ParseTreeTransforms import AlignFunctionDefinitions, GilCheck
        from AnalysedTreeTransforms import AutoTestDictTransform
        from AutoDocTransforms import EmbedSignature
        from Optimize import FlattenInListTransform, SwitchTransform, IterationTransform
        from Optimize import EarlyReplaceBuiltinCalls, OptimizeBuiltinCalls
        from Optimize import ConstantFolding, FinalOptimizePhase
        from Optimize import DropRefcountingTransform
        from Buffer import IntroduceBufferAuxiliaryVars
        from ModuleNode import check_c_declarations, check_c_declarations_pxd

        if pxd:
            _check_c_declarations = check_c_declarations_pxd
            _specific_post_parse = PxdPostParse(self)
        else:
            _check_c_declarations = check_c_declarations
            _specific_post_parse = None

        if py and not pxd:
            _align_function_definitions = AlignFunctionDefinitions(self)
        else:
            _align_function_definitions = None

        return [
            NormalizeTree(self),
            PostParse(self),
            _specific_post_parse,
            InterpretCompilerDirectives(self, self.compiler_directives),
            MarkClosureVisitor(self),
            _align_function_definitions,
            ConstantFolding(),
            FlattenInListTransform(),
            WithTransform(self),
            DecoratorTransform(self),
            AnalyseDeclarationsTransform(self),
            AutoTestDictTransform(self),
            EmbedSignature(self),
            EarlyReplaceBuiltinCalls(self),  ## Necessary?
            MarkAssignments(self),
            MarkOverflowingArithmetic(self),
            TransformBuiltinMethods(self),  ## Necessary?
            IntroduceBufferAuxiliaryVars(self),
            _check_c_declarations,
            AnalyseExpressionsTransform(self),
            CreateClosureClasses(self),  ## After all lookups and type inference
            ExpandInplaceOperators(self),
            OptimizeBuiltinCalls(self),  ## Necessary?
            IterationTransform(),
            SwitchTransform(),
            DropRefcountingTransform(),
            FinalOptimizePhase(self),
            GilCheck(),
            ]
Esempio n. 2
0
    def create_pyx_python_backend_pipeline(self, options, result):
        def generate_python_code(module_node):
            module_node.process_python_implementation(options, result)
            result.compilation_source = module_node.compilation_source
            return result

        from Visitor import PrintTree
        from ParseTreeTransforms import WithTransform, NormalizeTree, PostParse, PxdPostParse
        from ParseTreeTransforms import AnalyseDeclarationsTransform, AnalyseExpressionsTransform
        from ParseTreeTransforms import CreateClosureClasses, MarkClosureVisitor, DecoratorTransform
        from ParseTreeTransforms import InterpretCompilerDirectives, TransformBuiltinMethods
        from ParseTreeTransforms import ExpandInplaceOperators
        from TypeInference import MarkAssignments, MarkOverflowingArithmetic
        from ParseTreeTransforms import AlignFunctionDefinitions, GilCheck
        from AnalysedTreeTransforms import AutoTestDictTransform
        from AutoDocTransforms import EmbedSignature
        from Optimize import FlattenInListTransform, SwitchTransform, IterationTransform
        from Optimize import EarlyReplaceBuiltinCalls, OptimizeBuiltinCalls
        from Optimize import ConstantFolding, FinalOptimizePhase
        from Optimize import DropRefcountingTransform
        from Buffer import IntroduceBufferAuxiliaryVars
        from ModuleNode import check_c_declarations, check_c_declarations_pxd
        import Options

        Options.store_code = True

        # Check what optimisations are useful for the Cython backend
        return [
            create_parse(self),
            NormalizeTree(self),
            PostParse(self),
            InterpretCompilerDirectives(self, self.compiler_directives),
            MarkClosureVisitor(self),
            ConstantFolding(),
            FlattenInListTransform(),
            WithTransform(self),
            DecoratorTransform(self),
            AnalyseDeclarationsTransform(self),
            AutoTestDictTransform(self),
            EmbedSignature(self),
            EarlyReplaceBuiltinCalls(self),  ## Necessary?
            MarkAssignments(self),
            MarkOverflowingArithmetic(self),
            TransformBuiltinMethods(self),  ## Necessary?
            IntroduceBufferAuxiliaryVars(self),
            AnalyseExpressionsTransform(self),
            CreateClosureClasses(
                self),  ## After all lookups and type inference
            ExpandInplaceOperators(self),
            OptimizeBuiltinCalls(self),  ## Necessary?
            IterationTransform(),
            SwitchTransform(),
            DropRefcountingTransform(),
            FinalOptimizePhase(self),
            generate_python_code,
        ]
Esempio n. 3
0
    def create_pipeline(self, pxd, py=False):
        from Visitor import PrintTree
        from ParseTreeTransforms import WithTransform, NormalizeTree, PostParse, PxdPostParse
        from ParseTreeTransforms import AnalyseDeclarationsTransform, AnalyseExpressionsTransform
        from ParseTreeTransforms import CreateClosureClasses, MarkClosureVisitor, DecoratorTransform
        from ParseTreeTransforms import InterpretCompilerDirectives, TransformBuiltinMethods
        from ParseTreeTransforms import AlignFunctionDefinitions
        from AutoDocTransforms import EmbedSignature
        from Optimize import FlattenInListTransform, SwitchTransform, FinalOptimizePhase
        from Buffer import IntroduceBufferAuxiliaryVars
        from ModuleNode import check_c_declarations

        if pxd:
            _check_c_declarations = None
            _specific_post_parse = PxdPostParse(self)
        else:
            _check_c_declarations = check_c_declarations
            _specific_post_parse = None
            
        if py and not pxd:
            _align_function_definitions = AlignFunctionDefinitions(self)
        else:
            _align_function_definitions = None
 
        return [
            NormalizeTree(self),
            PostParse(self),
            _specific_post_parse,
            _align_function_definitions,
            InterpretCompilerDirectives(self, self.pragma_overrides),
            FlattenInListTransform(),
            WithTransform(self),
            DecoratorTransform(self),
            AnalyseDeclarationsTransform(self),
            EmbedSignature(self),
            TransformBuiltinMethods(self),
            IntroduceBufferAuxiliaryVars(self),
            _check_c_declarations,
            AnalyseExpressionsTransform(self),
            SwitchTransform(),
            FinalOptimizePhase(self),
#            SpecialFunctions(self),
            #        CreateClosureClasses(context),
            ]
Esempio n. 4
0
def create_pipeline(context, mode, exclude_classes=()):
    assert mode in ('pyx', 'py', 'pxd')
    from Visitor import PrintTree
    from ParseTreeTransforms import WithTransform, NormalizeTree, PostParse, PxdPostParse
    from ParseTreeTransforms import ForwardDeclareTypes, AnalyseDeclarationsTransform
    from ParseTreeTransforms import AnalyseExpressionsTransform
    from ParseTreeTransforms import CreateClosureClasses, MarkClosureVisitor, DecoratorTransform
    from ParseTreeTransforms import InterpretCompilerDirectives, TransformBuiltinMethods
    from ParseTreeTransforms import ExpandInplaceOperators, ParallelRangeTransform
    from TypeInference import MarkAssignments, MarkOverflowingArithmetic
    from ParseTreeTransforms import AdjustDefByDirectives, AlignFunctionDefinitions
    from ParseTreeTransforms import RemoveUnreachableCode, GilCheck
    from FlowControl import CreateControlFlowGraph
    from AnalysedTreeTransforms import AutoTestDictTransform
    from AutoDocTransforms import EmbedSignature
    from Optimize import FlattenInListTransform, SwitchTransform, IterationTransform
    from Optimize import EarlyReplaceBuiltinCalls, OptimizeBuiltinCalls
    from Optimize import ConstantFolding, FinalOptimizePhase
    from Optimize import DropRefcountingTransform
    from Buffer import IntroduceBufferAuxiliaryVars
    from ModuleNode import check_c_declarations, check_c_declarations_pxd
    from ModuleNode import check_c_declarations


    if mode == 'pxd':
        _check_c_declarations = check_c_declarations_pxd
        _specific_post_parse = PxdPostParse(context)
    else:
        _check_c_declarations = check_c_declarations
        _specific_post_parse = None

    if mode == 'py':
        _align_function_definitions = AlignFunctionDefinitions(context)
    else:
        _align_function_definitions = None

    # NOTE: This is the "common" parts of the pipeline, which is also
    # code in pxd files. So it will be run multiple times in a
    # compilation stage.
    stages = [
        NormalizeTree(context),
        PostParse(context),
        _specific_post_parse,
        InterpretCompilerDirectives(context, context.compiler_directives),
        ParallelRangeTransform(context),
        AdjustDefByDirectives(context),
        MarkClosureVisitor(context),
        _align_function_definitions,
        RemoveUnreachableCode(context),
        ConstantFolding(),
        FlattenInListTransform(),
        WithTransform(context),
        DecoratorTransform(context),
        ForwardDeclareTypes(context),
        AnalyseDeclarationsTransform(context),
        AutoTestDictTransform(context),
        EmbedSignature(context),
        EarlyReplaceBuiltinCalls(context),  ## Necessary?
        TransformBuiltinMethods(context),  ## Necessary?
        MarkAssignments(context),
        CreateControlFlowGraph(context),
        RemoveUnreachableCode(context),
        # MarkAssignments(context),
        MarkOverflowingArithmetic(context),
        IntroduceBufferAuxiliaryVars(context),
        _check_c_declarations,
        AnalyseExpressionsTransform(context),
        CreateClosureClasses(context),  ## After all lookups and type inference
        ExpandInplaceOperators(context),
        OptimizeBuiltinCalls(context),  ## Necessary?
        IterationTransform(),
        SwitchTransform(),
        DropRefcountingTransform(),
        FinalOptimizePhase(context),
        GilCheck(),
        UseUtilityCodeDefinitions(context),
        ]
    filtered_stages = []
    for s in stages:
        if s.__class__ not in exclude_classes:
            filtered_stages.append(s)
    return filtered_stages
Esempio n. 5
0
    def create_pipeline(self, pxd, py=False):
        from Visitor import PrintTree
        from ParseTreeTransforms import WithTransform, NormalizeTree, PostParse, PxdPostParse
        from ParseTreeTransforms import AnalyseDeclarationsTransform, AnalyseExpressionsTransform
        from ParseTreeTransforms import CreateClosureClasses, MarkClosureVisitor, DecoratorTransform
        from ParseTreeTransforms import InterpretCompilerDirectives, TransformBuiltinMethods
        from TypeInference import MarkAssignments
        from ParseTreeTransforms import AlignFunctionDefinitions, GilCheck
        from AnalysedTreeTransforms import AutoTestDictTransform
        from AutoDocTransforms import EmbedSignature
        from Optimize import FlattenInListTransform, SwitchTransform, IterationTransform
        from Optimize import EarlyReplaceBuiltinCalls, OptimizeBuiltinCalls
        from Optimize import ConstantFolding, FinalOptimizePhase
        from Optimize import DropRefcountingTransform
        from Buffer import IntroduceBufferAuxiliaryVars
        from ModuleNode import check_c_declarations, check_c_declarations_pxd

        # Temporary hack that can be used to ensure that all result_code's
        # are generated at code generation time.
        import Visitor

        class ClearResultCodes(Visitor.CythonTransform):
            def visit_ExprNode(self, node):
                self.visitchildren(node)
                node.result_code = "<cleared>"
                return node

        if pxd:
            _check_c_declarations = check_c_declarations_pxd
            _specific_post_parse = PxdPostParse(self)
        else:
            _check_c_declarations = check_c_declarations
            _specific_post_parse = None

        if py and not pxd:
            _align_function_definitions = AlignFunctionDefinitions(self)
        else:
            _align_function_definitions = None

        return [
            NormalizeTree(self),
            PostParse(self),
            _specific_post_parse,
            InterpretCompilerDirectives(self, self.compiler_directives),
            _align_function_definitions,
            ConstantFolding(),
            FlattenInListTransform(),
            WithTransform(self),
            DecoratorTransform(self),
            AnalyseDeclarationsTransform(self),
            AutoTestDictTransform(self),
            EmbedSignature(self),
            EarlyReplaceBuiltinCalls(self),
            MarkAssignments(self),
            TransformBuiltinMethods(self),
            IntroduceBufferAuxiliaryVars(self),
            _check_c_declarations,
            AnalyseExpressionsTransform(self),
            OptimizeBuiltinCalls(self),
            IterationTransform(),
            SwitchTransform(),
            DropRefcountingTransform(),
            FinalOptimizePhase(self),
            GilCheck(),
            #            ClearResultCodes(self),
            #            SpecialFunctions(self),
            #        CreateClosureClasses(context),
        ]