11import cllvm
22
3+ /// Enumerates the calling conventions supported by LLVM.
4+ ///
5+ /// The raw values of this enumeration *must* match those in
6+ /// [llvm-c/Core.h](https://github.com/llvm-mirror/llvm/blob/master/include/llvm-c/Core.h)
7+ public enum CallingConvention : UInt32 {
8+ /// The default LLVM calling convention, compatible with C.
9+ case c = 0
10+ /// This calling convention attempts to make calls as fast as possible
11+ /// (e.g. by passing things in registers).
12+ case fast = 8
13+ /// This calling convention attempts to make code in the caller as efficient
14+ /// as possible under the assumption that the call is not commonly executed.
15+ /// As such, these calls often preserve all registers so that the call does
16+ /// not break any live ranges in the caller side.
17+ case cold = 9
18+ /// Calling convention for stack based JavaScript calls.
19+ case webKitJS = 12
20+ /// Calling convention for dynamic register based calls
21+ /// (e.g. stackmap and patchpoint intrinsics).
22+ case anyReg = 13
23+ /// The calling conventions mostly used by the Win32 API.
24+ ///
25+ /// It is basically the same as the C convention with the difference in that
26+ /// the callee is responsible for popping the arguments from the stack.
27+ case x86Stdcall = 64
28+ /// "Fast" analog of `x86Stdcall`.
29+ ///
30+ /// Passes first two arguments in ECX:EDX registers, others via the stack.
31+ /// The callee is responsible for stack cleaning.
32+ case x86Fastcall = 65
33+ }
34+
335/// A `Function` represents a named function body in LLVM IR source. Functions
436/// in LLVM IR encapsulate a list of parameters and a sequence of basic blocks
537/// and provide a way to append to that sequence to build out its body.
@@ -9,6 +41,12 @@ public class Function: IRGlobal {
941 self . llvm = llvm
1042 }
1143
44+ /// Accesses the calling convention for this function.
45+ public var callingConvention : CallingConvention {
46+ get { return CallingConvention ( rawValue: LLVMGetFunctionCallConv ( llvm) ) ! }
47+ set { LLVMSetFunctionCallConv ( llvm, newValue. rawValue) }
48+ }
49+
1250 /// Retrieves the entry block of this function.
1351 ///
1452 /// The first basic block in a function is special in two ways: it is
0 commit comments