Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | ## |
Taylor Simpson | e28b77a | 2023-03-06 18:58:26 -0800 | [diff] [blame] | 4 | ## Copyright(c) 2019-2023 Qualcomm Innovation Center, Inc. All Rights Reserved. |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 5 | ## |
| 6 | ## This program is free software; you can redistribute it and/or modify |
| 7 | ## it under the terms of the GNU General Public License as published by |
| 8 | ## the Free Software Foundation; either version 2 of the License, or |
| 9 | ## (at your option) any later version. |
| 10 | ## |
| 11 | ## This program is distributed in the hope that it will be useful, |
| 12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | ## GNU General Public License for more details. |
| 15 | ## |
| 16 | ## You should have received a copy of the GNU General Public License |
| 17 | ## along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 18 | ## |
| 19 | |
| 20 | import sys |
| 21 | import re |
| 22 | import string |
| 23 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 24 | behdict = {} # tag ->behavior |
| 25 | semdict = {} # tag -> semantics |
| 26 | attribdict = {} # tag -> attributes |
| 27 | macros = {} # macro -> macro information... |
| 28 | attribinfo = {} # Register information and misc |
| 29 | tags = [] # list of all tags |
| 30 | overrides = {} # tags with helper overrides |
| 31 | idef_parser_enabled = {} # tags enabled for idef-parser |
| 32 | |
Matheus Tavares Bernardino | 3608c24 | 2023-05-24 11:41:47 -0300 | [diff] [blame] | 33 | def bad_register(regtype, regid): |
| 34 | raise Exception(f"Bad register parse: regtype '{regtype}' regid '{regid}'") |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 35 | |
| 36 | # We should do this as a hash for performance, |
| 37 | # but to keep order let's keep it as a list. |
| 38 | def uniquify(seq): |
| 39 | seen = set() |
| 40 | seen_add = seen.add |
| 41 | return [x for x in seq if x not in seen and not seen_add(x)] |
| 42 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 43 | |
| 44 | regre = re.compile(r"((?<!DUP)[MNORCPQXSGVZA])([stuvwxyzdefg]+)([.]?[LlHh]?)(\d+S?)") |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 45 | immre = re.compile(r"[#]([rRsSuUm])(\d+)(?:[:](\d+))?") |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 46 | reg_or_immre = re.compile( |
| 47 | r"(((?<!DUP)[MNRCOPQXSGVZA])([stuvwxyzdefg]+)" |
| 48 | + "([.]?[LlHh]?)(\d+S?))|([#]([rRsSuUm])(\d+)[:]?(\d+)?)" |
| 49 | ) |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 50 | relimmre = re.compile(r"[#]([rR])(\d+)(?:[:](\d+))?") |
| 51 | absimmre = re.compile(r"[#]([sSuUm])(\d+)(?:[:](\d+))?") |
| 52 | |
| 53 | finished_macros = set() |
| 54 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 55 | |
| 56 | def expand_macro_attribs(macro, allmac_re): |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 57 | if macro.key not in finished_macros: |
| 58 | # Get a list of all things that might be macros |
| 59 | l = allmac_re.findall(macro.beh) |
| 60 | for submacro in l: |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 61 | if not submacro: |
| 62 | continue |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 63 | if not macros[submacro]: |
Marco Liebel | cd6c4ed | 2023-03-20 02:25:32 -0700 | [diff] [blame] | 64 | raise Exception(f"Couldn't find macro: <{l}>") |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 65 | macro.attribs |= expand_macro_attribs(macros[submacro], allmac_re) |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 66 | finished_macros.add(macro.key) |
| 67 | return macro.attribs |
| 68 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 69 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 70 | # When qemu needs an attribute that isn't in the imported files, |
| 71 | # we'll add it here. |
| 72 | def add_qemu_macro_attrib(name, attrib): |
| 73 | macros[name].attribs.add(attrib) |
| 74 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 75 | |
| 76 | immextre = re.compile(r"f(MUST_)?IMMEXT[(]([UuSsRr])") |
| 77 | |
Taylor Simpson | 613653e | 2022-11-08 08:29:01 -0800 | [diff] [blame] | 78 | |
| 79 | def is_cond_jump(tag): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 80 | if tag == "J2_rte": |
Taylor Simpson | 613653e | 2022-11-08 08:29:01 -0800 | [diff] [blame] | 81 | return False |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 82 | if "A_HWLOOP0_END" in attribdict[tag] or "A_HWLOOP1_END" in attribdict[tag]: |
Taylor Simpson | 613653e | 2022-11-08 08:29:01 -0800 | [diff] [blame] | 83 | return False |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 84 | return re.compile(r"(if.*fBRANCH)|(if.*fJUMPR)").search(semdict[tag]) != None |
| 85 | |
Taylor Simpson | 613653e | 2022-11-08 08:29:01 -0800 | [diff] [blame] | 86 | |
| 87 | def is_cond_call(tag): |
| 88 | return re.compile(r"(if.*fCALL)").search(semdict[tag]) != None |
| 89 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 90 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 91 | def calculate_attribs(): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 92 | add_qemu_macro_attrib("fREAD_PC", "A_IMPLICIT_READS_PC") |
| 93 | add_qemu_macro_attrib("fTRAP", "A_IMPLICIT_READS_PC") |
| 94 | add_qemu_macro_attrib("fWRITE_P0", "A_WRITES_PRED_REG") |
| 95 | add_qemu_macro_attrib("fWRITE_P1", "A_WRITES_PRED_REG") |
| 96 | add_qemu_macro_attrib("fWRITE_P2", "A_WRITES_PRED_REG") |
| 97 | add_qemu_macro_attrib("fWRITE_P3", "A_WRITES_PRED_REG") |
| 98 | add_qemu_macro_attrib("fSET_OVERFLOW", "A_IMPLICIT_WRITES_USR") |
| 99 | add_qemu_macro_attrib("fSET_LPCFG", "A_IMPLICIT_WRITES_USR") |
| 100 | add_qemu_macro_attrib("fLOAD", "A_SCALAR_LOAD") |
| 101 | add_qemu_macro_attrib("fSTORE", "A_SCALAR_STORE") |
Taylor Simpson | b9f0326 | 2023-04-27 16:00:01 -0700 | [diff] [blame] | 102 | add_qemu_macro_attrib('fLSBNEW0', 'A_IMPLICIT_READS_P0') |
| 103 | add_qemu_macro_attrib('fLSBNEW0NOT', 'A_IMPLICIT_READS_P0') |
| 104 | add_qemu_macro_attrib('fREAD_P0', 'A_IMPLICIT_READS_P0') |
| 105 | add_qemu_macro_attrib('fLSBNEW1', 'A_IMPLICIT_READS_P1') |
| 106 | add_qemu_macro_attrib('fLSBNEW1NOT', 'A_IMPLICIT_READS_P1') |
| 107 | add_qemu_macro_attrib('fREAD_P3', 'A_IMPLICIT_READS_P3') |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 108 | |
| 109 | # Recurse down macros, find attributes from sub-macros |
| 110 | macroValues = list(macros.values()) |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 111 | allmacros_restr = "|".join(set([m.re.pattern for m in macroValues])) |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 112 | allmacros_re = re.compile(allmacros_restr) |
| 113 | for macro in macroValues: |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 114 | expand_macro_attribs(macro, allmacros_re) |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 115 | # Append attributes to all instructions |
| 116 | for tag in tags: |
| 117 | for macname in allmacros_re.findall(semdict[tag]): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 118 | if not macname: |
| 119 | continue |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 120 | macro = macros[macname] |
| 121 | attribdict[tag] |= set(macro.attribs) |
| 122 | # Figure out which instructions write predicate registers |
| 123 | tagregs = get_tagregs() |
| 124 | for tag in tags: |
| 125 | regs = tagregs[tag] |
Matheus Tavares Bernardino | 3608c24 | 2023-05-24 11:41:47 -0300 | [diff] [blame] | 126 | for regtype, regid in regs: |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 127 | if regtype == "P" and is_written(regid): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 128 | attribdict[tag].add("A_WRITES_PRED_REG") |
Taylor Simpson | 613653e | 2022-11-08 08:29:01 -0800 | [diff] [blame] | 129 | # Mark conditional jumps and calls |
| 130 | # Not all instructions are properly marked with A_CONDEXEC |
| 131 | for tag in tags: |
| 132 | if is_cond_jump(tag) or is_cond_call(tag): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 133 | attribdict[tag].add("A_CONDEXEC") |
| 134 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 135 | |
| 136 | def SEMANTICS(tag, beh, sem): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 137 | # print tag,beh,sem |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 138 | behdict[tag] = beh |
| 139 | semdict[tag] = sem |
| 140 | attribdict[tag] = set() |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 141 | tags.append(tag) # dicts have no order, this is for order |
| 142 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 143 | |
| 144 | def ATTRIBUTES(tag, attribstring): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 145 | attribstring = attribstring.replace("ATTRIBS", "").replace("(", "").replace(")", "") |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 146 | if not attribstring: |
| 147 | return |
| 148 | attribs = attribstring.split(",") |
| 149 | for attrib in attribs: |
| 150 | attribdict[tag].add(attrib.strip()) |
| 151 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 152 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 153 | class Macro(object): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 154 | __slots__ = ["key", "name", "beh", "attribs", "re"] |
| 155 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 156 | def __init__(self, name, beh, attribs): |
| 157 | self.key = name |
| 158 | self.name = name |
| 159 | self.beh = beh |
| 160 | self.attribs = set(attribs) |
| 161 | self.re = re.compile("\\b" + name + "\\b") |
| 162 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 163 | |
| 164 | def MACROATTRIB(macname, beh, attribstring): |
| 165 | attribstring = attribstring.replace("(", "").replace(")", "") |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 166 | if attribstring: |
| 167 | attribs = attribstring.split(",") |
| 168 | else: |
| 169 | attribs = [] |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 170 | macros[macname] = Macro(macname, beh, attribs) |
| 171 | |
Matheus Tavares Bernardino | 3608c24 | 2023-05-24 11:41:47 -0300 | [diff] [blame] | 172 | def compute_tag_regs(tag, full): |
| 173 | tagregs = regre.findall(behdict[tag]) |
| 174 | if not full: |
| 175 | tagregs = map(lambda reg: reg[:2], tagregs) |
| 176 | return uniquify(tagregs) |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 177 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 178 | def compute_tag_immediates(tag): |
| 179 | return uniquify(immre.findall(behdict[tag])) |
| 180 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 181 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 182 | ## |
| 183 | ## tagregs is the main data structure we'll use |
| 184 | ## tagregs[tag] will contain the registers used by an instruction |
| 185 | ## Within each entry, we'll use the regtype and regid fields |
| 186 | ## regtype can be one of the following |
| 187 | ## C control register |
| 188 | ## N new register value |
| 189 | ## P predicate register |
| 190 | ## R GPR register |
| 191 | ## M modifier register |
Taylor Simpson | 144da35 | 2021-05-18 16:45:18 -0500 | [diff] [blame] | 192 | ## Q HVX predicate vector |
| 193 | ## V HVX vector register |
| 194 | ## O HVX new vector register |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 195 | ## regid can be one of the following |
| 196 | ## d, e destination register |
| 197 | ## dd destination register pair |
| 198 | ## s, t, u, v, w source register |
| 199 | ## ss, tt, uu, vv source register pair |
| 200 | ## x, y read-write register |
| 201 | ## xx, yy read-write register pair |
| 202 | ## |
Matheus Tavares Bernardino | 3608c24 | 2023-05-24 11:41:47 -0300 | [diff] [blame] | 203 | def get_tagregs(full=False): |
| 204 | compute_func = lambda tag: compute_tag_regs(tag, full) |
| 205 | return dict(zip(tags, list(map(compute_func, tags)))) |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 206 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 207 | def get_tagimms(): |
| 208 | return dict(zip(tags, list(map(compute_tag_immediates, tags)))) |
| 209 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 210 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 211 | def is_pair(regid): |
| 212 | return len(regid) == 2 |
| 213 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 214 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 215 | def is_single(regid): |
| 216 | return len(regid) == 1 |
| 217 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 218 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 219 | def is_written(regid): |
| 220 | return regid[0] in "dexy" |
| 221 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 222 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 223 | def is_writeonly(regid): |
| 224 | return regid[0] in "de" |
| 225 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 226 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 227 | def is_read(regid): |
| 228 | return regid[0] in "stuvwxy" |
| 229 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 230 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 231 | def is_readwrite(regid): |
| 232 | return regid[0] in "xy" |
| 233 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 234 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 235 | def is_scalar_reg(regtype): |
| 236 | return regtype in "RPC" |
| 237 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 238 | |
Taylor Simpson | 144da35 | 2021-05-18 16:45:18 -0500 | [diff] [blame] | 239 | def is_hvx_reg(regtype): |
| 240 | return regtype in "VQ" |
| 241 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 242 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 243 | def is_old_val(regtype, regid, tag): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 244 | return regtype + regid + "V" in semdict[tag] |
| 245 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 246 | |
| 247 | def is_new_val(regtype, regid, tag): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 248 | return regtype + regid + "N" in semdict[tag] |
| 249 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 250 | |
| 251 | def need_slot(tag): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 252 | if ( |
Taylor Simpson | e5d0d78 | 2023-04-27 16:00:11 -0700 | [diff] [blame] | 253 | "A_CVI_SCATTER" not in attribdict[tag] |
| 254 | and "A_CVI_GATHER" not in attribdict[tag] |
| 255 | and ("A_STORE" in attribdict[tag] |
| 256 | or "A_LOAD" in attribdict[tag]) |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 257 | ): |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 258 | return 1 |
| 259 | else: |
| 260 | return 0 |
| 261 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 262 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 263 | def need_part1(tag): |
| 264 | return re.compile(r"fPART1").search(semdict[tag]) |
| 265 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 266 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 267 | def need_ea(tag): |
| 268 | return re.compile(r"\bEA\b").search(semdict[tag]) |
| 269 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 270 | |
Taylor Simpson | 4008590 | 2022-11-08 08:29:00 -0800 | [diff] [blame] | 271 | def need_PC(tag): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 272 | return "A_IMPLICIT_READS_PC" in attribdict[tag] |
| 273 | |
Taylor Simpson | 4008590 | 2022-11-08 08:29:00 -0800 | [diff] [blame] | 274 | |
Taylor Simpson | 613653e | 2022-11-08 08:29:01 -0800 | [diff] [blame] | 275 | def helper_needs_next_PC(tag): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 276 | return "A_CALL" in attribdict[tag] |
| 277 | |
Taylor Simpson | 613653e | 2022-11-08 08:29:01 -0800 | [diff] [blame] | 278 | |
Taylor Simpson | fb67c2b | 2022-11-08 08:28:59 -0800 | [diff] [blame] | 279 | def need_pkt_has_multi_cof(tag): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 280 | return "A_COF" in attribdict[tag] |
| 281 | |
Taylor Simpson | fb67c2b | 2022-11-08 08:28:59 -0800 | [diff] [blame] | 282 | |
Taylor Simpson | d54c561 | 2023-04-27 16:00:02 -0700 | [diff] [blame] | 283 | def need_pkt_need_commit(tag): |
| 284 | return 'A_IMPLICIT_WRITES_USR' in attribdict[tag] |
| 285 | |
Taylor Simpson | e28b77a | 2023-03-06 18:58:26 -0800 | [diff] [blame] | 286 | def need_condexec_reg(tag, regs): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 287 | if "A_CONDEXEC" in attribdict[tag]: |
Matheus Tavares Bernardino | 3608c24 | 2023-05-24 11:41:47 -0300 | [diff] [blame] | 288 | for regtype, regid in regs: |
Taylor Simpson | e28b77a | 2023-03-06 18:58:26 -0800 | [diff] [blame] | 289 | if is_writeonly(regid) and not is_hvx_reg(regtype): |
| 290 | return True |
| 291 | return False |
| 292 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 293 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 294 | def skip_qemu_helper(tag): |
| 295 | return tag in overrides.keys() |
| 296 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 297 | |
Taylor Simpson | 144da35 | 2021-05-18 16:45:18 -0500 | [diff] [blame] | 298 | def is_tmp_result(tag): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 299 | return "A_CVI_TMP" in attribdict[tag] or "A_CVI_TMP_DST" in attribdict[tag] |
| 300 | |
Taylor Simpson | 144da35 | 2021-05-18 16:45:18 -0500 | [diff] [blame] | 301 | |
| 302 | def is_new_result(tag): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 303 | return "A_CVI_NEW" in attribdict[tag] |
| 304 | |
Taylor Simpson | 144da35 | 2021-05-18 16:45:18 -0500 | [diff] [blame] | 305 | |
Alessandro Di Federico | e71fdc4 | 2022-09-23 19:38:30 +0200 | [diff] [blame] | 306 | def is_idef_parser_enabled(tag): |
| 307 | return tag in idef_parser_enabled |
| 308 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 309 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 310 | def imm_name(immlett): |
Marco Liebel | cd6c4ed | 2023-03-20 02:25:32 -0700 | [diff] [blame] | 311 | return f"{immlett}iV" |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 312 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 313 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 314 | def read_semantics_file(name): |
| 315 | eval_line = "" |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 316 | for line in open(name, "rt").readlines(): |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 317 | if not line.startswith("#"): |
| 318 | eval_line += line |
| 319 | if line.endswith("\\\n"): |
| 320 | eval_line.rstrip("\\\n") |
| 321 | else: |
| 322 | eval(eval_line.strip()) |
| 323 | eval_line = "" |
| 324 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 325 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 326 | def read_attribs_file(name): |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 327 | attribre = re.compile( |
| 328 | r"DEF_ATTRIB\(([A-Za-z0-9_]+), ([^,]*), " |
| 329 | + r'"([A-Za-z0-9_\.]*)", "([A-Za-z0-9_\.]*)"\)' |
| 330 | ) |
| 331 | for line in open(name, "rt").readlines(): |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 332 | if not attribre.match(line): |
| 333 | continue |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 334 | (attrib_base, descr, rreg, wreg) = attribre.findall(line)[0] |
| 335 | attrib_base = "A_" + attrib_base |
| 336 | attribinfo[attrib_base] = {"rreg": rreg, "wreg": wreg, "descr": descr} |
| 337 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 338 | |
| 339 | def read_overrides_file(name): |
| 340 | overridere = re.compile("#define fGEN_TCG_([A-Za-z0-9_]+)\(.*") |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 341 | for line in open(name, "rt").readlines(): |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 342 | if not overridere.match(line): |
| 343 | continue |
| 344 | tag = overridere.findall(line)[0] |
| 345 | overrides[tag] = True |
Alessandro Di Federico | e71fdc4 | 2022-09-23 19:38:30 +0200 | [diff] [blame] | 346 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 347 | |
Alessandro Di Federico | e71fdc4 | 2022-09-23 19:38:30 +0200 | [diff] [blame] | 348 | def read_idef_parser_enabled_file(name): |
| 349 | global idef_parser_enabled |
| 350 | with open(name, "r") as idef_parser_enabled_file: |
| 351 | lines = idef_parser_enabled_file.read().strip().split("\n") |
| 352 | idef_parser_enabled = set(lines) |