/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. from bgenBuffer import FixedInputBufferType, FixedOutputBufferType
  3. class StackOutputBufferType(FixedOutputBufferType):
  4. """Fixed output buffer allocated on the stack -- passed as (buffer, size).
  5. Instantiate with the buffer size as parameter.
  6. """
  7. def passOutput(self, name):
  8. return "%s__out__, %s" % (name, self.size)
  9. class VarStackOutputBufferType(StackOutputBufferType):
  10. """Output buffer allocated on the stack -- passed as (buffer, &size).
  11. Instantiate with the buffer size as parameter.
  12. """
  13. def getSizeDeclarations(self, name):
  14. return []
  15. def getAuxDeclarations(self, name):
  16. return ["int %s__len__ = %s" % (name, self.size)]
  17. def passOutput(self, name):
  18. return "%s__out__, &%s__len__" % (name, name)
  19. def mkvalueArgs(self, name):
  20. return "%s__out__, (int)%s__len__" % (name, name)
  21. class VarVarStackOutputBufferType(VarStackOutputBufferType):
  22. """Output buffer allocated on the stack -- passed as (buffer, size, &size).
  23. Instantiate with the buffer size as parameter.
  24. """
  25. def passOutput(self, name):
  26. return "%s__out__, %s__len__, &%s__len__" % (name, name, name)
  27. class ReturnVarStackOutputBufferType(VarStackOutputBufferType):
  28. """Output buffer allocated on the stack -- passed as (buffer, size) -> size.
  29. Instantiate with the buffer size as parameter.
  30. The function's return value is the size.
  31. (XXX Should have a way to suppress returning it separately, too.)
  32. """
  33. def passOutput(self, name):
  34. return "%s__out__, %s__len__" % (name, name)
  35. def mkvalueArgs(self, name):
  36. return "%s__out__, (int)_rv" % name