diff options
author | Daniil Baturin <daniil@baturin.org> | 2018-05-26 03:28:36 +0700 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2018-05-26 03:28:36 +0700 |
commit | 557f45a5a606b8f8ae1630c9f267d31376912746 (patch) | |
tree | f981b1ee0655a34399585c7b520619c14ff9a962 /stub_generator | |
download | libvyosconfig-557f45a5a606b8f8ae1630c9f267d31376912746.tar.gz libvyosconfig-557f45a5a606b8f8ae1630c9f267d31376912746.zip |
Import the initial, proof of concept implementation.
Diffstat (limited to 'stub_generator')
-rw-r--r-- | stub_generator/generate.ml | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/stub_generator/generate.ml b/stub_generator/generate.ml new file mode 100644 index 0000000..48ac707 --- /dev/null +++ b/stub_generator/generate.ml @@ -0,0 +1,30 @@ +(** A driver for stub generation. Build OCaml and C code from the + Bindings.Stubs functor. *) + +let generate dirname = + let prefix = "vyosconfig" in + let path basename = Filename.concat dirname basename in + let ml_fd = open_out (path "vyosconfig_bindings.ml") in + let c_fd = open_out (path "vyosconfig.c") in + let h_fd = open_out (path "vyosconfig.h") in + let stubs = (module Bindings.Stubs : Cstubs_inverted.BINDINGS) in + begin + (* Generate the ML module that links in the generated C. *) + Cstubs_inverted.write_ml + (Format.formatter_of_out_channel ml_fd) ~prefix stubs; + + (* Generate the C source file that exports OCaml functions. *) + Format.fprintf (Format.formatter_of_out_channel c_fd) + "#include \"vyosconfig.h\"@\n%a" + (Cstubs_inverted.write_c ~prefix) stubs; + + (* Generate the C header file that exports OCaml functions. *) + Cstubs_inverted.write_c_header + (Format.formatter_of_out_channel h_fd) ~prefix stubs; + + end; + close_out h_fd; + close_out c_fd; + close_out ml_fd + +let () = generate (Sys.argv.(1)) |