Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Move utility files to utils folder #319

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,37 @@ make EXTENSIONS='rv*_i rv*_m'
Which will print the following log:

```
Running with args : ['./parse.py', '-c', '-chisel', '-sverilog', '-rust', '-latex', 'rv32_i', 'rv64_i', 'rv_i', 'rv64_m', 'rv_m']
Running with args : ['./parse.py', '-c', '-go', '-chisel', '-sverilog', '-rust', '-latex', '-spinalhdl', 'rv32_i', 'rv64_i', 'rv_i', 'rv64_m', 'rv_m']
Extensions selected : ['rv32_i', 'rv64_i', 'rv_i', 'rv64_m', 'rv_m']
INFO:: encoding.out.h generated successfully
INFO:: inst.chisel generated successfully
INFO:: inst.spinalhdl generated successfully
INFO:: inst.sverilog generated successfully
INFO:: inst.rs generated successfully
INFO:: inst.go generated successfully
INFO:: instr-table.tex generated successfully
INFO:: priv-instr-table.tex generated successfully
```

If you only want a specific artifact you can use one or more of the following targets : `c`, `rust`, `chisel`, `sverilog`, `latex`
If you only want a specific artifact you can use one or more of the following targets : `c`, `rust`, `chisel`, `sverilog`, `latex`.
For example, if you want to generate the `c` based artifact with extensions as shown earlier, you can use the following command:

```bash
./parse.py -c EXTENSIONS='rv*_i rv*_m'
```
Which will print the following log:

```
Running with args : ['./parse.py', '-c', 'EXTENSIONS=rv*_i rv*_m']
Extensions selected : ['EXTENSIONS=rv*_i rv*_m']
INFO:: encoding.out.h generated successfully
```

or you can also use the `make` command as:

```bash
make encoding.out.h EXTENSIONS='rv*_i rv*_m'
```
You can use the `clean` target to remove all artifacts.

## Adding a new extension
Expand Down
16 changes: 8 additions & 8 deletions parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import pprint
import sys

from c_utils import make_c
from chisel_utils import make_chisel
from constants import emitted_pseudo_ops
from go_utils import make_go
from latex_utils import make_latex_table, make_priv_latex_table
from rust_utils import make_rust
from shared_utils import add_segmented_vls_insn, create_inst_dict
from sverilog_utils import make_sverilog
from utils.c_utils import make_c
from utils.chisel_utils import make_chisel
from utils.constants import emitted_pseudo_ops
from utils.go_utils import make_go
from utils.latex_utils import make_latex_table, make_priv_latex_table
from utils.rust_utils import make_rust
from utils.shared_utils import add_segmented_vls_insn, create_inst_dict
from utils.sverilog_utils import make_sverilog

LOG_FORMAT = "%(levelname)s:: %(message)s"
LOG_LEVEL = logging.INFO
Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unittest
from unittest.mock import Mock, patch

from shared_utils import (
from utils.shared_utils import (
InstrDict,
check_arg_lut,
check_overlapping_bits,
Expand Down
8 changes: 5 additions & 3 deletions c_utils.py → utils/c_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import os
import pprint

from constants import causes, csrs, csrs32
from shared_utils import InstrDict, arg_lut
from utils.constants import causes, csrs, csrs32
from utils.shared_utils import InstrDict, arg_lut

pp = pprint.PrettyPrinter(indent=2)
logging.basicConfig(level=logging.INFO, format="%(levelname)s:: %(message)s")
Expand Down Expand Up @@ -43,7 +43,9 @@ def make_c(instr_dict: InstrDict):
mask = ((1 << (end - begin + 1)) - 1) << begin
arg_str += f"#define INSN_FIELD_{sanitized_name.upper()} {hex(mask)}\n"

with open(f"{os.path.dirname(__file__)}/encoding.h", "r", encoding="utf-8") as file:
with open(
os.path.join(os.path.dirname(__file__), "../encoding.h"), "r", encoding="utf-8"
) as file:
enc_header = file.read()

commit = os.popen('git log -1 --format="format:%h"').read()
Expand Down
4 changes: 2 additions & 2 deletions chisel_utils.py → utils/chisel_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
import pprint

from constants import causes, csrs, csrs32
from shared_utils import InstrDict, instr_dict_2_extensions
from utils.constants import causes, csrs, csrs32
from utils.shared_utils import InstrDict, instr_dict_2_extensions

pp = pprint.PrettyPrinter(indent=2)
logging.basicConfig(level=logging.INFO, format="%(levelname)s:: %(message)s")
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion go_utils.py → utils/go_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess
import sys

from shared_utils import InstrDict, signed
from utils.shared_utils import InstrDict, signed

pp = pprint.PrettyPrinter(indent=2)
logging.basicConfig(level=logging.INFO, format="%(levelname)s:: %(message)s")
Expand Down
4 changes: 2 additions & 2 deletions latex_utils.py → utils/latex_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pprint
from typing import TextIO

from constants import latex_fixed_fields, latex_inst_type, latex_mapping
from shared_utils import InstrDict, arg_lut, create_inst_dict
from utils.constants import latex_fixed_fields, latex_inst_type, latex_mapping
from utils.shared_utils import InstrDict, arg_lut, create_inst_dict

pp = pprint.PrettyPrinter(indent=2)
logging.basicConfig(level=logging.INFO, format="%(levelname)s:: %(message)s")
Expand Down
4 changes: 2 additions & 2 deletions rust_utils.py → utils/rust_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
import pprint

from constants import causes, csrs, csrs32
from shared_utils import InstrDict
from utils.constants import causes, csrs, csrs32
from utils.shared_utils import InstrDict

pp = pprint.PrettyPrinter(indent=2)
logging.basicConfig(level=logging.INFO, format="%(levelname)s:: %(message)s")
Expand Down
7 changes: 5 additions & 2 deletions shared_utils.py → utils/shared_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from itertools import chain
from typing import Dict, Optional, TypedDict

from constants import (
from utils.constants import (
arg_lut,
fixed_ranges,
imported_regex,
Expand Down Expand Up @@ -575,7 +575,10 @@ def create_inst_dict(
if include_pseudo_ops is None:
include_pseudo_ops = []

opcodes_dir = os.path.dirname(os.path.realpath(__file__)) + "/extensions"
script_path = os.path.realpath(__file__)
dir_path, _ = os.path.split(script_path)
opcodes_dir = os.path.dirname(dir_path) + "/extensions"
print(opcodes_dir, "############")
instr_dict: InstrDict = {}

file_names = [
Expand Down
4 changes: 2 additions & 2 deletions sverilog_utils.py → utils/sverilog_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pprint
from pathlib import Path

from constants import csrs, csrs32
from shared_utils import InstrDict
from utils.constants import csrs, csrs32
from utils.shared_utils import InstrDict

pp = pprint.PrettyPrinter(indent=2)
logging.basicConfig(level=logging.INFO, format="%(levelname)s:: %(message)s")
Expand Down
Loading