From 9f61bf9b1a23f6b5558a055aeaf19b303a9e0dcf Mon Sep 17 00:00:00 2001 From: Tim Hutt Date: Tue, 29 Oct 2024 21:11:41 +0000 Subject: [PATCH] Generate JSON instead of YAML Previously this generate a `instr_dict.yaml` file, however there is no need to use YAML here. The only advantages of YAML over JSON are that it is (debatably) easier for humans to write, making it suitable as human-edited input files. This is a machine-generated output file so JSON is better. The main advantages are: 1. It removes the dependency on PyYAML, which is the only external dependency of this project. Python external dependencies are quite a pain - PyYAML is a particularly troublesome one - and having no dependencies is very convenient (no need for venv etc.). 2. It means consumers of the file don't need to depend on PyYAML. Note this could have been done in an 100% backwards compatible way by keeping the file name unchanged (since JSON is valid YAML), however I figured there probably aren't that many users of this file, and since the only thing they need to change is the filename it's probably better to minimise confusion by renaming it. It also makes it clear that it is guaranteed to be JSON. --- .github/workflows/python-app.yml | 3 +-- .github/workflows/tests.yml | 3 +-- .gitignore | 2 +- .pre-commit-config.yaml | 4 ---- README.md | 22 ++++++++-------------- c_utils.py | 2 -- chisel_utils.py | 2 -- go_utils.py | 2 -- latex_utils.py | 2 -- parse.py | 7 +++---- requirements.txt | 1 - rust_utils.py | 2 -- sverilog_utils.py | 2 -- 13 files changed, 14 insertions(+), 40 deletions(-) delete mode 100644 requirements.txt diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 4aac843c..95c39fad 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -15,9 +15,8 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.8 - - name: Install PyYAML + - name: Install Coverage run: | - pip3 install -r requirements.txt pip3 install coverage - name: Run pre-commit run: | diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a30716ac..0eb0c898 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,9 +15,8 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.8 - - name: Install PyYAML + - name: Install Coverage run: | - pip3 install -r requirements.txt pip3 install coverage - name: Test error outputs run: coverage run -m unittest -b diff --git a/.gitignore b/.gitignore index 4ddba6b5..13806158 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,6 @@ priv-instr-table.tex inst.rs inst.spinalhdl inst.sverilog -instr_dict.yaml +instr_dict.json __pycache__/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cca4b3b9..61540b13 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,13 +26,9 @@ repos: # rev: v3.3.1 # hooks: # - id: pylint - # additional_dependencies: - # - "pyyaml==6.0.2" # TODO: Enable this when types are added. # - repo: https://github.com/RobertCraigie/pyright-python # rev: v1.1.383 # hooks: # - id: pyright - # additional_dependencies: - # - "pyyaml==6.0.2" diff --git a/README.md b/README.md index e6702ed6..e7a988cc 100644 --- a/README.md +++ b/README.md @@ -126,9 +126,11 @@ of extensions are being processed such that the *base-instruction* is not includ The following artifacts can be generated using parse.py: -- instr\_dict.yaml : This is file generated always by parse.py and contains the - entire main dictionary `instr\_dict` in YAML format. Note, in this yaml the - *dots* in an instruction are replaced with *underscores* +- instr\_dict.json : This is always generated by parse.py and contains the + entire main dictionary `instr\_dict` in JSON format. Note, in this file the + *dots* in an instruction are replaced with *underscores*. In previous + versions of this project the generated file was instr\_dict.yaml. Note that + JSON is a subset of YAML so the file can still be read by any YAML parser. - encoding.out.h : this is the header file that is used by tools like spike, pk, etc - instr-table.tex : the latex table of instructions used in the riscv-unpriv spec - priv-instr-table.tex : the latex table of instruction used in the riscv-priv spec @@ -138,14 +140,6 @@ The following artifacts can be generated using parse.py: - inst.spinalhdl : spinalhdl code to decode instructions - inst.go : go code to decode instructions -Make sure you install the required python pre-requisites are installed by executing the following -command: - -``` -sudo apt-get install python-pip3 -pip3 install -r requirements.txt -``` - To generate all the above artifacts for all instructions currently checked in, simply run `make` from the root-directory. This should print the following log on the command-line: ``` @@ -220,6 +214,6 @@ DEBUG:: Processing line: bne bimm12hi rs1 rs2 bimm12lo 14..12=1 6..2=0x ## How do I find where an instruction is defined? You can use `grep "^\s*" rv* unratified/rv*` OR run `make` and open -`instr_dict.yaml` and search of the instruction you are looking for. Within that -instruction the `extension` field will indicate which file the instruction was -picked from. +`instr_dict.json` and search for the instruction you are looking for. Within +that instruction the `extension` field will indicate which file the +instruction was picked from. diff --git a/c_utils.py b/c_utils.py index cff33dd8..d2e2775d 100644 --- a/c_utils.py +++ b/c_utils.py @@ -6,8 +6,6 @@ import re import sys -import yaml - # from shared_utils import overlaps, overlap_allowed, extension_overlap_allowed, instruction_overlap_allowed, process_enc_line, same_base_isa, add_segmented_vls_insn, expand_nf_field from shared_utils import * diff --git a/chisel_utils.py b/chisel_utils.py index 957e4f8a..f9c66f6d 100644 --- a/chisel_utils.py +++ b/chisel_utils.py @@ -7,8 +7,6 @@ import re import sys -import yaml - from constants import * # from shared_utils import overlaps, overlap_allowed, extension_overlap_allowed, instruction_overlap_allowed, process_enc_line, same_base_isa, add_segmented_vls_insn, expand_nf_field diff --git a/go_utils.py b/go_utils.py index 1f4c94bb..af952eab 100644 --- a/go_utils.py +++ b/go_utils.py @@ -6,8 +6,6 @@ import re import sys -import yaml - # from shared_utils import overlaps, overlap_allowed, extension_overlap_allowed, instruction_overlap_allowed, process_enc_line, same_base_isa, add_segmented_vls_insn, expand_nf_field from shared_utils import * diff --git a/latex_utils.py b/latex_utils.py index ab5f6f92..be009019 100644 --- a/latex_utils.py +++ b/latex_utils.py @@ -7,8 +7,6 @@ import re import sys -import yaml - from constants import * from shared_utils import * diff --git a/parse.py b/parse.py index 9677ed6d..4152fe06 100755 --- a/parse.py +++ b/parse.py @@ -1,11 +1,10 @@ #!/usr/bin/env python3 import collections +import json import logging import pprint import sys -import yaml - from c_utils import * from chisel_utils import * from constants import * @@ -44,8 +43,8 @@ instr_dict = create_inst_dict(extensions, include_pseudo) - with open("instr_dict.yaml", "w") as outfile: - yaml.dump(add_segmented_vls_insn(instr_dict), outfile, default_flow_style=False) + with open("instr_dict.json", "w") as outfile: + json.dump(add_segmented_vls_insn(instr_dict), outfile, indent=2) instr_dict = collections.OrderedDict(sorted(instr_dict.items())) if "-c" in sys.argv[1:]: diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index c3726e8b..00000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -pyyaml diff --git a/rust_utils.py b/rust_utils.py index 19a47b95..4a0c1286 100644 --- a/rust_utils.py +++ b/rust_utils.py @@ -7,8 +7,6 @@ import re import sys -import yaml - from constants import * # from shared_utils import overlaps, overlap_allowed, extension_overlap_allowed, instruction_overlap_allowed, process_enc_line, same_base_isa, add_segmented_vls_insn, expand_nf_field diff --git a/sverilog_utils.py b/sverilog_utils.py index 1fe20680..afe04d4d 100644 --- a/sverilog_utils.py +++ b/sverilog_utils.py @@ -6,8 +6,6 @@ import re import sys -import yaml - # from shared_utils import overlaps, overlap_allowed, extension_overlap_allowed, instruction_overlap_allowed, process_enc_line, same_base_isa, add_segmented_vls_insn, expand_nf_field from shared_utils import *