Skip to content

Commit 100555c

Browse files
authored
AppModel (#45)
* model compiler * jit model * consistent this * cleanup * fix toggle
1 parent 6fae38a commit 100555c

File tree

5 files changed

+376
-146
lines changed

5 files changed

+376
-146
lines changed

JitExplorer/AppModel.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using JitExplorer.Engine;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.ComponentModel;
5+
using System.Runtime.CompilerServices;
6+
using System.Text;
7+
8+
namespace JitExplorer
9+
{
10+
public class AppModel : INotifyPropertyChanged
11+
{
12+
public event PropertyChangedEventHandler PropertyChanged;
13+
14+
public virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
15+
{
16+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
17+
}
18+
19+
public AppModel()
20+
{
21+
this.CompilerModel = new CompilerModel();
22+
this.JitModel = new JitModel();
23+
}
24+
25+
private CompilerModel compilerModel;
26+
private JitModel jitModel;
27+
28+
public CompilerModel CompilerModel
29+
{
30+
get { return this.compilerModel; }
31+
set
32+
{
33+
if (value == this.compilerModel)
34+
{
35+
return;
36+
}
37+
38+
this.compilerModel = value;
39+
this.OnPropertyChanged();
40+
}
41+
}
42+
43+
public JitModel JitModel
44+
{
45+
get { return this.jitModel; }
46+
set
47+
{
48+
if (value == this.jitModel)
49+
{
50+
return;
51+
}
52+
53+
this.jitModel = value;
54+
this.OnPropertyChanged();
55+
}
56+
}
57+
58+
public Config GetConfig()
59+
{
60+
var config = new Config()
61+
{
62+
CompilerOptions = this.CompilerModel.GetCompilerConfig(),
63+
JitMode = this.JitModel.GetJitMode(),
64+
};
65+
66+
return config;
67+
}
68+
}
69+
}

JitExplorer/CompilerModel.cs

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
using JitExplorer.Engine.Compile;
2+
using Microsoft.CodeAnalysis;
3+
using Microsoft.CodeAnalysis.CSharp;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.ComponentModel;
7+
using System.Runtime.CompilerServices;
8+
using System.Text;
9+
10+
namespace JitExplorer
11+
{
12+
public class CompilerModel : INotifyPropertyChanged
13+
{
14+
public event PropertyChangedEventHandler PropertyChanged;
15+
16+
public virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
17+
{
18+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
19+
}
20+
21+
private int languageSelection;
22+
private int buildConfig;
23+
private int plaform;
24+
private bool allowUnsafe;
25+
26+
public int LanguageSelection
27+
{
28+
get { return this.languageSelection; }
29+
set
30+
{
31+
if (value == this.languageSelection)
32+
{
33+
return;
34+
}
35+
36+
this.languageSelection = value;
37+
this.OnPropertyChanged();
38+
}
39+
}
40+
41+
public int BuildConfig
42+
{
43+
get { return this.buildConfig; }
44+
set
45+
{
46+
if (value == this.buildConfig)
47+
{
48+
return;
49+
}
50+
51+
this.buildConfig = value;
52+
this.OnPropertyChanged();
53+
}
54+
}
55+
56+
public int Platform
57+
{
58+
get { return this.plaform; }
59+
set
60+
{
61+
if (value == this.plaform)
62+
{
63+
return;
64+
}
65+
66+
this.plaform = value;
67+
this.OnPropertyChanged();
68+
}
69+
}
70+
71+
public bool AllowUnsafe
72+
{
73+
get { return this.allowUnsafe; }
74+
set
75+
{
76+
if (value == this.allowUnsafe)
77+
{
78+
return;
79+
}
80+
81+
this.allowUnsafe = value;
82+
this.OnPropertyChanged();
83+
}
84+
}
85+
86+
public CompilerOptions GetCompilerConfig()
87+
{
88+
var compilerOptions = new CompilerOptions()
89+
{
90+
OutputKind = OutputKind.ConsoleApplication,
91+
LanguageVersion = GetLanguageVersion(),
92+
Platform = GetPlatform(),
93+
OptimizationLevel = GetOptimizationLevel(),
94+
AllowUnsafe = this.allowUnsafe,
95+
};
96+
97+
return compilerOptions;
98+
}
99+
100+
private LanguageVersion GetLanguageVersion()
101+
{
102+
switch (this.languageSelection)
103+
{
104+
case 1:
105+
return Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp1;
106+
case 2:
107+
return Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp2;
108+
case 3:
109+
return Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp3;
110+
case 4:
111+
return Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp4;
112+
case 5:
113+
return Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp5;
114+
case 6:
115+
return Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp6;
116+
case 7:
117+
return Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp7;
118+
case 8:
119+
return Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp7_1;
120+
case 9:
121+
return Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp7_2;
122+
case 10:
123+
return Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp7_3;
124+
case 11:
125+
return Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp8;
126+
case 12:
127+
return Microsoft.CodeAnalysis.CSharp.LanguageVersion.Latest;
128+
default:
129+
return Microsoft.CodeAnalysis.CSharp.LanguageVersion.Default;
130+
}
131+
}
132+
133+
private Platform GetPlatform()
134+
{
135+
switch (this.plaform)
136+
{
137+
case 0:
138+
return Microsoft.CodeAnalysis.Platform.X64;
139+
case 1:
140+
return Microsoft.CodeAnalysis.Platform.X86;
141+
}
142+
143+
return Microsoft.CodeAnalysis.Platform.AnyCpu;
144+
}
145+
146+
private OptimizationLevel GetOptimizationLevel()
147+
{
148+
return this.buildConfig == 0 ? OptimizationLevel.Release : OptimizationLevel.Debug;
149+
}
150+
}
151+
}

JitExplorer/JitModel.cs

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using JitExplorer.Engine;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.ComponentModel;
5+
using System.Runtime.CompilerServices;
6+
using System.Text;
7+
8+
namespace JitExplorer
9+
{
10+
public class JitModel : INotifyPropertyChanged
11+
{
12+
public event PropertyChangedEventHandler PropertyChanged;
13+
14+
public virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
15+
{
16+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
17+
}
18+
19+
private bool legacyJit;
20+
private bool tieredCompilation;
21+
private bool quick;
22+
private bool quickLoop;
23+
24+
public bool LegacyJit
25+
{
26+
get { return this.legacyJit; }
27+
set
28+
{
29+
if (value == this.legacyJit)
30+
{
31+
return;
32+
}
33+
34+
this.legacyJit = value;
35+
this.LegacyChanged();
36+
this.OnPropertyChanged();
37+
}
38+
}
39+
40+
public bool TieredCompilation
41+
{
42+
get { return this.tieredCompilation; }
43+
set
44+
{
45+
if (value == this.tieredCompilation)
46+
{
47+
return;
48+
}
49+
50+
this.tieredCompilation = value;
51+
this.ModernChanged();
52+
this.OnPropertyChanged();
53+
}
54+
}
55+
56+
public bool Quick
57+
{
58+
get { return this.quick; }
59+
set
60+
{
61+
if (value == this.quick)
62+
{
63+
return;
64+
}
65+
66+
this.quick = value;
67+
this.ModernChanged();
68+
this.OnPropertyChanged();
69+
}
70+
}
71+
72+
public bool QuickLoop
73+
{
74+
get { return this.quickLoop; }
75+
set
76+
{
77+
if (value == this.quickLoop)
78+
{
79+
return;
80+
}
81+
82+
this.quickLoop = value;
83+
this.ModernChanged();
84+
this.OnPropertyChanged();
85+
}
86+
}
87+
88+
private void LegacyChanged()
89+
{
90+
if (this.legacyJit)
91+
{
92+
this.tieredCompilation = false;
93+
this.quick = false;
94+
this.quickLoop = false;
95+
96+
// fire the events afterwards, else we trigger ModernChanged while with this.quick == true or this.quickLoop == true
97+
// before they are reset
98+
this.OnPropertyChanged(nameof(TieredCompilation));
99+
this.OnPropertyChanged(nameof(Quick));
100+
this.OnPropertyChanged(nameof(QuickLoop));
101+
}
102+
}
103+
104+
private void ModernChanged()
105+
{
106+
if (this.tieredCompilation || this.quick || this.quickLoop)
107+
{
108+
this.LegacyJit = false;
109+
}
110+
}
111+
112+
public JitMode GetJitMode()
113+
{
114+
JitMode jitMode = JitMode.Default;
115+
116+
if (this.tieredCompilation)
117+
{
118+
jitMode = JitMode.Tiered;
119+
}
120+
121+
if (this.quick)
122+
{
123+
jitMode = jitMode | JitMode.Quick;
124+
}
125+
126+
if (this.quickLoop)
127+
{
128+
jitMode = jitMode | JitMode.QuickLoop;
129+
}
130+
131+
if (this.legacyJit)
132+
{
133+
jitMode = jitMode | JitMode.Legacy;
134+
}
135+
136+
return jitMode;
137+
}
138+
}
139+
}

0 commit comments

Comments
 (0)