blob: f4fa7b3fc623de7e65efb8e6ec5f472717be5004 [file] [log] [blame]
/**
********************************************************************************
* 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.hw
import com.google.inject.Inject
import com.google.inject.Singleton
import org.eclipse.app4mc.amalthea.model.HWModel
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 HwModelTransformer extends BaseTransformer {
protected static def String getModulePath() {
return AmaltheaTransformer.getModulePath() + "/hwModel"
}
protected def getModuleName() {
return getModulePath + "/hwModel"
}
private def getFunctionDef() {
return "init_hwModel()"
}
private def getLibName() {
return "hwModel_lib"
}
@Inject OutputBuffer outputBuffer
@Inject HwStructureTransformer hwStructureTransformer
@Inject FrequencyDomainTransformer frequencyDomainTransformer
@Inject ProcessingUnitDefinitionTransformer processingUnitDefinitionTransformer
@Inject ProcessingUnitTransformer processingUnitTransformer
@Inject MemoryTransformer memoryTransformer
@Inject ConnectionHandlerTransformer connectionHandlerTransformer
@Inject HwConnectionTransformer hwConnectionTransformer
@Inject HwFeatureTransformer hwFeatureTransformer
@Inject HwAccessElementTransformer hwAccessElementTransformer
def create new TranslationUnit transform(HWModel hwModel) {
if (hwModel === null) {
it.module = "UNSPECIFIED_HWMODEL"
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)
outputBuffer.appendTo("INC", it.module, toH(hwModel))
outputBuffer.appendTo("SRC", it.module, toCpp(hwModel))
val buf = getCMake(it.module);
outputBuffer.appendTo("OTHER", getModulePath() + "/CMakeLists.txt", buf);
}
private def String toH(HWModel hwModel) '''
#include <systemc>
#include <memory>
#include "Common.h"
#include "HardwareModel.h"
//include model elements
«FOR structure : hwModel.structures»
#include "../../«hwStructureTransformer.transform(structure).module».h"
«ENDFOR»
void «getFunctionDef()»;
'''
private def String toCpp(HWModel hwModel) '''
#include "../../«getModuleName».h"
/* Hardware */
void «getFunctionDef()»{
«FOR structure : hwModel.structures»
«hwStructureTransformer.transform(structure).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
#features
«FOR obj : hwFeatureTransformer.cache.values»
"../../«(obj as TranslationUnit).module».cpp"
«ENDFOR»
#definitions
«FOR obj : processingUnitDefinitionTransformer.cache.values»
"../../«(obj as TranslationUnit).module».cpp"
«ENDFOR»
#domains
«FOR obj : frequencyDomainTransformer.cache.values»
"../../«(obj as TranslationUnit).module».cpp"
«ENDFOR»
#hw structure
«FOR obj : hwStructureTransformer.cache.values»
"../../«(obj as TranslationUnit).module».cpp"
«ENDFOR»
# modules
«FOR obj : memoryTransformer.cache.values»
"../../«(obj as TranslationUnit).module».cpp"
«ENDFOR»
«FOR obj : processingUnitTransformer.cache.values»
"../../«(obj as TranslationUnit).module».cpp"
«ENDFOR»
«FOR obj : connectionHandlerTransformer.cache.values»
"../../«(obj as TranslationUnit).module».cpp"
«ENDFOR»
#connections
«FOR obj : hwConnectionTransformer.cache.values»
"../../«(obj as TranslationUnit).module».cpp"
«ENDFOR»
#HW access elements
«FOR obj : hwAccessElementTransformer.cache.values»
"../../«(obj as TranslationUnit).module».cpp"
«ENDFOR»
"../../«thisModule».cpp")
#target_include_directories(RUNNABLES_LIB
# PUBLIC
# ${CMAKE_CURRENT_LIST_DIR}/definitions/_inc
# ${CMAKE_CURRENT_LIST_DIR}/../labels/_inc
target_link_libraries(«getLibName()» app4mc.sim_lib effolkronium_random easyloggingpp systemc)
'''
}