| 1 |
|
|---|
| 2 | For implementing malloc:
|
|---|
| 3 |
|
|---|
| 4 | Add sizeof expression in model.
|
|---|
| 5 |
|
|---|
| 6 | During model building, count the malloc statements.
|
|---|
| 7 | Every time you come to a malloc call, create a new system
|
|---|
| 8 | function:
|
|---|
| 9 |
|
|---|
| 10 | T* __malloc__i($heap *h, int size);
|
|---|
| 11 |
|
|---|
| 12 | where T is obtained from the cast wrapping the malloc
|
|---|
| 13 | and i is the counter.
|
|---|
| 14 | Add this to the model and use this in the translation.
|
|---|
| 15 | Maybe even create a special class for it extending
|
|---|
| 16 | FunctionCall.
|
|---|
| 17 |
|
|---|
| 18 | Complete the $heap type:
|
|---|
| 19 | For each i, you have the static CIVL type T_i and the
|
|---|
| 20 | __malloc__ function. Compute the most general symbolic
|
|---|
| 21 | type t_i by translating t_i and using incomplete types
|
|---|
| 22 | for arrays. Store t_i in the malloc call object.
|
|---|
| 23 | let $heap be the symbolic type which is the tuple type
|
|---|
| 24 |
|
|---|
| 25 | [array of array of t1,
|
|---|
| 26 | array of array of t2,
|
|---|
| 27 | array of array of t3, ...]
|
|---|
| 28 |
|
|---|
| 29 | Initial value:
|
|---|
| 30 |
|
|---|
| 31 | [array of length 0, array of length 0, ...]
|
|---|
| 32 |
|
|---|
| 33 | Semantics:
|
|---|
| 34 | to execute a __malloc__i:
|
|---|
| 35 | let h be the result of evaluating the heap argument. *h is a tuple.
|
|---|
| 36 | (*h).i is a concrete array. Let l be its concrete length.
|
|---|
| 37 | create a new symbolic constant whose name is a function of
|
|---|
| 38 | the pid, dynamic scope id, heap variable ID, index i, and
|
|---|
| 39 | l. The type of this new symbolic constant is array of t_i
|
|---|
| 40 | of length arg/sizeof(t+i), where arg is the result of evaluating
|
|---|
| 41 | the size argument. Check that it evenly divides, and log
|
|---|
| 42 | an error if it might not. Now append this symbolic constant
|
|---|
| 43 | to the concrete array. [Really need a method in SARL to do this.]
|
|---|
| 44 | Anyway, since it is concrete, get its sequence and append on to that.
|
|---|
| 45 | Return the reference with tree:
|
|---|
| 46 | - ref to heap (h)
|
|---|
| 47 | - tuple component ref (i)
|
|---|
| 48 | - array element reference (l)
|
|---|
| 49 | - array element reference (0)
|
|---|
| 50 | which is a reference to the first element of the newly allocated
|
|---|
| 51 | array.
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 | free: sets the value in the heap array to some symbolic constant
|
|---|
| 55 | UNDEFINED of type array of t_i.
|
|---|
| 56 |
|
|---|
| 57 | Canonicalization: map
|
|---|
| 58 | Ref[h,i,l,0] -> Ref[h,i,l',0]
|
|---|
| 59 | H_p_s_v_i_l -> H_p_s_v_i_l' (symbolic constants)
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 | ---
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 | Think about moving more stuff into model factory, like pointer value
|
|---|
| 67 | manipulation
|
|---|
| 68 |
|
|---|
| 69 | better printing of model
|
|---|
| 70 |
|
|---|
| 71 | better printing of states during execution
|
|---|