📄 marte2cheddar.atl
字号:
else #SCHED_OTHERS endif endif endif else OclUndefined endif; } } else { e.errorMessage('<<SchedulableResource>> is not applied, workaround won\'t work'); } root.task <- root.task->append(t); }}rule resource_user (root : CHEDDAR!resource, link:UML!Dependency) { to ru : CHEDDAR!resource_user ( -- task name task_name <- CHEDDAR!task.allInstances()->select(t | t.name = link.getClients().first().getQName())->first(), -- start time start_time <- let mc : UML!Constraint = UML!Constraint.allInstances()->select(c | c.getConstrainedElements()->exists(ce | ce=link))->first() in if not mc.oclIsUndefined() then mc.getSpecification().value() else OclUndefined endif, -- TODO improve this because value is specific to opaque expressions -- end time end_time <- if link.marteHasVSLInteger(link.ResourceUsage(), link.ResourceUsage_execTime(),Sequence{'value'}) and ru.start_time <> 0 then link.marteGetVSLInteger(link.ResourceUsage(), link.ResourceUsage_execTime(),Sequence{'value'}) + ru.start_time - 1 else 0 endif ) do { link.verboseMessage('resource_user ' +ru.task_name.name); root.resource_used_by <- root.resource_used_by->append(ru); }}rule resource (root : CHEDDAR!Root, e:UML!Element) { to r: CHEDDAR!resource ( -- name name <- e.getQName(), -- protocol protocol <- let cap: String = e.getStereotypeAttributeValue(e.SwMutualExclusionResource(),e.SwMutualExclusionResource_concurrentAccessProtocol()).toString() in if cap = 'IN!'+e.ConcurrentAccessProtocolKind_PIP() then #PIP else if cap = 'IN!'+e.ConcurrentAccessProtocolKind_PCP() then #PCP else if cap = 'IN!'+e.ConcurrentAccessProtocolKind_NoPreemption() then #NO_PROTOCOL else if cap = 'IN!'+e.ConcurrentAccessProtocolKind_Other() then if not e.getOwnedAttributes()->select(e|e.name='cheddar_IPCP').first().oclIsUndefined() then #IPCP else #NO_PROTOCOL endif else #NO_PROTOCOL endif endif endif endif, -- state state <- let m : String = e.getStereotypeAttributeValue(e.SwMutualExclusionResource(),e.SwMutualExclusionResource_mechanism()).toString() in if m = 'IN!'+ e.MutualExclusionResourceKind_BooleanSemaphore() then 0 else if m = 'IN!'+ e.MutualExclusionResourceKind_Mutex() then 1 else if m = 'IN!'+ e.MutualExclusionResourceKind_CountSemaphore() then e.getIntSADVBN(e.SwMutualExclusionResource(), e.SwResource_stateElements(), 'cheddar_state') else 0 endif endif endif, -- address space name address_space_name <- let mas : UML!Element = CHEDDAR!address_space.allInstances() ->select(as | e.getSuppliersKindOf(e.MemoryPartition())->exists(a | a.getQName() = as.name))->first() in if not mas.oclIsUndefined() then mas else OclUndefined endif, -- cpu name cpu_name <- if not r.address_space_name.oclIsUndefined() then r.address_space_name.cpu_name else OclUndefined endif, -- resource used by resource_used_by <- Sequence {} ) do { e.verboseMessage('resource ' + e.getQName()); for(d in e.getSupplyingDependencies()->select(dep | dep.marteIsKindOf(e.ResourceUsage()))) { if(CHEDDAR!task.allInstances()->exists(t | t.name=d.getClients().first().getQName())) { thisModule.resource_user(r,d); } } root.resource <- root.resource->append(r); }}rule buffer_user (root : CHEDDAR!buffer, link:UML!Dependency) { to bu : CHEDDAR!buffer_user ( -- task name task_name <- CHEDDAR!task.allInstances()->select(t | t.name = link.getClients().first().getQName())->first(), -- time time <- let mc : UML!Constraint = UML!Constraint.allInstances()->select(c | c.getConstrainedElements()->exists(ce | ce=link))->first() in if not mc.oclIsUndefined() then mc.getSpecification().value() else OclUndefined endif, -- TODO improve this because value is specific to opaque expressions -- size size <- if link.marteHasVSLInteger(link.ResourceUsage(),link.ResourceUsage_msgSize(),Sequence{'value'}) then link.marteGetVSLInteger(link.ResourceUsage(),link.ResourceUsage_msgSize(),Sequence{'value'}) else 0 endif, -- buffer role buffer_role <- if bu.size > 0 then #producer else #consumer endif, -- size size <- if bu.size < 0 then 0-bu.size else bu.size endif ) do { link.verboseMessage('buffer_user ' +bu.task_name.name); root.buffer_used_by <- root.buffer_used_by->append(bu); }}rule buffer (root : CHEDDAR!Root,e:UML!Element ) { to b: CHEDDAR!buffer ( -- name name <- e.getQName(), -- x x <- 0, -- y y <- 0, -- qs qs <- let s: String = e.getDefaultValueAttributeByName('cheddar_qs') in if s = 'QS_PP1' then #QS_PP1 else if s = 'QS_MM1' then #QS_MM1 else if s = 'QS_MD1' then #QS_MD1 else if s = 'QS_MP1' then #QS_MP1 else if s = 'QS_MG1' then #QS_MG1 else if s = 'QS_MMS' then #QS_MMS else if s = 'QS_MDS' then #QS_MDS else if s = 'QS_MPS' then #QS_MPS else if s = 'QS_MGS' then #QS_MGS else if s = 'QS_MM1N' then #QS_MM1N else if s = 'QS_MD1N' then #QS_MD1N else if s = 'QS_MP1N' then #QS_MP1N else if s = 'QS_MG1N' then #QS_MG1N else if s = 'QS_MMSN' then #QS_MMSN else if s = 'QS_MDSN' then #QS_MDSN else if s = 'QS_MPSN' then #QS_MPSN else if s = 'QS_MGSN' then #QS_MGSN else OclUndefined endif endif endif endif endif endif endif endif endif endif endif endif endif endif endif endif endif, -- size size <- if e.marteHasAttributeValue(e.StorageResource(), e.StorageResource_elementSize()) then e.marteGetAttributeValue(e.StorageResource(), e.StorageResource_elementSize()).toInteger() else 0 endif, -- address space name address_space_name <- let mas : UML!Element = CHEDDAR!address_space.allInstances() ->select(as | e.getSuppliersKindOf(e.MemoryPartition())->exists(a | a.getQName() = as.name))->first() in if not mas.oclIsUndefined() then mas else OclUndefined endif, -- cpu name cpu_name <- if not b.address_space_name.oclIsUndefined() then b.address_space_name.cpu_name else OclUndefined endif, -- buffer used by buffer_used_by <- Sequence {} ) do { e.verboseMessage('buffer ' + e.getQName()); for(d in e.getSupplyingDependencies()->select(dep | dep.marteIsTypeOf(e.ResourceUsage()) and CHEDDAR!task.allInstances()->exists(t | t.name=dep.getClients().first().getQName()) )) { thisModule.buffer_user(b,d); } root.buffer <- root.buffer->append(b); }}rule message (root : CHEDDAR!Root, e:UML!Element) { to t: CHEDDAR!message ( -- name name <- e.getQName(), -- x x <- 0, -- y y <- 0, -- jitter jitter <- e.getDefaultValueAttributeByName('cheddar_jitter'), -- deadline deadline <- if e.marteHasVSLInteger(e.SaCommStep(),e.SaCommStep_deadline(),Sequence{'value'}) then e.marteGetVSLInteger(e.SaCommStep(), e.SaCommStep_deadline(),Sequence{'value'}) else 0 endif, -- period period <- if e.marteHasVSLInteger(e.SaCommStep(), e.GaScenario_interOccT(),Sequence{'value'}) then e.marteGetVSLInteger(e.SaCommStep(), e.GaScenario_interOccT(),Sequence{'value'}) else 0 endif, -- response time response_time <- if e.marteHasVSLInteger(e.SaCommStep(), e.GaScenario_respT(),Sequence{'value'}) then e.marteGetVSLInteger(e.SaCommStep(), e.GaScenario_respT(),Sequence{'value'}) else 0 endif, -- size size <- if e.marteHasVSLInteger(e.SaCommStep(),e.GaCommStep_msgSize(),Sequence{'value'}) then e.marteGetVSLInteger(e.SaCommStep(),e.GaCommStep_msgSize(),Sequence{'value'}) else 0 endif, -- communication time communication_time <- if e.marteHasVSLInteger(e.SaCommStep(),e.ResourceUsage_execTime(),Sequence{'value'}) then e.marteGetVSLInteger(e.SaCommStep(),e.ResourceUsage_execTime(),Sequence{'value'}) else 0 endif ) do { e.verboseMessage('message '+e.getQName()); root.message <- root.message->append(t); }}rule event_analyzer (root : CHEDDAR!Root, e : String) { to t: CHEDDAR!event_analyzer ( -- parametric filename parametric_filename <- e ) do { e.verboseMessage('event_analyzer '+e); root.event_analyzer <- root.event_analyzer->append(t); }}rule dependency (root : CHEDDAR!Root, e: UML!dependency) { to t: CHEDDAR!dependency ( -- to to <- let elem:UML!Element = CHEDDAR!DependencyElement.allInstances() ->select(a | a.name = e.getClients()->first().getQName())->first() in if not elem.oclIsUndefined() then elem else OclUndefined endif, -- from from <- let elem:UML!Element = CHEDDAR!DependencyElement.allInstances() ->select(a | a.name = e.getSuppliers()->first().getQName())->first() in if not elem.oclIsUndefined() then elem else OclUndefined endif, -- from type from_type <- let f : CHEDDAR!DependencyElement = t.from in if not f.oclIsUndefined() then if f.oclType() = CHEDDAR!task then #task else if f.oclType() = CHEDDAR!buffer then #buffer else #message endif endif else OclUndefined endif, -- to type to_type <- let f : CHEDDAR!DependencyElement = t.to in if not f.oclIsUndefined() then if f.oclType() = CHEDDAR!task then #task else if f.oclType() = CHEDDAR!buffer then #buffer else #message endif endif else OclUndefined endif ) do { e.verboseMessage('dependency '+t.from.name + ' -> ' + t.to.name); root.dependency <- root.dependency->append(t); }}------ Root rule----rule AnalysisContext { from e:UML!NamedElement ((e.marteIsTypeOf(e.GaAnalysisContext()) or e.marteIsTypeOf(e.SaAnalysisContext())) and e.isTarget()) to root : CHEDDAR!Root do { e.verboseMessage('MARTE 2 Cheddar transformation for '+e.getName()); -- processors for( elem in e.getStereoElemsKindOfStereoAttrib(if e.marteIsTypeOf(e.GaAnalysisContext()) then e.GaAnalysisContext() else e.SaAnalysisContext() endif, e.GaAnalysisContext_platform(), e.GaResourcesPlatform())) { for(elem2 in elem.getStereoElemsKindOfStereoAttrib(e.GaResourcesPlatform(),e.GaResourcesPlatform_resources(), e.GaExecHost())){ thisModule.processor(root, elem2); } } -- address spaces for( elem in e.getStereoElemsKindOfStereoAttrib(if e.marteIsTypeOf(e.GaAnalysisContext()) then e.GaAnalysisContext() else e.SaAnalysisContext() endif, e.GaAnalysisContext_platform(), e.GaResourcesPlatform())) { for(elem2 in elem.getStereoElemsKindOfStereoAttrib(e.GaResourcesPlatform(),e.GaResourcesPlatform_resources(), e.MemoryPartition())){ thisModule.address_space(root, elem2); } } -- tasks for( elem in e.getStereoElemsKindOfStereoAttrib(if e.marteIsTypeOf(e.GaAnalysisContext()) then e.GaAnalysisContext() else e.SaAnalysisContext() endif, e.GaAnalysisContext_platform(), e.GaResourcesPlatform())) { for(elem2 in elem.getStereoElemsKindOfStereoAttrib(e.GaResourcesPlatform(),e.GaResourcesPlatform_resources(), e.SwSchedulableResource())){ thisModule.task(root, elem2); } } -- resources for( elem in e.getStereoElemsKindOfStereoAttrib(if e.marteIsTypeOf(e.GaAnalysisContext()) then e.GaAnalysisContext() else e.SaAnalysisContext() endif, e.GaAnalysisContext_platform(), e.GaResourcesPlatform())) { for(elem2 in elem.getStereoElemsKindOfStereoAttrib(e.GaResourcesPlatform(),e.GaResourcesPlatform_resources(), e.SwMutualExclusionResource())){ thisModule.resource(root, elem2); } } -- buffer for( elem in e.getStereoElemsKindOfStereoAttrib(if e.marteIsTypeOf(e.GaAnalysisContext()) then e.GaAnalysisContext() else e.SaAnalysisContext() endif, e.GaAnalysisContext_platform(), e.GaResourcesPlatform())) { -- buffer for(elem2 in elem.getStereoElemsKindOfStereoAttrib(e.GaResourcesPlatform(),e.GaResourcesPlatform_resources(), e.StorageResource())){ thisModule.buffer(root, elem2); } } -- event_analyzers for( elem in e.marteGetAttributeValueSequence(if e.marteIsTypeOf(e.GaAnalysisContext()) then e.GaAnalysisContext() else e.SaAnalysisContext() endif, e.GaAnalysisContext_contextParams())) { thisModule.event_analyzer(root, elem); } -- messages for(elem in e.getStereoElemsKindOfStereoAttrib(e.ACV(), e.GaAnalysisContext_workload(), e.GaWorkloadBehavior())) { for(elem2 in elem.getStereoElemsKindOfStereoAttrib(e.GaWorkloadBehavior(), e.GaWorkloadBehavior_behavior(), e.GaScenario()) ) { for(msg in elem2.getStereoElemsKindOfStereoAttrib(e.GaScenario(), e.GaScenario_steps(), e.SaCommStep())){ thisModule.message(root, msg); } } } -- dependencies for(elem in e.getStereoElemsKindOfStereoAttrib(e.ACV(), e.GaAnalysisContext_workload(), e.GaWorkloadBehavior())) { for(elem2 in elem.getStereoElemsKindOfStereoAttrib(e.GaWorkloadBehavior(), e.GaWorkloadBehavior_behavior(), e.GaScenario()) ) { for(step in elem2.getStereotypeAttributeValue(e.GaScenario(), e.GaScenario_steps())) { if(step.oclType() = UML!Dependency and step.marteIsKindOf(step.GaStep())) { thisModule.dependency(root, step); } } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -