Index: contrib/arch/hadlbppp.py
===================================================================
--- contrib/arch/hadlbppp.py	(revision 303738425e404f1f592efe97699a11cb627d7dbd)
+++ contrib/arch/hadlbppp.py	(revision 6d4c5497f87538bcbe4b9753ccd5efe134ee9ec4)
@@ -36,11 +36,11 @@
 INC, POST_INC, BLOCK_COMMENT, LINE_COMMENT, SYSTEM, ARCH, HEAD, BODY, NULL, \
 	INST, VAR, FIN, BIND, TO, SUBSUME, DELEGATE, IFACE, EXTENDS, PRE_BODY, \
-	PROTOTYPE, PAR_LEFT, PAR_RIGHT, SIGNATURE, PROTOCOL, FRAME, PROVIDES, \
-	REQUIRES = range(27)
+	PROTOTYPE, PAR_LEFT, PAR_RIGHT, SIGNATURE, PROTOCOL, INITIALIZATION, \
+	FINALIZATION, FRAME, PROVIDES, REQUIRES = range(29)
 
 def usage(prname):
 	"Print usage syntax"
 	
-	print "%s <OUTPUT>" % prname
+	print "%s <--dumpbp|--dumpadl|--noop>+ <OUTPUT>" % prname
 
 def tabs(cnt):
@@ -246,5 +246,5 @@
 	"Convert interface Behavior Protocol to generic protocol"
 	
-	result = ["("]
+	result = []
 	i = 0
 	
@@ -266,14 +266,12 @@
 		i += 1
 	
-	result.append(")")
-	result.append("*")
-	
 	return result
 
-def merge_bp(protocols):
+def merge_bp(initialization, finalization, protocols):
 	"Merge several Behavior Protocols"
 	
+	indep = []
+	
 	if (len(protocols) > 1):
-		result = []
 		first = True
 		
@@ -282,16 +280,45 @@
 				first = False
 			else:
-				result.append("|")
-			
-			result.append("(")
-			result.extend(protocol)
-			result.append(")")
-		
-		return result
-	
-	if (len(protocols) == 1):
-		return protocols[0]
-	
-	return []
+				indep.append("|")
+			
+			indep.append("(")
+			indep.extend(protocol)
+			indep.append(")")
+	elif (len(protocols) == 1):
+		indep = protocols[0]
+	
+	inited = []
+	
+	if (initialization != None):
+		if (len(indep) > 0):
+			inited.append("(")
+			inited.extend(initialization)
+			inited.append(")")
+			inited.append(";")
+			inited.append("(")
+			inited.extend(indep)
+			inited.append(")")
+		else:
+			inited = initialization
+	else:
+		inited = indep
+	
+	finited = []
+	
+	if (finalization != None):
+		if (len(inited) > 0):
+			finited.append("(")
+			finited.extend(inited)
+			finited.append(")")
+			finited.append(";")
+			finited.append("(")
+			finited.extend(finalization)
+			finited.append(")")
+		else:
+			finited = finalization
+	else:
+		finited = inited
+	
+	return finited
 
 def parse_bp(name, tokens, base_indent):
@@ -373,7 +400,11 @@
 	"Dump Behavior Protocol of a given frame"
 	
+	global opt_bp
+	
 	fname = "%s.bp" % frame['name']
 	
-	archf.write("instantiate %s from \"%s\"\n" % (var, fname))
+	if (archf != None):
+		archf.write("instantiate %s from \"%s\"\n" % (var, fname))
+	
 	outname = os.path.join(outdir, fname)
 	
@@ -381,4 +412,14 @@
 	if ('protocol' in frame):
 		protocols.append(frame['protocol'])
+	
+	if ('initialization' in frame):
+		initialization = frame['initialization']
+	else:
+		initialization = None
+	
+	if ('finalization' in frame):
+		finalization = frame['finalization']
+	else:
+		finalization = None
 	
 	if ('provides' in frame):
