mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 03:27:48 +00:00
89ffb47a0c
Add unwinding and recover support for wasm using WebAssembly exception
handling. This still has a few gotchas:
* Many WASI systems don't support exception handling yet.
For example, see:
https://github.com/bytecodealliance/wasmtime/issues/2049
* Asyncify doesn't support wasm exception handling:
https://github.com/WebAssembly/binaryen/issues/4470
This means it's not possible to use goroutines together with
panic/recover.
* The current way that exceptions are implemented pretend to be C++
exceptions, but work slightly differently. If C++ code is called
(for example through CGo) that raises an exception, that exception
will be eaten by TinyGo and not be propagated. This is fixable, it
just hasn't been implemented (because we don't actually support C++
right now).
I hope that these issues will be resolved over time. At least for now,
people who need `recover()` have a way to use it.
181 lines
6.3 KiB
LLVM
181 lines
6.3 KiB
LLVM
; ModuleID = 'go1.21.go'
|
|
source_filename = "go1.21.go"
|
|
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
|
|
target triple = "wasm32-unknown-wasi"
|
|
|
|
%runtime._string = type { ptr, i32 }
|
|
|
|
; Function Attrs: allockind("alloc,zeroed") allocsize(0)
|
|
declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare void @runtime.trackPointer(ptr nocapture readonly, ptr, ptr) #1
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden void @main.init(ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
ret void
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden i32 @main.min1(i32 %a, ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
ret i32 %a
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden i32 @main.min2(i32 %a, i32 %b, ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
%0 = call i32 @llvm.smin.i32(i32 %a, i32 %b)
|
|
ret i32 %0
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden i32 @main.min3(i32 %a, i32 %b, i32 %c, ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
%0 = call i32 @llvm.smin.i32(i32 %a, i32 %b)
|
|
%1 = call i32 @llvm.smin.i32(i32 %0, i32 %c)
|
|
ret i32 %1
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden i32 @main.min4(i32 %a, i32 %b, i32 %c, i32 %d, ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
%0 = call i32 @llvm.smin.i32(i32 %a, i32 %b)
|
|
%1 = call i32 @llvm.smin.i32(i32 %0, i32 %c)
|
|
%2 = call i32 @llvm.smin.i32(i32 %1, i32 %d)
|
|
ret i32 %2
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden i8 @main.minUint8(i8 %a, i8 %b, ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
%0 = call i8 @llvm.umin.i8(i8 %a, i8 %b)
|
|
ret i8 %0
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden i32 @main.minUnsigned(i32 %a, i32 %b, ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
%0 = call i32 @llvm.umin.i32(i32 %a, i32 %b)
|
|
ret i32 %0
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden float @main.minFloat32(float %a, float %b, ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
%0 = fcmp olt float %a, %b
|
|
%1 = select i1 %0, float %a, float %b
|
|
ret float %1
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden double @main.minFloat64(double %a, double %b, ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
%0 = fcmp olt double %a, %b
|
|
%1 = select i1 %0, double %a, double %b
|
|
ret double %1
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden %runtime._string @main.minString(ptr %a.data, i32 %a.len, ptr %b.data, i32 %b.len, ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
%0 = insertvalue %runtime._string zeroinitializer, ptr %a.data, 0
|
|
%1 = insertvalue %runtime._string %0, i32 %a.len, 1
|
|
%2 = insertvalue %runtime._string zeroinitializer, ptr %b.data, 0
|
|
%3 = insertvalue %runtime._string %2, i32 %b.len, 1
|
|
%stackalloc = alloca i8, align 1
|
|
%4 = call i1 @runtime.stringLess(ptr %a.data, i32 %a.len, ptr %b.data, i32 %b.len, ptr undef) #5
|
|
%5 = select i1 %4, %runtime._string %1, %runtime._string %3
|
|
%6 = extractvalue %runtime._string %5, 0
|
|
call void @runtime.trackPointer(ptr %6, ptr nonnull %stackalloc, ptr undef)
|
|
ret %runtime._string %5
|
|
}
|
|
|
|
declare i1 @runtime.stringLess(ptr, i32, ptr, i32, ptr) #2
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden i32 @main.maxInt(i32 %a, i32 %b, ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
%0 = call i32 @llvm.smax.i32(i32 %a, i32 %b)
|
|
ret i32 %0
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden i32 @main.maxUint(i32 %a, i32 %b, ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
%0 = call i32 @llvm.umax.i32(i32 %a, i32 %b)
|
|
ret i32 %0
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden float @main.maxFloat32(float %a, float %b, ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
%0 = fcmp ogt float %a, %b
|
|
%1 = select i1 %0, float %a, float %b
|
|
ret float %1
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden %runtime._string @main.maxString(ptr %a.data, i32 %a.len, ptr %b.data, i32 %b.len, ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
%0 = insertvalue %runtime._string zeroinitializer, ptr %a.data, 0
|
|
%1 = insertvalue %runtime._string %0, i32 %a.len, 1
|
|
%2 = insertvalue %runtime._string zeroinitializer, ptr %b.data, 0
|
|
%3 = insertvalue %runtime._string %2, i32 %b.len, 1
|
|
%stackalloc = alloca i8, align 1
|
|
%4 = call i1 @runtime.stringLess(ptr %b.data, i32 %b.len, ptr %a.data, i32 %a.len, ptr undef) #5
|
|
%5 = select i1 %4, %runtime._string %1, %runtime._string %3
|
|
%6 = extractvalue %runtime._string %5, 0
|
|
call void @runtime.trackPointer(ptr %6, ptr nonnull %stackalloc, ptr undef)
|
|
ret %runtime._string %5
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden void @main.clearSlice(ptr %s.data, i32 %s.len, i32 %s.cap, ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
%0 = shl i32 %s.len, 2
|
|
call void @llvm.memset.p0.i32(ptr align 4 %s.data, i8 0, i32 %0, i1 false)
|
|
ret void
|
|
}
|
|
|
|
; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
|
|
declare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1 immarg) #3
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden void @main.clearZeroSizedSlice(ptr %s.data, i32 %s.len, i32 %s.cap, ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
ret void
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define hidden void @main.clearMap(ptr dereferenceable_or_null(40) %m, ptr %context) unnamed_addr #1 {
|
|
entry:
|
|
call void @runtime.hashmapClear(ptr %m, ptr undef) #5
|
|
ret void
|
|
}
|
|
|
|
declare void @runtime.hashmapClear(ptr dereferenceable_or_null(40), ptr) #2
|
|
|
|
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
|
|
declare i32 @llvm.smin.i32(i32, i32) #4
|
|
|
|
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
|
|
declare i8 @llvm.umin.i8(i8, i8) #4
|
|
|
|
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
|
|
declare i32 @llvm.umin.i32(i32, i32) #4
|
|
|
|
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
|
|
declare i32 @llvm.smax.i32(i32, i32) #4
|
|
|
|
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
|
|
declare i32 @llvm.umax.i32(i32, i32) #4
|
|
|
|
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+exception-handling,+mutable-globals,+nontrapping-fptoint,+sign-ext" }
|
|
attributes #1 = { nounwind "target-features"="+bulk-memory,+exception-handling,+mutable-globals,+nontrapping-fptoint,+sign-ext" }
|
|
attributes #2 = { "target-features"="+bulk-memory,+exception-handling,+mutable-globals,+nontrapping-fptoint,+sign-ext" }
|
|
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
|
|
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
|
|
attributes #5 = { nounwind }
|