Ejemplo 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] !;
        }
Ejemplo n.º 2
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.ThrowIfInvalid( )) !);
                }

                set
                {
                    index.ValidateRange(0, Count, nameof(index));
                    LibLLVMNamedMDNodeSetOperand(OwningNode.NativeHandle, ( uint )index, value.MetadataHandle);
                }
            }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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)
        {
            other.ValidateNotNull(nameof(other));

            if (!IsTemporary || IsResolved)
            {
                throw new InvalidOperationException(Resources.Cannot_replace_non_temporary_or_resolved_MDNode);
            }

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

            // grab the context before replacement as replace deletes and invalidates the node
            var context = Context;

            LLVMMetadataReplaceAllUsesWith(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;
        }
Ejemplo n.º 5
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;
 }