File: target.pas

package info (click to toggle)
fpc 3.0.4%2Bdfsg-22
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 291,080 kB
  • sloc: pascal: 3,216,108; xml: 161,992; ansic: 9,637; asm: 8,297; java: 5,346; sh: 4,137; yacc: 3,747; php: 3,283; makefile: 2,711; lex: 2,538; sql: 267; cpp: 145; perl: 134; sed: 132; csh: 34; tcl: 7
file content (238 lines) | stat: -rw-r--r-- 7,499 bytes parent folder | download
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
{

    FPCRes - Free Pascal Resource Converter
    Part of the Free Pascal distribution
    Copyright (C) 2008 by Giulio Bernardi

    Target selection and definitions

    See the file COPYING, included in this distribution,
    for details about the copyright.

    This program 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.
}

unit target;

{$MODE OBJFPC}

interface

type
  TMachineType = (mtnone, mti386,mtx86_64,mtppc,mtppc64,mtarm,mtarmeb,mtm68k,
                  mtsparc,mtalpha,mtia64,mtmips,mtmipsel,mtaarch64,
                  mtBigEndian,mtLittleEndian);
  TMachineTypes = set of TMachineType;

  TSubMachineTypeArm = (smtarm_all,smtarm_v4t,smtarm_v6,smtarm_v5tej,smtarm_xscale,smtarm_v7);
  TSubMachineTypeGeneric = (smtgen_all);

  TSubMachineType = record
    case TMachineType of
      mtarm,mtarmeb:
        (subarm: TSubMachineTypeArm);
      mtnone, mti386,mtx86_64,mtppc,mtppc64,mtm68k,
      mtsparc,mtalpha,mtia64,mtmips,mtmipsel,mtaarch64,
      mtBigEndian,mtLittleEndian:
        (subgen: TSubMachineTypeGeneric);
  end;

  TObjFormat = (ofNone, ofRes, ofElf, ofCoff, ofXCoff, ofMachO, ofExt);
  TObjFormats = set of TObjFormat;
  

  TMachineInfo = record
    name : string;
    formats : TObjFormats;
    alias : string;
  end;
  
  TFormatInfo = record
    name : string;
    ext : string;
    machines : TMachineTypes;
  end;

  TResTarget = record
    machine : TMachineType;
    submachine : TSubMachineType;
    objformat : TObjFormat;
  end;

function GetDefaultMachineForFormat(aFormat : TObjFormat) : TMachineType;
function GetDefaultSubMachineForMachine(aMachine: TMachineType) : TSubMachineType;
function TargetToStr(const aTarget : TResTarget) : string;
function MachineToStr(const aMachine : TMachineType) : string;
function ObjFormatToStr(const aFormat : TObjFormat) : string;

var
  Machines : array[TMachineType] of TMachineInfo =
  (
    (name : '';             formats : [ofRes]),                   //mtnone
    (name : 'i386';         formats : [ofElf, ofCoff, ofMachO]),  //mti386
    (name : 'x86_64';       formats : [ofElf, ofCoff, ofMachO]),  //mtx86_64
    (name : 'powerpc';      formats : [ofElf, ofXCoff, ofMachO]), //mtppc
    (name : 'powerpc64';    formats : [ofElf, {ofXCoff,} ofMachO]), //mtppc64
    (name : 'arm';          formats : [ofElf, ofCoff, ofMachO]),  //mtarm
    (name : 'armeb';        formats : [ofElf]),                   //mtarmeb
    (name : 'm68k';         formats : [ofElf]),                   //mtm68k
    (name : 'sparc';        formats : [ofElf]),                   //mtsparc
    (name : 'alpha';        formats : [ofElf]),                   //mtalpha
    (name : 'ia64';         formats : [ofElf]),                   //mtia64
    (name : 'mips';         formats : [ofElf]; alias : 'mipseb'), //mtmips
    (name : 'mipsel';       formats : [ofElf]),                   //mtmipsel
    (name : 'aarch64';      formats : [ofElf, ofMachO]),          //mtaarch64
    (name : 'bigendian';    formats : [ofExt]),                   //mtBigEndian
    (name : 'littleendian'; formats : [ofExt])                    //mtLittleEndian
  );

  SubMachinesArm: array[TSubMachineTypeArm] of string[8] =
    ('all','armv4','armv6','armv5tej','xscale','armv7');
  SubMachinesGen: array[TSubMachineTypeGeneric] of string[3] =
    ('all');
  
  ObjFormats : array[TObjFormat] of TFormatInfo =
  (
    (name : '';         ext : '';        machines : []),
    (name : 'res';      ext : '.res';    machines : [mtnone]),
    (name : 'elf';      ext : '.or';     machines : [mti386,mtx86_64,mtppc,
                                                     mtppc64,mtarm,mtarmeb,
                                                     mtm68k,mtsparc,mtalpha,
                                                     mtaarch64,mtmips,mtmipsel]),
    (name : 'coff';     ext : '.o';      machines : [mti386,mtx86_64,mtarm,
                                                     mtppc,mtppc64]),
    (name : 'xcoff';    ext : '.o';      machines : [mtppc{,mtppc64}]),
    (name : 'mach-o';   ext : '.or';     machines : [mti386,mtx86_64,mtppc,
                                                     mtppc64,mtarm,mtaarch64]),
    (name : 'external'; ext : '.fpcres'; machines : [mtBigEndian,mtLittleEndian])
  );


  CurrentTarget : TResTarget =
  (
  {$if defined(CPUI386)}
    machine : mti386;
    submachine : (subgen: smtgen_all);
  {$elseif defined(CPUX86_64)}
    machine : mtx86_64;
    submachine : (subgen: smtgen_all);
  {$elseif defined(CPUPOWERPC32)}
    machine : mtppc;
    submachine : (subgen: smtgen_all);
  {$elseif defined(CPUPOWERPC64)}
    machine : mtppc64;
    submachine : (subgen: smtgen_all);
  {$elseif defined(CPUARM)}
    {$IFDEF ENDIAN_LITTLE}
    machine : mtarm;
    submachine : (subarm: smtarm_all);
    {$ELSE}
    machine : mtarmeb;
    submachine : (subarm: smtarm_all);
    {$ENDIF}
  {$elseif defined(CPU68K)}
    machine : mtm68k;
    submachine : (subgen: smtgen_all);
  {$elseif defined(CPUSPARC)}
    machine : mtsparc;
    submachine : (subgen: smtgen_all);
  {$elseif defined(CPUALPHA)}
    machine : mtalpha;
    submachine : (subgen: smtgen_all);
  {$elseif defined(CPUIA64)}
    machine : mtia64;
    submachine : (subgen: smtgen_all);
  {$elseif defined(CPUMIPSEL)}
    machine : mtmipsel;
    submachine : (subgen: smtgen_all);
  {$elseif defined(CPUMIPS)}
    machine : mtmips;
    submachine : (subgen: smtgen_all);
  {$elseif defined(CPUAARCH64)}
    machine : mtaarch64;
    submachine : (subgen: smtgen_all);
  {$else}
    machine : mti386;  //default i386
    submachine : (subgen: smtgen_all);
  {$endif}

  {$IFDEF WINDOWS}
    objformat : ofCoff;
  {$ELSE}
    {$IF defined(DARWIN)}
      objformat : ofMachO;
    {$ELSEIF defined(AIX)}
      objformat : ofXCoff;
    {$ELSE}
      objformat : ofElf;
    {$ENDIF}
  {$ENDIF}
  );


implementation

function GetDefaultMachineForFormat(aFormat : TObjFormat) : TMachineType;
begin
  case aFormat of
    ofNone : Result:=mtnone;
    ofRes  : Result:=mtnone;
    ofElf  : Result:=mti386;
    ofCoff : Result:=mti386;
    ofXCoff: Result:=mtppc;
    ofMachO: Result:=mti386;
    {$IFDEF ENDIAN_BIG}
    ofExt  : Result:=mtBigEndian;
    {$ELSE}
    ofExt  : Result:=mtLittleEndian;
    {$ENDIF}
  end;
end;

function MachineToStr(const aMachine : TMachineType) : string;
begin
  Result:=Machines[aMachine].name;
end;

function SubMachineToStr(const aMachine : TMachineType; const aSubMachine : TSubMachineType) : string;
begin
  case aMachine of
    mtarm,mtarmeb:
      result:=SubMachinesArm[aSubMachine.subarm];
    else
      // no need to confuse people with the "all" suffix, it doesn't do
      // anything anyway
      result:='';
  end;
end;

function ObjFormatToStr(const aFormat : TObjFormat) : string;
begin
  Result:=ObjFormats[aFormat].name;
end;

function GetDefaultSubMachineForMachine(aMachine: TMachineType): TSubMachineType;
begin
  case aMachine of
    mtarm,mtarmeb:
      result.subarm:=smtarm_all;
    else
      result.subgen:=smtgen_all;
  end;
end;

function TargetToStr(const aTarget : TResTarget) : string;
var s1, s2, s3 : string;
begin
  s1:=MachineToStr(aTarget.machine);
  s2:=ObjFormatToStr(aTarget.objformat);
  s3:=SubMachineToStr(aTarget.Machine,aTarget.submachine);
  if (s1='') or (s2='') then Result:=s1+s2
  else Result:=s1+' - '+s2;
  if s3<>'' then
    Result:=Result+'-'+s3;
end;

end.