'-initialize_to_zero' mode for code generator

This commit is contained in:
rusefi 2019-06-15 15:54:58 -04:00
parent 995cf20b4b
commit c3cfa41b98
4 changed files with 33 additions and 9 deletions

Binary file not shown.

View File

@ -37,6 +37,8 @@ public class ConfigDefinition {
private static final String KEY_ROMRAIDER_DESTINATION = "-romraider_destination";
public static final String KEY_PREPEND = "-prepend";
private static final String KEY_SKIP = "-skip";
private static final String KEY_ZERO_INIT = "-initialize_to_zero";
public static boolean needZeroInit; // ugly quick implementation
public static String definitionInputFile = null;
public static void main(String[] args) throws IOException {
@ -77,6 +79,8 @@ public class ConfigDefinition {
tsPath = args[i + 1];
} else if (key.equals(KEY_C_DESTINATION)) {
destCHeader = args[i + 1];
} else if (key.equals(KEY_ZERO_INIT)) {
needZeroInit = true;
} else if (key.equals(KEY_C_DEFINES)) {
destCDefines = args[i + 1];
} else if (key.equals(KEY_JAVA_DESTINATION)) {

View File

@ -22,18 +22,33 @@ public class TypesHelper {
return state.structures.get(type).totalSize;
if (state != null && state.tsCustomSize.containsKey(type))
return state.tsCustomSize.get(type);
if (type.equals(INT8_T) || type.equals(UINT8_T))
if (isPrimitive1byte(type))
return 1;
if (type.equals(INT_16_T) || type.equals(UINT_16_T)) {
if (isPrimitive2byte(type)) {
return 2;
}
if (type.equals(FLOAT_T) || type.equals(INT_32_T) || type.equals(UINT_32_T) ||
type.equals("angle_t")) {
if (isPrimitive4byte(type)) {
return 4;
}
throw new IllegalArgumentException("Unknown type " + type);
}
public static boolean isPrimitive(String type) {
return isPrimitive1byte(type) || isPrimitive2byte(type) || isPrimitive4byte(type);
}
private static boolean isPrimitive1byte(String type) {
return type.equals(INT8_T) || type.equals(UINT8_T);
}
private static boolean isPrimitive2byte(String type) {
return type.equals(INT_16_T) || type.equals(UINT_16_T);
}
private static boolean isPrimitive4byte(String type) {
return type.equals(INT_32_T) || isFloat(type);
}
public static String convertToTs(String type) {
if (isFloat(type))
return "F32";
@ -54,6 +69,8 @@ public class TypesHelper {
}
public static boolean isFloat(String type) {
return "float".equals(type) || type.equalsIgnoreCase("angle_t");
return FLOAT_T.equals(type) ||
type.equalsIgnoreCase("floatms_t") ||
type.equalsIgnoreCase("angle_t");
}
}

View File

@ -3,10 +3,9 @@ package com.rusefi.output;
import com.rusefi.ConfigDefinition;
import com.rusefi.ConfigField;
import com.rusefi.ConfigStructure;
import com.rusefi.TypesHelper;
import com.rusefi.util.LazyFile;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import static com.rusefi.ConfigDefinition.EOL;
@ -18,7 +17,7 @@ public class CHeaderConsumer implements ConfigurationConsumer {
public static final String BOOLEAN_TYPE = "bool";
private final LazyFile cHeader;
public CHeaderConsumer(String destCHeader) throws IOException {
public CHeaderConsumer(String destCHeader) {
System.out.println("Writing C header to " + destCHeader);
cHeader = new LazyFile(destCHeader);
cHeader.write("// this section " + ConfigDefinition.MESSAGE + EOL);
@ -39,7 +38,11 @@ public class CHeaderConsumer implements ConfigurationConsumer {
if (configField.getArraySize() == 1) {
// not an array
cEntry += "\t" + configField.getType() + " " + configField.getName() + ";" + EOL;
cEntry += "\t" + configField.getType() + " " + configField.getName();
if (ConfigDefinition.needZeroInit && TypesHelper.isPrimitive(configField.getType())) {
cEntry += " = 0";
}
cEntry += ";" + EOL;
} else {
cEntry += "\t" + configField.getType() + " " + configField.getName() + "[" + configField.arraySizeVariableName + "];" + EOL;
}