summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Reinhardt <stever@eecs.umich.edu>2006-12-17 23:09:36 -0800
committerSteve Reinhardt <stever@eecs.umich.edu>2006-12-17 23:09:36 -0800
commitd19d7aa8a55cd4413ab00de69deb237d89d5ef4a (patch)
treedb697d8110e815ed928fac3cf674ff0bb0220e0f
parent968048f56a5f866b267ad9961cbe8d16788bcc89 (diff)
downloadgem5-d19d7aa8a55cd4413ab00de69deb237d89d5ef4a.tar.xz
Minor cleanup of new snippet/subst code.
--HG-- extra : convert_revision : d81e0d1356f3433e8467e407d66d4afb95614748
-rwxr-xr-xsrc/arch/isa_parser.py82
-rw-r--r--src/arch/mips/isa/decoder.isa39
-rw-r--r--src/arch/mips/isa/formats/int.isa7
-rw-r--r--src/arch/sparc/isa/formats/mem/util.isa1
4 files changed, 59 insertions, 70 deletions
diff --git a/src/arch/isa_parser.py b/src/arch/isa_parser.py
index bd34afb11..07ae72cb8 100755
--- a/src/arch/isa_parser.py
+++ b/src/arch/isa_parser.py
@@ -1017,39 +1017,37 @@ 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])
-
- compositeCode += (" " + template)
+ 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)
@@ -1070,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
@@ -1665,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:
@@ -1692,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)
diff --git a/src/arch/mips/isa/decoder.isa b/src/arch/mips/isa/decoder.isa
index d65e3eb94..12f36c449 100644
--- a/src/arch/mips/isa/decoder.isa
+++ b/src/arch/mips/isa/decoder.isa
@@ -154,19 +154,20 @@ decode OPCODE_HI default Unknown::unknown() {
0x3: decode FUNCTION_LO {
format HiLoOp {
- 0x0: mult({{ val = Rs.sd * Rt.sd; }});
- 0x1: multu({{ val = Rs.ud * Rt.ud; }});
- }
-
- format HiLoMiscOp {
- 0x2: div({{ if (Rt.sd != 0) {
- HI = Rs.sd % Rt.sd;
- LO = Rs.sd / Rt.sd;
+ 0x0: mult({{ int64_t val = Rs.sd * Rt.sd; }});
+ 0x1: multu({{ uint64_t val = Rs.ud * Rt.ud; }});
+ 0x2: div({{ int64_t val;
+ if (Rt.sd != 0) {
+ int64_t hi = Rs.sd % Rt.sd;
+ int64_t lo = Rs.sd / Rt.sd;
+ val = (hi << 32) | lo;
}
}});
- 0x3: divu({{ if (Rt.ud != 0) {
- HI = Rs.ud % Rt.ud;
- LO = Rs.ud / Rt.ud;
+ 0x3: divu({{ uint64_t val;
+ if (Rt.ud != 0) {
+ uint64_t hi = Rs.ud % Rt.ud;
+ uint64_t lo = Rs.ud / Rt.ud;
+ val = (hi << 32) | lo;
}
}});
}
@@ -950,17 +951,17 @@ decode OPCODE_HI default Unknown::unknown() {
}});
format HiLoOp {
- 0x0: madd({{ val = ((int64_t) HI << 32 | LO) +
- (Rs.sd * Rt.sd);
+ 0x0: madd({{ int64_t val = ((int64_t) HI << 32 | LO) +
+ (Rs.sd * Rt.sd);
}});
- 0x1: maddu({{ val = ((uint64_t) HI << 32 | LO) +
- (Rs.ud * Rt.ud);
+ 0x1: maddu({{ uint64_t val = ((uint64_t) HI << 32 | LO) +
+ (Rs.ud * Rt.ud);
}});
- 0x4: msub({{ val = ((int64_t) HI << 32 | LO) -
- (Rs.sd * Rt.sd);
+ 0x4: msub({{ int64_t val = ((int64_t) HI << 32 | LO) -
+ (Rs.sd * Rt.sd);
}});
- 0x5: msubu({{ val = ((uint64_t) HI << 32 | LO) -
- (Rs.ud * Rt.ud);
+ 0x5: msubu({{ uint64_t val = ((uint64_t) HI << 32 | LO) -
+ (Rs.ud * Rt.ud);
}});
}
}
diff --git a/src/arch/mips/isa/formats/int.isa b/src/arch/mips/isa/formats/int.isa
index e9b096f56..2f131f6d9 100644
--- a/src/arch/mips/isa/formats/int.isa
+++ b/src/arch/mips/isa/formats/int.isa
@@ -240,11 +240,6 @@ def format IntImmOp(code, *opt_flags) {{
}};
def format HiLoOp(code, *opt_flags) {{
- if '.sd' in code:
- code = 'int64_t ' + code
- elif '.ud' in code:
- code = 'uint64_t ' + code
-
code += 'HI = val<63:32>;\n'
code += 'LO = val<31:0>;\n'
@@ -260,7 +255,7 @@ def format HiLoMiscOp(code, *opt_flags) {{
header_output = BasicDeclare.subst(iop)
decoder_output = BasicConstructor.subst(iop)
decode_block = BasicDecode.subst(iop)
- exec_output = HiLoExecute.subst(iop)
+ exec_output = BasicExecute.subst(iop)
}};
diff --git a/src/arch/sparc/isa/formats/mem/util.isa b/src/arch/sparc/isa/formats/mem/util.isa
index 03b08ae18..2f8ef4798 100644
--- a/src/arch/sparc/isa/formats/mem/util.isa
+++ b/src/arch/sparc/isa/formats/mem/util.isa
@@ -170,7 +170,6 @@ def template LoadInitiateAcc {{
{
Fault fault = NoFault;
Addr EA;
- uint%(mem_acc_size)s_t Mem;
%(op_decl)s;
%(op_rd)s;
%(ea_code)s;