Skip to content

Commit

Permalink
Change runtime/gen_primitives.sh to take the list of .c files as argu…
Browse files Browse the repository at this point in the history
…ment

This avoids writing the list twice, in the top-level Makefile and in the script.
The Dune build needs updating accordingly.

Also: move relevant comments from Makefile to runtime/gen_primitives.sh .
  • Loading branch information
xavierleroy committed Oct 28, 2023
1 parent f6d6f65 commit 2f944c9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 34 deletions.
22 changes: 2 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1251,29 +1251,11 @@ runtime/ld.conf: $(ROOTDIR)/Makefile.config
$(V_GEN)echo "$(STUBLIBDIR)" > $@ && \
echo "$(LIBDIR)" >> $@

# If primitives contain duplicated lines (e.g. because the code is defined
# like
# #ifdef X
# CAMLprim value caml_foo() ...
# #else
# CAMLprim value caml_foo() ...
# #endif), horrible things will happen: duplicated entries in Runtimedef ->
# double registration in Symtable -> empty entry in the PRIM table ->
# the bytecode interpreter is confused.
# We sort the primitive file and remove duplicates to avoid this problem.

# Warning: we use "sort | uniq" instead of "sort -u" because in the MSVC
# port, the "sort" program in the path is Microsoft's and not cygwin's

# Warning: POSIX sort is locale dependent, that's why we set LC_ALL explicitly.
# Sort is unstable for "is_directory" and "isatty"
# see http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html:
# "using sort to process pathnames, it is recommended that LC_ALL .. set to C"

# To speed up builds, we avoid changing "primitives" when files
# containing primitives change but the primitives table does not
runtime/primitives: \
$(shell runtime/gen_primitives.sh > runtime/primitives.new; \
$(shell runtime/gen_primitives.sh $(runtime_BYTECODE_C_SOURCES) \
> runtime/primitives.new; \
cmp -s runtime/primitives runtime/primitives.new || \
echo runtime/primitives.new)
$(V_GEN)cp $^ $@
Expand Down
39 changes: 25 additions & 14 deletions runtime/gen_primitives.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,29 @@
#* *
#**************************************************************************

# #8985: the meaning of character range a-z depends on the locale, so force C
# locale throughout.
# If primitives contain duplicated lines (e.g. because the code is defined
# like
# #ifdef X
# CAMLprim value caml_foo() ...
# #else
# CAMLprim value caml_foo() ...
# #endif), horrible things will happen: duplicated entries in Runtimedef ->
# double registration in Symtable -> empty entry in the PRIM table ->
# the bytecode interpreter is confused.
# We sort the primitive file and remove duplicates to avoid this problem.

# Warning: we use "sort | uniq" instead of "sort -u" because in the MSVC
# port, the "sort" program in the path is Microsoft's and not cygwin's

# Warning: POSIX sort is locale dependent, that's why we set LC_ALL explicitly.
# Sort is unstable for "is_directory" and "isatty"
# see http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html:
# "using sort to process pathnames, it is recommended that LC_ALL .. set to C"

# #8985: in sed, the meaning of character range a-z depends on the locale,
# so force C locale throughout.

export LC_ALL=C
(
for prim in \
alloc array compare extern floats gc_ctrl hash intern interp ints io \
lexing md5 meta memprof obj parsing signals str sys callback weak \
finalise domain platform fiber memory startup_aux runtime_events sync \
dynlink backtrace_byt backtrace afl \
bigarray prng
do
sed -n -e 's/^CAMLprim value \([a-z0-9_][a-z0-9_]*\).*/\1/p' \
"runtime/$prim.c"
done
) | sort | uniq

sed -n -e 's/^CAMLprim value \([a-z][a-z0-9_]*\).*$/\1/p' "$@" | \
sort | uniq

0 comments on commit 2f944c9

Please sign in to comment.