summaryrefslogtreecommitdiff
path: root/Function.py
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2011-12-01 18:28:36 +0000
committerPeter Wu <lekensteyn@gmail.com>2011-12-01 18:28:36 +0000
commit20416d5ae946d4defbfea66c53e58761cf885b73 (patch)
tree2ade535a438652f14bc6e9f55dcab077ed6d4e18 /Function.py
parent55ad98c9c392ad92c22d25f6d00978d8cec2959a (diff)
downloadpp2cc-20416d5ae946d4defbfea66c53e58761cf885b73.tar.gz
WIP for func parameter support and local (automatic) variables
Diffstat (limited to 'Function.py')
-rw-r--r--Function.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Function.py b/Function.py
index 6621fb8..de0c49d 100644
--- a/Function.py
+++ b/Function.py
@@ -22,9 +22,21 @@ class Function(object):
def __init__(self, node):
self.name = node.decl.name
self.node = node
+ self.reserved_stack = 0
def labelBegin(self):
"""Returns a label pointing to the begin of a function"""
return "fn_" + self.name
def labelEnd(self):
"""Returns a label pointing to the end of a function"""
return "fne_" + self.name
+ def allocStack(self, count=1):
+ """Reserve some memory (for local variables and params) on the stack
+ and return the begin of the allocated memory
+
+ Keyword arguments:
+ count -- The number of words to be allocated which should be at least 1
+ """
+ assert count > 0, "The stack allocation count must be at least 1"
+ begin_address = self.reserved_stack + 1
+ self.reserved_stack += count
+ return begin_address