code generator: unifying size logic

This commit is contained in:
rusefillc 2021-12-11 03:50:28 -05:00
parent 90586f02a4
commit 742d0918b2
6 changed files with 27 additions and 28 deletions

Binary file not shown.

View File

@ -15,7 +15,7 @@ import java.util.regex.Pattern;
* 1/15/15
*/
public class ConfigField {
public static final ConfigField VOID = new ConfigField(null, "", null, null, null, new int[0], null, false, false, false, null, -1, null, null);
public static final ConfigField VOID = new ConfigField(null, "", null, null, null, new int[0], null, false, false, false, null, null);
private static final String typePattern = "([\\w\\d_]+)(\\[([\\w\\d]+)(\\sx\\s([\\w\\d]+))?(\\s([\\w\\d]+))?\\])?";
@ -60,8 +60,6 @@ public class ConfigField {
boolean isIterate,
boolean fsioVisible,
boolean hasAutoscale,
String individualName,
int indexWithinArray,
String trueName,
String falseName) {
this.fsioVisible = fsioVisible;
@ -160,7 +158,7 @@ public class ConfigField {
ConfigField field = new ConfigField(state, name, comment, arraySizeAsText, type, arraySizes,
tsInfo, isIterate, isFsioVisible, hasAutoscale, null, -1, null, null);
tsInfo, isIterate, isFsioVisible, hasAutoscale, null, null);
SystemOut.println("type " + type);
SystemOut.println("name " + name);
SystemOut.println("comment " + comment);

View File

@ -53,7 +53,7 @@ public class ReaderState {
String trueName = bitNameParts.length > 1 ? bitNameParts[1].replaceAll("\"", "") : null;
String falseName = bitNameParts.length > 2 ? bitNameParts[2].replaceAll("\"", "") : null;
ConfigField bitField = new ConfigField(state, bitNameParts[0], comment, null, BOOLEAN_T, new int[0], null, false, false, false, null, -1, trueName, falseName);
ConfigField bitField = new ConfigField(state, bitNameParts[0], comment, null, BOOLEAN_T, new int[0], null, false, false, false, trueName, falseName);
if (state.stack.isEmpty())
throw new IllegalStateException("Parent structure expected");
ConfigStructure structure = state.stack.peek();
@ -242,8 +242,8 @@ public class ReaderState {
if (cf == null) {
if (ConfigField.isPreprocessorDirective(line)) {
cf = new ConfigField(state, "", line, null,
ConfigField.DIRECTIVE_T, new int[0], null, false, false, false, null, 0,
null, null);
ConfigField.DIRECTIVE_T, new int[0], null, false, false, false,
null, null);
} else {
throw new IllegalStateException("Cannot parse line [" + line + "]");
}
@ -266,7 +266,7 @@ public class ReaderState {
structure.addC(cf);
for (int i = 1; i <= cf.getArraySizes()[0]; i++) {
ConfigField element = new ConfigField(state, cf.getName() + i, cf.getComment(), null,
cf.getType(), new int[0], cf.getTsInfo(), false, false, false, cf.getName(), i, null, null);
cf.getType(), new int[0], cf.getTsInfo(), false, false, false, null, null);
structure.addTs(element);
}
} else if (cf.isDirective()) {

View File

@ -78,7 +78,7 @@ public class ConfigStructure {
}
ConfigField fill = new ConfigField(state, ALIGNMENT_FILL_AT + totalSize, "need 4 byte alignment",
"" + fillSize,
TypesHelper.UINT8_T, fillSizeArray, "\"units\", 1, 0, -20, 100, 0", false, false, false, null, -1, null, null);
TypesHelper.UINT8_T, fillSizeArray, "\"units\", 1, 0, -20, 100, 0", false, false, false, null, null);
addBoth(fill);
}
totalSize += fillSize;
@ -112,7 +112,7 @@ public class ConfigStructure {
return;
int sizeAtStartOfPadding = cFields.size();
while (readingBitState.get() < 32) {
ConfigField bitField = new ConfigField(readerState, "unusedBit_" + sizeAtStartOfPadding + "_" + readingBitState.get(), "", null, BOOLEAN_T, new int[0], null, false, false, false, null, -1, null, null);
ConfigField bitField = new ConfigField(readerState, "unusedBit_" + sizeAtStartOfPadding + "_" + readingBitState.get(), "", null, BOOLEAN_T, new int[0], null, false, false, false, null, null);
addBitField(bitField);
}
readingBitState.reset();

View File

@ -19,12 +19,19 @@ public class FieldIterator {
this.tsFields = tsFields;
}
/**
* return previous field which is not a directive
*/
public ConfigField getPrev() {
return prev;
}
public void start(int index) {
next = index == tsFields.size() - 1 ? ConfigField.VOID : tsFields.get(index + 1);
int nextIndex = index + 1;
while (nextIndex < tsFields.size() && tsFields.get(nextIndex).isDirective())
nextIndex++;
next = nextIndex >= tsFields.size() ? ConfigField.VOID : tsFields.get(nextIndex);
cf = tsFields.get(index);
}

View File

@ -28,7 +28,10 @@ public class TsOutput {
return settingContextHelp;
}
private int writeTunerStudio(ConfigField configField, String prefix, Writer tsHeader, int tsPosition, ConfigField next, int bitIndex) throws IOException {
private int writeTunerStudio(FieldIterator it, String prefix, Writer tsHeader, int tsPosition) throws IOException {
ConfigField configField = it.cf;
ConfigField next = it.next;
int bitIndex = it.bitState.get();
String nameWithPrefix = prefix + configField.getName();
if (configField.isDirective() && configField.getComment() != null) {
@ -70,7 +73,8 @@ public class TsOutput {
bits = bits.replaceAll("@OFFSET@", "" + tsPosition);
tsHeader.write(nameWithPrefix + " = " + bits);
tsPosition += configField.getState().tsCustomSize.get(configField.getType());
if (!configField.getName().equals(next.getName()))
tsPosition += configField.getState().tsCustomSize.get(configField.getType());
} else if (configField.getTsInfo() == null) {
throw new IllegalArgumentException("Need TS info for " + configField.getName() + " at " + prefix);
} else if (configField.getArraySizes().length == 0) {
@ -78,7 +82,8 @@ public class TsOutput {
tsHeader.write(TypesHelper.convertToTs(configField.getType()) + ",");
tsHeader.write(" " + tsPosition + ",");
tsHeader.write(" " + handleTsInfo(configField.getTsInfo(), 1));
tsPosition += configField.getSize(next);
if (!configField.getName().equals(next.getName()))
tsPosition += configField.getSize(next);
} else if (configField.getSize(next) == 0) {
// write nothing for empty array
// TS does not like those
@ -98,7 +103,8 @@ public class TsOutput {
}
tsHeader.write("], " + handleTsInfo(configField.getTsInfo(), 1));
tsPosition += configField.getSize(next);
if (!configField.getName().equals(next.getName()))
tsPosition += configField.getSize(next);
}
tsHeader.write(EOL);
return tsPosition;
@ -106,22 +112,10 @@ public class TsOutput {
protected int writeTunerStudio(ConfigStructure configStructure, String prefix, Writer tsHeader, int tsPosition) throws IOException {
FieldIterator iterator = new FieldIterator(configStructure.tsFields);
int prevTsPosition = tsPosition;
for (int i = 0; i < configStructure.tsFields.size(); i++) {
iterator.start(i);
// if duplicate names, use previous position
// we can have same member twice in the
if (iterator.cf.getName().equals(iterator.getPrev().getName())) {
tsPosition = prevTsPosition;
}
// Update 'prev' state needed for duplicate names recognition
if (!iterator.cf.isDirective()) {
prevTsPosition = tsPosition;
}
tsPosition = writeTunerStudio(iterator.cf, prefix, tsHeader, tsPosition, iterator.next, iterator.bitState.get());
tsPosition = writeTunerStudio(iterator, prefix, tsHeader, tsPosition);
iterator.end();
}