diff options
author | Sébastien Hinderer <Sebastien.Hinderer@inria.fr> | 2017-11-03 18:52:11 +0100 |
---|---|---|
committer | Sébastien Hinderer <Sebastien.Hinderer@inria.fr> | 2017-11-23 17:04:46 +0100 |
commit | f0b9b8e9c40d97c99e1a031c4e220992fe33347f (patch) | |
tree | c3841d6f64610ac11310dc0885bb785b13ff95c3 /ocamltest/ocaml_backends.ml | |
parent | c6f3a00b3105a5496783ac89d9213a5d866d5063 (diff) | |
download | ocaml-f0b9b8e9c40d97c99e1a031c4e220992fe33347f.tar.gz |
ocamltest: refactoring and implementation of hooks
Diffstat (limited to 'ocamltest/ocaml_backends.ml')
-rw-r--r-- | ocamltest/ocaml_backends.ml | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/ocamltest/ocaml_backends.ml b/ocamltest/ocaml_backends.ml new file mode 100644 index 0000000000..1a41d3c399 --- /dev/null +++ b/ocamltest/ocaml_backends.ml @@ -0,0 +1,41 @@ +(**************************************************************************) +(* *) +(* OCaml *) +(* *) +(* Sebastien Hinderer, projet Gallium, INRIA Paris *) +(* *) +(* Copyright 2016 Institut National de Recherche en Informatique et *) +(* en Automatique. *) +(* *) +(* All rights reserved. This file is distributed under the terms of *) +(* the GNU Lesser General Public License version 2.1, with the *) +(* special exception on linking described in the file LICENSE. *) +(* *) +(**************************************************************************) + +(* Backends of the OCaml compiler and their properties *) + +open Ocamltest_stdlib + +type t = Sys.backend_type + +let string_of_backend = function + | Sys.Bytecode -> "bytecode" + | Sys.Native -> "native" + | Sys.Other backend_name -> backend_name + +(* Creates a function that returns its first argument for Bytecode, *) +(* its second argument for Native code and fails for other backends *) +let make_backend_function bytecode_value native_value = function + | Sys.Bytecode -> bytecode_value + | Sys.Native -> native_value + | Sys.Other backend_name -> + let error_message = + ("Other backend " ^ backend_name ^ " not supported") in + raise (Invalid_argument error_message) + +let module_extension = make_backend_function "cmo" "cmx" + +let library_extension = make_backend_function "cma" "cmxa" + +let executable_extension = make_backend_function "byte" "opt" |