PageRenderTime 63ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 18ms app.codeStats 0ms

/Tools/bgen/bgen/bgenStackBuffer.py

http://unladen-swallow.googlecode.com/
Python | 62 lines | 23 code | 20 blank | 19 comment | 0 complexity | 6867f16383d397d4ab85d08cf88b83b1 MD5 | raw file
 1"""Buffers allocated on the stack."""
 2
 3
 4from bgenBuffer import FixedInputBufferType, FixedOutputBufferType
 5
 6
 7class StackOutputBufferType(FixedOutputBufferType):
 8
 9    """Fixed output buffer allocated on the stack -- passed as (buffer, size).
10
11    Instantiate with the buffer size as parameter.
12    """
13
14    def passOutput(self, name):
15        return "%s__out__, %s" % (name, self.size)
16
17
18class VarStackOutputBufferType(StackOutputBufferType):
19
20    """Output buffer allocated on the stack -- passed as (buffer, &size).
21
22    Instantiate with the buffer size as parameter.
23    """
24
25    def getSizeDeclarations(self, name):
26        return []
27
28    def getAuxDeclarations(self, name):
29        return ["int %s__len__ = %s" % (name, self.size)]
30
31    def passOutput(self, name):
32        return "%s__out__, &%s__len__" % (name, name)
33
34    def mkvalueArgs(self, name):
35        return "%s__out__, (int)%s__len__" % (name, name)
36
37
38class VarVarStackOutputBufferType(VarStackOutputBufferType):
39
40    """Output buffer allocated on the stack -- passed as (buffer, size, &size).
41
42    Instantiate with the buffer size as parameter.
43    """
44
45    def passOutput(self, name):
46        return "%s__out__, %s__len__, &%s__len__" % (name, name, name)
47
48
49class ReturnVarStackOutputBufferType(VarStackOutputBufferType):
50
51    """Output buffer allocated on the stack -- passed as (buffer, size) -> size.
52
53    Instantiate with the buffer size as parameter.
54    The function's return value is the size.
55    (XXX Should have a way to suppress returning it separately, too.)
56    """
57
58    def passOutput(self, name):
59        return "%s__out__, %s__len__" % (name, name)
60
61    def mkvalueArgs(self, name):
62        return "%s__out__, (int)_rv" % name