]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | ; Copyright 2013 The Rust Project Developers. See the COPYRIGHT |
2 | ; file at the top-level directory of this distribution and at | |
3 | ; http://rust-lang.org/COPYRIGHT. | |
4 | ; | |
5 | ; Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | ; http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | ; <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | ; option. This file may not be copied, modified, or distributed | |
9 | ; except according to those terms. | |
10 | ||
11 | ; Rust's try-catch | |
12 | ; When f(...) returns normally, the return value is null. | |
13 | ; When f(...) throws, the return value is a pointer to the caught exception object. | |
14 | ||
15 | ; See also: libstd/rt/unwind.rs | |
16 | ||
17 | define i8* @rust_try(void (i8*)* %f, i8* %env) { | |
18 | ||
19 | %1 = invoke i8* @rust_try_inner(void (i8*)* %f, i8* %env) | |
20 | to label %normal | |
21 | unwind label %catch | |
22 | ||
23 | normal: | |
24 | ret i8* %1 | |
25 | ||
26 | catch: | |
27 | landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @rust_eh_personality_catch to i8*) | |
28 | catch i8* null | |
29 | ; rust_try_inner's landing pad does not resume unwinds, so execution will never reach here | |
30 | ret i8* null | |
31 | } | |
32 | ||
33 | define internal i8* @rust_try_inner(void (i8*)* %f, i8* %env) { | |
34 | ||
35 | invoke void %f(i8* %env) | |
36 | to label %normal | |
37 | unwind label %catch | |
38 | ||
39 | normal: | |
40 | ret i8* null | |
41 | ||
42 | catch: | |
43 | %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @rust_eh_personality to i8*) | |
44 | catch i8* null | |
45 | ; extract and return pointer to the exception object | |
46 | %2 = extractvalue { i8*, i32 } %1, 0 | |
47 | ret i8* %2 | |
48 | } | |
49 | ||
50 | declare i32 @rust_eh_personality(...) | |
51 | declare i32 @rust_eh_personality_catch(...) |