22
22
import string
23
23
from io import StringIO
24
24
25
- from hex_common import *
25
+ import hex_common
26
26
27
27
##
28
28
## Helpers for gen_helper_function
@@ -59,26 +59,26 @@ def gen_helper_arg_ext_pair(f,regtype,regid,regno):
59
59
f .write ("void *%s%sV_void" % (regtype ,regid ))
60
60
61
61
def gen_helper_arg_opn (f ,regtype ,regid ,i ,tag ):
62
- if (is_pair (regid )):
63
- if (is_hvx_reg (regtype )):
62
+ if (hex_common . is_pair (regid )):
63
+ if (hex_common . is_hvx_reg (regtype )):
64
64
gen_helper_arg_ext_pair (f ,regtype ,regid ,i )
65
65
else :
66
66
gen_helper_arg_pair (f ,regtype ,regid ,i )
67
- elif (is_single (regid )):
68
- if is_old_val (regtype , regid , tag ):
69
- if (is_hvx_reg (regtype )):
67
+ elif (hex_common . is_single (regid )):
68
+ if hex_common . is_old_val (regtype , regid , tag ):
69
+ if (hex_common . is_hvx_reg (regtype )):
70
70
gen_helper_arg_ext (f ,regtype ,regid ,i )
71
71
else :
72
72
gen_helper_arg (f ,regtype ,regid ,i )
73
- elif is_new_val (regtype , regid , tag ):
73
+ elif hex_common . is_new_val (regtype , regid , tag ):
74
74
gen_helper_arg_new (f ,regtype ,regid ,i )
75
75
else :
76
76
print ("Bad register parse: " ,regtype ,regid ,toss ,numregs )
77
77
else :
78
78
print ("Bad register parse: " ,regtype ,regid ,toss ,numregs )
79
79
80
80
def gen_helper_arg_imm (f ,immlett ):
81
- f .write (", int32_t %s" % (imm_name (immlett )))
81
+ f .write (", int32_t %s" % (hex_common . imm_name (immlett )))
82
82
83
83
def gen_helper_dest_decl (f ,regtype ,regid ,regno ,subfield = "" ):
84
84
f .write (" int32_t %s%sV%s = 0;\n " % \
@@ -97,13 +97,13 @@ def gen_helper_dest_decl_ext_pair(f,regtype,regid,regno):
97
97
(regtype ,regid ,regtype , regid ))
98
98
99
99
def gen_helper_dest_decl_opn (f ,regtype ,regid ,i ):
100
- if (is_pair (regid )):
101
- if (is_hvx_reg (regtype )):
100
+ if (hex_common . is_pair (regid )):
101
+ if (hex_common . is_hvx_reg (regtype )):
102
102
gen_helper_dest_decl_ext_pair (f ,regtype ,regid , i )
103
103
else :
104
104
gen_helper_dest_decl_pair (f ,regtype ,regid ,i )
105
- elif (is_single (regid )):
106
- if (is_hvx_reg (regtype )):
105
+ elif (hex_common . is_single (regid )):
106
+ if (hex_common . is_hvx_reg (regtype )):
107
107
gen_helper_dest_decl_ext (f ,regtype ,regid )
108
108
else :
109
109
gen_helper_dest_decl (f ,regtype ,regid ,i )
@@ -133,13 +133,13 @@ def gen_helper_dst_write_ext_pair(f,regtype,regid):
133
133
(regtype ,regid , regtype ,regid ))
134
134
135
135
def gen_helper_return_opn (f , regtype , regid , i ):
136
- if (is_pair (regid )):
137
- if (is_hvx_reg (regtype )):
136
+ if (hex_common . is_pair (regid )):
137
+ if (hex_common . is_hvx_reg (regtype )):
138
138
gen_helper_dst_write_ext_pair (f ,regtype ,regid )
139
139
else :
140
140
gen_helper_return_pair (f ,regtype ,regid ,i )
141
- elif (is_single (regid )):
142
- if (is_hvx_reg (regtype )):
141
+ elif (hex_common . is_single (regid )):
142
+ if (hex_common . is_hvx_reg (regtype )):
143
143
gen_helper_dst_write_ext (f ,regtype ,regid )
144
144
else :
145
145
gen_helper_return (f ,regtype ,regid ,i )
@@ -167,12 +167,12 @@ def gen_helper_function(f, tag, tagregs, tagimms):
167
167
numscalarresults = 0
168
168
numscalarreadwrite = 0
169
169
for regtype ,regid ,toss ,numregs in regs :
170
- if (is_written (regid )):
170
+ if (hex_common . is_written (regid )):
171
171
numresults += 1
172
- if (is_scalar_reg (regtype )):
172
+ if (hex_common . is_scalar_reg (regtype )):
173
173
numscalarresults += 1
174
- if (is_readwrite (regid )):
175
- if (is_scalar_reg (regtype )):
174
+ if (hex_common . is_readwrite (regid )):
175
+ if (hex_common . is_scalar_reg (regtype )):
176
176
numscalarreadwrite += 1
177
177
178
178
if (numscalarresults > 1 ):
@@ -184,14 +184,14 @@ def gen_helper_function(f, tag, tagregs, tagimms):
184
184
## register (if scalar)
185
185
i = 0
186
186
for regtype ,regid ,toss ,numregs in regs :
187
- if (is_written (regid )):
188
- if (is_pair (regid )):
189
- if (is_hvx_reg (regtype )):
187
+ if (hex_common . is_written (regid )):
188
+ if (hex_common . is_pair (regid )):
189
+ if (hex_common . is_hvx_reg (regtype )):
190
190
continue
191
191
else :
192
192
gen_helper_return_type_pair (f ,regtype ,regid ,i )
193
- elif (is_single (regid )):
194
- if (is_hvx_reg (regtype )):
193
+ elif (hex_common . is_single (regid )):
194
+ if (hex_common . is_hvx_reg (regtype )):
195
195
continue
196
196
else :
197
197
gen_helper_return_type (f ,regtype ,regid ,i )
@@ -206,14 +206,14 @@ def gen_helper_function(f, tag, tagregs, tagimms):
206
206
## Arguments include the vector destination operands
207
207
i = 1
208
208
for regtype ,regid ,toss ,numregs in regs :
209
- if (is_written (regid )):
210
- if (is_pair (regid )):
211
- if (is_hvx_reg (regtype )):
209
+ if (hex_common . is_written (regid )):
210
+ if (hex_common . is_pair (regid )):
211
+ if (hex_common . is_hvx_reg (regtype )):
212
212
gen_helper_arg_ext_pair (f ,regtype ,regid ,i )
213
213
else :
214
214
continue
215
- elif (is_single (regid )):
216
- if (is_hvx_reg (regtype )):
215
+ elif (hex_common . is_single (regid )):
216
+ if (hex_common . is_hvx_reg (regtype )):
217
217
gen_helper_arg_ext (f ,regtype ,regid ,i )
218
218
else :
219
219
# This is the return value of the function
@@ -224,75 +224,76 @@ def gen_helper_function(f, tag, tagregs, tagimms):
224
224
225
225
## Arguments to the helper function are the source regs and immediates
226
226
for regtype ,regid ,toss ,numregs in regs :
227
- if (is_read (regid )):
228
- if (is_hvx_reg (regtype ) and is_readwrite (regid )):
227
+ if (hex_common .is_read (regid )):
228
+ if (hex_common .is_hvx_reg (regtype ) and
229
+ hex_common .is_readwrite (regid )):
229
230
continue
230
231
gen_helper_arg_opn (f ,regtype ,regid ,i ,tag )
231
232
i += 1
232
233
for immlett ,bits ,immshift in imms :
233
234
gen_helper_arg_imm (f ,immlett )
234
235
i += 1
235
- if need_slot (tag ):
236
+ if hex_common . need_slot (tag ):
236
237
if i > 0 : f .write (", " )
237
238
f .write ("uint32_t slot" )
238
239
i += 1
239
- if need_part1 (tag ):
240
+ if hex_common . need_part1 (tag ):
240
241
if i > 0 : f .write (", " )
241
242
f .write ("uint32_t part1" )
242
243
f .write (")\n {\n " )
243
- if (not need_slot (tag )):
244
+ if (not hex_common . need_slot (tag )):
244
245
f .write (" uint32_t slot __attribute__((unused)) = 4;\n " )
245
- if need_ea (tag ): gen_decl_ea (f )
246
+ if hex_common . need_ea (tag ): gen_decl_ea (f )
246
247
## Declare the return variable
247
248
i = 0
248
249
for regtype ,regid ,toss ,numregs in regs :
249
- if (is_writeonly (regid )):
250
+ if (hex_common . is_writeonly (regid )):
250
251
gen_helper_dest_decl_opn (f ,regtype ,regid ,i )
251
252
i += 1
252
253
253
254
for regtype ,regid ,toss ,numregs in regs :
254
- if (is_read (regid )):
255
- if (is_pair (regid )):
256
- if (is_hvx_reg (regtype )):
255
+ if (hex_common . is_read (regid )):
256
+ if (hex_common . is_pair (regid )):
257
+ if (hex_common . is_hvx_reg (regtype )):
257
258
gen_helper_src_var_ext_pair (f ,regtype ,regid ,i )
258
- elif (is_single (regid )):
259
- if (is_hvx_reg (regtype )):
259
+ elif (hex_common . is_single (regid )):
260
+ if (hex_common . is_hvx_reg (regtype )):
260
261
gen_helper_src_var_ext (f ,regtype ,regid )
261
262
else :
262
263
print ("Bad register parse: " ,regtype ,regid ,toss ,numregs )
263
264
264
- if 'A_FPOP' in attribdict [tag ]:
265
+ if 'A_FPOP' in hex_common . attribdict [tag ]:
265
266
f .write (' arch_fpop_start(env);\n ' );
266
267
267
- f .write (" %s\n " % semdict [tag ])
268
+ f .write (" %s\n " % hex_common . semdict [tag ])
268
269
f .write (" COUNT_HELPER(%s);\n " % tag )
269
270
270
- if 'A_FPOP' in attribdict [tag ]:
271
+ if 'A_FPOP' in hex_common . attribdict [tag ]:
271
272
f .write (' arch_fpop_end(env);\n ' );
272
273
273
274
## Save/return the return variable
274
275
for regtype ,regid ,toss ,numregs in regs :
275
- if (is_written (regid )):
276
+ if (hex_common . is_written (regid )):
276
277
gen_helper_return_opn (f , regtype , regid , i )
277
278
f .write ("}\n \n " )
278
279
## End of the helper definition
279
280
280
281
def main ():
281
- read_semantics_file (sys .argv [1 ])
282
- read_attribs_file (sys .argv [2 ])
283
- read_overrides_file (sys .argv [3 ])
284
- calculate_attribs ()
285
- tagregs = get_tagregs ()
286
- tagimms = get_tagimms ()
282
+ hex_common . read_semantics_file (sys .argv [1 ])
283
+ hex_common . read_attribs_file (sys .argv [2 ])
284
+ hex_common . read_overrides_file (sys .argv [3 ])
285
+ hex_common . calculate_attribs ()
286
+ tagregs = hex_common . get_tagregs ()
287
+ tagimms = hex_common . get_tagimms ()
287
288
288
289
f = StringIO ()
289
290
290
- for tag in tags :
291
+ for tag in hex_common . tags :
291
292
## Skip the priv instructions
292
- if ( "A_PRIV" in attribdict [tag ] ) :
293
+ if ( "A_PRIV" in hex_common . attribdict [tag ] ) :
293
294
continue
294
295
## Skip the guest instructions
295
- if ( "A_GUEST" in attribdict [tag ] ) :
296
+ if ( "A_GUEST" in hex_common . attribdict [tag ] ) :
296
297
continue
297
298
## Skip the diag instructions
298
299
if ( tag == "Y6_diag" ) :
@@ -301,7 +302,7 @@ def main():
301
302
continue
302
303
if ( tag == "Y6_diag1" ) :
303
304
continue
304
- if ( skip_qemu_helper (tag ) ):
305
+ if ( hex_common . skip_qemu_helper (tag ) ):
305
306
continue
306
307
307
308
gen_helper_function (f , tag , tagregs , tagimms )
0 commit comments