summaryrefslogtreecommitdiff
path: root/tests/utils/avx/options.pas
blob: c7f59f61fbad256758dad50c59e2132f697ab3cb (plain)
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
{

  Copyright (C) <avx-testfile-generator> <Torsten Grundke>

  This source is free software; you can redistribute it and/or modify it under
  the terms of the GNU General Public License as published by the Free
  Software Foundation; either version 2 of the License, or (at your option)
  any later version.

  This code is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  details.

  A copy of the GNU General Public License is available on the World Wide Web
  at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  MA 02110-1301, USA.
}

{$mode objfpc}

unit options;

interface

type

  { TOptions }

  TOptions = class(TObject)
  private
    FAVX512: boolean;
    FHelp: boolean;
    FX64: boolean;
    FOutputFormat: Char;
    FPath: string;
  public
    constructor Create;

    procedure LoadParams;

    property Help: boolean read FHelp write FHelp;
    property OutputFormat: Char read FOutputFormat write FOutputFormat;
    property X64: boolean read FX64 write FX64;
    property AVX512: boolean read FAVX512 write FAVX512;
    property Path: string read FPath write FPath;
  end;

implementation

uses SysUtils;

{ TOptions }

constructor TOptions.Create;
begin
  FHelp          := false;
  FX64           := false;
  FAVX512        := false;
  FOutputFormat  := '?';
  FPath          := '';
end;

procedure TOptions.LoadParams;
var
  i: integer;
  sParam: Char;
  sValue: String;
  IsInvalidParam: boolean;
begin
  if ParamCount = 0 then FHelp := true
   else FHelp := false;

  FX64 := false;
  FOutputFormat := 'f'; // default = fpc
  FPath := IncludeTrailingBackslash(GetCurrentDir);

  for i := 1 to ParamCount do
  begin
    if copy(ParamStr(i), 1, 1) = '-' then
    begin
      sParam := copy(ParamStr(i) + '  ', 2, 1)[1];
      sValue := copy(ParamStr(i), 3, length(ParamStr(i)));

      IsInvalidParam := false;
      case sParam of
         'h': FHelp := true;
         'f': if sValue = 'fpc' then FOutputFormat := 'f'
               else if sValue = 'nasm' then FOutputFormat := 'n'
               else if sValue = 'fasm' then FOutputFormat := 'F'
               else if sValue = 'fpcinc' then FOutputFormat := 'I'
               else IsInvalidParam := true;
         'p': if sValue = 'x8664' then
              begin
                Fx64 := true;
              end
              else IsInvalidParam := true;
         'z': FAVX512 := true;
         'o': if sValue <> '' then
              begin
                FPath :=  IncludeTrailingBackslash(sValue);
              end
              else
              begin
                FPath := '';
              end;
         else begin
                FHelp := true;
                writeln(format('invalid param "%s"', [ParamStr(i)]));
              end;
      end;
    end
    else IsInvalidParam := true;

    if IsInvalidParam then
    begin
      FHelp := true;
      writeln(format('invalid param "%s"', [ParamStr(i)]));
    end;
  end;
end;

end.