|
1 | 1 | from cerberus import Validator |
2 | 2 | from riscv_config.warl import warl_interpreter |
3 | 3 | import riscv_config.constants as constants |
| 4 | +from riscv_config.isa_validator import * |
4 | 5 | import re |
5 | | -import os |
6 | 6 |
|
7 | 7 |
|
8 | 8 | class schemaValidator(Validator): |
@@ -74,58 +74,15 @@ def _check_with_capture_isa_specifics(self, field, value): |
74 | 74 | ext = value[5:] |
75 | 75 | else: |
76 | 76 | self._error(field, "Invalid width in ISA.") |
77 | | - #ISA checks |
78 | | - str_match = re.findall('(?P<stdisa>[^\d]*?)(?!_)*(?P<zext>Z.*?)*(?P<sext>S[a-z]*)*(_|$)',value) |
79 | | - extension_list= [] |
80 | | - standard_isa = '' |
81 | | - for match in str_match: |
82 | | - stdisa, zext, sext, ignore = match |
83 | | - if stdisa != '': |
84 | | - for e in stdisa: |
85 | | - extension_list.append(e) |
86 | | - standard_isa = stdisa |
87 | | - if zext != '': |
88 | | - extension_list.append(zext) |
89 | | - if sext != '': |
90 | | - extension_list.append(sext) |
91 | | - # check ordering of ISA |
92 | | - canonical_ordering = 'IEMAFDQLCBJKTPVNSHU' |
93 | | - order_index = {c: i for i, c in enumerate(canonical_ordering)} |
94 | | - for i in range(len(standard_isa)-1): |
95 | | - a1 = standard_isa[i] |
96 | | - a2 = standard_isa[i+1] |
97 | | - |
98 | | - if order_index[a1] > order_index[a2]: |
99 | | - self._error(field, "Alphabet '" + a1 + "' should occur after '" + a2) |
100 | | - |
101 | | - if 'I' not in extension_list and 'E' not in extension_list: |
102 | | - self._error(field, 'Either of I or E base extensions need to be present in the ISA string') |
103 | | - if 'F' in extension_list and not "Zicsr" in extension_list: |
104 | | - self._error(field, "F cannot exist without Zicsr.") |
105 | | - if 'D' in extension_list and not 'F' in extension_list: |
106 | | - self._error(field, "D cannot exist without F.") |
107 | | - if 'Q' in extension_list and not 'D' in extension_list: |
108 | | - self._error(field, "Q cannot exist without D and F.") |
109 | | - if 'Zam' in extension_list and not 'A' in extension_list: |
110 | | - self._error(field, "Zam cannot exist without A.") |
111 | | - if 'N' in extension_list and not 'U' in extension_list: |
112 | | - self._error(field, "N cannot exist without U.") |
113 | | - if 'S' in extension_list and not 'U' in extension_list: |
114 | | - self._error(field, "S cannot exist without U.") |
115 | | - if 'Zkg' in extension_list and 'Zbc' in extension_list: |
116 | | - self._error(field, "Zkg being a proper subset of Zbc (from B extension) should be ommitted from the ISA string") |
117 | | - if 'Zkb' in extension_list and 'Zbp' in extension_list : |
118 | | - self._error(field, "Zkb being a proper subset of Zbp (from B extension) should be ommitted from the ISA string") |
119 | | - if 'Zks' in extension_list and ( set(['Zkse', 'Zksh','Zkg','Zkb']) & set(extension_list) ): |
120 | | - self._error(field, "Zks is a superset of Zkse, Zksh, Zkg and Zkb. In presence of Zks the subsets must be ignored in the ISA string.") |
121 | | - if 'Zkn' in extension_list and ( set(['Zkne','Zknd','Zknh','Zkg','Zkb']) & set(extension_list) ): |
122 | | - self._error(field, "Zkn is a superset of Zkne, Zknd, Zknh, Zkg and Zkb, In presence of Zkn the subsets must be ignored in the ISA string") |
123 | | - if 'K' in extension_list and ( set(['Zkn','Zkr','Zkne','Zknd','Zknh','Zkg','Zkb']) & set(extension_list) ) : |
124 | | - self._error(field, "K is a superset of Zkn and Zkr , In presence of K the subsets must be ignored in the ISA string") |
125 | | - |
126 | | -# if 'Z' in value and not self.document['User_Spec_Version'] == "2.3": |
127 | | -# self._error( |
128 | | -# field, "Z is not supported in the User Spec given version.") |
| 77 | + |
| 78 | + if not constants.isa_regex.match(value): |
| 79 | + self._error(field, 'Input ISA string does not match regex') |
| 80 | + |
| 81 | + (extension_list, err, err_list) = get_extension_list(value) |
| 82 | + if err: |
| 83 | + for e in err_list: |
| 84 | + self._error(field, e) |
| 85 | + |
129 | 86 | #ISA encoding for future use. |
130 | 87 | for x in "ABCDEFHIJKLMNPQSTUVX": |
131 | 88 | if (x in ext): |
|
0 commit comments