@@ -393,7 +434,9 @@
 				print "%s: Provided interface '%s' is undefined" % (frame['name'], provides['iface'])
 	
-	outf = file(outname, "w")
-	outf.write(parse_bp(outname, merge_bp(protocols), 0))
-	outf.close()
+	
+	if (opt_bp):
+		outf = file(outname, "w")
+		outf.write(parse_bp(outname, merge_bp(initialization, finalization, protocols), 0))
+		outf.close()
 
 def get_system_arch():
@@ -431,10 +474,15 @@
 	"Create null frame protocol"
 	
-	archf.write("frame \"%s\"\n" % fname)
+	global opt_bp
+	
+	if (archf != None):
+		archf.write("frame \"%s\"\n" % fname)
+	
 	outname = os.path.join(outdir, fname)
 	
-	outf = file(outname, "w")
-	outf.write("NULL")
-	outf.close()
+	if (opt_bp):
+		outf = file(outname, "w")
+		outf.write("NULL")
+		outf.close()
 
 def flatten_binds(binds, delegates, subsumes):
@@ -521,4 +569,6 @@
 	"Dump system architecture Behavior Protocol"
 	
+	global opt_bp
+	
 	arch = get_system_arch()
 	
@@ -562,6 +612,10 @@
 			break
 	
+	
 	outname = os.path.join(outdir, "%s.archbp" % arch['name'])
-	outf = file(outname, "w")
+	if (opt_bp):
+		outf = file(outname, "w")
+	else:
+		outf = None
 	
 	create_null_bp("null.bp", outdir, outf)
@@ -573,7 +627,9 @@
 	
 	for dst, src in directed_binds.items():
-		outf.write("bind %s to %s\n" % (", ".join(src), dst))
-	
-	outf.close()
+		if (outf != None):
+			outf.write("bind %s to %s\n" % (", ".join(src), dst))
+	
+	if (outf != None):
+		outf.close()
 
 def preproc_adl(raw, inarg):
@@ -591,4 +647,6 @@
 	global frame
 	global protocol
+	global initialization
+	global finalization
 	
 	global iface_properties
@@ -689,4 +747,72 @@
 			
 			if (BODY in context):
+				if (FINALIZATION in context):
+					if (token == "{"):
+						indent += 1
+					elif (token == "}"):
+						indent -= 1
+					
+					if (((token[-1] == ":") and (indent == 0)) or (indent == -1)):
+						bp = split_bp(finalization)
+						finalization = None
+						
+						if (not frame in frame_properties):
+							frame_properties[frame] = {}
+						
+						if ('finalization' in frame_properties[frame]):
+							print "%s: Finalization protocol for frame '%s' already defined" % (inname, frame)
+						else:
+							frame_properties[frame]['finalization'] = bp
+						
+						output += "\n%s" % tabs(2)
+						output += parse_bp(inname, bp, 2)
+						
+						context.remove(FINALIZATION)
+						if (indent == -1):
+							output += "\n%s" % token
+							context.remove(BODY)
+							context.add(NULL)
+							indent = 0
+							continue
+						else:
+							indent = 2
+					else:
+						finalization += token
+						continue
+				
+				if (INITIALIZATION in context):
+					if (token == "{"):
+						indent += 1
+					elif (token == "}"):
+						indent -= 1
+					
+					if (((token[-1] == ":") and (indent == 0)) or (indent == -1)):
+						bp = split_bp(initialization)
+						initialization = None
+						
+						if (not frame in frame_properties):
+							frame_properties[frame] = {}
+						
+						if ('initialization' in frame_properties[frame]):
+							print "%s: Initialization protocol for frame '%s' already defined" % (inname, frame)
+						else:
+							frame_properties[frame]['initialization'] = bp
+						
+						output += "\n%s" % tabs(2)
+						output += parse_bp(inname, bp, 2)
+						
+						context.remove(INITIALIZATION)
+						if (indent == -1):
+							output += "\n%s" % token
+							context.remove(BODY)
+							context.add(NULL)
+							indent = 0
+							continue
+						else:
+							indent = 2
+					else:
+						initialization += token
+						continue
+				
 				if (PROTOCOL in context):
 					if (token == "{"):
