-
Notifications
You must be signed in to change notification settings - Fork 0
/
_tab_main.ahk
288 lines (265 loc) · 9.85 KB
/
_tab_main.ahk
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#Requires AutoHotkey v2.0+
CL_GCC := 1
CL_CLANG := 2
CL_WSL := 4
CL_IDENT := ""
AS_GAS := 1
AS_WSL := 4
AS_IDENT := ""
PROGRAM_SOURCE_FILE := ""
AHK_SOURCE_FILE := ""
CL_USED := 0
CL_LOC := ""
CL_FLG := "-march=native"
CL_OPT := "-O2"
AS_USED := 0
AS_LOC := ""
AS_FLG := "-O2"
class tabMain extends GuiBase {
log := 0
ctrl_cl_idnt := 0
ctrl_as_idnt := 0
getName() {
return "Main"
}
preInit() {
GuiBase.register(this)
AppendConfig([ "PROGRAM_SOURCE_FILE", "AHK_SOURCE_FILE",
"CL_USED", "AS_USED",
"CL_LOC", "CL_FLG", "CL_OPT",
"AS_LOC", "AS_FLG", ])
}
start() {
this.guiAdd("Text", "section h0 w0")
this.startGroupBox("Configuration Used")
cfg_copythis := -1
(ctrl_cfg_dn := this.guiAdd("Button", "section xs", "<")).OnEvent("Click", cfg_dn)
ctrl_cfg_txt := this.guiAdd("Text", "ys hp center 0x200", "000000", )
(ctrl_cfg_up := this.guiAdd("Button", "ys +disabled", ">")).OnEvent("Click", cfg_up)
this.guiAdd("Button", "ys", "Add new").OnEvent("Click", cfg_add)
(ctrl_cfg_dl := this.guiAdd("Button", "ys +disabled", "Delete current")).OnEvent("Click", cfg_dl)
(ctrl_cfg_cp := this.guiAdd("Button", "ys", "Copy current")).OnEvent("Click", cfg_cp)
(ctrl_cfg_ps := this.guiAdd("Button", "ys +disabled", "Paste 999")).OnEvent("Click", cfg_ps)
update_cfg_ctls()
update_cfg_ctls() {
ctrl_cfg_txt.Value := _ACTIVE_CONFIGURATION
ctrl_cfg_dn.Opt(_ACTIVE_CONFIGURATION ? "-disabled" : "+disabled")
ctrl_cfg_up.Opt(IsConfigSlotUsed(_ACTIVE_CONFIGURATION+1) ? "-disabled" : "+disabled")
ctrl_cfg_dl.Opt((_ACTIVE_CONFIGURATION && IsConfigSlotUsed(_ACTIVE_CONFIGURATION)) ? "-disabled" : "+disabled")
ctrl_cfg_ps.Opt((cfg_copythis = -1 || _ACTIVE_CONFIGURATION = cfg_copythis) ? "+disabled" : "-disabled")
this.updateImageButtonText(ctrl_cfg_ps, (cfg_copythis = -1) ? "Paste" : ("Paste " . cfg_copythis))
ctrl_cfg_cp.Opt((!IsConfigSlotUsed(_ACTIVE_CONFIGURATION)) ? "+disabled" : "-disabled")
}
cfg_dn(*) {
SaveSettings()
SetGlobal("_ACTIVE_CONFIGURATION", _ACTIVE_CONFIGURATION-1)
cfg_chg()
}
cfg_up(*) {
SaveSettings()
SetGlobal("_ACTIVE_CONFIGURATION", _ACTIVE_CONFIGURATION+1)
cfg_chg()
}
cfg_dl(*) {
RemoveCfgSection(_ACTIVE_CONFIGURATION)
SetGlobal("_ACTIVE_CONFIGURATION", _ACTIVE_CONFIGURATION-1)
cfg_copythis := -1
cfg_chg()
}
cfg_add(*) {
SaveSettings()
SetGlobal("_ACTIVE_CONFIGURATION", GetLastConfigSlotUsed()+1)
cfg_chg()
}
cfg_chg() {
SaveSettings(true)
LoadSettings(true)
theGui.refreshUIFromGlobals()
update_cfg_ctls()
SetGlobal("CL_USED", 0)
SetGlobal("CL_IDENT", 0)
}
cfg_cp(*) {
cfg_copythis := _ACTIVE_CONFIGURATION
cfg_chg()
}
cfg_ps(*) {
CfgCopy(cfg_copythis, _ACTIVE_CONFIGURATION)
LoadSettings(true)
cfg_chg()
}
this.endGroupBox()
this.columnWidth00 -= 100
this.columnWIdth01 += 100
this.startGroupBox("Source code")
this.addFileSelection(
"",
"PROGRAM_SOURCE_FILE",
"This is the C program you're compiling. ",
this.refreshStatus,
)
this.endGroupBox()
this.startGroupBox("Existing AHK script for auto-insertion (optional)")
this.addFileSelection(
"",
"AHK_SOURCE_FILE",
"The AutoHotkey script specified here will receive an automatically-inserted mcode block.`r`n`r`n"
. "Note that this will only UPDATE an existing block that you've manually pasted in before, "
. "and metadata must be present as comments (see Options tab).`r`n`r`n"
. "Leave this blank to not use this feature.",
this.refreshStatus,
)
this.endGroupBox()
this.startGroupBox("Compiler")
this.addFileSelection(
"Location",
"CL_LOC",
"Please select the compiler executable you intend to use..",
this.cl_changed.Bind(this),
)
this.guiAdd("Text", "section xs w" . this.columnWidth00, "Detected as")
this.ctrl_cl_idnt := this.guiAdd("Text", "ys w" . this.columnWidth01, "Unknown")
this.addDropDown(
"Options",
["-O0", "-O1", "-O2", "-O3", "-Os", "-Ofast", "-Oz"],
"","CL_OPT",
"", 0, 0, [this.columnWidth00, 70]
)
this.addEditBox(
"",
"CL_FLG",
"Select the level of optimization (-O2 or O3 recommended), and specify "
. "any additional command line options to pass to the compiler.`r`n`r`n"
. "This field is optional, even though you should probably select a "
. "-march option. The default provided can be safely changed or removed.",
"", "", [0, this.columnWidth01 - 70 - GuiBase.mainGui.MarginX * 1]
)
this.endGroupBox()
this.startGroupBox("GNU Assembler")
this.addFileSelection(
"Location",
"AS_LOC",
"Please select the as executable you intend to use.`r`n`r`n"
. "This is typically found as as.exe in the same location as gcc.exe. "
. "If you intend to use clang as your compiler, you might still need "
. "to install gcc just to get ahold of as.",
this.as_changed.Bind(this),
)
this.guiAdd("Text", "section xs w" . this.columnWidth00, "Detected as")
this.ctrl_as_idnt := this.guiAdd("Text", "ys w" . this.columnWidth01, "Unknown")
this.addEditBox(
"Options",
"AS_FLG",
"Specify additional options to pass to as.",
)
this.endGroupBox()
this.columnWidth00 += 100
this.columnWIdth01 -= 100
this.finalizeFinalColumn()
clobj := {
changes: 0,
ctl: this.ctrl_cl_idnt,
glbToolLoc: "CL_LOC",
glbToolUse: "CL_USED",
glbToolIdnt: "CL_IDENT",
useIdents: [ {regex: "i)\bGCC\b", ident: "CL_GCC"},
{regex: "i)\bclang\b", ident: "CL_CLANG"}
],
wsl: "CL_WSL",
}
asobj := {
changes: 0,
ctl: this.ctrl_as_idnt,
glbToolLoc: "AS_LOC",
glbToolUse: "AS_USED",
glbToolIdnt: "AS_IDENT",
useIdents: [{regex: ".*GNU assembler.*", ident: "AS_GAS"}],
wsl: "AS_WSL"
}
this.detectToolChangeTracker := Map("cl", clobj, "as", asobj)
this.refreshUI()
this.refreshStatus()
}
cl_changed(*) {
SetTimer(this.timerFn, 1000)
this.detectToolChangeTracker["cl"].changes++
SetGlobal("CL_USED", 0)
SetGlobal("CL_IDENT", 0)
this.refreshStatus()
this.ctrl_cl_idnt.Value := "One second..."
}
as_changed(*) {
SetTimer(this.timerFn, 1000)
this.detectToolChangeTracker["as"].changes++
SetGlobal("AS_USED", 0)
SetGlobal("AS_IDENT", 0)
this.refreshStatus()
this.ctrl_as_idnt.Value := "One second..."
}
detectToolLastCfg := 0
detectToolChangeTracker := 0
timerFn := ObjBindMethod(this, "refreshToolVersion")
refreshToolVersion() {
for id, obj in this.detectToolChangeTracker {
highmark := obj.changes
if highmark || this.detectToolLastCfg != _ACTIVE_CONFIGURATION {
obj.ctl.Text := "Working..."
this.detectToolVersion(obj)
this.refreshStatus()
obj.changes -= highmark
}
}
this.detectToolLastCfg := _ACTIVE_CONFIGURATION
}
refreshUI() {
this.cl_changed()
this.as_changed()
}
refreshStatus() {
if (!PROGRAM_SOURCE_FILE || !FileExist(PROGRAM_SOURCE_FILE))
GuiBase.status("Need source file specified")
else if !CL_IDENT
GuiBase.status("Need compiler")
else if !AS_IDENT
GuiBase.status("Need assembler")
else
GuiBase.status("Ready.")
}
detectToolVersion(obj) {
cfg := _ACTIVE_CONFIGURATION
local_tool_loc := %obj.glbToolLoc%
ver := this.detectCommandVersion(local_tool_loc)
; if the user flipped to a different configuration while the above
; command was running, this function is being called again
; so we don't need to go further
if cfg = _ACTIVE_CONFIGURATION && local_tool_loc = %obj.glbToolLoc% {
if ver && ver[1] {
for i in obj.useIdents
SetGlobal(obj.glbToolUse, %obj.glbToolUse% | ((RegExMatch(ver[1], i.regex)) ? %i.ident% : 0))
SetGlobal(obj.glbToolUse, %obj.glbToolUse% | (ver[2] ? %obj.wsl% : 0))
ver := ver[1]
} else {
ver := ""
}
obj.ctl.Value := ((%obj.glbToolUse% & %obj.wsl%) ? "*WSL* " : "") . (ver ? ver : "Unknown")
SetGlobal(obj.glbToolIdnt, ver)
}
}
detectCommandVersion(cmd) {
if RegExMatch(cmd, "\b(gcc|as|clang)\b") {
v := GetCommandOutput('"' . cmd . '" --version')
if (v) {
v := StrSplit(v, "`n", "`r")[1]
return [v, false]
}
if _OPTS_WSL && !InStr(cmd, "\") {
v := GetCommandOutput('wsl.exe "' . cmd . '" --version')
if (v) {
v := StrSplit(v, "`n", "`r")[1]
return [v, true]
}
}
}
return false
}
}