Home

57 The Cadvanced/Cbasic SDL to C Compiler

image

Contents

1. and either Two Examples of ADTs We now give two complete examples of abstract data types Example 364 ADT Example NEWTYPE Str STRUCT a Integer b Boolean c Real ADDING LITERALS Litl OPERATORS OPI Str Integer gt Str Op2 Str Boolean gt Str ADT B BODY Str Lit1 Str Result Telelogic Tau 4 5 User s Manual 2615 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2616 Result gt sa 2 Result gt b SDL False Result gt c 10 0 return Result Str Op1 Str P1 SDL Integer P2 Str Result Result P1 Result gt sa Pl gt a P2 return Result Str Op2 if P2 Result P1 else void Lit1 Result return Result ENDNEWTYPE Str P1 SDL Boolean P2 Str Result The example above should be compared with the same example written in SDL Note that the literal in the previous example is replaced with an operator without parameters The algorithmic extensions described in Grammar for the Algorithmic Extensions on page 146 in chapter 3 Using SDL Extensions in the SDL Suite Methodology Guidelines is also used as they provide a powerful way to write textual algorithms Example 365 ADT Example in pure SDL NEWTYPE Str STRUCT a Integer b Boolean c Real OPERATORS Litl gt Str Op1 Str Integer gt Str Op2 Str Boolean gt Str OPERATOR Lit1 RE
2. Example 371 Using S Standard Function or Operator Example of usage of S standard 4 gt integer real gt real OP SI sin real gt real 0P SP An SDL expression using these operators sin a 7 0 willbe translated to sin zh723_a 7 0 These examples show how standard functions in the target language can be directly utilized in abstract data types In C it is often easiest to use OP HP for such special cases and implement the operator in the HEADING section as a C macro transforming the call to the appropri ate syntax Generic Functions Type Info Nodes A generic function can perform a certain task for several different types To be able to write generic functions type specific information for the types must be made available This type of information could be for in stance size of the type component types for structured types and com ponent offsets This information is provided by the type info nodes A type info node is a struct that contains information that defines the type Each type has a corresponding type info node Each type info node contains two sections The first section contains a sequence of general components that is identical for all type info nodes The second section is an individual type specific sequence of components that defines each unique type Telelogic Tau 4 5 User s Manual 2623 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2624 Every newtype or synty
3. Synonyms Synonyms An SDL synonym is implemented either as a C macro def ine or as aC variable To be translated to a macro the expression defining the val ue of the synonym must be e Of one of the predefined SDL sorts Integer Real etc e Possible to calculate at analyze time i e it may only contain literals and operators defined in the predefined SDL sorts and other syn onyms which are possible to calculate at analyze time All other synonyms are implemented as variables given their values at program start up Telelogic Tau 4 5 User s Manual 2579 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2580 The reason for raising this question is because it is relevant to the im plementation of arrays and powersets There are two different imple mentations for each of these concepts see Array on page 2601 and Powerset on page 2602 An array in SDL can either be translated to an array in C or to a linked list in C A powerset can either be translated to a bit array in C or to a linked list The translation method is selected by looking at the index type If the index type is a syntype with one lim ited range the array and bit array scheme is used otherwise the linked list is used If a synonym translated to a variable is used in a range condition of a syntype and the syntype is used as an index sort in an array or powerset instantiation the linked list scheme is used to implement the array or pow
4. This example is taken from the ADT byte see Abstract Data Type for Byte on page 3176 in chapter 63 The ADT Library The byte type should be read and printed using HEX format ifdef XREADANDWRITEF static char yCTmp 20 extern int yRead_byte void Result unsigned temp xxToken Token Token xPromptQuestionMark byte byte yCTmp if Token xxId amp amp sscanf yCTmp X amp temp gt 1 byte Result byte temp return 1 xPrintString Illegal byte value n return 0 extern char yWri_byte void C sprintf yCTmp 0 2xX byte C return yCTmp endif Example 373 ADT Example Struct Write Functions This is an example of how the read and write functions for a struct with two components can look The monitor system can handle reading of writing of struct values automatically so please see this just as an ex ample Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types newtype structl NAME structl struct a b Integer ADT W BODY ifdef XREADANDWRITEF static char CTemp 500 char yWri_struct1 void In_ Addr strcpy CTemp strcat CTemp xWriteSort void amp struct1 In Addr gt a xSrtN_SDL_ Integer strcat CTemp strcat CTemp xWriteSort void amp struct1 In Addr gt b xSrtN_SDL Integer strcat CTemp
5. TestClass int TestClass TestClass int updateVar int int getVar private int v then the following abstract data type can be used to represent the class in the example the NAME directive see Specifying Names in Gener ated Code Directive NAME on page 2667 is used to instruct the Cadvanced Cbasic SDL to C Compiler which name to use in C for par ticular SDL objects NEWTYPE TestClass NAME TestClassPtr LITERALS Telelogic Tau 4 5 User s Manual July 2003 Using Cadvanced Cbasic SDL to C Compiler to Generate C July 2003 newTestClass NAME newlTestClass OPERATORS newTestClass NAME new2TestClass integer gt TestClass deleteTestClass NAME deleteTestClass TestClass gt TestClass updateVar NAME updateVar TestClass integer gt integer OP HC getVar NAME getVar TestClass gt integer OP HC ADT T A S E S D H H P TYPE include TestClass h typedef TestClass TestClassPtr COMMENT NOTE SDL data type TestClass is pointer to C class TestClass HEADING define yDef_TestClassPtr p p 0 define newlTestClass new TestClass define new2TestClass P new TestClass P extern TestClassPtr deleteTestClass TestClassPtr BODY extern TestClassPtr deleteTestClass TestClassPtr P delete P return TestC
6. iv cg acs should be changed to str litl str Result on str opl str P1 SDL Integer P2 str Result Updating Operator Literal Functions The implementation of the operator literal functions must be updated to reflect the change in parameters Example 405 Operator Literal Functions continued from Example 404 In the function op1 every occurrence of P1 should be replaced by P1 Special cases where other changes might be more appropriate amp P1 should be replaced by P1 Pl abc should be replaced by P1 gt abc The new Result parameter must be assigned the result value of the func tion and the function must end with a return statement Example 406 Return Parameter return Result Telelogic Tau 4 5 User s Manual 2687 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2688 It is not unusual that the function contains a local variable used for cal culating the result Normally this variable is no longer needed While updating the implementation of the function information from the next section on for example assign and equal function might be valuable Note Check that parameters that are passed as addresses are NOT CHANGED within the function If that is the case copy the value to a local variable first and work with that variable Update Calls to Functions The calls to the changed functions must be updated Calls made from SDL cause no problems as the SDL compilers produce the co
7. return CTemp endif endnewtype More about ADT When generate is specified for a function the code generator might de cide not to generate the heading of the function as in some cases it is not needed All code that is not generated is assumed to be included by the user in the TYPE HEADING and BODY sections in the ADT directive Another name for an assign function equal function and so on may be used by including the desired name within quotes together with the generation options in the ADT directive If for example the name of a certain assign function should be AssX this can be obtained by specifying A B AssX for the assign function This name will then be used throughout the generated code both in gen erated declaration and at the places where the function is called The name should be last in the specification for the actual function An include statement may be generated together with or replacing the type definition by giving a file name within quotes last in the specifica tion part of the ADT directive immediately before the first section with code Telelogic Tau 4 5 User s Manual 2645 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2646 Example 374 Including a File in ADT If the directive ADT T B A S E S file name is used the following include statement will be generated include file name Note Turning off the generation of the objects
8. s Manual 2673 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2674 Alternative Implementations of the String Generator Directive STRING An instantiation of the string generator can be translated to either a linked list or an array when implemented in C The STRING directive is used to determine which translation method to select The directive should be inserted in a NEWTYPE definition directly after the string name when defining a new string data type If the STRING directive is not included in the NEWTYPE definition the string is implemented as a linked list This is the default translation method However just adding the directive to the NEWTYPE defini tion is not enough to implement the string as an array The length of the array must also be defined This can be done either by using a directive parameter or by using a size constraint in the NEWTYPE definition of the string generator How this is done is presented in the examples be low Linked List Implementations The following examples show how to translate an instantiation of the string generator to a linked list Example 394 No STRING Directive NEWTYPE Example String string integer empty constants size 0 10 ENDNEWTYPE If the STRING directive is missing from the NEWTYPE definition the string will be implemented as a linked list The length of the list is unlimited unless a size constraints is defined In this case the length of
9. Connection con Signal sig Formal parameter for Signal list sil Gate gat Signal route sir Generator gen Sort Newtype sor Import imp State sta Label lab Syntype syt Literal lit Synonym syo Operator ope System System type sys Package pac Timer tim Predef pre Variable var Procedure prd View vie July 2003 Telelogic Tau 4 5 User s Manual 2665 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2666 Using entity class prefix means that the user must guarantee that no name conflict occurs It also means however that the generated names are predictable and thus simplifies writing C code where the SDL names are used It is only necessary to look for name conflicts within entity classes for example not having two sorts with the same name The en tity class prefixes handle the case when two objects of different entity class have the same name Note that the table above contains all entity classes Not all of the items are actually used by the code generator No Prefix The third alternative no prefix means of course that no prefixes are added to the SDL name The name in the C program will then be the SDL name stripped form characters that are not allowed in C identifiers everything except letters digits and underscore In this case the user must guarantee that no name conflict occurs and that the stripped name is allowed as a C identifier that is that it begins with a letter Special Prefix In the fourth alter
10. Integer More about operator implementation both parameter passing and how to include implementations written in C can be found in the next two sections Literals In sorts that are translated to enumeration types in C literals are obvi ously handled by the code generator In sorts that are not enumeration types literals are treated as operators without parameters and are han dled in exactly the same way as user defined operators Note The Cadvanced Cbasic SDL to C Compiler does not permit naming of literals using name class literals or character strings Axioms and Literal Mappings Axioms and literal mapping are allowed by the code generator in sorts but are completely ignored Telelogic Tau 4 5 User s Manual 2605 Chapter 57 The Cadvanced Cbasic SDL to C Compiler Parameter Passing to Operators For performance reasons the data types in SDL have been divide in two groups simple small types that are passed as values and structured larger types that are passed as references addresses Types passed as addresses structured types Bit_string Octet_string Object_identifier Struct types including UNION UNIONC Choice types Instantiations of generator Powerset Instantiations of generator Bag Instantiations of generator Array Instantiations of generator String Instantiations of generator Carray Syntypes of a type in this list Types that inheri
11. Note Even though the code size of the generated application is reduced the code size of the generated C code is increased Manual override In order to handle cases where operators are used invisibly from the Cbasic Cadvanced SDL to C Compiler for example in inline C code you can manually override the automatic configuration of the unused operators In the code generation process the Targeting Expert always generates a manual configuration file called sct_mcf h In this file you can list the unused operators that you have decided to include in the application This is done by un defining the previous definitions made in the sdl_cfg h file The sct_mcf h can be edited directly from Targeting Expert Select Edit Configuration Header File from the Edit menu to open the file Example 345 The undef command in the sct_mcf h file ifdef XNOUSE_AND BIT STRING undef XNOUSE_AND BIT STRING endif Telelogic Tau 4 5 User s Manual 2587 Chapter 57 The Cadvanced Cbasic SDL to C Compiler One section of the sct_mcf h file is dedicated for the manual edits This section is marked with the text BEGIN User Code END User Code The manual edits must be inserted between these to lines otherwise they will be deleted as the sct_mcf h file is re generated each time you generate code The information about the unused operators available in the sdl_cfg h file is imported to the sct_mcf h file This allows you to quickly s
12. Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types in a printable form This character string is the string that will be printed by the monitor when it needs to print a value of this type To implement the write function it is not uncommon that a static char array is needed Note The following two considerations when it comes to write and read functions e The read and write functions and any help variables and help func tions ought to be surrounded by ifdef XREADANDWRITEF endif to be removed if read and write functions are not needed e The string format used to represent value of a type should be the same in the read and the write function Otherwise communicating simulations will not work if this type is passed as parameter be tween the systems The function xWriteSort which is part of the run time kernel can be useful when implementing Write functions extern char xWriteSort void In Addr xSortIdNode SortNode The xWriteSort function takes the address of a value to be printed and a pointer to a xSortIdNode and returns the given value as a string This function is typically useful if the sort we are implementing a write func tion for contains one or several components of sorts defined in SDL Read Function In order to assign new values to variables that are of a sort that is imple mented in C i e has HADT T in its ADT directive it is necessary to implement a read fun
13. able features in the SDL suite including extensions for operators in out parameters no parameters no result etc One not too uncommon situation is when a value is passed as an in pa rameter then changed by the operator and returned as result value In every operator call the same variable is used as both the actual param eter and the receiver of the result To improve speed of the application the operator could be changed to an operator without result and using in out parameters If you perform a change like this remember to use the cross reference tool to find all places where the operator is used Step 4 Updating typedefs Overview Another area where backward incompatibility problems might be present is when the typedef is changed in an ADT directive especial ly if the assign equal or free functions are changed as well In the sec ond section of the file compat ibility warn all types changing the ty pedef and at least one of assign equal or free functions are listed Example 407 Typedef Change NEWTYPE example C name zDZ example lt lt SYSTEM mysystem gt gt SDTREF TEXT file sdl1 3096 9 Pass as Value ADT T B A B E B F B The example should be interpreted like this e The first line contains the name of the newtype in SDL and in C e The second line contains an appropriate qualifier that gives infor mation on where in the system the newtype is defined Telelogic Tau 4 5 User s Manua
14. e The formal parameters of a process or procedure e The definition of a block process procedure e The definition of a channel signal route signal signal list newtype syntype synonym generator connection valid input signal set variable view import timer remote variable remote procedure In the following small PR example the allowed positions are marked with an followed by a number Example 383 CODE Directive system s 1 signal sl s2 integer 2 channel cl from env to bl with sl s2 3 newtype n endnewtype n 4 block b1 5 signalroute srl from env to pl with sl s2 6 connect cl with srl 7 process pl 1 1 8 signalset sl s2 9 dcl an 10 start state endprocess pl 11 endblock b1 12 endsystem s1 A code directive is considered to belong to the unit where it is defined and the declarations within the directive are thus placed among the other C declaration for that unit In the example above directives at positions 1 2 3 4 12 belong to system s directives at positions 5 6 7 11 belong to block b1 while directives at positions 8 9 10 belong to process p1 Only one code directive may be placed at each available position Telelogic Tau 4 5 User s Manual 2659 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2660 Note A variable declared in a CODE directive that belongs to a process will be shared between the process instances of the process instance set Such a var
15. typedef enum a b c StrPresent typedef struct StrPresent Present union SDL Integer a SDL Boolean b SDL Real c 1U Str The component Present which is the tag field and its type StrPresent in the example above are both available in SDL The Present component can in SDL be accessed but not changed through Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types e component selection i e by Variable Present i e itis possible to for example test v Present a e the operators aPresent bPresent or cPresent which returns true or false depending on if the component is active or not The Present component is automatically set by the code generator when a component in the choice is given a value Note that during simulations and validations it is automatically tested that a component is present when an attempt is made to access the component A run time error is issued if this is not the case Array Instantiations of the predefined generator array can be handled by the code generator with the following restriction The component and index sort may be any sorts that the code generator can handle but may not directly or indirectly refer to the array type itself see also the previous paragraph on struct If the index sort is a discrete sort with one closed interval of values that is of the following sorts e Character e Boolean e Octet e Bit e A sort that is con
16. 2617 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2618 tained in generated code that can be useful when implementing opera tors in C see SDL Predefined Types on page 2588 and last in More about Abstract Data Types on page 2634 Error Situations in Operators In the C function used to implement operators and literals it is possible to define error situations and handle them as ordinary SDL run time er rors The C library function xSDLOpError with the following proto type extern void xSDLOpError char OpName char ErrText can be used for this purpose Example 367 Error Handler in Operator Example of use if strlen c lt 1 ifdef XECSOP xSDLOpError First in sort Charstring Charstring length is zero endif return SDL NUL else return C 1 This is a simplified version of the test in the function for the operator First in the sort Charstring Here the error situation is when we try to ac cess the first character in a charstring of length 0 In this case the xSDLOpError is called and a default value is returned NUL By in cluding the xSDLOpError call between ifdef XECSOP endif the function is only called to report the error if error checks are turned on The first parameter to xSDLOpError should identify the operator and the sort while the second parameter should describe the error Handling of the Charstring Sort The SDL sort Charstring is impleme
17. Pid Bit Bit_string Octet Octet_string Object_identifier ASString NumericString Printa bleString and VisibleString are completely handled The name of these types in the generated C code will be SDL_Integer SDL_Natural SDL_Boolean and so on The translation rules for these types and their operators are discussed in more detail in the SDL Predefined Types on page 2588 Telelogic Tau 4 5 User s Manual 2595 Chapter 57 The Cadvanced Cbasic SDL to C Compiler Enumeration Type A sort which is not a struct and does not contain any inheritance or gen erator instantiation but which contains a literal list is seen as an enu meration type See the example below Such a type is translated to int together with a list of defines where the literals are defined as 0 1 2 and so on As in all examples in this sub section the prefixes which are added to names when they are translated to C are not shown The pre fixes are added to make sure that no name conflicts occur in the gener ated program For more information about prefixes see Names and Prefixes in Generated Code on page 2663 Example 346 Enumeration Type NEWTYPE EnumType LITERALS Litl Lit2 Lit3 ENDNEWTYPE is translated to typedef XENUM_TYPE EnumType define Litl 0 define Lit2 1 define Lit3 2 Where the macro XENUM_TYPE is defined in sctpred c as ifndef XENUM TYP define XENUM TYPE int endif T
18. SDL actions such as tasks decisions and signal outputs are executed according to the semantics of SDL You interact using SDL terminology with the simulator through a monitor system which contains a number of commands to e Control the execution of transitions e Examine the status of objects in the system e Turn log facilities on and off e Affect the system by for example sending signal instances from the environment to the system 2566 Telelogic Tau 4 5 User s Manual July 2003 Introduction July 2003 Contents of This Chapter You can find more details on creating and executing a C program in the following sections In Generating a C Program on page 2568 the process of generat ing a C program is described In Abstract Data Types on page 2586 implementation aspects es pecially concerning abstract data types are described In Directives to the Cadvanced Cbasic SDL to C Compiler on page 2649 possibilities to give additional information to the Cad vanced Cbasic SDL to C Compiler are discussed The section Using Cadvanced Cbasic SDL to C Compiler to Gen erate C on page 2677 contains considerations on class defini tions as C code and the utilization of the classes as C code in SDL tasks In Restrictions on page 2681 the Cadvanced Cbasic SDL to C Compiler restrictions are covered Telelogic Tau 4 5 User s Manual 2567 Chapter 57 The Cadvanced Cbasic
19. Tau 4 5 User s Manual July 2003 July 2003 Implementation have therefore used an implementation strategy closer to the described behavior of the concepts rather than the model used to define the con cepts Implementation Strategy First we distinguish between those enabling conditions and continuous signals that are dynamic and those that are static that is containing ex pressions that can or cannot change their value when the corresponding process is waiting in the state The expression in a dynamic enabling condition or continuous signal contains some part that can change its value even though the process does not execute any statements Or put more precisely it contains at least one import view or reference to Now Static enabling conditions or continuous signals do not provide any problems or any execution overhead except that the corresponding ex pressions have to be calculated at nextstate operations Dynamic en abling conditions or continuous signals however have to repeatedly be recalculated The strategy selected for these expressions is to recalcu late them after each transition or timer output performed by any process and additionally also before the monitor is entered within a transition In other words each process waiting in a state containing a dynamic en abling condition or continuous signal executes an implicit nextstate op eration between each transition or timer output performed by other pro cesses
20. a number of di rectives given mainly in SDL comments The ADT OP UNION and REF directives used in abstract data types are examples of such di rectives The directives ADT and OP were described in the section Implementation of User Defined Operators on page 2609 Union on page 2598 and Directive REF on page 2646 in connection with ab stract data types and are not further discussed here A directive has the general structure 1 The start of comment character A character The directive name PLOOY Possible directive parameters given in free syntax That is spaces and carriage returns are allowed here 5 The end of comment characters Upper and lower case letters are considered to be equal in directive names Example 378 OP Directive Take as an example the directive OP B This comment will be recognized as a directive only if no other charac ter is inserted in the sequence o0P After this part spaces and carriage returns may be inserted freely July 2003 Telelogic Tau 4 5 User s Manual 2649 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2650 Selecting File Structure for Generated Code Directive SEPARATE The purpose of the separate generation feature is to specify the file structure of the generated program Both the division of the system into a number of files and the actual file names can be specified There are two ways this information ca
21. able in the target language which should be used as implementation of the SDL operator literal No function heading or function body is generated In expressions where such an operator is used no pre fix is added to the SDL name during the translation but the SDL name is used as it is if no NAME directive is present e P prefix or I infix where P is the default value These letters are used to indicate if the operator should be used as a function or an operator As an operator a 1 a 4 a Orasa function call sin a power a 3 Note As C does not include the possibility to have user defined operators I infix is only adequate together with S standard For each operator one of the letters B Q H S and one of the letters P I should be supplied either in a OP directive or in a ADT directive or as the defaults Q and P for literals P and I have no meaning The purpose of S is straight forward and easy to understand but H might require some explanation H means that the code generator will not gen Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types erate any code for the operator which leaves the user with a number of possibilities e By not including any code for an operator the user may skip the code for an unused operator e There might already exist external declarations for a number of op erators in a h file that should be used instead of the generated head ings
22. and so on Note It is completely up to the user to make certain that only valid com ponents in a UNION struct are accessed During simulation how ever tests are inserted to ensure that only valid components are ac cessed UnionC By using the directive UNIONC according to the example below it is possible to tell the Cadvanced Cbasic SDL to C Compiler to generate a true C union Example 351 UnionC NEWTYPE Str UNIONC STRUCT a integer b Boolean c real ENDNEWTYPE Telelogic Tau 4 5 User s Manual 2599 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2600 is translated to typedef union SDL Integer a SDL Boolean b SDL Real c Str Note The UNIONC directive is not recommended for use as the Cad vanced Cbasic SDL to C Compiler cannot give any support for checking the validity of component selection Both the UNION di rective and the CHOICE concept discussed below are much better Note also that pointer types including Charstrings are not allowed in UNIONC structs as it is not possible to know when to allocate and de allocate memory for such components Choice Choice which is an SDL extension originating from the needs when translating ASN 1 to SDL and which is included in SDL 2000 can be used to express a union with implicit tag Example 352 Choice NEWTYPE Str CHOIC a integer b Boolean c real ENDNEWTYPE J is translated to
23. called within an ex pression In the Cadvanced Cbasic SDL to C Compiler such procedure calls are implemented according to the model in the SDL recommenda tion that is by inserting an extra CALL just before the statement con Telelogic Tau 4 5 User s Manual July 2003 July 2003 Implementation taining the value returning procedure call The result from the call is stored in an anonymous variable which is then used in the expression Example 342 Procedure Call TASK i call p 1 call Q i k is translated to CALL p 1 Templ CALL q i k Temp2 Tempi Temp2 Note The value returning procedure calls are transformed to ordinary calls by adding a new IN OUT parameter for the procedure result last in the call Operators which are defined using operator diagrams are according the models in the SDL recommendation treated exactly as value returning procedure External Procedures And Operators External procedures is a extension to SDL introduced in SDL 96 An external procedure is defined in a text symbol as a procedure heading procedure test fpar a integer returns integer external Instead of giving an implementation for the procedure the keyword ex ternal is inserted The purpose of external procedures in SDL are to specify the existence of procedures without giving their implementa tion The Cadvanced Cbasic SDL to C Compiler will generate no code for an external procedure declaration
24. code in the directive is included in the if part of the if statement just like the assignment it is associated with This will be treated as if true i i144 3 i 5 To put the code directly after the if statement the following structure with an empty statement after the if statement can be used if true i i 4 CODE i 4 4 5 Including C Declarations Directive CODE The CODE directive can also be used to include C declarations for ex ample types variables functions define and include in the declara tion parts of the C program This version of the code directive has the following structure COD TYPE C code containing Types and variables HEADING C code containing Extern or static declarations of functions BODY C code containing Bodies of functions ay 5a The separation of functions into HEADING and BODY sections serves the same purpose as in the ADT directive see Implementation of User Defined Operators on page 2609 2658 Telelogic Tau 4 5 User s Manual July 2003 Directives to the Cadvanced Cbasic SDL to C Compiler July 2003 Code directives to include C declarations may generally speaking be placed immediately after a semicolon that ends a declaration in SDL More precisely it is allowed to place a CODE directive after the semi colon that ends e A heading of a system block substructure process procedure
25. follows SDL SDL name or SDL SDL name entity class name There is also a short form for the directive No characters are allowed between the character and the left parentheses in this form SDL name or SDL name entity class name Replace SDL name with the name of an object in the SDL definition and entity class name by any of the following identifiers upper and lower case letters are considered to be equal 2654 Telelogic Tau 4 5 User s Manual July 2003 Directives to the Cadvanced Cbasic SDL to C Compiler block operator signal blockinst package signallist blocksubst predef signalroute blocktype procedure sort newtype channel process state channelsubst processinst synonym connect processtype syntype formalpar remoteprd system gate remotevar systemtype generator service timer label serviceinst variable literal servicetype view newtype This list contains all entity classes which means that not all of the en tries are relevant for practical use When a SDL directive is found in included C code the code generator first identifies what SDL object is referred to and then replaces the directive by the C name for that object The search for the SDL object starts in the current scope the scope where the C code is included and follows the scope hierarchy outward to the system definition until an appropriate SDL object is found An appropriate SDL name is considered to be fou
26. for example a type or a function in the gener ated program To handle this problem the user can tell the code genera tor to translate a name in the C code in the same way as SDL names are otherwise translated This is specified by enclosing the SDL name be tween and in the C code The two functions in the previous ex ample and their headings would then become Example 363 Including SDL name in C Code extern Str Lit1 extern Str Op1 Str Seo SDL_ Integer Str Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types Str Lit1 Str Result Result gt sa 2 Result gt b false Result gt c 10 0 return Result Str Opl Str P1 SDL Integer P2 Str Result Result P1 Result sa Pl gt a P2 return Result This facility to access an SDL name in C code is described in more de tail in the section Accessing SDL Names in C Code Directive SDL on page 2654 A few observations concerning the example above might be appropriate 1 The predefined sorts in SDL that is for example integer natural Boolean have the names SDL_Integer SDL_Natural SDL_Boolean and so on in the generated code These types should not be enclosed between and The component names of a struct are unchanged in the struct imple mentation in C which means that struct components should not be enclosed between
27. generated code yourself you can use the NAME directive Place the directive directly after the name in the declaration of the object It should contain the desired name to be used in the generated code within quotes Example 387 NAME Directive NEWTYPE S NAME S STRUCT a integer b Boolean ADDING OPERATORS Op NAME OtherName S S gt Boolean ENDNEWTYPE The name defined in a NAME directive will be used everywhere that the SDL name is used in the generated code with two exceptions e Inthe monitor system the SDL names will be used in the communi cation with the user e The name of the files for generated code are not affected by the us age of NAME directives There are however some restrictions on where NAME directives can be placed Some objects in for example a block type are generated in each instantiation of the block type If a name directive is placed at such an object the name will probably be overloaded in C resulting in a C compilation error The sensitive objects are processes process instanti ations signal routes channels remote variables and remote proce dures Assigning Priorities Directive PRIO Priorities can be assigned to processes and process instantiations using the directive PRIO The process priorities will affect the scheduling of processes in the ready queue see Time on page 2576 A priority is a positive integer where low value
28. number of help functions that implement the operators for the Charstring sort supplied in the runtime library that might be helpful when handling Charstrings See SDL Predefined Types on page 2588 Other Types Containing Pointers The principal discussion about Charstrings in the previous section is also relevant for all other types containing pointers Such types are Bit_string Octet_string Object_identifier Strings not STRING General Arrays General Powersets Bags All these types contain a boolean component IsAssigned that gives the status of the data area IsAssigned serves the same purpose as the first extra character in a Charstring and has to be treated in a similar way Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types e IsAssigned equal to false means that this data area is a temporary re sult from a function returning the data type This memory should ei ther be assigned to an SDL variable or returned to the pool of free memory e IsAssigned equal to true means that this value is assigned to a vari able and may not be changed in any way It can also mean that the value is part of i e is assigned to a larger data structure External Properties As an alternative to the ADT directive which is a comment the exter nal properties clause in a newtype can be used as container for this in formation See the following example Example 370
29. the Make dialog A C program can only be generated for an SDL system The C code that constitutes the program can however be generated on multiple files which means that a local change in for example a block diagram only requires a regeneration and recompilation of the code for that unit The object files the compiled versions of the C files for the other un changed units can then be used in the link operation to form a new exe cutable program This feature in automatically used by the make facility and the quick buttons to minimize the amount of work and thus the turn around time for the process from a change in the SDL system to a new simulator for example Telelogic Tau 4 5 User s Manual July 2003 July 2003 Generating a C Program The separation of the C code for an SDL system can be decided by the user The Edit Separation command from the Generate menu is used for that purpose see Edit Separation on page 136 in chapter 2 The Orga nizer The effect on the generated file structure and some guidelines of how to use separation can be found in the section Selecting File Struc ture for Generated Code Directive SEPARATE on page 2650 Executing a C Program The generated C programs can in principle be compiled as either a sim ulator a validator or an application Generated applications have no further connection with the SDL suite and are executed as any other ap plication A generated simu
30. the kernel at each lo cation where an assignment should take place The three macro param eters are e V the variable on the left hand side e E the expression on the right hand side e A an integer giving the properties of the assignment Telelogic Tau 4 5 User s Manual July 2003 Abstract Data Types This macro will either become an assignment statement in C or a call of an assignment function An assignment statement will be used if assign ment is allowed according to C for the current type and if it has the cor rect semantics comparing with assignment in SDL If assignment is not possible to use the assign macro will become a call to an assignment function The basic generic assignment function can be found in sctpred c and sctpred h extern void GenericAssignSort void void int tSDLTypeInfo where e The first parameter is the address of the variable on the left hand side e The second parameter is the address of the expression on the right hand side e The third parameter is the properties of the assignment e The fourth parameter is the type info node for the actual type GenericAssignSort returns the address passed as the first parameter The GenericAssignSort function performs three tasks 1 The old value on the left hand side variable is released if that is specified in properties of the assignment and if the value contains any pointers 2 The value is copied from the expression to the varia
31. the string is within the range of 0 and 10 Example 395 STRING Directive without Limited String Size NEWTYPE Example String STRING string integer empty ENDNEWTYPE In this example the string is also implemented as a linked list The rea son for this is that we have not defined a maximum length of the string Telelogic Tau 4 5 User s Manual July 2003 Directives to the Cadvanced Cbasic SDL to C Compiler July 2003 Example 396 STRING Directive with Parameter Value 0 NEWTYPE Example String STRING 0 string integer empty constants size 0 10 ENDNEWTYPE If the parameter value of the STRING directive is 0 the directive is ig nored Therefore the string will be implemented as a linked list The size constant will still decide the length of the string This example however shows how to gradually migrate from a linked list implementation to an array implementation By just changing the parameter value to anything larger than 0 this NEWTYPE definition creates an array implementation Array Implementations The following examples show how to translate an instantiation of the string generator to an array Example 397 STRING Directive with Limited String Size NEWTYPE Example String STRING string integer empty constants size 0 10 ENDNEWTYPE In this case the string is implemented as an array with the maximum length of 10 Example 398 STRING Dir
32. to be changed and that calls to such operators directly from C have to be changed e Predefined operators like assignment equal test make and so on as well as operators in predefined generators might have changed their prototypes in C which means that calls to such operators di rectly in C have to be changed Also types where the implementa tion of assignment equal and similar operators are changed by a ADT directive might have to be updated The first of these problems is fairly straight forward to fix while the second might be more complex Step 1 Identifying Migration Problems Before continuing with the migration instructions check if your SDL systems are affected by any incompatibility problems 1 Find an SDL system that compiles without errors in a previous ver sion of the SDL suite with the old style operator implementations 2 Open it in the 4 5 version of Telelogic Tau 3 Compile it and see if you get any compilations errors If your compilation errors are similar to the errors in Example 401 on page 2684 you can assume that you have a migration problem Example 401 Compilation Errors The compilation error in this example originates from the GNU compil er gcc It gives a fairly good feeling of what kind of errors you can ex pect file c 50825 conflicting types for yAss_ example file c 50844 conflicting types for yEq example file c 51496 conflicting types for opl file c 211376
33. too many arguments to function opl file c 211376 cannot convert to a pointer type file c 6042 incompatible type for argument 2 of GenericAssignSort file c 6081 incompatible type for argument 2 of opl 2684 Telelogic Tau 4 5 User s Manual July 2003 July 2003 Migration Guide for Generic Functions Step 2 Locating the Compatibility Problems Note Before you try to investigate and correct any error from the list of C compilation errors you should perform this step The reason is that many of the errors will point at the wrong place so correcting them might introduce errors rather than correcting anything The Cadvanced Cbasic and Cmicro SDL to C compilers allows you to find the operators and literals that should be updated By setting the en vironment variable SDT_COMP_WARN the code generators will produce a file called compatibility warn in the target directory while generat ing code for the system In the first section of this file all operators and literals that might have to be changed are listed Example 402 Contents of compatibility warn LITERAL NewDb C name z0VO_NewDb lt lt SYSTEM accesscontrolooa gt gt SDTREF TEXT file sd1 57 12 Literal function result passed as address OPERATOR ValidateCard C name z0V1_ValidateCard lt lt SYSTEM accesscontrolooa TYPE CardDbType gt gt SDTREF TEXT file sd1 59 5 Parameter 2 passed as address Used in DIRECTIVE at SDTREF TEXT fi
34. will be set to 0 by us ing a memset to 0 Operators In SDL 92 it is possible to define the behavior of operators in ADTs di rectly in SDL using operator diagrams or operator implementations in SDL textual form Such operators are translated to C by the Cad vanced Cbasic SDL to C Compiler and none of what is said below is Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types valid for such an operator It is also possible to specify that an operator is external In this case the code generator assumes that a C function with the name used in SDL exists and translates calls to the external op erator directly to calls to the C function A user defined operator in an SDL sort definition which is not defined by an operator diagram is translated to a C function which asks the user for the result of the operation At a call of an operator the user is sup plied with information describing what the operator and the sort are called and given information about the parameter values You are then requested to answer with the result value If you press lt Return gt at the prompt for the result the default value of the actual result type is re turned If the operator does not have a result type no question is asked Example 355 Operator Operator Op in sort S is called Parameter 1 true Parameter 2 10 Enter value integer 12 assuming that newtype S contains an operator Op Boolean Integer gt
35. 21 c P2250 The c files contain the C code for the corresponding SDL unit and the h files contain the module interfaces 2652 Telelogic Tau 4 5 User s Manual July 2003 Directives to the Cadvanced Cbasic SDL to C Compiler July 2003 Applying Separate Generation If User defined separate generation is selected then the following files will be generated Sfile c Sfile h Contains code for units S B2 P21 Bl c Bl h Contains code for units B1 P12 Plifile c Contains code for unit P11 P22 c Contains code for unit P22 The user defined separate generation option thus makes it possible for a user to completely decide the file structure for the generated code The comments on files and extensions given above are of course also valid in this case Applying No Separate Generation If the separation option No is selected only the following file will be generated Sfile c Contains code for all units The comments on files and extensions earlier are valid even here Guidelines Generally a system should be divided into manageable pieces of code That is for a large system full separate generation should be used while for a small system no separate generation ought to be used The possibility to regenerate and recompile only parts of a system usually compensate for the overhead in generating and compiling several files for a large system Note A file name has to b
36. 22 in block b2 is gener ated with the Cadvanced SDL to C Compiler The modularity is user de fined and a system header file ifc file will also be generated Code from the code generators will be placed in a subdirectory with the name given in the Program command to the directory given by target directory If this subdirectory does not exist it will be created Note You should always include a target directory command in a build script as otherwise the target directory will depend on where the SDL suite is started In the example above the generated C code can be found in the directory home jk example target MyExample In Windows c example target MyExample In the example below three programs are generated for three different partitionings also using different code generators Telelogic Tau 4 5 User s Manual 2573 Chapter 57 The Cadvanced Cbasic SDL to C Compiler Example 337 Build script with several programs target directory home jk example target program MyExample component system example block b1 component system example block b2 process p22 set env header on set modularity user set kernel SCTDEBCOM generate advanced c program MyExamplel component system example block b2 process p21 generate micro c program MyExample2 component system example block b3 set modularity no generate chipsy chill Analyzer commands that are of the type set up an option can be placed outside of the Prog
37. BODY Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types C code Af where each x on the first line should be replaced by one of the characters B H Q S or G Replace y by P or I The interpretation of these char acters is similar to the their interpretation for operators Body Heading Question Standard Generate Prefix 5 Q aj o T w Infix The reason why G generate is not allowed for operators or literals is of course that it would mean to generate the implementation of the op erators from the axioms which is at least in the general case an impos sible task For an operator defined in an operator diagram G is assumed independently of what the user specifies The specifications given in ADT directives of how to generate code for type definition assignment test for equal default values and free func tion should be interpreted according to the table below Type Definition First the actual type definition The entry should be interpreted as if no specification is given for T Type Interpretation T G Generate type definition from SDL sort T B Do not generate type definition Assume the type should be passed as value to operators T BV Do not generate type definition Assume the type should be passed as address to operators Telelogic Tau 4 5 User s Manual 2635 Chapter 57 The Cadvan
38. Chapter 57 July 2003 The Cadvanced Cbasic SDL to C Compiler The Cadvanced Cbasic SDL to C Compiler translates your SDL system into a C program that you can compile and link together with a runtime library to form an executable program such as a simulator a validator or in the case of Cadvanced an application This chapter is a reference manual to the Cadvanced Cbasic SDL to C Compiler There are also a number of other chapters related to code generation In chapter 50 The SDL Simulator you will find a reference to the simulation facilities in the SDL suite In chapter 51 Simulat ing a System you will find a user s guide to the simulator In chapter 53 The SDL Validator you will find a reference to the validation facilities in the SDL suite In chapter 54 Validating a System you will find a user s guide to the validator In chapter 58 Building an Application you may read about how to generate applications for host and target environments In chapter 62 The Master Library you will find information about how to customize your own libraries for a specific pur pose such as application generation for target computers The chapter also describes the structure of the generated C code and the internal data structures in the generated C code In chapter 63 The ADT Library you will find a reference to the library of abstract data types that is distributed with the SDL suite and that you may use in your systems desi
39. External Properties in a Newtype NEWTYPE Str STRUCT a integer b Boolean c real ADDING LITERALS Lit OPERATORS Op1 Str integer gt Str Op2 Str Boolean gt Str ALTERNATIVE C ADT B BODY some appropriate C code ENDALTERNATIVE ENDNEWTYPE The ADT directive without the can be placed between ALTERNATIVE C and ENDALTERNATIVE Note According to the syntax of SDL if you have an external properties clause i e alternative endalternative you cannot in the same newtype have operator diagrams axioms or literal mappings Telelogic Tau 4 5 User s Manual 2621 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2622 More about Operators For an operator in an abstract data type not only B body or Q ques tion may be specified The following choices are available e Q question This is the default value and specifies that the code generator should generate the interactive routines describe above e B body This specifies that the code generator should generate the heading of the operator or literal function while the user should supply the body of the function e H heading This specifies that the code generator should neither generate the heading nor the body of the operator or literal function The user is assumed to supply the necessary code e S standard This is used to indicate that a standard function or operator is avail
40. Manual July 2003 July 2003 Abstract Data Types This function takes the address of a variable and a type info node and releases the dynamic memory used by this value contained in the vari able Generic Make Functions There are four generic functions constructing values of structured types extern void GenericMakeStruct void tSDLTypeInfo extern void GenericMakeChoice void tSDLTypeInfo int void extern void GenericMakeOwnRef tSDLTypeInfo void j extern void GenericMakeArray void tSDLTypeInfo void GenericMakeStruct According to SDL the Make operator is only available for the struct type However in the SDL suite the Make oper ator and thus the GenericMakeStruct function is also available for the Object_identifier type and the instantiations of the generators string powerset and bag e The void parameter is the address of a variable where the result should be placed This value is also returned e The tSDLTypelnfo parameter is the address to the type info node for the type to be created ec e denotes a list of addresses to the values for the components in the struct All parameters must be passed as addresses void re gardless if the component type should be passed as an address or as a value The only exceptions are the types represented as pointers themselves Charstring Ref Own ORef and syntypes of these types where the pointers are passed not
41. ODE 724 Jo TASK ENDDECISION In this case the sort of the decision cannot be resolved To overcome this problem the question could be written as DECISION TYPE integer CODE a Names and Prefixes in Generated Code When an SDL name is translated to an identifier in C a prefix is nor mally added to the name given in SDL This prefix is used to prevent name conflicts in the generated code as SDL has other scope rules than C and also allow different objects defined in the same scope to have the same name if the objects are of different entity classes It is for exam ple allowed in SDL to have a sort a variable and a procedure with the same name defined in a process So the purpose of the prefixes is to make each translated SDL name to a unique name in the C program A generated name for an SDL object contains four parts in the following order 1 The character z 2 A sequence of characters that make the name unique If the object is part of a package the package name will appear in this sequence ee 99 3 An underscore 4 The SDL name stripped from characters not allowed in C identifiers Sequence of Characters A C identifier may contain letters digits and underscore start with a letter ee 99 and must The sequence of characters that make the name unique is determined by the position of the declaration in structure of declarations in the system e Each declaration on a level is given
42. S MR TMP NF int 2 define XASS AR TMP_NF int The macro names above are all of the form XASS_1_2_ 3 where the ab breviations placed at 1 2 and 3 should be read e I AC always copy e 1 MR may reuse take pointer if temporary object e AR always reuse take pointer e 2 ASS new object assigned to variable e 2 TMP new object temporary e 3 FR call free for old value referred to by variable e 3 NF do not call free for old value The distinction between all these assignment possibility is only of inter est when handling types using or containing pointers Generic Equal Functions Each type in SDL has access to an equal macro yEqF_typename and an not equal macro yNEgF_typename Examples for type Boolean and for a user defined type A define yEgF SDL Boolean E1 E2 E1 E2 define yNEgF SDL Boolean E1 E2 E1 E2 define yEQgF_z3_A Exprl1 Expr2 yEq_z3_A Exprl1 Expr2 define yNEgF_z3 A Exprl1 Expr2 yEq_z3 A Expr1 Expr2 define yEq z3 A Exprl1 Expr2 GenericEqualSort void Expr1 void Expr2 tSDLTypeInfo amp ySDL_z3_ A July 2003 Telelogic Tau 4 5 User s Manual 2627 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2628 These macros are used in the generated code and in the kernel at each location where equality tests are needed The parameters to the equal and not equal macro are the two expressions that should be tested If C equal or n
43. SDL to C Compiler Generating a C Program 2568 A generated C program can be used for several things for example as a simulator as a validator or as an application with the behavior defined by the translated SDL system The process of generation of simulators validators or applications see below is started in the Organizer in the make dialog see Make on page 119 in chapter 2 The Organizer or by the quick buttons for simulation and validation see Quick Buttons on page 176 in chapter 2 The Organizer The SDL Analyzer which contains the C code generation facility can also be started as a stand alone tool For more information about this possibility please see The Analyzer Command Line UI on page 2404 in chapter 55 The SDL Analyzer Process of Generating a C Program There are four steps that must be performed to start the execution of for example a simulator 1 The SDL Analyzer and its built in Cadvanced Cbasic SDL to C Compiler create a program expressed in C source code 2 The generated C file or files is compiled 3 The compiled file or files is linked together with a predefined li brary 4 The executable program that is created in the link operation is start ed This process has been automated and requires no user knowledge about compiling or linking of programs The process is initiated in the Orga nizer using the quick buttons for simulation and validation or by using
44. SFER will still be implemented as a signal copy It may be possible in an OS integration to avoid the copying if the OS supports such actions Normally the TRANSFER directive should be used in the following way INPUT signall j OUTPUT signall TRANSFER That is receive none of the signal parameters in the input and retransmit the signal unchanged If you want to receive for example the second parameter in variable Var1 and retransmit the signal unchanged ex cept for parameter 3 that should have a new value 73 the following code can be used INPUT signall Varl j OUTPUT signall 73 TRANSFER Telelogic Tau 4 5 User s Manual 2671 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2672 Linking with Other Object Files Directive WITH Note This feature is only valid for SDL PR as input when the Analyzer is executed stand alone Similar features are available in the Orga nizer s Make dialog among the Generate makefile options see Generate makefile on page 122 in chapter 2 The Organizer You can tell the Cadvanced Cbasic SDL to C Compiler that a number of user defined and precompiled units should be linked together with a generated simulation program You do this in a WITH directive that should be placed in the system definition directly after the system head ing Example 392 WITH Directive System S WITH filel o file2 o Within the WITH direc
45. Str The type Str will be passed as an address so the parameter passing rules described previously have to be applied The function heading of the correspond ing C functions should be Telelogic Tau 4 5 User s Manual 2613 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2614 Example 361 Implementing an Operator extern Str Litl Str extern Str Lit2 Str extern Str Opl Str SDL Integer Str j extern Str Op2 Str SDL Boolean Str j The function bodies which should be supplied by the user if B is spec ified in the OP or ADT directive are ordinary C functions Example 362 Implementing an Operator Str Litl Str Result Result gt sa 2 Result gt b false Result gt c 10 0 return Result Str Opl Str P1 SDL Integer P2 Str Result Result P1 Result gt a Pl gt a P2 return Result Before it is possible to give a complete example of an abstract data type with implementation of its operators supplied as C functions it is nec essary to look at the problem of names When a name of some object in SDL is translated to C a suitable sequence of characters a prefix is added to the SDL name to make the name unique in the C program see also Names and Prefixes in Generated Code on page 2663 This strat egy is selected in the Cadvanced Cbasic SDL to C Compiler to avoid name conflicts in the generated code but it makes it also impossible to predict the full name of
46. String SDL Octet String a Object_identifier yEq_SDL Octet String yNEq_ SDL Octet String SDL_Object_Identifier mkstring xMkString SDL Object Identifier length xLength_SDL_ Object _Identifier first xFirst_SDL Object Identifier last xLast_SDL Object_Identifier xConcat_ SDL Object Identifier substring xSubString SDL Object Identifier yEq_ SDL Object Identifier yNEq_SDL_ Object Identifier NULL sort SDL_Null NULL literal SDL_NullValue yEq_SDL Null yNEq_SDL_ Null Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types C Definitions We will here discuss the types and macros supplied by the runtime li brary in the Cadvanced Cbasic SDL to C Compiler for the predefined types in SDL These macros and extern definitions for functions can be found in the file sctpred h except for the Pid sort which is handled in the file scttypes h Note For more information about the Charstring sort see the section Handling of the Charstring Sort on page 2618 Translation of Sorts The following data types are handled by the Cadvanced Cbasic SDL to C Compiler e Predefined Types e Enumeration Type e Struct e Choice e Array Bag Ref Own Oref e Syntypes e Inheritance Predefined Types All the predefined data types Integer Natural Boolean Character Charstring Real Time Duration
47. TURNS Str RETURN 2 false 10 0 OPERATOR Opl FPAR P1 Str P2 Integer RETURNS Str DCL Result Str Result P1 Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types Result a Pl a P2 RETURN Result OPERATOR Op2 FPAR P1 Str P2 Boolean RETURNS Str IF P2 RETURN P1 RETURN Litl ENDNEWTYPE Example 366 ADT Example OO SYNTYPE Index Integer CONSTANTS 1 10 ENDSYNTYPE NEWTYPE A Array Index Integer ADDING LITERALS Zero OP B OPERATORS Add A A gt A OP B Sum A gt Integer ADT BODY A Zero A Result SDL_ Integer i 0 GenericMakeArray Result tSDLTypeInfo amp ySDL_ A amp i return Result A Add A P1 A P2 A Result nt int I for I 1 I lt 10 I Result gt A I P1 gt A I P2 gt A I return Result ae ENDNEWTYPE Note that no body is supplied for the operator Sum as the default imple mentation strategy for operators which should be used for Sum is Q question The GenericMakeArray function used to implement the lit eral is a generic function that constructs array values The details for this function will be described later in this section For more information about the functions and types supplied by the runtime library in the Cadvanced Cbasic SDL to C Compiler and con Telelogic Tau 4 5 User s Manual
48. The last void parameter is the address to the value that should be assigned to all components of the array Generic Function for Operators in Pre defined Generators The generic function for the operators in the pre defined generators fol low the general rules for operators with a few exceptions e atype info node is needed as a parameter as the C function can han dle all instantiations of a certain generator e parameters of generator parameter types component and index types for example must in many cases be passed as addresses as the properties of these types are not known General array extern void GenGArray Extract xGArray_ Type void tSDLGArrayInfo extern void GenGArray Modify xGArray_Type void tSDLGArrayInfo e Parameter 1 The array e Parameter 2 The index value passed as an address Telelogic Tau 4 5 User s Manual July 2003 Abstract Data Types e Parameter 3 The type info node e Result The address of the component Powerset Generic functions available for powersets with a simple component type The powerset is represented a sequences of bits unsigned char Appropriate_Length define GenPow_ Empty SDLInfo Result memset void Result 0 SDLInfo gt SortSize extern SDL Boolean GenPow In int xPowerset_Type tSDLPowersetInfo extern void GenPow_Incl int xPowerset_Type tSDLPowersetInfo xPowerset_ Type extern void GenPow Del int xPowers
49. a number 0 1 2 9 a b Z Telelogic Tau 4 5 User s Manual 2663 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2664 e Ifthe number of declaration on a level is greater than 36 the se quence is 00 10 20 90 a0 z0 01 11 21 91 al zl Oz 1z 2z 9Z aZ ZZ e Ifthe number of declarations is greater than 36 36 then three char acter sequences are used and so on The total sequence making a name unique is now constructed from the declaration numbers for the unit and its parents that is the units in which it is defined starting from the top If for example a sort is defined as the 5th declaration in a block that in turn is the 12th declaration in the system then the total sequence will be b4 if not more than 36 declarations are present on any of the two lev els Example 386 Generated Names in Code Examples of generated names ie Position of the Declaration Generated Name Name S1 10th declaration in the system z9_S1 Var2 3rd declaration in the process which is the ze42_Var2 5th declaration in the block which is the 15th declaration is system There will also be other generated names using the prefixes If for ex ample a sort MySort is translated to za2c_MySort then the equal func tion connected to this type if it exists will be called yEq_za2c_MySort Prefixes Note If the OO diagram types in SDL 92 are used system ty
50. ameter of type void or xString_Type after type info node The address where the result should be stored This address is re turned by the function e Parameters of type tsDLGenListInfo The type info node e Other parameters According to SDL definition of parameters Limited String Generic functions available for limited strings i e strings with STRING directive giving a max size of the string These strings are implemented as an array in C define GenLString Emptystring SDLInfo Result memset void Result 0 SDLInfo gt SortSize extern void GenLString MkString void tSDLLStringInfo xLString Type define GenLString Length ST SDLInfo ST gt Length extern void GenLString First xLString Type tSDLLStringInfo void extern void GenLString Last xLString_1 tSDLLStringInfo void extern void GenLString Concat xLString Type xLString Type tSDLLStringInfo xLString Type extern void GenLString SubString xLString Type SDL_ Integer SDL Integer tSDLLStringInfo xLString Type extern void GenLString Append xLString_1 ype ype void Telelogic Tau 4 5 User s Manual 2633 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2634 tSDLLStringInfo extern void GenLString Extract xLString Type SDL_ Integer tSDLLStringInfo e Parameter of type void in GenLString_MkString GenString_Append Address of component value e Paramet
51. an array value is implemented by generic Make function in C String Instantiations of the predefined generator string can be handled by the code generator with the following restriction The component sort may be any sorts that the code generator can handle but may not directly or indirectly refer to the string type itself There are two translation schemes for Strings The directive STRING decide whether the string should be translated to linked list or to an ar ray For the STRING directive please see Alternative Implementa tions of the String Generator Directive STRING on page 2674 Strings are translated to linked list containing one element for each ele ment in the string value Operations and component selection in string sorts are fully supported Powerset Instantiations of the predefined generator powerset can be handled by the code generator with the following restriction The component sort may be any sorts that the code generator can handle but may not direct ly or indirectly refer to the powerset type itself Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types There are two translation schemes for powersets If the component sort fulfills the conditions for index sorts mentioned in the subsection about arrays above Array on page 2601 an array of 32 bit integers are used Each bit will be used to represent a certain element whether it is a member of the powerset o
52. anced Cbasic SDL to C Compiler 2572 simulated on its own because of these dependencies Block and process instantiations can be simulated but only using build scripts as such ob jects cannot be selected in the Organizer The discussion above is of course also valid for generation of validators and applications Unconnected Diagrams As another special case there might be unconnected diagrams in the Or ganizer i e objects not bound to a file If such an object is a block pro cess or a procedure C code can anyhow be generated resulting in for example a Simulator or Validator e Ifa block is unconnected this is treated as an implicit partitioning excluding this block e Ifaprocess is unconnected this is treated as an implicit partitioning excluding this process If other processes try to create such a pro cess this will become a null action just indicated in the textual trace In an application such a create action will cause a compilation error e Ifaprocedure is unconnected any call to this procedure is just indi cated in the textual trace In an application such a procedure call will cause a compilation error Build Scripts In general cases build scripts should be used to specify the build pro cess Using such a file there are a number of features that can be used e Itis possible to generate code for several partitions using indepen dent options and potentially different code generators for different
53. and will translate a call to such a proce dure to an ordinary C function call It is then up to the user to provide the C implementation of this function Note that the code generator will in the generated function call use the name of the external procedure as it is No prefix is inserted in this case just as for external synonyms External operators are handled in the same way as external procedures The name of the external operator is used in C just as it is A quoted op Telelogic Tau 4 5 User s Manual 2583 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2584 erator will cause an infix operator to be generated while operators with ordinary names will cause C function calls to be generated Any There are two different applications of any It is possible to write any SortName within an expression or to write just any in a decision The second case with any in a decision is implemented in the following way e Simulator A question in the monitor giving the user a possibility to select the path to follow e Validator The validator sees this as an non deterministic choice and selects all possible paths e Applications Should not be used The first case the any SortName within an expression is implemented using a random number generator to draw a random number of the given type Note any Sort where Sort is a syntype is only implemented if the syntype contains at most one range condition whic
54. art of the section Implementation of User Defined Operators on page 2609 Unfortunately it is not possible to have C comments within the code that is included in any directive as SDL and C use the same symbols for start and end of comments See also Example 360 on page 2613 which illustrates the possibility to use the C macro COMMENT CODE directives in compound statements CODE directives are recognized after a semicolon that ends a state ment of one of the following kinds e Output statement e Create statement e Set statement e Reset statement e Export statement e Return statement e Call statement e Assignment statement e Break statement e Continue statement e Empty statement Example 381 CODE i 4 41 i i 2 CODE i i 3 This example contains first an empty statement followed by a directive and then an assignment followed by a directive The empty statement can as above be used to insert CODE directives at places that other wise would not be possible like at the beginning of a compound state ment or directly after a compound statement Note that the code in the CODE directive is associated to the statement just before the directive and is included in the scope of that statement Telelogic Tau 4 5 User s Manual 2657 Chapter 57 The Cadvanced Cbasic SDL to C Compiler Example 382 if true i i 4 COD i i 5 PJ In this case the
55. at an index value is within its range in an array component selection Example 354 Syntypes SYNTYPE Syn integer CONSTANTS 0 10 ENDSYNTYPE SYNTYPE Syn2 integer Telelogic Tau 4 5 User s Manual 2603 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2604 CONSTANTS lt 0 2 gt 10 ENDSYNTYPE SYNTYPE Arri DEFAULT 2 ENDSYNTYPE Arr defined above Arr o is translated to typedef SDL Integer Syn typedef SDL Integer Syn2 typedef Arr Arrl Inheritance A type that inherits another type is translated to a type equal to the par ent type using a typedef Default Values Default values are fully supported for all sorts that the code generator can handle both if a default value is given in a sort definition and if an initial value is given in a variable definition DCL Default values will also be assigned to all variables and components which do not have a default value specified in SDL The reason for this is to avoid handling undefined variables in C which might give serious problems and unexpected behavior of an executing program The values selected by the code generator in such a case can be found below Note This is a deviation from SDL 92 It means that the generated pro gram does not handle the value undefined for any type If no default value is given in the sort and no start value is given in the data definition DCL for a variable the variable
56. at for an ordinary SDL 88 system that is not generated using separate units no information about the channels and signal routes are needed to direct signal to the correct receiver For more information about the possible optimizations in applications please see the compilation switch XOPTCHAN and the ADT PidLit The Data Type PIdLit on page 3180 in chapter 63 The ADT Library Please note that XOPTCHAN and PidLit is almost impossible to use if the SDL system contains system types block types or process types Telelogic Tau 4 5 User s Manual 2585 Chapter 57 The Cadvanced Cbasic SDL to C Compiler Abstract Data Types 2586 This section is a reference to the abstract data types The following top ics will be discussed e We will have a look at the implementation of the predefined data types in SDL see SDL Predefined Types on page 2588 We then discuss how user defined abstract data types are translated see Translation of Sorts on page 2595 e Next implementation of operators and the possibility to include hand coded C functions as implementation of the operators is pre sented see Implementation of User Defined Operators on page 2609 e Last in More about Abstract Data Types on page 2634 we dis cuss more details about operators and the possibilities to include a hand coded type definition in C to represent the SDL sort Removing un used SDL Operators When implementing an SDL sy
57. ated memory to the pool of available memory and assign 0 to the pointer Telelogic Tau 4 5 User s Manual July 2003 Abstract Data Types Extract and Modify This entry specifies how component selection struct components array components for example should be performed In SDL a component can be selected in two ways Variable Component Variable Index An Extract operation can be generated in four ways Variable Component used for struct and UNIONC Variable U Component used for UNION and choice Variable A Index used for array yExtr_SortName Variable Expr The last version the Extract function is used for all other cases Type Interpretation X B Use Extract function X G Use component selection according to table above X Same as X B Same as X G A Modify operation can in the same way be generated in four ways Variable Component used for struct and UNIONC Variable U Component used for UNION and choice Variable A Index used for array yAddr SortName amp Variable Expr The last version the Addr function is used for all other cases Type Interpretation M B Use Addr function M G Use component selection according to table above M Same as M B Same as M G July 2003 Telelogic Tau 4 5 User s Manual 2639 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2640 Read and Write Function The write fun
58. ation is created macro definitions should be used for all external synonyms as the function for reading synonym values stored on file is not available See below Reading Values at Program Start up The other way to supply the values of the external synonyms is to read the values at program start up If there are any external synonyms that do not have a corresponding macro definition it is possible to choose between supplying the values of the remaining external synonyms from the keyboard or to use a file containing the values When the application is started the following prompt appears External synonym file e Press lt Returns gt to indicate that the values should be read from the terminal e Or type the name of a file that contains the values and press lt Return gt If the user chooses to read the values from the terminal he will be prompted for each value In the other case the user should have created a file containing the external synonym names and their corresponding value according the following example Example 341 Values at Program Startup synonyml valuel synonym2 value2 The synonyms may be defined in any order Telelogic Tau 4 5 User s Manual 2581 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2582 Import Export These concepts are not implemented with the full semantics according to the model in the SDL recommendation The model says that an im ported value should be obtained usin
59. be generated If for example the user has specified that a block and a sub block should be generated on the Telelogic Tau 4 5 User s Manual 2569 Chapter 57 The Cadvanced Cbasic SDL to C Compiler same file it is not possible to regenerate code only for the sub block e If the file structure is changed by for example changes in the Edit Separation command or in the SEPARATE directives then the complete system is regenerated Errors During Code Generation Errors that may occur during code generation are internal errors That is errors due to not yet implemented features of SDL and errors related to problems with opened or closed operations of files An error message starts with an SDT references and is followed by a de scription of the error including a error number Example ERROR 884 Not implemented Signal refinement 2570 Telelogic Tau 4 5 User s Manual July 2003 Features Features July 2003 Partitioning General Ideas The partitioning concept is a way to divide one SDL system into several applications As a special case this means also that it is possible to sim ulate and validate selected parts of a system You should note the differ ence between partitioning and separation The partitioning feature is a way to select the parts of an SDL system which should be handled while the separation feature is a way to select the file structure for the generated files To select a partition or a progra
60. below can also be useful while implementing Read func tion xPromptQuestionMark is suitable to obtain prompt in a similar way as for SDL defined sorts while xReadOneParameter can be used to read element for element in a list separated by commas and terminat ed either by or T The function xReadSort is similar to xWriteSort and can be used to read a component in the treated sort xPromptQuestionMark extern xxToken xPromptQuestionMark char Prompt char QuestionPrompt char strVar The function result and the parameter strVar behave in the same way as for the function xScanToken see above The parameter Prompt is the prompt that should be used This string has to start with a i e a space To conform with other built in read function the Prompt parameter Telelogic Tau 4 5 User s Manual 2643 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2644 should be SortName note the ending space colon space The QuestionPrompt parameter should either be identical to the Prompt pa rameter or be null i e char 0 If QuestionPrompt is null the xPromptQuestionMark function will return xxEoln if a end of line is found If QuestionPrompt is not null the xPromptQuestionMark func tion will print the QuestionPrompt and continue to read Normally QuestionPrompt should be equal to Prompt in a simple data type while it should be null in a structured data type Example 372 ADT Example Byte Type
61. ble If possible this is performed by the function memcpy otherwise special code depending on the kind of type is executed 3 The IsAssigned flags are set up for the variable according to the properties of the assignment Special treatment of Charstring and instantiations of the Own generator has made it necessary to introduce specific wrapper functions that in their turn call GenericAssignSort for these types extern void xAss SDL Charstring SDL _Charstring SDL Charstring int extern void GenOwn_ Assign void void int tSDLTypeInfo July 2003 Telelogic Tau 4 5 User s Manual 2625 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2626 An GenericAssignSort function must consider the following questions in order to handle the objects correctly How should one copy the object This is very important because performing the wrong action will lead to memory leaks or access errors Three different possibilities exist e AC always copy the referenced object e AR always copy the pointer i e reusing the referenced object e MR copy pointer if the object is temporary or copy object if not temporary What should be the status of the new object This is a preparation for the next operation on this object so the correct decision can be made according to the first question Two different pos sibilities exists e ASS an object should become assigned if it is assigned to a variable and needs to be copied in f
62. ced Cbasic SDL to C Compiler 2636 Type Interpretation T Same as T B Same as T G Assignment It is possible to select how assignments should be performed for values of the type Note that all generated assignments will be of the form yAssF_ SortName The yAssF_ SortName is a macro either implemented as assignment or as a call to the yAss_ SortName function if such function is to be used i e as define yAssF_ S V E A V E define yAssF S V E A yAss_ S amp V E A Type Interpretation A B Use and generate heading but not body of yAss_ S A H Use but generate no code for yAss_ S A G e If the type definition is generated Use if possible Otherwise use the GenericAssignSort function e If type definition is not generated T T B Use A S Use A Same as A B Same as A G If you define your own assign function it must be implemented as a function as the address of the function will be stored in the type info node for the data type so GenericAssignSort can call it to handle sub components of this type An assign function has the following heading void yAss_ SortName SortName yVar SortName yExpr int AssType Telelogic Tau 4 5 User s Manual July 2003 Abstract Data Types July 2003 It should assign the value passed as second parameter to the variable passed as f
63. cess or procedure heading see the following example Example 379 SEPARATE Directive system S SEPARATE filename block B SEPARATE process type Pl inherits PType SEPARATE process P2 1 SEPARATE procedure Q SEPARATE In the example above the two versions of separate directive with or without file name are shown As can be seen a file name should be en closed between quotes The code generator will append appropriate ex tensions to this name when it generates code If no file name is given in the directive the name of the system block process or procedure will be used to obtain a file name In such case the file name becomes the name of the unit with the appropriate extension c h depending on contents The file name is stripped from charac ters that are not letters digits or underscores The possibility to set up full user defined or no separation in the Orga nizer s Make dialog and in the user interface of a stand alone Analyzer see The Analyzer Command Line UI on page 2404 in chapter 55 The SDL Analyzer can be used in simple manner to select certain de fault separation schemes This setting will be interpreted in the follow ing way e No separation The system and each package will be generated on a separate file e User defined separation The system each package and each unit that the user has specified as separate will bec
64. contained in the include file must be performed by the user Directive REF Note This directive is provided only for backward compatibility The SDL suite now supports in out parameters for operators which serves exactly the same purpose In out parameter is an SDL 2000 extension and is supported also in operator diagrams The directive REF can be used to specify that the address not the val ue of a variable should be passed as parameter to an ADT operator as it is defined in SDL This feature cannot be used for operators defined in operator diagrams the directive will be ignored for such operators The REF directive is used as shown in the example below Example 375 Including a File in ADT operators eql Integer Integer gt Integer eq2 Integer REF Integer REF gt Integer The headings for these two operator will become in ANSI C syntax ig noring prefixes extern SDL Integer eql SDL Integer P1 SDL Integer P2 extern SDL Integer eq2 SDL Integer P1 SDL_ Integer P2 j This feature can be used to optimize parameter passing to operators The directive however also imposes the restriction that the actual parame ters must be a variable or a formal parameter see Example 376 below Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types This is checked by the code generator A REF directive does not in any way effect the way a operator call should be implemented
65. ct would not any longer be valid There are some extensions to SDL that are handled by the code genera tor It is possible to define bit fields i e to define the size of components as in C and to have optional components and components with initial values as in ASN 1 Examples are shown below Example 348 Struct with bit fields NEWTYPE str STRUCT a Integer 4 b Integer 4 c UnsignedInt 2 d Integer ENDNEWTYPE is translated to typedef struct str_s SDL_ Integer a 4 SDL_Integer b 4 int 0 UnsignedInt Ci se 2G SDL Integer d July 2003 Telelogic Tau 4 5 User s Manual 2597 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2598 str Note that only Integer and UnsignedInt should be used in bit field com ponents Example 349 Struct NEWTYPE str STRUC a b integer c Boolean OPTIONAL d str2 OPTIONAL e Charstring telelogic f arrg s 5 Li 2 ENDNEWTYPE is translated to typedef struct str_s SDL Integer a SDL Integer b SDL Boolean c SDL_ Boolean cPresent str2 d SDL_ Boolean dPresent SDL _Charstring e SDL Boolean ePresent arr3 f SDL_ Boolean fPresent str Both optional components and components with initial values have a Present flag This is according to ASN 1 and the translation of ASN 1 to SDL defined in Z 105 The present flag for a component with initial value is true if the component contains its
66. ction Otherwise the value can only be read as a HEX string Note that the run time kernel can automatically handle all SDL sorts for which the code generator generates the C type definition A read function should look like extern int yRead_SortName void Result A read function is given an address to store the value that is read It should return 1 if the read operation was successful Otherwise 0 should be returned and Result should be unchanged Telelogic Tau 4 5 User s Manual 2641 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2642 There are some suitable functions in the run time kernel which can help you when you are implementing a read function Basically the function xScanToken described below is a tokenizer that transforms sequences of characters to tokens This function returns tokens according to the following enum type typedef enum xxId xxString xxSlash xxColon xxMinus xxPlus xxStar xxComma xxSemicolon xxArrowHead xxLPar xxRPar xxLParDot xxRParDot xxLParColon xxRParColon xxDot xxLBracket xxRBracket xxLCurlyBracket xxRCurlyBracket xxAt xxQuaStart xxQuaEnd xxLT xXxLE xxGT xXXGE xXxXEQ xXxNE xxQuestionMark xx2QuestionMark xxExclMark xxSystem xxPackage xxBlock xxProcess xxProcedure xxOperator xxSubstructure xxChannel xxSignalroute xxType xxNull xxEnv xxSelf xxParent numbers SDL Charstring l
67. ction is used by the monitor system to write values of the type Type Interpretation W B Generate heading but not the body of a write function W H Generate neither heading nor body of a write function but assume that the user has provided such a function W S _ Values of this type are to be printed as a HEX string No write function is assumed to be present W Same as W B Same as W S The read function is used by the monitor system to read values of the type Type Interpretation R B Generate heading but not the body of a read function R H Generate neither heading nor body of a read function but assume that the user has provided such a function R S Values of this type are to be read as a HEX string No read function is assumed to be present R Same as R B Same as R S In order to examine variable values for variables that are of a sort that is implemented in C i e has ADT T in its ADT directive it is neces sary to implement a write function Otherwise the value can only be pre sented as a HEX string Note that the run time kernel can automatically handle all SDL sorts for which the code generator generates the C type definition A write function should look like extern char yWri_SortName void Value Given the address of a value of the type SortName this function should return a char i e a character string containing the value represented
68. d 1 is the first actual generator parameter e 2 and 2 is the second actual generator parameter e and so on 1 and 1 are equal except when the corresponding actual generator parameter is a struct or union In that case assuming the SDL struct Telelogic Tau 4 5 User s Manual 2647 Chapter 57 The Cadvanced Cbasic SDL to C Compiler newtype aaa struct a b integer endnewtype which will be generated as typedef struct aaa_s SDL Integer a SDL _ Integer b aaa 1 will become struct aaa_s Ofunion aaa_s if a union while 1 will become aaa Example 377 Example of User Defined Generator GENERATOR Ref TYPE Itemsort LITERALS Null OP S OPERATORS Ref2VStar Ref gt VoidStar OP HP DEFAULT Null ADT INSTTYPE typedef 1 0 INSTHEADING define Null o define Ref2VStar P VoidStar P ENDGENERATOR Ref Note the usage of INSTTYPE and INSTHEADING in the example above The code in these section will be inserted in each newtype de fined with this generator For example in a newtype NEWTYPE p Ref Integer ENDNEWTYPE The INSTTYPE section will become typedef SDL Integer p 2648 Telelogic Tau 4 5 User s Manual July 2003 Directives to the Cadvanced Cbasic SDL to C Compiler Directives to the Cadvanced Cbasic SDL to C Compiler Syntax of Directives The Cadvanced Cbasic SDL to C Compiler recognizes
69. de is to give the user the possibility of introduc ing a macro with the same name as the signal where the implementation of the output is expanded to in line code By just having a compilation switch which selects if this macro is visible or not the same generated code can be used both for simulation and for highly optimized applica tions An appropriate switch is probably XENV which governs the nor mal way of connecting an SDL system to the environment July 2003 Telelogic Tau 4 5 User s Manual 2669 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2670 Example 391 CODE Directive The following CODE directive can be included in a text symbol in the system diagram assuming a signal called SigName with one parame ter CODE TYPE ifdef XENV define EXT SigName Name IdNode ToExpr Parami suitable macro code endif The other two directives ALT and TRANSFER can be used together with appropriate real time operating systems to have two different in terpretations of an output internal or external output for example and to specify that a received signal should be immediately retransmitted TRANSFER These kinds of features are not uncommon in real time operating systems and can be modeled and simulated by the Cad vanced Cbasic SDL to C Compiler using these directives Both these di rectives should be placed last in the output symbol The presence of an ALT directive will be reflected in the
70. default value otherwise false the Present flag is used to determine code for some ASN 1 encoding scheme The present flag for an optional component is false until the component is assigned a value In SDL the present flags can only be ac cessed through operators and cannot be changed Union Please see also the CHOICE concept presented below as it usually pro vides a better and more secure solution to the same kind of problems Using the directive UNION see example below it is possible to tell the Cadvanced Cbasic SDL to C Compiler to generate a union accord ing to the following example Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types Example 350 Union NEWTYPE Str UNION STRUCT tag integer a integer b Boolean c real ENDNEWTY PE is translated to typedef struct SDL_ Integer tag union SDL Integer a SDL Boolean b SDL Real c U Str The first component in the struct is assumed to be a tag value indicating which of the union components that are active The tag should either be integer or an enumeration type Tag value 0 or first enumeration literal is used to indicate that the first of the remaining components are active and so on On the SDL level a UNION struct should be handled just like any other struct It is up to the code generator to generate the correct code for operations on the struct like assignment test for equality com ponent selection
71. e behavior of the processes in the system is of little or no interest In the internal view the internal be havior of the system specification is of concern while the external sig nal interface is simply seen as part of the internal behavior A simulation of the internal behavior of a system specification consti tutes an important part of the validation of the specification both as a debugging tool and as a means to increase the understanding of the dy namic behavior of the specification A designer of a system might use this kind of simulation to understand the specification better The ability to simulate and debug applications generated by the code generator at an SDL level is a very important feature towards achieving the correct overall behavior of the application The debugging facilities provided by the SDL suite have much in common with interactive de buggers for ordinary programming languages The debugging is per formed on a host computer Another application of the code generator as a simulator generator is of course in SDL education where simulation especially of the internal behavior of a system specification can serve as a powerful way of clar ifying the semantics of SDL concepts Performance Simulation The Cadvanced Cbasic SDL to C Compiler can be used for perfor mance simulations You describe the performance model of the actual system using SDL This model can be translated to a simulation and ex ecuted By in
72. e specified in the Organizer Edit Separation command see Edit Separation on page 136 in chapter 2 The Or ganizer or in the SEPARATE directive if two units in the system have the same name in SDL and should both be generated on sepa rate files otherwise the same file name will be used for both units Telelogic Tau 4 5 User s Manual 2653 Chapter 57 The Cadvanced Cbasic SDL to C Compiler Accessing SDL Names in C Code Directive SDL When writing C code that is to be included in a generated program it is often necessary to refer to names of objects defined in SDL The name of an SDL object is however transformed when it is translated to C A prefix which is a sequence of characters is added to the SDL name to make the C name unique in the C program Furthermore all characters in SDL name which are not allowed in a C name are removed The pre fixes are calculated by looking at the structure of definitions in the ac tual scope and in all scopes above This means that adding a declaration at the system level might change all prefixes in blocks and processes contained in the system As a consequence it is almost impossible to know the prefix of an object in advance To be able to write C code and use the name of SDL objects in that code the Cadvanced Cbasic SDL to C Compiler provides the directive SDL which is used in C code to translate an SDL name to the corresponding C name The syntax of the SDL directive is as
73. eal time operating systems The directive EXTSIG is used to replace the code for an SDL output with any appropriate in line C code This is an optimization and an al ternative to the OutEnv function see chapter 58 Building an Applica tion The EXTSIG directive can be specified e Last in an output symbol in PR just before the Telelogic Tau 4 5 User s Manual July 2003 Directives to the Cadvanced Cbasic SDL to C Compiler e Just before the or ending the definition of a signal In the first case the EXTSIG is valid for the signal s sent in the output symbol and in the second case for all outputs of the defined signal Example 390 EXTSIG Directive signal Signall EXTSIG Signal2 integer EXTSIG output Signal3 To Sender EXTSIG For each output of a signal with a EXTSIG directive in either way de scribed above the following code is generated ifndef EXT _SignalName the normal implementation of an output else EXT_SignalName SignalName ySigN SignalNameWithPrefix ToExpression SignalParameters endif where SignalName is the name of the signal in SDL The parameter ToExpression is a translated version of the SDL expression after TO in the output If no TO expression is given in the output this parameter will be xNotDefPld The entry SignalParameters will be replaced by the list of signal parameter values given in the output The intention of this co
74. ective with Parameter Value NEWTYPE Example String STRING 100 string integer empty constants size 0 10 ENDNEWTYPE In this example the string will be implemented as an array with the length of 100 The parameter value in the STRING directive overrides the size constant which in this case is redundant Telelogic Tau 4 5 User s Manual 2675 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2676 Size constraint The size constraint is decided by adding a constant in the NEWTYPE definition The following declarations are valid when defining a maxi mum size of the string constants size a b constants size a constants size a constants size lt a constants size lt a Differences between the Implementations Methods The different implementation methods affect the behavior and perfor mance of the generated code The following general statements apply to the methods e The performance of the array implementation is usually better than that of the linked list implementation e Ifthe number of string values are equal to or close to the maximum string length the array implementation is smaller e Ifthe number of string values are substantially smaller than the maximum string length the linked list requires less memory e The linked list requires memory allocation while the array does not Selecting implementation Methods It is of course hard to advice which method to select but the fo
75. ee which operators that are unused SDL Predefined Types Mapping Table Below is a table which summarizes the mapping rules between SDL and C concerning the predefined types in SDL and their operators Note that many of the operators are in C defined as macros and expanded by the C preprocessor to simple operators in C SDL name operator C name expression operator Boolean SDL Boolean False True SDL False SDL True not xNot_SDL_ Boolean and xAnd SDL Boolean or xOr_ SDL Boolean xor xXor SDL Boolean gt xImpl_ SDL Boolean yEgF SDL Boolean yNEqF_SDL_ Boolean 2588 Telelogic Tau 4 5 User s Manual July 2003 Abstract Data Types SDL name operator C name expression operator Character SDL Character NUL SDL_NUL SOH SDL SOH for all unprintable characters ral ral 1 b 1 b d for all printable characters except and peer NY NEE ENNA chr xChr SDL Character num xNum_SDL_ Character lt lt gt gt xLT_SDL Character xLE SDL Character xGT_SDL_ Character xGE SDL Character xEqF SDL Character xNEQF SDL Character Charstring SDL_Charstring aa SDL_CHARSTRING LIT Laa aa mkstring xMkString SDL _Charstring length xLength_SDL_Charstring first xFirst_SDL Charstring last xLast_SDL_ Charstring xConcat_SDL_Charstring substring xSubString SDL Chars
76. er of type void or xLString_Type after type info node The address where the result should be stored This address is returned by the function e Parameters of type tSDLLStringInfo The type info node e Other parameters According to SDL definition of parameters More about Abstract Data Types Including Type Definitions Note Use the features presented in this section with care The features were developed early in the SDL suite history Now in principle ev ery data type in C can be expressed in SDL as well Therefore the recommended method is to write the types in SDL or to translate C types to SDL using the cpp2sdl tool History has also shown that it has been difficult to keep full back ward compatibility for these features and at the same time improve the performance of the generated code This of course comes from that these features is highly dependent on the way code is generated In this subsection the inclusion of a type definition in the target lan guage for an abstract data type will be described When this facility is used it is necessary to specify how to perform assignment test for equal assign default values and so on as it is not possible to generate when the type definition is not known not generated All this informa tion is given in the ADT directive which has the following structure ADT T x A x E x F x K x X x M x W x R x xy file name TYPE C code HEADING C code
77. eractive routines describe above e B body This specifies that the code generator should generate the heading of the operator and literal functions while the user must supply the bodies of the functions Note The C functions are divided into a function heading extern or static declaration and a function body An example of a function heading extern declaration is Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types Example 357 Implementing an Operator extern SDL Integer Max SDL_Integer Paral SDL Integer Para2 while the corresponding function body is SDL _ Integer Max SDL_Integer Paral SDL Integer Para2 if Paral gt Para2 return Paral return Para2 The main reason for this division of functions into heading and body is the separate compilation scheme used in C If for example an abstract data type is defined in a system and used in a process in the system and the process is generated on a separate file then there has to be a module interface file a h file for the system containing the external interface types extern declarations of functions and so on The interface file should then be included in the file generated for the process Even if separate compilation is not used the division of functions into heading and body is useful By having static declarations of the func tions the order in which functions must be defined is relaxed If static declaration
78. erset The reason for this is that the length of the array cannot de pend on a variable in C External Synonyms External synonyms can be used to parameterize an SDL system and thereby also a generated program The values that should be used for the external synonyms can either be read by the generated program during start up or included as macro definitions into the generated code The Cadvanced Cbasic SDL to C Compiler can handle both these cases it is not necessary to select which way should be used for each synonym until the program is compiled Using a Macro Definition To use a macro definition in C to specify the value of an external syn onym perform the following steps 1 Write the macro definitions on a file Example 339 Macro Definition define synonyml valuel define synonym2 value2 The synonym names are the SDL names without any prefixes and with any character not in letters digits or underscore removed 2 Introduce the following CODE directive at the system level among the SDL definitions of for example synonyms sorts and signals but before any use of the synonyms Telelogic Tau 4 5 User s Manual July 2003 July 2003 Implementation Example 340 CODE Directive CODE TYPE include filename If this structure is used the value of an external synonym can be changed merely by changing the corresponding macro definition and recompiling the system Note When an applic
79. et_Type tSDLPowersetInfo xPowerset_Type extern void GenPow_Incl2 int xPowerset_Type tSDLPowersetInfo extern void GenPow Del2 int xPowerset Type tSDLPowersetInfo extern SDL Boolean GenPow_LT xPowerset_Type xPowerset Type tSDLPowersetInfo extern SDL Boolean GenPow_LE xPowerset_Type xPowerset Type tSDLPowersetInfo extern void GenPow_And xPowerset_Type xPowerset Type tSDLPowersetInfo xPowerset_ Type extern void GenPow_Or xPowerset Type xPowerset Type tSDLPowersetInfo xPowerset_Type extern SDL Integer GenPow_ Length xPowerset_Type tSDLPowersetInfo extern int GenPow Take xPowerset_Type tSDLPowersetInfo extern int GenPow Take2 xPowerset_ Type SDL Integer tSDLPowersetInfo e Parameter of type int in GenPow_In GenPow_Incl GenPow_Del GenPow_Incl2 GenPow_Del2 A component val ue e Result of type int in GenPow_Take GenPow_Take2 A compo nent value e Parameters of type tsDLPowersetInfo The type info node e Parameters of type xPowerset_Type after the type info node The address where the result should be stored This address is re turned by the function e Other xPowerset_Type parameters Powerset in parameters July 2003 Telelogic Tau 4 5 User s Manual 2631 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2632 Bag and General Powerset The following generic functions are available for bags and power
80. exts e After the last assignment statement or informal text e Immediately after the ending semicolon of a task this position is only available in SDL PR The C code in the directives is textually included in the generated code at the position of the directive If for example a code directive is placed between two assignment statements the code in the directive is inserted between the translated version of the assignment statements Note The Cadvanced Cbasic SDL to C Compiler handles the C code in di rectives as text and performs no check that the code is valid C code The code directive is included as a facility in the code generator to pro vide experienced users an escape possibility to the target language C This increases the application range of the code generator An example of a possible use of the code directive is An algorithm for some computation which in the SDL description is only indicated as a task with an informal text could be implemented in C In this case the directive SDL described in the previous subsection will probably be come useful to access variables and formal parameters defined in SDL Telelogic Tau 4 5 User s Manual July 2003 Directives to the Cadvanced Cbasic SDL to C Compiler July 2003 Some general hints on how to write C code that can be included into a simulation program especially when charstrings or sorts containing charstrings as components are used can be found in the last p
81. g a signal interchange between the importer and exporter In the Cadvanced Cbasic SDL to C Compiler we use a model where the imported value is directly obtained from the exporter which of course makes the import operation much faster However the scheduling effect of the signal interchange is lost as well as the change of SENDER in the involved processes If these effects are important for an application remote procedure calls can be used instead see below Remote Procedure Calls Remote procedure calls RPC have much in common with import ex port except that instead of obtaining one value RPCs give the opportu nity to execute a procedure in the exporting process In the Cad vanced Cbasic SDL to C Compiler the model described in the SDL rec ommendation is used in detail to implement RPCs This means that a remote procedure call is translated to output of pCALL signal with all parameters nextstate in pWAIT i e a implicit wait state input of pREPLY signal with all IN OUT parameters In the exporting process there will be implicit transitions where the pCALL signal can be handled input pCALL call remote procedure with parameters from pCALL output pREPLY with the IN OUT parameters nextstate For more details about this model please see the SDL recommendation Procedure Calls and Operator Calls In SDL 92 value returning procedures and remote procedures are in troduced This means that an SDL procedure can be
82. generated code in the way described below e If no directive is used the following macros will be present in gen erated code for sending a signal SDL_2OUTPUT used when the receiver is known SDL_2OUTPUT_NO_TO used when the receiver has to be calculated during runtime SDL_2OUTPUT_COMPUTED_TO used when the receiver is calculated during code generation e Ifan ALT directive is given these macros are replaced by SDL_ALT2OUTPUT SDL_ALT2OUTPUT_NO_TO SDL_ALT2OUTPUT_COMPUTED_TO In the Master Library the macros with and without ALT are expanded identically In an OS integration they might be handled differently to implement two classes of signal sending The presence of a TRANSFER directive indicates that a signal should be directly retransmitted to some other receiver This can of course be Telelogic Tau 4 5 User s Manual July 2003 Directives to the Cadvanced Cbasic SDL to C Compiler July 2003 performed in SDL by an input output but then it is necessary to create anew signal and copy the contents of the received signal to the new sig nal Using the TRANSFER directive this copying can be avoided In generated code the macros e ALLOC_SIGNAL e ALLOC_SIGNAL_ PAR are generated to allocate the data area for a new signal If a TRANS FER directive is present in the output statement these macros are re placed by e TRANSFER_SIGNAL e TRANSFER_SIGNAL_PAR Note In the master library TRAN
83. gned in SDL Some examples of use are also available In chapter 64 The Performance Library you may read about how to generate and run simulators which are specially adapted for the area of performance simulation Telelogic Tau 4 5 User s Manual 2561 Chapter 57 The Cadvanced Cbasic SDL to C Compiler Introduction 2562 Application Areas for the Cadvanced Cbasic SDL to C Compiler There are a number of application areas for the Cadvanced Cbasic SDL to C Compiler for example e Functional simulation and debugging of protocol specifications e Debugging of system designs described in SDL e Generation of applications including embedded system applica tions with real time characteristics e Performance simulations e Simulation of the behavior behind a user interface prototype In this part of the manual the general behavior of the code generator and its application for simulation and debugging are discussed The possi bility to generate simulators is described in chapter 50 The SDL Simu lator Functional Simulation and Debugging During the validation of a specification or design of an application ex pressed in ITU SDL you can use the Cadvanced Cbasic SDL to C Com piler as a tool for simulation to help you understand and debug the be havior of a system description See chapter 50 The SDL Simulator Errors arising from two different areas have to be considered in the val idation process In the language doma
84. h is of the form a b that is one limited range If it is a syntype of a real type e g Real or Time with a range condition it is not implemented If any SortName is used for a sort violating the note above there will be a C compilation error on the symbol ANY_SortName WithPrefix This means that a user can implement any for such sorts himself by de fining a C macro with this name that implements any for the given sort Such a macro should be inserted in the TYPE section of a ADT direc tive in the syntype Telelogic Tau 4 5 User s Manual July 2003 July 2003 Implementation Calculation of Receiver in Outputs The Cadvanced Cbasic SDL to C Compiler contains an algorithm that calculates the receiving process instance set for outputs without TO considering channels signal routes connection points and via list There are however a few restrictions for the algorithm e Outputs in process types or in processes in block types or system types cannot be handled The reason is that the same output might lead to different receivers in different instantiation e Paths channels signal routes that lead into other units that are separate see Edit Separation on page 136 in chapter 2 The Orga nizer cannot be followed by the algorithm as that would violate the separate generation scheme e Outputs in global procedures cannot be handled as the receiver de pends on the caller of the procedure This algorithm means th
85. he time in the simulation has no connection with the wall clock Instead the discrete event simulation technique is used This tech nique is based on the idea that the current value for the simulation time Now in SDL is equal to the time at which the currently executing event is scheduled After one event is finished the simulation time is in creased to the time when the next event is scheduled and this event is started Events in SDL will be process transitions timer outputs and signals sent to the system from the environment As an example the use of the discrete event simulation technique means that if the next event is a timer output scheduled one hour from now and the next transition is allowed to execute the timer output will occur immediately The sim ulation time will be increased by one hour but the user does not have to wait one hour Real Time If real time is used then there will be a connection between the clock in the executing program and the wall clock In the example above the user would have to wait one hour until the timer output took place To im plement real time a clock function provided by the operating system is used Not all systems are suitable to simulate in this way The time scale in the system ought to be seconds or maybe minutes not milliseconds and not hours Telelogic Tau 4 5 User s Manual July 2003 July 2003 Implementation At program start up the system time SDL Now is zero The system cl
86. his means that all enum types will be int types except if the macro XENUM_TYPE is redefined by the user to unsigned char for example An enum type with 256 or more values will always be of type int and will not be affected by the macro XENUM_TYPE E Struct An SDL struct is translated to a struct in C as can be seen in the example below Example 347 Struct NEWTYPE Str STRUCT a Integer b Boolean c Real ENDNEWTYPE 2596 Telelogic Tau 4 5 User s Manual July 2003 Abstract Data Types is translated to typedef struct SDL Integer a SDL Boolean b SDL Real c Str All the properties of a struct in SDL are preserved in the C code The predefined operators extract and modify are implemented as com ponent selections in the struct in the same way as in SDL that is if S is a variable of type Str then S a in SDL is translated to S a in C The predefined operator make which is a constructor of a struct value is implemented by generating a Make function in C This means that the expression 12 true 0 22 in SDL is in principle translated to the C function call Make 12 true 0 22 The components of a struct may be of any sort that the code generator can handle A component may however not directly or indirectly refer to the struct sort itself As an example the sort Str above may not have a component of sort Str In such a case the translation to aC stru
87. his program using an ordinary C compiler and link it with a predefined SDL run time library to form an executable pro gram See Figure 489 As indicated above the C code generation facility contains two compo nents e The SDL to C Compiler which can be seen as a back end to the SDL Analyzer This component generates a C program e Predefined and precompiled C units which implement an SDL runtime library and the command line user interface of a simula tor that is a monitor system The run time library also includes a communication mechanism which makes it possible to trace the execution of SDL transitions in the SDL Editor There are several versions of the library that are suitable to different application areas for the generated C code see Libraries on page 2698 in chapter 58 Building an Application July 2003 Telelogic Tau 4 5 User s Manual 2565 Chapter 57 The Cadvanced Cbasic SDL to C Compiler Generated Predefined runtime library and monitor SDL Progam system for SDL SDL specification Analyzer and Code Generator C system Executable program Figure 489 The production of an executable program Executing a C Program as a Simulator The generated C program uses an internal data representation of the SDL objects in the system for example process instances and signal in stances The process instances will execute transitions in a quasi paral lel manner During a transition
88. his value using an assignment statement e else if the type of the variable has a default value the variables are assigned this value using an assignment statement e else the variable is set to 0 using memset If 0 is not an appropriate initial value the function GenericDefault is called to initialize the variable Examples of types where 0 is not an appropriate value are structs with components with initial values Object_identifiers Strings general Powersets Bags and general Arrays As yDef functions macros do not exist in Generic mode all usage in in line C code must be changed There are several possibilities First de cide if assigning a default value is really necessary If it is necessary then some of the following principle solutions might be used e memset to 0 e GenericDefault amp variable tSDLTypeInfo amp ySDL_typename e yAss_typename variable expression XASS_MR_ASS_NF e direct C assignment if possible Telelogic Tau 4 5 User s Manual July 2003 July 2003 Migration Guide for Generic Functions Make Functions The yMake_typename function from the non generic mode is no longer used or generated All calls in inline code to yMake functions must be replaced by calls to proper GenericMake functions as described in Ge neric Make Functions on page 2629 Note yMake functions pass component values as values while Generic Make functions pass component values as addresses Operato
89. iable should only be used to represent some common property of all the process instances To have a variable that is local to a process instance the variable should be defined in SDL using DCL In the generated code the type sections are included in the order of ap pearance in SDL However the type sections are also sensitive for their relative position comparing with SDL sort definitions This means that the order of the type definitions in the system in the example above will be as follows 1 Type sections in 1 2 3 2 Type generated for newtype n 3 Type sections in 4 12 As the Cadvanced Cbasic SDL to C Compiler will generate the SDL sorts in the correct order definition before usage in C the full algo rithm is as follows e Step through all definitions in SDL in the order of appearance and include the type section of CODE directives and ADT directives generate typedef for a sort that have no reference to some other not yet generated sort e Step through all sorts that have not been generated checking wheth er each sort references some other sort that has not been generated If a sort does not reference some other un generated sort it requires typedef generation e Repeat the previous step until all sorts have been generated or until no more sorts can be generated If sorts remain not generated at this step a recursive dependency has been detected The heading sections are placed in the order of their appea
90. ically correct SDL expressions During code generation the code generator will just copy the Charstring parameter at the place of the CODE operator Example 384 CODE Directive Suppose that x and y are SDL variables which are translated to z272_x and z73_y that a and b are C variables and f is a C function defined in CODE directives SDL expression C expression x CODE a z72 x a x CODE a b zZ72_x a b x CODE a b y Z72_x atb z73_y CODE f a SDL x f a z72_x Within the Charstring parameter of a CODE operator the SDL direc tive is available in the same way as in other included C code This is also shown in the last of the examples above As there is one CODE operator for each sort in the system it is some times necessary to qualify the operator with a sort name to make it pos sible for the SDL Analyzer to resolve which operator that has been used If for example the question and all answers in a decision are given as applications of CODE operators then it is not possible to determine the type for the decision One of the CODE operators should then be qualified with a sort name to resolve the conflict Telelogic Tau 4 5 User s Manual July 2003 Directives to the Cadvanced Cbasic SDL to C Compiler July 2003 Example 385 Code Directive DECISION CODE a CODE 1 TASK C
91. in errors due to illegal or illogical usage of the language concepts might be introduced into the specifica tion while in the problem domain logical errors might be introduced With traditional computer program development most illegal uses of language concepts are found by compilers or by run time systems Ex amples are syntax errors missing declarations division by zero or in dexing an array out of its bounds In the problem domain however the only feasible ways of detecting logical errors in non trivial programs are testing and proofreading When it comes to specifications in SDL language domain errors can be Telelogic Tau 4 5 User s Manual July 2003 July 2003 Introduction detected by using the SDL Analyzer which can be seen as a compiler without a code generation facility see chapter 55 The SDL Analyzer To detect problem domain errors testing by simulating the specification is the main procedure available Please see also chapter 53 The SDL Validator The specification of a protocol in SDL for instance specifies a signal interface by giving a hypothetical implementation of the components in the protocol This strategy immediately brings up two different purpos es for simulating the behavior of a system specification to understand the external view and to understand the internal view In the external view the signal interface is of concern while the internal behavior of the system specification th
92. in SDL It is the responsibility of the code generator to generate the proper actual pa rameters in C Example 376 Including a File in ADT With the ADT in the previous example the following operator call is valid eql sVar 1 2 3 4 The same call of eq2 would not be valid as the second parameter is not a variable or a formal parameter Generators The Cadvanced Cbasic SDL to C Compiler handles all the predefined generators in SDL i e Array String Powerset and Bag It is also pos sible for a user to write his own generators and instantiate them in new types However the behavior of a user defined generator has to be spec ified completely by the user This is performed in a somewhat extended ADT directive placed just before the endgenerator keyword These ex tensions are described below There are three additional sections in the directive apart from TYPE HEADING and BODY These are INSTTYPE INSTHEADING and INSTBODY The inline C code in TYPE HEADING and BODY is placed at the point of the generator i e it is generated once The contents of INSTTYPE INSTHEADING and INSTBODY is inserted at each instantiation of the generator i e in each newtype de fined using the generator In the INSTTYPE INSTHEADING and INSTBODY it is possible to use followed by a number to access the information given in the generator instantiation e 0 means the name of the newtype in the instantiation e 1 an
93. ion 23 45 SDL_ DURATION LIT 23 45 23 450000000 xPlus_ SDL Duration monodic xMonMinus SDL Duration dyadic xMinus_ SDL Duration Duration Real xMult_SDL Duration Real Duration xMultRD_SDL Duration xDiv_SDL Duration ey SS Sy Se xLT_SDL Duration xLE_SDL_ Duration xGT_SDL Duration xGE_SDL Duration ey yEqF_SDL Duration yNEgF_SDL Duration Time SDL_Time 23 45 SDL_TIME LIT 23 45 23 450000000 Time Duration xPlus SDL Time Duration Time xPlusDT_SDL_ Time result Time xMinusT_SDL_Time result Duration xMinusD SDL Time i Bey Sy SS xLT_SDL_ Time xLE_ SDL Time xGT_SDL Time xGE SDL Time re yEqF_ SDL Time yNEqF_SDL Time IA5String SDL_IA5String NumericString SDL_NumericString VisibleString SDL_VisibleString PrintableString SDL_PrintableString 2591 Chapter 57 The Cadvanced Cbasic SDL to C Compiler SDL name operator C name expression operator Bit string Bit SDL Bit not xNot_SDL Bit and xAnd SDL Bit or xOr SDL Bit xor xXor SDL Bit gt xImpl_SDL Bit z J yEq_SDL Bit yNEq SDL Bit SDL Bit String not xNot_SDL_ Bit String and xAnd SDL Bit String or xOr SDL Bit String xor xXor SDL Bit String gt xImpl_ SDL Bit String mkstring xMkString SDL Bit String length xLength_SDL_ Bit String first xFirst_SDL Bit String last xLast_SDL Bit String xConcat SDL Bit Stri
94. ions must be updated If you have specified OP B the header is generated and thus already correct but if you have specified OP H you have included the header in C probably in the HEADING section in the ADT directive for the type 1 For each parameter that should be passed as an address add a af ter the corresponding type name in C 2 Ifthe result should be passed as an address add a after the result type in C and add an extra parameter with the same C type as the updated function result last among the parameters When this step has been performed for all types the C compilation er rors will be reliable again Example 403 Headers extern str litl void extern str opl str SDL Integer Assume str is the type that should be passed as an address The results of both functions and the first parameter of op1 are mentioned in the compatibility warn file The heading should be updated to extern str litl str extern str opl str SDL Integer str j Telelogic Tau 4 5 User s Manual July 2003 July 2003 Migration Guide for Generic Functions Updating Parameter Specifications The parameter specification and result in the function implementation must be updated to match the heading The function implementation is probably in the BODY section in the ADT directive of the type Example 404 Parameter Specifications continued from Example 403 str litl void str opl str P1 SDL Integer P2
95. irst parameter If the type that is to be assigned contains any pointers the assign function is a bit complicated to write in order to avoid access errors and memory leaks See the discussion about the As sType parameter to GenericAssignSort in Generic Assignment Func tions on page 2624 Equal Test It is possible to select how test for equality should be performed for val ues of the type Note that all generated equal tests will be of the form yEqF_ SortName The yEqF_ SortName is a macro either implemented as C equal or as a call to the yEq_ SortName function if such function is to be used i e as define yEqF S E1 E2 El E2 define yEQqF_ S E1 E2 yEq_ S E1 E2 The operator is represented by the macro define yNEgF S E1 E2 yEqF S E1 E2 Type Method E B Use and generate heading but not body of yEq_ S E H Use but generate no code for yEq_ S E G e Ifthe type definition is generated Use if possible Otherwise use the GenericEqualSort function e Ifthe type definition is not generated Use E S Use E Q Use and generate an equal function that asks for the result of the test same as Q for operators E Same as E B Same as E G Telelogic Tau 4 5 User s Manual 2637 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2638 If you define yo
96. iteral identifiers foe RoE p 47 A aay A T fa p lt lt gt gt lt lt gt gt l system package block process procedure operator substructure channel signalroute type null env self parent Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types xxOffspring offspring xxSender sender xxEoln end of line xxEOF end of file xxErrorToken used to indicate error xxToken Function xScanToken The function xScanToken extern xxToken xScanToken char strVar reads the next token from input stdin or Simulator UI and returns the type of the next token as function result If the token is xxId or xxString the strVar parameter will contain the identifier number or string The size of the char parameter passed as actual parameter should be large enough to store the possible values If some other token was found no information is stored in strVar xUngetToken Sometimes it is necessary to look ahead to determine how to handle the current token Using the function xUngetToken below it is possible re turn one token to the input Note that both parameters must have the val ues obtained from xScanToken extern void xUngetToken xxToken Token char strVar The functions
97. l 2689 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2690 e The third line is the SDT reference to the newtype This can be used in the Organizer s goto source feature to locate the SDL source code e The fourth line contains either Pass as Value or Pass as Ad dress depending on the property of the newtype followed by the interpretation of the ADT directive As the ADT directive can be used in many different ways it is impos sible to describe a general method how to correct any problems The type list in the compat ibility warn file indicates what newtypes that have highest probability to cause problems It is recommended that you go through the listed newtypes and review them given the information in the following sections You also have to find and in some cases correct the places where the functions discussed below are called The compiler error list is the main source of information for this task Please see Locating Source Code on page 2693 if you have problems locating the corresponding SDL source listed in a C compilation error message Assignment Functions For all types passed as addresses the differences between the old style and the new generic assignment functions are e The old functions pass the value of the right hand side expression as the second parameter while the new pass the address of the right hand side expression e The old functions returns void but the generic fu
98. lassPtr 0 ENDNEWTYPE Note that the ADT specification means that no code will be generated for the abstract data type The abstract data type can utilized in the fol lowing way DCL TClass TestClass I Integer TASK TClass newTestClass TASK TClass newTestClass 2 TASK I updateVar TClass I TASK I getVar TClass Telelogic Tau 4 5 User s Manual 2679 Chapter 57 The Cadvanced Cbasic SDL to C Compiler TASK TClass deleteTestClass TClass The only feature that is not described before is the C option in the OP directive C class is an alternative to I infix and P prefix and spec ifies that the operator call should be translated to a member function call of a C member function OP C means that an operator call F a b c is translated to a gt F b c Note This means that each operator mapped on class member function should have the class instance pointer as first parameter 2680 Telelogic Tau 4 5 User s Manual July 2003 Restrictions Restrictions SDL Restrictions The Cadvanced Cbasic SDL to C Compiler handles the majority of SDL concepts according to the definition of SDL 92 There are howev er a number of restrictions that are discussed in this section Analyzer Restrictions The restrictions in the SDL Analyzer are of course also valid in the Cadvanced Cbasic SDL to C Compiler For more information see SDL Analyzer on page 37 in chapte
99. lator or validator can however be started in two differ ent ways e From the Simulator Graphical User Interface which is started from the Organizer with the SDL gt Simulator UI command and provides a graphical interface with buttons and menus and of course full con nection to other SDL suite tools See Graphical User Interface on page 2130 in chapter 50 The SDL Simulator for more informa tion e From an OS shell just like any other executable program The user then invokes a command line monitor system If the Organizer is running when starting a simulator or validator the program will connect itself to the SDL suite If the Organizer is not running or the simulator validator is started with the program parameter nosdt the program will not connect itself to the SDL suite The SDL Unit for Which Code is Generated The first time a C program is generated for a system the complete sys tem will be selected for analysis and C code generation After that only the unit system or block that is changed will be selected Note that the lowest level of possible regeneration object is a block That block may not be a block type or be part of a block type or system type The reason that a process cannot be generated without regenerating the enclosing block is that internal process information about for example formal parameters are used to generate code for other processes within the same block e Only complete C files can
100. le sdl 62 Used in DIRECTIVE at SDTREF TEXT file sdl 62 This example shows one literal and one operator that have to be updat ed e The first line contains the name of the operator literal in SDL and in C e The second line contains an appropriate qualifier that gives infor mation on where in the system the item is defined e The third line is the SDT reference to the operator literal This can be used in the Organizer s Goto Source feature to show where the SDL source is located e The following lines indicate where changes are needed Each line states that the result or a parameter is passed as an address This means that previously this item was passed as a value but now it Telelogic Tau 4 5 User s Manual 2685 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2686 should be passed as an address A complete list of types that must be changed can be found in Mapping Table on page 2588 e Last a number of cross references might be found These show places where the operator is called from inline C using an SDL di rective These calls might have to be updated Step 3 Updating Operators and Literals For each operator or literal that is listed in the file compatibili ty warn perform the instructions presented in this section Note Literals should be treated as operators without parameters Updating the Headers The headers of the corresponding C funct
101. llowing recommendations apply e If the string size is not known use the linked list e Ifthe number of string values is substantially smaller than the max imum string length use the linked list if speed is not very important e If the maximum length is not large or the number of string values are almost equal to the maximum length use the array Telelogic Tau 4 5 User s Manual July 2003 Using Cadvanced Cbasic SDL to C Compiler to Generate C Using Cadvanced Cbasic SDL to C Compiler to Generate C July 2003 General The C code in the Master Library and the C code generated by the Cad vanced Cbasic SDL to C Compiler is in the common subset of C and C and will thus compile both as a C program and as a C program There is one special feature in the code generator concerning C when it comes to abstract data types and the possibility to match a C class and an SDL data type Otherwise all the features for including C code directive ADT directive CODE see Abstract Data Types on page 2586 and Accessing SDL Names in C Code Directive SDL on page 2654 and so on are directly applicable for C as well The CODE directives make it possible to include class definitions as C code and the utilization of the classes as C code in SDL tasks Example 399 Using C Classes CODE directive containing declarations see Including C Declarations Directive CODE on page 2658 which should be
102. lternative to opera tor diagrams or operators defined using SDL textual form where the operator is defined directly in SDL When the choice between an implementation in SDL or in C is to be made there are a few things to consider There is always problems when mixing languages for example how are C names for SDL entities constructed Checking of SDL is performed by the SDL Analyzer which will find problems much earlier than the C compiler checking C code Also pointing to the error will be more accurate in SDL SDL implementations will be more portable and might benefit from future improvements in the SDL Compiler The risk for backward compatibility problems in future releases of the SDL suite will be less for an SDL implementation However aC implementation might be more efficient or you might already have a corresponding C function So it is not obvious if SDL or C implementations should be used How ever we recommend SDL if there are no specific reasons for using C Note also that the SDL extension described in Grammar for the Algo rithmic Extensions on page 146 in chapter 3 Using SDL Extensions in the SDL Suite Methodology Guidelines could be very useful when writ ing implementations in SDL It is possible to choose between two alternatives to implement operators and literal functions e Q question This is the default value and specifies that the code generator should generate the int
103. m it is in simple cases possible to use selections in the Organizer and in more general cases possible to work with build scripts i e text files containing commands to the Analyzer the syntax used when running the Analyzer stand alone The restric tion in the Organizer view is that only one selection can be handled and that instantiation of OO types cannot be selected In a build script on the other hand several component commands can be used to select several parts of a system As the component command takes an SDL qualifier as a parameter instantiations can also easily be selected Using Selections in the Organizer To start with the simple case when one block or process should be sim ulated this is easy to perform directly from the Organizer Select the proper block or process and press the Simulate button or go via Make dialog Note If you already have generated a simulation from the Organizer and want to generate a new one with other options or with another selec tion you should perform a Full Make as changes in options or se lection is not handled by the build process Otherwise compilation or link errors might be the result of the build process Only the system a block or a process can be selected for simulation Types including procedures are only definitions and are not executable objects while services depend on its enclosing process and cannot be Telelogic Tau 4 5 User s Manual 2571 Chapter 57 The Cadv
104. means high priority PRIO directives can be placed directly after the process heading in the definition of the actual process or last in the reference symbol in SDL GR Telelogic Tau 4 5 User s Manual 2667 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2668 Example 388 PRIO Directive in process headings Process Pl PRIO 3 Process P2 1 1 PRIO 5 Process P3 P3Type PRIO 3 Process P4 1 1 P4Type PRIO 5 Processes that do not contain any priority directive will have the default priority 100 Initialization Directive MAIN The MAIN directive is used to include initialization code that should be executed before any process transitions are started The directive should be placed in the system definition directly after the system head ing Example 389 MAIN Directive System S MAIN C code for initialization The MAIN directive has exactly the same structure as the CODE di rective for including code in tasks The included code will however be placed last in the yInit function after the initialization of the internal structure but before any transitions are executed Modifying Outputs Directive EXTSIG ALT TRANSFER The purpose of these directives is to modify the standard behavior of an SDL output The EXTSIG directive can be used to build applications with the SDL suite run time library The directives ALT and TRANSFER are only useful together with other r
105. mp2 Param1 comp2 Result Param2 return Result always return the last extra parameter I il Note VERY IMPORTANT As IN parameters are passed as addresses for structured types changing such a parameter inside the operator might have undesired effects A variable passed as actual parameter is then also changed If you want to change the formal parameter copy it first to a operator local variable For Cadvanced Cbasic this rule applies to operators implemented in C For Cmicro this rule also applies to operators and procedures de fined in SDL Implementation of User Defined Operators Including Implementations of Operators In a previous subsection the default behavior of the Cadvanced Cbasic SDL to C Compiler concerning operators not defined in operator dia grams and literals were described If you do not specify otherwise in teractive functions are generated which in each case will ask you for the operator result or literal value This is a fast way of getting started but you will probably find it tedious in the long run especially if you are using abstract data types extensively To cope with this problem and to make it possible to generate applications the code generator offers a possibility to include implementations written in C of the operator and Telelogic Tau 4 5 User s Manual 2609 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2610 literal functions This possibility can be used as an a
106. mulations validations applications in generated envi ronment header files ifc files and in generated environment func tions Generation of Support Files The Cadvanced Cbasic SDL to C Compiler can generate a number of support files together with the ordinary c h and makefiles These files are e System header file ifc e Skeleton to environment functions _env c e Signal number file hs e Coder decoder framework files _cod c _cod h The generation of these files can be selected in the Organizer Make di alog or as an Analyzer command depending on which interface is used The details on the system header files and the environment function can be found in The Environment Functions on page 2702 while the sig nal number file can be used to assign numbers to all signals in the sys tem Signal number files are most used in connection with OS integra tions July 2003 Telelogic Tau 4 5 User s Manual 2575 Chapter 57 The Cadvanced Cbasic SDL to C Compiler Implementation 2576 In this section some implementation details are presented that can be useful for understanding how a generated simulation or application be haves Abstract data types are treated in the next section Time A generated C program can be executed in two modes with respect to the treatment of time e Simulated time e Real time Simulated Time Using simulated time which is the most useful mode for simulations means that t
107. n be given e Normally this information is set up in the Organizer using the Edit Separation command see Edit Separation on page 136 in chapter 2 The Organizer Here file names for the generated files can also be specified In the Make dialog in the Organizer see Make on page 119 in chapter 2 The Organizer it is possible to select full separate generation user defined separate generation or no separate gener ation e Foran SDL PR file that is used as input when running the SDL An alyzer as a stand alone tool the same information can be entered by SEPARATE directives directly introduced in the SDL program Full separate generation user defined separate generation or no separate generation can be set up in the command interface of a stand alone Analyzer see Set Modularity on page 2421 in chap ter 55 The SDL Analyzer The Cadvanced Cbasic SDL to C Compiler can generate a separate file for e system always separate e package always separate e system type e block e block type e process e process type e service e service type e procedure Note Instantiations cannot be separated i e an instance of a block type cannot be generated on a file of its own Telelogic Tau 4 5 User s Manual July 2003 Directives to the Cadvanced Cbasic SDL to C Compiler July 2003 If SEPARATE directives are used they should be placed directly after the first semicolon in the system block pro
108. native special prefix full prefixes are used for all en tity classes except variable formal parameter sort and syntype For these entity classes no prefix is used Conclusion As was said in the beginning of this subsection the user should have a good reason for selecting anything but the full prefix as it could be very difficult to spot name conflicts The C compiler will in some cases find a conflict but may in other cases consider the program as legal and gen erate an executable program with a possibly unwanted behavior The note above about OO concepts is also a strong argument for full prefix Case Sensitivity Another aspect concerning identifiers is that SDL is case insensitive while C is case sensitive The Cadvanced Cbasic SDL to C Compiler has two translation schemes for identifiers one is to use the capitaliza tion used in the declaration of the object of concern default and one is to use lower case identifiers The translation scheme is selected in the Make dialog in the Organizer see Make on page 119 in chapter 2 The Organizer or in the user interface of the Analyzer when it is executed stand alone The Analyzer Command Line UTI on page 2404 in chap ter 55 The SDL Analyzer Telelogic Tau 4 5 User s Manual July 2003 Directives to the Cadvanced Cbasic SDL to C Compiler July 2003 Specifying Names in Generated Code Directive NAME If you wish to decide the name of an object in
109. nctions return the first parameter i e the address of variable e Itis now required that the assignment function must be a function it cannot be a macro as the address of the function is stored in the type info node for the newtype Example 408 The Assignment Function The prototype for an old assign function would be void yAss typename typename typename int The prototype for a new assign function should be typename yAss typename typename typename int Telelogic Tau 4 5 User s Manual July 2003 July 2003 Migration Guide for Generic Functions The body of the assignment function must be updated for these changes If assignment for a type passed as an address is used in inline C code one of the following tasks must be performed e Ifthe expression parameter is a variable a amp should be added be fore the variable e Ifthe expression is an SDL operator call a change is normally not needed as the operator in the generic function model will return the address of a value not the value itself for types passed as address e You might want to add void before the yAss call to tell the com piler that you want to ignore the result For more information please see Generic Assignment Functions on page 2624 Equal Functions For all types passed as addresses the differences between the old and the new generic equal functions are e The old functions pass the values of the two expressi
110. nd if it has the specified name and is in the specified entity class If no entity class name is given the search is performed for all entity classes Note In types especially in block types SDL should be used with care The reason is that some of the objects in a block type are generated for each instantiation of the block A SDL directive on such an ob ject might lead to overloading of names in C Sensitive objects are processes process instantiations signal routes channels remote definitions The table in the subsection SDL Predefined Types on page 2588 gives the direct translation between an SDL name and the corresponding C name or expression For these names the SDL directive should not be used July 2003 Telelogic Tau 4 5 User s Manual 2655 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2656 Including C Code in Task Directive CODE The user s own C code may be included in tasks by using the CODE directive This directive has the following syntax CODE C code that should be included in generated code Type the directive name on the first line and the C code on the follow ing lines up to the end of comment symbol Note that text on the same line as the CODE directive are not handled A CODE directive can be placed e Before the first assignment statement or informal text e Immediately preceding or just following the comma that separates two assignment statements or informal t
111. ng substring xSubString SDL Bit String bitstr xBitStr_ SDL Bit String hexstr xHexStr_ SDL Bit String yEq SDL Bit String yNEq_SDL Bit String 2592 Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types SDL name operator C name expression operator Octet SDL Octet not xNot_SDL_ Octet and xAnd SDL Octet or xOr_ SDL Octet xor xXor SDL Octet gt xImpl_ SDL Octet shiftl xShiftL_ SDL Octet shiftr xShiftR_SDL_ Octet xPlus SDL Octet xMinus SDL Octet xMult_SDL_ Octet 120 xI20 SDL Octet o2i xO2I_SDL Octet J xDiv_SDL Octet mod xMod_SDL_Octet rem xRem_SDL_ Octet bitstr xBitStr_ SDL Octet hexstr xHexStr_ SDL Octet lt lt gt gt yLT_SDL Octet yLE SDL Octet yGT_SDL_ Octet yGE SDL Octet yEq_SDL Octet yNEq SDL Octet Telelogic Tau 4 5 User s Manual 2593 Chapter 57 The Cadvanced Cbasic SDL to C Compiler SDL name operator C name expression operator Octet_string SDL_Octet_String mkstring xMkString SDL Octet String length xLength_ SDL Octet String first xFirst_SDL Octet String last xLast_SDL Octet String xConcat_ SDL Octet String substring xSubString SDL Octet String bitstr xBitStr_ SDL Octet String hexstr xHexStr_ SDL Octet String bit_string xBit String SDL Octet String hex string xHex
112. nicating systems execute them using the SDL suite and obtain com munication between the systems As a generated C program does not know what it communicates with it can of course communicate with any type of application as long as the application is connected to the PostMaster the communication medi um and sends signals according to the defined format How to achieve this is described in chapter 13 Using the Telelogic Tau Public Inter face A very interesting group of such applications are user interfaces By connecting a user interface and an SDL simulation you can achieve sev eral things You can for example build well designed application ori ented user interfaces that present what is going on in a simulation or you can in a simple way define the logic behavior behind a user inter face during its prototyping phase Telelogic Tau 4 5 User s Manual July 2003 Introduction Overview of the Cadvanced Cbasic SDL to C Compiler To facilitate the validation of SDL specifications or descriptions the SDL Analyzer contains an SDL parser an SDL semantic checker and the Cadvanced Cbasic SDL to C Compiler Creating a C Program To obtain an executable program that behaves according to an SDL de scription you enter the SDL description into the SDL Analyzer which contains the Cadvanced Cbasic SDL to C Compiler If the SDL descrip tion is syntactically and semantically correct a C program is generated You then compile t
113. nted as char in C Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types Note This means that the value NUL ASCII character 0 cannot be part of a Charstring as this value is used as string terminator in C this is checked by the library functions for Charstring The code generator and the library functions for the Charstring opera tors use the first character index 0 in the C string to indicate the status of the string If the first character is e VW the string is assigned to an SDL variable and may not be changed in any way e A the string is a C char literal and may of course not be changed e Si Wig the string is a temporary result from a function returning a Char string This memory should either be assigned to an SDL variable or returned to the pool of free memory All the library functions for Charstrings handle memory in an appropri ate way A user only has to take the extra character in to account when Charstrings are handled in C Any Charstring function parameters hav ing a T as first character must be handled according to the discussion above A function that returns a Charstring and that creates new tempo rary memory to store the result should assign the value T to the first character in the Charstring As pointers and dynamic memory are used to implement Charstrings it is necessary to be careful when Charstrings are handled in C code which we show in two e
114. oach has a positive effect on the performance However the generic function approach introduces incompatibility problems if your existing system calls generated functions from inline C code If this is the case the function calls must be changed If you need to migrate an SDL system created with the old style code generation you must solve the incompatibility issue References to Information Generic Functions The major source of information regarding generic functions is Ab stract Data Types on page 2586 which contains a number of sections discussing different aspects of data types and operators e Translation of Sorts on page 2595 describes how different SDL types are translated to C Telelogic Tau 4 5 User s Manual July 2003 Migration Guide for Generic Functions July 2003 e Parameter Passing to Operators on page 2606 discusses the gen eral parameter passing principles for operators and literal functions This section also lists which types that are passed as values and which types that are passed as addresses e Implementation of User Defined Operators on page 2609 de scribes how to include your own implementation in C for an opera tor e Generic Functions on page 2623 introduces you to the type info node concept and describes the general operators assign equal free etc e Generic Function for Operators in Pre defined Generators on page 2630 describes the opera
115. ock is stopped during the time the program spends in the monitor sys tem Note The C standard function time used as real time clock returns the time in seconds It does not handle parts of seconds The implemen tation of the clock can be changed by re implementing the function SDL_Clock in sctos c Scheduling The process instances in the simulated system will execute transitions that consist of actions like tasks decisions outputs procedure calls etc according to the rules of SDL It is assumed that a transition takes no time and that a signal instance is immediately placed in the input port of the receiver when an output operation occurs A transition is always executed without any interrupts if the user does not manually rearrange the ready queue using an appropriate command provided by the monitor system Rearrange Ready Queue It is possi ble to execute a few SDL symbols in one transition and then to re ar range the ready queue and execute another transition The interrupted transition can afterwards be executed to its end A quasi parallel strategy for selecting transitions to be executed is thus the basic scheduling mechanism SDL does not in itself define an exe cution strategy so the selected strategy is therefore an allowed but not the only possible strategy for execution As aconsequence of the execution strategy a generated simulator is not directly suited for simulation of timing effects that is sit
116. ome a separate file e Full separation The system each package each block block type process process type service and service type will become a separate file Note that even in this case a procedure is separate only if the user has speci fied it as separate Independently if No User defined or Full separation has be selected the code generator will use the file name specified in the Edit Separa Telelogic Tau 4 5 User s Manual 2651 Chapter 57 The Cadvanced Cbasic SDL to C Compiler tion dialog or the SEPARATE directive for a file that is to be gener ated An Example of the Usage of the Separate Feature In the following example a system structure and the SEPARATE di rectives are given The same information can easily be set up in the Or ganizer as well This example is then used to show the generated file structure depending on selected generation option Example 380 SEPARATE Directive system S SEPARATE Sfile block B1 SEPARATE process P11 SEPARATE Plifile process P12 block B2 process P21 process P22 SEPARATE Note that SEPARATE directives can only be used in SDL PR files Normally this information is given in the Organizer Applying Full Separate Generation If Full separate generation is selected then the following files will be generated Sfile c Sfile h Bl c B1 h P11file c P12 c B2 c B2 h P
117. on while the new generic equal functions pass the addresses of the expressions e Itis now required that the equal function must be a function it can not be a macro as the address of the function is stored in the type info node for the newtype Example 409 The Equal Function The prototype for an old equal function would be SDL Boolean yEq typename typename typename The prototype for a new equal function should be SDL Boolean yEq typename typename typename The body of the equal function must be updated for these changes If equal for a type passed as an address is used in inline C code perform the same tasks as presented for the assignment function Telelogic Tau 4 5 User s Manual 2691 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2692 For more information please see Generic Equal Functions on page 2627 Free Functions The yFree_typename function is backward compatible However it is now required that the equal function must be a function it cannot be a macro as the address of the function is stored in the type info node for the newtype For more information please see Generic Free Functions on page 2628 Default Functions The yDef_typename macro or function from the non generic mode is no longer used or generated Initialization of SDL variables are per formed as follows e if the variable has an initial value given in the declaration the vari able is assigned t
118. ot equal are not possible to use the equal macros will be come calls to an equal function The basic generic equal function can be found in sctpred hand sctpred h extern SDL Boolean GenericEqualSort void void tSDLTypelInfo where e the first two parameters are the addresses to the two expressions to be tested e the third parameter is the type info node for the actual type Special treatment of Charstring and instantiations of the Own generator has made it necessary to introduce specific wrapper functions that in turn calls GenericEqualSort for these types extern SDL Boolean xEq SDL _Charstring SDL_Charstring SDL _Charstring extern SDL Boolean GenOwn_Equal void void tSDLTypeInfo Generic Free Functions Each type in SDL that is implemented as a pointer or that contains a pointer that references to memory that is automatically handled in prin ciple all pointers except Ref pointers has access to a corresponding yFree_typename function or macro In the generic function model this is always a macro define yFree SDL Charstring P xFree SDL Charstring P define xFree SDL Charstring P GenericFreeSort P tSDLTypeInfo amp ySDL_ SDL Charstring define yFree A P GenericFreeSort P tSDLTypeInfo amp ySDL_A The yFree macro will always be translated to a call to the function Ge nericFreeSort extern void GenericFreeSort void tSDLTypeInfo Telelogic Tau 4 5 User s
119. parts of the system all in one build process e Each partition can consist of several objects and objects might be instantiations There are two Analyzer commands see Description of Analyzer Com mands on page 2406 in chapter 55 The SDL Analyzer that are of ma jor interest for specifying a partition First we have the Program com mand which takes a name as parameter Second we have the Compo nent command which takes a qualifier as a parameter The Program command gives the start of a partitioning specification while the Com ponent command is used to select an SDL component that should be Telelogic Tau 4 5 User s Manual July 2003 July 2003 Features part of the partitioning A partition specification can of course contain a number of components The Component command is very similar to a selection in the Organizer when running directly from the Organizer A program section in a build script typically starts with a Program com mand and ends with a Generate command Example 336 Build script program MyExample component system example block b1 component system example block b2 process p22 target directory home jk example target set env header on set modularity user generate advanced c In Windows the target directory command could for example be target directory c example target The example above means that a program containing the implementa tion of the complete block b1 and the process p
120. pe block type process type full prefix should always be used as the OO concepts in itself most likely mean the name conflicts will be intro duced in C Telelogic Tau 4 5 User s Manual July 2003 Directives to the Cadvanced Cbasic SDL to C Compiler This strategy for naming objects in the generated code should be used in all normal situations as it guarantees that no name conflicts occur The Cadvanced Cbasic SDL to C Compiler offers however possibili ties to change this strategy In the Make dialog in the Organizer see Make on page 119 in chapter 2 The Organizer and in the user inter face an Analyzer running stand alone see The Analyzer Command Line UI on page 2404 in chapter 55 The SDL Analyzer it is possible to select one of the following strategies full prefix entity class prefix no prefix or special prefix Full prefix is default and is the strategy de scribed above Entity Class Prefix If entity class prefix is selected then the prefix that is concatenated with the SDL name will be in accordance with the table below and depends only of the entity class of the object Entity class Prefix Entity class Prefix Block block type blo Process Process type prs block instance Process instance Block substructure bls Remote procedure rpc Channel cha Remote variable imp Channel substructure chs Service Service type ser Service instance
121. pe introduced in SDL will be described by a type info node in the generated C code For the predefined data types the following type info nodes can be found in sctpred h and sct pred c extern tSDLTypeInfo ySDL SDL Integer extern tSDLTypeInfo ySDL_ SDL Real extern tSDLTypeInfo ySDL SDL Natural extern tSDLTypeInfo ySDL_ SDL Boolean extern tSDLTypeInfo ySDL SDL Character extern tSDLTypeInfo ySDL_SDL_ Time extern tSDLTypeInfo ySDL SDL Duration extern tSDLTypeInfo ySDL SDL PId extern tSDLTypeInfo ySDL_ SDL Charstring extern tSDLTypeInfo ySDL_ SDL Bit extern tSDLTypeInfo ySDL_ SDL Bit String extern tSDLTypeInfo ySDL SDL Octet extern tSDLTypeInfo ySDL_ SDL Octet String extern tSDLTypeInfo ySDL_SDL_IAS5String extern tSDLTypeInfo ySDL_ SDL NumericString extern tSDLTypeInfo ySDL_SDL_PrintableString extern tSDLTypeInfo ySDL_ SDL VisibleString extern tSDLTypeInfo ySDL SDL Null extern tSDLGenListInfo ySDL_SDL Object Identifier For a user defined type the type info node will have the name ySDL_ TypeName Generic Assignment Functions Each type in SDL has access to an assignment macro yAssF_typename Examples for type Boolean and for a user defined type A define yAssF SDL Boolean V E A V E define yAssF A V E A yAss_ A amp V E A define yAss A Addr Expr AssName void GenericAssignSort Addr Expr AssName tSDLTypeInfo amp ySDL_A This macro is used in the generated code and in
122. placed among the SDL declarations CODE HEADING class TEST public void putvar int avar int bvar a avar b bvar int geta return a int getb return b private int a b TESTvar ts Example of usage of the class in a CODE directive in a TASK see In cluding C Code in Task Directive CODE on page 2656 TASK CODE TESTvar putvar I I 10 Example of usage of the class in a CODE operators in expressions see Including C Code in SDL Expressions Operator CODE on page 2662 Telelogic Tau 4 5 User s Manual 2677 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2678 OUTPUT Score CODE TESTvar geta CODE TESTvar getb CODE TClass gt getVar i Connection Between C Classes and SDL To obtain a close connection between a C class and SDL an abstract data type in SDL can be used see below If you have a C class from a class library or developed specifically for the project then the following correspondence rules can be used to map the class on an abstract data type C SDL Class definition Abstract data type definition Class instance pointer Process variable Member functions Operators new delete Operators Example 400 SDL and C Class Suppose we have a C class with the following interface h file class TestClass public
123. process which will be inserted last among the processes with the same priority but before all processes with lower priority high priority value low priority A process will never be inserted before the process currently executing as pre emptive scheduling is not used In more detail e Ifa process outputs a signal to another process which immediately can receive the signal the receiving process will be inserted into the ready queue last among the processes with the same priority but never before the currently executing process e If the processes currently executing a nextstate immediately can continue to execute another transition it will be inserted into the ready queue last among the processes with the same priority This means that it can remain as first process in the ready queue but it can also be re inserted somewhere else e Ifthe receiving process at a timer output immediately can execute a transition as response to the received signal the process will be in serted into the ready queue last among the processes with the same priority This means that it can be inserted anywhere in the queue Enabling Conditions and Continuous Signals Enabling conditions and continuous signals are additional concepts in SDL The model for these concepts use repetitive signal sending to have the expressions recalculated repeatedly This model is not suitable during simulation and definitely not acceptable in an application We Telelogic
124. r 2 Release Notes in the Release Guide Cadvanced Cbasic SDL to C Compiler Restrictions The Cadvanced Cbasic SDL to C Compiler introduces more severe re strictions on the allowed set of SDL concepts than the Analyzer For more information see SDL to C Compiler on page 40 in chapter 2 Release Notes in the Release Guide July 2003 Telelogic Tau 4 5 User s Manual 2681 Chapter 57 The Cadvanced Cbasic SDL to C Compiler Migration Guide for Generic Functions 2682 General This section provides help to migrate a system using old style code gen eration for operators to the new Generic Function style Introduction The basic idea of the generic function approach is to decrease the num ber of generated help functions and functions for operators in pre defined generators This is accomplished by generating generic func tions that can be re used by different types This means for instance that only one assignment function is created This function however can be used by all types In the old style meth od one assignment function was created for each type For operators in predefined generators there is now one single length function calculat ing the length of all string generator instantiations In order to implement the generic functions the parameter passing mechanisms have been changed In principle a generic function cannot take a value as parameter it must receive a pointer to the value This ap pr
125. r not If this is not the case a linked list of all elements that are member of the set is used to represent the powerset All the available operations defined for Powersets in SDL are supported Bag The Bag generator which is introduced in SDL in Z 105 i e in the map ping from ASN 1 to SDL is similar to powerset However it is possible to have several elements with the same value in a bag A bag is always translated into a linked list with one element for each value that is a member of the bag Each element contains the value and the number of occurrences of this value Ref Own Oref These generators represent pointers with different properties They are all translated to pointers in C Syntypes Syntypes may be defined for any sort that the code generator can han dle giving a new name for the sort and possibly a new default value for variables of the sort Range conditions that restrict the allowed range of values are also allowed A syntype is translated to a type equal to the parent type using typedef The check that a variable of a syntype is only assigned legal values is implemented in a test function that is generated together with the type definition An attempt to assign an illegal value to such a variable will be reported as an SDL dynamic error If the syntype is can be used as index sort in an array and the generated type in C would become an ar ray there will also be a test function that can be used to check th
126. ram commands The options actually used at the generate commands are the options set up after executing all the commands up to the generate command All the possibilities in the Make dialog and the Analyze dialog in the Organizer are also provided as commands in the Analyzer Please see The Analyzer Command Line UI on page 2404 in chapter 55 The SDL Analyzer for a list of all commands Note When build scripts are used all features in the Analyzer will have its hard coded defaults if it is not set in the build script Preferences and your settings in the Organizer are ignored The default values are given in The Analyzer Command Line UI on page 2404 in chapter 55 The SDL Analyzer or you can start a stand alone ana lyzer sdtsan directly in an OS shell and issue the commands Show Analyze Options and Show Generate Options See also SDL Make on page 120 in chapter 2 The Organizer for han dling of build scripts in the Organizer 2574 Telelogic Tau 4 5 User s Manual July 2003 Features Behavior of Generated Partitioning The basic idea is to redirect all channel going to objects not part of the current partitioning to the environment This operation is performed by the code generator at code generation time This means that all signals sent between objects in the partitioning and objects outside the parti tioning will be seen as signals to or from the environment This is true everywhere in si
127. rance in SDL This applies to the body sections as well All body sections will be placed after the sequence of heading sections and the heading section will be placed after all the type definitions The SDL declarations made in the corresponding unit are available in the code directives and can as usual be reached using the SDL directive All declarations made in Telelogic Tau 4 5 User s Manual July 2003 Directives to the Cadvanced Cbasic SDL to C Compiler code directives are of course available in code directives in tasks in the corresponding unit or in its subunits The general hints on how to write C code that fits into a generated C program given in the section Implementation of User Defined Opera tors on page 2609 and in the section Accessing SDL Names in C Code Directive SDL on page 2654 are also applicable here July 2003 Telelogic Tau 4 5 User s Manual 2661 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2662 Including C Code in SDL Expressions Operator CODE For each sort defined in an SDL system both predefined and user de fined the Cadvanced Cbasic SDL to C Compiler includes an operator CODE with the following signature CODE Charstring gt S where S is replaced by the sort name This operator or rather these op erators make it possible to access variables and functions defined in C using the CODE directive in SDL expressions and still have syntacti cally and semant
128. re ENDNEWTYPE the de fault implementation technique can be given When the code generator determines how to generate code for a literal or an operator it first looks for an OP directive after the literal name or operator definition If no such directive is found it looks for a directive immediately before ENDNEWTYPE If no ADT directive is found here the generation technique Q question is assumed For Cmicro Q is not used so the de fault is B An OP or ADT directive specifying a generation technique should have the following structure OP B ADT B The letter between the parentheses should be either Q question or B body The interpretation of Q and B was explained earlier If B has been specified for any operators or literals then the C code for these functions must be supplied by the user This code should be placed in the BODY section in the ADT directive according to the following example Example 359 Implementing an Operator ADT ADT B BODY C code representing bodies of functions Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types The section name i e BODY must be given on a line of its own and must have the character in the first position of the line Upper case and lower case letters are as usual considered to be equal If the section is empty the section name can also be removed Note The Cadvanced Cbasic SDL to C Compiler will not check the con
129. rrect code Only calls made directly from inline C code may have to be updated The operator list in the file compatibility warn contains cross refer ences to the inline C code where the operator is called using an SDL di rective Note Operator calls in C without the SDL directive are not listed in com patibility warn These calls can only be found via the compiler error list For parameters that has changed parameter passing mechanism from pass as value to pass as address you should perform one of the following tasks e Ifthe actual parameter is a variable or something it is possible to take the address of add a amp before the variable e Ifthe actual parameter is a call to a function then probably this function has changed its prototype so that it now returns an address In that case nothing needs to be performed In other cases proceed to the next possibility e If none of the situation above is appropriate insert a new function local variable of the parameter type assign the value of the actual parameter to this variable and insert the address of the variable as actual parameter Telelogic Tau 4 5 User s Manual July 2003 July 2003 Migration Guide for Generic Functions Implementation Hint Note The following information is not required for the migration of the system but can be used to improve the performance of the system When updating the operators it might be worth investigating the avail
130. rs in Predefined Generators The operators in predefined generators have got new generic implemen tations All the available generic implementations are listed in Generic Function for Operators in Pre defined Generators on page 2630 Mac ros that support the old operators names and translate them to the gener ic functions are generated If you get compilation errors in such a call you should compare the call with the macro and the generic function to see if there are any differences in the parameter passing principle Locating Source Code A typical error message from a C compiler lists a file name a line num ber and a description of the error To locate the corresponding SDL source code perform the following 1 Ina text editor open the file that is listed in the error message 2 Go to the given line number 3 Search upwards for an SDT reference that is a C comment starting with SDTREF Copy the SDT reference and paste it into the Goto Source feature in the Organizer The Organizer will show you where the C code originated from Telelogic Tau 4 5 User s Manual 2693 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2694 Telelogic Tau 4 5 User s Manual July 2003
131. s were not used a function could only call the functions that are defined textually before the actual function To select the way the Cadvanced Cbasic SDL to C Compiler should generate code for operators and literals code generator directives are used A code generator directive is an SDL comment with the first char acters equal to followed by a sequence of letters identifying the di rective In this case the letters are ADT for Abstract Data Type and OP for operator An ADT directive and a OP directive should thus look like ADT OP The text is not case sensitive OP directives are recognized at two different positions in an abstract data type e Directly after the name of a literal e Directly after the semicolon ending the definition of an operator Telelogic Tau 4 5 User s Manual 2611 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2612 ADT directives are recognized immediately before the reserved word ENDNEWTYPE or ENDSYNTYPE Example 358 Implementing an Operator ADT NEWTYPE Str STRUCT a integer b Boolean c real ADDING LITERALS Litl 0P Lit2 OP OPERATORS Op1 Str integer gt Str OP Op2 Str Boolean gt Str OP ADT ENDNEWTYPE At each of the positions after a literal name or operator definition there is a possibility to specify how this literal or operator should be imple mented In the directive immediately befo
132. sets with complex component type These types are represented as linked lists in C define GenBag Empty SDLInfo Result memset void Result 0 SDLInfo gt SortSize extern void GenBag Makebag void tSDLGenListInfo xBag_ Type extern SDL Boolean GenBag In void xBag Type tSDLGenListInfo extern void GenBag Incl void xBag Type tSDLGenListInfo xBag Type extern void GenBag Del void xBag Type tSDLGenListInfo xBag Type extern void GenBag Incl2 void xBag Type tSDLGenListInfo extern void GenBag Del2 void xBag Type tSDLGenListInfo extern SDL Boolean GenBag_Li tSDLGenListInfo extern SDL Boolean GenBag LE xBag Type xBag Type tSDLGenListInfo extern void GenBag And xBag Type xBag Type tSDLGenListInfo xBag Type extern void GenBag Or xBag Type xBag Type tSDLGenListInfo xBag Type extern SDL Integer GenBag Length xBag Type tSDLGenListInfo extern void GenBag Take xBag Type tSDLGenListInfo void extern void GenBag Take2 xBag Type SDL Integer tSDLGenListInfo void xBag_Type xBag Type e Parameter of type int in GenBag_Makebag GenBag_In GenBag_Incl GenBag_Del GenBag_Incl2 GenBag_Del2 The address of the component value Result of type int in GenBag_Take GenBag_Take2 The address of the component value e Parameters of type tSsDLGenListInfo The t
133. sidered as an enumeration type e Syntypes of integer character Boolean Octet Bit and enumera tion types The subtypes may only have one range condition that specifies a closed interval of values then the SDL array is translated to a struct containing an element which is an array in C If the index sort is not one of the sort in the enumeration above the SDL array is translated to a linked list The list head contains the default val ue for all possible indexes while the list elements contain value pairs index_value component_value for each index having a component value not equal to the default value Example 353 Array SYNTYPE Syn integer CONSTANTS 0 10 Telelogic Tau 4 5 User s Manual 2601 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2602 ENDSYNTYPE NEWTYPE Arr ARRAY Syn real ENDNEWTYPE is translated to typedef SDL Integer Syn typedef struct SDL Real A 11 Arr All the properties of an array in SDL are preserved in the C code The predefined operators extract and modify are implemented as com ponent selection of the array in C in the same way as in SDL so if AVar is a variable of type Arr and Index is a valid index expression then Av ar Index in SDL is translated to AVar A Index in C In the case of a link list implementation of the array component selection is made through function calls The predefined operator make which is a constructor of
134. sistency between the specification of implementation techniques and the actual code included in the body section This check is to gether with checking the C code for syntactic and semantic errors left to the C compiler Unfortunately it is not possible to have C comments within the code that is included in a ADT directive as SDL and C use the same symbols for start and end of comments If a C comment is included the SDL An alyzer will consider the end of the C comment as the end of the SDL comment Instead a C macro called COMMENT can be used according to the examples below Note that there might be some compiler depen dent restriction of the character set allowed within the COMMENT macro For example the character might not be allowed Example 360 Comment in ADT COMMENT This is a comment COMMENT These comments may not contain commas and should have a backslash at each line break COMMENT By having double parenthesis any text can be entered into the comments Some compilers might not allow everything The function headings representing literals and operators are deter mined by their corresponding definition in SDL The number of param eters their types the result type of the function and function name are all defined in SDL In the example above where the struct Str is de fined there are two literals Litl and Lit2 and two operators Op1 Str integer gt Str and Op2 Str Boolean gt
135. stem you do not always use all avail able SDL operators The Cbasic Cadvanced SDL to C Compiler re moves the declarations of unused operators thus minimizing the code size of the generated application Unused operators that are removed are e operators in predefined data types for example substring concate nate length in the newtype Charstring etc e operators defined in the predefined generators String Array Pow erset Bag e special operators and help functions like assign equal default make extract modify free The Cbasic Cadvanced SDL to C Compiler performs the following steps to optimize the code 1 Every C function that implements an operator is surrounded by an ifndef definition Example 343 The ifndef definition ifndef XNOUSE AND BIT STRING function implementing the operator Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types endif 2 During the code generation the usage of the operators in the trans lated SDL transitions is recorded 3 The interdependencies between different operators are updated For instance an equal operator for a struct type may depend on equal operators for all its component types 4 For each operator that is found to be unused a define definition is generated that removes the code for that operator All the defines are placed in a file called sdl_cfg h Example 344 The define command define XNOUSE AND BIT STRING
136. t a type in this list Table 1 Types Passed as Addresses 2606 Telelogic Tau 4 5 User s Manual July 2003 Abstract Data Types Types passed as values simple types Integer Real Natural Boolean Character Time Duration Pld Charstring Bit Octet TASString NumericString PrintableString VisibleString NULL Enumeration types Instantiations of generator Ref Own ORef Syntypes of a type in this list Types that inherit a type in this list Table 2 Types Passed as Values Note For types represented as pointers Charstring including its syn types Ref Own ORef the pointers not the addresses of the point ers are passed as parameters July 2003 Telelogic Tau 4 5 User s Manual 2607 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2608 The parameter passing for operators implemented in C works as follows for Cmicro the mechanism described below is also used for operator di agrams and procedures In parameters e Passed as a value in C if the type is in the list Passed as value This means that the parameter type in C is the same type as in SDL e Passed as an address in C if the type is in the list Passed as ad dress This means that the C parameter is SDL_type if the type in SDL is SDL_type In Out parameters Parameters are always passed as addresses i e the C parame
137. ter is SDL_type if the type in SDL is SDL_type Operator result e Ifthe result type is in the list Passed as value the C function result type will be the same as in SDL e If the result type is in the list Passed as address two things are changed Firstly the C result type will be SDL_type i e the re sult will be an address Secondly an extra parameter is inserted last in the C function This parameter is also of type SDL_type and is used as a location to store the result of the function At an operator call a dummy variable should be passed as the actual parameter The C function can then use this to store the result of the operator and should return the variable again as result Example 356 Assume that struct is a newtype struct in SDL operators X integer in out integer gt integer Y structl in out structl gt structl The C prototypes for these operators are SDL_Integer X SDL Integer SDL Integer j structl Y structl structl structl The example implementations are SDL Integer X SDL_Integer Paraml SDL Integer Param2 Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types Param2 Param2 Paraml1 return Param2 structl Y structl Paraml structl Param2 structl Result implementation assuming structl to contain two integers Param2 comp1 Param2 comp1 Param1 comp1 Param2 comp2 Param2 co
138. the addresses of the point ers In case of an optional field or a field with an initializer a 0 or T is passed to indicate if a value for the component is present or not If 1 is passed the value follows as next parameter If 0 is passed no value is present in the actual parameter list GenericMakeChoice This function is used for choice types e The first void parameter is the address of a variable where the re sult should be placed This value is also returned e The tSDLTypelnfo parameter is the address to the type info node for the type to be created e The int parameter decides which choice component that is present Telelogic Tau 4 5 User s Manual 2629 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2630 e The last void parameter is the address of the value GenericMakeOwnkef This function is used for instantiations of gen erators Own and Ref e The tSDLTypelnfo parameter is the address to the type info node for the type to be created e The void parameter is the address to the value that should be as signed to the memory allocated by this function GenericMakeArray This function is used for instantiations of the gen erators Array Carray and GArray e The first void parameter is the address of a variable where the re sult should be placed This value is also returned e The tSDLTypelnfo parameter is the address to the type info node for the type to be created e
139. tive the object files that are to be part in the link operation should be given between quotes as in the example above These files will be included in the definition of the link operation in the generated m file The make file will however not include any definition of how to com pile the corresponding source files as it is impossible for the code gen erator to know the compilation options or even what compiler the user wants A user that knows how to interface routines in other languages in a C program can with this knowledge and the WITH directive link modules written in another language together with the generated pro gram Note The WITH directive will only affect the generated make file There will be no change in the generated C code when a WITH directive is introduced Telelogic Tau 4 5 User s Manual July 2003 Directives to the Cadvanced Cbasic SDL to C Compiler July 2003 Naming Tasks in Trace Output Directive ID To simplify the identification of a TASK in a trace printout the Cad vanced Cbasic SDL to C Compiler uses the variable on the left hand side of the first assignment statement or the first informal text in the task symbol A user that is not satisfied with this can name the tasks using ID directives An ID directive should contain the character string that is to be used as identification in trace printouts Example 393 ID Directive ID Identification of task The code generator
140. tors in the predefined generators e More about Abstract Data Types on page 2634 comprises infor mation on how to change the implementation of a data type SDL Data Types Information on SDL data types and operators seen from the SDL point of view is available in Using SDL Data Types on page 42 in chapter 2 Data Types in the SDL Suite Methodology Guidelines Although this section does not discuss the use of generic functions it provides the framework for SDL data types and operators In some circumstances it might be better to rewrite a data type or operator in SDL than to fix the problems in C A number of extensions and improvements have been included in the support for data types Type Info Nodes For more information on the contents of the type info nodes please see Type Info Nodes on page 2979 in chapter 62 The Master Library in the User s Manual This section does not cover migration aspects but provides implementation details for an interested reader Migrating Strategy Overview The common problems that might occur when migrating a system from the old style operator implementation to the generic functions imple mentation can be divided into two groups Telelogic Tau 4 5 User s Manual 2683 Chapter 57 The Cadvanced Cbasic SDL to C Compiler e Some user defined SDL operators have changed their prototypes in C This means that user provided implementations of the operators have
141. tring yEQF SDL Charstring yNEgF_SDL_Charstring July 2003 Telelogic Tau 4 5 User s Manual 2589 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2590 SDL name operator Integer C name expression operator SDL_Integer 0 1 etc SDL_INTEGER_LIT 0 SDL_INTEGER_LIT 1 etc xPlus SDL Integer monodic dyadic xMonMinus SDL Integer xMinus SDL Integer xMult_SDL_ Integer xDiv_SDL_ Integer mod xMod_SDL_Integer rem xRem_SDL_ Integer float xFloat_SDL_ Integer fix xFix SDL Integer lt lt gt gt xLT_SDL_ Integer xLE SDL Integer xGT_SDL_ Integer xGE SDL Integer yEqF SDL Integer yNEQqF SDL Integer Natural SDL Natural Real SDL Real 12 45 SDL REAL LIT 12 45 12 450000000 monodic dyadic xMonMinus_SDL Real xMinus_ SDL Real xPlus SDL Real xMult_SDL_ Real xDiv_SDL_ Real Ly Sh Sy SS xLT_SDL Real xLE_SDL Real xGT SDL Real xGE SDL Real yEQgF SDL Real yNEgF_ SDL Real Telelogic Tau 4 5 User s Manual July 2003 Abstract Data Types SDL name operator C name expression operator July 2003 Telelogic Tau 4 5 User s Manual Pid SDL_PId Null SDL_NULL So Ve yEQF_ SDL PId yNEqF SDL PId Duration SDL Durat
142. troducing measurements of interesting data such as queue lengths delays and so on into the SDL model it is possible to gather statistical data during the execution of the simulation In chapter 64 The Telelogic Tau 4 5 User s Manual 2563 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2564 Performance Library you can find a description of the performance simulation facilities To simplify this kind of simulation a number of SDL abstract data types and their implementations have been developed where for example random number generation and handling of queues are supported Please see chapter 63 The ADT Library Validation The SDL Validator uses the code produced by the Cadvanced Cbasic SDL to C Compiler to form a program suitable for validation of an SDL system The Validator uses state space exploration and can be used to e Find run time errors e Verify MSCs against the SDL system e Verify user defined rules The Validator is described in chapter 53 The SDL Validator Communicating Simulations You can specify that a generated C program should be able to commu nicate over the PostMaster which is the mechanism used for communi cation between the SDL suite tools Signals sent from the SDL system the generated program to the environment and signals coming to the SDL system from the environment can be handled This facility makes it for example possible to develop simulation programs for two com mu
143. uations where the time or order of actions in different process instances is of vi tal importance Example 338 Scheduling Anexample of such a situation is Suppose a process instance A outputs two signal instances during the same transition one to process instance B and one to process instance C During the corresponding transitions of B and C a signal instance is sent to process instance D If the behavior of the system is dependent on the order in which the sig nal instances are received in the input port of D this is a hazard situation Telelogic Tau 4 5 User s Manual 2577 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2578 where the execution speed of process instances and the delay of signals in channels will determine the behavior The way to handle such a situ ation would be to manually decide the order in which transitions should be executed As the Cadvanced SDL to C Compiler is also intended to generate ap plications process priority has been introduced as an additional feature For more information about how to assign priorities to processes see sub section Assigning Priorities Directive PRIO on page 2667 The Ready Queue The ready queue is a queue containing all process instances which have received a signal that can cause a transition but which have not yet completed that transition The ready queue is ordered firstly according to the priority and secondly according to insert time that is a
144. ur own equal function it must be implemented as a function as the address of the function will be stored in the type info node for the data type so GenericEqualSort can call it to handle sub components of this type An equal function has the following heading SDL_ Boolean yEq_ SortName SortName yExpr1 SortName yExpr2 It should return true or false depending on if the two values passed as parameters are equal or not If the parameters contain pointers it might be necessary to free these values please see the discussion on general parameters to operators in Other Types Containing Pointers on page 2620 Free of Dynamic Memory This section describes how dynamic memory if used for the type will be released for reuse when it is no longer needed Type Interpretation F B Generate heading but no body of the free function yFree_ SortName F A Generate neither heading nor body of the free function F S Use the function GenericFreeSort F Same as F B Do not use free function If you define your own free function it must be implemented as a func tion as the address of the function will be stored in the type info node for the data type so GenericFreeSort can call it to handle subcompo nents of this type A free function should have the following prototype void yFree_ SortName void yVar The function should take the address to a pointer return the alloc
145. uture assignments i e corresponds to the values V and L for the first character in a C string representing the Charstring sort A typical case is a normal assignment statement in SDL e TMP an object should become temporary if it is not assigned to any persistent variable and therefore should not be copied in subsequent assignments i e corresponds to the value T for the first character in a C string representing the Charstring sort A typical case is a re sult value from an operator What should be done with the old value referenced by the left hand side variable Normally free should be performed on the value as otherwise there would be a memory leak However when initializing a variable no free ought to be performed as free might be called on a random address Two different possibilities exists FR free old value NF do not free old value Telelogic Tau 4 5 User s Manual July 2003 Abstract Data Types The third assignment property parameter in the GenericAssignSort function should be given a value according to the ideas given above preferably using the macros indicated define XASS AC ASS FR int 25 define XASS MR ASS FR int 26 define XASS AR ASS FR int 28 define XASS AC TMP FR int define XASS MR TMP FR int 18 define XASS AR TMP FR int define XASS AC ASS NF int 9 define XASS MR ASS NF int 10 define XASS AR ASS NF int 12 define XASS AC TMP NF int define XAS
146. will use the first ID directive it finds in a TASK if any An ID directive may be placed e First in the task in PR that is just after the keyword TASK e Immediately before or just after a comma separating two assign ments or two informal texts e Last in a task in PR that is just before the semicolon e Directly after the semicolon this position is only available in SDL PR Directive C SYNT SYNTNN ASN1 These directives are used to pass information from the tools generating SDL from other languages for example for C a h file or ASN 1 The C and the ASN 1 directive will be inserted after the semicolon ending the package definition or after the package name package asnl_module ASN 1 Module Name package asnl_ module ASN 1 Module Name The ASN 1 directive contains the ASN 1 module name and the C di rective contains the name of the originating h file The SYNT directive and its special form the SYNTNN directive are used in a package generated from C to indicate which SDL sorts that are synthesized i e which sorts that where needed in SDL but do not have a name and definition in C As the originating h file is included in the generated code with a include no typedefs should be generated for the non SYNT sorts while typedefs have to be generated for the synthesized sorts The SYNT directive is inserted directly after the name of the newtype or syntype Telelogic Tau 4 5 User
147. xamples Example 368 Equal Test on Charstring Sort If the c operator is used to check if two charstrings are equal then the actual test that is performed is to see if the two pointer values to the data areas representing the characters in the string are equal To check if the characters in the charstrings are equal the equal function should be used yEGF SDL _Charstring Telelogic Tau 4 5 User s Manual 2619 Chapter 57 The Cadvanced Cbasic SDL to C Compiler 2620 Example 369 Assignment on Charstring Sort If the C assignment operator is used to assign the value of one char string variable C1 to another charstring variable C2 then two things will go wrong 1 The memory used to represent the old value of C1 is lost and can never be reused 2 Cl and C2 now refer to the same memory area which means that if one of the variables is changed the other will also be changed This leads to unpredictable behavior of the program The correct way to handle assignment of charstrings is to use the rou tine yAssF_SDL_Charstring The problems mentioned above can of course also occur if a struct or array containing charstring components or subcomponents is handled carelessly It is for example necessary to use the generic equal and as sign functions to perform equal test and assignment To avoid problems one should be aware that Charstring is implemented as char in C and take the consequences thereof There are a
148. ype info node e Parameters of type xBag_Type after the type info node The address where the result should be stored This address is returned by the function e Parameters of type void after the type info node The address where the result should be stored This address is returned by the function e Other xBag_Type parameters Bag Powerset in parameters Telelogic Tau 4 5 User s Manual July 2003 July 2003 Abstract Data Types String The following Generic functions are available for String instantiations A String is implemented as a linked list define GenString Emptystring SDLInfo Result memset void Result 0 SDLInfo gt SortSize extern void GenString MkString void tSDLGenListInfo xString Type extern SDL Integer GenString Length xString Type tSDLGenListInfo extern void GenString First xString Type tSDLGenListInfo void extern void GenString Last xString Type tSDLGenListInfo void extern void GenString Concat xString Type xString Type tSDLGenListInfo xString Type extern void GenString SubString xString Type SDL_ Integer SDL Integer tSDLGenListInfo xString Type extern void GenString Append xString Type void tSDLGenListInfo extern void GenString Extract xString Type SDL Integer tSDLGenListInfo e Parameter of type void in GenString_MkString GenString_Append Address of component value e Par

Download Pdf Manuals

image

Related Search

Related Contents

les accueils périscolaires  Logitech UE 9000  取扱説明書  Manual - Data Support Company  How to Remote Debug on Windows-CE devices with Microsoft  Manuel D`Installation et D`Utilisation  MEDIA Distribution Cinema Selective Support eForm 2009 User Guide  IEEE 802.11 b/g PCI-Express 1X Wireless Card AW  

Copyright © All rights reserved.
Failed to retrieve file