Skip to content

Commit

Permalink
feat: default value for 'name' parameter in many functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziqi-Yang committed Aug 1, 2024
1 parent 354acc3 commit 58a7df4
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 85 deletions.
5 changes: 3 additions & 2 deletions docs/source/tips.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Tips
=====

How to find corresponding python function for a C API
======================================================
-----------------------------------------------------

Pls search the whole project or specific files for that C API
Pls search the whole project or specific files for that C API. (Note, bindings
may also live in the macros in header files)
22 changes: 11 additions & 11 deletions example/llvmir_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@
fn_type = core.FunctionType(IntType.GlobalInt32,
[IntType.GlobalInt32, IntType.GlobalInt32],
False)
m = core.Module("")
fn = core.Function(m, "foo", fn_type)
bb_entry = fn.append_basic_block("")
m = core.Module()
fn = core.Function(m, fn_type, name="foo")
bb_entry = fn.append_basic_block()

builder = core.Builder()
builder.position_at_end(bb_entry)

stackint = builder.alloca(IntType.GlobalInt32, name="")
stackint = builder.alloca(IntType.GlobalInt32)
assert isinstance(stackint.type, IntType) # remove lsp diagnostic
builder.store(core.ConstantInt(stackint.type, 123, True), stackint)
myint = builder.load2(stackint.type, stackint, "")
myint = builder.load2(stackint.type, stackint)

# Currently, every property goes through an function call through LLVM
# involving WRAP and UNWRAP multiple many times through both python - LLVM-C
# layer and LLVM-C - LLVM-C++ layer. There may be some performance loss.
# In the future, we may add cache to object properties.
add_inst = builder.add(fn.params[0], fn.params[1], "")
mul_inst = builder.mul(add_inst, core.ConstantInt(IntType.GlobalInt32, 123, True), "")
pred = builder.icmp(IntPredicate.SLE, add_inst, mul_inst, "")
add_inst = builder.add(fn.params[0], fn.params[1])
mul_inst = builder.mul(add_inst, core.ConstantInt(IntType.GlobalInt32, 123, True))
pred = builder.icmp(IntPredicate.SLE, add_inst, mul_inst)
builder.ret(mul_inst)

bb_block = fn.append_basic_block("")
bb_block = fn.append_basic_block()
builder.position_at_end(bb_block)

bb_exit = fn.append_basic_block("")
bb_exit = fn.append_basic_block()

pred = builder.trunc(add_inst, IntType.GlobalInt1, "")
pred = builder.trunc(add_inst, IntType.GlobalInt1)
builder.cond_br(pred, bb_block, bb_exit)

builder.position_at_end(bb_exit)
Expand Down
1 change: 1 addition & 0 deletions note.typ
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ directory(e.g. `.venv/lib/python3.12/site-packages/llvmpym/llvmpym_ext`) to corr
+ `__str__`
+ `__repr__` (TODO subclasses for type, value)
+ with clause: `__enter__` and `__exit__`
+ iterator for methods like `functions` for Module



Expand Down
Loading

0 comments on commit 58a7df4

Please sign in to comment.