| /** |
| * Copyright (c) 2020 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.commons.m2t.generators; |
| |
| import org.eclipse.app4mc.amalthea.model.Label; |
| import org.eclipse.app4mc.transformation.util.OutputBuffer; |
| |
| public class LabelTranslationUnit extends TranslationUnit { |
| public static String getModulePathStatic() { |
| return "synthetic_gen" + "/" + getModuleNameStatic(); |
| } |
| |
| public static String getMakeFilePathStatic() { |
| return getModulePathStatic() + "/" + "CMakeLists.txt"; |
| } |
| |
| public static String getModuleNameStatic() { |
| return "labels"; |
| } |
| |
| public static String getLibName() { |
| return "LABELS_LIB"; |
| } |
| |
| public String getModuleName() { |
| return LabelTranslationUnit.getModuleNameStatic(); |
| } |
| |
| protected String getName() { |
| return this.label.getName(); |
| } |
| |
| public String getInitCall() { return "initialize_" + getName() + "()"; } |
| |
| public String readCall(final String param) { return "read_" + getName() + "(" + param + ")"; } |
| |
| public String writeCall(final String param) { return "write_" + getName() + "(" + param + ")"; } |
| |
| public String getIncFile() { return getModuleName() + ".h"; } |
| |
| private final Label label; |
| private OutputBuffer outputBuffer; |
| |
| public LabelTranslationUnit(final OutputBuffer outputBuffer, final Label label) { |
| super(); |
| this.label = label; |
| this.outputBuffer = outputBuffer; |
| this.genFiles(); |
| } |
| |
| public void genFiles() { |
| if (isSrcFileEmpty()) { |
| srcAppend("#include \"" + getIncFile() + "\"\n\n"); |
| } |
| if (isIncFileEmpty()) { |
| incAppend("#include <stdbool.h>\n\n"); |
| } |
| |
| incAppend(LabelGenerator.toH(label)); |
| srcAppend(LabelGenerator.toCpp(label)); |
| } |
| |
| protected long getSize() { |
| return this.label.getSize().getNumberBytes(); |
| } |
| |
| public String getBasePath() { |
| return "synthetic_gen"; |
| } |
| |
| public String getModulePath() { return this.getBasePath() + "/" + this.getModuleName(); } |
| |
| @Override |
| public String getSrcFile() { return this.getModuleName() + ".cpp"; } |
| |
| public String getIncPath() { return this.getModulePath() + "/_inc/" + this.getIncFile(); } |
| |
| public String getSrcPath() { return this.getModulePath() + "/_src/" + this.getSrcFile(); } |
| |
| public boolean isIncFileEmpty() { |
| return (!this.outputBuffer.bufferExists("INC", ((this.getModulePath() + "/_inc/") + this.getModuleName()))); |
| } |
| |
| public boolean isSrcFileEmpty() { |
| return (!this.outputBuffer.bufferExists("SRC", ((this.getModulePath() + "/_src/") + this.getModuleName()))); |
| } |
| |
| public boolean incAppend(final String str) { |
| return this.outputBuffer.appendTo("INC", ((this.getModulePath() + "/_inc/") + this.getModuleName()), str); |
| } |
| |
| public boolean srcAppend(final String str) { |
| return this.outputBuffer.appendTo("SRC", ((this.getModulePath() + "/_src/") + this.getModuleName()), str); |
| } |
| |
| } |