blob: 2fd777a76880a4b9a87fb233e4e67ae5a9571542 [file] [log] [blame]
/**
********************************************************************************
* Copyright (c) 2018-2021 Robert Bosch GmbH and others.
*
* 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 app4mc.example.transform.m2m.transformers
import app4mc.example.transform.samplemodel.Model
import org.eclipse.app4mc.amalthea.model.Cache
import org.eclipse.app4mc.amalthea.model.HWModel
import org.eclipse.app4mc.amalthea.model.Memory
import org.eclipse.app4mc.amalthea.model.ProcessingUnit
import org.eclipse.app4mc.amalthea.model.StructureType
import org.eclipse.app4mc.transformation.ServiceConstants
import org.eclipse.app4mc.transformation.transformers.AbstractTransformer
import org.osgi.service.component.annotations.Activate
import org.osgi.service.component.annotations.Component
import org.osgi.service.component.annotations.ConfigurationPolicy
import org.osgi.service.component.annotations.Reference
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@Component(
configurationPid = ServiceConstants.SESSION_CONFIGURATION_PID,
configurationPolicy = ConfigurationPolicy.REQUIRE,
service = #[ HWTransformer, AbstractTransformer ]
)
class HWTransformer extends AbstractTransformer {
static final Logger LOG = LoggerFactory.getLogger(typeof(HWTransformer))
@Reference MemoryTransformer memoryTransformer
@Reference CacheTransformer cacheTransformer
@Reference ProcessingUnitTransformer processingUnitTransformer
@Activate
def package void activate() {
LOG.debug("HWTransformer activated : "+this.hashCode)
}
def transfromHWModel(HWModel hwModel, Model outputModel) {
// Getting all caches
val structures = hwModel.structures
for (hwStructureTypeSystem : structures) {
if (hwStructureTypeSystem.structureType == StructureType.SYSTEM) {
val hwStructuresOfTypeECU = hwStructureTypeSystem.structures
for (hwStructureECU : hwStructuresOfTypeECU) {
if (hwStructureECU.structureType == StructureType.ECU) {
val hwStructuresOfTypeMC = hwStructureECU.structures
for (hwStructureMC : hwStructuresOfTypeMC) {
if (hwStructureMC.structureType == StructureType.MICROCONTROLLER) {
val hwModules = hwStructureMC.modules
hwModules.forEach [ hwModule |
if (hwModule instanceof Cache) {
// global cache : object creation
val outputCache = cacheTransformer.transfromCache(hwModule)
outputModel.caches.add(outputCache)
}
else if (hwModule instanceof Memory) {
val outputMemory = memoryTransformer.transfromMemory(hwModule as Memory)
outputModel.memories.add(outputMemory as app4mc.example.transform.samplemodel.Memory)
}
else if (hwModule instanceof ProcessingUnit) {
LOG.info("Transforming PU : " + hwModule)
processingUnitTransformer.transfromProcessingUnit(hwModule,outputModel)
}
]
}
}
}
}
}
}
}
}