Pragmas

From STRIDE Wiki
Revision as of 16:45, 5 July 2015 by Marku (talk | contribs)
Jump to: navigation, search

The SCL pragmas are designed to allow annotation of C language constructs in such a way as to identify and define messages, function calls, and test units so that they can be transparently intercepted and remoted.

scl_function

The scl_function pragma allows the user to capture a function. When captured for the purpose of interception (intercept-able) the optional arguments are used to specify how the intercept should be executed.

Syntax

#pragma scl_function(function-name [,context, name-mangling, group-id])


Parameters Type Description
function-name Identifier Name of the function to capture.
context String Optional. Context in which the function is going to be intercepted. Possible values are "REFERENCE" - intercept at the function call (i.e. where the function is called) or "DEFINITION" - intercept at the function definition (i.e. where the function is implemented).
name-mangling String Optional. Type of name mangling to be used when intercepted. Possible values are "EXPLICIT" or "IMPLICIT". If the context argument is defined the default will be IMPLICIT. Note that if EXPLICIT is set the srTEST_INTERCEPT(<function_name>)" macro is required.
group-id String Optional. User defined identifier representing the group to which this function belongs when enabling interception. The default group-id is set to STRIDE_TEST_GROUP.


Notes

  • The function must be declared as a designator with external linkage.
  • A compilation error is reported if an attempt is made to capture a function more than once.

Examples

Using the defaults for IMPLICIT and STRIDE_TEST_GROUP when capturing boo

int foo(int x);

void boo(void);

#pragma scl_function(foo)
#pragma scl_function(boo, "DEFINITION")


Setting a specific GROUP ID

void boo(void);

#pragma scl_function(boo, "DEFINITION", ''IMPLICIT'', ''MY_TEST_GROUP'')


scl_cast

Constraining is the transformation of a data type so that it behaves like another data type. There are two forms of constraining: type constraining and value constraining (see scl_values pragma).

Type constraining, as in the C language, has a source type and a destination type. The source type is the data type that is originally specified (e.g., written in the header file). The destination type is the data type into which the source type is being transformed.

The scl_cast pragma is used for type constraining. It would commonly be used to map enumerations to other types, or to map a void pointer. The STRIDE host environment treats the constrained (or casted) field as if it were the new type, but the original type size is maintained.

Syntax

The following form changes the type inside the specified container (the function or structure):

#pragma scl_cast(global-type-specifier, cast-type)

The following form changes the type globally:

#pragma scl_cast(container-specifier, field-specifier, cast-type)
Parameters Type Description
container-specifier String Name of the container of the field to be cast
field-specifier String Name of the field to be cast
cast-type String Name of the new type for the cast result
global-type-specifier String Name of the global type to be cast

Notes

  • scl_cast() can only be used to cast items that are of exactly the same size.
  • scl_cast() can only be applied to the integral type and pointer type instances, or typedef names for integral types or pointer types. The type-specifier must designate a pointer type or integral type.
  • scl_cast() can be used to cast a data item of type void* to a union type, if all members of the union are of type pointer.
  • scl_cast() cannot be applied to bit fields.
  • An error will result if scl_cast() is applied to a set of runtime values that intersects with the set of values explicitly specified by any pragma that has appeared earlier (by way of lexical position) in the source code. In other words, scl_cast() cannot be used to "cast away" information conveyed by previous pragmas. (Refer to section 1.2.16, Absolute Specifiers, in the SCL Reference Guide for a description and definition of runtime value sets.)

Examples

Example 1

int func(void *p); 

#pragma scl_function(func)
#pragma scl_cast(func, p, int *)

Example 2

typedef unsigned int u32_t; 
typedef enum 
{
  ONE = 1, 
  TWO = 2, 
  THREE = 3
} numbers_e; 

// cast occurrences of u32_t to numbers_e
#pragma scl_cast(u32_t, numbers_e)

int func(u32_t x); 
#pragma scl_function(func)