Further code generation ** NOT WORKING **
[virt-mem.git] / extract / codegen / compile_kerneldb.ml
index 27fcb14..9d9e89c 100644 (file)
@@ -102,59 +102,10 @@ open Printf
 
 module PP = Pahole_parser
 module SC = Struct_classify
+module CG = Code_generation
 
 let (//) = Filename.concat
 
-(* Couple of handy camlp4 construction functions which do some
- * things that ought to be easy/obvious but aren't.
- *
- * 'concat_str_items' concatenates a list of str_item together into
- * one big str_item.
- *
- * 'concat_record_fields' concatenates a list of records fields into
- * a record.  The list must have at least one element.
- *
- * 'build_record' builds a record out of record fields.
- * 
- * 'build_tuple_from_exprs' builds an arbitrary length tuple from
- * a list of expressions of length >= 2.
- *
- * Thanks to bluestorm on #ocaml for getting these working.
- *)
-let concat_str_items _loc items =
-  match items with
-  | [] -> <:str_item< >>
-  | x :: xs ->
-      List.fold_left (fun xs x -> <:str_item< $xs$ $x$ >>) x xs
-
-let concat_sig_items _loc items =
-  match items with
-  | [] -> <:sig_item< >>
-  | x :: xs ->
-      List.fold_left (fun xs x -> <:sig_item< $xs$ $x$ >>) x xs
-
-let concat_record_fields _loc fields =
-  match fields with
-    | [] -> assert false
-    | f :: fs ->
-       List.fold_left (fun fs f -> <:ctyp< $fs$ ; $f$ >>) f fs
-
-let concat_record_bindings _loc rbs =
-  match rbs with
-    | [] -> assert false
-    | rb :: rbs ->
-       List.fold_left (fun rbs rb -> <:rec_binding< $rbs$ ; $rb$ >>) rb rbs
-
-let build_record _loc rbs =
-  Ast.ExRec (_loc, rbs, Ast.ExNil _loc)
-
-let build_tuple_from_exprs _loc exprs =
-  match exprs with
-  | [] | [_] -> assert false
-  | x :: xs ->
-      Ast.ExTup (_loc,
-                List.fold_left (fun xs x -> Ast.ExCom (_loc, x, xs)) x xs)
-
 (* Start of the main program. *)
 let () =
   let quick = ref false in
@@ -380,3 +331,24 @@ Options:
            printf "      -> (%s, %s)\n" sf.SC.sf_name cf.SC.cf_name
        ) palist
     ) structures;
+
+  (* Now let's generate some code. *)
+  let implem_types, interf_types =
+    CG.generate_types (
+      List.map (
+       fun (struct_name,
+            (_, _, sflist, _, cflist, _, _, _)) ->
+         (struct_name, sflist, cflist)
+      ) 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;
+
+  let output_file = outputdir // "kernel.ml" in
+  printf "Writing kernel data parsers to %s ...\n%!" output_file;
+  CG.output_implem ~output_file implem_types;
+
+  (* XXX Here we need to substitute the parser code. *)