-
Notifications
You must be signed in to change notification settings - Fork 1
/
translator.cmd
378 lines (295 loc) · 11.9 KB
/
translator.cmd
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
REM Òðàíñëÿòîð áåéñèê-ôàéëîâ
REM Èñõîäíûå êîäû: *.bas
REM Âêëþ÷àåìûå ôàéëû: *.bi
REM Ôàéëû ðåñóðñîâ: *.rc
REM Ïàðàìåòðû:
REM 1. Âñå êîìïèëèðóåìûå *.bas è *.rc ôàéëû (â êàâû÷êàõ)
REM 2. Òèï èñïîëíÿåìîãî ôàéëà [console | gui | lib | dll | native | driver]
REM 3. Èìÿ ñêîìïèëèðîâàííîãî ôàéëà [â êàâû÷êàõ] = èìÿ ïåðâîãî ôàéëà + .exe
REM 4. Äèðåêòîðèÿ êîìïèëÿòîðà [â êàâû÷êàõ] %ProgramFiles%\FreeBASIC
REM 5. Äîïîëíèòåëüíûå ïàðàìåòðû êîìïèëÿöèè [â êàâû÷êàõ]
REM 6. Ôëàã îòëàäêè [release | debug]
REM 7. Ôëàã ïðîôèëèðîâùèêà [noprofile | profile]
REM 8. Ôëàã óäàëåíèÿ RTL [runtime | withoutruntime]
REM Òèïû èñïîëíÿåìûõ ôàéëîâ
REM lib Ñòàòè÷åñêè ïîäêëþ÷àåìàÿ áèáëèîòåêà -
REM dll Äèíàìè÷åñêè ïîäêëþ÷àåìàÿ áèáëèîòåêà console
REM console Êîíñîëüíîå ïðèëîæåíèå console
REM gui Ãðàôè÷åñêîå ïðèëîæåíèå gui
REM native Íàòèâíîå ïðèëîæåíèå native
REM driver Äðàéâåð native
set CompilerLogErrorFileName=_out.txt
set AllCompiledFiles=%~1
set ExeTypeKind=%~2
set OutputFileName=%~3
set Directory=%~4
set CompilerParameters=%~5
set DebugFlag=%~6
set ProfileFlag=%~7
set WithoutRuntimeLibraryesFlag=%~8
:CreateCompilerPath
if "%Directory%"=="" (
set FreeBasicCompilerFilePath="%ProgramFiles%\FreeBASIC\fbc.exe"
if "%PROCESSOR_ARCHITECTURE%"=="x86" (
set GccFilePath="%ProgramFiles%\FreeBASIC\bin\win32\gcc.exe"
set AssemblerFilePath="%ProgramFiles%\FreeBASIC\bin\win32\as.exe"
set LinkerFilePath="%ProgramFiles%\FreeBASIC\bin\win32\ld.exe"
set DllToolFilePath="%ProgramFiles%\FreeBASIC\bin\win32\dlltool.exe"
set ArchiveCompilerFilePath="%ProgramFiles%\FreeBASIC\bin\win32\ar.exe"
set ResourceCompilerFilePath="%ProgramFiles%\FreeBASIC\bin\win32\GoRC.exe"
set CompilerLibDirectoryPath="%ProgramFiles%\FreeBASIC\lib\win32"
set CodeGenerationBackend=gas
) else (
REM set GccFilePath="%ProgramFiles%\FreeBASIC\bin\win64\gcc.exe"
REM set AssemblerFilePath="%ProgramFiles%\FreeBASIC\bin\win64\as.exe"
REM set LinkerFilePath="%ProgramFiles%\FreeBASIC\bin\win64\ld.exe"
REM set DllToolFilePath="%ProgramFiles%\FreeBASIC\bin\win64\dlltool.exe"
REM set ArchiveCompilerFilePath="%ProgramFiles%\FreeBASIC\bin\win64\ar.exe"
REM set ResourceCompilerFilePath="%ProgramFiles%\FreeBASIC\bin\win64\GoRC.exe"
set CompilerLibDirectoryPath="%ProgramFiles%\FreeBASIC\lib\win64"
set CodeGenerationBackend=gcc
)
) else (
set FreeBasicCompilerFilePath="%Directory%\fbc.exe"
if "%PROCESSOR_ARCHITECTURE%"=="x86" (
set GccFilePath="%Directory%\bin\win32\gcc.exe"
set AssemblerFilePath="%Directory%\bin\win32\as.exe"
set LinkerFilePath="%Directory%\bin\win32\ld.exe"
set DllToolFilePath="%Directory%\bin\win32\dlltool.exe"
set ArchiveCompilerFilePath="%Directory%\bin\win32\ar.exe"
set ResourceCompilerFilePath="%Directory%\bin\win32\GoRC.exe"
set CompilerLibDirectoryPath="%Directory%\lib\win32"
set CodeGenerationBackend=gas
) else (
set ClangFilePath="%ProgramFiles%\LLVM\bin\clang.exe"
set LlvmLinkerFilePath="%ProgramFiles%\LLVM\bin\lld-link.exe"
REM gcc version 5.2.0
set GccFilePath="%Directory%\bin\win64\gcc.exe"
set AssemblerFilePath="%Directory%\bin\win64\as.exe"
set LinkerFilePath="%Directory%\bin\win64\ld.exe"
set DllToolFilePath="%Directory%\bin\win64\dlltool.exe"
set ArchiveCompilerFilePath="%Directory%\bin\win64\ar.exe"
REM gcc version 8.1.0
REM set GccFilePath="%ProgramFiles%\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\gcc.exe"
REM set AssemblerFilePath="%ProgramFiles%\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\as.exe"
REM set LinkerFilePath="%ProgramFiles%\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\ld.exe"
REM set DllToolFilePath="%ProgramFiles%\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\dlltool.exe"
REM set ArchiveCompilerFilePath="%ProgramFiles%\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\ar.exe"
set ResourceCompilerFilePath="%Directory%\bin\win64\GoRC.exe"
set CompilerLibDirectoryPath="%Directory%\lib\win64"
set CodeGenerationBackend=gcc
)
)
:CreateCompilerExeTypeKind
if "%ExeTypeKind%"=="dll" (
if "%WithoutRuntimeLibraryesFlag%"=="withoutruntime" (
set CompilerExeTypeKind=-lib
) else (
set CompilerExeTypeKind=-dll
)
) else (
if "%WithoutRuntimeLibraryesFlag%"=="withoutruntime" (
set CompilerExeTypeKind=-lib
) else (
if "%ExeTypeKind%"=="lib" (
set CompilerExeTypeKind=-lib
)
)
)
:CreateWin32Subsystem
if "%ExeTypeKind%"=="lib" (
set Win32Subsystem=console
) else (
if "%ExeTypeKind%"=="dll" (
set Win32Subsystem=console
) else (
if "%ExeTypeKind%"=="console" (
set Win32Subsystem=console
) else (
if "%ExeTypeKind%"=="gui" (
if "%WithoutRuntimeLibraryesFlag%"=="withoutruntime" (
set Win32Subsystem=windows
) else (
set Win32Subsystem=gui
)
) else (
if "%ExeTypeKind%"=="native" (
set Win32Subsystem=native
) else (
if "%ExeTypeKind%"=="driver" (
set Win32Subsystem=native
) else (
set Win32Subsystem=console
)
)
)
)
)
)
:CreateCompilerOutputFileName
if "%OutputFileName%"=="" (
for /F "tokens=1" %%I in ("%AllCompiledFiles%") do (
call :SetCompilerOutputFileName %%I
)
) else (
set CompilerOutputFileName=%OutputFileName%
)
:CreateCompilerDebugFlag
if "%DebugFlag%"=="debug" (
set CompilerDebugFlag=-g
) else (
set CompilerDebugFlag=
)
:CreateCompilerProfileFlag
if "%ProfileFlag%"=="profile" (
set CompilerProfileFlag=-profile
) else (
set CompilerProfileFlag=
)
:CreateWithoutRuntimeLibraryesFlag
if "%WithoutRuntimeLibraryesFlag%"=="withoutruntime" (
set WITHOUT_RUNTIME_DEFINED=-d WITHOUT_RUNTIME
set WriteOutOnlyAsmFlag=-r
)
:RuntimeCompilation
%FreeBasicCompilerFilePath% %WITHOUT_RUNTIME_DEFINED% -x %CompilerOutputFileName% %WriteOutOnlyAsmFlag% -s %Win32Subsystem% %CompilerExeTypeKind% -gen %CodeGenerationBackend% %CompilerDebugFlag% %CompilerProfileFlag% %CompilerParameters% %AllCompiledFiles% >%CompilerLogErrorFileName%
if %errorlevel% GEQ 1 (
exit /b %errorlevel%
)
if not "%WithoutRuntimeLibraryesFlag%"=="withoutruntime" (
exit /b 0
)
:WithoutRuntimeCompilation
set AllFileWithExtensionC=
set AllFileWithExtensionAsm=
set AllObjectFiles=
for %%I IN (%AllCompiledFiles%) do (
if "%%~xI"==".bas" (
call :GccCompier %%I
)
)
for %%I IN (%AllCompiledFiles%) do (
if "%%~xI"==".RC" (
call :ResourceCompiler %%I
)
)
call :GccLinker
call :CleanUp
exit /b 0
:CleanUp
if %CodeGenerationBackend%==gcc (
REM del %AllFileWithExtensionC% %AllFileWithExtensionAsm% %AllObjectFiles%
) else (
REM del %AllFileWithExtensionAsm% %AllObjectFiles%
)
exit /b 0
:GccLinker
REM Îáû÷íûé è îòëàä÷èê
REM "C:\Program Files\FreeBASIC\lib\win64\fbextra.x"
REM "C:\Program Files\FreeBASIC\lib\win64\crt2.o"
REM "C:\Program Files\FreeBASIC\lib\win64\crtbegin.o"
REM "C:\Program Files\FreeBASIC\lib\win64\fbrt0.o"
REM (áèáëèîòåêè)
REM "C:\Program Files\FreeBASIC\lib\win64\crtend.o"
REM Ïðîôèëèðîâùèê
REM "C:\Program Files\FreeBASIC\lib\win64\fbextra.x"
REM "C:\Program Files\FreeBASIC\lib\win64\crt2.o"
REM "C:\Program Files\FreeBASIC\lib\win64\gcrt2.o"
REM "C:\Program Files\FreeBASIC\lib\win64\crtbegin.o"
REM "C:\Program Files\FreeBASIC\lib\win64\fbrt0.o"
REM (áèáëèîòåêè)
REM "C:\Program Files\FreeBASIC\lib\win64\crtend.o"
set UuidObjectLibraries=-luuid
set GMonitorObjectLibraries=-lgmon
set GccObjectLibraries=-lmoldname -lgcc
set WinApiObjectLibraries=-ladvapi32 -lcards -lcomctl32 -lcomdlg32 -lcrypt32 -lgdi32 -lgdiplus -limm32 -lkernel32 -lmsimg32 -lmsvcrt -lmswsock -lole32 -loleaut32 -lshell32 -lshlwapi -luser32 -lversion -lwinmm -lwinspool -lws2_32
set AllObjectLibraries=%WinApiObjectLibraries% %GMonitorObjectLibraries% %GccObjectLibraries%
set UseThreadSafeRuntime=
set MajorImageVersion=--major-image-version 1
set MinorImageVersion=--minor-image-version 0
set OutputDefinitionFileName=%OutputFileName:~0,-3%def
if "%PROCESSOR_ARCHITECTURE%"=="x86" (
if "%ExeTypeKind%"=="dll" (
set EntryPoint=_DllMain@12 --dll --enable-stdcall-fixup --output-def %OutputDefinitionFileName%
) else (
set EntryPoint=_EntryPoint@0
)
set PEFileFormat=i386pe
) else (
if "%ExeTypeKind%"=="dll" (
set EntryPoint=DllMain --dll --enable-stdcall-fixup --output-def %OutputDefinitionFileName%
) else (
set EntryPoint=EntryPoint
)
set PEFileFormat=i386pep
)
if "%DebugFlag%"=="debug" (
set LinkerStripFlag=
) else (
set LinkerStripFlag=-s
)
%LinkerFilePath% -m %PEFileFormat% -o %CompilerOutputFileName% -subsystem %Win32Subsystem% -e %EntryPoint% --stack 1048576,1048576 %LinkerStripFlag% -L %CompilerLibDirectoryPath% -L "." %AllObjectFiles% -( %AllObjectLibraries% -)
if "%ExeTypeKind%"=="dll" (
%DllToolFilePath% --def %OutputDefinitionFileName% --dllname %CompilerOutputFileName% --output-lib lib%CompilerOutputFileName%.a
)
exit /b 0
:GccCompier
set GCCWarning=-Werror -Wall -Wno-unused-label -Wno-unused-function -Wno-main
set GCCNoInclude=-nostdlib -nostdinc
if "%DebugFlag%"=="debug" (
set OptimizationLevel=-Og
) else (
set OptimizationLevel=-O3 -mno-stack-arg-probe -fno-stack-check -fno-stack-protector -fno-strict-aliasing -frounding-math -fno-math-errno -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-ident
)
set GCCOptimizations=%OptimizationLevel%
set FileWithExtensionBas=%1
set FileWithoutExtension=%FileWithExtensionBas:~0,-3%
set FileWithExtensionC=%FileWithoutExtension%c
set FileWithExtensionAsm=%FileWithoutExtension%asm
set FileWithExtensionObj=%FileWithoutExtension%o
if "%PROCESSOR_ARCHITECTURE%"=="x86" (
set TargetAssemblerArch=--32
set GCCArchitecture=
) else (
set TargetAssemblerArch=--64
set GCCArchitecture=-m64 -march=x86-64
)
if "%CodeGenerationBackend%"=="gcc" (
REM replace.vbs %FileWithExtensionC%
%GccFilePath% %GCCWarning% %GCCNoInclude% %GCCOptimizations% %GCCArchitecture% %CompilerDebugFlag% -masm=intel -S %FileWithExtensionC% -o %FileWithExtensionAsm%
)
set AllFileWithExtensionC=%AllFileWithExtensionC% %FileWithExtensionC%
set AllFileWithExtensionAsm=%AllFileWithExtensionAsm% %FileWithExtensionAsm%
if "%DebugFlag%"=="debug" (
set AssemblerStripFlag=
) else (
set AssemblerStripFlag=--strip-local-absolute
)
%AssemblerFilePath% %TargetAssemblerArch% %AssemblerStripFlag% %FileWithExtensionAsm% -o %FileWithExtensionObj%
set AllObjectFiles=%AllObjectFiles% %FileWithExtensionObj%
exit /b 0
:ResourceCompiler
set ResourceFileWithExtension=%1
set ResourceFileWithoutExtension=%ResourceFileWithExtension:~0,-2%
set ResourceFileWithExtensionObj=%ResourceFileWithoutExtension%obj
if "%PROCESSOR_ARCHITECTURE%"=="x86" (
set ResourceCompilerBitFlag=/nw
) else (
set ResourceCompilerBitFlag=/machine X64
)
%ResourceCompilerFilePath% /ni %ResourceCompilerBitFlag% /o /fo %ResourceFileWithExtensionObj% %ResourceFileWithExtension%
set AllObjectFiles=%AllObjectFiles% %ResourceFileWithExtensionObj%
exit /b 0
:SetCompilerOutputFileName
set CompilerOutputFileNameWithExtensionBas=%1
set CompilerOutputFileNameWithouExtension=%CompilerOutputFileNameWithExtensionBas:~0,-3%
if "%ExeTypeKind%"=="lib" (
set CompilerOutputFileName=lib%CompilerOutputFileNameWithouExtension%.a
) else (
if "%ExeTypeKind%"=="dll" (
set CompilerOutputFileName=%CompilerOutputFileNameWithouExtension%.dll
) else (
set CompilerOutputFileName=%CompilerOutputFileNameWithouExtension%.exe
)
)
exit /b 0