| /** |
| * ******************************************************************************* |
| * Copyright (c) 2019-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.amlt2systemc.m2t.transformers.sw |
| |
| import com.google.inject.Inject |
| import com.google.inject.Singleton |
| import org.eclipse.app4mc.amalthea.model.Runnable |
| import org.eclipse.app4mc.amlt2systemc.m2t.transformers.TranslationUnit |
| import org.eclipse.app4mc.transformation.util.OutputBuffer |
| |
| @Singleton |
| class RunnableTransformer extends IActivityGraphItemContainerTransformer { |
| |
| @Inject OutputBuffer outputBuffer |
| var cntNull=0; |
| var cntNameMissing=0; |
| |
| def getModuleName(String runnableName) { |
| return SWModelTransformer.getModulePath() + "/runnables/" + runnableName |
| } |
| |
| def getFunctionDef(String runnableName) { |
| return "get_" + runnableName + "()" |
| |
| } |
| |
| def create new TranslationUnit transform(Runnable runnable) { |
| |
| if (runnable === null) { |
| val runnableName ="UNSPECIFIED_RUNNABLE_" + cntNameMissing |
| it.module = getModuleName(runnableName) |
| it.call = getFunctionDef(runnableName) |
| // write header file |
| outputBuffer.appendTo("INC", it.module, toH(runnableName)) |
| // write implementation file |
| outputBuffer.appendTo("SRC", it.module, toCpp(runnableName)) |
| cntNull++ |
| }else if (runnable.name === null || runnable.name.empty){ |
| val runnableName ="UNNAMED_RUNNABLE_" + cntNameMissing |
| it.module = getModuleName(runnableName) |
| it.call = getFunctionDef(runnableName) |
| transformItems(runnable.activityGraph, it) |
| // write header file |
| outputBuffer.appendTo("INC", it.module, toH(runnableName)) |
| // write implementation file |
| outputBuffer.appendTo("SRC", it.module, toCpp(runnableName)) |
| cntNameMissing++ |
| |
| }else{ |
| it.module = getModuleName(runnable.name) |
| it.call = getFunctionDef(runnable.name) |
| transformItems(runnable.activityGraph, it) |
| // write header file |
| outputBuffer.appendTo("INC", it.module, toH(runnable.name)) |
| // write implementation file |
| outputBuffer.appendTo("SRC", it.module, toCpp(runnable.name)) |
| } |
| } |
| |
| private def String toH(String runnableName) ''' |
| #include "SoftwareModel.h" |
| |
| std::shared_ptr<Runnable> «getFunctionDef(runnableName)»; |
| ''' |
| |
| private def String toCpp(String runnableName) ''' |
| #include <systemc> |
| #include "Common.h" |
| #include "GenericQueueAccess.h" |
| #include "ChannelAccess.h" |
| #include "Deviation.h" |
| #include "../../../«getModuleName(runnableName)».h" |
| |
| «FOR include : activityItemIncludes» |
| #include "../../../«include».h" |
| «ENDFOR» |
| |
| std::shared_ptr<Runnable> «runnableName» = nullptr; |
| |
| std::shared_ptr<Runnable> «getFunctionDef(runnableName)» { |
| |
| if («runnableName» == nullptr) { |
| //initialize |
| «runnableName» = std::make_shared<Runnable>("«runnableName»"); |
| «FOR call : activityItemCalls» |
| «IF !(call.startsWith("//") || call.startsWith("/*"))» |
| «runnableName»->addActivityGraphItem«call»; |
| «ELSE» |
| «call» |
| «ENDIF» |
| «ENDFOR» |
| } |
| return «runnableName»; |
| } |
| |
| ''' |
| |
| def getCache() { |
| this._createCache_transform |
| } |
| |
| } |