mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-30 22:03:54 -06:00
Use black code style for python scripts
Signed-off-by: Marco Liebel <quic_mliebel@quicinc.com> Signed-off-by: Taylor Simpson <tsimpson@quicinc.com> Acked-by: Taylor Simpson <tsimpson@quicinc.com> Tested-by: Taylor Simpson <tsimpson@quicinc.com> Message-Id: <20230320092533.2859433-3-quic_mliebel@quicinc.com>
This commit is contained in:
parent
cd6c4edff6
commit
5bb322e2a8
13 changed files with 1191 additions and 911 deletions
|
@ -26,32 +26,34 @@ import hex_common
|
|||
## Helpers for gen_helper_prototype
|
||||
##
|
||||
def_helper_types = {
|
||||
'N' : 's32',
|
||||
'O' : 's32',
|
||||
'P' : 's32',
|
||||
'M' : 's32',
|
||||
'C' : 's32',
|
||||
'R' : 's32',
|
||||
'V' : 'ptr',
|
||||
'Q' : 'ptr'
|
||||
"N": "s32",
|
||||
"O": "s32",
|
||||
"P": "s32",
|
||||
"M": "s32",
|
||||
"C": "s32",
|
||||
"R": "s32",
|
||||
"V": "ptr",
|
||||
"Q": "ptr",
|
||||
}
|
||||
|
||||
def_helper_types_pair = {
|
||||
'R' : 's64',
|
||||
'C' : 's64',
|
||||
'S' : 's64',
|
||||
'G' : 's64',
|
||||
'V' : 'ptr',
|
||||
'Q' : 'ptr'
|
||||
"R": "s64",
|
||||
"C": "s64",
|
||||
"S": "s64",
|
||||
"G": "s64",
|
||||
"V": "ptr",
|
||||
"Q": "ptr",
|
||||
}
|
||||
|
||||
|
||||
def gen_def_helper_opn(f, tag, regtype, regid, toss, numregs, i):
|
||||
if (hex_common.is_pair(regid)):
|
||||
if hex_common.is_pair(regid):
|
||||
f.write(f", {def_helper_types_pair[regtype]}")
|
||||
elif (hex_common.is_single(regid)):
|
||||
elif hex_common.is_single(regid):
|
||||
f.write(f", {def_helper_types[regtype]}")
|
||||
else:
|
||||
print("Bad register parse: ",regtype,regid,toss,numregs)
|
||||
print("Bad register parse: ", regtype, regid, toss, numregs)
|
||||
|
||||
|
||||
##
|
||||
## Generate the DEF_HELPER prototype for an instruction
|
||||
|
@ -66,90 +68,108 @@ def gen_helper_prototype(f, tag, tagregs, tagimms):
|
|||
numresults = 0
|
||||
numscalarresults = 0
|
||||
numscalarreadwrite = 0
|
||||
for regtype,regid,toss,numregs in regs:
|
||||
if (hex_common.is_written(regid)):
|
||||
for regtype, regid, toss, numregs in regs:
|
||||
if hex_common.is_written(regid):
|
||||
numresults += 1
|
||||
if (hex_common.is_scalar_reg(regtype)):
|
||||
if hex_common.is_scalar_reg(regtype):
|
||||
numscalarresults += 1
|
||||
if (hex_common.is_readwrite(regid)):
|
||||
if (hex_common.is_scalar_reg(regtype)):
|
||||
if hex_common.is_readwrite(regid):
|
||||
if hex_common.is_scalar_reg(regtype):
|
||||
numscalarreadwrite += 1
|
||||
|
||||
if (numscalarresults > 1):
|
||||
if numscalarresults > 1:
|
||||
## The helper is bogus when there is more than one result
|
||||
f.write(f'DEF_HELPER_1({tag}, void, env)\n')
|
||||
f.write(f"DEF_HELPER_1({tag}, void, env)\n")
|
||||
else:
|
||||
## Figure out how many arguments the helper will take
|
||||
if (numscalarresults == 0):
|
||||
def_helper_size = len(regs)+len(imms)+numscalarreadwrite+1
|
||||
if hex_common.need_pkt_has_multi_cof(tag): def_helper_size += 1
|
||||
if hex_common.need_part1(tag): def_helper_size += 1
|
||||
if hex_common.need_slot(tag): def_helper_size += 1
|
||||
if hex_common.need_PC(tag): def_helper_size += 1
|
||||
if hex_common.helper_needs_next_PC(tag): def_helper_size += 1
|
||||
if hex_common.need_condexec_reg(tag, regs): def_helper_size += 1
|
||||
f.write(f'DEF_HELPER_{def_helper_size}({tag}')
|
||||
if numscalarresults == 0:
|
||||
def_helper_size = len(regs) + len(imms) + numscalarreadwrite + 1
|
||||
if hex_common.need_pkt_has_multi_cof(tag):
|
||||
def_helper_size += 1
|
||||
if hex_common.need_part1(tag):
|
||||
def_helper_size += 1
|
||||
if hex_common.need_slot(tag):
|
||||
def_helper_size += 1
|
||||
if hex_common.need_PC(tag):
|
||||
def_helper_size += 1
|
||||
if hex_common.helper_needs_next_PC(tag):
|
||||
def_helper_size += 1
|
||||
if hex_common.need_condexec_reg(tag, regs):
|
||||
def_helper_size += 1
|
||||
f.write(f"DEF_HELPER_{def_helper_size}({tag}")
|
||||
## The return type is void
|
||||
f.write(', void' )
|
||||
f.write(", void")
|
||||
else:
|
||||
def_helper_size = len(regs)+len(imms)+numscalarreadwrite
|
||||
if hex_common.need_pkt_has_multi_cof(tag): def_helper_size += 1
|
||||
if hex_common.need_part1(tag): def_helper_size += 1
|
||||
if hex_common.need_slot(tag): def_helper_size += 1
|
||||
if hex_common.need_PC(tag): def_helper_size += 1
|
||||
if hex_common.need_condexec_reg(tag, regs): def_helper_size += 1
|
||||
if hex_common.helper_needs_next_PC(tag): def_helper_size += 1
|
||||
f.write(f'DEF_HELPER_{def_helper_size}({tag}')
|
||||
def_helper_size = len(regs) + len(imms) + numscalarreadwrite
|
||||
if hex_common.need_pkt_has_multi_cof(tag):
|
||||
def_helper_size += 1
|
||||
if hex_common.need_part1(tag):
|
||||
def_helper_size += 1
|
||||
if hex_common.need_slot(tag):
|
||||
def_helper_size += 1
|
||||
if hex_common.need_PC(tag):
|
||||
def_helper_size += 1
|
||||
if hex_common.need_condexec_reg(tag, regs):
|
||||
def_helper_size += 1
|
||||
if hex_common.helper_needs_next_PC(tag):
|
||||
def_helper_size += 1
|
||||
f.write(f"DEF_HELPER_{def_helper_size}({tag}")
|
||||
|
||||
## Generate the qemu DEF_HELPER type for each result
|
||||
## Iterate over this list twice
|
||||
## - Emit the scalar result
|
||||
## - Emit the vector result
|
||||
i=0
|
||||
for regtype,regid,toss,numregs in regs:
|
||||
if (hex_common.is_written(regid)):
|
||||
if (not hex_common.is_hvx_reg(regtype)):
|
||||
i = 0
|
||||
for regtype, regid, toss, numregs in regs:
|
||||
if hex_common.is_written(regid):
|
||||
if not hex_common.is_hvx_reg(regtype):
|
||||
gen_def_helper_opn(f, tag, regtype, regid, toss, numregs, i)
|
||||
i += 1
|
||||
|
||||
## Put the env between the outputs and inputs
|
||||
f.write(', env' )
|
||||
f.write(", env")
|
||||
i += 1
|
||||
|
||||
# Second pass
|
||||
for regtype,regid,toss,numregs in regs:
|
||||
if (hex_common.is_written(regid)):
|
||||
if (hex_common.is_hvx_reg(regtype)):
|
||||
for regtype, regid, toss, numregs in regs:
|
||||
if hex_common.is_written(regid):
|
||||
if hex_common.is_hvx_reg(regtype):
|
||||
gen_def_helper_opn(f, tag, regtype, regid, toss, numregs, i)
|
||||
i += 1
|
||||
|
||||
## For conditional instructions, we pass in the destination register
|
||||
if 'A_CONDEXEC' in hex_common.attribdict[tag]:
|
||||
if "A_CONDEXEC" in hex_common.attribdict[tag]:
|
||||
for regtype, regid, toss, numregs in regs:
|
||||
if (hex_common.is_writeonly(regid) and
|
||||
not hex_common.is_hvx_reg(regtype)):
|
||||
if hex_common.is_writeonly(regid) and not hex_common.is_hvx_reg(
|
||||
regtype
|
||||
):
|
||||
gen_def_helper_opn(f, tag, regtype, regid, toss, numregs, i)
|
||||
i += 1
|
||||
|
||||
## Generate the qemu type for each input operand (regs and immediates)
|
||||
for regtype,regid,toss,numregs in regs:
|
||||
if (hex_common.is_read(regid)):
|
||||
if (hex_common.is_hvx_reg(regtype) and
|
||||
hex_common.is_readwrite(regid)):
|
||||
for regtype, regid, toss, numregs in regs:
|
||||
if hex_common.is_read(regid):
|
||||
if hex_common.is_hvx_reg(regtype) and hex_common.is_readwrite(regid):
|
||||
continue
|
||||
gen_def_helper_opn(f, tag, regtype, regid, toss, numregs, i)
|
||||
i += 1
|
||||
for immlett,bits,immshift in imms:
|
||||
for immlett, bits, immshift in imms:
|
||||
f.write(", s32")
|
||||
|
||||
## Add the arguments for the instruction pkt_has_multi_cof, slot and
|
||||
## part1 (if needed)
|
||||
if hex_common.need_pkt_has_multi_cof(tag): f.write(', i32')
|
||||
if hex_common.need_PC(tag): f.write(', i32')
|
||||
if hex_common.helper_needs_next_PC(tag): f.write(', i32')
|
||||
if hex_common.need_slot(tag): f.write(', i32' )
|
||||
if hex_common.need_part1(tag): f.write(' , i32' )
|
||||
f.write(')\n')
|
||||
if hex_common.need_pkt_has_multi_cof(tag):
|
||||
f.write(", i32")
|
||||
if hex_common.need_PC(tag):
|
||||
f.write(", i32")
|
||||
if hex_common.helper_needs_next_PC(tag):
|
||||
f.write(", i32")
|
||||
if hex_common.need_slot(tag):
|
||||
f.write(", i32")
|
||||
if hex_common.need_part1(tag):
|
||||
f.write(" , i32")
|
||||
f.write(")\n")
|
||||
|
||||
|
||||
def main():
|
||||
hex_common.read_semantics_file(sys.argv[1])
|
||||
|
@ -173,28 +193,29 @@ def main():
|
|||
tagimms = hex_common.get_tagimms()
|
||||
|
||||
output_file = sys.argv[-1]
|
||||
with open(output_file, 'w') as f:
|
||||
with open(output_file, "w") as f:
|
||||
for tag in hex_common.tags:
|
||||
## Skip the priv instructions
|
||||
if ( "A_PRIV" in hex_common.attribdict[tag] ) :
|
||||
if "A_PRIV" in hex_common.attribdict[tag]:
|
||||
continue
|
||||
## Skip the guest instructions
|
||||
if ( "A_GUEST" in hex_common.attribdict[tag] ) :
|
||||
if "A_GUEST" in hex_common.attribdict[tag]:
|
||||
continue
|
||||
## Skip the diag instructions
|
||||
if ( tag == "Y6_diag" ) :
|
||||
if tag == "Y6_diag":
|
||||
continue
|
||||
if ( tag == "Y6_diag0" ) :
|
||||
if tag == "Y6_diag0":
|
||||
continue
|
||||
if ( tag == "Y6_diag1" ) :
|
||||
if tag == "Y6_diag1":
|
||||
continue
|
||||
|
||||
if ( hex_common.skip_qemu_helper(tag) ):
|
||||
if hex_common.skip_qemu_helper(tag):
|
||||
continue
|
||||
if ( hex_common.is_idef_parser_enabled(tag) ):
|
||||
if hex_common.is_idef_parser_enabled(tag):
|
||||
continue
|
||||
|
||||
gen_helper_prototype(f, tag, tagregs, tagimms)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue