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

Structured constant generation (and Matlab) #43

Merged
merged 4 commits into from
Apr 17, 2024

Conversation

lorenzschmid
Copy link
Contributor

Adds support to generate structured constants: So far, the --gen-consts options allows to generate constant files for different programming languages (internally called "styles"). Thereby, different properties of the register map, its registers and fields are printed in a non-hierarchical way. The constants have no logical connection but are placed one after the other.

Using the new --gen-struct option, still generates constant files but extends the concept by generating hierarchical structures. To give an example with the Matlab "style":

--gen-consts:

ADDR_REG_MAP_REPEAT_BLOCK_REGISTER_A0_FIELD_B = 0;
REG_MAP_REPEAT_BLOCK_REGISTER_A0_FIELD_B_OFFSET = 21;
REG_MAP_REPEAT_BLOCK_REGISTER_A0_FIELD_B = 2097152;
REG_MAP_REPEAT_BLOCK_REGISTER_A0_FIELD_B_PRESET = 0;
ADDR_REG_MAP_REPEAT_BLOCK_REGISTER_A0_FIELD_A = 0;
REG_MAP_REPEAT_BLOCK_REGISTER_A0_FIELD_A_OFFSET = 19;
REG_MAP_REPEAT_BLOCK_REGISTER_A0_FIELD_A = 524288;
REG_MAP_REPEAT_BLOCK_REGISTER_A0_FIELD_A_PRESET = 0;

--gen-struct (newly added):

REG_MAP.repeat_block(1).register_a.field_b.ADDR = 0;
REG_MAP.repeat_block(1).register_a.field_b.OFFSET = 21;
REG_MAP.repeat_block(1).register_a.field_b.WIDTH = 1;
REG_MAP.repeat_block(1).register_a.field_b.PRESET = 0;
REG_MAP.repeat_block(1).register_a.field_c.ADDR = 0;
REG_MAP.repeat_block(1).register_a.field_c.OFFSET = 19;
REG_MAP.repeat_block(1).register_a.field_c.WIDTH = 1;
REG_MAP.repeat_block(1).register_a.field_c.PRESET = 0;

This MR also adds support for printing Matlab constants.

@tgingold-cern
Copy link
Owner

I am OK with the idea, but I am not sure the name of the new option is intuitive enough.
I have two counter-proposition:

  • Use --gen-struct-consts
  • Or, in the style: --consts-style=matlab-struct

I suppose that very few languages supports structured constants. Only python and matlab ?

@lorenzschmid
Copy link
Contributor Author

Thanks for your feedback. In fact, I thought about your second proposal too. In the end, it was easier to implement it with a separate argument. But I do not mind adapting it by using --consts-style=matlab-struct.

Right now, I added only support for Matlab. But Python should be easy to add.

@tgingold-cern
Copy link
Owner

So let's go for --consts-style=matlab-struct.

@lorenzschmid
Copy link
Contributor Author

Implemented in 40a5af0.

@tgingold-cern tgingold-cern merged commit bac5e3e into tgingold-cern:master Apr 17, 2024
2 checks passed
@lorenzschmid lorenzschmid deleted the gen-struct-matlab branch April 17, 2024 15:17
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