Begin generating C implementation code.
authorRichard W.M. Jones <rjones@redhat.com>
Sat, 31 Dec 2011 19:56:22 +0000 (19:56 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Sat, 31 Dec 2011 20:25:54 +0000 (20:25 +0000)
12 files changed:
APIs/error.api
APIs/filesize.api
APIs/mknod.api
generator/.depend
generator/Makefile.am
generator/wrappi_c.mli
generator/wrappi_c_impl.ml [new file with mode: 0644]
generator/wrappi_c_impl.mli [new file with mode: 0644]
generator/wrappi_main.ml
lib/.gitignore [new file with mode: 0644]
lib/Makefile.am
lib/implementation_files.mk [new file with mode: 0644]

index 190af67..e315338 100644 (file)
@@ -27,3 +27,7 @@ void clear_error ()
 <<
   w->error_flag = 0;
 >>
+
+(*
+event error ???
+*)
index e57df8e..89a4063 100644 (file)
@@ -22,7 +22,7 @@ off_t filesize (pathname path)
   struct stat buf;
 
   if (stat (path, &buf) == -1) {
-    error_errno ("stat: %s", path);
+    set_error_errno ("stat: %s", path);
     return -1;
   }
 
index 2e16a3c..85c6458 100644 (file)
@@ -20,7 +20,7 @@ entry_point
 void mknod_char (pathname path, fileperm perm, uint64 major, uint64 minor)
 <<
   if (mknod (path, S_IFCHR | perm, makedev (major, minor)) == -1) {
-    error_errno ("mknod: %s", path);
+    set_error_errno ("mknod: %s", path);
     return -1;
   }
   return 0;
index 9fe3110..033feaf 100644 (file)
@@ -4,8 +4,11 @@ wrappi_boilerplate.cmx: wrappi_pr.cmx wrappi_boilerplate.cmi
 wrappi_c.cmi:
 wrappi_c.cmo: wrappi_pr.cmi wrappi_boilerplate.cmi wrappi_c.cmi
 wrappi_c.cmx: wrappi_pr.cmx wrappi_boilerplate.cmx wrappi_c.cmi
-wrappi_main.cmo: wrappi_pr.cmi wrappi_c.cmi
-wrappi_main.cmx: wrappi_pr.cmx wrappi_c.cmx
+wrappi_c_impl.cmi:
+wrappi_c_impl.cmo: wrappi_pr.cmi wrappi_boilerplate.cmi wrappi_c_impl.cmi
+wrappi_c_impl.cmx: wrappi_pr.cmx wrappi_boilerplate.cmx wrappi_c_impl.cmi
+wrappi_main.cmo: wrappi_pr.cmi wrappi_c_impl.cmi wrappi_c.cmi
+wrappi_main.cmx: wrappi_pr.cmx wrappi_c_impl.cmx wrappi_c.cmx
 wrappi_pr.cmi:
 wrappi_pr.cmo: wrappi_pr.cmi
 wrappi_pr.cmx: wrappi_pr.cmi
index 1379f1a..872d000 100644 (file)
@@ -26,6 +26,8 @@ OCAMLOPTFLAGS = $(OCAMLCFLAGS)
 SOURCES = \
        wrappi_boilerplate.mli \
        wrappi_boilerplate.ml \
+       wrappi_c_impl.mli \
+       wrappi_c_impl.ml \
        wrappi_c.mli \
        wrappi_c.ml \
        wrappi_main.ml \
@@ -36,6 +38,7 @@ SOURCES = \
 OBJECTS = \
        wrappi_pr.cmo \
        wrappi_boilerplate.cmo \
+       wrappi_c_impl.cmo \
        wrappi_c.cmo \
        wrappi_main.cmo
 
index 9c4991d..958942c 100644 (file)
@@ -16,4 +16,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *)
 
+(** Generate the C bindings. *)
+
 val generate : Wrappi_types.api -> unit
