Home | History | Annotate | Download | only in bgen
      1 """Buffers allocated on the stack."""
      2 
      3 
      4 from bgenBuffer import FixedInputBufferType, FixedOutputBufferType
      5 
      6 
      7 class 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 
     18 class 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 
     38 class 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 
     49 class 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
     63