tgingold-cern / cheby

GNU General Public License v3.0
7 stars 4 forks source link

Structured constant generation (and Matlab) #43

Closed lorenzschmid closed 2 months ago

lorenzschmid commented 2 months ago

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 commented 2 months ago

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:

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

lorenzschmid commented 2 months ago

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 commented 2 months ago

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

lorenzschmid commented 2 months ago

Implemented in 40a5af0286b84ff152a7e7c7d87996d7835099e3.