Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
numba
GitHub Repository: numba/llvmlite
Path: blob/main/examples/ir_fpadd.py
1154 views
1
"""
2
This file demonstrates a trivial function "fpadd" returning the sum of
3
two floating-point numbers.
4
"""
5
6
from llvmlite import ir
7
8
# Create some useful types
9
double = ir.DoubleType()
10
fnty = ir.FunctionType(double, (double, double))
11
12
# Create an empty module...
13
module = ir.Module(name=__file__)
14
# and declare a function named "fpadd" inside it
15
func = ir.Function(module, fnty, name="fpadd")
16
17
# Now implement the function
18
block = func.append_basic_block(name="entry")
19
builder = ir.IRBuilder(block)
20
a, b = func.args
21
result = builder.fadd(a, b, name="res")
22
builder.ret(result)
23
24
# Print the module IR
25
print(module)
26
27