Add preprocessor.
authorRichard W.M. Jones <rjones@redhat.com>
Thu, 29 Dec 2011 11:43:36 +0000 (11:43 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Thu, 29 Dec 2011 11:44:49 +0000 (11:44 +0000)
15 files changed:
.gitignore
APIs/Makefile.am [new file with mode: 0644]
APIs/block_devices.api
APIs/mkdir.api
APIs/mknod.api
APIs/processes.api
Makefile.am
configure.ac
generator/.depend [new file with mode: 0644]
generator/Makefile.am [new file with mode: 0644]
lib/Makefile.am [new file with mode: 0644]
preprocessor/.depend [new file with mode: 0644]
preprocessor/Makefile.am [new file with mode: 0644]
preprocessor/pa_wrap.ml [new file with mode: 0644]
preprocessor/wrappi_types.ml [new file with mode: 0644]

index 41a0ade..892cb64 100644 (file)
@@ -1,4 +1,7 @@
 *~
+*.cmi
+*.cmo
+*.cmx
 Makefile
 Makefile.in
 /aclocal.m4
diff --git a/APIs/Makefile.am b/APIs/Makefile.am
new file mode 100644 (file)
index 0000000..deac8a9
--- /dev/null
@@ -0,0 +1,35 @@
+# 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.
+
+OCAMLCFLAGS = -g -warn-error CDEFLMPSUVYZX
+OCAMLOPTFLAGS = $(OCAMLCFLAGS)
+
+PP = -pp '$(CAMLP4O) ../preprocessor/pa_wrap.cmo -impl'
+
+#API_FILES = $(wildcard *.api)
+API_FILES = mkdir.api mknod.api
+
+OBJ_FILES = $(patsubst %.api,%.cmo,$(API_FILES))
+
+noinst_SCRIPTS = $(OBJ_FILES)
+
+%.cmo: %.api
+       $(OCAMLFIND) ocamlc $(OCAMLOPTFLAGS) $(PP) -impl $< -c -o $@
+
+CLEANFILES = *.cmi *.cmo *.cmx *~
+
+SUFFIXES = .cmo .cmi .cmx .ml .mli .mll .mly .api
index 8d4fc30..5b19993 100644 (file)
@@ -1,4 +1,4 @@
-object block_device
+system_object block_device
   dir_list "/sys/block/[hsv]d[a-z]*"
 
   property string name << return safe_strdup ($basename); >>
index 2070c41..09e9527 100644 (file)
@@ -1 +1 @@
-function err mkdir (pathname path, fileperm perm) (* implicit *);;
+entry_point err mkdir (pathname path, fileperm perm) (* implicit *);;
index 3ed3c55..ceedd78 100644 (file)
@@ -1,13 +1,8 @@
-function
-err mknod_char (pathname path, fileperm perm, int<??> major, int<??> minor)
+entry_point
+err mknod_char (pathname path, fileperm perm, int64 major, int64 minor)
 <<
   return mknod (path, S_IFCHR | perm, makedev (major, minor));
 >>
-<:doc<
-
-
-
->>
 
 ;;
 
index 090245e..98fc527 100644 (file)
@@ -1,4 +1,4 @@
-object process
+system_object process
   dir_list "/proc/[1-9]*"
 
   constructor <<
index 300b8f8..8731aaf 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 ACLOCAL_AMFLAGS = -I m4
+
+# The API files are actually linked into the generator, but an extra
+# camlp4-based preprocessor must be compiled first before we can
+# compile the rest of the generator.  Hence the rather convoluted set
+# of subdirectories here.
+SUBDIRS = preprocessor APIs generator
+
+# The C library.
+SUBDIRS += lib
index f1c908b..21832b1 100644 (file)
@@ -37,17 +37,28 @@ AM_PROG_CC_C_O
 dnl Check support for 64 bit file offsets.
 AC_SYS_LARGEFILE
 
-dnl Check for OCaml compiler and camlp4.
+dnl Check for OCaml compiler.
 AC_PROG_OCAML
 if test "$OCAMLC" = "no"; then
     AC_MSG_ERROR([You must install the OCaml compiler])
 fi
 
+dnl Camlp4 is required.
 AC_PROG_CAMLP4
 if test "$CAMLP4" = "no"; then
     AC_MSG_ERROR([You must install camlp4 (the OCaml macro preprocessor)])
 fi
 
+dnl OCaml findlib ("ocamlfind") is required.
+AC_PROG_FINDLIB
+if test "$OCAMLFIND" = "no"; then
+    AC_MSG_ERROR([You must install OCaml findlib (the ocamlfind command)])
+fi
+
 AC_CONFIG_HEADERS([config.h])
-AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([Makefile
+                 APIs/Makefile
+                 generator/Makefile
+                 lib/Makefile
+                 preprocessor/Makefile])
 AC_OUTPUT
diff --git a/generator/.depend b/generator/.depend
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/generator/Makefile.am b/generator/Makefile.am
new file mode 100644 (file)
index 0000000..6cfc2c2
--- /dev/null
@@ -0,0 +1,42 @@
+# 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.
+
+OCAMLCFLAGS = -g -warn-error CDEFLMPSUVYZX
+OCAMLOPTFLAGS = $(OCAMLCFLAGS)
+
+%.cmi: %.mli
+       $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@
+%.cmo: %.ml
+       $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@
+%.cmx: %.ml
+       $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -c $< -o $@
+
+CLEANFILES = *.cmi *.cmo *.cmx *~
+
+depend: .depend
+
+.depend: $(wildcard *.mli) $(wildcard *.ml)
+       rm -f $@ $@-t
+       $(OCAMLFIND) ocamldep $^ | \
+         $(SED) -e 's/ *$$//' | \
+         $(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' | \
+         LANG=C sort > $@-t
+       mv $@-t $@
+
+include .depend
+
+SUFFIXES = .cmo .cmi .cmx .ml .mli .mll .mly
diff --git a/lib/Makefile.am b/lib/Makefile.am
new file mode 100644 (file)
index 0000000..5e79bf3
--- /dev/null
@@ -0,0 +1,16 @@
+# 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.
diff --git a/preprocessor/.depend b/preprocessor/.depend
new file mode 100644 (file)
index 0000000..c44a80c
--- /dev/null
@@ -0,0 +1,4 @@
+pa_wrap.cmo: wrappi_types.cmo
+pa_wrap.cmx: wrappi_types.cmx
+wrappi_types.cmo:
+wrappi_types.cmx:
diff --git a/preprocessor/Makefile.am b/preprocessor/Makefile.am
new file mode 100644 (file)
index 0000000..f0e8e93
--- /dev/null
@@ -0,0 +1,49 @@
+# 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.
+
+OCAMLCFLAGS = -g -warn-error CDEFLMPSUVYZX
+OCAMLOPTFLAGS = $(OCAMLCFLAGS)
+
+noinst_SCRIPTS = pa_wrap.cmo
+
+pa_wrap.cmo: pa_wrap.ml wrappi_types.cmo
+       $(OCAMLFIND) ocamlc -I +camlp4 dynlink.cma camlp4lib.cma \
+         -pp $(CAMLP4OF) \
+         wrappi_types.cmo -c $< -o $@
+
+%.cmi: %.mli
+       $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@
+%.cmo: %.ml
+       $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@
+%.cmx: %.ml
+       $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -c $< -o $@
+
+CLEANFILES = *.cmi *.cmo *.cmx *~
+
+depend: .depend
+
+.depend: $(wildcard *.mli) $(wildcard *.ml)
+       rm -f $@ $@-t
+       $(OCAMLFIND) ocamldep -pp $(CAMLP4OF) $^ | \
+         $(SED) -e 's/ *$$//' | \
+         $(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' | \
+         LANG=C sort > $@-t
+       mv $@-t $@
+
+include .depend
+
+SUFFIXES = .cmo .cmi .cmx .ml .mli .mll .mly
diff --git a/preprocessor/pa_wrap.ml b/preprocessor/pa_wrap.ml
new file mode 100644 (file)
index 0000000..c8e8af8
--- /dev/null
@@ -0,0 +1,77 @@
+(* 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.
+ *)
+
+(* For general information about camlp4, see:
+ * http://brion.inria.fr/gallium/index.php/Camlp4
+ * For information about quotations, see:
+ * http://brion.inria.fr/gallium/index.php/Quotation
+ *)
+
+open Camlp4.PreCast
+open Syntax
+open Ast
+
+open Wrappi_types
+
+let add_entry_point _loc name parameters return_type code =
+  (* XXX *)
+  <:str_item< >>
+
+let () =
+  (* Quotation expander for C code. *)
+  let c_quotation_expander _loc _ code =
+    (* XXX Expand %- or $- expressions in code. *)
+    ExStr (_loc, code)
+  in
+  Quotation.add "c" Quotation.DynAst.expr_tag c_quotation_expander;
+
+  (* Default quotation expander (<< .. >>) should be C code ("c"). *)
+  Quotation.default := "c"
+
+;;
+
+(* Extend the regular OCaml grammar. *)
+EXTEND Gram
+  GLOBAL: str_item;
+
+  (* A parameter or return type. *)
+  any_type: [
+    [ "int32" -> TInt32 ]
+  | [ "int64" -> TInt64 ]
+  | [ t = LIDENT -> Type t ]
+  ];
+
+  (* A return type. *)
+  return_type: [
+    [ "err" -> RErr ]
+  | [ t = any_type -> Return t ]
+  ];
+
+  (* A single function parameter. *)
+  parameter: [[ t = any_type; name = LIDENT -> (t, name) ]];
+
+  str_item: LEVEL "top" [
+    [ "entry_point";
+      return_type = return_type; name = LIDENT;
+      "("; parameters = LIST0 parameter SEP ","; ")";
+      code = OPT [ code = expr -> code ] ->
+      add_entry_point _loc name parameters return_type code
+    ]
+  ];
+
+END
diff --git a/preprocessor/wrappi_types.ml b/preprocessor/wrappi_types.ml
new file mode 100644 (file)
index 0000000..3f3ca58
--- /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.
+ *)
+
+type any_type = TInt32 | TInt64 | Type of string
+
+type return_type = RErr | Return of any_type