aboutsummaryrefslogtreecommitdiffstats
path: root/powerpc/Machregsaux.ml
blob: 0b0d4548e837560f8161673816629b5b1947d4d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(* *********************************************************************)
(*                                                                     *)
(*              The Compcert verified compiler                         *)
(*                                                                     *)
(*          Xavier Leroy, INRIA Paris-Rocquencourt                     *)
(*                                                                     *)
(*  Copyright Institut National de Recherche en Informatique et en     *)
(*  Automatique.  All rights reserved.  This file is distributed       *)
(*  under the terms of the INRIA Non-Commercial License Agreement.     *)
(*                                                                     *)
(* *********************************************************************)

(** Auxiliary functions on machine registers *)

open Camlcoq
open Machregs

let register_names : (mreg, string) Hashtbl.t = Hashtbl.create 31

let _ =
  List.iter
    (fun (s, r) -> Hashtbl.add register_names r (camlstring_of_coqstring s))
    Machregs.register_names

let is_scratch_register s = s = "R0" || s = "r0"

let name_of_register r =
  try Some (Hashtbl.find register_names r) with Not_found -> None

let register_by_name s =
  Machregs.register_by_name (coqstring_uppercase_ascii_of_camlstring s)

let can_reserve_register r =
  List.mem r Conventions1.int_callee_save_regs
  || List.mem r Conventions1.float_callee_save_regs
                                              
let class_of_type = function
  | AST.Tint | AST.Tlong -> 0
  | AST.Tfloat | AST.Tsingle -> 1
  | AST.Tany32 | AST.Tany64 -> assert false