forked from ocaml-flambda/flambda-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12700 from xavierleroy/gen-prims
Generate runtime/prims.c with the correct types in primitive declarations
- Loading branch information
Showing
6 changed files
with
114 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/sh | ||
|
||
#************************************************************************** | ||
#* * | ||
#* OCaml * | ||
#* * | ||
#* Xavier Leroy, Collège de France and Inria * | ||
#* * | ||
#* Copyright 2023 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. * | ||
#* * | ||
#************************************************************************** | ||
|
||
# Build the runtime/prims.c file, with proper C declarations of the primitives | ||
|
||
export LC_ALL=C | ||
|
||
case $# in | ||
0) echo "Usage: gen_primsc.sh <primitives file> <.c files>" 1>&2 | ||
exit 2;; | ||
*) primitives="$1"; shift;; | ||
esac | ||
|
||
cat <<'EOF' | ||
/* Generated file, do not edit */ | ||
#define CAML_INTERNALS | ||
#include "caml/mlvalues.h" | ||
#include "caml/prims.h" | ||
EOF | ||
|
||
# Extract the beginning of primitive definitions: | ||
# from 'CAMLprim' at beginning of line to the first closing parenthesis. | ||
# The first pattern below matches single-line definitions such as | ||
# CAMLprim value foo(value x) { | ||
# The second pattern matches multi-line definitions such as | ||
# CAMLprim value foo(value x, | ||
# value y) | ||
sed -n \ | ||
-e '/^CAMLprim value .*)/p' \ | ||
-e '/^CAMLprim value [^)]*$/,/)/p' \ | ||
"$@" | | ||
# Transform these definitions into "CAMLextern" declarations | ||
sed \ | ||
-e 's/^CAMLprim /CAMLextern /' \ | ||
-e 's/).*$/);/' | ||
|
||
# Generate the table of primitives | ||
echo | ||
echo 'const c_primitive caml_builtin_cprim[] = {' | ||
sed -e 's/.*/ (c_primitive) &,/' "$primitives" | ||
echo ' 0 };' | ||
|
||
# Generate the table of primitive names | ||
echo | ||
echo 'const char * const caml_names_of_builtin_cprim[] = {' | ||
sed -e 's/.*/ "&",/' "$primitives" | ||
echo ' 0 };' |