Changes between Version 45 and Version 46 of IR


Ignore:
Timestamp:
11/24/15 11:37:59 (10 years ago)
Author:
zmanchun
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • IR

    v45 v46  
    1717Example:
    1818{{{
    19 $integer f() {
    20   $real x;
    21   $real y;
    22   $float(16,23) z;
     19\Integer f() {
     20  \Real x;
     21  \Rreal y;
     22  \Float(16,23) z;
    2323 
    2424L1 :
    25   $choose {
     25  {
    2626    $when (g1) stmt1; goto L2;
    2727    $when (g2) stmt2; goto L3;
     
    2929
    3030  { // begin new scope
    31     $real x;
     31    \Real x;
    3232
    3333L2 :
    34     $choose {
     34    {
    3535      $when (g3) stmt3; goto L4;
    3636      ...
     
    4545{{{
    4646{
    47   $integer x=3*y;
    48   $integer a[x+1];
     47  \Integer x=3*y;
     48  \Array(\Integer, x+1) a;
    4949}
    5050}}}
     
    5252{{{
    5353{
    54   $integer x;
    55   $integer a[];
     54  \Integer x;
     55  \Array(\Integer) a;
    5656L1:
    57   $choose { $when ($true) x=3*y; goto L2; }
     57  { $when ($true) x=3*y; goto L2; }
    5858L2:
    59   $choose { $when ($true) a=$initval($integer[x+1]); goto L3; }
     59  { $when ($true) a=\initval(\Array(\Integer, x+1)); goto L3; }
    6060L3:
    6161}
     
    6767The types are:
    6868
    69 * `$bool` : boolean type, values are `$true` and `$false`
    70 * `$proc` : process type
    71 * `$scope` : scope type
    72 * `$char` : character type.  Alternatively, get rid of this and just use an integer type.
    73 * `$bundle` : type representing some un-typed chunk of data
    74 * `$heap` : heap type
    75 * `$range` : ordered set of integers
    76 * `$domain` : ordered set of tuples of integers
    77 * `$domain(n)`, n is an integer at least 1; subtype of `$domain` in which all tuples have arity n.
    78 * `enum` types.
     69* `\Bool` : boolean type, values are `$true` and `$false`
     70* `\Proc` : process type
     71* `\Scope` : scope type
     72* `\Char` : character type.  Alternatively, get rid of this and just use an integer type.
     73* `\Bundle` : type representing some un-typed chunk of data
     74* `\Heap` : heap type
     75* `\Range` : ordered set of integers
     76* `\Domain` : ordered set of tuples of integers
     77* `\Domain(n)`, n is an integer at least 1; subtype of `$domain` in which all tuples have arity n.
     78* `\Enum` types.
    7979 * **different from integers or like C?**
    80 * `$integer` : the mathematical integers
    81 * `$int(lo,hi,wrap)`
    82  * lo, hi are integers, wrap is boolean
    83  * finite interval of integers [lo,hi].  If `wrap` is true then all operations "wrap", otherwise, any operation resulting in a value outside of the interval results in an exception being thrown.
     80* `\Integer` : the mathematical integers
     81* `\Int(lo,hi,wrap)`
     82 * `lo`, `hi` are integers, `wrap` is boolean
     83 * finite interval of integers `[lo,hi]`.  If `wrap` is true then all operations "wrap", otherwise, any operation resulting in a value outside of the interval results in an exception being thrown.
    8484 * **Do we want to allow `lo` and `hi` to be any values of type `$integer`, which means they are dynamic types, like complete array types?**
    85 * `$hint` : Herbrand integers.  Values are unsimplified symbolic expressions.
    86 * `$real` : the mathematical real numbers
    87 * `$float(e,f)`, e, f are integers, each at least 1.  **Same question for e and f as for lo and hi.**
     85* `\Hint` : Herbrand integers.  Values are unsimplified symbolic expressions.
     86* `\Real` : the mathematical real numbers
     87* `\Float(e,f)`, e, f are integers, each at least 1.  **Same question for e and f as for lo and hi.**
    8888 * IEEE754 floating point numbers
    89 * `$hreal` : Herbrand real numbers.  Values are unsimplified symbolic expressions.
    90 * `struct` types
    91  * `struct tag { decl1; ...; decln };` or
    92  * `struct tag;`
     89* `\Hreal` : Herbrand real numbers.  Values are unsimplified symbolic expressions.
     90* `\Struct` types
     91 * `\Struct tag { decl1; ...; decln };` or
     92 * `\Struct tag;`
    9393 * structure type with named fields.  Names may not seem necessary but if you want a subset of CIVL-C...
    9494 * **What about bit-widths?**
    95 * `union`: similar to structs
    96 * `T[]` : array-of-T
    97 * Function<S1,...,Sn;T>
    98  * function consuming S1,...,Sn and returning T.  T can be void.  The actual notation is the horrible C notation.
    99 * `$mem` : type representing a memory set.  May be thought of as a set of pointers.
    100 * `void*` : all pointers, a subtype of `$mem`
    101  * `T*` : pointer-to-T, subtype of `void*`
     95* `\Union`: similar to structs
     96* `\Array(T)` : array-of-T
     97* `\Function(S1,...,Sn;T)`
     98 * function consuming `S1,...,Sn` and returning `T`.  `T` can be void.  The actual notation is the horrible C notation.
     99* `\Mem` : type representing a memory set.  May be thought of as a set of pointers.
     100* `\Pointer(\Void)` : all pointers, a subtype of `\Mem`
     101 * `\Pointer(T)` : pointer-to-T, subtype of `\Pointer(\Void)`
    102102
    103103Type facts:
     
    109109A **type name** is a syntactic element that names a (pure or augmented) type  Examples include `int[]` and `int[n*m]`.  This is the same as in C.
    110110
    111 The expression `$initval(T)` takes a type name and returns the initial value for an object of that type.   The initial value of `$integer` and other primitive (non-compound) types is "undefined".   The initial value of `$integer[]` is an array of length 0 of `$integer`.  The initial value of `$real*` is the undefined pointer to `$real`.    The initial value of `$real[10]` is the array of length 10 in which each element is undefined.  In general, the initial value of an array of length n is the sequence of length n in which every element is the initial value of the element type of the array.   The initial value of a structure is the tuple in which each component is assigned the initial value for its type.
     111The expression `\initval(T)` takes a type name and returns the initial value for an object of that type.   The initial value of `\Integer` and other primitive (non-compound) types is "undefined".   The initial value of `\Array(\Integer)` is an array of length 0 of `\Integer`.  The initial value of `\Pointer(\Real)` is the undefined pointer to `\Real`.    The initial value of `\Array(\Real, 10)` is the array of length 10 in which each element is undefined.  In general, the initial value of an array of length n is the sequence of length n in which every element is the initial value of the element type of the array.   The initial value of a structure is the tuple in which each component is assigned the initial value for its type.
    112112
    113113Example:
    114114{{{
    115115// type definitions
    116 struct S { int a[];}
     116\Struct S { \Array(\Integer) a;}
    117117
    118118// variable decls
    119 int n;
    120 struct S _S_init;
    121 struct S x1;
    122 struct S x2;
     119\Integer n;
     120\Struct S _S_init;
     121\Struct S x1;
     122\Struct S x2;
    123123
    124124// statements (leaving out the chooses and whens for brevity)
    125125n=10;
    126 _S_init=$initval(struct S { int a[n]; };
     126_S_init=\initval(\Struct S { \Array(\Integer, n) a; };
    127127x1=_S_init;
    128128n=20;
     
    148148
    149149* literals
    150  * `$true`, `$false` : values of type `$bool`
    151  * 123, -123, 3.1415, etc. : values of type `$integer`, `$int`, `$real`, `$float`
     150 * `$true`, `$false` : values of type `\Bool`
     151 * 123, -123, 3.1415, etc. : values of type `\Integer`, `\Int`, `\Real`, `\Float`
    152152  * what particular notations for floating values?
    153153 * 'a', 'b', ... UNICODE?
    154  * `(T[]){e0, e1, ...}` : values of type `T[]`
    155  * `(S){e0, ...}` : values of type `S` (struct literal)
    156  * `e1..e2`, `e1..e2#e3` : values of type `$range`
     154 * `\cast(\Array(T), {e0, e1, ...})` : values of type `\Array(T)`
     155 * `\cast(S, {e0, ...})` : values of type `S` (struct literal)
     156 * `e1..e2`, `e1..e2#e3` : values of type `\Range`
    157157 * `($domain){r1,...,rn}` : value of type `$domain(n)`
    158158 * `"abc"` : string literals: value of type `$char[]`
     
    161161 * `NULL` : value of type `void*`
    162162* variables
    163 * `$sizeof(T)` : the size of the named type
    164 * `$sizeof(e)` : the size of the value of expression `e`
    165 * `$initval(T)` : initial value of the named type
    166 * `$defined(e)` : is `e` defined? Type is `$bool`
    167 * `$has_next(dom, i, j, k, …)`: an expression of boolean type, testing if the domain `dom` contains any element after `(i, j, k, ...)`
    168 * `e1+e2` : addition.   One of the following must hold:
     163* `\sizeof(T)` : the size of the named type
     164* `\sizeof(e)` : the size of the value of expression `e`
     165* `\initval(T)` : initial value of the named type
     166* `\defined(e)` : is `e` defined? Type is `$bool`
     167* `\has_next(dom, i, j, k, …)`: an expression of boolean type, testing if the domain `dom` contains any element after `(i, j, k, ...)`
     168* `\add(e1, e2)` : numeric addition. 
    169169 * `e1` and `e2` have the same numeric type.  Note that there are no "automatic conversions" as there are in C.  If the original expressions have different types, explicit casts must be inserted. 
    170  * `e1` has pointer type and `e2` has an integer type.  (Alternatively, we could define a separate function `$pointer_add(p,n)`.)
    171 * `e1-e2` : subtraction
    172 * `e1*e2` : multiplication
    173 * `e1/e2` : division
     170* `\padd(e1, e2)`: pointer addition.
     171 * `e1` has pointer type and `e2` has an integer type.
     172* `\subtract(e1, e2)` : subtraction
     173* `\multiply(e1, e2)` : multiplication
     174* `\divide(e1, e2)` : division
    174175 * If both are integer types, the result is integer division.  Otherwise it is real division.  Need to define what happens for negative integers.
    175 * `e1%e2` : modulus
    176 * `e1[e2]` : array subscript expression.  Note that `e1` must have array type, not pointer type. (This is different from C.)   If `e1` has pointer type, use `*(e1+e2)` instead. 
    177 * `*e` : pointer dereference
    178 * `&e` : address-of
    179 * `!e` : logical not
    180 * `-e` : negative
    181 * (T)e : casts `e` to a value of the named type
     176* `\mod(e1, e2)` : modulus
     177* `\array_subscript(e1, e2)` : array subscript expression.  Note that `e1` must have array type, not pointer type. (This is different from C.)   If `e1` has pointer type, use `\deref(\padd(e1, e2))` instead. 
     178* `\deref(e)` : pointer dereference
     179* `\address_of(e)` : address-of
     180* `\not(e)` : logical not
     181* `\neg(e)` : negative
     182* `\cast(T, e)` : casts `e` to a value of the named type
    182183 * need to list all of the legal casts and what they mean exactly
    183184 * cast of integer to array-of-boolean, and vice-versa?
    184 * `e1==e2`, `e1!=e2`
    185 * `e1&&e2`, `e1||e2`
    186 * `e1?e2:e3`
    187 * `e1<e2`, `e1<=e2`
     185* `\eq(e1, e2)`, `\neq(e1, e2)`: equality/inequality test
     186* `\and(e1, e2)`, `\or(e1, e2)`: logical and/or operation
     187* `\cond(e1, e2, e3)`: conditional expression, equivalent to `e1?e2:e3` in C.
     188* `\lt(e1, e2)`, `\lte(e1, e2)`: less than/less than or equal to
    188189* `e0(e1,...,en)` : a function call where `e` must evaluate to an abstract or pure system function
    189 * `$forall`, `$exists` :  `$forall {int i | e0} a[i] >= 0`
     190* `\forall`, `\exists` :  `\forall {\Integer i | e0} e1` or `\forall {\Integer i| e0}`
    190191* `e1.i`, some natural number i (tuple read)
    191192* `e1&e2`, `e1|e2`, `e1^e2`, `~e1` : bit-wise operations: arguments are arrays of booleans