Commit 46f2563c authored by Stefan Behnel's avatar Stefan Behnel

support named labels to improve code readability

parent d5a8f001
......@@ -30,14 +30,17 @@ class FunctionContext(object):
self.temps_used_type = {} # name -> type
self.temp_counter = 0
def new_label(self):
def new_label(self, name=None):
n = self.label_counter
self.label_counter = n + 1
return "%s%d" % (Naming.label_prefix, n)
label = "%s%d" % (Naming.label_prefix, n)
if name is not None:
label += '_' + name
return label
def new_error_label(self):
old_err_lbl = self.error_label
self.error_label = self.new_label()
self.error_label = self.new_label('error')
return old_err_lbl
def get_loop_labels(self):
......@@ -219,7 +222,7 @@ class CCodeWriter(object):
# Functions delegated to function scope
def new_label(self): return self.func.new_label()
def new_label(self, name=None): return self.func.new_label(name)
def new_error_label(self): return self.func.new_error_label()
def get_loop_labels(self): return self.func.get_loop_labels()
def set_loop_labels(self, labels): return self.func.set_loop_labels(labels)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment