m2isar 0.0.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. m2isar/__init__.py +45 -0
  2. m2isar/backends/__init__.py +15 -0
  3. m2isar/backends/coverage/__init__.py +11 -0
  4. m2isar/backends/coverage/coverage_dbg.py +114 -0
  5. m2isar/backends/coverage/coverage_lcov.py +274 -0
  6. m2isar/backends/coverage/id_transform.py +143 -0
  7. m2isar/backends/coverage/utils.py +14 -0
  8. m2isar/backends/disass/__init__.py +7 -0
  9. m2isar/backends/disass/disass.py +153 -0
  10. m2isar/backends/etiss/README.md +57 -0
  11. m2isar/backends/etiss/__init__.py +35 -0
  12. m2isar/backends/etiss/architecture_writer.py +263 -0
  13. m2isar/backends/etiss/instruction_generator.py +248 -0
  14. m2isar/backends/etiss/instruction_transform.py +838 -0
  15. m2isar/backends/etiss/instruction_utils.py +214 -0
  16. m2isar/backends/etiss/instruction_writer.py +110 -0
  17. m2isar/backends/etiss/pickle_writer.py +36 -0
  18. m2isar/backends/etiss/replacements.py +36 -0
  19. m2isar/backends/etiss/templates/__init__.py +16 -0
  20. m2isar/backends/etiss/templates/etiss_arch_cmake.mako +36 -0
  21. m2isar/backends/etiss/templates/etiss_arch_cpp.mako +205 -0
  22. m2isar/backends/etiss/templates/etiss_arch_gdbcore.mako +80 -0
  23. m2isar/backends/etiss/templates/etiss_arch_h.mako +117 -0
  24. m2isar/backends/etiss/templates/etiss_arch_lib.mako +69 -0
  25. m2isar/backends/etiss/templates/etiss_arch_specific_cpp.mako +201 -0
  26. m2isar/backends/etiss/templates/etiss_arch_specific_h.mako +131 -0
  27. m2isar/backends/etiss/templates/etiss_arch_struct.mako +40 -0
  28. m2isar/backends/etiss/templates/etiss_function.mako +15 -0
  29. m2isar/backends/etiss/templates/etiss_function_header.mako +0 -0
  30. m2isar/backends/etiss/templates/etiss_function_set_footer.mako +14 -0
  31. m2isar/backends/etiss/templates/etiss_function_set_header.mako +29 -0
  32. m2isar/backends/etiss/templates/etiss_functions_c.mako +15 -0
  33. m2isar/backends/etiss/templates/etiss_instruction.mako +30 -0
  34. m2isar/backends/etiss/templates/etiss_instruction_callback.mako +36 -0
  35. m2isar/backends/etiss/templates/etiss_instruction_set.mako +20 -0
  36. m2isar/backends/etiss/writer.py +182 -0
  37. m2isar/backends/isa_manual/.gitignore +6 -0
  38. m2isar/backends/isa_manual/README.md +25 -0
  39. m2isar/backends/isa_manual/__init__.py +9 -0
  40. m2isar/backends/isa_manual/package.json +5 -0
  41. m2isar/backends/isa_manual/render.sh +5 -0
  42. m2isar/backends/isa_manual/utils.py +45 -0
  43. m2isar/backends/isa_manual/visitor.py +169 -0
  44. m2isar/backends/isa_manual/writer.py +277 -0
  45. m2isar/backends/trace_gen/__init__.py +7 -0
  46. m2isar/backends/trace_gen/backend/CodeBuilder.py +221 -0
  47. m2isar/backends/trace_gen/backend/CodeGenerator.py +54 -0
  48. m2isar/backends/trace_gen/backend/__init__.py +7 -0
  49. m2isar/backends/trace_gen/backend/templates/channel/include/channel.mako +32 -0
  50. m2isar/backends/trace_gen/backend/templates/channel/src/channel.mako +14 -0
  51. m2isar/backends/trace_gen/backend/templates/monitor/include/monitor.mako +21 -0
  52. m2isar/backends/trace_gen/backend/templates/monitor/src/bitfields.mako +8 -0
  53. m2isar/backends/trace_gen/backend/templates/monitor/src/instructionMonitors.mako +42 -0
  54. m2isar/backends/trace_gen/backend/templates/monitor/src/monitor.mako +77 -0
  55. m2isar/backends/trace_gen/backend/templates/monitor/src/traceValueMonitor.mako +6 -0
  56. m2isar/backends/trace_gen/backend/templates/printer/include/printer.mako +45 -0
  57. m2isar/backends/trace_gen/backend/templates/printer/src/instructionPrinters.mako +33 -0
  58. m2isar/backends/trace_gen/backend/templates/printer/src/printer.mako +35 -0
  59. m2isar/backends/trace_gen/common/__init__.py +7 -0
  60. m2isar/backends/trace_gen/common/common.py +38 -0
  61. m2isar/backends/trace_gen/frontend/Parser.py +119 -0
  62. m2isar/backends/trace_gen/frontend/__init__.py +7 -0
  63. m2isar/backends/trace_gen/trace_gen.py +143 -0
  64. m2isar/backends/trace_gen/tracemodel/MetaTraceModel.py +277 -0
  65. m2isar/backends/trace_gen/tracemodel/__init__.py +7 -0
  66. m2isar/backends/viewer/__init__.py +9 -0
  67. m2isar/backends/viewer/treegen.py +226 -0
  68. m2isar/backends/viewer/utils.py +31 -0
  69. m2isar/backends/viewer/viewer.py +207 -0
  70. m2isar/frontends/__init__.py +12 -0
  71. m2isar/frontends/coredsl2/.gitignore +9 -0
  72. m2isar/frontends/coredsl2/CoreDSL2.g4 +319 -0
  73. m2isar/frontends/coredsl2/README.md +81 -0
  74. m2isar/frontends/coredsl2/__init__.py +9 -0
  75. m2isar/frontends/coredsl2/antlr.sh +11 -0
  76. m2isar/frontends/coredsl2/architecture_model_builder.py +535 -0
  77. m2isar/frontends/coredsl2/behavior_model_builder.py +438 -0
  78. m2isar/frontends/coredsl2/expr_interpreter.py +37 -0
  79. m2isar/frontends/coredsl2/importer.py +148 -0
  80. m2isar/frontends/coredsl2/load_order.py +74 -0
  81. m2isar/frontends/coredsl2/parser.py +267 -0
  82. m2isar/frontends/coredsl2/parser_gen/.gitignore +12 -0
  83. m2isar/frontends/coredsl2/parser_gen/CoreDSL2Lexer.py +510 -0
  84. m2isar/frontends/coredsl2/parser_gen/CoreDSL2Listener.py +786 -0
  85. m2isar/frontends/coredsl2/parser_gen/CoreDSL2Parser.py +6378 -0
  86. m2isar/frontends/coredsl2/parser_gen/CoreDSL2Visitor.py +443 -0
  87. m2isar/frontends/coredsl2/parser_gen/__init__.py +16 -0
  88. m2isar/frontends/coredsl2/utils.py +56 -0
  89. m2isar/metamodel/__init__.py +93 -0
  90. m2isar/metamodel/arch.py +611 -0
  91. m2isar/metamodel/behav.py +253 -0
  92. m2isar/metamodel/code_info.py +91 -0
  93. m2isar/metamodel/utils/__init__.py +27 -0
  94. m2isar/metamodel/utils/expr_preprocessor.py +85 -0
  95. m2isar/metamodel/utils/expr_simplifier.py +234 -0
  96. m2isar/metamodel/utils/function_staticness.py +139 -0
  97. m2isar/metamodel/utils/function_throws.py +141 -0
  98. m2isar/metamodel/utils/scalar_staticness.py +151 -0
  99. m2isar-0.0.5.dist-info/METADATA +10 -0
  100. m2isar-0.0.5.dist-info/RECORD +104 -0
  101. m2isar-0.0.5.dist-info/WHEEL +5 -0
  102. m2isar-0.0.5.dist-info/entry_points.txt +6 -0
  103. m2isar-0.0.5.dist-info/licenses/LICENSE +201 -0
  104. m2isar-0.0.5.dist-info/top_level.txt +1 -0
