diff options
author | Gabe Black <gblack@eecs.umich.edu> | 2006-12-18 12:19:30 -0500 |
---|---|---|
committer | Gabe Black <gblack@eecs.umich.edu> | 2006-12-18 12:19:30 -0500 |
commit | 9e7dc343832f473b2058d4f9b39a27430142006f (patch) | |
tree | 5f61750159b2b3e64468155cb2d9a5d24a3d8524 /src/arch/isa_parser.py | |
parent | c3ec52346b99d398916765679877686c109e3513 (diff) | |
parent | d19d7aa8a55cd4413ab00de69deb237d89d5ef4a (diff) | |
download | gem5-9e7dc343832f473b2058d4f9b39a27430142006f.tar.xz |
Merge zizzer.eecs.umich.edu:/.automount/zower/eecshome/m5/newmem
into zizzer.eecs.umich.edu:/z/m5/Bitkeeper/sparco3
--HG--
extra : convert_revision : f17800685609d8353ec14676f45fbb123fc4e6c3
Diffstat (limited to 'src/arch/isa_parser.py')
-rwxr-xr-x | src/arch/isa_parser.py | 81 |
1 files changed, 39 insertions, 42 deletions
diff --git a/src/arch/isa_parser.py b/src/arch/isa_parser.py index 83cdf73bc..07ae72cb8 100755 --- a/src/arch/isa_parser.py +++ b/src/arch/isa_parser.py @@ -1017,37 +1017,38 @@ class Template: # CPU-model-specific substitutions are handled later (in GenCode). template = protect_cpu_symbols(template) - # 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() + if isinstance(d, InstObjParams): - # 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. compositeCode = '' - myDict = templateMap.copy() myDict.update(d.__dict__) # The "operands" and "snippets" attributes of the InstObjParams # objects are for internal use and not substitution. del myDict['operands'] del myDict['snippets'] - 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)] + + snippets = dict([(s, mungeSnippet(d.snippets[s])) + for s in snippetLabels]) + + myDict.update(snippets) + + compositeCode = ' '.join(map(str, snippets.values())) + + # Add in template itself in case it references any + # operands explicitly (like Mem) + compositeCode += ' ' + template + operands = SubOperandList(compositeCode, d.operands) myDict['op_decl'] = operands.concatAttrStrings('op_decl') @@ -1067,18 +1068,14 @@ class Template: myDict['mem_acc_size'] = d.operands.memOperand.mem_acc_size myDict['mem_acc_type'] = d.operands.memOperand.mem_acc_type - else: - # Start with the template namespace. Make a copy since we're - # going to modify it. - myDict = templateMap.copy() + elif isinstance(d, dict): # if the argument is a dictionary, we just use it. - if isinstance(d, dict): - myDict.update(d) + myDict.update(d) + elif hasattr(d, '__dict__'): # if the argument is an object, we use its attribute map. - 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" return template % myDict # Convert to string. This handles the case when a template with a @@ -1662,8 +1659,12 @@ assignRE = re.compile(r'\s*=(?!=)', re.MULTILINE) def substMungedOpNames(code): return operandsWithExtRE.sub(r'\1', code) -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 def makeFlagConstructor(flag_list): if len(flag_list) == 0: @@ -1689,17 +1690,13 @@ opClassRE = re.compile(r'.*Op|No_OpClass') class InstObjParams: def __init__(self, mnem, class_name, base_class = '', - snippets = None, opt_args = []): + snippets = {}, opt_args = []): self.mnemonic = mnem self.class_name = class_name self.base_class = base_class - 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())) self.snippets = snippets self.operands = OperandList(compositeCode) |