@@ -47,59 +47,8 @@ let print_list fn p l =
4747
4848exception Not_an_identifier
4949
50- let sanitize s =
51- let s' = Bytes. create (String. length s) in
52- for i = 0 to String. length s - 1 do
53- Bytes. set s' i
54- (match String. get s i with
55- | 'A' ..'Z' | 'a' ..'z' | '0' ..'9' | '_' as c -> c
56- | ' ' | '$' -> '_'
57- | _ -> raise Not_an_identifier )
58- done ;
59- Bytes. to_string s'
60-
61- let temp_names : (ident, string) Hashtbl.t = Hashtbl. create 17
62-
6350let ident p id =
64- try
65- let s = Hashtbl. find string_of_atom id in
66- fprintf p " _%s" (sanitize s)
67- with Not_found | Not_an_identifier ->
68- try
69- let s = Hashtbl. find temp_names id in
70- fprintf p " %s" s
71- with Not_found ->
72- fprintf p " %ld%%positive" (P. to_int32 id)
73-
74- let iter_hashtbl_sorted (h : ('a, string) Hashtbl.t ) (f : 'a * string -> unit ) =
75- List. iter f
76- (List. fast_sort (fun (k1 , d1 ) (k2 , d2 ) -> String. compare d1 d2)
77- (Hashtbl. fold (fun k d accu -> (k, d) :: accu) h [] ))
78-
79- let define_idents p =
80- iter_hashtbl_sorted
81- string_of_atom
82- (fun (id , name ) ->
83- try
84- fprintf p " Definition _%s : ident := %ld%%positive.@ "
85- (sanitize name) (P. to_int32 id)
86- with Not_an_identifier ->
87- () );
88- iter_hashtbl_sorted
89- temp_names
90- (fun (id , name ) ->
91- fprintf p " Definition %s : ident := %ld%%positive.@ "
92- name (P. to_int32 id));
93- fprintf p " @ "
94-
95- let name_temporary t =
96- let t1 = P. to_int t and t0 = P. to_int (first_unused_ident () ) in
97- if t1 > = t0 && not (Hashtbl. mem temp_names t)
98- then Hashtbl. add temp_names t (sprintf " _t'%d" (t1 - t0 + 1 ))
99-
100- let name_opt_temporary = function
101- | None -> ()
102- | Some id -> name_temporary id
51+ fprintf p " #\" %s\" " (extern_atom id)
10352
10453(* Numbers *)
10554
@@ -490,67 +439,11 @@ From compcert Require Import Coqlib Integers Floats AST Ctypes Cop Clight Clight
490439Local Open Scope Z_scope.\n \
491440\n "
492441
493- (* Naming the compiler-generated temporaries occurring in the program *)
494-
495- let rec name_expr = function
496- | Evar (id , t ) -> ()
497- | Etempvar (id , t ) -> name_temporary id
498- | Ederef (a1 , t ) -> name_expr a1
499- | Efield (a1 , f , t ) -> name_expr a1
500- | Econst_int (n , t ) -> ()
501- | Econst_float (n , t ) -> ()
502- | Econst_long (n , t ) -> ()
503- | Econst_single (n , t ) -> ()
504- | Eunop (op , a1 , t ) -> name_expr a1
505- | Eaddrof (a1 , t ) -> name_expr a1
506- | Ebinop (op , a1 , a2 , t ) -> name_expr a1; name_expr a2
507- | Ecast (a1 , t ) -> name_expr a1
508- | Esizeof (t1 , t ) -> ()
509- | Ealignof (t1 , t ) -> ()
510-
511- let rec name_stmt = function
512- | Sskip -> ()
513- | Sassign (e1 , e2 ) -> name_expr e1; name_expr e2
514- | Sset (id , e2 ) -> name_temporary id; name_expr e2
515- | Scall (optid , e1 , el ) ->
516- name_opt_temporary optid; name_expr e1; List. iter name_expr el
517- | Sbuiltin (optid , ef , tyl , el ) ->
518- name_opt_temporary optid; List. iter name_expr el
519- | Ssequence (s1 , s2 ) -> name_stmt s1; name_stmt s2
520- | Sifthenelse (e , s1 , s2 ) -> name_expr e; name_stmt s1; name_stmt s2
521- | Sloop (s1 , s2 ) -> name_stmt s1; name_stmt s2
522- | Sbreak -> ()
523- | Scontinue -> ()
524- | Sswitch (e , cases ) -> name_expr e; name_lblstmts cases
525- | Sreturn (Some e ) -> name_expr e
526- | Sreturn None -> ()
527- | Slabel (lbl , s1 ) -> name_stmt s1
528- | Sgoto lbl -> ()
529-
530- and name_lblstmts = function
531- | LSnil -> ()
532- | LScons (lbl , s , ls ) -> name_stmt s; name_lblstmts ls
533-
534- let name_function f =
535- List. iter (fun (id , ty ) -> name_temporary id) f.fn_temps;
536- name_stmt f.fn_body
537-
538- let name_globdef (id , g ) =
539- match g with
540- | Gfun (Ctypes. Internal f ) -> name_function f
541- | _ -> ()
542-
543- let name_program p =
544- List. iter name_globdef p.Ctypes. prog_defs
545-
546442(* All together *)
547443
548444let print_program p prog =
549- Hashtbl. clear temp_names;
550- name_program prog;
551445 fprintf p " @[<v 0>" ;
552446 fprintf p " %s" prologue;
553- define_idents p;
554447 List. iter (print_globdef p) prog.Ctypes. prog_defs;
555448 fprintf p " Definition composites : list composite_definition :=@ " ;
556449 print_list print_composite_definition p prog.prog_types;
0 commit comments