mirror of
https://github.com/dolphin-emu/gcdsp-ida.git
synced 2026-01-31 01:05:17 +01:00
sas@ never ended up contributing to that project (though he brainstormed the design with me initially). Moved to my @dolphin-emu.org email since this is going to be moved to the dolphin-emu org instead of my own account.
81 lines
2.3 KiB
Python
Executable File
81 lines
2.3 KiB
Python
Executable File
#! /usr/bin/env python2
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
gen_from_tables.py
|
|
|
|
Generate a Python instruction table from the one provided in DSPTables.cpp
|
|
(part of the Dolphin project).
|
|
|
|
Copyright (C) 2011 Pierre Bourdon <delroth@dolphin-emu.org>
|
|
|
|
Licensed under the GPLv2 license, see the LICENSE file at the root of this
|
|
repository.
|
|
"""
|
|
|
|
import ast
|
|
import sys
|
|
|
|
class Modes: # enumeration
|
|
SKIP = 0
|
|
OPCODES = 1
|
|
OPCODES_EXT = 2
|
|
|
|
def full_strip(line):
|
|
"""Strips comments and trailing whitespaces from a line."""
|
|
comment_start = line.find('//')
|
|
if comment_start != -1:
|
|
line = line[:comment_start]
|
|
return line.strip()
|
|
|
|
def gen_from_text(text):
|
|
"""Generates the Python code from the file text."""
|
|
lines = [full_strip(l) for l in text.split('\n')]
|
|
mode = Modes.SKIP
|
|
|
|
opcodes = []
|
|
opcodes_ext = []
|
|
|
|
for line in lines:
|
|
if mode == Modes.SKIP:
|
|
if line == 'const DSPOPCTemplate opcodes[] =':
|
|
mode = Modes.OPCODES
|
|
elif line == 'const DSPOPCTemplate opcodes_ext[] =':
|
|
mode = Modes.OPCODES_EXT
|
|
else:
|
|
if line == '};':
|
|
mode = Modes.SKIP
|
|
elif line == '{' or not line:
|
|
continue
|
|
else:
|
|
fields = line.replace('{', '[').replace('}', ']').split(',')
|
|
fields = fields[0:3] + fields[5:-5] + [fields[-4]]
|
|
fields = map(str.strip, fields)
|
|
fields = ','.join(fields) + ']'
|
|
fields = fields.replace('true', 'True')
|
|
fields = fields.replace('false', 'False')
|
|
fields = fields.replace('P_', 'OpType.')
|
|
if mode == Modes.OPCODES:
|
|
opcodes.append(fields)
|
|
else:
|
|
opcodes_ext.append(fields)
|
|
|
|
print 'opcodes = ['
|
|
print ' ' + ',\n '.join(opcodes)
|
|
print ']'
|
|
print
|
|
print 'opcodes_ext = ['
|
|
print ' ' + ',\n '.join(opcodes_ext)
|
|
print ']'
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) != 2:
|
|
print 'usage: %s /path/to/DSPTables.cpp' % sys.argv[0]
|
|
sys.exit(1)
|
|
|
|
text = open(sys.argv[1]).read()
|
|
|
|
print "#### THIS CODE WAS AUTO-GENERATED BY gen_from_tables.py ####"
|
|
gen_from_text(text)
|
|
print "#### END AUTO-GENERATED CODE ####"
|