ฉันกำลังพยายามสร้างไฟล์ wasm ที่ถูกต้องซึ่งเว็บเบราว์เซอร์ (Firefox) จะเข้าใจได้อย่างถูกต้อง แต่ฉันไม่แน่ใจว่าฉันทำผิดที่นี่
นี่คือไฟล์ Main.ll
define i32 @main() {
ret i32 42
}
จากนั้นฉันใช้ llc (Linux):
./llc -mtriple=wasm32-unknown-unknown -O3 -filetype=obj main.ll -o main.o
จากนั้นฉันใช้ wasm-ld (Linux):
./wasm-ld main.o -o main.wasm --no-entry -allow-unknown
จากนั้นฉันกำลังคัดลอก main.wasm
ไปยัง Windows แล้วเปิดหน้าไฟล์ในเครื่องนี้:
|-- fille.html
|-- main.wasm
<div id="test">
</div>
<style>
#test
{
border: 3px solid red;
width: 100%;
height: 100%;
}
</style>
<script>
fetch("main.wasm")
.then(response => response.arrayBuffer())
.then(bytes => WebAssembly.instantiate(bytes, {}))
.then(results => {
window.alert(results.instance.exports.main());
});
</script>
แต่
TypeError: results.instance.exports.main ไม่ใช่ฟังก์ชัน
เกิดอะไรขึ้น?
นี่คือผลลัพธ์ของ:
console.log(JSON.stringify(ผลลัพธ์));
{"module":{},"instance":{}}
รุ่น:
./llc --version
LLVM (http://llvm.org/):
LLVM version 10.0.0
./wasm-ld --version
LLD 10.0.0