-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathevil.pas
65 lines (61 loc) · 1.19 KB
/
evil.pas
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
program evil;
{$mode objfpc}
{$H+}
uses
SysUtils, Classes, ScriptEngine;
var
SE: TScriptEngine;
SL: TStrings;
IsD: Boolean = False;
IsO: Boolean = True;
IsA: Boolean = False;
I: Integer;
AsmStr: String;
begin
if ParamCount < 1 then
begin
Writeln('Usage: evil <options> [script file]');
Writeln('Options: ');
Writeln(' -d : Disassembly');
Writeln(' -do : Disable optimizations');
Writeln(' -da : Disable assertions');
Halt;
end;
if ParamCount > 1 then
begin
for I := 1 to ParamCount - 1 do
case ParamStr(I) of
'-d':
IsD := True;
'-do':
IsO := False;
'-da':
IsA := True;
end;
end;
SE := TScriptEngine.Create;
SE.OptimizePeephole := IsO;
SE.OptimizeConstantFolding := IsO;
SE.OptimizeAsserts := IsA;
SL := TStringList.Create;
try
try
SL.LoadFromFile(ParamStr(ParamCount));
SE.Source := SL.Text;
if IsD then
begin
SE.Lex;
SE.Parse;
SEDisAsm(SE.VM, AsmStr);
Writeln(AsmStr);
end else
SE.Exec;
except
on E: Exception do
Writeln(E.Message);
end;
finally
SE.Free;
SL.Free;
end;
end.