CCR2SR(1)

NAME
ccr2sr - CCR notation to SR code preprocessor

SYNOPSIS
ccr2sr [-e] file.ccr

DESCRIPTION

Ccr2sr converts a program written in CCR (Conditional Critical Region) notation into an equivalent one written in the SR language. The SR program is placed in file.sr, which may then be compiled and linked using sr(1). The -e (experimental) option is for testing ccr2sr.

The exact syntax of the CCR notation can be discerned by examining the CCR programs in the examples directory. Each CCR-notation construct begins with an underscore; CCR code is mixed with regular SR code. Syntactic peculiarities exist to ease implementation.

Ccr2sr translates a CCR resource into an SR global and translates a CCR region statement into code that uses Rem's algorithm. Typically, the rest of the user's code will be a single SR resource program. The resultant SR code should be run on only one virtual machine so that only one global is created. Variables declared within CCR resources can be used only within region statements.

One-dimensional and two-dimensional arrays of CCR resources are supported. The bounds and subscripts for arrays of CCR resources must be integers. In conventional CCR notation (e.g., see Andrews's book), each variable declared within a CCR resource is replicated within each element of the CCR resource array. In the ccr2sr CCR notation, such replication does not occur. Instead, to effect such replication, the programmer needs to augment the declaration of each variable declared within a CCR resource array with array bounds matching those for the CCR resource array; an element of these arrays should be accessed only within a region statement for the corresponding element of the CCR resource. Hence, former simple variables become arrays and former arrays become higher-dimensional arrays. A variable whose declaration is not augmented as described above will be shared between all elements of the CCR resource array, which is not conventional CCR semantics.

A number of syntactic limitations exist to ease the implementation. Do not use names of SR predefined functions or reserved words (e.g., free, exit, or skip) as variable names within CCRs. Do not use identifiers beginning with r_ within CCR code. Do not use any other SR synchronization or return/reply within a CCR program. Do not use the # form of comment; use only the /* */ form, but do not nest comments. Do not use /% or %/. Spaces in source text, even within string literals, between the following pairs of characters will be deleted: / and %, % and /, / and /, [ and ], * and *, ~ and =, and : and =; in addition spaces preceding : and = will also be deleted. Within string literals, use an escape character (\) to retain the desired spacing. Do not use the [a,b] form of subscripting a two-dimensional array as part of a CCR construct (e.g., _region2); instead use the [a][b] form.

The predefined SR procedure nap, which puts the currently executing process to sleep for a while and performs a context switch to another process, is useful in CCR programs to alter the interleaving of process execution. For example, it can be used with the random number functions to obtain different interleavings to test whether a critical section algorithm works. See the programs in the examples directory for examples.

QUICK REFERENCE
_resource(name)
_resource_end(name)

_region(name,when)	use true for when if empty
_region_end(name)

_resource1(name,l1,u1)	one-dim CCR resource name[l1:u1]
_resource_end1(name)

_region1(name,v1,when)	use true for when if empty; v1 is subscript
_region_end1(name,v1)

_resource2(name,l1,u1,l2,u2)	two-dim CCR resource name[l1:u1,l2:u2]
_resource_end2(name)

_region2(name,v1,v2,when)	use true for when if empty; v1 and v2 are subscripts
_region_end2(name,v1,v2)

FILES
file.ccr    CCR source file
file.sr    generated SR source file

SEE ALSO
Gregory R. Andrews and Ronald A. Olsson, The SR Programming Language: Concurrency in Practice. Benjamin/Cummings, 1993, ISBN 0-8053-0088-0.

Gregory R. Andrews, Concurrent Programming: Principles and Practice. Benjamin/Cummings, 1991, ISBN 0-8053-0086-4.

sr(1), cpp(1), csp2sr(1), m2sr(1)

DIAGNOSTICS

Some erroneous CCR code will cause errors from cpp. The line numbers that cpp complains about generally correspond to the ones in the .ccr file. Other than that, ccr2sr does nearly no error checking. To flag some errors, ccr2sr intentionally generates invalid SR code containing the word "ERROR" followed by an explanation. The SR compiler will detect that as an error later.

Other errors in CCR code are detected by the SR compiler. The line numbers for these errors will not correspond to those in the original source file, but they can be mapped back by looking in the generated code file. That file will be rather ugly, but the cause of the error can be found there. To give some help in tracing back errors to the original source file, the generated code file contains comments of the form /*--X--*/, where X is a line number in the original source file. These comments are generated for any construct that the preprocessor replaces by other text. If, for example, the SR compiler reports an error on line 38, then look at line 38 of the generated SR file. If on that line you find the comment /*--12--*/, examine line 12 of the original source file to see the error's cause. If you see no /*--X--*/ comment on the line itself, you should look for the first /*--X--*/ comment that appears above the line and use that number to point you back to the correct line in the original source file.