| /** |
| ******************************************************************************** |
| * 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.commons.m2t.generators |
| |
| import java.util.List |
| import org.eclipse.app4mc.amalthea.model.Label |
| import org.eclipse.app4mc.slg.commons.m2t.AmaltheaModelUtils |
| |
| class LabelGenerator { |
| |
| // Suppress default constructor |
| private new() { |
| throw new IllegalStateException("Utility class"); |
| } |
| |
| static def String toCMake(List<String> srcFiles) |
| ''' |
| # «LabelTranslationUnit.libName» ################################################################ |
| #### |
| add_library(«LabelTranslationUnit.libName» STATIC |
| «FOR srcFile : srcFiles» |
| ${CMAKE_CURRENT_LIST_DIR}/_src/«srcFile» |
| «ENDFOR» |
| ) |
| |
| target_include_directories(«LabelTranslationUnit.getLibName()» |
| PUBLIC ${CMAKE_CURRENT_LIST_DIR}/_inc |
| ) |
| ''' |
| |
| static def String toH(Label label) |
| ''' |
| void «initCall(label.name)»; |
| void «readCall(label.name, "int labelAccessStatistics")»; |
| void «writeCall(label.name, "int labelAccessStatistics")»; |
| |
| ''' |
| |
| static def String toCpp(Label label) |
| ''' |
| int «label.name»[«AmaltheaModelUtils.getLabelArraySize(label)»]; |
| |
| static bool isIinitialized_«label.name» = false; |
| void «initCall(label.name)» { |
| if (!isIinitialized_«label.name»){ |
| for (int i=0; i < «AmaltheaModelUtils.getLabelArraySize(label)»; i++){ |
| «label.name»[i] = i+1; |
| } |
| isIinitialized_«label.name» = true; |
| } |
| } |
| |
| |
| void «readCall(label.name, "int labelAccessStatistics")» { |
| int numberOfBytes = «label?.size?.numberBytes»; |
| |
| for (int repeat = 0 ; repeat < labelAccessStatistics; repeat++){ |
| if(numberOfBytes < 4){ |
| numberOfBytes = 4; |
| } |
| int arraysize = sizeof(«label.name») / 4; |
| |
| //printf("number of bytes:%d\n",arraysize); |
| int leftOverElements=arraysize%10; |
| |
| int arraySizeWith10Multiples=arraysize-leftOverElements; |
| int i = 0; |
| int a = 0; |
| for (i = 0; i < arraySizeWith10Multiples; i = i + 10) { //iteration with 10 reads |
| a = «label.name»[i]; |
| a = «label.name»[i+1]; |
| a = «label.name»[i+2]; |
| a = «label.name»[i+3]; |
| a = «label.name»[i+4]; |
| a = «label.name»[i+5]; |
| a = «label.name»[i+6]; |
| a = «label.name»[i+7]; |
| a = «label.name»[i+8]; |
| a = «label.name»[i+9]; |
| } |
| for(;i<arraysize;i++){ |
| a = «label.name»[i]; |
| } |
| } |
| } |
| |
| void «writeCall(label.name, "int labelAccessStatistics")» { |
| int numberOfBytes = «label?.size?.numberBytes»; |
| for (int repeat = 0 ; repeat < labelAccessStatistics; repeat++){ |
| if(numberOfBytes < 4){ |
| numberOfBytes = 4; |
| } |
| int arraysize = sizeof(«label.name») / 4; |
| int leftOverElements=arraysize%10; |
| int arraySizeWith10Multiples=arraysize-leftOverElements; |
| |
| int i = 0; |
| for (i = 0; i < arraySizeWith10Multiples; i = i + 10) { |
| «label.name»[i] = 0xAFFE; |
| «label.name»[i+1] = 0xAFFE; |
| «label.name»[i+2] = 0xAFFE; |
| «label.name»[i+3] = 0xAFFE; |
| «label.name»[i+4] = 0xAFFE; |
| «label.name»[i+5] = 0xAFFE; |
| «label.name»[i+6] = 0xAFFE; |
| «label.name»[i+7] = 0xAFFE; |
| «label.name»[i+8] = 0xAFFE; |
| «label.name»[i+9] = 0xAFFE; |
| } |
| for(;i<arraysize;i++){ |
| «label.name»[i]=0xAFFE; |
| } |
| } |
| } |
| |
| ''' |
| |
| static def String initCall(String name) '''initialize_«name»()''' |
| |
| static def String readCall(String name, String param) '''read_«name»(«param»)''' |
| |
| static def String writeCall(String name, String param) '''write_«name»(«param»)''' |
| |
| } |