Skip to content
Merged
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
24 changes: 19 additions & 5 deletions m2isar/backends/etiss/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,30 @@ These functionalities must be implemented manually in the file `<core_name>ArchS

```
$ etiss_writer --help
usage: writer.py [-h] [-s] [--log {critical,error,warning,info,debug}] top_level
usage: writer.py [-h] [--separate | --no-separate] [--static-scalars | --no-static-scalars]
[--block-end-on {none,uncond,all}] [--coverage | --no-coverage]
[--log {critical,error,warning,info,debug}] [--gdb-xml-descr GDB_XML_DESCR [GDB_XML_DESCR ...]]
[--fill-mode {auto,empty}]
top_level

positional arguments:
top_level A .m2isarmodel file containing the models to generate.

optional arguments:
options:
-h, --help show this help message and exit
-s, --separate Generate separate .cpp files for each instruction set.
--static-scalars Enable crude static detection for scalars. WARNING: known to break!
--separate, --no-separate
Generate separate .cpp files for each instruction set. (default: True)
--static-scalars, --no-static-scalars
Enable static detection for Variables. (default: True)
--block-end-on {none,uncond,all}
Force end translation blocks on no instructions, uncoditional jumps or all jumps.
--coverage, --no-coverage
Generate coverage tracking code into model. (default: False)
--log {critical,error,warning,info,debug}
--gdb-xml-descr GDB_XML_DESCR [GDB_XML_DESCR ...]
--fill-mode {auto,empty}
How to deal with generated arch-specific impl files (empty: generate placeholders, auto:
pre-populate using available metadata)
```

## Internals
Expand All @@ -54,4 +68,4 @@ def operation(self: behav.Operation, context: TransformerContext):

The patching logic would perform the assignment `behav.Operation.generate = operation`. For the implementation of the patching logic, see [here](https://github.com/tum-ei-eda/M2-ISA-R/blob/coredsl2/m2isar/backends/etiss/instruction_generator.py#L14).

High-level code generation is done through `mako` templates, where large amounts of static text is required. Behavioral code is generated directly in Python through string operations. To pass state information between generation nodes, `CodeString` objects containing the actual string and supporting data are used.
High-level code generation is done through `mako` templates, where large amounts of static text is required. Behavioral code is generated directly in Python through string operations. To pass state information between generation nodes, `CodeString` objects containing the actual string and supporting data are used.
9 changes: 6 additions & 3 deletions m2isar/backends/etiss/instruction_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ def generate_arg_str(arg: arch.FnParam):
full_type = f"{arg_type}{arg_size}"
else:
assert isinstance(arg.ty, type_info.PointerType) and isinstance(arg.ty.ty, type_info.PrimitiveType)
arg_type = f"{instruction_utils.data_type_map[arg.ty.ty.kind]}* "
arg_size = actual_size(arg.ty.ty.size)
full_type = f"{arg_type}{arg_size}*"
if arg.ty.ty.kind == type_info.TypeKind.VOID:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case might not be necessary or is something not working here? The map has also the VOID case in there:

type_info.TypeKind.VOID: 'void'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jokap11 but void pointers have a size=None which breaks arg_size = actual_size(arg.ty.ty.size).

But you are correct that I could still use data_type_map. Let me know if I should change it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not really matter anyways, but thanks for the explanation. LGTM now!

full_type = "void*"
else:
arg_type = f"{instruction_utils.data_type_map[arg.ty.ty.kind]}* "
arg_size = actual_size(arg.ty.ty.size)
full_type = f"{arg_type}{arg_size}*"

return f'{full_type}{arg_name}'

Expand Down
2 changes: 1 addition & 1 deletion m2isar/backends/etiss/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def setup():
parser.add_argument("--coverage", action=BooleanOptionalAction, default=False, help="Generate coverage tracking code into model.")
parser.add_argument("--log", default="info", choices=["critical", "error", "warning", "info", "debug"])
parser.add_argument("--gdb-xml-descr", nargs="+", default=[])
parser.add_argument("--fill-mode", choices=["auto", "empty"], default="empty")
parser.add_argument("--fill-mode", choices=["auto", "empty"], default="empty", help="How to deal with generated arch-specific impl files (empty: generate placeholders, auto: pre-populate using available metadata)")
# TODO: add modes for rvv,...
args = parser.parse_args()

Expand Down
2 changes: 2 additions & 0 deletions m2isar/frontends/coredsl2/architecture_model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ def visitDeclaration(self, ctx: CoreDSL2Parser.DeclarationContext):
self._csr_reg_file = m
elif m.is_main_mem:
self.main_memory = m
elif m.is_vector_reg:
self._vector_reg_file = m

self._memories[name] = m
ret_decls.append(m)
Expand Down
8 changes: 6 additions & 2 deletions m2isar/metamodel/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,19 +381,21 @@ def data_range(self):

return RangeSpec(self.range.upper - self.range.lower, 0)


@property
def is_csr_reg(self) -> bool:
"""Return true if this memory is tagged as being a csr register array or named CSR."""
return self._is_specific_memory(attribute_info.MemoryAttribute.IS_CSR_REG, "CSR")

@property
def is_vector_reg(self) -> bool:
"""Return true if this memory is tagged as being a vector register array or named V."""
return self._is_specific_memory(attribute_info.MemoryAttribute.IS_VECTOR_REG, "V")

@property
def is_main_mem(self):
"""Return true if this memory is tagged as being the main memory array."""
return self._is_specific_memory(attribute_info.MemoryAttribute.IS_MAIN_MEM)


def _is_specific_memory(self, memory_type: attribute_info.MemoryAttribute, expected_name: str = "") -> bool:
"""
This is a helper function to ensure, that all checks are performed always the same.
Expand Down Expand Up @@ -726,6 +728,8 @@ def __init__(self, name, contributing_types: "list[str]", template: str, paramet
self.main_memory = mem
elif mem.is_csr_reg:
self.csr_reg_file = mem
elif mem.is_vector_reg:
self.vector_reg_file = mem
elif attribute_info.MemoryAttribute.ETISS_IS_GLOBAL_IRQ_EN in mem.attributes:
self.global_irq_en_memory = mem
elif attribute_info.MemoryAttribute.ETISS_IS_PROCNO in mem.attributes:
Expand Down
1 change: 1 addition & 0 deletions m2isar/metamodel/attribute_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class MemoryAttribute(Enum):
IS_MAIN_MEM = auto()
IS_CSR_REG = auto()
IS_VECTOR_REG = auto()
DELETE = auto()
ETISS_CAN_FAIL = auto()
ETISS_IS_GLOBAL_IRQ_EN = auto()
Expand Down