reduce flash footprint by smarter code generation #4163
This commit is contained in:
parent
a0943133cd
commit
8ad27f100f
|
@ -3,11 +3,14 @@ package com.rusefi.output;
|
|||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.TypesHelper;
|
||||
import com.rusefi.core.Pair;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.rusefi.output.ConfigStructure.ALIGNMENT_FILL_AT;
|
||||
import static com.rusefi.output.DataLogConsumer.UNUSED;
|
||||
|
@ -51,7 +54,7 @@ public class GetConfigValueConsumer implements ConfigurationConsumer {
|
|||
"\t}\n" +
|
||||
"\n";
|
||||
private static final String SET_METHOD_FOOTER = "}\n";
|
||||
private final StringBuilder getterBody = new StringBuilder();
|
||||
private final List<Pair<String, String>> getterPairs = new ArrayList<>();
|
||||
private final StringBuilder setterBody = new StringBuilder();
|
||||
private final StringBuilder allFloatAddresses = new StringBuilder(
|
||||
"static plain_get_float_s getF_plain[] = {\n");
|
||||
|
@ -105,8 +108,7 @@ public class GetConfigValueConsumer implements ConfigurationConsumer {
|
|||
if (TypesHelper.isFloat(cf.getType())) {
|
||||
allFloatAddresses.append("\t{" + quote(userName) + ", &engineConfiguration->" + userName + "},\n");
|
||||
} else {
|
||||
getterBody.append(getCompareName(userName));
|
||||
getterBody.append("\t\treturn " + javaName + cf.getName() + ";\n");
|
||||
getterPairs.add(new Pair<>(userName, javaName + cf.getName()));
|
||||
|
||||
setterBody.append(getCompareName(userName));
|
||||
String str = getAssignment(cf, javaName, "(int)");
|
||||
|
@ -138,6 +140,11 @@ public class GetConfigValueConsumer implements ConfigurationConsumer {
|
|||
|
||||
@NotNull
|
||||
public String getComleteGetterBody() {
|
||||
StringBuilder getterBody = new StringBuilder();
|
||||
for (Pair<String, String> pair : getterPairs) {
|
||||
getterBody.append(getCompareName(pair.first));
|
||||
getterBody.append("\t\treturn " + pair.second + ";\n");
|
||||
}
|
||||
return GET_METHOD_HEADER + getterBody + GET_METHOD_FOOTER;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,11 @@ package com.rusefi.output;
|
|||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.TypesHelper;
|
||||
import com.rusefi.core.Pair;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.rusefi.output.ConfigStructure.ALIGNMENT_FILL_AT;
|
||||
import static com.rusefi.output.DataLogConsumer.UNUSED;
|
||||
|
@ -13,7 +16,7 @@ import static com.rusefi.output.GetConfigValueConsumer.getCompareName;
|
|||
|
||||
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||
public class GetOutputValueConsumer implements ConfigurationConsumer {
|
||||
private final StringBuilder getterBody = new StringBuilder();
|
||||
private final List<Pair<String, String>> getterPairs = new ArrayList<>();
|
||||
private final String fileName;
|
||||
|
||||
public GetOutputValueConsumer(String fileName) {
|
||||
|
@ -42,8 +45,8 @@ public class GetOutputValueConsumer implements ConfigurationConsumer {
|
|||
String userName = prefix + cf.getName();
|
||||
String javaName = "engine->outputChannels." + prefix;
|
||||
|
||||
getterBody.append(getCompareName(userName));
|
||||
getterBody.append("\t\treturn " + javaName + cf.getName() + ";\n");
|
||||
getterPairs.add(new Pair<>(userName, javaName + cf.getName()));
|
||||
|
||||
|
||||
return "";
|
||||
}
|
||||
|
@ -54,6 +57,12 @@ public class GetOutputValueConsumer implements ConfigurationConsumer {
|
|||
}
|
||||
|
||||
public String getContent() {
|
||||
StringBuilder getterBody = new StringBuilder();
|
||||
for (Pair<String, String> pair : getterPairs) {
|
||||
getterBody.append(getCompareName(pair.first));
|
||||
getterBody.append("\t\treturn " + pair.second + ";\n");
|
||||
}
|
||||
|
||||
return FILE_HEADER +
|
||||
"float getOutputValueByName(const char *name) {\n" + getterBody + GetConfigValueConsumer.GET_METHOD_FOOTER;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue