1 (* Memory info command for virtual domains.
2 (C) Copyright 2008 Richard W.M. Jones, Red Hat Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 module PP = Pahole_parser
30 pa_endian : Bitstring.endian;
31 pa_structure : Pahole_parser.structure;
34 and pahash = (string, parser_) Hashtbl.t
36 let endian_of_architecture arch =
37 if String.starts_with arch "i386" ||
38 String.starts_with arch "i486" ||
39 String.starts_with arch "i586" ||
40 String.starts_with arch "i686" ||
41 String.starts_with arch "x86_64" ||
42 String.starts_with arch "x86-64" then
43 Bitstring.LittleEndian
44 else if String.starts_with arch "ia64" then
45 Bitstring.LittleEndian (* XXX usually? *)
46 else if String.starts_with arch "ppc" then
48 else if String.starts_with arch "sparc" then
51 failwith (sprintf "endian_of_architecture: cannot parse %S" arch)
58 let hash_values h = Hashtbl.fold (fun _ v vs -> v :: vs) h []
60 let minimize_parsers struct_name kernels =
61 let h = Hashtbl.create 13 in
62 let rh = Hashtbl.create 13 in
64 (* Do not change - see Code_generation.re_subst. *)
65 let name_of i = sprintf "%s_parser_%d" struct_name i in
68 fun ({ PP.kernel_version = version; arch = arch },
69 ({ PP.struct_fields = fields; struct_name = name_check }
71 assert (struct_name = name_check);
72 let endian = endian_of_architecture arch in
73 let key = endian, fields in
75 try Hashtbl.find h key
78 let pa = { pa_i = i; pa_name = name_of i;
80 pa_structure = structure } in
83 Hashtbl.add rh version pa
86 let pas = hash_values h in