| 1 |
|
|---|
| 2 | For implementing malloc:
|
|---|
| 3 |
|
|---|
| 4 | Add sizeof expression in model:
|
|---|
| 5 | CIVLType getType();
|
|---|
| 6 | [do we also need sizeof(expr)? -- that's different!]
|
|---|
| 7 |
|
|---|
| 8 | For primitive types, add a method:
|
|---|
| 9 | NumericExpression getSizeof();
|
|---|
| 10 |
|
|---|
| 11 | Create a symbolic constant for each primitive type, of type int,
|
|---|
| 12 | named SIZEOF_INT, etc. Set this in model factory.
|
|---|
| 13 |
|
|---|
| 14 | In Evaluator: as a side-effect, if a sizeof expression is ever evaluated,
|
|---|
| 15 | add some facts about it to the path condition: sizeof(...)>0,
|
|---|
| 16 | maybe sizeof(char)=1 ?
|
|---|
| 17 |
|
|---|
| 18 | Evaluator: for primitive types, get it from type.
|
|---|
| 19 | Otherwise, compute: for arrays, multiply extent and sizeof
|
|---|
| 20 | element type (evaluating extent). For all others (records,
|
|---|
| 21 | pointers) use an uninterpreted function sizeof(...) which
|
|---|
| 22 | takes a DynamicType and returns int.
|
|---|
| 23 |
|
|---|
| 24 | Add a MallocStatement to the model. Example
|
|---|
| 25 | (double*)malloc(&h, sizeof(double)*10).
|
|---|
| 26 | - int getMallocId();
|
|---|
| 27 | - Expression getHeapPointerExpression(); // &h
|
|---|
| 28 | - CIVLType getStaticElementType(); // double
|
|---|
| 29 | - SymbolicType getDynamicElementType() // symbolic real
|
|---|
| 30 | - SymbolicType getDynamicObjectType(); // symbolic array of real
|
|---|
| 31 | - Expression getSizeExpression(); // sizeof(double)*10
|
|---|
| 32 | - SymbolicExpression getUndefinedObject(); // symbolic constant UNDEFINED
|
|---|
| 33 | // of type array of real
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | During model building, count the malloc statements as they are
|
|---|
| 39 | encountered and assign each a unique ID.
|
|---|
| 40 |
|
|---|
| 41 | Complete the $heap type:
|
|---|
| 42 | For each i, you have the static CIVL type T_i and the
|
|---|
| 43 | __malloc__ function. Compute the most general symbolic
|
|---|
| 44 | type t_i by translating t_i and using incomplete types
|
|---|
| 45 | for arrays. Store t_i in the malloc call object.
|
|---|
| 46 | let $heap be the symbolic type which is the tuple type
|
|---|
| 47 |
|
|---|
| 48 | [array of array of t1,
|
|---|
| 49 | array of array of t2,
|
|---|
| 50 | array of array of t3, ...]
|
|---|
| 51 |
|
|---|
| 52 | Initial value:
|
|---|
| 53 |
|
|---|
| 54 | [array of length 0, array of length 0, ...]
|
|---|
| 55 |
|
|---|
| 56 | Semantics:
|
|---|
| 57 | to execute a malloc statement with malloc index i:
|
|---|
| 58 | let h be the result of evaluating the heap argument. *h is a tuple.
|
|---|
| 59 | (*h).i is a concrete array. Let l be its concrete length.
|
|---|
| 60 | create a new symbolic constant whose name is a function of
|
|---|
| 61 | the pid, dynamic scope id, heap variable ID, index i, and
|
|---|
| 62 | l. The type of this new symbolic constant is array of t_i
|
|---|
| 63 | of length arg/sizeof(t+i), where arg is the result of evaluating
|
|---|
| 64 | the size argument. Check that it evenly divides, and log
|
|---|
| 65 | an error if it might not. Now append this symbolic constant
|
|---|
| 66 | to the concrete array. [Really need a method in SARL to do this.]
|
|---|
| 67 | Anyway, since it is concrete, get its sequence and append on to that.
|
|---|
| 68 | Return the reference with tree:
|
|---|
| 69 | - ref to heap (h)
|
|---|
| 70 | - tuple component ref (i)
|
|---|
| 71 | - array element reference (l)
|
|---|
| 72 | - array element reference (0)
|
|---|
| 73 | which is a reference to the first element of the newly allocated
|
|---|
| 74 | array.
|
|---|
| 75 |
|
|---|
| 76 | free: sets the value in the heap array to some symbolic constant
|
|---|
| 77 | UNDEFINED of type array of t_i.
|
|---|
| 78 |
|
|---|
| 79 | Canonicalization: map
|
|---|
| 80 | Ref[h,i,l,0] -> Ref[h,i,l',0]
|
|---|
| 81 | H_p_s_v_i_l -> H_p_s_v_i_l' (symbolic constants)
|
|---|
| 82 | Perform substitution on the state
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 | ---
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | Think about moving more stuff into model factory, like pointer value
|
|---|
| 89 | manipulation
|
|---|
| 90 |
|
|---|
| 91 | better printing of model
|
|---|
| 92 |
|
|---|
| 93 | better printing of states during execution
|
|---|