Skip to content

Commit 21f258a

Browse files
committed
LLVMValueRef::Instructions
1 parent 5f87067 commit 21f258a

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,40 @@ public readonly uint InstructionCallConv
176176

177177
public readonly LLVMBasicBlockRef InstructionParent => (IsAInstruction != null) ? LLVM.GetInstructionParent(this) : default;
178178

179+
public readonly IEnumerable<LLVMValueRef> Instructions
180+
{
181+
get
182+
{
183+
if (IsAFunction != default)
184+
{
185+
return GetFunctionInstructions(this);
186+
}
187+
else if (IsABasicBlock != default)
188+
{
189+
return AsBasicBlock().Instructions;
190+
}
191+
else if (IsAInstruction != default)
192+
{
193+
return [this];
194+
}
195+
else
196+
{
197+
return [];
198+
}
199+
200+
static IEnumerable<LLVMValueRef> GetFunctionInstructions(LLVMValueRef function)
201+
{
202+
foreach (LLVMBasicBlockRef basicBlock in function.GetBasicBlocks())
203+
{
204+
foreach (LLVMValueRef instruction in basicBlock.Instructions)
205+
{
206+
yield return instruction;
207+
}
208+
}
209+
}
210+
}
211+
}
212+
179213
public readonly uint IntrinsicID => (Handle != IntPtr.Zero) ? LLVM.GetIntrinsicID(this) : default;
180214

181215
public readonly LLVMValueRef IsAAddrSpaceCastInst => LLVM.IsAAddrSpaceCastInst(this);

0 commit comments

Comments
 (0)