};
]
-(*----------------------------------------------------------------------
- * These are the code fragments which run over kernel structures.
- *----------------------------------------------------------------------*)
-
-let fragments = [
- <:str_item<
- let get_net_devices net_device =
- let rec loop dev acc =
- let ipv4 = net_device.ip_ptr.ifa_list in
- let ipv4_addresses =
- let rec loop2 ipv4 acc =
- let addr = ipv4.ifa_address :: acc in
- let ipv4 = ipv4.ifa_next in
- loop2 ipv4
- in
- loop ipv4 [] in
- let acc = ipv4_addresses :: acc in
- let next = get_net_devices net_device.dev_list'next in
- if next <> net_device then loop next
- else acc
- >>;
-
- <:str_item<
- let get_net_devices_from_init_net net =
- get_net_devices net.dev_base_head'next
- >>;
-
-]
-
let debug = false
open Camlp4.PreCast
open Printf
module PP = Pahole_parser
-module SC = Struct_classify
+module MM = Minimizer
module CG = Code_generation
let (//) = Filename.concat
(List.length kernels);
printf " union of fields found:\n";
List.iter (
- fun (field_name, field_type) ->
- printf " %s %s\n" (PP.string_of_f_type field_type) field_name
+ fun (field_name, (field_type, always_available)) ->
+ printf " %s %s /* %s */\n"
+ (PP.string_of_f_type field_type) field_name
+ (if always_available then "always" else "optional")
) all_fields
) structures;
- (* Now perform the minimization step for each structure.
- * We do separate minimization for:
- * - shape field structures
- * - content field structures
- * - parsers
- *)
+ (* Now perform the minimization step for parsers. *)
let structures =
List.map (
fun (struct_name, (kernels, all_fields)) ->
- let sflist, sfhash =
- SC.minimize_shape_field_structs struct_name good_struct_names
- kernels in
-
- let cflist, cfhash =
- SC.minimize_content_field_structs struct_name good_struct_names
- kernels in
-
- let palist, pahash =
- SC.minimize_parsers struct_name kernels sfhash cfhash in
+ let palist, pahash = MM.minimize_parsers struct_name kernels in
- (struct_name, (kernels, all_fields,
- sflist, sfhash, cflist, cfhash, palist, pahash))
+ (struct_name, (kernels, all_fields, palist, pahash))
) structures in
if debug then
List.iter (
fun (struct_name,
- (kernels, all_fields,
- sflist, sfhash, cflist, cfhash, palist, pahash)) ->
+ (kernels, all_fields, palist, pahash)) ->
printf "struct %s:\n" struct_name;
- printf " shape field structures:\n";
- List.iter (
- fun { SC.sf_name = name; sf_fields = fields } ->
- printf " type %s = {\n" name;
- List.iter (
- fun (name, typ) ->
- printf " %s %s;\n" (PP.string_of_f_type typ) name
- ) fields;
- printf " }\n";
- ) sflist;
-
- printf " content field structures:\n";
+ printf " parsers:\n";
List.iter (
- fun { SC.cf_name = name; cf_fields = fields } ->
- printf " type %s = {\n" name;
+ fun { MM.pa_name = name; pa_structure = structure } ->
+ printf " let %s bits =\n" name;
List.iter (
- fun (name, typ) ->
+ fun ({ PP.field_name = name; field_type = typ }) ->
printf " %s %s;\n" (PP.string_of_f_type typ) name
- ) fields;
- printf " }\n";
- ) cflist;
-
- printf " parsers:\n";
- List.iter (
- fun { SC.pa_name = name;
- pa_shape_field_struct = sf;
- pa_content_field_struct = cf } ->
- printf " let %s = ...\n" name;
- printf " -> (%s, %s)\n" sf.SC.sf_name cf.SC.cf_name
+ ) structure.PP.struct_fields;
) palist
) structures;
let implem_types, interf_types =
CG.generate_types (
List.map (
- fun (struct_name,
- (_, _, sflist, _, cflist, _, _, _)) ->
- (struct_name, sflist, cflist)
+ fun (struct_name, (_, all_fields, _, _)) ->
+ (struct_name, all_fields)
) structures
) in
let implem_offsets, interf_offsets =
CG.generate_offsets (
List.map (
- fun (struct_name,
- (kernels, all_fields, _, _, _, _, _, _)) ->
+ fun (struct_name, (kernels, all_fields, _, _)) ->
(struct_name, (kernels, all_fields))
) structures
) in
let (implem_parsers, interf_parsers), subst_parsers =
CG.generate_parsers (
List.map (
- fun (struct_name, (_, _, _, _, _, _, palist, _)) ->
- (struct_name, palist)
+ fun (struct_name, (_, all_fields, palist, _)) ->
+ (struct_name, (all_fields, palist))
+ ) structures
+ ) in
+
+ let implem_version_maps, interf_version_maps =
+ CG.generate_version_maps (
+ List.map (
+ fun (struct_name, (kernels, _, _, pahash)) ->
+ (struct_name, (kernels, pahash))
) structures
) in
let implem_followers, interf_followers =
- CG.generate_followers (
+ CG.generate_followers good_struct_names (
List.map (
- fun (struct_name, (kernels, _, sflist, sfhash, _, _, _, pahash)) ->
- (struct_name, (kernels, sflist, sfhash, pahash))
+ fun (struct_name, (_, all_fields, _, _)) -> (struct_name, all_fields)
) structures
) in
let output_file = outputdir // "kernel.mli" in
printf "Writing kernel data interface to %s ...\n%!" output_file;
CG.output_interf ~output_file
- interf_types interf_offsets interf_parsers interf_followers;
+ interf_types interf_offsets interf_parsers
+ interf_version_maps interf_followers;
let output_file = outputdir // "kernel.ml" in
printf "Writing kernel data parsers to %s ...\n%!" output_file;
CG.output_implem ~output_file
- implem_types implem_offsets implem_parsers subst_parsers implem_followers;
+ implem_types implem_offsets implem_parsers subst_parsers
+ implem_version_maps implem_followers;
printf "Finished.\n"