from __future__ import print_function
import sys
+import argparse
import collections
import itertools
from functools import reduce
-
+SUPPORTED_ISA_SPEC = ["2.2", "20190608", "20191213"]
CANONICAL_ORDER = "imafdgqlcbjtpvn"
LONG_EXT_PREFIXES = ['z', 's', 'h', 'x']
# IMPLIED_EXT(ext) -> implied extension list.
#
IMPLIED_EXT = {
- "d" : ["f"],
+ "d" : ["f", "zicsr"],
+ "f" : ["zicsr"],
}
-def arch_canonicalize(arch):
+def arch_canonicalize(arch, isa_spec):
# TODO: Support extension version.
+ is_isa_spec_2p2 = isa_spec == '2.2'
new_arch = ""
+ extra_long_ext = []
if arch[:5] in ['rv32e', 'rv32i', 'rv32g', 'rv64i', 'rv64g']:
- # TODO: We should expand g to imad_zifencei once we support newer spec.
new_arch = arch[:5].replace("g", "imafd")
+ if arch[:5] in ['rv32g', 'rv64g']:
+ if not is_isa_spec_2p2:
+ extra_long_ext = ['zicsr', 'zifencei']
else:
raise Exception("Unexpected arch: `%s`" % arch[:5])
long_exts = []
std_exts = list(arch[5:])
+ long_exts += extra_long_ext
+
#
# Handle implied extensions.
#
- for ext in std_exts + long_exts:
- if ext in IMPLIED_EXT:
- implied_exts = IMPLIED_EXT[ext]
- for implied_ext in implied_exts:
- if implied_ext not in std_exts + long_exts:
- long_exts.append(implied_ext)
+ any_change = True
+ while any_change:
+ any_change = False
+ for ext in std_exts + long_exts:
+ if ext in IMPLIED_EXT:
+ implied_exts = IMPLIED_EXT[ext]
+ for implied_ext in implied_exts:
+ if implied_ext == 'zicsr' and is_isa_spec_2p2:
+ continue
+
+ if implied_ext not in std_exts + long_exts:
+ long_exts.append(implied_ext)
+ any_change = True
# Single letter extension might appear in the long_exts list,
# becasue we just append extensions list to the arch string.
return (exts.startswith("x"), exts.startswith("zxm"),
LONG_EXT_PREFIXES.index(exts[0]), canonical_sort, exts[1:])
+ # Removing duplicates.
+ long_exts = list(set(long_exts))
+
# Multi-letter extension must be in lexicographic order.
long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts),
key=longext_sort))
# Concat rest of the multi-char extensions.
if long_exts:
new_arch += "_" + "_".join(long_exts)
+
return new_arch
if len(sys.argv) < 2:
print ("Usage: %s <arch_str> [<arch_str>*]" % sys.argv)
sys.exit(1)
-for arg in sys.argv[1:]:
- print (arch_canonicalize(arg))
+parser = argparse.ArgumentParser()
+parser.add_argument('-misa-spec', type=str,
+ default='20191213',
+ choices=SUPPORTED_ISA_SPEC)
+parser.add_argument('arch_strs', nargs=argparse.REMAINDER)
+
+args = parser.parse_args()
+
+for arch in args.arch_strs:
+ print (arch_canonicalize(arch, args.misa_spec))
# TODO: Add test for this script.
#
+SUPPORTED_ISA_SPEC = ["2.2", "20190608", "20191213"]
arches = collections.OrderedDict()
abis = collections.OrderedDict()
required = []
reuse = []
-def arch_canonicalize(arch):
+def arch_canonicalize(arch, isa_spec):
this_file = os.path.abspath(os.path.join( __file__))
arch_can_script = \
os.path.join(os.path.dirname(this_file), "arch-canonicalize")
- proc = subprocess.Popen([sys.executable, arch_can_script, arch],
+ proc = subprocess.Popen([sys.executable, arch_can_script,
+ '-misa-spec=%s' % isa_spec, arch],
stdout=subprocess.PIPE)
out, err = proc.communicate()
return out.decode().strip()
parser = argparse.ArgumentParser()
parser.add_argument("--cmodel", type=str)
+parser.add_argument('-misa-spec', type=str,
+ default='20191213',
+ choices=SUPPORTED_ISA_SPEC)
parser.add_argument("cfgs", type=str, nargs='*')
args = parser.parse_args()
if cmodel == "compact" and arch.startswith("rv32"):
continue
- arch = arch_canonicalize (arch)
+ arch = arch_canonicalize (arch, args.misa_spec)
arches[arch] = 1
abis[abi] = 1
extra = list(filter(None, extra.split(',')))
ext_combs = expand_combination(ext)
alts = sum([[x] + [x + y for y in ext_combs] for x in [arch] + extra], [])
- alts = list(map(arch_canonicalize, alts))
+ alts = filter(lambda x: len(x) != 0, alts)
+ alts = list(map(lambda a : arch_canonicalize(a, args.misa_spec), alts))
# Drop duplicated entry.
alts = unique(alts)