blob: 16c78ddb971c79acb2c03526875e0bedb8d0b21f [file] [log] [blame]
/**
* Copyright (c) 2020-2021 Robert Bosch GmbH.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Robert Bosch GmbH - initial API and implementation
*/
package org.eclipse.app4mc.slg.ros2.generators;
import org.eclipse.app4mc.amalthea.model.Label;
import org.eclipse.app4mc.slg.commons.m2t.generators.LabelTranslationUnit;
import org.eclipse.app4mc.transformation.util.OutputBuffer;
import org.eclipse.xtend2.lib.StringConcatenation;
public class RosLabelTranslationUnit extends LabelTranslationUnit {
public RosLabelTranslationUnit(final OutputBuffer outputBuffer, final Label label) {
super(outputBuffer, label);
}
public static String getModulePathStatic() {
String _basePathStatic = "synthetic_gen";
String _moduleNameStatic = RosLabelTranslationUnit.getModuleNameStatic();
return _basePathStatic + "/" + _moduleNameStatic;
}
public static String getMakeFilePathStatic() {
String _modulePathStatic = RosLabelTranslationUnit.getModulePathStatic();
String _makeFileName = "CMakeLists.txt";
return _modulePathStatic + "/" + _makeFileName;
}
public static String getModuleNameStatic() {
return "labels";
}
public static String getLibName() {
return "LABELS_LIB";
}
@Override
public String getModuleName() {
return RosLabelTranslationUnit.getModuleNameStatic();
}
@Override
public String getIncFile() {
return this.getModuleName() + ".h";
}
@Override
public void genFiles() {
if (isSrcFileEmpty()) {
srcAppend("#include \"" + getIncFile() + "\"\n\n");
srcAppend("#include <stdlib.h>\n");
}
incAppend(this.toH());
srcAppend(this.toCpp());
}
private String toH() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("typedef struct ");
String _name = this.getName();
_builder.append(_name);
_builder.append("_CacheLine");
_builder.newLineIfNotEmpty();
_builder.append("{");
_builder.newLine();
_builder.append(" ");
_builder.append("struct ");
String _name_1 = this.getName();
_builder.append(_name_1, " ");
_builder.append("_CacheLine* ptrCacheLine[8] ;");
_builder.newLineIfNotEmpty();
_builder.append("} ");
String _name_2 = this.getName();
_builder.append(_name_2);
_builder.append("_CacheLine ;");
_builder.newLineIfNotEmpty();
_builder.append("void initialize_");
String _name_3 = this.getName();
_builder.append(_name_3);
_builder.append("(");
String _name_4 = this.getName();
_builder.append(_name_4);
_builder.append("_CacheLine* array,int array_elements);");
_builder.newLineIfNotEmpty();
_builder.append("void ");
String _readCall = this.readCall("int labelAccessStatistics");
_builder.append(_readCall);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("void ");
String _writeCall = this.writeCall("int labelAccessStatistics");
_builder.append(_writeCall);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
return _builder.toString();
}
private String toCpp() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("void initialize_");
String _name = this.getName();
_builder.append(_name);
_builder.append("(");
String _name_1 = this.getName();
_builder.append(_name_1);
_builder.append("_CacheLine* array,int array_elements) {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("int steps = array_elements / 2 ;");
_builder.newLine();
_builder.append(" ");
_builder.append("int bottom = 0 ;");
_builder.newLine();
_builder.append(" ");
_builder.append("int top = steps ;");
_builder.newLine();
_builder.append(" ");
_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 = this.readCall("int labelAccessStatistics");
_builder.append(_readCall);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("static bool initialized = false;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("int numberOfBytes = ");
long _size = this.getSize();
_builder.append(_size, "\t\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("static ");
String _name_2 = this.getName();
_builder.append(_name_2, "\t\t");
_builder.append("_CacheLine* ");
String _name_3 = this.getName();
_builder.append(_name_3, "\t\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("if(!initialized) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("//init");
_builder.newLine();
_builder.append("\t\t\t");
String _name_4 = this.getName();
_builder.append(_name_4, "\t\t\t");
_builder.append(" = (");
String _name_5 = this.getName();
_builder.append(_name_5, "\t\t\t");
_builder.append("_CacheLine*) malloc(sizeof(");
String _name_6 = this.getName();
_builder.append(_name_6, "\t\t\t");
_builder.append("_CacheLine) * 17000);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("initialize_");
String _name_7 = this.getName();
_builder.append(_name_7, "\t\t\t");
_builder.append("(");
String _name_8 = this.getName();
_builder.append(_name_8, "\t\t\t");
_builder.append(", 17000);");
_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 ");
String _name_9 = this.getName();
_builder.append(_name_9, "\t\t");
_builder.append("_CacheLine* i = ");
String _name_10 = this.getName();
_builder.append(_name_10, "\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 = ");
String _name_11 = this.getName();
_builder.append(_name_11, "\t\t\t");
_builder.append(";");
_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.newLine();
_builder.append("\t\t\t");
_builder.append("i = i->ptrCacheLine[0];");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.newLine();
_builder.newLine();
_builder.append("void ");
String _writeCall = this.writeCall("int labelAccessStatistics");
_builder.append(_writeCall);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("static bool initialized = false;");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("int numberOfBytes = ");
long _size_1 = this.getSize();
_builder.append(_size_1, "\t\t\t\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t");
_builder.append("static ");
String _name_12 = this.getName();
_builder.append(_name_12, "\t\t\t\t");
_builder.append("_CacheLine* ");
String _name_13 = this.getName();
_builder.append(_name_13, "\t\t\t\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t");
_builder.append("if(!initialized) {");
_builder.newLine();
_builder.append("\t\t\t\t\t");
_builder.append("//init");
_builder.newLine();
_builder.append("\t\t\t\t\t");
String _name_14 = this.getName();
_builder.append(_name_14, "\t\t\t\t\t");
_builder.append(" = (");
String _name_15 = this.getName();
_builder.append(_name_15, "\t\t\t\t\t");
_builder.append("_CacheLine*) malloc(sizeof(");
String _name_16 = this.getName();
_builder.append(_name_16, "\t\t\t\t\t");
_builder.append("_CacheLine) * 17000);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t\t");
_builder.append("initialize_");
String _name_17 = this.getName();
_builder.append(_name_17, "\t\t\t\t\t");
_builder.append("(");
String _name_18 = this.getName();
_builder.append(_name_18, "\t\t\t\t\t");
_builder.append(", 17000);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t\t");
_builder.append("initialized = true;");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t\t");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("static ");
String _name_19 = this.getName();
_builder.append(_name_19, "\t\t\t\t");
_builder.append("_CacheLine* i = ");
String _name_20 = this.getName();
_builder.append(_name_20, "\t\t\t\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t");
_builder.append("static int counter = 0;");
_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 = ");
String _name_21 = this.getName();
_builder.append(_name_21, "\t\t\t\t\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t\t");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("int end_value = counter + numberOfBytes;");
_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("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
return _builder.toString();
}
}