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();
|
||||
|
||||
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
|
||||
|
|
|
@ -13,10 +13,14 @@ public class BitGroupLayout extends Layout {
|
|||
private class BitLayout {
|
||||
public final String name;
|
||||
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.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.");
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -51,8 +55,7 @@ public class BitGroupLayout extends Layout {
|
|||
ps.print(", [");
|
||||
ps.print(i + ":" + i);
|
||||
|
||||
// TODO: print actual bit options
|
||||
ps.print("], \"false\", \"true\"");
|
||||
ps.print("], " + bit.falseValue + ", " + bit.trueValue);
|
||||
|
||||
ps.println();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.newparse.layout;
|
||||
|
||||
import com.rusefi.ConfigDefinition;
|
||||
import com.rusefi.newparse.parsing.FieldOptions;
|
||||
import com.rusefi.newparse.parsing.ScalarField;
|
||||
import com.rusefi.newparse.parsing.Type;
|
||||
|
@ -27,9 +28,9 @@ public class ScalarLayout extends Layout {
|
|||
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(" = scalar, ");
|
||||
ps.print(" = " + fieldType + ", ");
|
||||
ps.print(this.type.tsType);
|
||||
ps.print(", ");
|
||||
ps.print(this.offset);
|
||||
|
@ -44,7 +45,12 @@ public class ScalarLayout extends Layout {
|
|||
|
||||
@Override
|
||||
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(arrayLength);
|
||||
|
@ -55,14 +61,20 @@ public class ScalarLayout extends Layout {
|
|||
|
||||
@Override
|
||||
public void writeTunerstudioLayout(PrintStream ps, StructNamePrefixer prefixer) {
|
||||
printBeforeArrayLength(ps, prefixer);
|
||||
printBeforeArrayLength(ps, prefixer, "scalar");
|
||||
printAfterArrayLength(ps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCLayout(PrintStream ps) {
|
||||
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
|
||||
|
|
|
@ -158,7 +158,6 @@ public class StructLayout extends Layout {
|
|||
@Override
|
||||
public void writeTunerstudioLayout(PrintStream ps, StructNamePrefixer prefixer) {
|
||||
if (!this.noPrefix) {
|
||||
ps.println("; start struct " + this.typeName);
|
||||
prefixer.push(this.name);
|
||||
}
|
||||
|
||||
|
@ -168,10 +167,6 @@ public class StructLayout extends Layout {
|
|||
if (!this.noPrefix) {
|
||||
prefixer.pop();
|
||||
}
|
||||
|
||||
if (!this.noPrefix) {
|
||||
ps.println("; end struct " + this.typeName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,10 +3,14 @@ package com.rusefi.newparse.parsing;
|
|||
public class BitField {
|
||||
public final String name;
|
||||
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.comment = comment;
|
||||
this.trueValue = trueValue;
|
||||
this.falseValue = falseValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -36,16 +36,27 @@ public class FieldOptions {
|
|||
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) {
|
||||
ps.print(units);
|
||||
ps.print(", ");
|
||||
ps.print(scale);
|
||||
ps.print(tryRound(scale));
|
||||
ps.print(", ");
|
||||
ps.print(offset);
|
||||
ps.print(tryRound(offset));
|
||||
ps.print(", ");
|
||||
ps.print(min);
|
||||
ps.print(tryRound(min));
|
||||
ps.print(", ");
|
||||
ps.print(max);
|
||||
ps.print(tryRound(max));
|
||||
ps.print(", ");
|
||||
ps.print(digits);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue