From: Jacob Lifshay Date: Thu, 10 Dec 2020 02:12:56 +0000 (-0800) Subject: convert sv_analysis.py to use more standard Markdown tables X-Git-Tag: convert-csv-opcode-to-binary~1444 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ca56ba4893ae8a41a4541acd1d894c6866206a92;p=libreriscv.git convert sv_analysis.py to use more standard Markdown tables --- diff --git a/openpower/sv_analysis.py b/openpower/sv_analysis.py index 87e6dfd78..ec0a442b0 100644 --- a/openpower/sv_analysis.py +++ b/openpower/sv_analysis.py @@ -135,8 +135,13 @@ def dformat(d): return ' '.join(res) -def tformat(d): - return ' | '.join(d) + "|" +def print_table_row(*cols): + print(f"| {' | '.join(cols)} |") + + +def print_table_header(*cols): + print_table_row(*cols) + print_table_row(*map(lambda v: '-'*max(1, len(v)), cols)) def keyname(row): @@ -169,10 +174,10 @@ def process_csvs(): immediates = {} print("# OpenPOWER ISA register 'profile's") - print('') + print() print("this page is auto-generated, do not edit") - print("created by http://libre-soc.org/openpower/sv_analysis.py") - print('') + print("created by https://libre-soc.org/openpower/sv_analysis.py") + print() # Expand that (all .csv files) pth = find_wiki_file("*.csv") @@ -249,48 +254,40 @@ def process_csvs(): 'LDST-3R-1W': 'R/TBD - st*x', # st*x } print("# map to old SV Prefix") - print('') - print('[[!table data="""') + print() + print_table_header("register profile", "old SV Prefix") for key in primarykeys: name = keyname(dictkeys[key]) value = mapsto.get(name, "-") - print(tformat([name, value + " "])) - print('"""]]') - print('') + print_table_row(name, value) + print() print("# keys") - print('') - print('[[!table data="""') - print(tformat(tablecols) + " imms | name |") - + print() + print_table_header(*tablecols, "imms", "name") for key in primarykeys: name = keyname(dictkeys[key]) - row = tformat(dictkeys[key].values()) imms = list(immediates.get(key, "")) imms.sort() - row += " %s | " % ("/".join(imms)) - row += " %s |" % name - print(row) - print('"""]]') - print('') + print_table_row(*dictkeys[key].values(), "/".join(imms), name) + print() for key in primarykeys: name = keyname(dictkeys[key]) value = mapsto.get(name, "-") print("## %s (%s)" % (name, value)) - print('') - print('[[!table data="""') - print(tformat(['CSV', 'opcode', 'asm', 'form'])) + print() + print_table_header('CSV', 'opcode', 'asm', 'form') rows = bykey[key] rows.sort() for row in rows: - print(tformat(row)) - print('"""]]') - print('') + print_table_row(*row) + print() - bykey = {} - for fname, csv in csvs.items(): - key + # TODO(lkcl): what did this do: + # bykey = {} + # for fname, csv in csvs.items(): + # key if __name__ == '__main__':