blob: e27f385e9a9040bcb4fb4530f753b2680e2ba03f [file] [log] [blame]
/**
* *******************************************************************************
* 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
import org.eclipse.app4mc.amlt2systemc.m2t.utils.TuSort
@Singleton
class SWModelTransformer extends BaseTransformer {
@Inject OutputBuffer outputBuffer
@Inject TaskTransformer taskTransformer
@Inject RunnableTransformer runnableTransformer
@Inject ChannelTransformer channelTransformer
@Inject LabelTransformer labelTransformer
@Inject ModeLabelTransformer modeLabelTransformer
@Inject ModeTransformer modeTransformer
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(
getModuleName(),
getFunctionDef()
) transform(SWModel swModel) {
// 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() '''
void «getFunctionDef()»;
'''
private def String toCpp() '''
#include "APP4MCsim.h"
#include "«getModuleName».h"
«FOR obj : TuSort.byModule(taskTransformer.cache.values)»
#include "«(obj as TranslationUnit).module».h"
«ENDFOR»
/* Software */
void «getFunctionDef()»{
«FOR obj : TuSort.byCall(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 : TuSort.byModule(modeTransformer.cache.values)»
"${PROJECT_SOURCE_DIR}/«(obj as TranslationUnit).module».cpp"
«ENDFOR»
«FOR obj : TuSort.byModule(channelTransformer.cache.values)»«
» "${PROJECT_SOURCE_DIR}/«(obj as TranslationUnit).module».cpp"«
»«ENDFOR»
«FOR obj : TuSort.byModule(labelTransformer.cache.values)»
"${PROJECT_SOURCE_DIR}/«(obj as TranslationUnit).module».cpp"
«ENDFOR»
«FOR obj : TuSort.byModule(modeLabelTransformer.cache.values)»
"${PROJECT_SOURCE_DIR}/«(obj as TranslationUnit).module».cpp"
«ENDFOR»
«FOR obj : TuSort.byModule(runnableTransformer.cache.values)»
"${PROJECT_SOURCE_DIR}/«(obj as TranslationUnit).module».cpp"
«ENDFOR»
«FOR obj : TuSort.byModule(taskTransformer.cache.values)»
"${PROJECT_SOURCE_DIR}/«(obj as TranslationUnit).module».cpp"
«ENDFOR»
"${PROJECT_SOURCE_DIR}/«thisModule».cpp" )
target_link_libraries(«getLibName()» app4mc.sim_lib effolkronium_random easyloggingpp)
'''
}