MCPcopy Create free account
hub / github.com/Inori/GPCS4 / WriteOpFormat

Function WriteOpFormat

Tools/ParseOpcode.py:313–359  ·  view source on GitHub ↗
(op_dic)

Source from the content-addressed store, hash-verified

311
312
313def WriteOpFormat(op_dic):
314 dst = open('OpFormat.cpp', 'w')
315
316 for encoding, op_list in op_dic.items():
317
318 array_size = GetArraySize(op_list)
319
320 dst.write('const std::array<GcnInstFormat, {}> g_instructionFormat{} = {{{{\n'.format(array_size, encoding.replace('GCNENC_', '')))
321
322 struct_array = ['\t{ },'] * array_size
323 for opcode, value, mode in op_list:
324 op_key = GetOpKey(encoding, opcode)
325
326 if not op_key in InstDefDic:
327 #print('inst not found: {}'.format(op_key))
328 continue
329
330 inst_info = InstDefDic[op_key]
331 cls = inst_info[0]
332 src_count = DefaultSrcCountTable[encoding]
333 dst_type, src_type = ParseOpType(opcode)
334 src_type = GetScalarType(src_type)
335 dst_type = GetScalarType(dst_type)
336 category = GetInstCategory(cls)
337
338 if 'GCN_SRC_NONE' in mode:
339 src_count = 0
340 if 'GCN_SRC2_NONE' in mode:
341 src_count -= 1
342 if 'GCN_VOP3_VOP2_DS01' in mode:
343 src_count = 2
344 if 'GCN_VOP3_VOP1_DS0' in mode:
345 src_count = 1
346 if 'GCN_VOP_ARG_NONE' in mode:
347 src_count = 0
348 # VOPC in VOP3, specify 2 src operands
349 if encoding == 'GCNENC_VOP3' and (value >= 0 and value <= 247):
350 src_count = 2
351
352 code_line = '\t// {} = {}\n\t{{ GcnInstClass::{}, GcnInstCategory::{}, {}, {},\n\t\tGcnScalarType::{}, GcnScalarType::{} }},'.\
353 format(value, opcode, cls, category, src_count, 1, src_type, dst_type)
354 struct_array[value] = code_line
355
356 dst.write('\n'.join(struct_array))
357 dst.write('\n}};\n\n\n')
358
359 dst.close()
360
361def WriteOpEnum(op_dic):
362 dst = open('OpEnum.cpp', 'w')

Callers 1

ProcessOpcodesFunction · 0.85

Calls 9

GetArraySizeFunction · 0.85
GetOpKeyFunction · 0.85
ParseOpTypeFunction · 0.85
GetScalarTypeFunction · 0.85
GetInstCategoryFunction · 0.85
replaceMethod · 0.80
writeMethod · 0.45
formatMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected