Ejemplo n.º 1
0
        public bool TryPrintToFile(ReadOnlySpan <char> Filename, out string ErrorMessage)
        {
            using var marshaledFilename = new MarshaledString(Filename);

            sbyte *pErrorMessage = null;
            int    result        = 0;

            try
            {
                result = LLVM.PrintModuleToFile(this, marshaledFilename, &pErrorMessage);
            }
            catch (Exception)
            {
            }

            if (pErrorMessage is null)
            {
                ErrorMessage = string.Empty;
            }
            else
            {
                var span = new ReadOnlySpan <byte>(pErrorMessage, int.MaxValue);
                ErrorMessage = span.Slice(0, span.IndexOf((byte)'\0')).AsString();
            }

            return(result == 0);
        }
 public bool TryFindFunction(ReadOnlySpan <char> Name, out LLVMValueRef OutFn)
 {
     fixed(LLVMValueRef *pOutFn = &OutFn)
     {
         using var marshaledName = new MarshaledString(Name);
         return(LLVM.FindFunction(this, marshaledName, (LLVMOpaqueValue **)pOutFn) == 0);
     }
 }
Ejemplo n.º 3
0
        public LLVMMetadataRef CreateMacro(LLVMMetadataRef ParentMacroFile, uint Line, LLVMDWARFMacinfoRecordType RecordType, ReadOnlySpan <char> Name, ReadOnlySpan <char> Value)
        {
            using var marshaledName  = new MarshaledString(Name);
            using var marshaledValue = new MarshaledString(Value);
            var nameLength  = (uint)marshaledName.Length;
            var valueLength = (uint)marshaledValue.Length;

            return(LLVM.DIBuilderCreateMacro(this, ParentMacroFile, Line, RecordType, marshaledName, (UIntPtr)nameLength, marshaledValue, (UIntPtr)valueLength));
        }
Ejemplo n.º 4
0
        public LLVMMetadataRef CreateCompileUnit(LLVMDWARFSourceLanguage SourceLanguage, LLVMMetadataRef FileMetadata, ReadOnlySpan <char> Producer, int IsOptimized, ReadOnlySpan <char> Flags, uint RuntimeVersion,
                                                 ReadOnlySpan <char> SplitName, LLVMDWARFEmissionKind DwarfEmissionKind, uint DWOld, int SplitDebugInlining, int DebugInfoForProfiling)
        {
            using var marshaledProducer       = new MarshaledString(Producer);
            using var marshaledFlags          = new MarshaledString(Flags);
            using var marshaledSplitNameFlags = new MarshaledString(SplitName);

            return(LLVM.DIBuilderCreateCompileUnit(this, SourceLanguage, FileMetadata, marshaledProducer, (UIntPtr)marshaledProducer.Length, IsOptimized, marshaledFlags, (UIntPtr)marshaledFlags.Length,
                                                   RuntimeVersion, marshaledSplitNameFlags, (UIntPtr)marshaledSplitNameFlags.Length, DwarfEmissionKind, DWOld, SplitDebugInlining, DebugInfoForProfiling));
        }
Ejemplo n.º 5
0
        public LLVMMetadataRef CreateFunction(LLVMMetadataRef Scope, ReadOnlySpan <char> Name, ReadOnlySpan <char> LinkageName, LLVMMetadataRef File, uint LineNo, LLVMMetadataRef Type, int IsLocalToUnit, int IsDefinition,
                                              uint ScopeLine, LLVMDIFlags Flags, int IsOptimized)
        {
            using var marshaledName        = new MarshaledString(Name);
            using var marshaledLinkageName = new MarshaledString(LinkageName);
            var methodNameLength  = (uint)marshaledName.Length;
            var linkageNameLength = (uint)marshaledLinkageName.Length;

            return(LLVM.DIBuilderCreateFunction(this, Scope, marshaledName, (UIntPtr)(methodNameLength), marshaledLinkageName, (UIntPtr)(linkageNameLength), File,
                                                LineNo, Type, IsLocalToUnit, IsDefinition, ScopeLine, Flags, IsOptimized));
        }
Ejemplo n.º 6
0
        public LLVMValueRef[] GetNamedMetadataOperands(ReadOnlySpan <char> Name)
        {
            using var marshaledName = new MarshaledString(Name);
            var Dest = new LLVMValueRef[LLVM.GetNamedMetadataNumOperands(this, marshaledName)];

            fixed(LLVMValueRef *pDest = Dest)
            {
                LLVM.GetNamedMetadataOperands(this, marshaledName, (LLVMOpaqueValue **)pDest);
            }

            return(Dest);
        }
