-
Notifications
You must be signed in to change notification settings - Fork 10
/
GlobalObjectExtensions.cs
88 lines (79 loc) · 3.89 KB
/
GlobalObjectExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// -----------------------------------------------------------------------
// <copyright file="GlobalObjectExtensions.cs" company="Ubiquity.NET Contributors">
// Copyright (c) Ubiquity.NET Contributors. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
using System;
namespace Ubiquity.NET.Llvm.Values
{
/// <summary>Fluent style extensions for properties of <see cref="GlobalObject"/></summary>
public static class GlobalObjectExtensions
{
/// <summary>Sets a named <see cref="Ubiquity.NET.Llvm.Comdat"/> for a <see cref="GlobalObject"/></summary>
/// <param name="self">Global to get the Comdat for</param>
/// <param name="name">name of the ComDat</param>
/// <returns><paramref name="self"/> for fluent use</returns>
/// <remarks>
/// This finds a <see cref="Ubiquity.NET.Llvm.Comdat"/> in the <see cref="GlobalValue.ParentModule"/>
/// of the object if it exists or creates a new one if it doesn't and assigns the <see cref="GlobalObject.Comdat"/>
/// property with the <see cref="Ubiquity.NET.Llvm.Comdat"/>.
/// </remarks>
public static GlobalObject Comdat( this GlobalObject self, string name ) => Comdat( self, name, ComdatKind.Any );
/// <summary>Sets a named <see cref="Ubiquity.NET.Llvm.Comdat"/> for a <see cref="GlobalObject"/></summary>
/// <param name="self">Global to get the Comdat for</param>
/// <param name="name">name of the Comdat</param>
/// <param name="kind">Kind of Comdat to create if it doesn't exist already</param>
/// <returns><paramref name="self"/> for fluent use</returns>
/// <remarks>
/// This finds a <see cref="Ubiquity.NET.Llvm.Comdat"/> in the <see cref="GlobalValue.ParentModule"/>
/// of the object if it exists or creates a new one if it doesn't and assigns the <see cref="GlobalObject.Comdat"/>
/// property with the <see cref="Ubiquity.NET.Llvm.Comdat"/>.
/// </remarks>
/// <seealso cref="GlobalObject.Comdat"/>
public static GlobalObject Comdat( this GlobalObject self, string name, ComdatKind kind )
{
if( self == null )
{
throw new ArgumentNullException( nameof( self ) );
}
if( !self.ParentModule.Comdats.TryGetValue( name, out Comdat comdat ) )
{
comdat = self.ParentModule.Comdats.InsertOrUpdate( name, kind );
}
else
{
comdat.Kind = kind;
}
self.Comdat = comdat;
return self;
}
/// <summary>Sets the linker section name for a <see cref="GlobalObject"/></summary>
/// <param name="self"><see cref="GlobalObject"/> to set the section for</param>
/// <param name="name">Name of the section</param>
/// <returns><paramref name="self"/> for fluent use</returns>
/// <seealso cref="GlobalObject.Section"/>
public static GlobalObject SectionName( this GlobalObject self, string name )
{
if( self == null )
{
throw new ArgumentNullException( nameof( self ) );
}
self.Section = name;
return self;
}
/// <summary>Sets the alignment for a <see cref="GlobalObject"/></summary>
/// <param name="self">Object to set the alignment of</param>
/// <param name="value">Alignment value to set</param>
/// <returns><paramref name="self"/> for fluent use</returns>
/// <seealso cref="GlobalObject.Alignment"/>
public static GlobalObject Alignment( this GlobalObject self, uint value )
{
if( self == null )
{
throw new ArgumentNullException( nameof( self ) );
}
self.Alignment = value;
return self;
}
}
}