/// <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)); }
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]; }
internal MDOperand(MDNode owningNode, LLVMMDOperandRef handle) { handle.ValidateNotDefault(nameof(handle)); OperandHandle = handle; OwningNode = owningNode; }
/// <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)); }
internal MDOperand(MDNode owningNode, LLVMMDOperandRef handle) { if (handle.Pointer == IntPtr.Zero) { throw new ArgumentNullException(nameof(handle)); } OperandHandle = handle; OwningNode = owningNode; }
/// <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); }
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); }
internal MDNodeOperandList(MDNode owningNode, int offset) { Offset = offset; OwningNode = owningNode; }
internal MDNodeOperandList(MDNode owningNode) : this(owningNode, 0) { }
internal void RemoveDeletedNode(MDNode node) { MetadataCache.Remove(node.MetadataHandle); }
internal static MDOperand FromHandle(MDNode owningNode, LLVMMDOperandRef handle) { return(owningNode.Context.GetOperandFor(owningNode, handle)); }
internal MDNodeOperandList(MDNode owningNode) { OwningNode = owningNode; }