ConTraST

Introduction

ConTraST (Configurable Transpiler for SDL to C++ Translation) is a configurable C++ code generator that provides a mapping of SDL specifications in SDL/PR to an object-oriented C++ representation. The transformation from one high level language to another allows the configuration of supported language features, thus giving the name: a configurable transpiler. Over the past 30 years, SDL has been evolving to a fairly complex description language offering a multitude of different object-oriented features. But not all features are necessarily required to specify SDL systems, and resulting waste of resources should be avoided.

With SDL-2000 a formal semantics based on Abstract State Machines (ASM) was introduced, eliminating the ambiguities that come with the informal language definition.

The intention is to maintain the object-oriented structure and thereby increase the readability and traceability of the generated code. This code is compiled together with an SDL runtime environment, which was derived by manually transforming the formal semantics of SDL-2000 standard Z.100 F.3 into C++ preserving both structure and behavior. This provides a continuous traceability from the SDL specification to the executing system including its runtime environment.


Code generator

Transition state idle;

input Signal1(number);

task value:=CALL MyProc(number);

decision value>0;
(true):
output Signal1(value) to sender;
(false):
enddecision;

nextstate idle;
Figure: Exemplary transition in SDL/GR (left) and SDL/PR (right)

The figure above shows an exemplary transition in the graphical representation (SDL/GR) on the left and the corresponding textual representation SDL/PR on the right. In the following, this transition is used to present the transformation of ConTraST. The transformation of an SDL specification into a C++ representation is done in six steps:

/* Transition ( MyProcess.spr, Page 1 ) */
void MySystem::MyBlock::MyProcess::MyProcess_T1::fire(SignalInst* signal)
{
  switch (offset) {
  case 0:
    LeaveStateNode(1);
    break;
  case 1:
    VAR->number = ((::MySystem::Signal::Signal1*)signal)->Param1;
    delete signal;
    VAR->value = MySystem::MyProc(Transition::owner, VAR->number).Call();
    if ((VAR->value > 0)==true)
      Output( (new ::MySystem::Signal::Signal1(VAR->value))->To(Sender) );
    }
    NextState(State_idle::ID());
    break;
  default:
    SDL.Error("Invalid position within transition.\n");
  }
}
Listing: The generated C++ code of the transition presented above

The challenge in transformation is to exploit and retain the given object-oriented structure of SDL/PR allowing a successive traceability from an SDL specification to its C++ representation. This is achieved by inheritance of C++ classes, each representing one specific SDL object. Most of these objects, such as plain data types or signals, can be described by simple classes with parameters, while processes with corresponding types are represented by the use of template classes. Thereby, a complete SDL system specification can be transformed to an object-oriented C++ representation.

In C++, the examplary transition is represented by a method Transition1::fire() within the given context, where MySystem, MyBlock and MyProcess are the surrounding process, block and system. The prefix of the method fire() represents the scope. The usage of switch/case constructs permits the continuation of transition execution and therefore enables the interruption of transitions after every behavior primitive and the continuation at any other position. It therefore replaces the continue label of the Z.100 F3 and enables e.g. the usage of connectors. Comparing both, the SDL/PR representation and the generated C++ code, the similarity and tracebility from one to the other is clearly visible.

A detailed description of the code generator and the transformation from SDL/PR to C++ can be found in FlGrWe06b and We05.

A simple Ping-Pong example can be downloaded here.


SDL Runtime Environment (SDLRE)

The focus for the development of an SDL runtime environment was the dynamic semantics of SDL, which is described in the Z.100 Annex F.3 (Part 2). Other parts such as the data semantics or ASN.1 coder were added as considered necessary. With SDL-2000 a formal semantics based on Abstract State Machines was introduced, eliminating the ambiguities that come with the informal language definition. The precise mathematical formalisms of ASMs, which are used to describe the formal semantics, provide a rigorous basis for compilers and runtime environments.

Domains in ASM describe types of elements, which are mapped to C++ classes. This also allows the definition of derived domains by the use of inheritance of classes. Controlled functions in ASM are represented by member variables of classes. The definition on multiple domains can be expressed by inheritance of classes in C++. ASM macros are transformed to methods of classes. This assignment of methods to classes is possible, since either it is implicitly given by the description, or one of the macro parameters is an object on which an operation is performed.

The described transformations were performed manually to a subset of Z.100 F3. This subset is a language profile, which covers all language features of SDL-2000 that are necessary to support the execution of SDL-96 specifications. In the following, an example of a transformed macro of the behaviour semantics of SDL (Z.100 Annex F.3 (2.1.1.3)):

FORWARDSIGNAL ≡
  if Self.from.queue ≠ empty then
    let si = Self.from.queue.head in
      if Applicable(si.signalType,si.toArg,si.viaArg,Self.from,Self) then
        DELETE(si,Self.from)
        INSERT(si,now+Self.delay,Self.to)
        si.viaArg := si.viaArg \
          {Self.from.nodeAS1.nodeAS1ToId, Self.nodeAS1.nodeAS1ToId}
      endif
    endlet
  endif
Listing: The macro ForwardSignal from the SDL fromal semantics

The C++ representation is presented below:

bool Link::ForwardSignal(void) {
  if ( this->from->queue()->empty()==false ) {
    SignalInst* si = this->from->queue()->head();
    if (Applicable(si->signalType(),si->toArg,si->viaArg,this->from,this)) {
      this->from->Delete(si);
      this->to->Insert(si,this->delay);
      si->viaArg.erase(this->from->Gate_name);
      si->viaArg.erase(this->Agent_name);
      return true;
    }
  }
  return false;
}
Listing: The transformed macro ForwardSignal represented in C++

This example exemplifies the straight transformation of an excerpt from the SDL recommendation to a C++ implementation. Most differences are simple rewrite rules from the ASM syntax to the C++ notation. A detailed description of the transformations and the overall runtime environment can be found in FlGrWe06b.


Download

ConTraST and the associated runtime environment SdlRE are currently available on demand only.
If you are interested, please get in contact with Ingmar Fliege or Prof. Gotzhein.



 

 
Go to the contact details of the person in charge of this page

 
This page in german. Diese Seite auf deutsch.