@@ -66,7 +66,8 @@ let struct_name_to_ident2 = ident_generator "" "struct"
66
66
let struct_field_name_to_ident2 = ident_generator " " " field"
67
67
let backend_ident_of_globvar = ident_generator " var_" " var2"
68
68
let backend_ident_of_funcname = ident_generator " ident_" " function"
69
- let backend_ident_of_tempvar = ident_generator " temp_" " var"
69
+ (* let backend_ident_of_tempvar = ident_generator "temp_" "var" *)
70
+ let backend_ident_of_tempvar = positive_of_int 11
70
71
71
72
let rec gen_ctype =
72
73
let open Ctypes in
@@ -128,7 +129,8 @@ let rec gen_rexpr e =
128
129
let open Language in
129
130
match e with
130
131
| (t , SId(Sglobal,l )) -> Evar (backend_ident_of_globvar l, gen_ctype t)
131
- | (t , SId(Slocal,l )) -> Etempvar (backend_ident_of_tempvar l, gen_ctype t)
132
+ (* | (t, SId(Slocal,l)) -> Etempvar (backend_ident_of_tempvar l, gen_ctype t) *)
133
+ | (t , SId(Slocal,l )) -> Etempvar (backend_ident_of_tempvar, gen_ctype t)
132
134
| se -> raise (Failure (" Not implemented: " ^ string_of_sexpr se))
133
135
134
136
let rec gen_lexpr e =
@@ -142,7 +144,8 @@ let rec gen_lexpr e =
142
144
| true -> Econst_int256 (Int256. one, Tint (I256 , Unsigned ))
143
145
| false -> Econst_int256 (Int256. zero, Tint (I256 , Unsigned )) )
144
146
| (t , SId(Sglobal,l )) -> Evar (backend_ident_of_globvar l, gen_ctype t)
145
- | (t , SId(Slocal,l )) -> Etempvar (backend_ident_of_tempvar l, gen_ctype t)
147
+ (* | (t, SId(Slocal,l)) -> Etempvar (backend_ident_of_tempvar l, gen_ctype t) *)
148
+ | (t , SId(Slocal,l )) -> Etempvar (backend_ident_of_tempvar, gen_ctype t)
146
149
| (t1 , SBinop ((t2 , se1 ), op , (t3 , se2 ))) -> Ebinop (gen_binop op, gen_lexpr (t2, se1), gen_lexpr (t3, se2), gen_ctype t1)
147
150
| (t , SComparsion ((t1 , se1 ), op , (t2 , se2 ))) -> Ebinop (gen_binop op, gen_lexpr (t1, se1), gen_lexpr (t2, se2), gen_ctype t)
148
151
| (t , SMapexpr((t1 , se1 ), selist )) ->
@@ -182,7 +185,8 @@ let gen_params sparams =
182
185
let open Datatypes in
183
186
let open Globalenvs.Genv in
184
187
let cvt = function
185
- | Var (Id str , typ ) -> Some (Coq_pair (backend_ident_of_tempvar str, gen_ctype typ))
188
+ (* | Var (Id str , typ ) -> Some (Coq_pair(backend_ident_of_tempvar str , gen_ctype typ )) * )
189
+ | Var (Id str , typ ) -> Some (Coq_pair (backend_ident_of_tempvar, gen_ctype typ))
186
190
| _ -> None
187
191
in
188
192
coqlist_of_list (filter_map cvt sparams)
@@ -247,13 +251,21 @@ let gen_methoddef m =
247
251
{
248
252
fn_return = ret_type m.sreturns;
249
253
fn_params = gen_params m.sparams; (* (ident, coq_type) prod list; *)
250
- fn_temps = Coq_nil ; (* coqlist_of_list (gen_tempenv ((dest,mt.aMethodReturnType.aTypeCtype) :: gen_cmd_locals m.aMethodBody dest))*)
251
- fn_body = (if has_return then
254
+ (* fn_temps = Coq_nil; coqlist_of_list (gen_tempenv ((dest,mt.aMethodReturnType.aTypeCtype) :: gen_cmd_locals m.aMethodBody dest)) *)
255
+ fn_temps = coqlist_of_list [Coq_pair (positive_of_int 10 , gen_ctype (Void " void" ))];
256
+ fn_body = gen_storage_cmd m.sstorage_body
257
+ (* (if has_return then
252
258
Ssequence(Ssequence(gen_guard_cmd m.sguard_body, gen_storage_cmd m.sstorage_body), gen_return_cmd m.sreturns)
253
259
else
254
- Ssequence (gen_guard_cmd m.sguard_body, gen_storage_cmd m.sstorage_body))
260
+ Ssequence(gen_guard_cmd m.sguard_body, gen_storage_cmd m.sstorage_body)) *)
255
261
}
256
262
263
+ (* { fn_return = Tvoid;
264
+ fn_params = (11,TInt (SIZE,SIGNEDNESS))::nil;
265
+ fn_temps = (10,Tvoid)::nil;
266
+ fn_body = Sassign(Evar(550,TInt (SIZE,SIGNEDNESS)),Etempvar(11,TInt (SIZE,SIGNEDNESS)))
267
+ } *)
268
+
257
269
(* let gen_methoddef objname m =
258
270
let open Datatypes in
259
271
let mt = m.aMethodType in
@@ -273,15 +285,74 @@ let gen_methoddef m =
273
285
body)
274
286
} *)
275
287
288
+ (* Print MiniC expressions/statements, for debugging purposes. *)
276
289
277
290
291
+ let rec string_of_ctype =
292
+ let open Ctypes in
293
+ function
294
+ | Tvoid -> " Tvoid"
295
+ | Tint (_ ,_ ) -> " TInt (SIZE,SIGNEDNESS)"
296
+ | Tpointer _ -> " Tpointer"
297
+ | Tarray (t ,z ) -> (" Tarray (" ^ string_of_ctype t^ " ," ^ string_of_int(int_of_z z)^ " )" )
298
+ | Thashmap (t1 ,t2 ) -> (" Thashmap(" ^ string_of_ctype t1^ " ," ^ string_of_ctype t2^ " )" )
299
+ | Tfunction (ts ,t ) -> " Tfunction (TYPES,TYPE)"
300
+ | Tstruct (id ,flds ) -> " Tstring (IDENT, FIELDS)"
301
+ | Tunion (id ,flds ) -> " Tunion (IDENT, FIELDS)"
302
+ | Tcomp_ptr id -> " Tcomp_ptr ID"
303
+
304
+ let rec string_of_expr = function
305
+ | Econst_int (z , t ) -> (" Econst_int (" ^ string_of_int (int_of_z z) ^ " ," ^ string_of_ctype t^ " )" )
306
+ | Econst_int256 (z , t ) -> (" Econst_int (" ^ string_of_int (int_of_z z) ^ " ," ^ string_of_ctype t^ " )" )
307
+ | Evar (id ,t ) -> (" Evar(" ^ string_of_int (int_of_positive id)^ " ," ^ string_of_ctype t^ " )" )
308
+ | Etempvar (id ,t ) -> (" Etempvar(" ^ string_of_int (int_of_positive id)^ " ," ^ string_of_ctype t^ " )" )
309
+ | Ederef (e ,t ) -> (" Ederef(" ^ string_of_expr e ^ " ," ^ string_of_ctype t ^ " )" )
310
+ | Eunop (op ,e ,t ) -> (" Eunop(OP," ^ string_of_expr e^ " ," ^ string_of_ctype t ^ " )" )
311
+ | Ebinop (op ,e1 ,e2 ,t ) -> (" Ebinop(OP," ^ string_of_expr e1^ " ," ^ string_of_expr e2^ " ," ^ string_of_ctype t ^ " )" )
312
+ | Efield (e , ident , t ) ->(" Efield(" ^ string_of_expr e^ " ," ^ string_of_int (int_of_positive ident)^ " ," ^ string_of_ctype t^ " )" )
313
+ | Earrayderef (e1 ,e2 ,t ) -> (" Earrayderef(" ^ string_of_expr e1 ^ " ," ^ string_of_expr e2^ " ," ^ string_of_ctype t^ " )" )
314
+ | Ehashderef (e1 ,e2 ,t ) -> (" Ehashderef(" ^ string_of_expr e1 ^ " ," ^ string_of_expr e2^ " ," ^ string_of_ctype t^ " )" )
315
+ | Ecall0 (bt ,t ) -> " Ecall0(BUILTIN,TYPE)"
316
+ | Ecall1 (bt ,e ,t ) -> " Ecall0(BUILTIN,EXPR,TYPE)"
317
+
318
+ let rec string_of_statement = function
319
+ | Sskip -> " Sskip"
320
+ | Sassign (e1 ,e2 ) -> (" Sassign(" ^ string_of_expr e1 ^ " ," ^ string_of_expr e2 ^ " )" )
321
+ | Sset (id ,e ) -> (" Sset(" ^ string_of_int(int_of_positive id)^ " ," ^ string_of_expr e^ " )" )
322
+ | Scall (None, lab , exprs ) -> " Scall(None, LABEL, ARGS)"
323
+ | Scall (Some id , lab , expr ) -> " Scall(Some ID, LABEL, ARGS)"
324
+ | Ssequence (s1 ,s2 ) -> (" Ssequence(" ^ string_of_statement s1 ^ " ," ^ string_of_statement s2^ " )" )
325
+ | Sifthenelse (e ,s1 ,s2 ) -> (" Sifthenelse(" ^ string_of_expr e^ " ," ^ string_of_statement s1^ " ," ^ string_of_statement s2 ^ " )" )
326
+ | Sloop s -> " (Sloop " ^ string_of_statement s^ " )"
327
+ | Sbreak -> " Sbreak"
328
+ | Sreturn None -> " Sreturn None"
329
+ | Sreturn (Some e ) -> (" Sreturn Some(" ^ string_of_expr e^ " )" )
330
+ | Stransfer (e1 ,e2 ) -> " Stransfer (" ^ string_of_expr e1 ^ " ," ^ string_of_expr e2 ^ " )"
331
+ | Scallmethod (e1 ,ids ,z ,e ,es ) -> " Scallmethod TODO"
332
+ | Slog e -> " Slog " ^ string_of_expr e
333
+ | Srevert -> " Srevert"
334
+
335
+ let rec string_of_params =
336
+ let open Datatypes in
337
+ function
338
+ | Coq_cons (Coq_pair(id , t ) , params ) -> " (" ^ string_of_int (int_of_positive id) ^ " ," ^ string_of_ctype t ^ " )::" ^ string_of_params params
339
+ | Coq_nil -> " nil"
340
+
341
+ let string_of_methoddef md =
342
+ " { fn_return = " ^ string_of_ctype md.fn_return ^ " ;\n "
343
+ ^ " fn_params = " ^ string_of_params md.fn_params ^ " ;\n "
344
+ ^ " fn_temps = " ^ string_of_params md.fn_temps ^ " ;\n "
345
+ ^ " fn_body = " ^ string_of_statement md.fn_body ^ " \n "
346
+ ^ " }"
347
+
348
+
278
349
(* * gen_object_methods :
279
350
(Int.int, coq_fun) prod list **)
280
351
let gen_object_methods gen_methodname gen_method o =
281
352
let open Datatypes in
282
353
coqlist_of_list
283
354
(List. map
284
- (fun m -> Coq_pair (gen_methodname m, gen_method m))
355
+ (fun m -> print_endline(string_of_methoddef (gen_method m)); Coq_pair (gen_methodname m, gen_method m)) (* for debugging purpose * )
285
356
o.smethods)
286
357
287
358
(* * gen_object_fields :
@@ -340,38 +411,3 @@ type genv = {
340
411
genv_constructor : coq_function option
341
412
}
342
413
**)
343
-
344
- (*
345
- (* Print MiniC expressions/statements, for debugging purposes. *)
346
- let rec string_of_ctype =
347
- let open Ctypes in
348
- function
349
- | Tvoid -> "Tvoid"
350
- | Tint (_,_) -> "TInt (SIZE,SIGNEDNESS)"
351
- | Tpointer _ -> "Tpointer"
352
- | Tarray (t,z) -> ("Tarray ("^string_of_ctype t^","^string_of_int(int_of_z z)^")")
353
- | Thashmap (t1,t2) -> ("Thashmap("^string_of_ctype t1^","^string_of_ctype t2^")")
354
- | Tfunction (ts,t) -> "Tfunction (TYPES,TYPE)"
355
- | Tstruct (id,flds) -> "Tstring (IDENT, FIELDS)"
356
- | Tunion (id,flds) -> "Tunion (IDENT, FIELDS)"
357
- | Tcomp_ptr id -> "Tcomp_ptr ID"
358
-
359
- let rec string_of_expr = function
360
- | Econst_int (z, t) -> ("Econst_int (" ^ string_of_int (int_of_z z) ^ ","^string_of_ctype t^")")
361
- | Econst_int256 (z, t) -> ("Econst_int (" ^ string_of_int (int_of_z z) ^ ","^string_of_ctype t^")")
362
- | Evar (id,t) -> ("Evar("^string_of_int (int_of_positive id)^","^string_of_ctype t^")")
363
- | Etempvar (id,t) -> ("Etempvar("^string_of_int (int_of_positive id)^","^string_of_ctype t^")")
364
- | Ederef (e,t) -> ("Ederef(" ^ string_of_expr e ^","^ string_of_ctype t ^")")
365
- | Eunop (op,e,t) -> ("Eunop(OP,"^string_of_expr e^","^string_of_ctype t ^")")
366
- | Ebinop (op,e1,e2,t) -> ("Ebinop(OP,"^string_of_expr e1^","^string_of_expr e2^","^string_of_ctype t ^")")
367
- | Efield (e, ident, t) ->("Efield("^string_of_expr e^","^string_of_int (int_of_positive ident)^","^string_of_ctype t^")")
368
- | Earrayderef (e1,e2,t) -> ("Earrayderef("^string_of_expr e1 ^","^string_of_expr e2^","^string_of_ctype t^")")
369
- | Ehashderef (e1,e2,t) -> ("Ehashderef("^string_of_expr e1 ^","^string_of_expr e2^","^string_of_ctype t^")")
370
- | Ecall0 (bt,t) -> "Ecall0(BUILTIN,TYPE)"
371
- | Ecall1 (bt,e,t) -> "Ecall0(BUILTIN,EXPR,TYPE)"
372
-
373
- let rec string_of_params =
374
- let open Datatypes in
375
- function
376
- | Coq_cons (Coq_pair(id, t) , params) -> "("^string_of_int (int_of_positive id) ^","^string_of_ctype t ^")::"^ string_of_params params
377
- | Coq_nil -> "nil" *)
0 commit comments