4 ## Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
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.
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.
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/>.
26 ## Generate data for printing each instruction (format string + operands)
30 str += ":".join(["%d"]*len(m
.group(2)))
32 if ('S' in m
.group(1)) and (len(m
.group(2)) == 1):
34 elif ('C' in m
.group(1)) and (len(m
.group(2)) == 1):
39 # Regular expression that matches any operator that contains '=' character:
40 opswithequal_re
= '[-+^&|!<>=]?='
41 # Regular expression that matches any assignment operator.
42 assignment_re
= '[-+^&|]?='
44 # Out of the operators that contain the = sign, if the operator is also an
45 # assignment, spaces will be added around it, unless it's enclosed within
46 # parentheses, or spaces are already present.
48 equals
= re
.compile(opswithequal_re
)
49 assign
= re
.compile(assignment_re
)
64 # Iterate over all operators that contain the equal sign. If any
65 # match is also an assignment operator, add spaces around it if
66 # the parenthesis count is 0.
69 for m
in equals
.finditer(s
):
72 # t is the string that matched opswithequal_re.
76 if paren_count
[ms
] == 0:
77 # Check if the entire string t is an assignment.
79 if am
and len(am
.group(0)) == me
-ms
:
80 # Don't add spaces if they are already there.
81 if ms
> 0 and s
[ms
-1] != ' ':
84 if me
< slen
and s
[me
] != ' ':
87 # If this is not an assignment, just append it to the output
91 # Append the remaining part of the string.
96 hex_common
.read_semantics_file(sys
.argv
[1])
97 hex_common
.read_attribs_file(sys
.argv
[2])
99 immext_casere
= re
.compile(r
'IMMEXT\(([A-Za-z])')
101 with
open(sys
.argv
[3], 'w') as f
:
102 for tag
in hex_common
.tags
:
103 if not hex_common
.behdict
[tag
]: continue
104 extendable_upper_imm
= False
105 extendable_lower_imm
= False
106 m
= immext_casere
.search(hex_common
.semdict
[tag
])
108 if m
.group(1).isupper():
109 extendable_upper_imm
= True
111 extendable_lower_imm
= True
112 beh
= hex_common
.behdict
[tag
]
113 beh
= hex_common
.regre
.sub(regprinter
,beh
)
114 beh
= hex_common
.absimmre
.sub(r
"#%s0x%x",beh
)
115 beh
= hex_common
.relimmre
.sub(r
"PC+%s%d",beh
)
117 # Print out a literal "%s" at the end, used to match empty string
118 # so C won't complain at us
119 if ("A_VECX" in hex_common
.attribdict
[tag
]):
120 macname
= "DEF_VECX_PRINTINFO"
121 else: macname
= "DEF_PRINTINFO"
122 f
.write('%s(%s,"%s%%s"' % (macname
,tag
,beh
))
124 hex_common
.reg_or_immre
.findall(hex_common
.behdict
[tag
])
127 for allregs
,a
,b
,c
,d
,allimm
,immlett
,bits
,immshift
in regs_or_imms
:
135 f
.write(', insn->regno[%d]' % regno
)
137 f
.write(', sreg2str(insn->regno[%d])' % regno
)
139 f
.write(', creg2str(insn->regno[%d])' % regno
)
141 f
.write(', insn->regno[%d] + 1, insn->regno[%d]' % \
144 print("Put some stuff to handle quads here")
145 if b
not in seenregs
:
150 if (immlett
.isupper()):
151 if extendable_upper_imm
:
153 f
.write(',insn->extension_valid?"##":""')
155 f
.write(',insn->extension_valid?"#":""')
160 if extendable_lower_imm
:
162 f
.write(',insn->extension_valid?"##":""')
164 f
.write(',insn->extension_valid?"#":""')
168 f
.write(', insn->immed[%d]' % ii
)
169 # append empty string so there is at least one more arg
172 if __name__
== "__main__":