code generator: unifying size logic
This commit is contained in:
parent
3d33f45ab2
commit
7bc46cf448
Binary file not shown.
|
@ -15,7 +15,7 @@ import java.util.regex.Pattern;
|
||||||
* 1/15/15
|
* 1/15/15
|
||||||
*/
|
*/
|
||||||
public class ConfigField {
|
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]+))?\\])?";
|
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 isIterate,
|
||||||
boolean fsioVisible,
|
boolean fsioVisible,
|
||||||
boolean hasAutoscale,
|
boolean hasAutoscale,
|
||||||
String individualName,
|
|
||||||
int indexWithinArray,
|
|
||||||
String trueName,
|
String trueName,
|
||||||
String falseName) {
|
String falseName) {
|
||||||
this.fsioVisible = fsioVisible;
|
this.fsioVisible = fsioVisible;
|
||||||
|
@ -160,7 +158,7 @@ public class ConfigField {
|
||||||
|
|
||||||
|
|
||||||
ConfigField field = new ConfigField(state, name, comment, arraySizeAsText, type, arraySizes,
|
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("type " + type);
|
||||||
SystemOut.println("name " + name);
|
SystemOut.println("name " + name);
|
||||||
SystemOut.println("comment " + comment);
|
SystemOut.println("comment " + comment);
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class ReaderState {
|
||||||
String trueName = bitNameParts.length > 1 ? bitNameParts[1].replaceAll("\"", "") : null;
|
String trueName = bitNameParts.length > 1 ? bitNameParts[1].replaceAll("\"", "") : null;
|
||||||
String falseName = bitNameParts.length > 2 ? bitNameParts[2].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())
|
if (state.stack.isEmpty())
|
||||||
throw new IllegalStateException("Parent structure expected");
|
throw new IllegalStateException("Parent structure expected");
|
||||||
ConfigStructure structure = state.stack.peek();
|
ConfigStructure structure = state.stack.peek();
|
||||||
|
@ -242,8 +242,8 @@ public class ReaderState {
|
||||||
if (cf == null) {
|
if (cf == null) {
|
||||||
if (ConfigField.isPreprocessorDirective(line)) {
|
if (ConfigField.isPreprocessorDirective(line)) {
|
||||||
cf = new ConfigField(state, "", line, null,
|
cf = new ConfigField(state, "", line, null,
|
||||||
ConfigField.DIRECTIVE_T, new int[0], null, false, false, false, null, 0,
|
ConfigField.DIRECTIVE_T, new int[0], null, false, false, false,
|
||||||
null, null);
|
null, null);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Cannot parse line [" + line + "]");
|
throw new IllegalStateException("Cannot parse line [" + line + "]");
|
||||||
}
|
}
|
||||||
|
@ -266,7 +266,7 @@ public class ReaderState {
|
||||||
structure.addC(cf);
|
structure.addC(cf);
|
||||||
for (int i = 1; i <= cf.getArraySizes()[0]; i++) {
|
for (int i = 1; i <= cf.getArraySizes()[0]; i++) {
|
||||||
ConfigField element = new ConfigField(state, cf.getName() + i, cf.getComment(), null,
|
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);
|
structure.addTs(element);
|
||||||
}
|
}
|
||||||
} else if (cf.isDirective()) {
|
} else if (cf.isDirective()) {
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class ConfigStructure {
|
||||||
}
|
}
|
||||||
ConfigField fill = new ConfigField(state, ALIGNMENT_FILL_AT + totalSize, "need 4 byte alignment",
|
ConfigField fill = new ConfigField(state, ALIGNMENT_FILL_AT + totalSize, "need 4 byte alignment",
|
||||||
"" + fillSize,
|
"" + 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);
|
addBoth(fill);
|
||||||
}
|
}
|
||||||
totalSize += fillSize;
|
totalSize += fillSize;
|
||||||
|
@ -112,7 +112,7 @@ public class ConfigStructure {
|
||||||
return;
|
return;
|
||||||
int sizeAtStartOfPadding = cFields.size();
|
int sizeAtStartOfPadding = cFields.size();
|
||||||
while (readingBitState.get() < 32) {
|
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);
|
addBitField(bitField);
|
||||||
}
|
}
|
||||||
readingBitState.reset();
|
readingBitState.reset();
|
||||||
|
|
|
@ -19,12 +19,19 @@ public class FieldIterator {
|
||||||
this.tsFields = tsFields;
|
this.tsFields = tsFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return previous field which is not a directive
|
||||||
|
*/
|
||||||
public ConfigField getPrev() {
|
public ConfigField getPrev() {
|
||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(int index) {
|
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);
|
cf = tsFields.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,10 @@ public class TsOutput {
|
||||||
return settingContextHelp;
|
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();
|
String nameWithPrefix = prefix + configField.getName();
|
||||||
|
|
||||||
if (configField.isDirective() && configField.getComment() != null) {
|
if (configField.isDirective() && configField.getComment() != null) {
|
||||||
|
@ -70,7 +73,8 @@ public class TsOutput {
|
||||||
bits = bits.replaceAll("@OFFSET@", "" + tsPosition);
|
bits = bits.replaceAll("@OFFSET@", "" + tsPosition);
|
||||||
tsHeader.write(nameWithPrefix + " = " + bits);
|
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) {
|
} else if (configField.getTsInfo() == null) {
|
||||||
throw new IllegalArgumentException("Need TS info for " + configField.getName() + " at " + prefix);
|
throw new IllegalArgumentException("Need TS info for " + configField.getName() + " at " + prefix);
|
||||||
} else if (configField.getArraySizes().length == 0) {
|
} else if (configField.getArraySizes().length == 0) {
|
||||||
|
@ -78,7 +82,8 @@ public class TsOutput {
|
||||||
tsHeader.write(TypesHelper.convertToTs(configField.getType()) + ",");
|
tsHeader.write(TypesHelper.convertToTs(configField.getType()) + ",");
|
||||||
tsHeader.write(" " + tsPosition + ",");
|
tsHeader.write(" " + tsPosition + ",");
|
||||||
tsHeader.write(" " + handleTsInfo(configField.getTsInfo(), 1));
|
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) {
|
} else if (configField.getSize(next) == 0) {
|
||||||
// write nothing for empty array
|
// write nothing for empty array
|
||||||
// TS does not like those
|
// TS does not like those
|
||||||
|
@ -98,7 +103,8 @@ public class TsOutput {
|
||||||
}
|
}
|
||||||
tsHeader.write("], " + handleTsInfo(configField.getTsInfo(), 1));
|
tsHeader.write("], " + handleTsInfo(configField.getTsInfo(), 1));
|
||||||
|
|
||||||
tsPosition += configField.getSize(next);
|
if (!configField.getName().equals(next.getName()))
|
||||||
|
tsPosition += configField.getSize(next);
|
||||||
}
|
}
|
||||||
tsHeader.write(EOL);
|
tsHeader.write(EOL);
|
||||||
return tsPosition;
|
return tsPosition;
|
||||||
|
@ -106,22 +112,10 @@ public class TsOutput {
|
||||||
|
|
||||||
protected int writeTunerStudio(ConfigStructure configStructure, String prefix, Writer tsHeader, int tsPosition) throws IOException {
|
protected int writeTunerStudio(ConfigStructure configStructure, String prefix, Writer tsHeader, int tsPosition) throws IOException {
|
||||||
FieldIterator iterator = new FieldIterator(configStructure.tsFields);
|
FieldIterator iterator = new FieldIterator(configStructure.tsFields);
|
||||||
int prevTsPosition = tsPosition;
|
|
||||||
for (int i = 0; i < configStructure.tsFields.size(); i++) {
|
for (int i = 0; i < configStructure.tsFields.size(); i++) {
|
||||||
iterator.start(i);
|
iterator.start(i);
|
||||||
|
|
||||||
// if duplicate names, use previous position
|
tsPosition = writeTunerStudio(iterator, prefix, tsHeader, tsPosition);
|
||||||
// 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());
|
|
||||||
|
|
||||||
iterator.end();
|
iterator.end();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue