Introduction
To allow the user to write programs which run on a system with a partitioned cache, a compiler is supplied which compiles a high level language into an assembly language suitable for the target machine.This high level language, from here on refered to as PRE, is a provides an easy to understand syntax that combines elements from C and Occam. Aside from normal program operation, useful items of information, such as the type of accesses that will be made to a variable, are contained within a program written in PRE language. The compiler uses this information as a basis for its control policy for the partitioned cache.
Because the PRE language is very similar to C, it may be helpful to read a good book on C programming before this document if you have not encountered the language before.
Brian W Kernighan and Dennis M Ritchie
The ANSI C Programming Language (2nd edition)
Prentice Hall Software Series
ISBN 0-13-110362-8
1988
£ 29.95
A program written in the PRE language is made up from the following syntactic elements :
File Name Conventions
Files written in the PRE language are, by convention, appended with a suffix of .pre to distinguish them from other file types.Comments
To provide the programmer with a means of documenting their source code, the PRE language supports C style comments within the program. These comments take the form of single line comments which start with // and continue to the end of the line, and multi line comments wich start with /* and continue until */. Note that unlike C, nested comments are not currently allowed.Data Types
All user defined variables in the PRE language are of numeric, integer type although they can be either scalar or vector in terms of size. This reduces the complexity of the compiler and although it restricts the kind of programs that can be written in the PRE language, the facility to implement new types is left open.To allocate storage space for user variables, the allocation statement is used. This statement tells the compiler the type and name of the variable and the size required by the variable ie. if it is a scalar or a vector of given size. Hence int x allocates a integer scalar variable called x and int[10] y allocates a 10 element integer vector varaible called y.
It is worth taking note that all variables must be allocated in this manner before they are used in any other program construct. Loop counters for bounded loops must be allocated in this same way but can not be assigned to inside the body of the loop.
Expressions
Although you can only have user defined variables of numeric type, there are two types of expression in the PRE language which are numeric and boolean. Both kinds of expressions are combinations, via operators, of constants and user defined variables and the results of function calls, which evaluate into a final value. A simple precedence system is employed while parsing the expressions which dictates which operator will be taken as being more important in the absence of any information conveyed via bracketing.| Precedence | Operator | Operand Type(s) | Operation Performed |
| 1 | +, - | numeric | unary plus and minus |
| 1 | ~ | numeric | bitwise NOT |
| 1 | ! | boolean | logical NOT |
| 2 | *, /, % | numeric | multiplication, division and remainder (MOD) |
| 2 | &, ^ | numeric | bitwise AND and XOR |
| 3 | +, - | numeric | addition and subtraction |
| 3 | | | numeric | bitwise OR |
| 4 | <<, >> | numeric | sign filled (signed) left and right shift |
| 4 | >>> | numeric | zero filled (unsigned) right shift |
| 5 | <, <=, >, >= | numeric | less than, less than or equals. greater than and greater than or equals |
| 6 | !=, == | numeric | not equals and equals |
| 7 | && | boolean | logical AND |
| 8 | || | boolean | logical OR |
Basic Statements
Assignment
Bounded Loop
Using this syntax, the statement x = 0 for 5 { .. } would use the variable x as the loop counter, initialise it to 0 before executing the loop. Each time the loop is executed, the loop counter will be incremented by one with the final value on exit from the statement being calculated by the sum of the initial value and number of iterations.
Unbounded Loop
An unbounded loop uses a booleanExpression as the condition for exiting the loop. Until this condition evaluates as false, the loop will continue to repeatedly execute. It should be noted that because of this, infinite loops can be written which may, under some circumstances, cause the machine to crash.
Conditional
Inline Assembly Language
Procedures
- You must have one procedure with the prototype void main() to act as the entry point to the program.
- Procedures can be recursive.
- Procedures must be uniquely named, ie. all procedure identifiers are unique.
- All arguments are all passed in the same way as Occam. As far as the programmer is concerned this is the same as "by reference" in C, but implemented via a copy back mechanism.
Procedures in the PRE language are the building blocks of a program. You can have any number of procedures, which are defined in a similar way to in C, in your program as long as they are all uniquely named and there is at least one called main which takes no arguments.
Defining Procedures
To define a procedure the user needs to give a procedure prototype followed by a block of code that represents the procedure. The procedure prototype tells the compiler about the name of the procedure and the number, type and name of any parameters as well as the return type. This allows the procedure to be sucessfully referenced from elsewhere in the program. The block of code that represents the procedure is executed when the procedure is called. This block of code can make use of all the parameters by referencing them in the same way as a normal user defined variable.Procedures may be declared external using the extern keyword. A prototype for an external procedure is given so that type checking can be performed but the implementation of the procedure is given else where.
The program can exit from anywhere in the procedure by using the return statement which will return control to where the procedure was called from. Note that if the procedure has a return value a value must be provided and that if no return statement is encountered, the procedure will return when encountering the end of the procedure.
It should be noted that although scalars and one dimensional vectors can be declared as parameters to a procedure, two dimensional vectors can not.
Calling Procedures
A procedure can either be called as a basic statement or as part of an expression, in which case the return type of the procedure can not be void. In either case the calling syntax is the same as C. Type checking is performed on the arguments the users types to pass via the procedure call against the parameters defined in the procedure prototype so that it is not possible to call a procedure with the wrong number or type of arguments or include a function with a void return type in an expression.Arguments passes to a procedure are all passed, as far as the programmer is concerned, "by reference" and so assignments to parameters within the called procedure will effect the value of the arguments in the calling procedure.

