From 4b297842f3b45c7857623c1c309654c339b28d85 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 3 Dec 2011 14:30:41 +0000 Subject: Support for static functions --- Function.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'Function.py') diff --git a/Function.py b/Function.py index 38d01ea..6be2bfe 100644 --- a/Function.py +++ b/Function.py @@ -19,12 +19,14 @@ __maintainer__ = "Peter Wu" __email__ = "uwretep@gmail.com" class Function(object): - def __init__(self, decl_node): + def __init__(self, decl_node, is_static=False, uniq_provider=None): """Initializes an object for holding a function declaration and related properties Keyword arguments: - decl_node -- A Node object + decl_node -- A Node object + is_static -- True if the function is static, False otherwise. Static + functions are local to a file and won't be visible to other files. """ assert type(decl_node).__name__ == "FuncDecl", ("decl_node is not a" " function declaration") @@ -32,12 +34,24 @@ class Function(object): self.name = self.decl_node.type.declname self.reserved_stack = 0 self.linked_node = None + self.is_static = is_static + common_fn_prefix = "sfn_" if self.isStatic() else "fn_" + if self.isStatic(): + assert uniq_provider != None, "No unique label provider found" + self.label_begin = uniq_provider("sfn_" + self.name) + self.label_end = uniq_provider("sfne_" + self.name) + else: + self.label_begin = "fn_" + self.name + self.label_end = "fne_" + self.name + def isStatic(self): + """Returns True if this is a static function, False otherwise""" + return self.is_static def labelBegin(self): """Returns a label pointing to the begin of a function""" - return "fn_" + self.name + return self.label_begin def labelEnd(self): """Returns a label pointing to the end of a function""" - return "fne_" + self.name + return self.label_end def allocStack(self, count=1): """Reserve some memory (for local variables and params) on the stack and return the begin of the allocated memory -- cgit v1.2.1