Add a func_addr instruction.

Get the callable address of a function. Use for long distance calls and
for creating arguments to call_indirect in general.
This commit is contained in:
Jakob Stoklund Olesen
2017-09-19 15:54:02 -07:00
parent 0cfea8858a
commit d92686d1cd
8 changed files with 42 additions and 8 deletions

View File

@@ -411,13 +411,7 @@ This simple example illustrates direct function calls and signatures::
Indirect function calls use a signature declared in the preamble.
.. autoinst:: call_indirect
.. todo:: Define safe indirect function calls.
The :inst:`call_indirect` instruction is dangerous to use in a sandboxed
environment since it is not easy to verify the callee address.
We need a table-driven indirect call instruction, similar to
:inst:`br_table`.
.. autoinst:: func_addr
Memory

View File

@@ -69,6 +69,19 @@ ebb0(v0: i64):
; check: $v3, $v4 = call_indirect $sig2, $v1()
; check: return
function %long_call() {
sig0 = ()
fn0 = sig0 %none
ebb0:
v0 = func_addr.i32 fn0
call_indirect sig0, v0()
return
}
; check: $v0 = func_addr.i32 $fn0
; check: call_indirect $sig0, $v0()
; check: return
; Special purpose function arguments
function %special1(i32 sret, i32 fp, i32 csr, i32 link) -> i32 link, i32 fp, i32 csr, i32 sret {
ebb0(v1: i32, v2: i32, v3: i32, v4: i32):