source: CIVL/notes/notes.txt@ 95a2a9e

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 95a2a9e was ee41939, checked in by Stephen Siegel <siegel@…>, 13 years ago

Implemented sizeof (but need tests), corrected error in dynamicStruct.cvl example (sum is n*(n-1)/2, not n*(n+1)/2), other minor improvements.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@168 fb995dde-84ed-4084-dfe6-e5aef3e2452c

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