A method add_external_function(self, name: str, ty: types.Function) -> Function for SimpleModule that adds an externally linked function declaration.
A method call(self, function: Function, args: Sequence[Value]) -> None on Builder that calls a function returned by add_external_function.
A bunch of representations of LLVM and QIR types that are needed to describe the type of an external function, defined in pyqir-generator/pyqir/generator/types.py.
I chose this representation for the types based on two main design goals:
Basic LLVM type system rules should be statically checkable by mypy. For example, Void can be used as a return type, but not as the type of a value. In the future there will be additional rules, like Function can't be used as the type of a value unless it's wrapped in a Pointer (we don't support pointer types yet).
Inspecting a type should work well with Python 3.10 match statements and mypy exhaustiveness checking. mypy has special support for enum.Enum exhaustiveness, so I created singleton enums for the types that don't have any fields. This is difficult to do in Rust, so I defined them in a pure Python module and manually converted them to Rust types.
Resolves #63. The additions to the API are:
add_external_function(self, name: str, ty: types.Function) -> Function
forSimpleModule
that adds an externally linked function declaration.call(self, function: Function, args: Sequence[Value]) -> None
onBuilder
that calls a function returned byadd_external_function
.I chose this representation for the types based on two main design goals:
Void
can be used as a return type, but not as the type of a value. In the future there will be additional rules, likeFunction
can't be used as the type of a value unless it's wrapped in aPointer
(we don't support pointer types yet).match
statements and mypy exhaustiveness checking. mypy has special support forenum.Enum
exhaustiveness, so I created singleton enums for the types that don't have any fields. This is difficult to do in Rust, so I defined them in a pure Python module and manually converted them to Rust types.