Skip to content

Commit

Permalink
Provide a way to build the bytecode compiler using Dune (#2093)
Browse files Browse the repository at this point in the history
  • Loading branch information
trefis authored Oct 10, 2018
1 parent 8e80195 commit d68e0e2
Show file tree
Hide file tree
Showing 25 changed files with 953 additions and 131 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
_ocamltest
_ocamltestd
*.odoc
.merlin
_build

# local to root directory

Expand Down
59 changes: 0 additions & 59 deletions .merlin

This file was deleted.

75 changes: 5 additions & 70 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -298,68 +298,8 @@ endif

# The configuration file

# SUBST generates the sed substitution for the variable *named* in $1
# SUBST_QUOTE does the same, adding double-quotes around non-empty strings
# (see FLEXDLL_DIR which must empty if FLEXDLL_DIR is empty but an OCaml
# string otherwise)
SUBST_ESCAPE=$(subst ",\\",$(subst \,\\,$(if $2,$2,$($1))))
SUBST=-e 's|%%$1%%|$(call SUBST_ESCAPE,$1,$2)|'
SUBST_QUOTE2=-e 's|%%$1%%|$(if $2,"$2")|'
SUBST_QUOTE=$(call SUBST_QUOTE2,$1,$(call SUBST_ESCAPE,$1,$2))
FLEXLINK_LDFLAGS=$(if $(OC_LDFLAGS), -link "$(OC_LDFLAGS)")
utils/config.ml: utils/config.mlp Makefile.config Makefile
sed $(call SUBST,AFL_INSTRUMENT) \
$(call SUBST,ARCH) \
$(call SUBST,ARCMD) \
$(call SUBST,ASM) \
$(call SUBST,ASM_CFI_SUPPORTED) \
$(call SUBST,BYTECCLIBS) \
$(call SUBST,CC) \
$(call SUBST,CCOMPTYPE) \
$(call SUBST,CC_PROFILE) \
$(call SUBST,OUTPUTOBJ) \
$(call SUBST,EXT_ASM) \
$(call SUBST,EXT_DLL) \
$(call SUBST,EXE) \
$(call SUBST,EXT_LIB) \
$(call SUBST,EXT_OBJ) \
$(call SUBST,FLAMBDA) \
$(call SUBST,WITH_FLAMBDA_INVARIANTS) \
$(call SUBST,FLEXLINK_FLAGS) \
$(call SUBST_QUOTE,FLEXDLL_DIR) \
$(call SUBST,HOST) \
$(call SUBST,LIBDIR) \
$(call SUBST,LIBUNWIND_AVAILABLE) \
$(call SUBST,LIBUNWIND_LINK_FLAGS) \
$(call SUBST,MKDLL) \
$(call SUBST,MKEXE) \
$(call SUBST,FLEXLINK_LDFLAGS) \
$(call SUBST,MKMAINDLL) \
$(call SUBST,MODEL) \
$(call SUBST,NATIVECCLIBS) \
$(call SUBST,OCAMLC_CFLAGS) \
$(call SUBST,OCAMLC_CPPFLAGS) \
$(call SUBST,OCAMLOPT_CFLAGS) \
$(call SUBST,OCAMLOPT_CPPFLAGS) \
$(call SUBST,PACKLD) \
$(call SUBST,PROFILING) \
$(call SUBST,PROFINFO_WIDTH) \
$(call SUBST,RANLIBCMD) \
$(call SUBST,FORCE_SAFE_STRING) \
$(call SUBST,DEFAULT_SAFE_STRING) \
$(call SUBST,WINDOWS_UNICODE) \
$(call SUBST,SUPPORTS_SHARED_LIBRARIES) \
$(call SUBST,SYSTEM) \
$(call SUBST,SYSTHREAD_SUPPORT) \
$(call SUBST,TARGET) \
$(call SUBST,WITH_FRAME_POINTERS) \
$(call SUBST,WITH_PROFINFO) \
$(call SUBST,WITH_SPACETIME) \
$(call SUBST,ENABLE_CALL_COUNTS) \
$(call SUBST,FLAT_FLOAT_ARRAY) \
$(call SUBST,CC_HAS_DEBUG_PREFIX_MAP) \
$(call SUBST,AS_HAS_DEBUG_PREFIX_MAP) \
$< > $@
utils/config.ml:
$(MAKE) -C utils config.ml

ifeq "$(UNIX_OR_WIN32)" "unix"
.PHONY: reconfigure
Expand Down Expand Up @@ -908,14 +848,9 @@ $(COMMON:.cmo=.cmx) $(BYTECOMP:.cmo=.cmx) $(OPTCOMP:.cmo=.cmx): ocamlopt
runtime/primitives:
$(MAKE) -C runtime primitives

bytecomp/runtimedef.ml: runtime/primitives runtime/caml/fail.h
(echo 'let builtin_exceptions = [|'; \
cat runtime/caml/fail.h | tr -d '\r' | \
sed -n -e 's|.*/\* \("[A-Za-z_]*"\) \*/$$| \1;|p'; \
echo '|]'; \
echo 'let builtin_primitives = [|'; \
sed -e 's/.*/ "&";/' runtime/primitives; \
echo '|]') > $@
bytecomp/runtimedef.ml: bytecomp/generate_runtimedef.sh runtime/caml/fail.h \
runtime/primitives
$^ > $@

partialclean::
rm -f bytecomp/runtimedef.ml
Expand Down
44 changes: 44 additions & 0 deletions asmcomp/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
;**************************************************************************
;* *
;* OCaml *
;* *
;* Thomas Refis, Jane Street Europe *
;* *
;* Copyright 2018 Jane Street Group LLC *
;* *
;* 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. *
;* *
;**************************************************************************

(rule
(targets arch.ml CSE.ml proc.ml reload.ml scheduling.ml selection.ml)
(mode fallback)
(deps (:conf ../Makefile.config)
(glob_files amd64/*.ml)
(glob_files arm/*.ml)
(glob_files arm64/*.ml)
(glob_files i386/*.ml)
(glob_files power/*.ml)
(glob_files s390x/*.ml))
(action (bash "cp `grep 'ARCH=' %{conf} | cut -d'=' -f2`/*.ml .")))

(rule
(targets emit.ml)
(mode fallback)
(deps (:conf ../Makefile.config)
amd64/emit.mlp
arm/emit.mlp
arm64/emit.mlp
i386/emit.mlp
power/emit.mlp
s390x/emit.mlp)
(action
(progn
(with-stdout-to contains-input-name
(bash "echo `grep 'ARCH=' %{conf} | cut -d'=' -f2`/emit.mlp"))
(with-stdout-to %{targets}
(progn
(bash "echo \\# 1 \\\"`cat contains-input-name`\\\"")
(bash "%{dep:../tools/cvt_emit.exe} < `cat contains-input-name`"))))))
28 changes: 28 additions & 0 deletions bytecomp/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
;**************************************************************************
;* *
;* OCaml *
;* *
;* Thomas Refis, Jane Street Europe *
;* *
;* Copyright 2018 Jane Street Group LLC *
;* *
;* 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. *
;* *
;**************************************************************************

(rule
(targets opcodes.ml)
(mode fallback)
(deps (:instr (file ../runtime/caml/instruct.h)))
(action
(bash "%{dep:../tools/make_opcodes.exe} -opcodes < %{instr} > %{targets}")))

(rule
(targets runtimedef.ml)
(mode fallback)
(deps (:fail (file ../runtime/caml/fail.h))
(:prim (file ../runtime/primitives)))
(action (with-stdout-to %{targets}
(run ./generate_runtimedef.sh %{fail} %{prim}))))
25 changes: 25 additions & 0 deletions bytecomp/generate_runtimedef.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

#**************************************************************************
#* *
#* OCaml *
#* *
#* Xavier Leroy, projet Cristal, INRIA Rocquencourt *
#* *
#* Copyright 1999 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. *
#* *
#**************************************************************************

echo 'let builtin_exceptions = [|'
cat "$1" | tr -d '\r' | \
sed -n -e 's|.*/\* \("[A-Za-z_]*"\) \*/$| \1;|p'
echo '|]'

echo 'let builtin_primitives = [|'
sed -e 's/.*/ "&";/' "$2"
echo '|]'
25 changes: 25 additions & 0 deletions debugger/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
;**************************************************************************
;* *
;* OCaml *
;* *
;* Thomas Refis, Jane Street Europe *
;* *
;* Copyright 2018 Jane Street Group LLC *
;* *
;* 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. *
;* *
;**************************************************************************

(ocamllex lexer)
(ocamlyacc parser)

(executable
(name main)
(modes byte)
(flags (:standard -w -9))
(modules_without_implementation parser_aux)
(libraries ocamlcommon ocamltoplevel runtime stdlib unix))

(rule (copy main.exe ocamldebug.byte))
6 changes: 6 additions & 0 deletions driver/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(rule
(targets compdynlink.ml)
(deps (:ml (file ../otherlibs/dynlink/dynlink.ml)))
(action
(with-stdout-to %{targets}
(bash "grep -v 'REMOVE_ME for ../../debugger/dynlink.ml' %{ml}"))))
Loading

0 comments on commit d68e0e2

Please sign in to comment.