1020,1022c1020,1024
< # if we're dealing with an InstObjParams object, we need to be a
< # little more sophisticated. Otherwise, just do what we've always
< # done
---
> # Build a dict ('myDict') to use for the template substitution.
> # Start with the template namespace. Make a copy since we're
> # going to modify it.
> myDict = templateMap.copy()
>
1024,1028c1026,1029
< # The instruction wide parameters are already formed, but the
< # parameters which are only function wide still need to be
< # generated.
< perFuncNames = ['op_decl', 'op_src_decl', 'op_dest_decl', \
< 'op_rd', 'op_wb', 'mem_acc_size', 'mem_acc_type']
---
> # If we're dealing with an InstObjParams object, we need
> # to be a little more sophisticated. The instruction-wide
> # parameters are already formed, but the parameters which
> # are only function wide still need to be generated.
1031d1031
< myDict = templateMap.copy()
1038,1050c1038,1039
< for name in labelRE.findall(template):
< # Don't try to find a snippet to go with things that will
< # match against attributes of d, or that are other templates,
< # or that we're going to generate later, or that we've already
< # found.
< if not hasattr(d, name) and \
< not templateMap.has_key(name) and \
< not myDict.has_key(name) and \
< name not in perFuncNames:
< myDict[name] = d.snippets[name]
< if isinstance(myDict[name], str):
< myDict[name] = substMungedOpNames(substBitOps(myDict[name]))
< compositeCode += (" " + myDict[name])
---
> snippetLabels = [l for l in labelRE.findall(template)
> if d.snippets.has_key(l)]
1052c1041,1042
< compositeCode += (" " + template)
---
> snippets = dict([(s, mungeSnippet(d.snippets[s]))
> for s in snippetLabels])
1053a1044,1051
> myDict.update(snippets)
>
> compositeCode = ' '.join(map(str, snippets.values()))
>
> # Add in template itself in case it references any
> # operands explicitly (like Mem)
> compositeCode += ' ' + template
>
1073,1076c1071
< else:
< # Start with the template namespace. Make a copy since we're
< # going to modify it.
< myDict = templateMap.copy()
---
> elif isinstance(d, dict):
1078,1079c1073,1074
< if isinstance(d, dict):
< myDict.update(d)
---
> myDict.update(d)
> elif hasattr(d, '__dict__'):
1081,1084c1076,1078
< elif hasattr(d, '__dict__'):
< myDict.update(d.__dict__)
< else:
< raise TypeError, "Template.subst() arg must be or have dictionary"
---
> myDict.update(d.__dict__)
> else:
> raise TypeError, "Template.subst() arg must be or have dictionary"
1668,1669c1662,1667
< def joinLists(t):
< return map(string.join, t)
---
> # Fix up code snippets for final substitution in templates.
> def mungeSnippet(s):
> if isinstance(s, str):
> return substMungedOpNames(substBitOps(s))
> else:
> return s
1695c1693
< snippets = None, opt_args = []):
---
> snippets = {}, opt_args = []):
1699,1705c1697,1699
< compositeCode = ''
< if snippets:
< if not isinstance(snippets, dict):
< snippets = {'code' : snippets}
< for snippet in snippets.values():
< if isinstance(snippet, str):
< compositeCode += (" " + snippet)
---
> if not isinstance(snippets, dict):
> snippets = {'code' : snippets}
> compositeCode = ' '.join(map(str, snippets.values()))