dirparse.pas 9.5 KB

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