summaryrefslogtreecommitdiff
path: root/common/PrintAST.ml
blob: 971bf77ce93960e3b05970e780e78b1c0e1d41a0 (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
41
42
43
44
45
46
47
(* *********************************************************************)
(*                                                                     *)
(*              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.     *)
(*                                                                     *)
(* *********************************************************************)

(** Useful functions for pretty-printers *)

open Printf
open Camlcoq
open AST

let name_of_type = function Tint -> "int" | Tfloat -> "float"

let name_of_chunk = function
  | Mint8signed -> "int8signed"
  | Mint8unsigned -> "int8unsigned"
  | Mint16signed -> "int16signed"
  | Mint16unsigned -> "int16unsigned"
  | Mint32 -> "int32"
  | Mfloat32 -> "float32"
  | Mfloat64 -> "float64"
  | Mfloat64al32 -> "float64al32"

let name_of_external = function
  | EF_external(name, sg) -> extern_atom name
  | EF_builtin(name, sg) -> extern_atom name
  | EF_vload chunk -> sprintf "volatile load %s" (name_of_chunk chunk)
  | EF_vstore chunk -> sprintf "volatile store %s" (name_of_chunk chunk)
  | EF_vload_global(chunk, id, ofs) ->
      sprintf "volatile load %s global %s %ld"
              (name_of_chunk chunk) (extern_atom id) (camlint_of_coqint ofs)
  | EF_vstore_global(chunk, id, ofs) ->
      sprintf "volatile store %s global %s %ld"
              (name_of_chunk chunk) (extern_atom id) (camlint_of_coqint ofs)
  | EF_malloc -> "malloc"
  | EF_free -> "free"
  | EF_memcpy(sz, al) ->
      sprintf "memcpy size %ld align %ld " (camlint_of_z sz) (camlint_of_z al)
  | EF_annot(text, targs) -> sprintf "annot %S" (extern_atom text)
  | EF_annot_val(text, targ) ->  sprintf "annot_val %S" (extern_atom text)