aboutsummaryrefslogtreecommitdiff
path: root/parse.py
blob: 29f6062e21116ac8065b962c3d4d34c4c364daf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
import collections
import logging
import pprint
import sys

import yaml

from c_utils import *
from chisel_utils import *
from constants import *
from go_utils import *
from latex_utils import *
from rust_utils import *
from shared_utils import *
from sverilog_utils import *

LOG_FORMAT = "%(levelname)s:: %(message)s"
LOG_LEVEL = logging.INFO

pretty_printer = pprint.PrettyPrinter(indent=2)
logging.basicConfig(level=LOG_LEVEL, format=LOG_FORMAT)

if __name__ == "__main__":
    print(f"Running with args : {sys.argv}")

    extensions = sys.argv[1:]

    targets = {
        "-c",
        "-chisel",
        "-go",
        "-latex",
        "-pseudo",
        "-rust",
        "-spinalhdl",
        "-sverilog",
    }

    extensions = [ext for ext in extensions if ext not in targets]
    print(f"Extensions selected : {extensions}")

    include_pseudo = False
    if "-pseudo" in sys.argv[1:]:
        include_pseudo = True

    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)
    instr_dict = collections.OrderedDict(sorted(instr_dict.items()))

    if "-c" in sys.argv[1:]:
        instr_dict_c = create_inst_dict(
            extensions, False, include_pseudo_ops=emitted_pseudo_ops
        )
        instr_dict_c = collections.OrderedDict(sorted(instr_dict_c.items()))
        make_c(instr_dict_c)
        logging.info("encoding.out.h generated successfully")

    if "-chisel" in sys.argv[1:]:
        make_chisel(instr_dict)
        logging.info("inst.chisel generated successfully")

    if "-spinalhdl" in sys.argv[1:]:
        make_chisel(instr_dict, True)
        logging.info("inst.spinalhdl generated successfully")

    if "-sverilog" in sys.argv[1:]:
        make_sverilog(instr_dict)
        logging.info("inst.sverilog generated successfully")

    if "-rust" in sys.argv[1:]:
        make_rust(instr_dict)
        logging.info("inst.rs generated successfully")

    if "-go" in sys.argv[1:]:
        make_go(instr_dict)
        logging.info("inst.go generated successfully")

    if "-latex" in sys.argv[1:]:
        make_latex_table()
        logging.info("instr-table.tex generated successfully")
        make_priv_latex_table()
        logging.info("priv-instr-table.tex generated successfully")