Introduce the type Cmm.exttype to precisely describe arguments to
external C functions, especially unboxed numerical arguments.
Annotate Cmm.Cextcall with the types of the arguments (Cmm.exttype list).
An empty list means "all arguments have default type XInt".
Annotate Mach.Iextcall with the type of the result (Cmm.machtype)
and the types of the arguments (Cmm.exttype list).
Change (slightly) the API for describing calling conventions in Proc:
- loc_external_arguments now takes a Cmm.exttype list,
in order to know more precisely the types of the arguments.
- loc_arguments, loc_parameters, loc_results, loc_external_results
now take a Cmm.machype instead of an array of pseudoregisters.
(Only the types of the pseudoregisters mattered anyway.)
Update the implementations of module Proc accordingly, in every port.
Introduce a new overridable method in Selectgen, insert_move_extcall_arg,
to produce the code that moves an argument of an external C function
to the locations returned by Proc.loc_external_arguments.
Revise the selection of external calls accordingly
(method emit_extcall_args in Selectgen).
Software emulation of floating-point arithmetic, as in the ARM EABI port,
use pairs of pseudoregisters of type Int to represent values of type Float.
This is achieved by the `regs_for` method of class `selector_generic`,
which defaults to `Reg.createv` but is overriden for ARM EABI so
as to perform the transformation Float -> Int,Int on the fly.
The method `bind_let_mut` uses `Reg.createv` to associate
pseudoregisters to bound variables. This is incorrect in a soft FP
context, as a bound variable of type Float will get a Float register
nonetheless. `self#regs_for` must be used instead. This is what this
commit does.
Since #9316 was merged, Cconst_pointer is compiled in exactly the same way as Cconst_int. This commit removes the now-redundant Cconst_pointer and Cconst_natpointer.
Fix tail-call optimisation with a mutable ref
(Clet_mutable was not recognized properly in tail position.)
Add a test for tail-call optimisation with a mutable ref
This code is adapted from jhjourdan's 2c93ca1e711. Comballoc is
extended to keep track of allocation sizes and debug info for each
allocation, and the frame table format is modified to store them.
The native code GC-entry logic is changed to match bytecode, by
calling the garbage collector at most once per allocation.
amd64 only, for now.
Since we cannot access backtrace position in cmmgen.ml anymore,
Cmm.raise_kind in removed. Instead, we use Lambda.raise_kind. When
assembly code is generated, we reset the backtrace position to 0 in the
case of regular raise. Importantly, the semantics remains the same.
Following on from GPR#851 and GPR#873, this pull request further enhances debugging information in Cmm terms. This was driven both by manually examining the debugger's behaviour and also by a report received from a user regarding substandard DWARF location information.
- Ident.create now takes a scope as argument
- added Ident.create_var to use when the scope doesn't matter
- the current_time and the current_level are unrelated as of this
commit. But one has to remember to bump the level when creating new
scopes.
Summary
-------
This patch adds explicit type annotations for Ccatch payloads in the CMM
IR, thus supporting payloads which are not of type `val`.
Rationale
---------
While CMM generated from OCaml source will always generate payloads of type
`val`, this is not the case when targeting CMM to compile from a different
language. As a concrete example, I am currently targeting the CMM backend for
compilation of WebAssembly, and require `float` payloads. Additionally, @mshinwell
has noted that such an extension will be useful for flambda2. As a result, this
patch will increase the applicability of the CMM IR as a compilation target.
Updates
-------
25/06/2018: Incorporate review comments by @xclerc
Design
------
The design of the patch is as follows:
1. Add explicit type annotations to Ccatch handlers. Specifically,
```Ccatch (int * (Ident.t list) * expression)```
becomes
```Ccatch (int * (Ident.t * machtype) list * expression)```
2. By default, in `cmmgen`, select `typ_val` as the `machtype`
3. Select an appropriate register using the type annotation in `selectgen`,
instead of defaulting to `typ_val`
4. Test updates:
- Update the CMM parser and pretty-printer to require annotations on Ccatch
handlers
- Update the existing CMM tests to add the required annotations
- Add new tests which require the use of floating-point registers, for
which the compiler would generate invalid ASM prior to this patch
Since all OCaml code will use `typ_val` as before in `cmmgen` and therefore
`selectgen`, compilation for OCaml programs will be identical.
since the semantic changed. There is no need to check Clflags.debug
anymore Raise_withtrace, means that traces must be computed (if the
runtime boolean is true).