예제 #1
0
        /// <summary>Create an <see cref="MDNode"/> from a string</summary>
        /// <param name="value">String value</param>
        /// <returns>New node with the string as the first element of the <see cref="MDNode.Operands"/> property (as an MDString)</returns>
        public MDNode CreateMDNode(string value)
        {
            var elements = new[] { CreateMetadataString(value).MetadataHandle };
            var hNode    = LibLLVMMDNode2(ContextHandle, elements, ( uint )elements.Length);

            return(MDNode.FromHandle <MDNode>(hNode));
        }
예제 #2
0
        internal ModuleFlag(MDNode node)
        {
            node.ValidateNotNull(nameof(node));
            if (node.Operands.Count != 3)
            {
                throw new ArgumentException(Resources.Expected_node_with_3_operands, nameof(node));
            }

            if (!(node.Operands[0] is ConstantAsMetadata behavior))
            {
                throw new ArgumentException(Resources.Expected_ConstantAsMetadata_for_first_operand, nameof(node));
            }

            if (!(behavior.Constant is ConstantInt behaviorConst))
            {
                throw new ArgumentException(Resources.Expected_ConstantInt_wrapped_in_first_operand, nameof(node));
            }

            if (!(node.Operands[1] is MDString nameMd))
            {
                throw new ArgumentException(Resources.Expected_MDString_as_second_operand, nameof(node));
            }

            Behavior = ( ModuleFlagBehavior )(behaviorConst.ZeroExtendedValue);
            Name     = nameMd.ToString( );
            Metadata = node.Operands[2];
        }
예제 #3
0
파일: MDOperand.cs 프로젝트: nbsn2/Llvm.NET
        internal MDOperand(MDNode owningNode, LLVMMDOperandRef handle)
        {
            handle.ValidateNotDefault(nameof(handle));

            OperandHandle = handle;
            OwningNode    = owningNode;
        }
예제 #4
0
        /// <summary>Create an <see cref="MDNode"/> from a string</summary>
        /// <param name="value">String value</param>
        /// <returns>New node with the string as the first element of the <see cref="MDNode.Operands"/> property (as an MDString)</returns>
        public MDNode CreateMDNode(string value)
        {
            ValidateHandle( );
            var elements = new LLVMMetadataRef[] { LLVMMDString2(Context.ContextHandle, value, ( uint )(value?.Length ?? 0)) };
            var hNode    = LLVMMDNode2(Context.ContextHandle, out elements[0], ( uint )elements.Length);

            return(MDNode.FromHandle <MDNode>(hNode));
        }
예제 #5
0
        internal MDOperand(MDNode owningNode, LLVMMDOperandRef handle)
        {
            if (handle.Pointer == IntPtr.Zero)
            {
                throw new ArgumentNullException(nameof(handle));
            }

            OperandHandle = handle;
            OwningNode    = owningNode;
        }
예제 #6
0
        /// <summary>Creates a Function definition with Debug information</summary>
        /// <param name="scope">Containing scope for the function</param>
        /// <param name="name">Name of the function in source language form</param>
        /// <param name="linkageName">Mangled linker visible name of the function (may be same as <paramref name="name"/> if mangling not required by source language</param>
        /// <param name="file">File containing the function definition</param>
        /// <param name="line">Line number of the function definition</param>
        /// <param name="signature">LLVM Function type for the signature of the function</param>
        /// <param name="isLocalToUnit">Flag to indicate if this function is local to the compilation unit</param>
        /// <param name="isDefinition">Flag to indicate if this is a definition</param>
        /// <param name="scopeLine">First line of the function's outermost scope, this may not be the same as the first line of the function definition due to source formatting</param>
        /// <param name="debugFlags">Additional flags describing this function</param>
        /// <param name="isOptimized">Flag to indicate if this function is optimized</param>
        /// <param name="tParam">Parameter Metadata node</param>
        /// <param name="decl">Declaration Metadata node</param>
        /// <returns>Function described by the arguments</returns>
        public Function CreateFunction(DIScope scope
                                       , string name
                                       , string linkageName
                                       , DIFile file
                                       , uint line
                                       , DebugFunctionType signature
                                       , bool isLocalToUnit
                                       , bool isDefinition
                                       , uint scopeLine
                                       , DebugInfoFlags debugFlags
                                       , bool isOptimized
                                       , [CanBeNull] MDNode tParam = null
                                       , [CanBeNull] MDNode decl   = null
                                       )
        {
            ValidateHandle( );
            scope.ValidateNotNull(nameof(scope));
            name.ValidateNotNullOrWhiteSpace(nameof(name));
            signature.ValidateNotNull(nameof(signature));
            if (signature.DIType == null)
            {
                throw new ArgumentException("Signature requires debug type information", nameof(signature));
            }

            var func        = AddFunction(linkageName ?? name, signature);
            var diSignature = signature.DIType;
            var diFunc      = DIBuilder.CreateFunction(scope: scope
                                                       , name: name
                                                       , mangledName: linkageName
                                                       , file: file
                                                       , line: line
                                                       , signatureType: diSignature
                                                       , isLocalToUnit: isLocalToUnit
                                                       , isDefinition: isDefinition
                                                       , scopeLine: scopeLine
                                                       , debugFlags: debugFlags
                                                       , isOptimized: isOptimized
                                                       , function: func
                                                       , typeParameter: tParam
                                                       , declaration: decl
                                                       );

            Debug.Assert(diFunc.Describes(func), "Expected to get a debug function that describes the provided function");
            func.DISubProgram = diFunc;
            return(func);
        }
예제 #7
0
        internal MDOperand GetOperandFor(MDNode owningNode, LLVMMDOperandRef handle)
        {
            if (owningNode.Context != this)
            {
                throw new ArgumentException("Cannot get operand for a node from a different context", nameof(owningNode));
            }

            if (handle.Pointer == IntPtr.Zero)
            {
                throw new ArgumentNullException(nameof(handle));
            }

            if (MDOperandCache.TryGetValue(handle, out MDOperand retVal))
            {
                return(retVal);
            }

            retVal = new MDOperand(owningNode, handle);
            MDOperandCache.Add(handle, retVal);
            return(retVal);
        }
예제 #8
0
 internal MDNodeOperandList(MDNode owningNode, int offset)
 {
     Offset     = offset;
     OwningNode = owningNode;
 }
예제 #9
0
 internal MDNodeOperandList(MDNode owningNode)
     : this(owningNode, 0)
 {
 }
예제 #10
0
 internal void RemoveDeletedNode(MDNode node)
 {
     MetadataCache.Remove(node.MetadataHandle);
 }
예제 #11
0
 internal static MDOperand FromHandle(MDNode owningNode, LLVMMDOperandRef handle)
 {
     return(owningNode.Context.GetOperandFor(owningNode, handle));
 }
예제 #12
0
 internal MDNodeOperandList(MDNode owningNode)
 {
     OwningNode = owningNode;
 }