dirparse.pas 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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 if tok='MAXCRECORD' then
  90. b.maxCrecordalign:=l
  91. else { Error }
  92. UpdateAlignmentStr:=false;
  93. until false;
  94. Result:=Result and UpdateAlignment(a,b);
  95. end;
  96. function UpdateOptimizerStr(s:string;var a:toptimizerswitches):boolean;
  97. var
  98. tok : string;
  99. doset,
  100. found : boolean;
  101. opt : toptimizerswitch;
  102. begin
  103. result:=true;
  104. uppervar(s);
  105. repeat
  106. tok:=GetToken(s,',');
  107. if tok='' then
  108. break;
  109. if Copy(tok,1,2)='NO' then
  110. begin
  111. delete(tok,1,2);
  112. doset:=false;
  113. end
  114. else
  115. doset:=true;
  116. found:=false;
  117. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  118. begin
  119. if OptimizerSwitchStr[opt]=tok then
  120. begin
  121. found:=true;
  122. break;
  123. end;
  124. end;
  125. if found then
  126. begin
  127. {$ifdef llvm}
  128. { -Ooregvar is not supported, llvm will take care of that }
  129. if opt<>cs_opt_regvar then
  130. {$endif llvm}
  131. if doset then
  132. include(a,opt)
  133. else
  134. exclude(a,opt);
  135. end
  136. else
  137. result:=false;
  138. until false;
  139. end;
  140. function UpdateWpoStr(s: string; var a: twpoptimizerswitches): boolean;
  141. var
  142. tok : string;
  143. doset,
  144. found : boolean;
  145. opt : twpoptimizerswitch;
  146. begin
  147. result:=true;
  148. uppervar(s);
  149. repeat
  150. tok:=GetToken(s,',');
  151. if tok='' then
  152. break;
  153. if Copy(tok,1,2)='NO' then
  154. begin
  155. delete(tok,1,2);
  156. doset:=false;
  157. end
  158. else
  159. doset:=true;
  160. found:=false;
  161. if (tok = 'ALL') then
  162. begin
  163. for opt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  164. if doset then
  165. include(a,opt)
  166. else
  167. exclude(a,opt);
  168. end
  169. else
  170. begin
  171. for opt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  172. begin
  173. if WPOptimizerSwitchStr[opt]=tok then
  174. begin
  175. found:=true;
  176. break;
  177. end;
  178. end;
  179. if found then
  180. begin
  181. if doset then
  182. include(a,opt)
  183. else
  184. exclude(a,opt);
  185. end
  186. else
  187. result:=false;
  188. end;
  189. until false;
  190. end;
  191. function UpdateDebugStr(s:string;var a:tdebugswitches):boolean;
  192. var
  193. tok : string;
  194. doset,
  195. found : boolean;
  196. opt : tdebugswitch;
  197. begin
  198. result:=true;
  199. uppervar(s);
  200. repeat
  201. tok:=GetToken(s,',');
  202. if tok='' then
  203. break;
  204. if Copy(tok,1,2)='NO' then
  205. begin
  206. delete(tok,1,2);
  207. doset:=false;
  208. end
  209. else
  210. doset:=true;
  211. found:=false;
  212. for opt:=low(tdebugswitch) to high(tdebugswitch) do
  213. begin
  214. if DebugSwitchStr[opt]=tok then
  215. begin
  216. found:=true;
  217. break;
  218. end;
  219. end;
  220. if found then
  221. begin
  222. if doset then
  223. include(a,opt)
  224. else
  225. exclude(a,opt);
  226. end
  227. else
  228. result:=false;
  229. until false;
  230. end;
  231. function UpdateTargetSwitchStr(s: string; var a: ttargetswitches; global: boolean): boolean;
  232. var
  233. tok,
  234. value : string;
  235. setstr: string[2];
  236. equalspos: longint;
  237. doset,
  238. gotvalue,
  239. found : boolean;
  240. opt : ttargetswitch;
  241. begin
  242. result:=true;
  243. value:='';
  244. repeat
  245. tok:=GetToken(s,',');
  246. if tok='' then
  247. break;
  248. setstr:=upper(copy(tok,length(tok),1));
  249. if setstr='-' then
  250. begin
  251. setlength(tok,length(tok)-1);
  252. doset:=false;
  253. end
  254. else
  255. doset:=true;
  256. { value specified? }
  257. gotvalue:=false;
  258. equalspos:=pos('=',tok);
  259. if equalspos<>0 then
  260. begin
  261. value:=copy(tok,equalspos+1,length(tok));
  262. delete(tok,equalspos,length(tok));
  263. gotvalue:=true;
  264. end;
  265. found:=false;
  266. uppervar(tok);
  267. for opt:=low(ttargetswitch) to high(ttargetswitch) do
  268. begin
  269. if TargetSwitchStr[opt].name=tok then
  270. begin
  271. found:=true;
  272. break;
  273. end;
  274. end;
  275. if found then
  276. begin
  277. if not global and
  278. TargetSwitchStr[opt].isglobal then
  279. result:=false
  280. else if not TargetSwitchStr[opt].hasvalue then
  281. begin
  282. if gotvalue then
  283. result:=false;
  284. if (TargetSwitchStr[opt].define<>'') and (doset xor (opt in a)) then
  285. if doset then
  286. def_system_macro(TargetSwitchStr[opt].define)
  287. else
  288. undef_system_macro(TargetSwitchStr[opt].define);
  289. if doset then
  290. include(a,opt)
  291. else
  292. exclude(a,opt)
  293. end
  294. else
  295. begin
  296. if not gotvalue or
  297. not doset then
  298. result:=false
  299. else
  300. begin
  301. case opt of
  302. ts_auto_getter_prefix:
  303. prop_auto_getter_prefix:=value;
  304. ts_auto_setter_predix:
  305. prop_auto_setter_prefix:=value;
  306. else
  307. begin
  308. writeln('Internalerror 2012053001');
  309. halt(1);
  310. end;
  311. end;
  312. end;
  313. end;
  314. end
  315. else
  316. result:=false;
  317. until false;
  318. end;
  319. end.