Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,33 @@ public readonly int IsNewDbgInfoFormat
}
}

public readonly string InlineAsm
{
get
{
if (Handle == IntPtr.Zero)
{
return string.Empty;
}

nuint len;
var pInlineAsm = LLVM.GetModuleInlineAsm(this, &len);

if (pInlineAsm == null)
{
return string.Empty;
}

return SpanExtensions.AsString(pInlineAsm);
}

set
{
using var marshaledInlineAsm = new MarshaledString(value.AsSpan());
LLVM.SetModuleInlineAsm2(this, marshaledInlineAsm, (nuint)marshaledInlineAsm.Length);
}
}

public readonly LLVMValueRef LastFunction => (Handle != IntPtr.Zero) ? LLVM.GetLastFunction(this) : default;

public readonly LLVMValueRef LastGlobal => (Handle != IntPtr.Zero) ? LLVM.GetLastGlobal(this) : default;
Expand All @@ -85,6 +112,60 @@ public readonly int IsNewDbgInfoFormat

public readonly LLVMModuleNamedMetadataEnumerable NamedMetadata => new LLVMModuleNamedMetadataEnumerable(this);

public readonly string ModuleIdentifier
{
get
{
if (Handle == IntPtr.Zero)
{
return string.Empty;
}

nuint len;
var pModuleIdentifier = LLVM.GetModuleIdentifier(this, &len);

if (pModuleIdentifier == null)
{
return string.Empty;
}

return SpanExtensions.AsString(pModuleIdentifier);
}

set
{
using var marshaledModuleIdentifier = new MarshaledString(value.AsSpan());
LLVM.SetModuleIdentifier(this, marshaledModuleIdentifier, (nuint)marshaledModuleIdentifier.Length);
}
}

public readonly string SourceFileName
{
get
{
if (Handle == IntPtr.Zero)
{
return string.Empty;
}

nuint len;
var pSourceFileName = LLVM.GetSourceFileName(this, &len);

if (pSourceFileName == null)
{
return string.Empty;
}

return SpanExtensions.AsString(pSourceFileName);
}

set
{
using var marshaledSourceFileName = new MarshaledString(value.AsSpan());
LLVM.SetSourceFileName(this, marshaledSourceFileName, (nuint)marshaledSourceFileName.Length);
}
}

public readonly string Target
{
get
Expand Down
53 changes: 53 additions & 0 deletions sources/LLVMSharp.Interop/Extensions/LLVMTargetMachineRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,59 @@ public unsafe partial struct LLVMTargetMachineRef(IntPtr handle) : IEquatable<LL

public static bool operator !=(LLVMTargetMachineRef left, LLVMTargetMachineRef right) => !(left == right);

public readonly string CPU
{
get
{
var pCPU = LLVM.GetTargetMachineCPU(this);

if (pCPU == null)
{
return string.Empty;
}

var result = SpanExtensions.AsString(pCPU);
LLVM.DisposeMessage(pCPU);
return result;
}
}

public readonly string FeatureString
{
get
{
var pFeatureString = LLVM.GetTargetMachineFeatureString(this);

if (pFeatureString == null)
{
return string.Empty;
}

var result = SpanExtensions.AsString(pFeatureString);
LLVM.DisposeMessage(pFeatureString);
return result;
}
}

public readonly LLVMTargetRef Target => (Handle != IntPtr.Zero) ? LLVM.GetTargetMachineTarget(this) : default;

public readonly string Triple
{
get
{
var pTriple = LLVM.GetTargetMachineTriple(this);

if (pTriple == null)
{
return string.Empty;
}

var result = SpanExtensions.AsString(pTriple);
LLVM.DisposeMessage(pTriple);
return result;
}
}

public readonly LLVMTargetDataRef CreateTargetDataLayout() => LLVM.CreateTargetDataLayout(this);

public readonly void EmitToFile(LLVMModuleRef module, string fileName, LLVMCodeGenFileType codegen) => EmitToFile(module, fileName.AsSpan(), codegen);
Expand Down
26 changes: 26 additions & 0 deletions sources/LLVMSharp.Interop/Extensions/LLVMTargetRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,32 @@ public static IEnumerable<LLVMTargetRef> Targets
}
}

