wamr-python: Enable debugging WASM and grant dir access (#2449)
- Enable debugging a WASM loaded and executed from Python. - Expose API to enable access to list of host directories. Similar to --dir in iwasm. - Add another python language binding sample: native-symbol.
This commit is contained in:
11
language-bindings/python/wamr-api/samples/basic/compile.sh
Executable file
11
language-bindings/python/wamr-api/samples/basic/compile.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
/opt/wasi-sdk/bin/clang \
|
||||
-O0 -z stack-size=4096 -Wl,--initial-memory=65536 \
|
||||
-Wl,--strip-all,--no-entry -nostdlib \
|
||||
-Wl,--export=sum\
|
||||
-Wl,--allow-undefined \
|
||||
-o sum.wasm sum.c
|
||||
22
language-bindings/python/wamr-api/samples/basic/main.py
Normal file
22
language-bindings/python/wamr-api/samples/basic/main.py
Normal file
@ -0,0 +1,22 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
from wamr.wamrapi.wamr import Engine, Module, Instance, ExecEnv
|
||||
from ctypes import c_uint
|
||||
import pathlib
|
||||
|
||||
def main():
|
||||
engine = Engine()
|
||||
module = Module.from_file(engine, pathlib.Path(__file__).parent / "sum.wasm")
|
||||
module_inst = Instance(module)
|
||||
exec_env = ExecEnv(module_inst)
|
||||
|
||||
func = module_inst.lookup_function("sum")
|
||||
|
||||
argv = (c_uint * 2)(*[10, 11])
|
||||
exec_env.call(func, len(argv), argv)
|
||||
print(argv[0])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
12
language-bindings/python/wamr-api/samples/basic/sum.c
Normal file
12
language-bindings/python/wamr-api/samples/basic/sum.c
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
sum(int a, int b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
Reference in New Issue
Block a user