📄 marte2cheddar.atl
字号:
-- Thales MARTE to Cheddar (Copyright (c) THALES 2007 All rights reserved) is free software; you can redistribute itand/or modify-- it under the terms of the Eclipse Public License as published in http://www.eclipse.org/legal/epl-v10.html---- Thales MARTE to Cheddar is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Eclipse Public License for more details.---------------------------------------------------- Nicolas VIENNE-- Eric MAES---------------------------------------------------- Transforms a well formed MARTE model to Cheddar metamodel for scheduling analysis--------------------------------------------------module MARTE2cheddar;create OUT:CHEDDAR from IN:UML, parameters:XML;------ Libraries----uses MARTE;uses UML2;uses MARTE4CHEDDAR;uses XMLPARAMETERS;------ Check if the element is the element targeted by parameters----helper context UML!Element def : isTarget() : Boolean = if thisModule.hasParameter('targetElement') then if self.oclIsKindOf(UML!NamedElement) then if thisModule.getParameter('targetElement') = self.getQualifiedName() then true else false endif else true endif else true endif;------ Rules----lazy rule scheduler { from e:UML!Element (e.marteIsTypeOf(e.Scheduler())) to scheduler : CHEDDAR!scheduler do { if( not e.oclIsUndefined() ) { -- Scheduler defini ... -- Scheduling Policy scheduler.policy <- let sp : String = e.marteGetAttributeValue(e.Scheduler(), e.Scheduler_schedPolicy()).toString() in if sp='IN!'+e.SchedPolicyKind_EarliestDeadlineFirst() then #EARLIEST_DEADLINE_FIRST_PROTOCOL else if sp='IN!'+e.SchedPolicyKind_LeastLaxityFirst() then #LEAST_LAXITY_FIRST_PROTOCOL else if sp='IN!'+e.SchedPolicyKind_FixedPriority() then #POSIX_1003_HIGHEST_PRIORITY_FIRST_PROTOCOL else if sp='IN!'+e.SchedPolicyKind_RoundRobin() then #ROUND_ROBIN_PROTOCOL else if sp='IN!'+e.SchedPolicyKind_Other() then if e.marteHasAttributeValue(e.Scheduler(), e.Scheduler_otherSchedPolicy()) then let sp2 : String = e.marteGetAttributeValue(e.Scheduler(), e.Scheduler_otherSchedPolicy()) in if sp2 = 'RATE_MONOTONIC_PROTOCOL' then #RATE_MONOTONIC_PROTOCOL else if sp2 = 'DEADLINE_MONOTONIC_PROTOCOL' then #DEADLINE_MONOTONIC_PROTOCOL else if sp2 = 'TIME_SHARING_BASED_ON_WAIT_TIME_PROTOCOL' then #TIME_SHARING_BASED_ON_WAIT_TIME_PROTOCOL else if sp2 = 'MAXIMUM_URGENCY_FIRST_BASED_ON_LAXITY_PROTOCOL' then #MAXIMUM_URGENCY_FIRST_BASED_ON_LAXITY_PROTOCOL else if sp2 = 'MAXIMUM_URGENCY_FIRST_BASED_ON_DEADLINE_PROTOCOL' then #MAXIMUM_URGENCY_FIRST_BASED_ON_DEADLINE_PROTOCOL else if sp2 = 'D_OVER_PROTOCOL' then #D_OVER_PROTOCOL else if sp2 = 'TIME_SHARING_BASED_ON_CPU_USAGE_PROTOCOL' then #TIME_SHARING_BASED_ON_CPU_USAGE_PROTOCOL else #NO_SCHEDULING_PROTOCOL -- policy=Other and otherSched invalid endif endif endif endif endif endif endif else #NO_SCHEDULING_PROTOCOL -- policy=Other and otherSched undef endif else if sp='IN!'+e.SchedPolicyKind_Undef() then #PIPELINE_USER_DEFINED_PROTOCOL else #NO_SCHEDULING_PROTOCOL -- Should never happen endif endif endif endif endif endif; if (scheduler.policy.toString() = 'NO_SCHEDULING_PROTOCOL') { e.errorMessage(e.name + ' -> ' + 'Scheduler::schedPolicy and/or Scheduler::otherSchedPolicy seems to be invalid'); } -- quantum if (not e.getDefaultValueAttributeByName('cheddar_quantum').oclIsUndefined()) { scheduler.quantum <- e.getDefaultValueAttributeByName('cheddar_quantum'); } -- Preemptibility if(e.marteHasAttributeValue(e.Scheduler(), e.Scheduler_isPreemptible())) { if(e.marteGetAttributeValue(e.Scheduler(), e.Scheduler_isPreemptible()) = 'true') { scheduler.is_preemptive <- #PREEMPTIVE; } else if(e.marteGetAttributeValue(e.Scheduler(), e.Scheduler_isPreemptible()) = 'false') { scheduler.is_preemptive <- #NOT_PREEMPTIVE; } else { e.errorMessage(e.name + ' -> ' + 'Scheduler::isPreemtible invalid'); } } else { e.warningMessage(e.name + ' -> ' + 'Scheduler::isPreemtible undefined'); } -- parametric_filename if (e.marteGetAttributeValue(e.Scheduler(), e.Scheduler_schedPolicy()).toString() = 'IN!'+e.SchedPolicyKind_Undef()) { if( e.marteHasAttributeValue(e.Scheduler(), e.Scheduler_otherSchedPolicy())) { scheduler.parametric_filename <- e.marteGetAttributeValue(e.Scheduler(), e.Scheduler_otherSchedPolicy()).toString(); } else { e.errorMessage('otherSchedPolicy (parametric_filename) undefined with scheduling policy Undef'); } } } else { -- Scheduler undef, using default e.warningMessage('Scheduler is missing, using default'); scheduler.policy <- #NO_SCHEDULING_PROTOCOL; } }}rule processor(root : CHEDDAR!Root, e:UML!Element) { to nw : CHEDDAR!network ( value <- 'No network' ), proc: CHEDDAR!processor ( name <- e.getQName(), network_link <- nw ) do { e.verboseMessage('processor ' + e.getQName()); proc.scheduler <- thisModule.scheduler(e.getStereotypeAttributeValue(if e.marteIsTypeOf(e.SaExecHost()) then e.SaExecHost() else e.GaExecHost() endif,e.ProcessingResource_mainScheduler())); root.processor <- root.processor->append(proc); }}rule address_space (root : CHEDDAR!Root, e:UML!Element) { to as: CHEDDAR!address_space ( -- name name <- e.getQName(), -- text memory size text_memory_size <- e.getStorageResourceElementSize(e.MemoryPartition(), e.MemoryPartition_concurrentResources(),'text_memory_size'), -- heap memory size heap_memory_size <- e.getStorageResourceElementSize(e.MemoryPartition(), e.MemoryPartition_concurrentResources(),'heap_memory_size'), -- stack memory size stack_memory_size <- e.getStorageResourceElementSize(e.MemoryPartition(), e.MemoryPartition_concurrentResources(),'stack_memory_size'), -- data memory size data_memory_size <- e.getStorageResourceElementSize(e.MemoryPartition(), e.MemoryPartition_concurrentResources(),'data_memory_size'), -- cpu_name cpu_name <- let proc : UML!Element = e.getFirstStereotypedTypeOfStereotypeAttribute_Seq( e.MemoryPartition(), e.MemoryPartition_concurrentResources(), Sequence {e.GaExecHost(), e.SaExecHost()}) in if not proc.oclIsUndefined() then CHEDDAR!processor.allInstances()->select(elem | elem.name = proc.getQName())->first() else OclUndefined endif, -- scheduler scheduler <- let sched : UML!Element = e.getFirstStereotypedTypeOfStereotypeAttribute( e.MemoryPartition(), e.MemoryPartition_concurrentResources(), e.Scheduler()) in if not sched.oclIsUndefined() then thisModule.scheduler(sched) else OclUndefined endif ) do { e.verboseMessage('adress_space '+e.getQName()); if(as.cpu_name.oclIsUndefined()) { e.errorMessage('cpu_name undefined !'); } if(as.scheduler.oclIsUndefined()) { e.errorMessage('scheduler undefined !'); } root.address_space <- root.address_space->append(as); }}rule task (root : CHEDDAR!Root, e:UML!Element) { to t: CHEDDAR!task ( name <- e.getQName(), x <- 0, y <- 0, -- -- /!\ -- -- Need VSL functions to parse fields -- see do{} section for solution ... task_type <- OclUndefined, jitter <- OclUndefined, period <- OclUndefined, parameters <- Sequence {}, -- + <<SchedulableResource>> ... -- -- /!\ -- -- Missing inheritance link -- <<SwSchedulableResource>> does not inherit from <<SchedulableResource>> -- see do{} section for solution ... cpu_name <- OclUndefined, policy <- OclUndefined, -- address_space is matched by name address_space_name <- let as : UML!Element = e.getFirstStereotypedTypeOfStereotypeAttribute(e.SwSchedulableResource(), e.SwConcurrentResource_addressSpace(), e.MemoryPartition()) in if not as.oclIsUndefined() then CHEDDAR!address_space.allInstances()->select(i | i.name = as.getQName()).first() else OclUndefined endif, -- capacity capacity <- if e.marteHasAttributeValue(e.SwSchedulableResource(), e.SwConcurrentResource_activationCapacity()) then e.marteGetAttributeValue(e.SwSchedulableResource(), e.SwConcurrentResource_activationCapacity()).toInteger() else 0 endif, -- deadline deadline <- e.getIntSADVBN(e.SwSchedulableResource(), e.SwSchedulableResource_deadlineElements(),'deadline'), -- criticality criticality <- e.getIntSADVBN(e.SwSchedulableResource(), e.SwSchedulableResource_deadlineElements(),'criticality'), -- priority priority <- e.getIntSADVBN(e.SwSchedulableResource(), e.SwConcurrentResource_priorityElements(), 'priority'), -- start time start_time <- e.getIntSADVBN(e.SwSchedulableResource(), e.SwConcurrentResource_periodElements(), 'start_time'), -- blocking time blocking_time <- e.getIntSADVBN(e.SwSchedulableResource(), e.SwConcurrentResource_periodElements(), 'blocking_time'), -- activation rule activation_rule <- e.getStrSADVBN(e.SwSchedulableResource(), e.SwResource_stateElements(), 'activation_rule'), -- seed seed <- e.getStrSADVBN(e.SwSchedulableResource(), e.SwResource_stateElements(), 'seed'), -- predictable seed predictable_seed <- e.getBoolSADVBN(e.SwSchedulableResource(), e.SwResource_stateElements(), 'predictable_seed'), -- text memory size text_memory_size <- e.getStorageResourceElementSize(e.SwSchedulableResource(), e.SwResource_stateElements(), 'text_memory_size'), -- stack memory size stack_memory_size <- e.getStorageResourceElementSize(e.SwSchedulableResource(), e.SwResource_stateElements(), 'stack_memory_size'), -- offsets offsets <- Sequence {} -- Mapping to precise ) do { e.verboseMessage('task '+e.getQName()); -- task type -- -- /!\ -- -- WARNING : VSL Workaround t.task_type <- if e.marteHasAttributeValue(e.SwSchedulableResource(), e.SwConcurrentResource_type()) then let ty : String = e.marteGetAttributeValue(e.SwSchedulableResource(), e.SwConcurrentResource_type()) in if ty = 'PERIODIC_TYPE' then #PERIODIC_TYPE else if ty = 'APERIODIC_TYPE' then #APERIODIC_TYPE else if ty = 'SPORADIC_TYPE' then #SPORADIC_TYPE else if ty = 'POISSON_TYPE' then #POISSON_TYPE else if ty = 'PARAMETRIC_TYPE' then #PARAMETRIC_TYPE else OclUndefined -- default value ... endif endif endif endif endif else OclUndefined endif; -- default value ... -- period t.period <- e.getIntSADVBN(e.SwSchedulableResource(), e.SwConcurrentResource_periodElements(), 'period'); -- jitter t.jitter <- e.getIntSADVBN(e.SwSchedulableResource(), e.SwConcurrentResource_periodElements(), 'jitter'); -- cpu name -- -- /!\ -- -- WARNING : <<SchedulableResourceInheritance>> Workaround if(e.hasStereotypeKindOf(e.SchedulableResource())) { if(e.hasStereotypeAttributeValue(e.SchedulableResource(), e.SchedulableResource_host())) { -- CPU_NAME t.cpu_name <- let exechost : UML!Element = let scheduler : UML!Element = e.getStereotypeAttributeValue(e.SchedulableResource(), e.SchedulableResource_host()) in if not scheduler.oclIsUndefined() then if scheduler.hasStereotypeKindOf(e.Scheduler()) then scheduler.getStereotypeAttributeValue(e.Scheduler(), e.Scheduler_host()) else OclUndefined endif else OclUndefined endif in if not exechost.oclIsUndefined() then CHEDDAR!processor.allInstances()->select(a | a.name=exechost.getQName())->first() else OclUndefined endif; if(t.cpu_name.oclIsUndefined()) { e.errorMessage('cpu_name is undefined'); } -- policy t.policy <- let scheduler : UML!Element = e.getStereotypeAttributeValue(e.SchedulableResource(), e.SchedulableResource_host()) in if not scheduler.oclIsUndefined() then let sp : String = scheduler.marteGetAttributeValue(e.Scheduler(), e.Scheduler_schedPolicy()).toString() in if sp='IN!'+e.SchedPolicyKind_EarliestDeadlineFirst() then #SCHED_FIFO else if sp='IN!'+e.SchedPolicyKind_FixedPriority() then #SCHED_FIFO else if sp='IN!'+e.SchedPolicyKind_RoundRobin() then #SCHED_RR
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -