CBMC
cegis.c
Go to the documentation of this file.
1 /* FUNCTION: __CPROVER_danger_execute */
2 
3 #ifndef __CPROVER_cegis_number_of_vars
4 #define __CPROVER_cegis_number_of_vars 2
5 #endif
6 #ifndef __CPROVER_cegis_number_of_consts
7 #define __CPROVER_cegis_number_of_consts 1
8 #endif
9 #ifndef __CPROVER_cegis_number_of_ops
10 #define __CPROVER_cegis_number_of_ops 3
11 #endif
12 #ifndef __CPROVER_cegis_max_solution_size
13 #define __CPROVER_cegis_max_solution_size 1
14 #endif
15 
18 
19 typedef unsigned char opcodet;
20 typedef unsigned char opt;
22 {
27 };
28 
29 #define __CPROVER_cegis_max_instruction 24u
30 
32  unsigned char size)
33 {
34  for (unsigned char i = 0; i < size; ++i)
35  {
36 #define opcode program[i].opcode
38  const unsigned int op0_id=program[i].op0;
39  const unsigned int op1_id=program[i].op1;
40  const unsigned int op2_id=program[i].op2;
41  const unsigned int max_op_index=__CPROVER_cegis_number_of_vars + i;
42  __CPROVER_assume(op0_id < max_op_index && op1_id < max_op_index && op2_id < max_op_index
44  && (opcode > 5u || op0_id <= op1_id) && (opcode < 21u || !op1_id)
45  && (opcode == 9u || !op2_id)
46  && (opcode != 9u || op0_id != op2_id || op1_id <= op2_id));
47  const unsigned int * const op0_ptr=__CPROVER_cegis_OPS[op0_id];
48  const unsigned int * const op1_ptr=__CPROVER_cegis_OPS[op1_id];
49  const unsigned int * const op2_ptr=__CPROVER_cegis_OPS[op2_id];
50  __CPROVER_assume(op0_ptr && op1_ptr && op2_ptr); // No null pointers in op array
51  const unsigned int op0=*op0_ptr;
52  const unsigned int op1=*op1_ptr;
53  __CPROVER_assume((opcode != 19 && opcode != 20) || op1); // Avoid div by 0.
54  const unsigned int op2=*op2_ptr;
55 #define sop0 ((int) op0)
56 #define sop1 ((int) op1)
57 #define sop2 ((int) op2)
58 
59  unsigned int result;
60  if (opcode < 15)
61  if (opcode < 7)
62  if (opcode < 3)
63  if (opcode < 1)
64  __CPROVER_cegis_opcode_0: result=op0 + op1;
65  else if (opcode < 2)
66  __CPROVER_cegis_opcode_1: result=op0 * op1;
67  else
68  __CPROVER_cegis_opcode_2: result=op0 &op1;
69  else
70  if (opcode < 5)
71  if (opcode < 4)
72  __CPROVER_cegis_opcode_3: result=op0 | op1;
73  else
74  __CPROVER_cegis_opcode_4: result=op0 ^ op1;
75  else if (opcode < 6)
76  __CPROVER_cegis_opcode_5: result=op0 != op1;
77  else
78  __CPROVER_cegis_opcode_6: result=!op0 || op1;
79  else
80  if (opcode < 11)
81  if (opcode < 9)
82  if (opcode < 8)
83  {
84  __CPROVER_cegis_opcode_first_7: result=op0 < op1;
85  if (result) result=op0;
86  else __CPROVER_cegis_opcode_last_7: result=op1;
87  }
88  else
89  {
90  __CPROVER_cegis_opcode_first_8: result=op0 > op1;
91  if (result) result=op0;
92  else __CPROVER_cegis_opcode_last_8: result=op1;
93  }
94  else if (opcode < 10)
95  {
96  __CPROVER_cegis_opcode_first_9: if (op0) result=op1;
97  else __CPROVER_cegis_opcode_last_9: result=op2;
98  }
99  else
100  __CPROVER_cegis_opcode_10: result=op0 - op1;
101  else
102  if (opcode < 13)
103  if (opcode < 12)
104  {
105  __CPROVER_cegis_opcode_first_11: result=op1;
106  //result%=sizeof(op0);
107  result%=32u;
108  __CPROVER_cegis_opcode_last_11: result=op0 << result;
109  }
110  else
111  {
112  __CPROVER_cegis_opcode_first_12: result=op1;
113  //result%=sizeof(op0);
114  result%=32u;
115  __CPROVER_cegis_opcode_last_12: result=op0 >> result;
116  }
117  else if (opcode < 14)
118  {
119  __CPROVER_cegis_opcode_first_13: result=op1;
120  //result%=sizeof(op0);
121  result%=32u;
122  __CPROVER_cegis_opcode_last_13: result=op0 >> result;
123  }
124  else
125  {
126  __CPROVER_cegis_opcode_first_14: result=op1;
127  //result%=sizeof(op0);
128  result%=32u;
129  __CPROVER_cegis_opcode_last_14: result=sop0 >> result;
130  }
131  else if (opcode < 19)
132  if (opcode < 17)
133  if (opcode < 16)
134  __CPROVER_cegis_opcode_15: result=op0 <= op1;
135  else
136  __CPROVER_cegis_opcode_16: result=op0 < op1;
137  else if (opcode < 18)
138  __CPROVER_cegis_opcode_17: result=sop0 <= sop1;
139  else
140  __CPROVER_cegis_opcode_18: result=sop0 < sop1;
141  else if (opcode < 23)
142  if (opcode < 21)
143  if (opcode < 20)
144  __CPROVER_cegis_opcode_19: result=op0 / op1;
145  else
146  __CPROVER_cegis_opcode_20: result=op0 % op1;
147  else if (opcode < 22)
148  __CPROVER_cegis_opcode_21: result=-op0;
149  else
150  __CPROVER_cegis_opcode_22: result=~op0;
151  else if (opcode < 24)
152  //__CPROVER_cegis_opcode_23: result=0u;
153  __CPROVER_cegis_opcode_23: result=sop0 == -1;
154  else
155  __CPROVER_cegis_opcode_24: result=op0;
156  //__CPROVER_cegis_opcode_24: result=sop0 != -1;
157 
158  *(unsigned int *)__CPROVER_cegis_RESULT_OPS[i]=result;
159  }
160 }
void __CPROVER_danger_execute(struct __CPROVER_cegis_instructiont *program, unsigned char size)
Definition: cegis.c:31
#define sop1
#define sop0
#define __CPROVER_cegis_max_solution_size
Definition: cegis.c:13
void * __CPROVER_cegis_RESULT_OPS[1]
Definition: cegis.c:17
unsigned char opt
Definition: cegis.c:20
const void * __CPROVER_cegis_OPS[3]
Definition: cegis.c:16
#define __CPROVER_cegis_number_of_vars
Definition: cegis.c:4
unsigned char opcodet
Definition: cegis.c:19
#define opcode
#define __CPROVER_cegis_number_of_consts
Definition: cegis.c:7
#define __CPROVER_cegis_max_instruction
Definition: cegis.c:29
#define __CPROVER_cegis_number_of_ops
Definition: cegis.c:10
void __CPROVER_assume(__CPROVER_bool assumption)