let last_label = ref (-1) let last_temp = ref (-1) type label = {id : int; name : string} type temp = int let new_temp() = incr last_temp; !last_temp let registers = Array.init 100 (fun i -> new_temp());; let new_label() = incr last_label; {id = !last_label; name = "L"^(string_of_int !last_label)} let names = Hashtbl.create 3 let prefixed_label s = let n, sn = try let n = succ (Hashtbl.find names s) in n, s^"_"^(string_of_int n) with Not_found -> 0, s in incr last_label; let l = {id = !last_label; name = sn} in Hashtbl.add names s n; l ;; let named_label s = try let _ = Hashtbl.find names s in failwith "named_label" with Not_found -> prefixed_label s ;; (* pour imprimer les instructions et pour la mise au point *) let label_string l = l.name let temp_string t = "t"^(string_of_int t) let temp_int (t : int) = t let int_temp (t : int) = t let eq u v = (u = v);; let lt u v = (u < v);; let le u v = (u <= v);; let compare u v = if u < v then -1 else if u = v then 0 else 1;; let temp_interval k = let left = !last_temp in let rec alloc all k = if k > 0 then alloc (new_temp()::all) (pred k) else all in let all = alloc [] k in let right = !last_temp in let member t = lt left t && le t right in all, member ;;