Ejemplo n.º 7
0
        public LLVMMetadataRef CreateModule(LLVMMetadataRef ParentScope, ReadOnlySpan <char> Name, ReadOnlySpan <char> ConfigMacros, ReadOnlySpan <char> IncludePath, ReadOnlySpan <char> SysRoot)
        {
            using var marshaledName         = new MarshaledString(Name);
            using var marshaledConfigMacros = new MarshaledString(ConfigMacros);
            using var marshaledIncludePath  = new MarshaledString(IncludePath);
            using var marshaledSysRoot      = new MarshaledString(SysRoot);
            var nameLength         = (uint)marshaledName.Length;
            var configMacrosLength = (uint)marshaledConfigMacros.Length;
            var includePathLength  = (uint)marshaledIncludePath.Length;
            var sysRootLength      = (uint)marshaledSysRoot.Length;

            return(LLVM.DIBuilderCreateModule(this, ParentScope, marshaledName, (UIntPtr)nameLength, marshaledConfigMacros, (UIntPtr)configMacrosLength, marshaledIncludePath, (UIntPtr)includePathLength, marshaledSysRoot, (UIntPtr)sysRootLength));
        }
Ejemplo n.º 8
0
        public MarshaledStringArray(ReadOnlySpan <string> inputs)
        {
            if (inputs.IsEmpty)
            {
                Count  = 0;
                Values = null;
            }
            else
            {
                Count  = inputs.Length;
                Values = new MarshaledString[Count];

                for (int i = 0; i < Count; i++)
                {
                    Values[i] = new MarshaledString(inputs[i].AsSpan());
                }
            }
        }
Ejemplo n.º 9
0
        public bool TryEmitToFile(LLVMModuleRef module, string fileName, LLVMCodeGenFileType codegen, out string message)
        {
            using var marshaledFileName = new MarshaledString(fileName);

            sbyte *errorMessage;
            int    result = LLVM.TargetMachineEmitToFile(this, module, marshaledFileName, codegen, &errorMessage);

            if (errorMessage is null)
            {
                message = string.Empty;
            }
            else
            {
                var span = new ReadOnlySpan <byte>(errorMessage, int.MaxValue);
                message = span.Slice(0, span.IndexOf((byte)'\0')).AsString();
                LLVM.DisposeErrorMessage(errorMessage);
            }

            return(result == 0);
        }
Ejemplo n.º 10
0
        public static bool TryGetTargetFromTriple(ReadOnlySpan <char> triple, out LLVMTargetRef outTarget, out string outError)
        {
            using var marshaledTriple = new MarshaledString(triple);

            fixed(LLVMTargetRef *pOutTarget = &outTarget)
            {
                sbyte *pError;
                var    result = LLVM.GetTargetFromTriple(marshaledTriple, (LLVMTarget **)pOutTarget, &pError);

                if (pError is null)
                {
                    outError = string.Empty;
                }
                else
                {
                    var span = new ReadOnlySpan <byte>(pError, int.MaxValue);
                    outError = span.Slice(0, span.IndexOf((byte)'\0')).AsString();
                }

                return(result == 0);
            }
        }
Ejemplo n.º 11
0
 public LLVMValueRef GetConstString(ReadOnlySpan <char> Str, bool DontNullTerminate)
 {
     using var marshaledStr = new MarshaledString(Str);
     return(LLVM.ConstStringInContext(this, marshaledStr, (uint)marshaledStr.Length, DontNullTerminate ? 1 : 0));
 }
Ejemplo n.º 12
0
 public LLVMValueRef GetNamedGlobal(ReadOnlySpan <char> Name)
 {
     using var marshaledName = new MarshaledString(Name);
     return(LLVM.GetNamedGlobal(this, marshaledName));
 }
Ejemplo n.º 13
0
 public void AddNamedMetadataOperand(ReadOnlySpan <char> Name, LLVMMetadataRef CompileUnitMetadata)
 {
     using var marshaledName = new MarshaledString(Name);
     LLVM.AddNamedMetadataOperand(this, marshaledName, LLVM.MetadataAsValue(Context, CompileUnitMetadata));
 }
Ejemplo n.º 14
0
 public void AddNamedMetadataOperand(ReadOnlySpan <char> Name, LLVMValueRef Val)
 {
     using var marshaledName = new MarshaledString(Name);
     LLVM.AddNamedMetadataOperand(this, marshaledName, Val);
 }
