X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=extract%2Fcodegen%2Fcompile_kerneldb.ml;h=a3ff911f068eb77db6b9cd82f84f1f812f91cbea;hb=03dcc62ed37ff0160f211927196e48033a6aeb81;hp=31bb00094aa1632daf957fe1c50fad6d2399d145;hpb=0ab39a448da6dd9bca3c2730f1221fad0718ac36;p=virt-mem.git diff --git a/extract/codegen/compile_kerneldb.ml b/extract/codegen/compile_kerneldb.ml index 31bb000..a3ff911 100644 --- a/extract/codegen/compile_kerneldb.ml +++ b/extract/codegen/compile_kerneldb.ml @@ -47,9 +47,9 @@ let good_structs = [ "comm"; "pid" ]; field_metadata = [ "tasks'next", ListHeadIsReally None; - "tasks'prev", ListHeadIsReally None; + (*"tasks'prev", ListHeadIsReally None; XXX point to 'next *) "run_list'next", ListHeadIsReally None; - "run_list'prev", ListHeadIsReally None; + (*"run_list'prev", ListHeadIsReally None; XXX point to 'next *) ]; }; "net_device", { @@ -59,7 +59,7 @@ let good_structs = [ "addr_len" ]; field_metadata = [ "dev_list'next", ListHeadIsReally None; - "dev_list'prev", ListHeadIsReally None; + (*"dev_list'prev", ListHeadIsReally None; XXX point to 'next *) "ip_ptr", VoidPointerIsReally "in_device"; "ip6_ptr", VoidPointerIsReally "inet6_dev"; ]; @@ -67,8 +67,10 @@ let good_structs = [ "net", { good_fields = [ "dev_base_head'next"; "dev_base_head'prev" ]; field_metadata = [ - "dev_base_head'next", ListHeadIsReally (Some ("net_device", "dev_list")); - "dev_base_head'prev", ListHeadIsReally (Some ("net_device", "dev_list")); + "dev_base_head'next", + ListHeadIsReally (Some ("net_device", "dev_list'next")); + "dev_base_head'prev", + ListHeadIsReally (Some ("net_device", "dev_list'next")); ]; }; "in_device", { @@ -101,7 +103,7 @@ open ExtString open Printf module PP = Pahole_parser -module SC = Struct_classify +module MM = Minimizer module CG = Code_generation let (//) = Filename.concat @@ -264,71 +266,36 @@ Options: (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 { PP.field_name = name; field_type = 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 { PP.field_name = name; field_type = 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; @@ -336,27 +303,53 @@ Options: 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_parsers, interf_parsers, subst_parsers = + let implem_offsets, interf_offsets = + CG.generate_offsets ( + List.map ( + 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 good_struct_names ( + List.map ( + fun (struct_name, (_, all_fields, _, _)) -> (struct_name, all_fields) ) structures ) in (* Output the generated code. *) 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_parsers; + CG.output_interf ~output_file + 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_parsers subst_parsers; + CG.output_implem ~output_file + implem_types implem_offsets implem_parsers subst_parsers + implem_version_maps implem_followers; printf "Finished.\n"