Module of module types for OrderedType,ComparableType,Printable,Serializable,Discrete...
[ocaml.git] / asmcomp / debuginfo.ml
blob84390442bc6bfff558420371f5e9a1d96994c617
1 (***********************************************************************)
2 (* *)
3 (* Objective Caml *)
4 (* *)
5 (* Xavier Leroy, projet Gallium, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 2006 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the Q Public License version 1.0. *)
10 (* *)
11 (***********************************************************************)
13 open Lexing
14 open Location
16 type kind = Dinfo_call | Dinfo_raise
18 type t = {
19 dinfo_kind: kind;
20 dinfo_file: string;
21 dinfo_line: int;
22 dinfo_char_start: int;
23 dinfo_char_end: int
26 let none = {
27 dinfo_kind = Dinfo_call;
28 dinfo_file = "";
29 dinfo_line = 0;
30 dinfo_char_start = 0;
31 dinfo_char_end = 0
34 let to_string d =
35 if d == none
36 then ""
37 else Printf.sprintf "{%s:%d,%d-%d}"
38 d.dinfo_file d.dinfo_line d.dinfo_char_start d.dinfo_char_end
40 let from_location kind loc =
41 if loc.loc_ghost then none else
42 { dinfo_kind = kind;
43 dinfo_file = loc.loc_start.pos_fname;
44 dinfo_line = loc.loc_start.pos_lnum;
45 dinfo_char_start = loc.loc_start.pos_cnum - loc.loc_start.pos_bol;
46 dinfo_char_end =
47 if loc.loc_end.pos_fname = loc.loc_start.pos_fname
48 then loc.loc_end.pos_cnum - loc.loc_start.pos_bol
49 else loc.loc_start.pos_cnum - loc.loc_start.pos_bol }
51 let from_call ev = from_location Dinfo_call ev.Lambda.lev_loc
52 let from_raise ev = from_location Dinfo_raise ev.Lambda.lev_loc