Skip to content

[BUGFIX] Fixing inconsistent check to classify Memory Type#106

Closed
MercurCodes wants to merge 1 commit into
coredsl2from
bugfix/memory_types
Closed

[BUGFIX] Fixing inconsistent check to classify Memory Type#106
MercurCodes wants to merge 1 commit into
coredsl2from
bugfix/memory_types

Conversation

@MercurCodes

Copy link
Copy Markdown
Contributor

This PR unifies how all attributes are checked and thereby fixes a problem in generating Float Registers for ETISS. The approach was aligned with a previous existing approach for checking if the memory is main memory.
This has as advantage, that in future, if the check needs to be adapated, it only needs to be adapted in one place, minimizing the risk of inconsistent behavior.

This fix ensures that the check if a given memory is a float register of something similar is performed equally wherever it is called.
@MercurCodes
MercurCodes requested a review from PhilippvK July 15, 2026 19:30
@jokap11

jokap11 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Dear Raphael,

Thanks for committing this.

I had a look at the changes, and I agree that it makes sense to add these properties to the central memory class.

The only issue is that we previously split the Memory superclass into four separate classes (Register, RegisterBanks, Memory, and Alias) to provide a clear separation aligned with the CoreDSL2 wiki:

https://github.com/Minres/CoreDSL/wiki/Structure-and-concepts#architectural-state
https://github.com/tum-ei-eda/M2-ISA-R/blob/behav_array_support/m2isar/metamodel/arch.py#L269

Because of this, we would need to distinguish between Memory, Register, and Alias checks, since memory (CSR + MEM) is different from registers (PC) and register banks (GPR/FPR, etc.). Or use hasattr ...

Other than that, I really like your approach here:
https://github.com/tum-ei-eda/M2-ISA-R/pull/106/changes#diff-b792a72017e4c7a5ebf8eed153cca7dfffa2cd9f65ec054b3e096f335fcf7213R404

BR,
Johannes

@PhilippvK What is your opinion?
PS: @MercurCodes We try to commit PRs to the coredsl2 branch within the next week

if m.is_vector_reg:
self._vector_reg_file = m
if arch.MemoryAttribute.IS_CSR_REG in attributes or name.upper() == "CSR":
if m.is_csr_reg:

@jokap11 jokap11 Jul 16, 2026

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.

There Is one potential Issue that CSR is declared in coredsl as a Memory Range "extern",
while the others are registers "register".
Also Alias were Memory objects before

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.

Sorry for being a bit imprecise. I was just referring to a piece of code that won't work together with the other PRs.

@PhilippvK and I still need to decide whether we want to merge your PR first or mine.

@MercurCodes MercurCodes Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have previously missed your comment on a global scope. Now it makes sense.
Here is an idea: I could refactor the checks to a Python - Mixin, which is then added to Alias, Registers, RegisterBank, Memory.
I think this would actually further improve consistency, especially, since I spotted that Register and RegisterBank both have i.e. is_pc as attribute. Would this solve your issue?
I'm however unsure if there is a proper OOP Solution, since this would imply the possibility of a Register being MainMemory... which is weird. What I could also do is refactor the functions as utils and put them into a seperate file?

@jokap11 jokap11 Jul 16, 2026

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.

Here is an idea: I could refactor the checks to a Python - Mixin, which is then added to Alias, Registers, >RegisterBank, Memory. I think this would actually further improve consistency, especially, since I spotted that >Register and RegisterBank both have i.e. is_pc as attribute. Would this solve your issue?

I think your approach with properties is still valid, and in my opinion it's an improvement over the current implementation. The main thing is to keep the responsibilities separated between the classes (PCRegister, Main_reg/Floating_reg....RegisterBank, Main_MEM/CSRMemory).

However, once you combine multiple dictionaries (e.g. Memory and Alias), you'll still need some form of type check, such as isinstance(...), before accessing class-specific attributes. Otherwise, you'll end up with AttributeErrors when an object doesn't define the expected attribute.

I'm however unsure if there is a proper OOP Solution, since this would imply the possibility of a Register being >MainMemory... which is weird. What I could also do is refactor the functions as utils and put them into a seperate >file?

Regarding moving the functions into a separate utility file, I don't think that's necessary. In some cases, it's useful to work with dictionaries containing multiple object types so the function can detect both Memory and Alias accesses. In that scenario, a small amount of type discrimination seems reasonable and keeps the logic where it's actually needed.

@jokap11 jokap11 self-assigned this Jul 16, 2026
@jokap11

jokap11 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Should be integrated into develop2 (see: #107).
Thanks for the bugfix!

@jokap11

jokap11 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Superseded by #107
Please re-open if you are not happy!

@jokap11 jokap11 closed this Jul 16, 2026
@jokap11 jokap11 mentioned this pull request Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants