From 20416d5ae946d4defbfea66c53e58761cf885b73 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 1 Dec 2011 18:28:36 +0000 Subject: WIP for func parameter support and local (automatic) variables --- Function.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Function.py') 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 -- cgit v1.2.1