Minor cleanup of new snippet/subst code.
--HG-- extra : convert_revision : d81e0d1356f3433e8467e407d66d4afb95614748
This commit is contained in:
parent
968048f56a
commit
d19d7aa8a5
|
@ -1017,39 +1017,37 @@ class Template:
|
||||||
# CPU-model-specific substitutions are handled later (in GenCode).
|
# CPU-model-specific substitutions are handled later (in GenCode).
|
||||||
template = protect_cpu_symbols(template)
|
template = protect_cpu_symbols(template)
|
||||||
|
|
||||||
# if we're dealing with an InstObjParams object, we need to be a
|
# Build a dict ('myDict') to use for the template substitution.
|
||||||
# little more sophisticated. Otherwise, just do what we've always
|
# Start with the template namespace. Make a copy since we're
|
||||||
# done
|
# going to modify it.
|
||||||
|
myDict = templateMap.copy()
|
||||||
|
|
||||||
if isinstance(d, InstObjParams):
|
if isinstance(d, InstObjParams):
|
||||||
# The instruction wide parameters are already formed, but the
|
# If we're dealing with an InstObjParams object, we need
|
||||||
# parameters which are only function wide still need to be
|
# to be a little more sophisticated. The instruction-wide
|
||||||
# generated.
|
# parameters are already formed, but the parameters which
|
||||||
perFuncNames = ['op_decl', 'op_src_decl', 'op_dest_decl', \
|
# are only function wide still need to be generated.
|
||||||
'op_rd', 'op_wb', 'mem_acc_size', 'mem_acc_type']
|
|
||||||
compositeCode = ''
|
compositeCode = ''
|
||||||
|
|
||||||
myDict = templateMap.copy()
|
|
||||||
myDict.update(d.__dict__)
|
myDict.update(d.__dict__)
|
||||||
# The "operands" and "snippets" attributes of the InstObjParams
|
# The "operands" and "snippets" attributes of the InstObjParams
|
||||||
# objects are for internal use and not substitution.
|
# objects are for internal use and not substitution.
|
||||||
del myDict['operands']
|
del myDict['operands']
|
||||||
del myDict['snippets']
|
del myDict['snippets']
|
||||||
|
|
||||||
for name in labelRE.findall(template):
|
snippetLabels = [l for l in labelRE.findall(template)
|
||||||
# Don't try to find a snippet to go with things that will
|
if d.snippets.has_key(l)]
|
||||||
# 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)
|
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)
|
operands = SubOperandList(compositeCode, d.operands)
|
||||||
|
|
||||||
|
@ -1070,18 +1068,14 @@ class Template:
|
||||||
myDict['mem_acc_size'] = d.operands.memOperand.mem_acc_size
|
myDict['mem_acc_size'] = d.operands.memOperand.mem_acc_size
|
||||||
myDict['mem_acc_type'] = d.operands.memOperand.mem_acc_type
|
myDict['mem_acc_type'] = d.operands.memOperand.mem_acc_type
|
||||||
|
|
||||||
else:
|
elif isinstance(d, dict):
|
||||||
# Start with the template namespace. Make a copy since we're
|
|
||||||
# going to modify it.
|
|
||||||
myDict = templateMap.copy()
|
|
||||||
# if the argument is a dictionary, we just use it.
|
# 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.
|
# if the argument is an object, we use its attribute map.
|
||||||
elif hasattr(d, '__dict__'):
|
myDict.update(d.__dict__)
|
||||||
myDict.update(d.__dict__)
|
else:
|
||||||
else:
|
raise TypeError, "Template.subst() arg must be or have dictionary"
|
||||||
raise TypeError, "Template.subst() arg must be or have dictionary"
|
|
||||||
return template % myDict
|
return template % myDict
|
||||||
|
|
||||||
# Convert to string. This handles the case when a template with a
|
# 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):
|
def substMungedOpNames(code):
|
||||||
return operandsWithExtRE.sub(r'\1', code)
|
return operandsWithExtRE.sub(r'\1', code)
|
||||||
|
|
||||||
def joinLists(t):
|
# Fix up code snippets for final substitution in templates.
|
||||||
return map(string.join, t)
|
def mungeSnippet(s):
|
||||||
|
if isinstance(s, str):
|
||||||
|
return substMungedOpNames(substBitOps(s))
|
||||||
|
else:
|
||||||
|
return s
|
||||||
|
|
||||||
def makeFlagConstructor(flag_list):
|
def makeFlagConstructor(flag_list):
|
||||||
if len(flag_list) == 0:
|
if len(flag_list) == 0:
|
||||||
|
@ -1692,17 +1690,13 @@ opClassRE = re.compile(r'.*Op|No_OpClass')
|
||||||
|
|
||||||
class InstObjParams:
|
class InstObjParams:
|
||||||
def __init__(self, mnem, class_name, base_class = '',
|
def __init__(self, mnem, class_name, base_class = '',
|
||||||
snippets = None, opt_args = []):
|
snippets = {}, opt_args = []):
|
||||||
self.mnemonic = mnem
|
self.mnemonic = mnem
|
||||||
self.class_name = class_name
|
self.class_name = class_name
|
||||||
self.base_class = base_class
|
self.base_class = base_class
|
||||||
compositeCode = ''
|
if not isinstance(snippets, dict):
|
||||||
if snippets:
|
snippets = {'code' : snippets}
|
||||||
if not isinstance(snippets, dict):
|
compositeCode = ' '.join(map(str, snippets.values()))
|
||||||
snippets = {'code' : snippets}
|
|
||||||
for snippet in snippets.values():
|
|
||||||
if isinstance(snippet, str):
|
|
||||||
compositeCode += (" " + snippet)
|
|
||||||
self.snippets = snippets
|
self.snippets = snippets
|
||||||
|
|
||||||
self.operands = OperandList(compositeCode)
|
self.operands = OperandList(compositeCode)
|
||||||
|
|
|
@ -154,19 +154,20 @@ decode OPCODE_HI default Unknown::unknown() {
|
||||||
|
|
||||||
0x3: decode FUNCTION_LO {
|
0x3: decode FUNCTION_LO {
|
||||||
format HiLoOp {
|
format HiLoOp {
|
||||||
0x0: mult({{ val = Rs.sd * Rt.sd; }});
|
0x0: mult({{ int64_t val = Rs.sd * Rt.sd; }});
|
||||||
0x1: multu({{ val = Rs.ud * Rt.ud; }});
|
0x1: multu({{ uint64_t val = Rs.ud * Rt.ud; }});
|
||||||
}
|
0x2: div({{ int64_t val;
|
||||||
|
if (Rt.sd != 0) {
|
||||||
format HiLoMiscOp {
|
int64_t hi = Rs.sd % Rt.sd;
|
||||||
0x2: div({{ if (Rt.sd != 0) {
|
int64_t lo = Rs.sd / Rt.sd;
|
||||||
HI = Rs.sd % Rt.sd;
|
val = (hi << 32) | lo;
|
||||||
LO = Rs.sd / Rt.sd;
|
|
||||||
}
|
}
|
||||||
}});
|
}});
|
||||||
0x3: divu({{ if (Rt.ud != 0) {
|
0x3: divu({{ uint64_t val;
|
||||||
HI = Rs.ud % Rt.ud;
|
if (Rt.ud != 0) {
|
||||||
LO = Rs.ud / Rt.ud;
|
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 {
|
format HiLoOp {
|
||||||
0x0: madd({{ val = ((int64_t) HI << 32 | LO) +
|
0x0: madd({{ int64_t val = ((int64_t) HI << 32 | LO) +
|
||||||
(Rs.sd * Rt.sd);
|
(Rs.sd * Rt.sd);
|
||||||
}});
|
}});
|
||||||
0x1: maddu({{ val = ((uint64_t) HI << 32 | LO) +
|
0x1: maddu({{ uint64_t val = ((uint64_t) HI << 32 | LO) +
|
||||||
(Rs.ud * Rt.ud);
|
(Rs.ud * Rt.ud);
|
||||||
}});
|
}});
|
||||||
0x4: msub({{ val = ((int64_t) HI << 32 | LO) -
|
0x4: msub({{ int64_t val = ((int64_t) HI << 32 | LO) -
|
||||||
(Rs.sd * Rt.sd);
|
(Rs.sd * Rt.sd);
|
||||||
}});
|
}});
|
||||||
0x5: msubu({{ val = ((uint64_t) HI << 32 | LO) -
|
0x5: msubu({{ uint64_t val = ((uint64_t) HI << 32 | LO) -
|
||||||
(Rs.ud * Rt.ud);
|
(Rs.ud * Rt.ud);
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,11 +240,6 @@ def format IntImmOp(code, *opt_flags) {{
|
||||||
}};
|
}};
|
||||||
|
|
||||||
def format HiLoOp(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 += 'HI = val<63:32>;\n'
|
||||||
code += 'LO = val<31:0>;\n'
|
code += 'LO = val<31:0>;\n'
|
||||||
|
|
||||||
|
@ -260,7 +255,7 @@ def format HiLoMiscOp(code, *opt_flags) {{
|
||||||
header_output = BasicDeclare.subst(iop)
|
header_output = BasicDeclare.subst(iop)
|
||||||
decoder_output = BasicConstructor.subst(iop)
|
decoder_output = BasicConstructor.subst(iop)
|
||||||
decode_block = BasicDecode.subst(iop)
|
decode_block = BasicDecode.subst(iop)
|
||||||
exec_output = HiLoExecute.subst(iop)
|
exec_output = BasicExecute.subst(iop)
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,6 @@ def template LoadInitiateAcc {{
|
||||||
{
|
{
|
||||||
Fault fault = NoFault;
|
Fault fault = NoFault;
|
||||||
Addr EA;
|
Addr EA;
|
||||||
uint%(mem_acc_size)s_t Mem;
|
|
||||||
%(op_decl)s;
|
%(op_decl)s;
|
||||||
%(op_rd)s;
|
%(op_rd)s;
|
||||||
%(ea_code)s;
|
%(ea_code)s;
|
||||||
|
|
Loading…
Reference in a new issue