m2isar/__init__.py ADDED
@@ -0,0 +1,45 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # This file is part of the M2-ISA-R project: https://github.com/tum-ei-eda/M2-ISA-R
4
+ #
5
+ # Copyright (C) 2022
6
+ # Chair of Electrical Design Automation
7
+ # Technical University of Munich
8
+
9
+ """This is the top-level M2-ISA-R package. The project is divided into three major parts:
10
+
11
+ * :mod:`m2isar.metamodel`, the metamodel classes and helpers.
12
+ * :mod:`m2isar.backends`, consumers of M2-ISA-R models. Provided are an architecture plugin
13
+ generator for ETISS and a graphical tool to inspect M2-ISA-R models.
14
+ * :mod:`m2isar.frontends`, producers of M2-ISA-R models. Currently provided is a parser for
15
+ CoreDSL 2 ISA models.
16
+ """
17
+
18
+ __version__ = "0.0.4"
19
+
20
+ from collections.abc import Iterable
21
+
22
+ class M2Error(Exception):
23
+ pass
24
+
25
+ class M2ValueError(ValueError, M2Error):
26
+ pass
27
+
28
+ class M2NameError(NameError, M2Error):
29
+ pass
30
+
31
+ class M2DuplicateError(M2NameError):
32
+ pass
33
+
34
+ class M2TypeError(TypeError, M2Error):
35
+ pass
36
+
37
+ class M2SyntaxError(SyntaxError, M2Error):
38
+ pass
39
+
40
+ def flatten(xs):
41
+ for x in xs:
42
+ if isinstance(x, Iterable) and not isinstance(x, (str, bytes)):
43
+ yield from flatten(x)
44
+ else:
45
+ yield x
@@ -0,0 +1,15 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # This file is part of the M2-ISA-R project: https://github.com/tum-ei-eda/M2-ISA-R
4
+ #
5
+ # Copyright (C) 2024
6
+ # Chair of Electrical Design Automation
7
+ # Technical University of Munich
8
+
9
+ """This module contains various consumers of M2-ISA-R models. Currently provided are:
10
+
11
+ * A generator for ETISS architecture plugins. This backend generates C++ plugin code for the ETISS
12
+ instruction set simulator, allowing easy and fast additions of ISAs to ETISS.
13
+ * A graphical inspection tool for M2-ISA-R models. The tool allows exploring the contents of an
14
+ M2-ISA-R model in an easy-to-use tree browser.
15
+ """
@@ -0,0 +1,11 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # This file is part of the M2-ISA-R project: https://github.com/tum-ei-eda/M2-ISA-R
4
+ #
5
+ # Copyright (C) 2024
6
+ # Chair of Electrical Design Automation
7
+ # Technical University of Munich
8
+
9
+ """This module contains tools to analyze coverage data generated from
10
+ :class:`m2isar.metamodel.code_info.CodeInfoBase` objects generated by M2-ISA-R model producers.
11
+ """
@@ -0,0 +1,114 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # This file is part of the M2-ISA-R project: https://github.com/tum-ei-eda/M2-ISA-R
4
+ #
5
+ # Copyright (C) 2024
6
+ # Chair of Electrical Design Automation
7
+ # Technical University of Munich
8
+
9
+ import argparse
10
+ import logging
11
+ import pathlib
12
+ import pickle
13
+ from collections import defaultdict
14
+
15
+ from tqdm import tqdm
16
+
17
+ from ...metamodel import M2_METAMODEL_VERSION, M2Model, arch, patch_model
18
+ from ...metamodel.code_info import FunctionInfo, LineInfo
19
+ from ...metamodel.utils.expr_preprocessor import (process_attributes,
20
+ process_functions,
21
+ process_instructions)
22
+ from . import id_transform
23
+ from .utils import IdMatcherContext
24
+
25
+ logger = logging.getLogger("coverage_lcov")
26
+
27
+ def main():
28
+ """Main app entrypoint."""
29
+
30
+ # read command line args
31
+ parser = argparse.ArgumentParser()
32
+ parser.add_argument('top_level', help="A .lineinfo file containing the line info database.")
33
+ parser.add_argument("--log", default="info", choices=["critical", "error", "warning", "info", "debug"])
34
+ parser.add_argument("-o", "--outfile", required=True)
35
+ args = parser.parse_args()
36
+
37
+ # initialize logging
38
+ logging.basicConfig(level=getattr(logging, args.log.upper()))
39
+
40
+ # resolve model paths
41
+ top_level = pathlib.Path(args.top_level)
42
+ abs_top_level = top_level.resolve()
43
+ search_path = abs_top_level.parent.parent
44
+ model_fname = abs_top_level
45
+
46
+ if abs_top_level.suffix == ".core_desc":
47
+ logger.warning(".core_desc file passed as input. This is deprecated behavior, please change your scripts!")
48
+ search_path = abs_top_level.parent
49
+ model_path = search_path.joinpath('gen_model')
50
+
51
+ if not model_path.exists():
52
+ raise FileNotFoundError('Models not generated!')
53
+ model_fname = model_path / (abs_top_level.stem + '.m2isarmodel')
54
+
55
+ logger.info("loading models")
56
+
57
+ with open(model_fname, 'rb') as f:
58
+ model_obj: "M2Model" = pickle.load(f)
59
+
60
+ if model_obj.model_version != M2_METAMODEL_VERSION:
61
+ logger.warning("Loaded model version mismatch")
62
+
63
+ for core_name, core_obj in model_obj.cores.items():
64
+ process_functions(core_obj)
65
+ process_instructions(core_obj)
66
+ process_attributes(core_obj)
67
+
68
+
69
+ patch_model(id_transform)
70
+
71
+ ctx = IdMatcherContext()
72
+
73
+ for core_name, core_obj in model_obj.cores.items():
74
+ ctx.arch_name = core_name
75
+
76
+ for fn_name, fn_obj in core_obj.functions.items():
77
+ if fn_obj.function_info is not None:
78
+ ctx.id_to_obj_map[core_name][fn_obj.function_info.id] = fn_obj
79
+
80
+ fn_obj.operation.generate(ctx)
81
+
82
+ for instr_name, instr_obj in core_obj.instructions.items():
83
+ ctx.id_to_obj_map[core_name][instr_obj.function_info.id] = instr_obj
84
+
85
+ instr_obj.operation.generate(ctx)
86
+
87
+ id_to_obj_map = {}
88
+
89
+ for core_name, objs in ctx.id_to_obj_map.items():
90
+ for id, owner in objs.items():
91
+ id_to_obj_map[id] = owner
92
+
93
+ linedata_by_file = defaultdict(dict)
94
+ for lineinfo in tqdm(model_obj.code_infos.values()):
95
+ if isinstance(lineinfo, LineInfo):
96
+ type_str = "L"
97
+ elif isinstance(lineinfo, FunctionInfo):
98
+ type_str = "F"
99
+
100
+ linedata_by_file[lineinfo.file_path][lineinfo.id] = (type_str, lineinfo.start_line_no, lineinfo.stop_line_no, id_to_obj_map.get(lineinfo.id))
101
+
102
+ for core_name, objs in ctx.id_to_obj_map.items():
103
+
104
+ with open(f"{core_name}.csv", "w") as f:
105
+ for id in sorted(objs):
106
+ f.write(f"{id}\n")
107
+
108
+ with open(args.outfile, "w") as f:
109
+ for fname, lines in sorted(linedata_by_file.items()):
110
+ for info_id, (type_str, start_line_no, stop_line_no, owner) in sorted(lines.items()):
111
+ f.write(f"{type_str};{fname.stem};{info_id};{start_line_no},{stop_line_no},{owner}\n")
112
+
113
+ if __name__ == "__main__":
114
+ main()
@@ -0,0 +1,274 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # This file is part of the M2-ISA-R project: https://github.com/tum-ei-eda/M2-ISA-R
4
+ #
5
+ # Copyright (C) 2024
6
+ # Chair of Electrical Design Automation
7
+ # Technical University of Munich
8
+
9
+ import argparse
10
+ import logging
11
+ import os
12
+ import pathlib
13
+ import pickle
14
+ from collections import defaultdict
15
+ from functools import partial
16
+
17
+ from tqdm.contrib.concurrent import process_map
18
+
19
+ from ...metamodel import M2_METAMODEL_VERSION, M2Model, patch_model
20
+ from ...metamodel.code_info import (BranchInfo, CodeInfoBase, FunctionInfo,
21
+ LineInfo)
22
+ from ...metamodel.utils.expr_preprocessor import (process_attributes,
23
+ process_functions,
24
+ process_instructions)
25
+ from . import id_transform
26
+ from .utils import IdMatcherContext
27
+
28
+ logger = logging.getLogger("coverage_lcov")
29
+
30
+ def generate_coverage(line_data_fname: "pathlib.Path", code_infos: "dict[int, CodeInfoBase]", line_counts_by_core_and_file, fn_counts_by_core_and_file, branch_counts_by_core_and_file):
31
+ line_data_path = pathlib.Path(line_data_fname)
32
+ logger.debug("processing file %s", line_data_path.name)
33
+ logger.debug("reading line data")
34
+
35
+ linedata: "dict[CodeInfoBase, int]" = {}
36
+ with open(line_data_path, 'r') as f:
37
+ core_name = f.readline().strip()
38
+ f.readline()
39
+ for line in f:
40
+ l_id, count = line.strip().split(";")
41
+ linedata[code_infos[int(l_id)]] = int(count)
42
+
43
+ checked_lineinfo = {}
44
+ checked_fninfo = {}
45
+
46
+ def already_checked(to_check, l: LineInfo, count):
47
+ for l2, count2 in to_check.items():
48
+ if l.line_eq(l2):
49
+ if count > count2:
50
+ return False
51
+ elif count < count2:
52
+ return True
53
+ else:
54
+ return True
55
+
56
+ return False
57
+
58
+ linedata_of_this_file = defaultdict(dict)
59
+
60
+ for lineinfo, count in linedata.items():
61
+ if isinstance(lineinfo, BranchInfo):
62
+ branch_counts_by_core_and_file[core_name][lineinfo.file_path][lineinfo.id] += count
63
+
64
+ if isinstance(lineinfo, LineInfo):
65
+ if already_checked(checked_lineinfo, lineinfo, count):
66
+ continue
67
+
68
+ checked_lineinfo[lineinfo] = count
69
+
70
+ linedata_of_this_file[lineinfo.file_path][lineinfo.start_line_no] = count
71
+
72
+ elif isinstance(lineinfo, FunctionInfo):
73
+ if already_checked(checked_fninfo, lineinfo, count):
74
+ continue
75
+
76
+ checked_fninfo[lineinfo] = count
77
+
78
+ fn_counts_by_core_and_file[core_name][lineinfo.file_path][lineinfo.fn_name] += count
79
+
80
+ for filepath, lines in linedata_of_this_file.items():
81
+ for line_no, line_count in lines.items():
82
+ line_counts_by_core_and_file[core_name][filepath][line_no] += line_count
83
+
84
+ return line_counts_by_core_and_file, fn_counts_by_core_and_file, branch_counts_by_core_and_file
85
+
86
+ def main():
87
+ """Main app entrypoint."""
88
+
89
+ # read command line args
90
+ parser = argparse.ArgumentParser()
91
+ parser.add_argument('top_level', help="A .m2isar file containing model.")
92
+ parser.add_argument('line_data', help="The CSV line data files matching the model.", nargs="+")
93
+ parser.add_argument("--log", default="info", choices=["critical", "error", "warning", "info", "debug"])
94
+ parser.add_argument("--legacy", action="store_true", help="Generate data for LOCV version < 2.0")
95
+ parser.add_argument("-o", "--outfile", required=True)
96
+ parser.add_argument("-a", "--target-arch", action="append")
97
+ parser.add_argument("-j", "--parallel", type=int, default=os.cpu_count())
98
+ args = parser.parse_args()
99
+
100
+ # initialize logging
101
+ logging.basicConfig(level=getattr(logging, args.log.upper()))
102
+
103
+ # resolve model paths
104
+ top_level = pathlib.Path(args.top_level)
105
+ abs_top_level = top_level.resolve()
106
+ search_path = abs_top_level.parent.parent
107
+ model_fname = abs_top_level
108
+
109
+ if abs_top_level.suffix == ".core_desc":
110
+ logger.warning(".core_desc file passed as input. This is deprecated behavior, please change your scripts!")
111
+ search_path = abs_top_level.parent
112
+ model_path = search_path.joinpath('gen_model')
113
+
114
+ if not model_path.exists():
115
+ raise FileNotFoundError('Models not generated!')
116
+
117
+ model_fname = model_path / (abs_top_level.stem + '.m2isarmodel')
118
+
119
+ logger.info("loading models")
120
+
121
+ with open(model_fname, 'rb') as f:
122
+ model_obj: "M2Model" = pickle.load(f)
123
+
124
+ if model_obj.model_version != M2_METAMODEL_VERSION:
125
+ logger.warning("Loaded model version mismatch")
126
+
127
+ if args.target_arch is not None:
128
+ cores_to_use = {arch_name: model_obj.cores[arch_name] for arch_name in args.target_arch}
129
+ model_obj.cores = cores_to_use
130
+
131
+ logger.info("preprocessing models")
132
+
133
+ for core_name, core_obj in model_obj.cores.items():
134
+ process_functions(core_obj)
135
+ process_instructions(core_obj)
136
+ process_attributes(core_obj)
137
+
138
+ logger.info("building model-specific coverage database")
139
+
140
+ patch_model(id_transform)
141
+
142
+ ctx = IdMatcherContext()
143
+
144
+ for core_name, core_obj in model_obj.cores.items():
145
+ ctx.arch_name = core_name
146
+
147
+ for fn_name, fn_obj in core_obj.functions.items():
148
+ if fn_obj.function_info is not None:
149
+ ctx.id_to_obj_map[core_name][fn_obj.function_info.id] = fn_obj
150
+
151
+ fn_obj.operation.generate(ctx)
152
+
153
+ for instr_name, instr_obj in core_obj.instructions.items():
154
+ ctx.id_to_obj_map[core_name][instr_obj.function_info.id] = instr_obj
155
+
156
+ instr_obj.operation.generate(ctx)
157
+
158
+
159
+ logger.info("initializing coverage counters")
160
+
161
+ line_counts_by_core_and_file: dict[str, dict[str, dict[int, int]]] = defaultdict(lambda: defaultdict(dict))
162
+ fn_counts_by_core_and_file: dict[str, dict[str, dict[str, int]]] = defaultdict(lambda: defaultdict(dict))
163
+ fnmeta_by_core_and_file: dict[str, dict[str, dict[str, tuple[int, int]]]] = defaultdict(lambda: defaultdict(dict))
164
+ branch_counts_by_core_and_file: dict[str, dict[str, dict[int, int]]] = defaultdict(lambda: defaultdict(dict))
165
+ branchmeta_by_core_and_file: dict[str, dict[str, dict[int, list[BranchInfo]]]] = defaultdict(lambda: defaultdict(lambda: defaultdict(list)))
166
+
167
+ for core_name, objs in ctx.id_to_obj_map.items():
168
+ for id, owner in objs.items():
169
+ codeinfo = model_obj.code_infos[id]
170
+
171
+ if isinstance(codeinfo, LineInfo):
172
+ line_counts_by_core_and_file[core_name][codeinfo.file_path][codeinfo.start_line_no] = 0
173
+
174
+ elif isinstance(codeinfo, FunctionInfo):
175
+ fn_counts_by_core_and_file[core_name][codeinfo.file_path][codeinfo.fn_name] = 0
176
+ fnmeta_by_core_and_file[core_name][codeinfo.file_path][codeinfo.fn_name] = (codeinfo.start_line_no, codeinfo.stop_line_no)
177
+
178
+ if isinstance(codeinfo, BranchInfo):
179
+ branch_counts_by_core_and_file[core_name][codeinfo.file_path][codeinfo.id] = 0
180
+ branchmeta_by_core_and_file[core_name][codeinfo.file_path][codeinfo.branch_id].append(codeinfo)
181
+
182
+ def dictconv(d: dict):
183
+ ret = dict(d)
184
+
185
+ for k, v in ret.items():
186
+ if isinstance(v, dict):
187
+ ret[k] = dictconv(v)
188
+
189
+ return ret
190
+
191
+ line_counts_by_core_and_file = dictconv(line_counts_by_core_and_file)
192
+ fn_counts_by_core_and_file = dictconv(fn_counts_by_core_and_file)
193
+ branch_counts_by_core_and_file = dictconv(branch_counts_by_core_and_file)
194
+
195
+ logger.info("generating coverage")
196
+
197
+ out = process_map(partial(generate_coverage, code_infos=model_obj.code_infos, line_counts_by_core_and_file=line_counts_by_core_and_file, fn_counts_by_core_and_file=fn_counts_by_core_and_file, branch_counts_by_core_and_file=branch_counts_by_core_and_file), args.line_data, max_workers=args.parallel)
198
+
199
+ def update(d: dict[str, dict[str, dict[int, int]]], u: dict[str, dict[str, dict[int, int]]]):
200
+ for core_name, data in u.items():
201
+ for filepath, lines in data.items():
202
+ for line_no, line_count in lines.items():
203
+ d[core_name][filepath][line_no] += line_count
204
+
205
+ for ret_line_data, ret_fn_data, ret_branch_data in out:
206
+ update(line_counts_by_core_and_file, ret_line_data)
207
+ update(fn_counts_by_core_and_file, ret_fn_data)
208
+ update(branch_counts_by_core_and_file, ret_branch_data)
209
+
210
+ logger.info("writing output")
211
+ for core_name, linedata_by_file in line_counts_by_core_and_file.items():
212
+ with open(f"{core_name}.{args.outfile}", 'w') as f:
213
+ for filepath, lines in linedata_by_file.items():
214
+ f.write("TN:\n")
215
+ f.write(f"SF:{filepath}\n")
216
+
217
+ branch_hit_counter = 0
218
+ line_hit_counter = 0
219
+ fn_hit_counter = 0
220
+
221
+ for branch_id, branch_infos in branchmeta_by_core_and_file[core_name][filepath].items():
222
+ total_count = branch_counts_by_core_and_file[core_name][filepath][branch_infos[0].id]
223
+ taken_counts = [branch_counts_by_core_and_file[core_name][filepath][x.id] for x in branch_infos[1:]]
224
+
225
+ remaining_count = total_count
226
+
227
+ branch_data = []
228
+
229
+ for count, branch_info in zip(taken_counts, branch_infos[1:]):
230
+ # line no, taken, not taken
231
+ d = (branch_info.start_line_no, count, remaining_count - count)
232
+
233
+ branch_hit_counter += count > 0 + (remaining_count - count) > 0
234
+
235
+ f.write(f"BRDA:{branch_info.start_line_no},0,0,{count if remaining_count > 0 else '-'}\n")
236
+ f.write(f"BRDA:{branch_info.start_line_no},0,1,{remaining_count - count if remaining_count > 0 else '-'}\n")
237
+
238
+ lines[branch_info.start_line_no] = remaining_count
239
+
240
+ branch_data.append(d)
241
+ remaining_count -= count
242
+
243
+
244
+ f.write(f"BRF:{len(branchmeta_by_core_and_file[core_name][filepath])}\n")
245
+ f.write(f"BRH:{branch_hit_counter}\n")
246
+
247
+ for line_no, line_count in sorted(lines.items()):
248
+ f.write(f"DA:{line_no},{line_count}\n")
249
+
250
+ if line_count > 0:
251
+ line_hit_counter += 1
252
+
253
+ f.write(f"LF:{len(lines)}\n")
254
+ f.write(f"LH:{line_hit_counter}\n")
255
+
256
+ for fn_name, (fn_start, fn_stop) in fnmeta_by_core_and_file[core_name][filepath].items():
257
+ if args.legacy:
258
+ f.write(f"FN:{fn_start},{fn_name}\n")
259
+ else:
260
+ f.write(f"FN:{fn_start},{fn_stop},{fn_name}\n")
261
+
262
+ for fn_name, fn_count in fn_counts_by_core_and_file[core_name][filepath].items():
263
+ f.write(f"FNDA:{fn_count},{fn_name}\n")
264
+
265
+ if fn_count > 0:
266
+ fn_hit_counter += 1
267
+
268
+ f.write(f"FNF:{len(fnmeta_by_core_and_file[core_name][filepath])}\n")
269
+ f.write(f"FNH:{fn_hit_counter}\n")
270
+
271
+ f.write("end_of_record\n")
272
+
273
+ if __name__ == "__main__":
274
+ main()
@@ -0,0 +1,143 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # This file is part of the M2-ISA-R project: https://github.com/tum-ei-eda/M2-ISA-R
4
+ #
5
+ # Copyright (C) 2024
6
+ # Chair of Electrical Design Automation
7
+ # Technical University of Munich
8
+
9
+
10
+ from ...metamodel import behav
11
+ from .utils import IdMatcherContext
12
+
13
+
14
+ def operation(self: behav.Operation, context: "IdMatcherContext"):
15
+ if self.line_info is not None:
16
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
17
+
18
+ for stmt in self.statements:
19
+ stmt.generate(context)
20
+
21
+ def block(self: behav.Block, context: "IdMatcherContext"):
22
+ if self.line_info is not None:
23
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
24
+
25
+ for stmt in self.statements:
26
+ stmt.generate(context)
27
+
28
+ def binary_operation(self: behav.BinaryOperation, context: "IdMatcherContext"):
29
+ if self.line_info is not None:
30
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
31
+
32
+ self.left.generate(context)
33
+ self.right.generate(context)
34
+
35
+ def slice_operation(self: behav.SliceOperation, context: "IdMatcherContext"):
36
+ if self.line_info is not None:
37
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
38
+
39
+ self.expr.generate(context)
40
+ self.left.generate(context)
41
+ self.right.generate(context)
42
+
43
+ def concat_operation(self: behav.ConcatOperation, context: "IdMatcherContext"):
44
+ if self.line_info is not None:
45
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
46
+
47
+ self.left.generate(context)
48
+ self.right.generate(context)
49
+
50
+ def number_literal(self: behav.IntLiteral, context: "IdMatcherContext"):
51
+ if self.line_info is not None:
52
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
53
+
54
+ def int_literal(self: behav.IntLiteral, context: "IdMatcherContext"):
55
+ if self.line_info is not None:
56
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
57
+
58
+ def scalar_definition(self: behav.ScalarDefinition, context: "IdMatcherContext"):
59
+ if self.line_info is not None:
60
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
61
+
62
+ def break_(self: behav.Break, context: "IdMatcherContext"):
63
+ if self.line_info is not None:
64
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
65
+
66
+ def assignment(self: behav.Assignment, context: "IdMatcherContext"):
67
+ if self.line_info is not None:
68
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
69
+
70
+ self.target.generate(context)
71
+ self.expr.generate(context)
72
+
73
+ def conditional(self: behav.Conditional, context: "IdMatcherContext"):
74
+ if self.line_info is not None:
75
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
76
+
77
+ for cond in self.conds:
78
+ cond.generate(context)
79
+
80
+ for stmt in self.stmts:
81
+ #
82
+ #for stmt in op:
83
+ stmt.generate(context)
84
+ #
85
+
86
+ def loop(self: behav.Loop, context: "IdMatcherContext"):
87
+ if self.line_info is not None:
88
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
89
+
90
+ self.cond.generate(context)
91
+
92
+ for stmt in self.stmts:
93
+ stmt.generate(context)
94
+
95
+ def ternary(self: behav.Ternary, context: "IdMatcherContext"):
96
+ if self.line_info is not None:
97
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
98
+
99
+ self.cond.generate(context)
100
+ self.then_expr.generate(context)
101
+ self.else_expr.generate(context)
102
+
103
+ def return_(self: behav.Return, context: "IdMatcherContext"):
104
+ if self.line_info is not None:
105
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
106
+
107
+ if self.expr is not None:
108
+ self.expr.generate(context)
109
+
110
+ def unary_operation(self: behav.UnaryOperation, context: "IdMatcherContext"):
111
+ if self.line_info is not None:
112
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
113
+
114
+ self.right.generate(context)
115
+
116
+ def named_reference(self: behav.NamedReference, context: "IdMatcherContext"):
117
+ if self.line_info is not None:
118
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
119
+
120
+ def indexed_reference(self: behav.IndexedReference, context: "IdMatcherContext"):
121
+ if self.line_info is not None:
122
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
123
+
124
+ self.index.generate(context)
125
+
126
+ def type_conv(self: behav.TypeConv, context: "IdMatcherContext"):
127
+ if self.line_info is not None:
128
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
129
+
130
+ self.expr.generate(context)
131
+
132
+ def callable_(self: behav.Callable, context: "IdMatcherContext"):
133
+ if self.line_info is not None:
134
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
135
+
136
+ for arg, arg_descr in zip(self.args, self.ref_or_name.args):
137
+ arg.generate(context)
138
+
139
+ def group(self: behav.Group, context: "IdMatcherContext"):
140
+ if self.line_info is not None:
141
+ context.id_to_obj_map[context.arch_name][self.line_info.id] = self
142
+
143
+ self.expr.generate(context)
@@ -0,0 +1,14 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # This file is part of the M2-ISA-R project: https://github.com/tum-ei-eda/M2-ISA-R
4
+ #
5
+ # Copyright (C) 2024
6
+ # Chair of Electrical Design Automation
7
+ # Technical University of Munich
8
+
9
+ from collections import defaultdict
10
+
11
+ class IdMatcherContext:
12
+ def __init__(self):
13
+ self.arch_name = None
14
+ self.id_to_obj_map = defaultdict(dict)
@@ -0,0 +1,7 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # This file is part of the M2-ISA-R project: https://github.com/tum-ei-eda/M2-ISA-R
4
+ #
5
+ # Copyright (C) 2022
6
+ # Chair of Electrical Design Automation
7
+ # Technical University of Munich