isa_parser.py (3953:300d526414e6) | isa_parser.py (3954:d689b611d9dc) |
---|---|
1# Copyright (c) 2003-2005 The Regents of The University of Michigan 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 1003 unchanged lines hidden (view full) --- 1012 myDict = None 1013 1014 # Protect non-Python-dict substitutions (e.g. if there's a printf 1015 # in the templated C++ code) 1016 template = protect_non_subst_percents(self.template) 1017 # CPU-model-specific substitutions are handled later (in GenCode). 1018 template = protect_cpu_symbols(template) 1019 | 1# Copyright (c) 2003-2005 The Regents of The University of Michigan 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 1003 unchanged lines hidden (view full) --- 1012 myDict = None 1013 1014 # Protect non-Python-dict substitutions (e.g. if there's a printf 1015 # in the templated C++ code) 1016 template = protect_non_subst_percents(self.template) 1017 # CPU-model-specific substitutions are handled later (in GenCode). 1018 template = protect_cpu_symbols(template) 1019 |
1020 # if we're dealing with an InstObjParams object, we need to be a 1021 # little more sophisticated. Otherwise, just do what we've always 1022 # done | 1020 # Build a dict ('myDict') to use for the template substitution. 1021 # Start with the template namespace. Make a copy since we're 1022 # going to modify it. 1023 myDict = templateMap.copy() 1024 |
1023 if isinstance(d, InstObjParams): | 1025 if isinstance(d, InstObjParams): |
1024 # The instruction wide parameters are already formed, but the 1025 # parameters which are only function wide still need to be 1026 # generated. 1027 perFuncNames = ['op_decl', 'op_src_decl', 'op_dest_decl', \ 1028 'op_rd', 'op_wb', 'mem_acc_size', 'mem_acc_type'] | 1026 # If we're dealing with an InstObjParams object, we need 1027 # to be a little more sophisticated. The instruction-wide 1028 # parameters are already formed, but the parameters which 1029 # are only function wide still need to be generated. |
1029 compositeCode = '' 1030 | 1030 compositeCode = '' 1031 |
1031 myDict = templateMap.copy() | |
1032 myDict.update(d.__dict__) 1033 # The "operands" and "snippets" attributes of the InstObjParams 1034 # objects are for internal use and not substitution. 1035 del myDict['operands'] 1036 del myDict['snippets'] 1037 | 1032 myDict.update(d.__dict__) 1033 # The "operands" and "snippets" attributes of the InstObjParams 1034 # objects are for internal use and not substitution. 1035 del myDict['operands'] 1036 del myDict['snippets'] 1037 |
1038 for name in labelRE.findall(template): 1039 # Don't try to find a snippet to go with things that will 1040 # match against attributes of d, or that are other templates, 1041 # or that we're going to generate later, or that we've already 1042 # found. 1043 if not hasattr(d, name) and \ 1044 not templateMap.has_key(name) and \ 1045 not myDict.has_key(name) and \ 1046 name not in perFuncNames: 1047 myDict[name] = d.snippets[name] 1048 if isinstance(myDict[name], str): 1049 myDict[name] = substMungedOpNames(substBitOps(myDict[name])) 1050 compositeCode += (" " + myDict[name]) | 1038 snippetLabels = [l for l in labelRE.findall(template) 1039 if d.snippets.has_key(l)] |
1051 | 1040 |
1052 compositeCode += (" " + template) | 1041 snippets = dict([(s, mungeSnippet(d.snippets[s])) 1042 for s in snippetLabels]) |
1053 | 1043 |
1044 myDict.update(snippets) 1045 1046 compositeCode = ' '.join(map(str, snippets.values())) 1047 1048 # Add in template itself in case it references any 1049 # operands explicitly (like Mem) 1050 compositeCode += ' ' + template 1051 |
|
1054 operands = SubOperandList(compositeCode, d.operands) 1055 1056 myDict['op_decl'] = operands.concatAttrStrings('op_decl') 1057 1058 is_src = lambda op: op.is_src 1059 is_dest = lambda op: op.is_dest 1060 1061 myDict['op_src_decl'] = \ 1062 operands.concatSomeAttrStrings(is_src, 'op_src_decl') 1063 myDict['op_dest_decl'] = \ 1064 operands.concatSomeAttrStrings(is_dest, 'op_dest_decl') 1065 1066 myDict['op_rd'] = operands.concatAttrStrings('op_rd') 1067 myDict['op_wb'] = operands.concatAttrStrings('op_wb') 1068 1069 if d.operands.memOperand: 1070 myDict['mem_acc_size'] = d.operands.memOperand.mem_acc_size 1071 myDict['mem_acc_type'] = d.operands.memOperand.mem_acc_type 1072 | 1052 operands = SubOperandList(compositeCode, d.operands) 1053 1054 myDict['op_decl'] = operands.concatAttrStrings('op_decl') 1055 1056 is_src = lambda op: op.is_src 1057 is_dest = lambda op: op.is_dest 1058 1059 myDict['op_src_decl'] = \ 1060 operands.concatSomeAttrStrings(is_src, 'op_src_decl') 1061 myDict['op_dest_decl'] = \ 1062 operands.concatSomeAttrStrings(is_dest, 'op_dest_decl') 1063 1064 myDict['op_rd'] = operands.concatAttrStrings('op_rd') 1065 myDict['op_wb'] = operands.concatAttrStrings('op_wb') 1066 1067 if d.operands.memOperand: 1068 myDict['mem_acc_size'] = d.operands.memOperand.mem_acc_size 1069 myDict['mem_acc_type'] = d.operands.memOperand.mem_acc_type 1070 |
1073 else: 1074 # Start with the template namespace. Make a copy since we're 1075 # going to modify it. 1076 myDict = templateMap.copy() | 1071 elif isinstance(d, dict): |
1077 # if the argument is a dictionary, we just use it. | 1072 # if the argument is a dictionary, we just use it. |
1078 if isinstance(d, dict): 1079 myDict.update(d) | 1073 myDict.update(d) 1074 elif hasattr(d, '__dict__'): |
1080 # if the argument is an object, we use its attribute map. | 1075 # if the argument is an object, we use its attribute map. |
1081 elif hasattr(d, '__dict__'): 1082 myDict.update(d.__dict__) 1083 else: 1084 raise TypeError, "Template.subst() arg must be or have dictionary" | 1076 myDict.update(d.__dict__) 1077 else: 1078 raise TypeError, "Template.subst() arg must be or have dictionary" |
1085 return template % myDict 1086 1087 # Convert to string. This handles the case when a template with a 1088 # CPU-specific term gets interpolated into another template or into 1089 # an output block. 1090 def __str__(self): 1091 return expand_cpu_symbols_to_string(self.template) 1092 --- 567 unchanged lines hidden (view full) --- 1660assignRE = re.compile(r'\s*=(?!=)', re.MULTILINE) 1661 1662# Munge operand names in code string to make legal C++ variable names. 1663# This means getting rid of the type extension if any. 1664# (Will match base_name attribute of Operand object.) 1665def substMungedOpNames(code): 1666 return operandsWithExtRE.sub(r'\1', code) 1667 | 1079 return template % myDict 1080 1081 # Convert to string. This handles the case when a template with a 1082 # CPU-specific term gets interpolated into another template or into 1083 # an output block. 1084 def __str__(self): 1085 return expand_cpu_symbols_to_string(self.template) 1086 --- 567 unchanged lines hidden (view full) --- 1654assignRE = re.compile(r'\s*=(?!=)', re.MULTILINE) 1655 1656# Munge operand names in code string to make legal C++ variable names. 1657# This means getting rid of the type extension if any. 1658# (Will match base_name attribute of Operand object.) 1659def substMungedOpNames(code): 1660 return operandsWithExtRE.sub(r'\1', code) 1661 |
1668def joinLists(t): 1669 return map(string.join, t) | 1662# Fix up code snippets for final substitution in templates. 1663def mungeSnippet(s): 1664 if isinstance(s, str): 1665 return substMungedOpNames(substBitOps(s)) 1666 else: 1667 return s |
1670 1671def makeFlagConstructor(flag_list): 1672 if len(flag_list) == 0: 1673 return '' 1674 # filter out repeated flags 1675 flag_list.sort() 1676 i = 1 1677 while i < len(flag_list): --- 9 unchanged lines hidden (view full) --- 1687# Assume all instruction flags are of the form 'IsFoo' 1688instFlagRE = re.compile(r'Is.*') 1689 1690# OpClass constants end in 'Op' except No_OpClass 1691opClassRE = re.compile(r'.*Op|No_OpClass') 1692 1693class InstObjParams: 1694 def __init__(self, mnem, class_name, base_class = '', | 1668 1669def makeFlagConstructor(flag_list): 1670 if len(flag_list) == 0: 1671 return '' 1672 # filter out repeated flags 1673 flag_list.sort() 1674 i = 1 1675 while i < len(flag_list): --- 9 unchanged lines hidden (view full) --- 1685# Assume all instruction flags are of the form 'IsFoo' 1686instFlagRE = re.compile(r'Is.*') 1687 1688# OpClass constants end in 'Op' except No_OpClass 1689opClassRE = re.compile(r'.*Op|No_OpClass') 1690 1691class InstObjParams: 1692 def __init__(self, mnem, class_name, base_class = '', |
1695 snippets = None, opt_args = []): | 1693 snippets = {}, opt_args = []): |
1696 self.mnemonic = mnem 1697 self.class_name = class_name 1698 self.base_class = base_class | 1694 self.mnemonic = mnem 1695 self.class_name = class_name 1696 self.base_class = base_class |
1699 compositeCode = '' 1700 if snippets: 1701 if not isinstance(snippets, dict): 1702 snippets = {'code' : snippets} 1703 for snippet in snippets.values(): 1704 if isinstance(snippet, str): 1705 compositeCode += (" " + snippet) | 1697 if not isinstance(snippets, dict): 1698 snippets = {'code' : snippets} 1699 compositeCode = ' '.join(map(str, snippets.values())) |
1706 self.snippets = snippets 1707 1708 self.operands = OperandList(compositeCode) 1709 self.constructor = self.operands.concatAttrStrings('constructor') 1710 self.constructor += \ 1711 '\n\t_numSrcRegs = %d;' % self.operands.numSrcRegs 1712 self.constructor += \ 1713 '\n\t_numDestRegs = %d;' % self.operands.numDestRegs --- 174 unchanged lines hidden --- | 1700 self.snippets = snippets 1701 1702 self.operands = OperandList(compositeCode) 1703 self.constructor = self.operands.concatAttrStrings('constructor') 1704 self.constructor += \ 1705 '\n\t_numSrcRegs = %d;' % self.operands.numSrcRegs 1706 self.constructor += \ 1707 '\n\t_numDestRegs = %d;' % self.operands.numDestRegs --- 174 unchanged lines hidden --- |