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
|
//
//
// The Nimrod Compiler
// (c) Copyright 2008 Andreas Rumpf
//
// See the file "copying.txt", included in this
// distribution, for details about the copyright.
//
unit condsyms;
// This module handles the conditional symbols.
{$include 'config.inc'}
interface
uses
nsystem, ast, astalgo, msgs, nhashes, platform, strutils, idents;
var
gSymbols: TStrTable;
procedure InitDefines;
procedure DeinitDefines;
procedure DefineSymbol(const symbol: string);
procedure UndefSymbol(const symbol: string);
function isDefined(symbol: PIdent): Boolean;
procedure ListSymbols;
function countDefinedSymbols: int;
implementation
procedure DefineSymbol(const symbol: string);
var
sym: PSym;
i: PIdent;
begin
i := getIdent(symbol);
sym := StrTableGet(gSymbols, i);
if sym = nil then begin
new(sym); // circumvent the ID mechanism
{@ignore}
fillChar(sym^, sizeof(sym^), 0);
{@emit}
sym.kind := skConditional;
sym.name := i;
StrTableAdd(gSymbols, sym);
end;
sym.position := 1;
end;
procedure UndefSymbol(const symbol: string);
var
sym: PSym;
begin
sym := StrTableGet(gSymbols, getIdent(symbol));
if sym <> nil then sym.position := 0;
end;
function isDefined(symbol: PIdent): Boolean;
var
sym: PSym;
begin
sym := StrTableGet(gSymbols, symbol);
result := (sym <> nil) and (sym.position = 1)
end;
procedure ListSymbols;
var
it: TTabIter;
s: PSym;
begin
s := InitTabIter(it, gSymbols);
MessageOut('-- List of currently defined symbols --');
while s <> nil do begin
if s.position = 1 then MessageOut(s.name.s);
s := nextIter(it, gSymbols);
end;
MessageOut('-- End of list --');
end;
function countDefinedSymbols: int;
var
it: TTabIter;
s: PSym;
begin
s := InitTabIter(it, gSymbols);
result := 0;
while s <> nil do begin
if s.position = 1 then inc(result);
s := nextIter(it, gSymbols);
end;
end;
procedure InitDefines;
begin
initStrTable(gSymbols);
DefineSymbol('nimrod'); // 'nimrod' is always defined
{@ignore}
DefineSymbol('nim'); // Pascal version defines 'nim' in addition
{@emit}
// add platform specific symbols:
case targetCPU of
cpuI386: DefineSymbol('x86');
cpuIa64: DefineSymbol('itanium');
cpuAmd64: DefineSymbol('x8664');
else begin end
end;
case targetOS of
osDOS: DefineSymbol('msdos');
osWindows: begin
DefineSymbol('mswindows');
DefineSymbol('win32');
end;
osLinux, osMorphOS, osSkyOS, osIrix, osPalmOS, osQNX, osAtari, osAix: begin
// these are all 'unix-like'
DefineSymbol('unix');
DefineSymbol('posix');
end;
osSolaris: begin
DefineSymbol('sunos');
DefineSymbol('unix');
DefineSymbol('posix');
end;
osNetBSD, osFreeBSD, osOpenBSD: begin
DefineSymbol('unix');
DefineSymbol('bsd');
DefineSymbol('posix');
end;
osMacOS: begin
DefineSymbol('macintosh');
end;
osMacOSX: begin
DefineSymbol('macintosh');
DefineSymbol('unix');
DefineSymbol('posix');
end;
else begin end
end;
DefineSymbol('cpu' + ToString( cpu[targetCPU].bit ));
DefineSymbol(normalize(endianToStr[cpu[targetCPU].endian]));
DefineSymbol(cpu[targetCPU].name);
DefineSymbol(platform.os[targetOS].name);
end;
procedure DeinitDefines;
begin
end;
end.
|