Exemplo n.º 1
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];
        }
Exemplo n.º 2
0
        /// <summary>Adds operand value to named metadata</summary>
        /// <param name="name">Name of the metadata</param>
        /// <param name="value">operand value</param>
        public void AddNamedMetadataOperand(string name, LlvmMetadata value)
        {
            ValidateHandle( );
            value.ValidateNotNull(nameof(value));
            name.ValidateNotNullOrWhiteSpace(nameof(name));

            LLVMAddNamedMetadataOperand2(ModuleHandle, name, value?.MetadataHandle ?? default);
        }
Exemplo n.º 3
0
 public MDNode this[int index]
 {
     get
     {
         var nodeHanlde = NativeMethods.NamedMDNodeGetOperand(OwningNode.NativeHandle, (uint)index);
         return(LlvmMetadata.FromHandle <MDNode>(OwningNode.ParentModule.Context, nodeHanlde));
     }
 }
Exemplo n.º 4
0
        /// <summary>Adds a module flag to the module</summary>
        /// <param name="behavior">Module flag behavior for this flag</param>
        /// <param name="name">Name of the flag</param>
        /// <param name="value">Value of the flag</param>
        public void AddModuleFlag(ModuleFlagBehavior behavior, string name, LlvmMetadata value)
        {
            ValidateHandle( );
            behavior.ValidateDefined(nameof(behavior));
            value.ValidateNotNull(nameof(value));
            name.ValidateNotNullOrWhiteSpace(nameof(name));

            // AddModuleFlag comes from custom LLVMDebug-C API
            LLVMAddModuleFlag(ModuleHandle, ( LLVMModFlagBehavior )behavior, name, value.MetadataHandle);
        }
Exemplo n.º 5
0
        /// <summary>Replace all uses of this descriptor with another</summary>
        /// <param name="other">New descriptor to replace this one with</param>
        public virtual void ReplaceAllUsesWith(LlvmMetadata other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            if (MetadataHandle == default)
            {
                throw new InvalidOperationException(Resources.Cannot_Replace_all_uses_of_a_null_descriptor);
            }

            LLVMMetadataReplaceAllUsesWith(MetadataHandle, other.MetadataHandle);
            MetadataHandle = default;
        }
Exemplo n.º 6
0
            public MDNode this[int index]
            {
                get
                {
                    var nodeHanlde = LLVMNamedMDNodeGetOperand(OwningNode.NativeHandle, (uint)index);
                    return(LlvmMetadata.FromHandle <MDNode>(OwningNode.ParentModule.Context, nodeHanlde));
                }

                /* TODO:
                 * set
                 * {   index.VerifyRange(0, Count, nameof(index));
                 *  LLVMNamedMDNodeSetOperand( index, value.NativeHandle );
                 * }
                 */
            }
Exemplo n.º 7
0
            public MDNode this[int index]
            {
                get
                {
                    index.ValidateRange(0, Count, nameof(index));
                    var nodeHanlde = LibLLVMNamedMDNodeGetOperand(OwningNode.NativeHandle, ( uint )index);
                    return(LlvmMetadata.FromHandle <MDNode>(OwningNode.ParentModule.Context, nodeHanlde));
                }

                set
                {
                    index.ValidateRange(0, Count, nameof(index));
                    LibLLVMNamedMDNodeSetOperand(OwningNode.NativeHandle, ( uint )index, value.MetadataHandle);
                }
            }
Exemplo n.º 8
0
        /*TODO:
         * MetadataKind Kind { get; }
         *
         */

        /// <summary>Replace all uses of this descriptor with another</summary>
        /// <param name="other">New descriptor to replace this one with</param>
        public virtual void ReplaceAllUsesWith(LlvmMetadata other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            if (MetadataHandle == default)
            {
                throw new InvalidOperationException("Cannot Replace all uses of a null descriptor");
            }

            NativeMethods.LLVMMetadataReplaceAllUsesWith(MetadataHandle, other.MetadataHandle);
            MetadataHandle = default;
        }
Exemplo n.º 9
0
        /// <summary>Replace all uses of this node with a new node</summary>
        /// <param name="other">Node to replace this one with</param>
        public override void ReplaceAllUsesWith(LlvmMetadata other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            if (!IsTemporary || IsResolved)
            {
                throw new InvalidOperationException("Cannot replace non temporary or resolved MDNode");
            }

            if (MetadataHandle == default)
            {
                throw new InvalidOperationException("Cannot Replace all uses of a null descriptor");
            }

            NativeMethods.LLVMMDNodeReplaceAllUsesWith(MetadataHandle, other.MetadataHandle);

            // remove current node mapping from the context.
            // It won't be valid for use after clearing the handle
            Context.RemoveDeletedNode(this);
            MetadataHandle = default;
        }
Exemplo n.º 10
0
 /// <summary>Initializes a new instance of the <see cref="ModuleFlag"/> class.</summary>
 /// <param name="behavior">Behavior for the flag</param>
 /// <param name="name">Name of the flag</param>
 /// <param name="metadata">Metadata for the flag</param>
 public ModuleFlag(ModuleFlagBehavior behavior, string name, LlvmMetadata metadata)
 {
     Behavior = behavior;
     Name     = name;
     Metadata = metadata;
 }