public readonly string Description
{
get
{
if (Handle == IntPtr.Zero)
{
return string.Empty;
}

var pDescription = LLVM.GetTargetDescription(this);

if (pDescription == null)
{
return string.Empty;
}

return SpanExtensions.AsString(pDescription);
}
}

public readonly bool HasAsmBackend => (Handle != IntPtr.Zero) && LLVM.TargetHasAsmBackend(this) != 0;

public readonly bool HasJIT => (Handle != IntPtr.Zero) && LLVM.TargetHasJIT(this) != 0;

public readonly bool HasTargetMachine => (Handle != IntPtr.Zero) && LLVM.TargetHasTargetMachine(this) != 0;

public readonly string Name
{
get
Expand Down
144 changes: 142 additions & 2 deletions sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,38 @@ public readonly LLVMDLLStorageClass DLLStorageClass

public readonly LLVMBasicBlockRef EntryBasicBlock => ((IsAFunction != null) && (BasicBlocksCount != 0)) ? LLVM.GetEntryBasicBlock(this) : default;

public readonly bool Exact
{
get
{
return InstructionOpcode is LLVMOpcode.LLVMUDiv or LLVMOpcode.LLVMSDiv or LLVMOpcode.LLVMLShr or LLVMOpcode.LLVMAShr && LLVM.GetExact(this) != 0;
}

set
{
if (InstructionOpcode is LLVMOpcode.LLVMUDiv or LLVMOpcode.LLVMSDiv or LLVMOpcode.LLVMLShr or LLVMOpcode.LLVMAShr)
{
LLVM.SetExact(this, value ? 1 : 0);
}
}
}

public readonly LLVMFastMathFlags FastMathFlags
{
get
{
return (LLVM.CanValueUseFastMathFlags(this) != 0) ? (LLVMFastMathFlags)LLVM.GetFastMathFlags(this) : default;
}

set
{
if (LLVM.CanValueUseFastMathFlags(this) != 0)
{
LLVM.SetFastMathFlags(this, (uint)value);
}
}
}

public readonly LLVMRealPredicate FCmpPredicate => (Handle != IntPtr.Zero) ? LLVM.GetFCmpPredicate(this) : default;

public readonly LLVMBasicBlockRef FirstBasicBlock => (IsAFunction != null) ? LLVM.GetFirstBasicBlock(this) : default;
Expand Down Expand Up @@ -201,6 +233,22 @@ public readonly string GC
}
}

public readonly LLVMGEPNoWrapFlags GEPNoWrapFlags
{
get
{
return (IsAGetElementPtrInst != null) ? (LLVMGEPNoWrapFlags)LLVM.GEPGetNoWrapFlags(this) : default;
}

set
{
if (IsAGetElementPtrInst != null)
{
LLVM.GEPSetNoWrapFlags(this, (uint)value);
}
}
}

public readonly LLVMTypeRef GEPSourceElementType => (IsAGetElementPtrInst != null) ? LLVM.GetGEPSourceElementType(this) : default;

public readonly LLVMValueRef GlobalIFuncResolver
Expand All @@ -224,9 +272,37 @@ public readonly LLVMValueRef GlobalIFuncResolver

public readonly bool HasMetadata => (IsAInstruction != null) && LLVM.HasMetadata(this) != 0;

public readonly bool HasNoSignedWrap => (IsAInstruction != null) && llvmsharp.Instruction_hasNoSignedWrap(this) != 0;
public readonly bool HasNoSignedWrap
{
get
{
return InstructionOpcode is LLVMOpcode.LLVMAdd or LLVMOpcode.LLVMSub or LLVMOpcode.LLVMMul or LLVMOpcode.LLVMShl && LLVM.GetNSW(this) != 0;
}

set
{
if (InstructionOpcode is LLVMOpcode.LLVMAdd or LLVMOpcode.LLVMSub or LLVMOpcode.LLVMMul or LLVMOpcode.LLVMShl)
{
LLVM.SetNSW(this, value ? 1 : 0);
}
}
}