diff --git a/generator/wrappi_c_impl.ml b/generator/wrappi_c_impl.ml
new file mode 100644 (file)
index 0000000..50673fc
--- /dev/null
@@ -0,0 +1,98 @@
+(* wrappi
+ * Copyright (C) 2011 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+open Camlp4.PreCast
+
+open Wrappi_utils
+open Wrappi_types
+open Wrappi_boilerplate
+open Wrappi_pr
+
+open Printf
+
+let generate_implementation ep =
+  generate_header CStyle LGPLv2plus;
+
+  pr "\
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include \"wrappi.h\"
+
+#include \"internal.h\"
+
+"
+
+  (* Depending on whether this is a local or remote function, include
+   * different definitions here.
+   *)
+  (*if ep.ep_local then ... *)
+
+(* Make a unique, reproducible filename for each entry point. *)
+let filename_of_ep ep =
+  let filename = Loc.file_name ep.ep_loc in
+  let filename = Filename.basename filename in
+  let filename =
+    try Filename.chop_extension filename
+    with Invalid_argument _ -> filename in
+  let filename = sprintf "%s-%s.c" filename ep.ep_name in
+  filename
+
+let generate_lib_implementation_files_mk api =
+  generate_header HashStyle GPLv2plus;
+
+  let eps = StringMap.bindings api.api_entry_points in
+  let cmp (a, _) (b, _) = compare a b in
+  let eps = List.sort cmp eps in
+  let eps = List.map snd eps in
+
+  let rec loop = function
+    | [] -> ()
+    | [ep] -> pr "\t%s\n" (filename_of_ep ep)
+    | ep :: eps -> pr "\t%s \\\n" (filename_of_ep ep); loop eps
+  in
+
+  pr "local_implementation_files := \\\n";
+
+  loop (List.filter (fun ep -> ep.ep_local) eps);
+
+  pr "\n";
+  pr "remote_implementation_files := \\\n";
+
+  loop (List.filter (fun ep -> not ep.ep_local) eps)
+
+let generate api =
+  let gitignores = ref [] in
+
+  iter_entry_points api (
+    fun ep ->
+      let filename = filename_of_ep ep in
+
+      gitignores := ("/" ^ filename) :: !gitignores;
+
+      output_to ("lib/" ^ filename) generate_implementation ep
+  );
+
+  let gitignores = List.rev !gitignores in
+  output_to "lib/.gitignore"
+    (fun () -> List.iter (pr "%s\n") gitignores) ();
+
+  output_to "lib/implementation_files.mk"
+    generate_lib_implementation_files_mk api
diff --git a/generator/wrappi_c_impl.mli b/generator/wrappi_c_impl.mli
new file mode 100644 (file)
index 0000000..eeaedb8
--- /dev/null
@@ -0,0 +1,21 @@
+(* wrappi
+ * Copyright (C) 2011 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+(** Generate the C implementation of the library. *)
+
+val generate : Wrappi_types.api -> unit
index ffcef60..8f92cb1 100644 (file)
@@ -113,6 +113,7 @@ Run it from the top source directory using the command
      exit 1);
 
   (* Generate code. *)
+  Wrappi_c_impl.generate api;
   Wrappi_c.generate api;
 
   printf "generated %d lines of code in %d files\n"
diff --git a/lib/.gitignore b/lib/.gitignore
new file mode 100644 (file)
index 0000000..51ea85c
--- /dev/null
@@ -0,0 +1,8 @@
+/error-clear_error.c
+/handle-connect.c
+/error-error.c
+/filesize-filesize.c
+/mkdir-mkdir.c
+/mknod-mknod_char.c
+/handle-set_hostname.c
+/handle-set_scheme.c
index 937c29f..d634a20 100644 (file)
@@ -15,6 +15,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
+include implementation_files.mk
+
 include_HEADERS = wrappi.h
 
 lib_LTLIBRARIES = libwrappi.la
@@ -26,4 +28,6 @@ libwrappi_la_LDFLAGS = -version-info $(LIB_MINOR):0:$(LIB_MINOR)
 
 libwrappi_la_SOURCES = \
        wrappi.h \
-       wrappi.c
+       wrappi.c \
+       $(local_implementation_files) \
+       $(remote_implementation_files)
diff --git a/lib/implementation_files.mk b/lib/implementation_files.mk
new file mode 100644 (file)
index 0000000..8760929
--- /dev/null
@@ -0,0 +1,32 @@
+# wrappi generated file
+# WARNING: THIS FILE IS GENERATED FROM:
+#   generator/wrappi_*.ml
+# ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
+#
+# Copyright (C) 2011 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+local_implementation_files := \
+       error-clear_error.c \
+       handle-connect.c \
+       error-error.c \
+       handle-set_hostname.c \
+       handle-set_scheme.c
+
+remote_implementation_files := \
+       filesize-filesize.c \
+       mkdir-mkdir.c \
+       mknod-mknod_char.c