@@ -695,5 +821,5 @@
 						indent -= 1
 					
-					if (indent == -1):
+					if (((token[-1] == ":") and (indent == 0)) or (indent == -1)):
 						bp = split_bp(protocol)
 						protocol = None
@@ -709,14 +835,17 @@
 						output += "\n%s" % tabs(2)
 						output += parse_bp(inname, bp, 2)
-						output += "\n%s" % token
-						indent = 0
 						
 						context.remove(PROTOCOL)
-						context.remove(BODY)
-						context.add(NULL)
+						if (indent == -1):
+							output += "\n%s" % token
+							context.remove(BODY)
+							context.add(NULL)
+							indent = 0
+							continue
+						else:
+							indent = 2
 					else:
 						protocol += token
-					
-					continue
+						continue
 				
 				if (REQUIRES in context):
@@ -816,5 +945,4 @@
 					output += "\n%s%s" % (tabs(indent - 1), token)
 					context.add(PROVIDES)
-					protocol = ""
 					continue
 				
@@ -822,5 +950,18 @@
 					output += "\n%s%s" % (tabs(indent - 1), token)
 					context.add(REQUIRES)
-					protocol = ""
+					continue
+				
+				if (token == "initialization:"):
+					output += "\n%s%s" % (tabs(indent - 1), token)
+					indent = 0
+					context.add(INITIALIZATION)
+					initialization = ""
+					continue
+				
+				if (token == "finalization:"):
+					output += "\n%s%s" % (tabs(indent - 1), token)
+					indent = 0
+					context.add(FINALIZATION)
+					finalization = ""
 					continue
 				
@@ -1012,5 +1153,5 @@
 						print "%s: Expected inherited interface name in interface head '%s'" % (inname, interface)
 					else:
-						output += " %s" % token
+						output += "%s " % token
 						if (not interface in iface_properties):
 							iface_properties[interface] = {}
@@ -1023,5 +1164,5 @@
 				
 				if (token == "extends"):
-					output += " %s" % token
+					output += "%s " % token
 					context.add(EXTENDS)
 					continue
@@ -1376,6 +1517,10 @@
 	global frame
 	global protocol
+	global initialization
+	global finalization
 	
 	global arg0
+	
+	global opt_adl
 	
 	output = ""
@@ -1385,4 +1530,6 @@
 	frame = None
 	protocol = None
+	initialization = None
+	finalization = None
 	arg0 = None
 	
@@ -1390,5 +1537,5 @@
 	output = output.strip()
 	
-	if (output != ""):
+	if ((output != "") and (opt_adl)):
 		outf = file(outname, "w")
 		outf.write(output)
@@ -1416,10 +1563,26 @@
 	global frame_properties
 	global arch_properties
-	
-	if (len(sys.argv) < 2):
+	global opt_bp
+	global opt_adl
+	
+	if (len(sys.argv) < 3):
 		usage(sys.argv[0])
 		return
 	
-	path = os.path.abspath(sys.argv[1])
+	opt_bp = False
+	opt_adl = False
+	
+	for arg in sys.argv[1:(len(sys.argv) - 1)]:
+		if (arg == "--dumpbp"):
+			opt_bp = True
+		elif (arg == "--dumpadl"):
+			opt_adl = True
+		elif (arg == "--noop"):
+			pass
+		else:
+			print "Error: Unknown command line option '%s'" % arg
+			return
+	
+	path = os.path.abspath(sys.argv[-1])
 	if (not os.path.isdir(path)):
 		print "Error: <OUTPUT> is not a directory"
