forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeCompiler.cs
More file actions
160 lines (142 loc) · 5.26 KB
/
NativeCompiler.cs
File metadata and controls
160 lines (142 loc) · 5.26 KB
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using UnityEditor.Utils;
using UnityEngine;
internal abstract class NativeCompiler : INativeCompiler
{
[CompilerGenerated]
private static Func<string, string, string> <>f__am$cache0;
[CompilerGenerated]
private static Func<string, string, string> <>f__am$cache1;
[CompilerGenerated]
private static Func<string, string, string> <>f__am$cache2;
protected NativeCompiler()
{
}
protected static string Aggregate(IEnumerable<string> items, string prefix, string suffix)
{
<Aggregate>c__AnonStorey0 storey = new <Aggregate>c__AnonStorey0 {
prefix = prefix,
suffix = suffix
};
return Enumerable.Aggregate<string, string>(items, "", new Func<string, string, string>(storey.<>m__0));
}
protected internal static IEnumerable<string> AllSourceFilesIn(string directory) =>
Directory.GetFiles(directory, "*.cpp", SearchOption.AllDirectories).Concat<string>(Directory.GetFiles(directory, "*.c", SearchOption.AllDirectories));
public abstract void CompileDynamicLibrary(string outFile, IEnumerable<string> sources, IEnumerable<string> includePaths, IEnumerable<string> libraries, IEnumerable<string> libraryPaths);
protected void Execute(string arguments, string compilerPath)
{
ProcessStartInfo startInfo = new ProcessStartInfo(compilerPath, arguments);
this.SetupProcessStartInfo(startInfo);
this.RunProgram(startInfo);
}
protected void ExecuteCommand(string command, params string[] arguments)
{
if (<>f__am$cache0 == null)
{
<>f__am$cache0 = (buff, s) => buff + " " + s;
}
ProcessStartInfo startInfo = new ProcessStartInfo(command, Enumerable.Aggregate<string>(arguments, <>f__am$cache0));
this.SetupProcessStartInfo(startInfo);
this.RunProgram(startInfo);
}
protected internal static bool IsSourceFile(string source)
{
string extension = Path.GetExtension(source);
return ((extension == "cpp") || (extension == "c"));
}
protected string ObjectFileFor(string source) =>
Path.ChangeExtension(source, this.objectFileExtension);
internal static void ParallelFor<T>(T[] sources, Action<T> action)
{
<ParallelFor>c__AnonStorey1<T> storey = new <ParallelFor>c__AnonStorey1<T> {
sources = sources,
action = action
};
Thread[] threadArray = new Thread[Environment.ProcessorCount];
Counter parameter = new Counter();
for (int i = 0; i < threadArray.Length; i++)
{
threadArray[i] = new Thread(new ParameterizedThreadStart(storey.<>m__0));
}
foreach (Thread thread in threadArray)
{
thread.Start(parameter);
}
foreach (Thread thread2 in threadArray)
{
thread2.Join();
}
}
private void RunProgram(ProcessStartInfo startInfo)
{
using (Program program = new Program(startInfo))
{
program.Start();
while (!program.WaitForExit(100))
{
}
string str = string.Empty;
string[] standardOutput = program.GetStandardOutput();
if (standardOutput.Length > 0)
{
if (<>f__am$cache1 == null)
{
<>f__am$cache1 = (buf, s) => buf + Environment.NewLine + s;
}
str = Enumerable.Aggregate<string>(standardOutput, <>f__am$cache1);
}
string[] errorOutput = program.GetErrorOutput();
if (errorOutput.Length > 0)
{
if (<>f__am$cache2 == null)
{
<>f__am$cache2 = (buf, s) => buf + Environment.NewLine + s;
}
str = str + Enumerable.Aggregate<string>(errorOutput, <>f__am$cache2);
}
if (program.ExitCode != 0)
{
UnityEngine.Debug.LogError("Failed running " + startInfo.FileName + " " + startInfo.Arguments + "\n\n" + str);
throw new Exception("IL2CPP compile failed.");
}
}
}
protected virtual void SetupProcessStartInfo(ProcessStartInfo startInfo)
{
}
protected virtual string objectFileExtension =>
"o";
[CompilerGenerated]
private sealed class <Aggregate>c__AnonStorey0
{
internal string prefix;
internal string suffix;
internal string <>m__0(string current, string additionalFile) =>
(current + this.prefix + additionalFile + this.suffix);
}
[CompilerGenerated]
private sealed class <ParallelFor>c__AnonStorey1<T>
{
internal Action<T> action;
internal T[] sources;
internal void <>m__0(object obj)
{
int num;
NativeCompiler.Counter counter = (NativeCompiler.Counter) obj;
while ((num = Interlocked.Increment(ref counter.index)) <= this.sources.Length)
{
this.action(this.sources[num - 1]);
}
}
}
private class Counter
{
public int index;
}
}