2 byte pin index #4097

short alignment
This commit is contained in:
rusefillc 2022-04-24 17:24:28 -04:00
parent 9947b34aec
commit 6354f6372c
3 changed files with 14 additions and 14 deletions

View File

@ -66,7 +66,7 @@ public class ReaderState {
if (log.debugEnabled())
log.debug("Need to align before bit " + bitName);
state.stack.peek().addAlignmentFill(state);
state.stack.peek().addAlignmentFill(state, 4);
String trueName = bitNameParts.length > 1 ? bitNameParts[1].replaceAll("\"", "") : null;
String falseName = bitNameParts.length > 2 ? bitNameParts[2].replaceAll("\"", "") : null;
@ -183,7 +183,7 @@ public class ReaderState {
ConfigStructure structure = stack.pop();
if (log.debugEnabled())
log.debug("Ending structure " + structure.getName());
structure.addAlignmentFill(this);
structure.addAlignmentFill(this, 4);
structures.put(structure.getName(), structure);
@ -287,10 +287,10 @@ public class ReaderState {
ConfigStructure structure = state.stack.peek();
Integer getPrimitiveSize = TypesHelper.getPrimitiveSize(cf.getType());
if (getPrimitiveSize != null && getPrimitiveSize % 4 == 0) {
if (getPrimitiveSize != null && getPrimitiveSize > 1) {
if (log.debugEnabled())
log.debug("Need to align before " + cf.getName());
structure.addAlignmentFill(state);
structure.addAlignmentFill(state, getPrimitiveSize);
} else {
// adding a structure instance - had to be aligned
// todo? structure.addAlignmentFill(state);

View File

@ -54,7 +54,7 @@ public class ConfigStructure {
return name;
}
public void addAlignmentFill(ReaderState state) {
public void addAlignmentFill(ReaderState state, int alignment) {
/**
* we make alignment decision based on C fields since we expect iteration and non-iteration fields
* to match in size
@ -69,7 +69,7 @@ public class ConfigStructure {
iterator.loop();
totalSize = iterator.currentOffset;
int fillSize = totalSize % 4 == 0 ? 0 : 4 - (totalSize % 4);
int fillSize = totalSize % alignment == 0 ? 0 : alignment - (totalSize % alignment);
if (fillSize != 0) {
int[] fillSizeArray;

View File

@ -286,8 +286,8 @@ public class ConfigFieldParserTest {
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
state.readBufferedReader(test, consumer, javaFieldsConsumer);
assertEquals("\tpublic static final Field BYTE1 = Field.create(\"BYTE1\", 0, FieldType.INT8).setScale(1.0);\n" +
"\tpublic static final Field SHORT = Field.create(\"SHORT\", 1, FieldType.INT16).setScale(1.0);\n" +
"\tpublic static final Field ALIGNMENTFILL_AT_3 = Field.create(\"ALIGNMENTFILL_AT_3\", 3, FieldType.INT8).setScale(1.0);\n" +
"\tpublic static final Field ALIGNMENTFILL_AT_1 = Field.create(\"ALIGNMENTFILL_AT_1\", 1, FieldType.INT8).setScale(1.0);\n" +
"\tpublic static final Field SHORT = Field.create(\"SHORT\", 2, FieldType.INT16).setScale(1.0);\n" +
"\tpublic static final Field INT2 = Field.create(\"INT2\", 4, FieldType.INT).setScale(1.0);\n" +
"\tpublic static final Field BYTE2 = Field.create(\"BYTE2\", 8, FieldType.INT8).setScale(1.0);\n" +
"\tpublic static final Field ALIGNMENTFILL_AT_9 = Field.create(\"ALIGNMENTFILL_AT_9\", 9, FieldType.INT8).setScale(1.0);\n" +
@ -331,15 +331,15 @@ public class ConfigFieldParserTest {
"\t */\n" +
"\tint8_t byte1 = (int8_t)0;\n" +
"\t/**\n" +
"\t * offset 1\n" +
"\t */\n" +
"\tint16_t short = (int16_t)0;\n" +
"\t/**\n" +
"\t * need 4 byte alignment\n" +
"\tunits\n" +
"\t * offset 3\n" +
"\t * offset 1\n" +
"\t */\n" +
"\tuint8_t alignmentFill_at_3[1];\n" +
"\tuint8_t alignmentFill_at_1[1];\n" +
"\t/**\n" +
"\t * offset 2\n" +
"\t */\n" +
"\tint16_t short = (int16_t)0;\n" +
"\t/**\n" +
"\t * offset 4\n" +
"\t */\n" +