2
0

dirparse.pas 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements some support functions for the parsing of directives
  4. and option strings
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit dirparse;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. globtype,
  23. systems;
  24. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  25. function UpdateOptimizerStr(s:string;var a:toptimizerswitches):boolean;
  26. function UpdateWpoStr(s: string; var a: twpoptimizerswitches): boolean;
  27. function UpdateDebugStr(s:string;var a:tdebugswitches):boolean;
  28. function UpdateTargetSwitchStr(s: string; var a: ttargetswitches; global: boolean): boolean;
  29. implementation
  30. uses
  31. globals,
  32. cutils,
  33. symtable;
  34. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  35. var
  36. tok : string;
  37. vstr : string;
  38. l : longint;
  39. code : integer;
  40. b : talignmentinfo;
  41. begin
  42. UpdateAlignmentStr:=true;
  43. uppervar(s);
  44. fillchar(b,sizeof(b),0);
  45. repeat
  46. tok:=GetToken(s,'=');
  47. if tok='' then
  48. break;
  49. vstr:=GetToken(s,',');
  50. val(vstr,l,code);
  51. if tok='PROC' then
  52. b.procalign:=l
  53. else if tok='JUMP' then
  54. b.jumpalign:=l
  55. else if tok='LOOP' then
  56. b.loopalign:=l
  57. else if tok='CONSTMIN' then
  58. begin
  59. b.constalignmin:=l;
  60. if l>b.constalignmax then
  61. b.constalignmax:=l;
  62. end
  63. else if tok='CONSTMAX' then
  64. b.constalignmax:=l
  65. else if tok='VARMIN' then
  66. begin
  67. b.varalignmin:=l;
  68. if l>b.varalignmax then
  69. b.varalignmax:=l;
  70. end
  71. else if tok='VARMAX' then
  72. b.varalignmax:=l
  73. else if tok='LOCALMIN' then
  74. begin
  75. b.localalignmin:=l;
  76. if l>b.localalignmax then
  77. b.localalignmax:=l;
  78. end
  79. else if tok='LOCALMAX' then
  80. b.localalignmax:=l
  81. else if tok='RECORDMIN' then
  82. begin
  83. b.recordalignmin:=l;
  84. if l>b.recordalignmax then
  85. b.recordalignmax:=l;
  86. end
  87. else if tok='RECORDMAX' then
  88. b.recordalignmax:=l
  89. else { Error }
  90. UpdateAlignmentStr:=false;
  91. until false;
  92. Result:=Result and UpdateAlignment(a,b);
  93. end;
  94. function UpdateOptimizerStr(s:string;var a:toptimizerswitches):boolean;
  95. var
  96. tok : string;
  97. doset,
  98. found : boolean;
  99. opt : toptimizerswitch;
  100. begin
  101. result:=true;
  102. uppervar(s);
  103. repeat
  104. tok:=GetToken(s,',');
  105. if tok='' then
  106. break;
  107. if Copy(tok,1,2)='NO' then
  108. begin
  109. delete(tok,1,2);
  110. doset:=false;
  111. end
  112. else
  113. doset:=true;
  114. found:=false;
  115. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  116. begin
  117. if OptimizerSwitchStr[opt]=tok then
  118. begin
  119. found:=true;
  120. break;
  121. end;
  122. end;
  123. if found then
  124. begin
  125. {$ifdef llvm}
  126. { -Ooregvar is not supported, llvm will take care of that }
  127. if opt<>cs_opt_regvar then
  128. {$endif llvm}
  129. if doset then
  130. include(a,opt)
  131. else
  132. exclude(a,opt);
  133. end
  134. else
  135. result:=false;
  136. until false;
  137. end;
  138. function UpdateWpoStr(s: string; var a: twpoptimizerswitches): boolean;
  139. var
  140. tok : string;
  141. doset,
  142. found : boolean;
  143. opt : twpoptimizerswitch;
  144. begin
  145. result:=true;
  146. uppervar(s);
  147. repeat
  148. tok:=GetToken(s,',');
  149. if tok='' then
  150. break;
  151. if Copy(tok,1,2)='NO' then
  152. begin
  153. delete(tok,1,2);
  154. doset:=false;
  155. end
  156. else
  157. doset:=true;
  158. found:=false;
  159. if (tok = 'ALL') then
  160. begin
  161. for opt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  162. if doset then
  163. include(a,opt)
  164. else
  165. exclude(a,opt);
  166. end
  167. else
  168. begin
  169. for opt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  170. begin
  171. if WPOptimizerSwitchStr[opt]=tok then
  172. begin
  173. found:=true;
  174. break;
  175. end;
  176. end;
  177. if found then
  178. begin
  179. if doset then
  180. include(a,opt)
  181. else
  182. exclude(a,opt);
  183. end
  184. else
  185. result:=false;
  186. end;
  187. until false;
  188. end;
  189. function UpdateDebugStr(s:string;var a:tdebugswitches):boolean;
  190. var
  191. tok : string;
  192. doset,
  193. found : boolean;
  194. opt : tdebugswitch;
  195. begin
  196. result:=true;
  197. uppervar(s);
  198. repeat
  199. tok:=GetToken(s,',');
  200. if tok='' then
  201. break;
  202. if Copy(tok,1,2)='NO' then
  203. begin
  204. delete(tok,1,2);
  205. doset:=false;
  206. end
  207. else
  208. doset:=true;
  209. found:=false;
  210. for opt:=low(tdebugswitch) to high(tdebugswitch) do
  211. begin
  212. if DebugSwitchStr[opt]=tok then
  213. begin
  214. found:=true;
  215. break;
  216. end;
  217. end;
  218. if found then
  219. begin
  220. if doset then
  221. include(a,opt)
  222. else
  223. exclude(a,opt);
  224. end
  225. else
  226. result:=false;
  227. until false;
  228. end;
  229. function UpdateTargetSwitchStr(s: string; var a: ttargetswitches; global: boolean): boolean;
  230. var
  231. tok,
  232. value : string;
  233. setstr: string[2];
  234. equalspos: longint;
  235. doset,
  236. gotvalue,
  237. found : boolean;
  238. opt : ttargetswitch;
  239. begin
  240. result:=true;
  241. value:='';
  242. repeat
  243. tok:=GetToken(s,',');
  244. if tok='' then
  245. break;
  246. setstr:=upper(copy(tok,length(tok),1));
  247. if setstr='-' then
  248. begin
  249. setlength(tok,length(tok)-1);
  250. doset:=false;
  251. end
  252. else
  253. doset:=true;
  254. { value specified? }
  255. gotvalue:=false;
  256. equalspos:=pos('=',tok);
  257. if equalspos<>0 then
  258. begin
  259. value:=copy(tok,equalspos+1,length(tok));
  260. delete(tok,equalspos,length(tok));
  261. gotvalue:=true;
  262. end;
  263. found:=false;
  264. uppervar(tok);
  265. for opt:=low(ttargetswitch) to high(ttargetswitch) do
  266. begin
  267. if TargetSwitchStr[opt].name=tok then
  268. begin
  269. found:=true;
  270. break;
  271. end;
  272. end;
  273. if found then
  274. begin
  275. if not global and
  276. TargetSwitchStr[opt].isglobal then
  277. result:=false
  278. else if not TargetSwitchStr[opt].hasvalue then
  279. begin
  280. if gotvalue then
  281. result:=false;
  282. if (TargetSwitchStr[opt].define<>'') and (doset xor (opt in a)) then
  283. if doset then
  284. def_system_macro(TargetSwitchStr[opt].define)
  285. else
  286. undef_system_macro(TargetSwitchStr[opt].define);
  287. if doset then
  288. include(a,opt)
  289. else
  290. exclude(a,opt)
  291. end
  292. else
  293. begin
  294. if not gotvalue or
  295. not doset then
  296. result:=false
  297. else
  298. begin
  299. case opt of
  300. ts_auto_getter_prefix:
  301. prop_auto_getter_prefix:=value;
  302. ts_auto_setter_predix:
  303. prop_auto_setter_prefix:=value;
  304. else
  305. begin
  306. writeln('Internalerror 2012053001');
  307. halt(1);
  308. end;
  309. end;
  310. end;
  311. end;
  312. end
  313. else
  314. result:=false;
  315. until false;
  316. end;
  317. end.