| /** |
| * ******************************************************************************* |
| * Copyright (c) 2019 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.SWModel |
| import org.eclipse.app4mc.amlt2systemc.m2t.module.BaseTransformer |
| import org.eclipse.app4mc.amlt2systemc.m2t.transformers.AmaltheaTransformer |
| import org.eclipse.app4mc.amlt2systemc.m2t.transformers.TranslationUnit |
| import org.eclipse.app4mc.transformation.util.OutputBuffer |
| |
| @Singleton |
| class SWModelTransformer extends BaseTransformer { |
| |
| @Inject OutputBuffer outputBuffer |
| @Inject TaskTransformer taskTransformer |
| @Inject RunnableTransformer runnableTransformer |
| @Inject ChannelTransformer channelTransformer |
| @Inject LabelTransformer labelTransformer |
| |
| protected static def getModulePath() { |
| return AmaltheaTransformer.getModulePath() + "/swModel" |
| } |
| |
| private def getModuleName() { |
| return getModulePath + "/swModel" |
| } |
| |
| private def getFunctionDef() { |
| return "init_swModel()" |
| } |
| |
| private def getLibName() { |
| return "swModel_lib" |
| } |
| |
| def create new TranslationUnit transform(SWModel swModel) { |
| |
| if (swModel === null) { |
| it.module = "UNSPECIFIED_SWMODEL" |
| it.call = it.module |
| return |
| } |
| |
| it.module = getModuleName() |
| it.call = getFunctionDef() |
| |
| // start transformation @ task level, |
| // Note: generate referenced object (e.g. runnables) when referenced (eg. in a runnable call within the call graph) |
| swModel.tasks.forEach[taskTransformer.transform(it)] |
| |
| outputBuffer.appendTo("INC", it.module, toH()) |
| outputBuffer.appendTo("SRC", it.module, toCpp()) |
| outputBuffer.appendTo("OTHER", getModulePath() + "/CMakeLists.txt", getCMake(it.module)); |
| } |
| |
| private def String toH() ''' |
| #include <systemc> |
| #include <memory> |
| #include "Common.h" |
| #include "SoftwareModel.h" |
| #include "Channel.h" |
| #include "ChannelAccess.h" |
| #include "ModeChangeItem.h" |
| #include "EventTrigger.h" |
| #include "PriorityScheduler.h" |
| //include model elements» |
| «FOR obj : taskTransformer.cache.values» |
| #include "../../«(obj as TranslationUnit).module».h" |
| «ENDFOR» |
| void «getFunctionDef()»; |
| |
| ''' |
| |
| private def String toCpp() ''' |
| #include "../../«getModuleName».h" |
| |
| /* Software */ |
| void «getFunctionDef()»{ |
| «FOR obj : taskTransformer.cache.values» |
| «(obj as TranslationUnit).call»; |
| «ENDFOR» |
| } |
| ''' |
| |
| def String getCMake(String thisModule) ''' |
| # CMakeList.txt: CMake project for "«getLibName()»". |
| # Include the source and define project specific logic here. |
| # |
| cmake_minimum_required (VERSION 3.12) |
| |
| # Add a source to the project executable |
| add_library («getLibName()» OBJECT |
| «FOR obj : channelTransformer.cache.values» |
| "../../«(obj as TranslationUnit).module».cpp" |
| «ENDFOR» |
| «FOR obj : labelTransformer.cache.values» |
| "../../«(obj as TranslationUnit).module».cpp" |
| «ENDFOR» |
| «FOR obj : runnableTransformer.cache.values» |
| "../../«(obj as TranslationUnit).module».cpp" |
| «ENDFOR» |
| |
| «FOR obj : taskTransformer.cache.values» |
| "../../«(obj as TranslationUnit).module».cpp" |
| «ENDFOR» |
| |
| "../../«thisModule».cpp" ) |
| target_link_libraries(«getLibName()» app4mc.sim_lib effolkronium_random easyloggingpp) |
| ''' |
| |
| } |