-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathCounterDefCmakeGen.cs
204 lines (181 loc) · 7.95 KB
/
CounterDefCmakeGen.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// =====================================================================
// <copyright file="CounterDefCMakeGen.cs" company="Advanced Micro Devices, Inc.">
// Copyright (c) 2019-2023 Advanced Micro Devices, Inc. All rights reserved.
// </copyright>
// <author>
// AMD Developer Tools Team
// </author>
// <summary>
// CMake File generator for counter definitions.
// </summary>
// =====================================================================
using System;
using System.Collections.Generic;
using System.IO;
using ApiDictionary = System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>>;
using FileList = System.Collections.Generic.List<string>;
namespace GpaTools
{
class CounterDefCMakeGenerator
{
/// <summary>
/// Derived counter names dictionary
/// </summary>
public static ApiDictionary derivedCounters = new ApiDictionary();
/// <summary>
/// counter definitions dictionary
/// </summary>
public static ApiDictionary counterDefs = new ApiDictionary();
/// <summary>
/// Initializes the memory for the file lists
/// </summary>
public static void Init()
{
// PublicCounterDefs - GPA
counterDefs.Add(Gpa.DX12, new FileList());
counterDefs.Add(Gpa.DX11, new FileList());
counterDefs.Add(Gpa.VK, new FileList());
counterDefs.Add(Gpa.GL, new FileList());
counterDefs.Add(Gpa.CL, new FileList());
// PublicDerivedCounters - GPA
derivedCounters.Add(Gpa.DX12, new FileList());
derivedCounters.Add(Gpa.DX11, new FileList());
derivedCounters.Add(Gpa.VK, new FileList());
derivedCounters.Add(Gpa.GL, new FileList());
derivedCounters.Add(Gpa.CL, new FileList());
}
/// <summary>
/// Process the passed files depending on its name prefix
/// </summary>
/// <param name="fileName">name of the file</param>
public static void ProcessFiles(string fileName)
{
string file = Gpa.GetFileNameFromFilePath(fileName);
string prefix = Gpa.publicFilePrefix;
// PublicCounterDefs*
{
int indexOf = file.IndexOf(prefix + Gpa.counterDefinitionsStr, StringComparison.Ordinal);
if (indexOf != -1)
{
string api = Gpa.GetApiFromFileName(file);
if (null != api)
{
counterDefs[api].Add(fileName);
}
}
}
// DerivedCounterDefs*
{
int indexOf = file.IndexOf(prefix + Gpa.derivedCounterOutFileName, StringComparison.Ordinal);
if (indexOf != -1)
{
string api = Gpa.GetApiFromFileName(file);
if (null != api)
{
derivedCounters[api].Add(fileName);
}
}
}
}
/// <summary>
/// Writes the CMake file
/// </summary>
public static void CMakeWriter()
{
string TypePrefix = Gpa.publicStr;
foreach (var api in counterDefs)
{
bool Init = false;
TextWriter CMakeWriter = null;
string headerFiles = "set(" + TypePrefix.ToUpper() + "_COUNTER_DEF_HEADERS_" + api.Key.ToUpper();
string sourceFiles = "set(" + TypePrefix.ToUpper() + "_COUNTER_DEF_SRC_" + api.Key.ToUpper();
bool foundHeader = false;
foreach (var fileName in api.Value)
{
if (!Init)
{
Init = true;
string CMakeFileName = Gpa.GetDirectoryFromFilePath(fileName) + "\\" +
TypePrefix.ToLower() + "_" +
Gpa.counterDefinitionsStr + api.Key + ".cmake";
CMakeWriter = new StreamWriter(CMakeFileName);
CMakeWriter.WriteLine("## Copyright (c) {0} Advanced Micro Devices, Inc. All rights reserved.", DateTime.Today.Year);
CMakeWriter.WriteLine("cmake_minimum_required(VERSION 3.10)");
CMakeWriter.WriteLine();
CMakeWriter.WriteLine("set(CMAKE_INCLUDE_CURRENT_DIR ON)");
}
if (Gpa.IsHeaderFile(fileName))
{
headerFiles = headerFiles + Environment.NewLine + "${CMAKE_CURRENT_LIST_DIR}/" + Gpa.GetFileNameFromFilePath(fileName);
foundHeader = true;
}
else
{
sourceFiles = sourceFiles + Environment.NewLine + "${CMAKE_CURRENT_LIST_DIR}/" + Gpa.GetFileNameFromFilePath(fileName);
}
}
if (null != CMakeWriter)
{
if (foundHeader)
{
headerFiles = headerFiles + ")" + Environment.NewLine;
}
sourceFiles = sourceFiles + ")" + Environment.NewLine;
if (foundHeader)
{
CMakeWriter.WriteLine(headerFiles);
}
CMakeWriter.WriteLine(sourceFiles);
CMakeWriter.Close();
}
}
// DerivedCounterDefs
foreach (var api in derivedCounters)
{
bool Init = false;
TextWriter CMakeWriter = null;
string headerFiles = "set(" + TypePrefix.ToUpper() + "_DERIVED_COUNTERS_API_HEADERS_" + api.Key.ToUpper();
string sourceFiles = "set(" + TypePrefix.ToUpper() + "_DERIVED_COUNTERS_API_SRC_" + api.Key.ToUpper();
bool foundHeader = false;
foreach (var fileName in api.Value)
{
if (!Init)
{
Init = true;
string CMakeFileName = Gpa.GetDirectoryFromFilePath(fileName) + "\\" +
TypePrefix.ToLower() + "_" +
Gpa.derivedCounterOutFileName + api.Key + ".cmake";
CMakeWriter = new StreamWriter(CMakeFileName);
CMakeWriter.WriteLine("## Copyright (c) {0} Advanced Micro Devices, Inc. All rights reserved.", DateTime.Today.Year);
CMakeWriter.WriteLine("cmake_minimum_required(VERSION 3.10)");
CMakeWriter.WriteLine();
CMakeWriter.WriteLine("set(CMAKE_INCLUDE_CURRENT_DIR ON)");
}
if (Gpa.IsHeaderFile(fileName))
{
headerFiles = headerFiles + Environment.NewLine + "${CMAKE_CURRENT_LIST_DIR}/" + Gpa.GetFileNameFromFilePath(fileName);
foundHeader = true;
}
else
{
sourceFiles = sourceFiles + Environment.NewLine + "${CMAKE_CURRENT_LIST_DIR}/" + Gpa.GetFileNameFromFilePath(fileName);
}
}
if (null != CMakeWriter)
{
if (foundHeader)
{
headerFiles = headerFiles + ")" + Environment.NewLine;
}
sourceFiles = sourceFiles + ")" + Environment.NewLine;
if (foundHeader)
{
CMakeWriter.WriteLine(headerFiles);
}
CMakeWriter.WriteLine(sourceFiles);
CMakeWriter.Close();
}
}
}
}
}