config gen layout fixes (#2829)
* grammar and libs * gitignore * parsing * allow empty line as root statement * tolerate #if * config def changes * s * ant build * workaround * compiled tool * grammar for unions * parse unions * layout logic * fix union alignment * union in config * enable definition resolve * testing * zero init behavior * bit fields respect custom options * ts prints arrays correctly * ts prints structs correctly * auto round numbers * cleanup * bad merge * bad merge * jar * kick
This commit is contained in:
parent
f1ab826f57
commit
b6195fcc55
Binary file not shown.
|
@ -304,7 +304,15 @@ public class ParseState extends RusefiConfigGrammarBaseListener {
|
||||||
|
|
||||||
String comment = ctx.SemicolonedSuffix() == null ? null : ctx.SemicolonedSuffix().getText();
|
String comment = ctx.SemicolonedSuffix() == null ? null : ctx.SemicolonedSuffix().getText();
|
||||||
|
|
||||||
group.addBitField(new BitField(name, comment));
|
String trueValue = "\"true\"";
|
||||||
|
String falseValue = "\"false\"";
|
||||||
|
|
||||||
|
if (!ctx.QuotedString().isEmpty()) {
|
||||||
|
trueValue = ctx.QuotedString(0).getText();
|
||||||
|
falseValue = ctx.QuotedString(1).getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
group.addBitField(new BitField(name, comment, trueValue, falseValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,10 +13,14 @@ public class BitGroupLayout extends Layout {
|
||||||
private class BitLayout {
|
private class BitLayout {
|
||||||
public final String name;
|
public final String name;
|
||||||
public final String comment;
|
public final String comment;
|
||||||
|
public final String trueValue;
|
||||||
|
public final String falseValue;
|
||||||
|
|
||||||
public BitLayout(String name, String comment) {
|
public BitLayout(String name, String comment, String trueValue, String falseValue) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
|
this.trueValue = trueValue;
|
||||||
|
this.falseValue = falseValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +32,7 @@ public class BitGroupLayout extends Layout {
|
||||||
throw new RuntimeException("tried to create bit group starting with " + bitGroup.bitFields.get(0).name + " but it contained " + size + " which is more than the maximum of 32.");
|
throw new RuntimeException("tried to create bit group starting with " + bitGroup.bitFields.get(0).name + " but it contained " + size + " which is more than the maximum of 32.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.bits = bitGroup.bitFields.stream().map(bf -> new BitLayout(bf.name, bf.comment)).collect(Collectors.toList());
|
this.bits = bitGroup.bitFields.stream().map(bf -> new BitLayout(bf.name, bf.comment, bf.trueValue, bf.falseValue)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,8 +55,7 @@ public class BitGroupLayout extends Layout {
|
||||||
ps.print(", [");
|
ps.print(", [");
|
||||||
ps.print(i + ":" + i);
|
ps.print(i + ":" + i);
|
||||||
|
|
||||||
// TODO: print actual bit options
|
ps.print("], " + bit.falseValue + ", " + bit.trueValue);
|
||||||
ps.print("], \"false\", \"true\"");
|
|
||||||
|
|
||||||
ps.println();
|
ps.println();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.rusefi.newparse.layout;
|
package com.rusefi.newparse.layout;
|
||||||
|
|
||||||
|
import com.rusefi.ConfigDefinition;
|
||||||
import com.rusefi.newparse.parsing.FieldOptions;
|
import com.rusefi.newparse.parsing.FieldOptions;
|
||||||
import com.rusefi.newparse.parsing.ScalarField;
|
import com.rusefi.newparse.parsing.ScalarField;
|
||||||
import com.rusefi.newparse.parsing.Type;
|
import com.rusefi.newparse.parsing.Type;
|
||||||
|
@ -27,9 +28,9 @@ public class ScalarLayout extends Layout {
|
||||||
return "Scalar " + type.cType + " " + super.toString();
|
return "Scalar " + type.cType + " " + super.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printBeforeArrayLength(PrintStream ps, StructNamePrefixer prefixer) {
|
private void printBeforeArrayLength(PrintStream ps, StructNamePrefixer prefixer, String fieldType) {
|
||||||
ps.print(prefixer.get(this.name));
|
ps.print(prefixer.get(this.name));
|
||||||
ps.print(" = scalar, ");
|
ps.print(" = " + fieldType + ", ");
|
||||||
ps.print(this.type.tsType);
|
ps.print(this.type.tsType);
|
||||||
ps.print(", ");
|
ps.print(", ");
|
||||||
ps.print(this.offset);
|
ps.print(this.offset);
|
||||||
|
@ -44,7 +45,12 @@ public class ScalarLayout extends Layout {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTunerstudioLayout(PrintStream ps, StructNamePrefixer prefixer, int arrayLength) {
|
public void writeTunerstudioLayout(PrintStream ps, StructNamePrefixer prefixer, int arrayLength) {
|
||||||
printBeforeArrayLength(ps, prefixer);
|
if (arrayLength == 0) {
|
||||||
|
// Skip zero length arrays, they may be used for dynamic padding but TS doesn't like them
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printBeforeArrayLength(ps, prefixer, "array");
|
||||||
|
|
||||||
ps.print("[");
|
ps.print("[");
|
||||||
ps.print(arrayLength);
|
ps.print(arrayLength);
|
||||||
|
@ -55,14 +61,20 @@ public class ScalarLayout extends Layout {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTunerstudioLayout(PrintStream ps, StructNamePrefixer prefixer) {
|
public void writeTunerstudioLayout(PrintStream ps, StructNamePrefixer prefixer) {
|
||||||
printBeforeArrayLength(ps, prefixer);
|
printBeforeArrayLength(ps, prefixer, "scalar");
|
||||||
printAfterArrayLength(ps);
|
printAfterArrayLength(ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeCLayout(PrintStream ps) {
|
public void writeCLayout(PrintStream ps) {
|
||||||
this.writeCOffsetHeader(ps, this.options.comment, this.options.units);
|
this.writeCOffsetHeader(ps, this.options.comment, this.options.units);
|
||||||
ps.println("\t" + this.type.cType.replaceAll("^int32_t$", "int") + " " + this.name + ";");
|
ps.print("\t" + this.type.cType.replaceAll("^int32_t$", "int") + " " + this.name);
|
||||||
|
|
||||||
|
if (ConfigDefinition.needZeroInit) {
|
||||||
|
ps.print(" = (" + this.type.cType.replaceAll("^int32_t$", "int") + ")0");
|
||||||
|
}
|
||||||
|
|
||||||
|
ps.println(";");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -158,7 +158,6 @@ public class StructLayout extends Layout {
|
||||||
@Override
|
@Override
|
||||||
public void writeTunerstudioLayout(PrintStream ps, StructNamePrefixer prefixer) {
|
public void writeTunerstudioLayout(PrintStream ps, StructNamePrefixer prefixer) {
|
||||||
if (!this.noPrefix) {
|
if (!this.noPrefix) {
|
||||||
ps.println("; start struct " + this.typeName);
|
|
||||||
prefixer.push(this.name);
|
prefixer.push(this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,10 +167,6 @@ public class StructLayout extends Layout {
|
||||||
if (!this.noPrefix) {
|
if (!this.noPrefix) {
|
||||||
prefixer.pop();
|
prefixer.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.noPrefix) {
|
|
||||||
ps.println("; end struct " + this.typeName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,10 +3,14 @@ package com.rusefi.newparse.parsing;
|
||||||
public class BitField {
|
public class BitField {
|
||||||
public final String name;
|
public final String name;
|
||||||
public final String comment;
|
public final String comment;
|
||||||
|
public final String trueValue;
|
||||||
|
public final String falseValue;
|
||||||
|
|
||||||
public BitField(String name, String comment) {
|
public BitField(String name, String comment, String trueValue, String falseValue) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
|
this.trueValue = trueValue;
|
||||||
|
this.falseValue = falseValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -36,16 +36,27 @@ public class FieldOptions {
|
||||||
return other;
|
return other;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String tryRound(float value) {
|
||||||
|
int intVal = Math.round(value);
|
||||||
|
|
||||||
|
// If the rounded value can exactly represent this float, then print as an integer
|
||||||
|
if (value == intVal) {
|
||||||
|
return Integer.toString(intVal);
|
||||||
|
} else {
|
||||||
|
return Float.toString(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void printTsFormat(PrintStream ps) {
|
public void printTsFormat(PrintStream ps) {
|
||||||
ps.print(units);
|
ps.print(units);
|
||||||
ps.print(", ");
|
ps.print(", ");
|
||||||
ps.print(scale);
|
ps.print(tryRound(scale));
|
||||||
ps.print(", ");
|
ps.print(", ");
|
||||||
ps.print(offset);
|
ps.print(tryRound(offset));
|
||||||
ps.print(", ");
|
ps.print(", ");
|
||||||
ps.print(min);
|
ps.print(tryRound(min));
|
||||||
ps.print(", ");
|
ps.print(", ");
|
||||||
ps.print(max);
|
ps.print(tryRound(max));
|
||||||
ps.print(", ");
|
ps.print(", ");
|
||||||
ps.print(digits);
|
ps.print(digits);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue