-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.erplag
116 lines (95 loc) · 3.07 KB
/
.erplag
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
@echo off
setlocal EnableDelayedExpansion
IF "%1" == "" (
echo ERPLAG : FATAL ERROR --^> No source file
EXIT /B 1
)
IF "%1" == "-a" (
.compiler %2
if not errorlevel 1 (
set str=%2
set str=!str:~0,-4!
echo ERPLAG : Compilation of %2 successful^^! Assembly file !str!^.asm generated
EXIT /B 0
)
EXIT /B 1
) ELSE IF "%1" == "-o" (
IF "%2" == "" (
echo ERPLAG : FATAL ERROR --^> Please provide executable file name
EXIT /B 1
) ELSE (
set ext=%2
set ext=!ext:~-4!
IF NOT "!ext!"==".exe" (
echo ERPLAG : FATAL ERROR --^> Please provide output file with .exe extension
EXIT /B 1
)
)
IF "%3" == "" (
echo ERPLAG : FATAL ERROR --^> No source file
EXIT /B 1
)
.compiler %3 $temp.erp.asm
if not errorlevel 1 (
nasm -fwin64 $temp.erp.asm -o $temp.erp.obj
gcc -o %2 $temp.erp.obj
del $temp.erp.asm
del $temp.erp.obj
set str=%3
set str=!str:~0,-4!
echo ERPLAG : Compilation of %3 successful^^! Executable %2 generated
EXIT /B 0
)
EXIT /B 1
) ELSE IF "%1" == "-h" (
echo The compiler can be used with the following options -
echo 1^. erplag -a ^<filename^>^.erp generates a ^.asm file with the same filename
echo 2^. erplag ^<filename^>^.asm generates an executable with the same filename
echo 3^. erplag -o myexec ^<filename^>^.erp generates an executable file named myexec
echo 4^. erplag ^<filename^>^.erp directly generates an executable with the same filename
echo.
echo If you are making any changes to the source code or the erplag batch script, make sure to run "rebuild" in the command prompt
echo.
echo Use make debug to create the following executables useful for debugging -
echo 1^. ast - To debug the abstract syntax tree (described in astDriver^.c^)
echo 2^. ST - To debug the symbol table (described in symbolTableDriver^.c^)
echo 3^. compiler - To debug the final compiler (described in erplag^.c^)
echo.
echo The compiler can be uninstalled from this repository by executing "uninstall" in the command prompt. If an installation does not exist, then any debugging files will be removed
) ELSE (
set str=%1
set str=!str:~0,1!
IF "!str!"=="-" (
echo Invalid option. Use -a to generate x86 assembly or use -o along with output name to generate executable. For more information, use -h
EXIT /B 1
)
set ext=%1
set ext=!ext:~-4!
set file=%1
set file=!file:~0,-4!
IF "!ext!"==".asm" (
if exist %1 (
nasm -fwin64 %1 -o $temp.erp.obj
gcc -o !file!.exe $temp.erp.obj
del $temp.erp.obj
echo ERPLAG : Assembly of %1 successful^^! Executable !file!^.exe generated
EXIT /B 0
) else (
echo ERPLAG : FATAL ERROR --^> Assembly file %1 does not exist
EXIT /B 1
)
) ELSE IF "!ext!"==".erp" (
.compiler %1 $temp.erp.asm
if not errorlevel 1 (
nasm -fwin64 $temp.erp.asm -o $temp.erp.obj
gcc -o !file!.exe $temp.erp.obj
del $temp.erp.asm
del $temp.erp.obj
echo ERPLAG : Compilation of %1 successful^^! Executable !file!^.exe generated
EXIT /B 0
)
EXIT /B 1
) ELSE (
echo ERPLAG : FATAL ERROR --^> Unsupported file format. Use ^.erp for source files and ^.asm for x86 assembly files
)
)