Ejemplo n.º 15
0
 public void AddModuleFlag(ReadOnlySpan <char> FlagName, LLVMModuleFlagBehavior Behavior, LLVMMetadataRef ValAsMetadataRef)
 {
     using var marshaledName = new MarshaledString(FlagName);
     LLVM.AddModuleFlag(this, Behavior, marshaledName, (UIntPtr)FlagName.Length, ValAsMetadataRef);
 }
Ejemplo n.º 16
0
 public LLVMValueRef AddGlobalInAddressSpace(LLVMTypeRef Ty, ReadOnlySpan <char> Name, uint AddressSpace)
 {
     using var marshaledName = new MarshaledString(Name);
     return(LLVM.AddGlobalInAddressSpace(this, Ty, marshaledName, AddressSpace));
 }
Ejemplo n.º 17
0
 public LLVMValueRef AddFunction(ReadOnlySpan <char> Name, LLVMTypeRef FunctionTy)
 {
     using var marshaledName = new MarshaledString(Name);
     return(LLVM.AddFunction(this, marshaledName, FunctionTy));
 }
Ejemplo n.º 18
0
 public LLVMTypeRef CreateNamedStruct(ReadOnlySpan <char> Name)
 {
     using var marshaledName = new MarshaledString(Name);
     return(LLVM.StructCreateNamed(this, marshaledName));
 }
Ejemplo n.º 19
0
 public static LLVMBasicBlockRef CreateInContext(LLVMContextRef C, ReadOnlySpan <char> Name)
 {
     using var marshaledName = new MarshaledString(Name);
     return(LLVM.CreateBasicBlockInContext(C, marshaledName));
 }
Ejemplo n.º 20
0
 public static LLVMModuleRef CreateWithName(ReadOnlySpan <char> ModuleID)
 {
     using var marshaledModuleID = new MarshaledString(ModuleID);
     return(LLVM.ModuleCreateWithName(marshaledModuleID));
 }
Ejemplo n.º 21
0
 public void SetModuleInlineAsm(ReadOnlySpan <char> Asm)
 {
     using var marshaledAsm = new MarshaledString(Asm);
     LLVM.SetModuleInlineAsm(this, marshaledAsm);
 }
Ejemplo n.º 22
0
 public uint GetNamedMetadataOperandsCount(ReadOnlySpan <char> Name)
 {
     using var marshaledName = new MarshaledString(Name);
     return(LLVM.GetNamedMetadataNumOperands(this, marshaledName));
 }
Ejemplo n.º 23
0
 public LLVMBasicBlockRef InsertBasicBlock(ReadOnlySpan <char> Name)
 {
     using var marshaledName = new MarshaledString(Name);
     return(LLVM.InsertBasicBlock(this, marshaledName));
 }
Ejemplo n.º 24
0
 public static LLVMBasicBlockRef InsertInContext(LLVMContextRef C, LLVMBasicBlockRef BB, ReadOnlySpan <char> Name)
 {
     using var marshaledName = new MarshaledString(Name);
     return(LLVM.InsertBasicBlockInContext(C, BB, marshaledName));
 }
Ejemplo n.º 25
0
 public LLVMTypeRef GetTypeByName(ReadOnlySpan <char> Name)
 {
     using var marshaledName = new MarshaledString(Name);
     return(LLVM.GetTypeByName(this, marshaledName));
 }
Ejemplo n.º 26
0
 public uint GetMDKindID(ReadOnlySpan <char> Name)
 {
     using var marshaledName = new MarshaledString(Name);
     return(LLVM.GetMDKindIDInContext(this, marshaledName, (uint)marshaledName.Length));
 }
Ejemplo n.º 27
0
 public int WriteBitcodeToFile(ReadOnlySpan <char> Path)
 {
     using var marshaledPath = new MarshaledString(Path);
     return(LLVM.WriteBitcodeToFile(this, marshaledPath));
 }
Ejemplo n.º 28
0
 public LLVMValueRef GetMDString(ReadOnlySpan <char> Str)
 {
     using var marshaledStr = new MarshaledString(Str);
     return(LLVM.MDStringInContext(this, marshaledStr, (uint)marshaledStr.Length));
 }
Ejemplo n.º 29
0
 public LLVMValueRef AddAlias(LLVMTypeRef Ty, LLVMValueRef Aliasee, ReadOnlySpan <char> Name)
 {
     using var marshaledName = new MarshaledString(Name);
     return(LLVM.AddAlias(this, Ty, Aliasee, marshaledName));
 }
Ejemplo n.º 30
0
 public LLVMModuleRef CreateModuleWithName(ReadOnlySpan <char> ModuleID)
 {
     using var marshaledModuleID = new MarshaledString(ModuleID);
     return(LLVM.ModuleCreateWithNameInContext(marshaledModuleID, this));
 }