pypy / pypy / jit / tool / oparser_model.py

Antonio Cuni da29984 




Hakan Ardo cb3302d 
Antonio Cuni da29984 
Antonio Cuni fdc5fb1 
Maciej Fijalkows… 6ee1610 
Antonio Cuni da29984 

Antonio Cuni 0ec0b2d 




Antonio Cuni db05c08 




Antonio Cuni d43ba26 




Antonio Cuni db05c08 
Antonio Cuni 77c7ac3 




Antonio Cuni da29984 


Hakan Ardo 175f0ef 
Antonio Cuni da29984 




Hakan Ardo 175f0ef 
Antonio Cuni 1d6329f 

Maciej Fijalkows… 97c7263 



Antonio Cuni f20d001 


Antonio Cuni da29984 


























Antonio Cuni e2ea2d7 



Antonio Cuni 0ec0b2d 


Antonio Cuni e2ea2d7 








Antonio Cuni 0ec0b2d 







Antonio Cuni db05c08 



Antonio Cuni d43ba26 



Antonio Cuni da29984 


Hakan Ardo 175f0ef 
Antonio Cuni da29984 
Hakan Ardo 175f0ef 
Antonio Cuni da29984 


































class Boxes(object):
    pass

def get_real_model():
    class LoopModel(object):
        from pypy.jit.metainterp.history import TreeLoop, JitCellToken
        from pypy.jit.metainterp.history import Box, BoxInt, BoxFloat
        from pypy.jit.metainterp.history import ConstInt, ConstObj, ConstPtr, ConstFloat
        from pypy.jit.metainterp.history import BasicFailDescr, TargetToken
        from pypy.jit.metainterp.typesystem import llhelper

        from pypy.jit.metainterp.history import get_const_ptr_for_string
        from pypy.jit.metainterp.history import get_const_ptr_for_unicode
        get_const_ptr_for_string = staticmethod(get_const_ptr_for_string)
        get_const_ptr_for_unicode = staticmethod(get_const_ptr_for_unicode)

        @staticmethod
        def convert_to_floatstorage(arg):
            from pypy.jit.codewriter import longlong
            return longlong.getfloatstorage(float(arg))

        @staticmethod
        def ptr_to_int(obj):
            from pypy.jit.codewriter.heaptracker import adr2int
            from pypy.rpython.lltypesystem import llmemory
            return adr2int(llmemory.cast_ptr_to_adr(obj))

        @staticmethod
        def ootype_cast_to_object(obj):
            from pypy.rpython.ootypesystem import ootype
            return ootype.cast_to_object(obj)

    return LoopModel

def get_mock_model():
    class MockLoopModel(object):

        class TreeLoop(object):
            def __init__(self, name):
                self.name = name

        class JitCellToken(object):
            I_am_a_descr = True

        class TargetToken(object):
            def __init__(self, jct):
                pass

        class BasicFailDescr(object):
            I_am_a_descr = True

        class Box(object):
            _counter = 0
            type = 'b'

            def __init__(self, value=0):
                self.value = value

            def __repr__(self):
                result = str(self)
                result += '(%s)' % self.value
                return result

            def __str__(self):
                if not hasattr(self, '_str'):
                    self._str = '%s%d' % (self.type, Box._counter)
                    Box._counter += 1
                return self._str

        class BoxInt(Box):
            type = 'i'

        class BoxFloat(Box):
            type = 'f'

        class BoxRef(Box):
            type = 'p'

        class Const(object):
            def __init__(self, value=None):
                self.value = value

            def _get_str(self):
                return str(self.value)

        class ConstInt(Const):
            pass

        class ConstPtr(Const):
            pass

        class ConstFloat(Const):
            pass

        @classmethod
        def get_const_ptr_for_string(cls, s):
            return cls.ConstPtr(s)

        @classmethod
        def get_const_ptr_for_unicode(cls, s):
            return cls.ConstPtr(s)

        @staticmethod
        def convert_to_floatstorage(arg):
            return float(arg)

        @staticmethod
        def ptr_to_int(obj):
            return id(obj)

        class llhelper(object):
            pass

    MockLoopModel.llhelper.BoxRef = MockLoopModel.BoxRef

    return MockLoopModel


def get_model(use_mock):
    if use_mock:
        model = get_mock_model()
    else:
        model = get_real_model()

    class ExtendedTreeLoop(model.TreeLoop):

        def getboxes(self):
            def opboxes(operations):
                for op in operations:
                    yield op.result
                    for box in op.getarglist():
                        yield box
            def allboxes():
                for box in self.inputargs:
                    yield box
                for box in opboxes(self.operations):
                    yield box

            boxes = Boxes()
            for box in allboxes():
                if isinstance(box, model.Box):
                    name = str(box)
                    setattr(boxes, name, box)
            return boxes

        def setvalues(self, **kwds):
            boxes = self.getboxes()
            for name, value in kwds.iteritems():
                getattr(boxes, name).value = value

    model.ExtendedTreeLoop = ExtendedTreeLoop
    return model
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.