[PATCH 09/22] MICROROS, EE3: Fixed generation for labels for ERIKA - Changed Label generator (copied from Linux SLG) - Added "extern C" for C code - Added debug printf
diff --git a/load_generator/plugins/org.eclipse.app4mc.slg.ros2/src/org/eclipse/app4mc/slg/microros/generators/MicroRosLabelGenerator.xtend b/load_generator/plugins/org.eclipse.app4mc.slg.ros2/src/org/eclipse/app4mc/slg/microros/generators/MicroRosLabelGenerator.xtend index 23eaa50..d06e8ee 100644 --- a/load_generator/plugins/org.eclipse.app4mc.slg.ros2/src/org/eclipse/app4mc/slg/microros/generators/MicroRosLabelGenerator.xtend +++ b/load_generator/plugins/org.eclipse.app4mc.slg.ros2/src/org/eclipse/app4mc/slg/microros/generators/MicroRosLabelGenerator.xtend
@@ -1,5 +1,5 @@ /** - * Copyright (c) 2020-2022 Robert Bosch GmbH. + * Copyright (c) 2020-2023 Robert Bosch GmbH. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -15,6 +15,7 @@ import java.util.List import org.eclipse.app4mc.amalthea.model.Label +import org.eclipse.app4mc.slg.commons.m2t.AmaltheaModelUtils class MicroRosLabelGenerator { @@ -25,9 +26,9 @@ // ---------- names of generated 'C' functions ---------- - static def String initCall(String labelName) { initCall(labelName, "_CacheLine* array, int array_elements") } + static def String initCall(String labelName) '''initialize_«labelName»()''' - static def String initCall(String labelName, String param) '''initialize_«labelName»(«labelName»«param»)''' + // static def String initCall(String labelName, String param) '''initialize_«labelName»(«labelName»«param»)''' static def String readCall(String labelName, String param) '''read_«labelName»(«param»)''' static def String writeCall(String labelName, String param) '''write_«labelName»(«param»)''' @@ -54,13 +55,11 @@ val name = if (label?.name.isNullOrEmpty) "<undefined label>" else label.name ''' - typedef struct «name»_CacheLine - { - struct «name»_CacheLine* ptrCacheLine[8] ; - } «name»_CacheLine ; - void «initCall(name, "_CacheLine* array, int array_elements")»; + extern "C" { + void «initCall(name)»; void «readCall(name, "int labelAccessStatistics")»; void «writeCall(name, "int labelAccessStatistics")»; + } ''' } @@ -70,77 +69,88 @@ val numberOfBytes = if (label?.size === null) 0 else label.size.numberBytes ''' - void initialize_«name»(«name»_CacheLine* array,int array_elements) { - int steps = array_elements / 2 ; - int bottom = 0 ; - int top = steps ; - int i = 0; - for (i = 0 ; i < steps ; i++) { - array[bottom].ptrCacheLine[0] = &array[top] ; - array[top].ptrCacheLine[0] = &array[bottom+1] ; - top++ ; - bottom++ ; - } - array[(array_elements-1)].ptrCacheLine[0] = NULL ; + int «name»[«AmaltheaModelUtils.getLabelArraySize(label)»]; + + static bool isIinitialized_«name» = false; + void «initCall(name)» { + if (!isIinitialized_«name»){ + int i; + for (i=0; i < «AmaltheaModelUtils.getLabelArraySize(label)»; i++){ + «name»[i] = i+1; + } + isIinitialized_«name» = true; + } } - - - - void «readCall(label.name, "int labelAccessStatistics")» { - static bool initialized = false; - int numberOfBytes = «numberOfBytes»; - static «name»_CacheLine* «name»; - if(!initialized) { - //init - «name» = («name»_CacheLine*) malloc(sizeof(«name»_CacheLine) * 17000); - initialize_«name»(«name», 17000); - initialized = true; + + void «readCall(name, "int labelAccessStatistics")» + { + debug_printf(" read «name»\n"); + int numberOfBytes = «numberOfBytes»; + int repeat; + for (repeat = 0 ; repeat < labelAccessStatistics; repeat++){ + if(numberOfBytes < 4){ + numberOfBytes = 4; } - - static «name»_CacheLine* i = «name»; - static int counter = 0; - - if(counter > 16100) { - counter = 0; - i = «name»; + int arraysize = sizeof(«name») / 4; + + int leftOverElements=arraysize%10; + int arraySizeWith10Multiples=arraysize-leftOverElements; + int i = 0; + int a = 0; + for (i = 0; i < arraySizeWith10Multiples; i = i + 10) { //iteration with 10 reads + a = «name»[i]; + a = «name»[i+1]; + a = «name»[i+2]; + a = «name»[i+3]; + a = «name»[i+4]; + a = «name»[i+5]; + a = «name»[i+6]; + a = «name»[i+7]; + a = «name»[i+8]; + a = «name»[i+9]; } - + int end_value = counter + numberOfBytes; - - for(; counter < end_value; counter ++) { - i = i->ptrCacheLine[0]; + + for(;i<arraysize;i++){ + a = «name»[i]; } - + + (void)a; + } } - - - - void «writeCall(label.name, "int labelAccessStatistics")» { - static bool initialized = false; - int numberOfBytes = «numberOfBytes»; - static «name»_CacheLine* «name»; - if(!initialized) { - //init - «name» = («name»_CacheLine*) malloc(sizeof(«name»_CacheLine) * 17000); - initialize_«name»(«name», 17000); - initialized = true; - } - - static «name»_CacheLine* i = «name»; - static int counter = 0; - - if(counter > 16100) { - counter = 0; - i = «name»; - } - - int end_value = counter + numberOfBytes; - - for(; counter < end_value; counter ++) { - i = i->ptrCacheLine[0]; - } + + void «writeCall(name, "int labelAccessStatistics")» + { + debug_printf(" write «name»\n"); + int numberOfBytes = «numberOfBytes»; + int repeat; + for (repeat = 0 ; repeat < labelAccessStatistics; repeat++){ + if(numberOfBytes < 4){ + numberOfBytes = 4; + } + int arraysize = sizeof(«name») / 4; + int leftOverElements=arraysize%10; + int arraySizeWith10Multiples=arraysize-leftOverElements; + + int i = 0; + for (i = 0; i < arraySizeWith10Multiples; i = i + 10) { + «name»[i] = 0x800A; + «name»[i+1] = 0xAFFE; + «name»[i+2] = 0xAFFE; + «name»[i+3] = 0xAFFE; + «name»[i+4] = 0xAFFE; + «name»[i+5] = 0xAFFE; + «name»[i+6] = 0xAFFE; + «name»[i+7] = 0xAFFE; + «name»[i+8] = 0xAFFE; + «name»[i+9] = 0xAFFE; + } + for(;i<arraysize;i++){ + «name»[i]=0xAFFE; + } + } } - ''' }
diff --git a/load_generator/plugins/org.eclipse.app4mc.slg.ros2/src/org/eclipse/app4mc/slg/microros/transformers/MicroRosLabelTransformer.java b/load_generator/plugins/org.eclipse.app4mc.slg.ros2/src/org/eclipse/app4mc/slg/microros/transformers/MicroRosLabelTransformer.java index 785d9da..779ec0e 100644 --- a/load_generator/plugins/org.eclipse.app4mc.slg.ros2/src/org/eclipse/app4mc/slg/microros/transformers/MicroRosLabelTransformer.java +++ b/load_generator/plugins/org.eclipse.app4mc.slg.ros2/src/org/eclipse/app4mc/slg/microros/transformers/MicroRosLabelTransformer.java
@@ -1,6 +1,6 @@ /** ******************************************************************************** - * Copyright (c) 2020-2022 Robert Bosch GmbH. + * Copyright (c) 2020-2023 Robert Bosch GmbH. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -15,52 +15,96 @@ package org.eclipse.app4mc.slg.microros.transformers; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.eclipse.app4mc.amalthea.model.Label; +import org.eclipse.app4mc.amalthea.model.Tag; import org.eclipse.app4mc.slg.commons.m2t.transformers.SLGTranslationUnit; -import org.eclipse.app4mc.slg.commons.m2t.transformers.sw.LabelTransformer; import org.eclipse.app4mc.slg.microros.generators.MicroRosLabelGenerator; +import org.eclipse.app4mc.slg.ros2.transformers.RosBaseTransformer; +import org.eclipse.app4mc.slg.ros2.transformers.utils.RosModelUtils; import org.eclipse.app4mc.transformation.util.OutputBuffer; import com.google.inject.Inject; -public class MicroRosLabelTransformer extends LabelTransformer { +public class MicroRosLabelTransformer extends RosBaseTransformer { public static final String LIB_NAME = "LABELS_LIB"; - public static final String BASE_PATH = "MICROROS_SLG/synthetic_gen"; + public static final String BASE_PATH = "synthetic_gen"; public static final String MODULE_NAME = "labels"; public static final String MODULE_PATH = BASE_PATH + "/" + MODULE_NAME; public static final String MAKEFILE_PATH = MODULE_PATH + "/CMakeLists.txt"; @Inject private OutputBuffer outputBuffer; - @Override - protected void genFiles(SLGTranslationUnit tu, Label label) { - if (isSrcFileEmpty(tu)) { + // ---------- generic part "def create new transform(...)" ---------- - srcAppend(tu,"#include \"" + getIncFile(tu) + "\"\n\n"); - srcAppend(tu, "#include <stdlib.h>\n"); + private final Map<List<Object>, SLGTranslationUnit> transformCache = new HashMap<>(); + + @Override + public Map<List<Object>, SLGTranslationUnit> getCache() { + return this.transformCache; + } + + public SLGTranslationUnit transform(final Label label, final Tag tag) { + final String target = RosModelUtils.getROSTargetName(tag); + final List<Object> key = new ArrayList<>(Arrays.asList(label, target)); + final SLGTranslationUnit tu; + + synchronized (transformCache) { + if (transformCache.containsKey(key)) { + return transformCache.get(key); + } + tu = createTranslationUnit(label, target); + transformCache.put(key, tu); } - incAppend(tu, "#pragma once \n\n"); - incAppend(tu, MicroRosLabelGenerator.toH(label)); - srcAppend(tu, MicroRosLabelGenerator.toCpp(label)); + + // if translation unit is newly created and valid -> create files + if (tu.isValid()) { + doTransform(tu, label); + } + + return tu; } - @Override - public boolean createCMake() { - return outputBuffer.appendTo( - "OTHER", MAKEFILE_PATH, MicroRosLabelGenerator.toCMake(LIB_NAME, getSrcFiles())); - } + // --------------------------------------------------- - @Override - protected SLGTranslationUnit createTranslationUnit(Label label) { + protected SLGTranslationUnit createTranslationUnit(Label label, String target) { if ((label == null)) { return new SLGTranslationUnit("UNSPECIFIED LABEL"); } else { - String basePath = BASE_PATH; + String basePath = target + "/" + BASE_PATH; String moduleName = MODULE_NAME; String call = label.getName(); return new SLGTranslationUnit(basePath, moduleName, call); } } + protected void doTransform(final SLGTranslationUnit tu, final Label label) { + genFiles(tu, label); + } + + protected void genFiles(SLGTranslationUnit tu, Label label) { + incAppend(tu, "#pragma once \n\n"); + incAppend(tu, MicroRosLabelGenerator.toH(label)); + + if (isSrcFileEmpty(tu)) { + srcAppend(tu, "#include \"" + getIncFile(tu) + "\"\n"); + srcAppend(tu, "#include <stdlib.h>\n"); + srcAppend(tu, "#include \"output_console.h\"\n\n"); + } + srcAppend(tu, "#ifdef __cplusplus \n extern \"C\" \n {\n#endif\n\n"); + srcAppend(tu, MicroRosLabelGenerator.toCpp(label)); + srcAppend(tu, "#ifdef __cplusplus \n }\n#endif\n\n"); + } + + public boolean createCMake(String target) { + return outputBuffer.appendTo( + "OTHER", target + "/" + MAKEFILE_PATH, MicroRosLabelGenerator.toCMake(LIB_NAME, getSrcFiles())); + } + }
diff --git a/load_generator/plugins/org.eclipse.app4mc.slg.ros2/xtend-gen/org/eclipse/app4mc/slg/microros/generators/MicroRosLabelGenerator.java b/load_generator/plugins/org.eclipse.app4mc.slg.ros2/xtend-gen/org/eclipse/app4mc/slg/microros/generators/MicroRosLabelGenerator.java index 6526769..737daf9 100644 --- a/load_generator/plugins/org.eclipse.app4mc.slg.ros2/xtend-gen/org/eclipse/app4mc/slg/microros/generators/MicroRosLabelGenerator.java +++ b/load_generator/plugins/org.eclipse.app4mc.slg.ros2/xtend-gen/org/eclipse/app4mc/slg/microros/generators/MicroRosLabelGenerator.java
@@ -1,5 +1,5 @@ /** - * Copyright (c) 2020-2022 Robert Bosch GmbH. + * Copyright (c) 2020-2023 Robert Bosch GmbH. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -15,6 +15,7 @@ import java.util.List; import org.eclipse.app4mc.amalthea.model.DataSize; import org.eclipse.app4mc.amalthea.model.Label; +import org.eclipse.app4mc.slg.commons.m2t.AmaltheaModelUtils; import org.eclipse.xtend2.lib.StringConcatenation; import org.eclipse.xtext.xbase.lib.StringExtensions; @@ -25,17 +26,10 @@ } public static String initCall(final String labelName) { - return MicroRosLabelGenerator.initCall(labelName, "_CacheLine* array, int array_elements"); - } - - public static String initCall(final String labelName, final String param) { StringConcatenation _builder = new StringConcatenation(); _builder.append("initialize_"); _builder.append(labelName); - _builder.append("("); - _builder.append(labelName); - _builder.append(param); - _builder.append(")"); + _builder.append("()"); return _builder.toString(); } @@ -106,23 +100,10 @@ } final String name = _xifexpression; StringConcatenation _builder = new StringConcatenation(); - _builder.append("typedef struct "); - _builder.append(name); - _builder.append("_CacheLine"); - _builder.newLineIfNotEmpty(); - _builder.append("{"); + _builder.append("extern \"C\" {"); _builder.newLine(); - _builder.append(" "); - _builder.append("struct "); - _builder.append(name, " "); - _builder.append("_CacheLine* ptrCacheLine[8] ;"); - _builder.newLineIfNotEmpty(); - _builder.append("} "); - _builder.append(name); - _builder.append("_CacheLine ;"); - _builder.newLineIfNotEmpty(); _builder.append("void "); - String _initCall = MicroRosLabelGenerator.initCall(name, "_CacheLine* array, int array_elements"); + String _initCall = MicroRosLabelGenerator.initCall(name); _builder.append(_initCall); _builder.append(";"); _builder.newLineIfNotEmpty(); @@ -136,6 +117,8 @@ _builder.append(_writeCall); _builder.append(";"); _builder.newLineIfNotEmpty(); + _builder.append("}"); + _builder.newLine(); _builder.newLine(); _xblockexpression = _builder.toString(); } @@ -170,241 +153,294 @@ } final long numberOfBytes = _xifexpression_1; StringConcatenation _builder = new StringConcatenation(); - _builder.append("void initialize_"); + _builder.append("int "); _builder.append(name); - _builder.append("("); - _builder.append(name); - _builder.append("_CacheLine* array,int array_elements) {"); + _builder.append("["); + long _labelArraySize = AmaltheaModelUtils.getLabelArraySize(label); + _builder.append(_labelArraySize); + _builder.append("];"); _builder.newLineIfNotEmpty(); - _builder.append(" "); - _builder.append("int steps = array_elements / 2 ;"); _builder.newLine(); - _builder.append(" "); - _builder.append("int bottom = 0 ;"); + _builder.append("static bool isIinitialized_"); + _builder.append(name); + _builder.append(" = false;"); + _builder.newLineIfNotEmpty(); + _builder.append("void "); + String _initCall = MicroRosLabelGenerator.initCall(name); + _builder.append(_initCall); + _builder.append(" {"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("if (!isIinitialized_"); + _builder.append(name, "\t"); + _builder.append("){"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t"); + _builder.append("int i;"); _builder.newLine(); - _builder.append(" "); - _builder.append("int top = steps ;"); + _builder.append("\t\t"); + _builder.append("for (i=0; i < "); + long _labelArraySize_1 = AmaltheaModelUtils.getLabelArraySize(label); + _builder.append(_labelArraySize_1, "\t\t"); + _builder.append("; i++){"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append(name, "\t\t\t"); + _builder.append("[i] = i+1;"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t"); + _builder.append("}"); _builder.newLine(); - _builder.append(" "); + _builder.append("\t\t"); + _builder.append("isIinitialized_"); + _builder.append(name, "\t\t"); + _builder.append(" = true;"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + _builder.newLine(); + _builder.append("void "); + String _readCall = MicroRosLabelGenerator.readCall(name, "int labelAccessStatistics"); + _builder.append(_readCall); + _builder.newLineIfNotEmpty(); + _builder.append("{"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("debug_printf(\" read "); + _builder.append(name, "\t"); + _builder.append("\\n\");"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("int numberOfBytes = "); + _builder.append(numberOfBytes, "\t"); + _builder.append(";"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("int repeat;"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("for (repeat = 0 ; repeat < labelAccessStatistics; repeat++){"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("if(numberOfBytes < 4){"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("numberOfBytes = 4;"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("int arraysize = sizeof("); + _builder.append(name, "\t\t"); + _builder.append(") / 4;"); + _builder.newLineIfNotEmpty(); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("int leftOverElements=arraysize%10;"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("int arraySizeWith10Multiples=arraysize-leftOverElements;"); + _builder.newLine(); + _builder.append("\t\t"); _builder.append("int i = 0;"); _builder.newLine(); - _builder.append(" "); - _builder.append("for (i = 0 ; i < steps ; i++) {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("array[bottom].ptrCacheLine[0] = &array[top] ;"); - _builder.newLine(); - _builder.append(" "); - _builder.append("array[top].ptrCacheLine[0] = &array[bottom+1] ;"); - _builder.newLine(); - _builder.append(" "); - _builder.append("top++ ;"); - _builder.newLine(); - _builder.append(" "); - _builder.append("bottom++ ;"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("array[(array_elements-1)].ptrCacheLine[0] = NULL ;\t"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.newLine(); - _builder.newLine(); - _builder.append("void "); - String _readCall = MicroRosLabelGenerator.readCall(label.getName(), "int labelAccessStatistics"); - _builder.append(_readCall); - _builder.append(" {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("static bool initialized = false;"); + _builder.append("\t\t"); + _builder.append("int a = 0;"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("int numberOfBytes = "); - _builder.append(numberOfBytes, "\t\t"); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("static "); - _builder.append(name, "\t\t"); - _builder.append("_CacheLine* "); - _builder.append(name, "\t\t"); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("if(!initialized) {"); + _builder.append("for (i = 0; i < arraySizeWith10Multiples; i = i + 10) { //iteration with 10 reads"); _builder.newLine(); _builder.append("\t\t\t"); - _builder.append("//init"); - _builder.newLine(); - _builder.append("\t\t\t"); + _builder.append("a = "); _builder.append(name, "\t\t\t"); - _builder.append(" = ("); - _builder.append(name, "\t\t\t"); - _builder.append("_CacheLine*) malloc(sizeof("); - _builder.append(name, "\t\t\t"); - _builder.append("_CacheLine) * 17000);"); + _builder.append("[i];"); _builder.newLineIfNotEmpty(); _builder.append("\t\t\t"); - _builder.append("initialize_"); + _builder.append("a = "); _builder.append(name, "\t\t\t"); - _builder.append("("); - _builder.append(name, "\t\t\t"); - _builder.append(", 17000);"); + _builder.append("[i+1];"); _builder.newLineIfNotEmpty(); _builder.append("\t\t\t"); - _builder.append("initialized = true;"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("static "); - _builder.append(name, "\t\t"); - _builder.append("_CacheLine* i = "); - _builder.append(name, "\t\t"); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("static int counter = 0;"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("if(counter > 16100) {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("counter = 0;"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("i = "); + _builder.append("a = "); _builder.append(name, "\t\t\t"); - _builder.append(";"); + _builder.append("[i+2];"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append("a = "); + _builder.append(name, "\t\t\t"); + _builder.append("[i+3];"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append("a = "); + _builder.append(name, "\t\t\t"); + _builder.append("[i+4];"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append("a = "); + _builder.append(name, "\t\t\t"); + _builder.append("[i+5];"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append("a = "); + _builder.append(name, "\t\t\t"); + _builder.append("[i+6];"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append("a = "); + _builder.append(name, "\t\t\t"); + _builder.append("[i+7];"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append("a = "); + _builder.append(name, "\t\t\t"); + _builder.append("[i+8];"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append("a = "); + _builder.append(name, "\t\t\t"); + _builder.append("[i+9];"); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.append("}"); _builder.newLine(); - _builder.append("\t"); _builder.newLine(); _builder.append("\t\t"); _builder.append("int end_value = counter + numberOfBytes;"); _builder.newLine(); - _builder.append("\t"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("for(; counter < end_value; counter ++) {"); + _builder.append("for(;i<arraysize;i++){"); _builder.newLine(); _builder.append("\t\t\t"); - _builder.append("i = i->ptrCacheLine[0];"); - _builder.newLine(); + _builder.append("a = "); + _builder.append(name, "\t\t\t"); + _builder.append("[i];"); + _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.append("}"); _builder.newLine(); _builder.newLine(); + _builder.append("\t\t"); + _builder.append("(void)a;"); + _builder.newLine(); + _builder.append("\t"); _builder.append("}"); _builder.newLine(); - _builder.newLine(); + _builder.append("}"); _builder.newLine(); _builder.newLine(); _builder.append("void "); - String _writeCall = MicroRosLabelGenerator.writeCall(label.getName(), "int labelAccessStatistics"); + String _writeCall = MicroRosLabelGenerator.writeCall(name, "int labelAccessStatistics"); _builder.append(_writeCall); - _builder.append(" {"); + _builder.newLineIfNotEmpty(); + _builder.append("{"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("debug_printf(\" write "); + _builder.append(name, "\t"); + _builder.append("\\n\");"); _builder.newLineIfNotEmpty(); _builder.append("\t"); - _builder.append("static bool initialized = false;"); - _builder.newLine(); - _builder.append("\t\t\t\t"); _builder.append("int numberOfBytes = "); - _builder.append(numberOfBytes, "\t\t\t\t"); + _builder.append(numberOfBytes, "\t"); _builder.append(";"); _builder.newLineIfNotEmpty(); - _builder.append("\t\t\t\t"); - _builder.append("static "); - _builder.append(name, "\t\t\t\t"); - _builder.append("_CacheLine* "); - _builder.append(name, "\t\t\t\t"); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t\t\t"); - _builder.append("if(!initialized) {"); + _builder.append("\t"); + _builder.append("int repeat;"); _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("//init"); + _builder.append("\t"); + _builder.append("for (repeat = 0 ; repeat < labelAccessStatistics; repeat++){"); _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append(name, "\t\t\t\t\t"); - _builder.append(" = ("); - _builder.append(name, "\t\t\t\t\t"); - _builder.append("_CacheLine*) malloc(sizeof("); - _builder.append(name, "\t\t\t\t\t"); - _builder.append("_CacheLine) * 17000);"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t\t\t\t"); - _builder.append("initialize_"); - _builder.append(name, "\t\t\t\t\t"); - _builder.append("("); - _builder.append(name, "\t\t\t\t\t"); - _builder.append(", 17000);"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t\t\t\t"); - _builder.append("initialized = true;"); + _builder.append("\t\t"); + _builder.append("if(numberOfBytes < 4){"); _builder.newLine(); - _builder.append("\t\t\t\t"); + _builder.append("\t\t\t"); + _builder.append("numberOfBytes = 4;"); + _builder.newLine(); + _builder.append("\t\t"); _builder.append("}"); _builder.newLine(); - _builder.append("\t\t\t"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("static "); - _builder.append(name, "\t\t\t\t"); - _builder.append("_CacheLine* i = "); - _builder.append(name, "\t\t\t\t"); - _builder.append(";"); + _builder.append("\t\t"); + _builder.append("int arraysize = sizeof("); + _builder.append(name, "\t\t"); + _builder.append(") / 4;"); _builder.newLineIfNotEmpty(); - _builder.append("\t\t\t\t"); - _builder.append("static int counter = 0;"); + _builder.append("\t\t"); + _builder.append("int leftOverElements=arraysize%10;"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("int arraySizeWith10Multiples=arraysize-leftOverElements;"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("int i = 0;"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("for (i = 0; i < arraySizeWith10Multiples; i = i + 10) {"); _builder.newLine(); _builder.append("\t\t\t"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("if(counter > 16100) {"); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("counter = 0;"); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("i = "); - _builder.append(name, "\t\t\t\t\t"); - _builder.append(";"); + _builder.append(name, "\t\t\t"); + _builder.append("[i] = 0x800A;"); _builder.newLineIfNotEmpty(); - _builder.append("\t\t\t\t"); + _builder.append("\t\t\t"); + _builder.append(name, "\t\t\t"); + _builder.append("[i+1] = 0xAFFE;"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append(name, "\t\t\t"); + _builder.append("[i+2] = 0xAFFE;"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append(name, "\t\t\t"); + _builder.append("[i+3] = 0xAFFE;"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append(name, "\t\t\t"); + _builder.append("[i+4] = 0xAFFE;"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append(name, "\t\t\t"); + _builder.append("[i+5] = 0xAFFE;"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append(name, "\t\t\t"); + _builder.append("[i+6] = 0xAFFE;"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append(name, "\t\t\t"); + _builder.append("[i+7] = 0xAFFE;"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append(name, "\t\t\t"); + _builder.append("[i+8] = 0xAFFE;"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append(name, "\t\t\t"); + _builder.append("[i+9] = 0xAFFE;"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t"); _builder.append("}"); _builder.newLine(); - _builder.append("\t\t\t"); + _builder.append("\t\t"); + _builder.append("for(;i<arraysize;i++){"); _builder.newLine(); _builder.append("\t\t\t\t"); - _builder.append("int end_value = counter + numberOfBytes;"); + _builder.append(name, "\t\t\t\t"); + _builder.append("[i]=0xAFFE;"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t"); + _builder.append("}"); _builder.newLine(); - _builder.append("\t\t\t"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("for(; counter < end_value; counter ++) {"); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("i = i->ptrCacheLine[0];"); - _builder.newLine(); - _builder.append("\t\t\t\t"); + _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); - _builder.newLine(); _xblockexpression = _builder.toString(); } return _xblockexpression;