| /** |
| ******************************************************************************** |
| * Copyright (c) 2020-2021 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.slg.linux.generators; |
| |
| import static org.eclipse.app4mc.amalthea.model.LabelAccessEnum._UNDEFINED_; |
| |
| import org.eclipse.app4mc.amalthea.model.LabelAccess; |
| import org.eclipse.app4mc.amalthea.model.MinAvgMaxStatistic; |
| import org.eclipse.app4mc.amalthea.model.NumericStatistic; |
| import org.eclipse.app4mc.amalthea.model.SingleValueStatistic; |
| import org.eclipse.app4mc.transformation.util.OutputBuffer; |
| |
| public class LinuxLabelAccessTranslationUnit extends LinuxBaseTranslationUnit { |
| |
| private final LinuxLabelTranslationUnit tuLabel; |
| private final LabelAccess labelAccess; |
| |
| public LinuxLabelAccessTranslationUnit( |
| final OutputBuffer outputBuffer, |
| final LinuxLabelTranslationUnit tuLabel, |
| final LabelAccess labelAccess) { |
| super(outputBuffer); |
| this.tuLabel = tuLabel; |
| this.labelAccess = labelAccess; |
| } |
| |
| // translation unit specific settings |
| |
| @Override |
| public String getBasePath() { return this.tuLabel.getBasePath(); } |
| |
| @Override |
| public String getModuleName() { return this.tuLabel.getModuleName(); } |
| |
| @Override |
| public String getIncFile() { return this.tuLabel.getIncFile(); } |
| |
| // ---------- names of generated 'C' functions ---------- |
| |
| @Override |
| public String getCall() { |
| if (labelAccess == null || tuLabel == null) return null; |
| |
| if (labelAccess.getAccess() == _UNDEFINED_) { |
| if (labelAccess.getData() == null) { |
| return "/* unspecified label access */"; |
| } else { |
| return ("/*underspecified access to label" + this.labelAccess.getData().getName()) + "*/"; |
| } |
| } |
| |
| final NumericStatistic stat = statisticValueOrNull(labelAccess); |
| final String statString = (stat == null) ? "1" : getNumericStatistic(stat); |
| |
| |
| switch (labelAccess.getAccess()) { |
| case READ: |
| return tuLabel.readCall(statString); |
| case WRITE: |
| return tuLabel.writeCall(statString); |
| default: |
| return null; |
| } |
| } |
| |
| // -------------------------------------------------- |
| |
| private NumericStatistic statisticValueOrNull(final LabelAccess access) { |
| if (access == null || access.getStatistic() == null) return null; |
| |
| return access.getStatistic().getValue(); |
| } |
| |
| private String getNumericStatistic(final NumericStatistic statistic) { |
| if (statistic instanceof MinAvgMaxStatistic) { |
| String valueString = String.format("%d", Math.ceil(((MinAvgMaxStatistic) statistic).getAvg())); |
| return (valueString + " /*MinAvgMaxStatistic not supported yet*/"); |
| } else if (statistic instanceof SingleValueStatistic) { |
| return String.format("%d", Math.ceil(((SingleValueStatistic) statistic).getValue())); |
| } |
| return null; |
| } |
| |
| } |