Skip to content

Commit

Permalink
Generate JSON instead of YAML
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Timmmm committed Oct 28, 2024
1 parent 25c09e6 commit b56d23a
Show file tree
Hide file tree
Showing 13 changed files with 12 additions and 38 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ priv-instr-table.tex
inst.rs
inst.spinalhdl
inst.sverilog
instr_dict.yaml
instr_dict.json

__pycache__/
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 file generated always 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
Expand All @@ -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:

```
Expand Down Expand Up @@ -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*<instr-name>" rv* unratified/rv*` OR run `make` and open
`instr_dict.yaml` and search of the instruction you are looking for. Within that
`instr_dict.json` and search of the instruction you are looking for. Within that
instruction the `extension` field will indicate which file the instruction was
picked from.
2 changes: 0 additions & 2 deletions c_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *

Expand Down
2 changes: 0 additions & 2 deletions chisel_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions go_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *

Expand Down
2 changes: 0 additions & 2 deletions latex_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import re
import sys

import yaml

from constants import *
from shared_utils import *

Expand Down
7 changes: 3 additions & 4 deletions parse.py
Original file line number Diff line number Diff line change
@@ -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 *
Expand Down Expand Up @@ -46,8 +45,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:]:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

2 changes: 0 additions & 2 deletions rust_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions sverilog_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *

Expand Down

0 comments on commit b56d23a

Please sign in to comment.