public readonly bool HasNoUnsignedWrap => (IsAInstruction != null) && llvmsharp.Instruction_hasNoUnsignedWrap(this) != 0;
public readonly bool HasNoUnsignedWrap
{
get
{
return InstructionOpcode is LLVMOpcode.LLVMAdd or LLVMOpcode.LLVMSub or LLVMOpcode.LLVMMul or LLVMOpcode.LLVMShl && LLVM.GetNUW(this) != 0;
}

set
{
if (InstructionOpcode is LLVMOpcode.LLVMAdd or LLVMOpcode.LLVMSub or LLVMOpcode.LLVMMul or LLVMOpcode.LLVMShl)
{
LLVM.SetNUW(this, value ? 1 : 0);
}
}
}

public readonly bool HasPersonalityFn => (IsAFunction != null) && LLVM.HasPersonalityFn(this) != 0;

Expand All @@ -245,6 +321,22 @@ public readonly bool HasUnnamedAddr

public readonly LLVMIntPredicate ICmpPredicate => (Handle != IntPtr.Zero) ? LLVM.GetICmpPredicate(this) : default;

public readonly bool ICmpSameSign
{
get
{
return (IsAICmpInst != null) && LLVM.GetICmpSameSign(this) != 0;
}

set
{
if (IsAICmpInst != null)
{
LLVM.SetICmpSameSign(this, value ? 1 : 0);
}
}
}

public readonly uint IncomingCount => (IsAPHINode != null) ? LLVM.CountIncoming(this) : default;

public readonly LLVMValueRef Initializer
Expand Down Expand Up @@ -489,6 +581,22 @@ public readonly bool IsCleanup

public readonly bool IsDeclaration => (IsAGlobalValue != null) && LLVM.IsDeclaration(this) != 0;

public readonly bool IsDisjoint
{
get
{
return InstructionOpcode is LLVMOpcode.LLVMOr && LLVM.GetIsDisjoint(this) != 0;
}

set
{
if (InstructionOpcode is LLVMOpcode.LLVMOr)
{
LLVM.SetIsDisjoint(this, value ? 1 : 0);
}
}
}

public readonly bool IsExternallyInitialized
{
get
Expand All @@ -515,6 +623,22 @@ public readonly bool IsGlobalConstant
}
}

public readonly bool IsInBounds
{
get
{
return (IsAGetElementPtrInst != null) && LLVM.IsInBounds(this) != 0;
}

set
{
if (IsAGetElementPtrInst != null)
{
LLVM.SetIsInBounds(this, value ? 1 : 0);
}
}
}

public readonly bool IsNull => (Handle != IntPtr.Zero) && LLVM.IsNull(this) != 0;

public readonly bool IsPoison => (Handle != IntPtr.Zero) && LLVM.IsPoison(this) != 0;
Expand Down Expand Up @@ -606,6 +730,22 @@ public readonly string Name

public readonly LLVMValueRef NextParam => (IsAArgument != null) ? LLVM.GetNextParam(this) : default;

public readonly bool NNeg
{
get
{
return InstructionOpcode is LLVMOpcode.LLVMZExt or LLVMOpcode.LLVMUIToFP && LLVM.GetNNeg(this) != 0;
}

set
{
if (InstructionOpcode is LLVMOpcode.LLVMZExt or LLVMOpcode.LLVMUIToFP)
{
LLVM.SetNNeg(this, value ? 1 : 0);
}
}
}

public readonly LLVMBasicBlockRef NormalDest => (IsAInvokeInst != null) ? LLVM.GetNormalDest(this) : default;

public readonly uint NumClauses => (IsALandingPadInst != null) ? LLVM.GetNumClauses(this) : default;
Expand Down
Loading
Loading