ra386att.pas 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Carl Eric Codere and Peter Vreman
  4. Does the parsing for the AT&T styled inline assembler.
  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 Ra386att;
  19. {$i defines.inc}
  20. Interface
  21. uses
  22. node;
  23. function assemble: tnode;
  24. Implementation
  25. uses
  26. { common }
  27. cutils,cobjects,
  28. { global }
  29. globtype,globals,verbose,
  30. systems,cpuinfo,
  31. { aasm }
  32. cpubase,aasm,
  33. { symtable }
  34. symconst,symtable,types,
  35. { pass 1 }
  36. nbas,
  37. { parser }
  38. scanner,
  39. ra386,rautils,
  40. { codegen }
  41. {$ifdef newcg}
  42. cgbase
  43. {$else}
  44. hcodegen
  45. {$endif}
  46. ;
  47. type
  48. tasmtoken = (
  49. AS_NONE,AS_LABEL,AS_LLABEL,AS_STRING,AS_INTNUM,
  50. AS_REALNUM,AS_COMMA,AS_LPAREN,
  51. AS_RPAREN,AS_COLON,AS_DOT,AS_PLUS,AS_MINUS,AS_STAR,
  52. AS_SEPARATOR,AS_ID,AS_REGISTER,AS_OPCODE,AS_SLASH,AS_DOLLAR,
  53. {------------------ Assembler directives --------------------}
  54. AS_DB,AS_DW,AS_DD,AS_DQ,AS_GLOBAL,
  55. AS_ALIGN,AS_BALIGN,AS_P2ALIGN,AS_ASCII,
  56. AS_ASCIIZ,AS_LCOMM,AS_COMM,AS_SINGLE,AS_DOUBLE,AS_EXTENDED,
  57. AS_DATA,AS_TEXT,AS_END,
  58. {------------------ Assembler Operators --------------------}
  59. AS_TYPE,AS_MOD,AS_SHL,AS_SHR,AS_NOT,AS_AND,AS_OR,AS_XOR,AS_NOR);
  60. tasmkeyword = string[10];
  61. const
  62. { These tokens should be modified accordingly to the modifications }
  63. { in the different enumerations. }
  64. firstdirective = AS_DB;
  65. lastdirective = AS_END;
  66. _count_asmprefixes = 5;
  67. _count_asmspecialops = 25;
  68. _count_asmoverrides = 3;
  69. token2str : array[tasmtoken] of tasmkeyword=(
  70. '','Label','LLabel','string','integer',
  71. 'float',',','(',
  72. ')',':','.','+','-','*',
  73. ';','identifier','register','opcode','/','$',
  74. '.byte','.word','.long','.quad','.globl',
  75. '.align','.balign','.p2align','.ascii',
  76. '.asciz','.lcomm','.comm','.single','.double','.tfloat',
  77. '.data','.text','END',
  78. 'TYPE','%','<<','>>','!','&','|','^','~');
  79. const
  80. newline = #10;
  81. firsttoken : boolean = TRUE;
  82. var
  83. _asmsorted : boolean;
  84. curlist : paasmoutput;
  85. c : char;
  86. actasmtoken : tasmtoken;
  87. prevasmtoken : tasmtoken;
  88. actasmpattern : string;
  89. actopcode : tasmop;
  90. actasmregister : tregister;
  91. actopsize : topsize;
  92. actcondition : tasmcond;
  93. iasmops : Pdictionary;
  94. iasmregs : ^reg2strtable;
  95. Procedure SetupTables;
  96. { creates uppercased symbol tables for speed access }
  97. var
  98. i : tasmop;
  99. j : tregister;
  100. str2opentry: pstr2opentry;
  101. Begin
  102. { opcodes }
  103. new(iasmops,init);
  104. for i:=firstop to lastop do
  105. begin
  106. new(str2opentry,initname(upper(att_op2str[i])));
  107. str2opentry^.op:=i;
  108. iasmops^.insert(str2opentry);
  109. end;
  110. { registers }
  111. new(iasmregs);
  112. for j:=firstreg to lastreg do
  113. iasmregs^[j] := upper(att_reg2str[j]);
  114. end;
  115. {---------------------------------------------------------------------}
  116. { Routines for the tokenizing }
  117. {---------------------------------------------------------------------}
  118. function is_asmopcode(const s: string):boolean;
  119. const
  120. { We need first to check the long prefixes, else we get probs
  121. with things like movsbl }
  122. att_sizesuffixstr : array[0..9] of string[2] = (
  123. '','BW','BL','WL','B','W','L','S','Q','T'
  124. );
  125. att_sizesuffix : array[0..9] of topsize = (
  126. S_NO,S_BW,S_BL,S_WL,S_B,S_W,S_L,S_FS,S_IQ,S_FX
  127. );
  128. att_sizefpusuffix : array[0..9] of topsize = (
  129. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_FL,S_FS,S_IQ,S_FX
  130. );
  131. att_sizefpuintsuffix : array[0..9] of topsize = (
  132. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_IL,S_IS,S_IQ,S_NO
  133. );
  134. var
  135. str2opentry: pstr2opentry;
  136. cond : string[4];
  137. cnd : tasmcond;
  138. len,
  139. j,
  140. sufidx : longint;
  141. Begin
  142. is_asmopcode:=FALSE;
  143. actopcode:=A_None;
  144. actcondition:=C_None;
  145. actopsize:=S_NO;
  146. { search for all possible suffixes }
  147. for sufidx:=low(att_sizesuffixstr) to high(att_sizesuffixstr) do
  148. begin
  149. len:=length(s)-length(att_sizesuffixstr[sufidx]);
  150. if copy(s,len+1,length(att_sizesuffixstr[sufidx]))=att_sizesuffixstr[sufidx] then
  151. begin
  152. { here we search the entire table... }
  153. str2opentry:=nil;
  154. if {(length(s)>0) and} (len>0) then
  155. str2opentry:=pstr2opentry(iasmops^.search(copy(s,1,len)));
  156. if assigned(str2opentry) then
  157. begin
  158. actopcode:=str2opentry^.op;
  159. if att_needsuffix[actopcode]=attsufFPU then
  160. actopsize:=att_sizefpusuffix[sufidx]
  161. else if att_needsuffix[actopcode]=attsufFPUint then
  162. actopsize:=att_sizefpuintsuffix[sufidx]
  163. else
  164. actopsize:=att_sizesuffix[sufidx];
  165. actasmtoken:=AS_OPCODE;
  166. is_asmopcode:=TRUE;
  167. exit;
  168. end;
  169. { not found, check condition opcodes }
  170. j:=0;
  171. while (j<CondAsmOps) do
  172. begin
  173. if Copy(s,1,Length(CondAsmOpStr[j]))=CondAsmOpStr[j] then
  174. begin
  175. cond:=Copy(s,Length(CondAsmOpStr[j])+1,len-Length(CondAsmOpStr[j]));
  176. if cond<>'' then
  177. begin
  178. for cnd:=low(TasmCond) to high(TasmCond) do
  179. if Cond=Upper(cond2str[cnd]) then
  180. begin
  181. actopcode:=CondASmOp[j];
  182. if att_needsuffix[actopcode]=attsufFPU then
  183. actopsize:=att_sizefpusuffix[sufidx]
  184. else if att_needsuffix[actopcode]=attsufFPUint then
  185. actopsize:=att_sizefpuintsuffix[sufidx]
  186. else
  187. actopsize:=att_sizesuffix[sufidx];
  188. actcondition:=cnd;
  189. actasmtoken:=AS_OPCODE;
  190. is_asmopcode:=TRUE;
  191. exit;
  192. end;
  193. end;
  194. end;
  195. inc(j);
  196. end;
  197. end;
  198. end;
  199. end;
  200. Function is_asmdirective(const s: string):boolean;
  201. var
  202. i : tasmtoken;
  203. hs : string;
  204. Begin
  205. { GNU as is also not casesensitive with this }
  206. hs:=lower(s);
  207. for i:=firstdirective to lastdirective do
  208. if hs=token2str[i] then
  209. begin
  210. actasmtoken:=i;
  211. is_asmdirective:=true;
  212. exit;
  213. end;
  214. is_asmdirective:=false;
  215. end;
  216. Function is_register(const s: string):boolean;
  217. Var
  218. i : tregister;
  219. Begin
  220. actasmregister:=R_NO;
  221. for i:=firstreg to lastreg do
  222. if s=iasmregs^[i] then
  223. begin
  224. actasmtoken:=AS_REGISTER;
  225. actasmregister:=i;
  226. is_register:=true;
  227. exit;
  228. end;
  229. is_register:=false;
  230. end;
  231. Function is_locallabel(const s: string):boolean;
  232. begin
  233. is_locallabel:=(length(s)>=2) and (s[1]='.') and (s[2]='L');
  234. end;
  235. Procedure GetToken;
  236. var
  237. len : longint;
  238. begin
  239. { save old token and reset new token }
  240. prevasmtoken:=actasmtoken;
  241. actasmtoken:=AS_NONE;
  242. { reset }
  243. actasmpattern:='';
  244. { while space and tab , continue scan... }
  245. while c in [' ',#9] do
  246. c:=current_scanner^.asmgetchar;
  247. { get token pos }
  248. if not (c in [newline,#13,'{',';']) then
  249. current_scanner^.gettokenpos;
  250. { Local Label, Label, Directive, Prefix or Opcode }
  251. if firsttoken and not(c in [newline,#13,'{',';']) then
  252. begin
  253. firsttoken:=FALSE;
  254. len:=0;
  255. { directive or local label }
  256. if c = '.' then
  257. begin
  258. inc(len);
  259. actasmpattern[len]:=c;
  260. { Let us point to the next character }
  261. c:=current_scanner^.asmgetchar;
  262. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  263. begin
  264. inc(len);
  265. actasmpattern[len]:=c;
  266. c:=current_scanner^.asmgetchar;
  267. end;
  268. actasmpattern[0]:=chr(len);
  269. { this is a local label... }
  270. if (c=':') and is_locallabel(actasmpattern) then
  271. Begin
  272. { local variables are case sensitive }
  273. actasmtoken:=AS_LLABEL;
  274. c:=current_scanner^.asmgetchar;
  275. firsttoken:=true;
  276. exit;
  277. end
  278. { must be a directive }
  279. else
  280. Begin
  281. { directives are case sensitive!! }
  282. if is_asmdirective(actasmpattern) then
  283. exit;
  284. Message1(asmr_e_not_directive_or_local_symbol,actasmpattern);
  285. end;
  286. end;
  287. { only opcodes and global labels are allowed now. }
  288. while c in ['A'..'Z','a'..'z','0'..'9','_'] do
  289. begin
  290. inc(len);
  291. actasmpattern[len]:=c;
  292. c:=current_scanner^.asmgetchar;
  293. end;
  294. actasmpattern[0]:=chr(len);
  295. { Label ? }
  296. if c = ':' then
  297. begin
  298. actasmtoken:=AS_LABEL;
  299. { let us point to the next character }
  300. c:=current_scanner^.asmgetchar;
  301. firsttoken:=true;
  302. exit;
  303. end;
  304. { Opcode ? }
  305. If is_asmopcode(upper(actasmpattern)) then
  306. Begin
  307. uppervar(actasmpattern);
  308. exit;
  309. end;
  310. { End of assemblerblock ? }
  311. if upper(actasmpattern) = 'END' then
  312. begin
  313. actasmtoken:=AS_END;
  314. exit;
  315. end;
  316. message1(asmr_e_unknown_opcode,actasmpattern);
  317. actasmtoken:=AS_NONE;
  318. end
  319. else { else firsttoken }
  320. { Here we must handle all possible cases }
  321. begin
  322. case c of
  323. '.' : { possiblities : - local label reference , such as in jmp @local1 }
  324. { - field of object/record }
  325. { - directive. }
  326. begin
  327. if (prevasmtoken in [AS_ID,AS_RPAREN]) then
  328. begin
  329. c:=current_scanner^.asmgetchar;
  330. actasmtoken:=AS_DOT;
  331. exit;
  332. end;
  333. actasmpattern:=c;
  334. c:=current_scanner^.asmgetchar;
  335. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  336. begin
  337. actasmpattern:=actasmpattern + c;
  338. c:=current_scanner^.asmgetchar;
  339. end;
  340. if is_asmdirective(actasmpattern) then
  341. exit;
  342. { local label references and directives }
  343. { are case sensitive }
  344. actasmtoken:=AS_ID;
  345. exit;
  346. end;
  347. { identifier, register, prefix or directive }
  348. '_','A'..'Z','a'..'z':
  349. begin
  350. len:=0;
  351. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  352. begin
  353. inc(len);
  354. actasmpattern[len]:=c;
  355. c:=current_scanner^.asmgetchar;
  356. end;
  357. actasmpattern[0]:=chr(len);
  358. uppervar(actasmpattern);
  359. { Opcode, can only be when the previous was a prefix }
  360. If is_prefix(actopcode) and is_asmopcode(upper(actasmpattern)) then
  361. Begin
  362. uppervar(actasmpattern);
  363. exit;
  364. end;
  365. { check for end which is a reserved word unlike the opcodes }
  366. if actasmpattern = 'END' then
  367. Begin
  368. actasmtoken:=AS_END;
  369. exit;
  370. end;
  371. if actasmpattern = 'TYPE' then
  372. Begin
  373. actasmtoken:=AS_TYPE;
  374. exit;
  375. end;
  376. actasmtoken:=AS_ID;
  377. exit;
  378. end;
  379. '%' : { register or modulo }
  380. begin
  381. len:=1;
  382. actasmpattern[len]:='%';
  383. c:=current_scanner^.asmgetchar;
  384. { to be a register there must be a letter and not a number }
  385. if c in ['0'..'9'] then
  386. begin
  387. actasmtoken:=AS_MOD;
  388. {Message(asmr_w_modulo_not_supported);}
  389. end
  390. else
  391. begin
  392. while c in ['a'..'z','A'..'Z','0'..'9'] do
  393. Begin
  394. inc(len);
  395. actasmpattern[len]:=c;
  396. c:=current_scanner^.asmgetchar;
  397. end;
  398. actasmpattern[0]:=chr(len);
  399. uppervar(actasmpattern);
  400. if (actasmpattern = '%ST') and (c='(') then
  401. Begin
  402. actasmpattern:=actasmpattern+c;
  403. c:=current_scanner^.asmgetchar;
  404. if c in ['0'..'9'] then
  405. actasmpattern:=actasmpattern + c
  406. else
  407. Message(asmr_e_invalid_fpu_register);
  408. c:=current_scanner^.asmgetchar;
  409. if c <> ')' then
  410. Message(asmr_e_invalid_fpu_register)
  411. else
  412. Begin
  413. actasmpattern:=actasmpattern + c;
  414. c:=current_scanner^.asmgetchar; { let us point to next character. }
  415. end;
  416. end;
  417. if is_register(actasmpattern) then
  418. exit;
  419. Message(asmr_e_invalid_register);
  420. actasmtoken:=AS_NONE;
  421. end;
  422. end;
  423. '1'..'9': { integer number }
  424. begin
  425. len:=0;
  426. while c in ['0'..'9'] do
  427. Begin
  428. inc(len);
  429. actasmpattern[len]:=c;
  430. c:=current_scanner^.asmgetchar;
  431. end;
  432. actasmpattern[0]:=chr(len);
  433. actasmpattern:=tostr(ValDecimal(actasmpattern));
  434. actasmtoken:=AS_INTNUM;
  435. exit;
  436. end;
  437. '0' : { octal,hexa,real or binary number. }
  438. begin
  439. actasmpattern:=c;
  440. c:=current_scanner^.asmgetchar;
  441. case upcase(c) of
  442. 'B': { binary }
  443. Begin
  444. c:=current_scanner^.asmgetchar;
  445. while c in ['0','1'] do
  446. Begin
  447. actasmpattern:=actasmpattern + c;
  448. c:=current_scanner^.asmgetchar;
  449. end;
  450. actasmpattern:=tostr(ValBinary(actasmpattern));
  451. actasmtoken:=AS_INTNUM;
  452. exit;
  453. end;
  454. 'D': { real }
  455. Begin
  456. c:=current_scanner^.asmgetchar;
  457. { get ridd of the 0d }
  458. if (c in ['+','-']) then
  459. begin
  460. actasmpattern:=c;
  461. c:=current_scanner^.asmgetchar;
  462. end
  463. else
  464. actasmpattern:='';
  465. while c in ['0'..'9'] do
  466. Begin
  467. actasmpattern:=actasmpattern + c;
  468. c:=current_scanner^.asmgetchar;
  469. end;
  470. if c='.' then
  471. begin
  472. actasmpattern:=actasmpattern + c;
  473. c:=current_scanner^.asmgetchar;
  474. while c in ['0'..'9'] do
  475. Begin
  476. actasmpattern:=actasmpattern + c;
  477. c:=current_scanner^.asmgetchar;
  478. end;
  479. if upcase(c) = 'E' then
  480. begin
  481. actasmpattern:=actasmpattern + c;
  482. c:=current_scanner^.asmgetchar;
  483. if (c in ['+','-']) then
  484. begin
  485. actasmpattern:=actasmpattern + c;
  486. c:=current_scanner^.asmgetchar;
  487. end;
  488. while c in ['0'..'9'] do
  489. Begin
  490. actasmpattern:=actasmpattern + c;
  491. c:=current_scanner^.asmgetchar;
  492. end;
  493. end;
  494. actasmtoken:=AS_REALNUM;
  495. exit;
  496. end
  497. else
  498. begin
  499. Message1(asmr_e_invalid_float_const,actasmpattern+c);
  500. actasmtoken:=AS_NONE;
  501. end;
  502. end;
  503. 'X': { hexadecimal }
  504. Begin
  505. c:=current_scanner^.asmgetchar;
  506. while c in ['0'..'9','a'..'f','A'..'F'] do
  507. Begin
  508. actasmpattern:=actasmpattern + c;
  509. c:=current_scanner^.asmgetchar;
  510. end;
  511. actasmpattern:=tostr(ValHexaDecimal(actasmpattern));
  512. actasmtoken:=AS_INTNUM;
  513. exit;
  514. end;
  515. '1'..'7': { octal }
  516. begin
  517. actasmpattern:=actasmpattern + c;
  518. while c in ['0'..'7'] do
  519. Begin
  520. actasmpattern:=actasmpattern + c;
  521. c:=current_scanner^.asmgetchar;
  522. end;
  523. actasmpattern:=tostr(ValOctal(actasmpattern));
  524. actasmtoken:=AS_INTNUM;
  525. exit;
  526. end;
  527. else { octal number zero value...}
  528. Begin
  529. actasmpattern:=tostr(ValOctal(actasmpattern));
  530. actasmtoken:=AS_INTNUM;
  531. exit;
  532. end;
  533. end; { end case }
  534. end;
  535. '&' :
  536. begin
  537. c:=current_scanner^.asmgetchar;
  538. actasmtoken:=AS_AND;
  539. end;
  540. '''' : { char }
  541. begin
  542. actasmpattern:='';
  543. repeat
  544. c:=current_scanner^.asmgetchar;
  545. case c of
  546. '\' :
  547. begin
  548. { copy also the next char so \" is parsed correctly }
  549. c:=current_scanner^.asmgetchar;
  550. actasmpattern:=actasmpattern+c;
  551. end;
  552. '''' :
  553. begin
  554. c:=current_scanner^.asmgetchar;
  555. break;
  556. end;
  557. newline:
  558. Message(scan_f_string_exceeds_line);
  559. else
  560. actasmpattern:=actasmpattern+c;
  561. end;
  562. until false;
  563. actasmpattern:=EscapeToPascal(actasmpattern);
  564. actasmtoken:=AS_STRING;
  565. exit;
  566. end;
  567. '"' : { string }
  568. begin
  569. actasmpattern:='';
  570. repeat
  571. c:=current_scanner^.asmgetchar;
  572. case c of
  573. '\' :
  574. begin
  575. { copy also the next char so \" is parsed correctly }
  576. c:=current_scanner^.asmgetchar;
  577. actasmpattern:=actasmpattern+c;
  578. end;
  579. '"' :
  580. begin
  581. c:=current_scanner^.asmgetchar;
  582. break;
  583. end;
  584. newline:
  585. Message(scan_f_string_exceeds_line);
  586. else
  587. actasmpattern:=actasmpattern+c;
  588. end;
  589. until false;
  590. actasmpattern:=EscapeToPascal(actasmpattern);
  591. actasmtoken:=AS_STRING;
  592. exit;
  593. end;
  594. '$' :
  595. begin
  596. actasmtoken:=AS_DOLLAR;
  597. c:=current_scanner^.asmgetchar;
  598. exit;
  599. end;
  600. ',' :
  601. begin
  602. actasmtoken:=AS_COMMA;
  603. c:=current_scanner^.asmgetchar;
  604. exit;
  605. end;
  606. '<' :
  607. begin
  608. actasmtoken:=AS_SHL;
  609. c:=current_scanner^.asmgetchar;
  610. if c = '<' then
  611. c:=current_scanner^.asmgetchar;
  612. exit;
  613. end;
  614. '>' :
  615. begin
  616. actasmtoken:=AS_SHL;
  617. c:=current_scanner^.asmgetchar;
  618. if c = '>' then
  619. c:=current_scanner^.asmgetchar;
  620. exit;
  621. end;
  622. '|' :
  623. begin
  624. actasmtoken:=AS_OR;
  625. c:=current_scanner^.asmgetchar;
  626. exit;
  627. end;
  628. '^' :
  629. begin
  630. actasmtoken:=AS_XOR;
  631. c:=current_scanner^.asmgetchar;
  632. exit;
  633. end;
  634. '!' :
  635. begin
  636. Message(asmr_e_nor_not_supported);
  637. c:=current_scanner^.asmgetchar;
  638. actasmtoken:=AS_NONE;
  639. exit;
  640. end;
  641. '(' :
  642. begin
  643. actasmtoken:=AS_LPAREN;
  644. c:=current_scanner^.asmgetchar;
  645. exit;
  646. end;
  647. ')' :
  648. begin
  649. actasmtoken:=AS_RPAREN;
  650. c:=current_scanner^.asmgetchar;
  651. exit;
  652. end;
  653. ':' :
  654. begin
  655. actasmtoken:=AS_COLON;
  656. c:=current_scanner^.asmgetchar;
  657. exit;
  658. end;
  659. '+' :
  660. begin
  661. actasmtoken:=AS_PLUS;
  662. c:=current_scanner^.asmgetchar;
  663. exit;
  664. end;
  665. '-' :
  666. begin
  667. actasmtoken:=AS_MINUS;
  668. c:=current_scanner^.asmgetchar;
  669. exit;
  670. end;
  671. '*' :
  672. begin
  673. actasmtoken:=AS_STAR;
  674. c:=current_scanner^.asmgetchar;
  675. exit;
  676. end;
  677. '/' :
  678. begin
  679. c:=current_scanner^.asmgetchar;
  680. actasmtoken:=AS_SLASH;
  681. exit;
  682. end;
  683. '{',#13,newline,';' :
  684. begin
  685. { the comment is read by asmgetchar }
  686. c:=current_scanner^.asmgetchar;
  687. firsttoken:=TRUE;
  688. actasmtoken:=AS_SEPARATOR;
  689. exit;
  690. end;
  691. else
  692. current_scanner^.illegal_char(c);
  693. end;
  694. end;
  695. end;
  696. function consume(t : tasmtoken):boolean;
  697. begin
  698. Consume:=true;
  699. if t<>actasmtoken then
  700. begin
  701. Message2(scan_f_syn_expected,token2str[t],token2str[actasmtoken]);
  702. Consume:=false;
  703. end;
  704. repeat
  705. gettoken;
  706. until actasmtoken<>AS_NONE;
  707. end;
  708. procedure RecoverConsume(allowcomma:boolean);
  709. begin
  710. While not (actasmtoken in [AS_SEPARATOR,AS_END]) do
  711. begin
  712. if allowcomma and (actasmtoken=AS_COMMA) then
  713. break;
  714. Consume(actasmtoken);
  715. end;
  716. end;
  717. {*****************************************************************************
  718. Parsing Helpers
  719. *****************************************************************************}
  720. Procedure BuildRecordOffsetSize(const expr: string;var offset:longint;var size:longint);
  721. { Description: This routine builds up a record offset after a AS_DOT }
  722. { token is encountered. }
  723. { On entry actasmtoken should be equal to AS_DOT }
  724. var
  725. s : string;
  726. Begin
  727. offset:=0;
  728. size:=0;
  729. s:=expr;
  730. while (actasmtoken=AS_DOT) do
  731. begin
  732. Consume(AS_DOT);
  733. if actasmtoken=AS_ID then
  734. s:=s+'.'+actasmpattern;
  735. if not Consume(AS_ID) then
  736. begin
  737. RecoverConsume(true);
  738. break;
  739. end;
  740. end;
  741. if not GetRecordOffsetSize(s,offset,size) then
  742. Message(asmr_e_building_record_offset);
  743. end;
  744. Procedure BuildConstSymbolExpression(allowref,betweenbracket,needofs:boolean;var value:longint;var asmsym:string);
  745. var
  746. hs,tempstr,expr : string;
  747. parenlevel,l,k : longint;
  748. errorflag : boolean;
  749. prevtok : tasmtoken;
  750. sym : psym;
  751. hl : PAsmLabel;
  752. Begin
  753. asmsym:='';
  754. value:=0;
  755. errorflag:=FALSE;
  756. tempstr:='';
  757. expr:='';
  758. parenlevel:=0;
  759. Repeat
  760. Case actasmtoken of
  761. AS_LPAREN:
  762. Begin
  763. { Exit if ref? }
  764. if allowref and (prevasmtoken in [AS_INTNUM,AS_ID]) then
  765. break;
  766. Consume(AS_LPAREN);
  767. expr:=expr + '(';
  768. inc(parenlevel);
  769. end;
  770. AS_RPAREN:
  771. Begin
  772. { end of ref ? }
  773. if (parenlevel=0) and betweenbracket then
  774. break;
  775. Consume(AS_RPAREN);
  776. expr:=expr + ')';
  777. dec(parenlevel);
  778. end;
  779. AS_SHL:
  780. Begin
  781. Consume(AS_SHL);
  782. expr:=expr + '<';
  783. end;
  784. AS_SHR:
  785. Begin
  786. Consume(AS_SHR);
  787. expr:=expr + '>';
  788. end;
  789. AS_SLASH:
  790. Begin
  791. Consume(AS_SLASH);
  792. expr:=expr + '/';
  793. end;
  794. AS_MOD:
  795. Begin
  796. Consume(AS_MOD);
  797. expr:=expr + '%';
  798. end;
  799. AS_STAR:
  800. Begin
  801. Consume(AS_STAR);
  802. expr:=expr + '*';
  803. end;
  804. AS_PLUS:
  805. Begin
  806. Consume(AS_PLUS);
  807. expr:=expr + '+';
  808. end;
  809. AS_MINUS:
  810. Begin
  811. Consume(AS_MINUS);
  812. expr:=expr + '-';
  813. end;
  814. AS_AND:
  815. Begin
  816. Consume(AS_AND);
  817. expr:=expr + '&';
  818. end;
  819. AS_NOT:
  820. Begin
  821. Consume(AS_NOT);
  822. expr:=expr + '~';
  823. end;
  824. AS_XOR:
  825. Begin
  826. Consume(AS_XOR);
  827. expr:=expr + '^';
  828. end;
  829. AS_OR:
  830. Begin
  831. Consume(AS_OR);
  832. expr:=expr + '|';
  833. end;
  834. AS_INTNUM:
  835. Begin
  836. expr:=expr + actasmpattern;
  837. Consume(AS_INTNUM);
  838. end;
  839. AS_DOLLAR:
  840. begin
  841. Consume(AS_DOLLAR);
  842. if actasmtoken<>AS_ID then
  843. Message(asmr_e_dollar_without_identifier);
  844. end;
  845. AS_STRING:
  846. Begin
  847. l:=0;
  848. case Length(actasmpattern) of
  849. 1 :
  850. l:=ord(actasmpattern[1]);
  851. 2 :
  852. l:=ord(actasmpattern[2]) + ord(actasmpattern[1]) shl 8;
  853. 3 :
  854. l:=ord(actasmpattern[3]) +
  855. Ord(actasmpattern[2]) shl 8 + ord(actasmpattern[1]) shl 16;
  856. 4 :
  857. l:=ord(actasmpattern[4]) + ord(actasmpattern[3]) shl 8 +
  858. Ord(actasmpattern[2]) shl 16 + ord(actasmpattern[1]) shl 24;
  859. else
  860. Message1(asmr_e_invalid_string_as_opcode_operand,actasmpattern);
  861. end;
  862. str(l, tempstr);
  863. expr:=expr + tempstr;
  864. Consume(AS_STRING);
  865. end;
  866. AS_TYPE:
  867. begin
  868. l:=0;
  869. Consume(AS_TYPE);
  870. if actasmtoken<>AS_ID then
  871. Message(asmr_e_type_without_identifier)
  872. else
  873. begin
  874. tempstr:=actasmpattern;
  875. Consume(AS_ID);
  876. if actasmtoken=AS_DOT then
  877. BuildRecordOffsetSize(tempstr,k,l)
  878. else
  879. begin
  880. getsym(tempstr,false);
  881. if assigned(srsym) then
  882. begin
  883. case srsym^.typ of
  884. varsym :
  885. l:=pvarsym(srsym)^.getsize;
  886. typedconstsym :
  887. l:=ptypedconstsym(srsym)^.getsize;
  888. typesym :
  889. l:=ptypesym(srsym)^.restype.def^.size;
  890. else
  891. Message(asmr_e_wrong_sym_type);
  892. end;
  893. end
  894. else
  895. Message1(sym_e_unknown_id,tempstr);
  896. end;
  897. end;
  898. str(l, tempstr);
  899. expr:=expr + tempstr;
  900. end;
  901. AS_ID:
  902. Begin
  903. hs:='';
  904. tempstr:=actasmpattern;
  905. prevtok:=prevasmtoken;
  906. consume(AS_ID);
  907. if SearchIConstant(tempstr,l) then
  908. begin
  909. str(l, tempstr);
  910. expr:=expr + tempstr;
  911. end
  912. else
  913. begin
  914. if is_locallabel(tempstr) then
  915. begin
  916. CreateLocalLabel(tempstr,hl,false);
  917. hs:=hl^.name
  918. end
  919. else
  920. if SearchLabel(tempstr,hl,false) then
  921. hs:=hl^.name
  922. else
  923. begin
  924. getsym(tempstr,false);
  925. sym:=srsym;
  926. if assigned(sym) then
  927. begin
  928. case srsym^.typ of
  929. varsym :
  930. begin
  931. if sym^.owner^.symtabletype in [localsymtable,parasymtable] then
  932. Message(asmr_e_no_local_or_para_allowed);
  933. hs:=pvarsym(srsym)^.mangledname;
  934. end;
  935. typedconstsym :
  936. hs:=ptypedconstsym(srsym)^.mangledname;
  937. procsym :
  938. hs:=pprocsym(srsym)^.mangledname;
  939. typesym :
  940. begin
  941. if not(ptypesym(srsym)^.restype.def^.deftype in [recorddef,objectdef]) then
  942. Message(asmr_e_wrong_sym_type);
  943. end;
  944. else
  945. Message(asmr_e_wrong_sym_type);
  946. end;
  947. end
  948. else
  949. Message1(sym_e_unknown_id,tempstr);
  950. end;
  951. { symbol found? }
  952. if hs<>'' then
  953. begin
  954. if needofs and (prevtok<>AS_DOLLAR) then
  955. Message(asmr_e_need_dollar);
  956. if asmsym='' then
  957. asmsym:=hs
  958. else
  959. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  960. if (expr='') or (expr[length(expr)]='+') then
  961. begin
  962. { don't remove the + if there could be a record field }
  963. if actasmtoken<>AS_DOT then
  964. delete(expr,length(expr),1);
  965. end
  966. else
  967. Message(asmr_e_only_add_relocatable_symbol);
  968. end;
  969. if actasmtoken=AS_DOT then
  970. begin
  971. BuildRecordOffsetSize(tempstr,l,k);
  972. str(l, tempstr);
  973. expr:=expr + tempstr;
  974. end
  975. else
  976. begin
  977. if (expr='') or (expr[length(expr)] in ['+','-','/','*']) then
  978. delete(expr,length(expr),1);
  979. end;
  980. end;
  981. { check if there are wrong operator used like / or mod etc. }
  982. if (hs<>'') and not(actasmtoken in [AS_MINUS,AS_PLUS,AS_COMMA,AS_SEPARATOR,AS_LPAREN,AS_END]) then
  983. Message(asmr_e_only_add_relocatable_symbol);
  984. end;
  985. AS_END,
  986. AS_SEPARATOR,
  987. AS_COMMA:
  988. Begin
  989. break;
  990. end;
  991. else
  992. Begin
  993. { write error only once. }
  994. if not errorflag then
  995. Message(asmr_e_invalid_constant_expression);
  996. { consume tokens until we find COMMA or SEPARATOR }
  997. Consume(actasmtoken);
  998. errorflag:=TRUE;
  999. end;
  1000. end;
  1001. Until false;
  1002. { calculate expression }
  1003. if not ErrorFlag then
  1004. value:=CalculateExpression(expr)
  1005. else
  1006. value:=0;
  1007. end;
  1008. Function BuildConstExpression(allowref,betweenbracket:boolean): longint;
  1009. var
  1010. l : longint;
  1011. hs : string;
  1012. begin
  1013. BuildConstSymbolExpression(allowref,betweenbracket,false,l,hs);
  1014. if hs<>'' then
  1015. Message(asmr_e_relocatable_symbol_not_allowed);
  1016. BuildConstExpression:=l;
  1017. end;
  1018. {****************************************************************************
  1019. T386ATTOperand
  1020. ****************************************************************************}
  1021. type
  1022. P386ATTOperand=^T386ATTOperand;
  1023. T386ATTOperand=object(T386Operand)
  1024. Procedure BuildOperand;virtual;
  1025. private
  1026. Procedure BuildReference;
  1027. Procedure BuildConstant;
  1028. end;
  1029. Procedure T386ATTOperand.BuildReference;
  1030. procedure Consume_RParen;
  1031. begin
  1032. if actasmtoken <> AS_RPAREN then
  1033. Begin
  1034. Message(asmr_e_invalid_reference_syntax);
  1035. RecoverConsume(true);
  1036. end
  1037. else
  1038. begin
  1039. Consume(AS_RPAREN);
  1040. if not (actasmtoken in [AS_COMMA,AS_SEPARATOR,AS_END]) then
  1041. Begin
  1042. Message(asmr_e_invalid_reference_syntax);
  1043. RecoverConsume(true);
  1044. end;
  1045. end;
  1046. end;
  1047. procedure Consume_Scale;
  1048. var
  1049. l : longint;
  1050. begin
  1051. { we have to process the scaling }
  1052. l:=BuildConstExpression(false,true);
  1053. if ((l = 2) or (l = 4) or (l = 8) or (l = 1)) then
  1054. opr.ref.scalefactor:=l
  1055. else
  1056. Begin
  1057. Message(asmr_e_wrong_scale_factor);
  1058. opr.ref.scalefactor:=0;
  1059. end;
  1060. end;
  1061. Begin
  1062. Consume(AS_LPAREN);
  1063. Case actasmtoken of
  1064. AS_INTNUM,
  1065. AS_MINUS,
  1066. AS_PLUS: { absolute offset, such as fs:(0x046c) }
  1067. Begin
  1068. { offset(offset) is invalid }
  1069. If opr.Ref.Offset <> 0 Then
  1070. Begin
  1071. Message(asmr_e_invalid_reference_syntax);
  1072. RecoverConsume(true);
  1073. End
  1074. Else
  1075. Begin
  1076. opr.Ref.Offset:=BuildConstExpression(false,true);
  1077. Consume_RParen;
  1078. end;
  1079. exit;
  1080. End;
  1081. AS_REGISTER: { (reg ... }
  1082. Begin
  1083. { Check if there is already a base (mostly ebp,esp) than this is
  1084. not allowed,becuase it will give crashing code }
  1085. if opr.ref.base<>R_NO then
  1086. Message(asmr_e_cannot_index_relative_var);
  1087. opr.ref.base:=actasmregister;
  1088. Consume(AS_REGISTER);
  1089. { can either be a register or a right parenthesis }
  1090. { (reg) }
  1091. if actasmtoken=AS_RPAREN then
  1092. Begin
  1093. Consume_RParen;
  1094. exit;
  1095. end;
  1096. { (reg,reg .. }
  1097. Consume(AS_COMMA);
  1098. if actasmtoken=AS_REGISTER then
  1099. Begin
  1100. opr.ref.index:=actasmregister;
  1101. Consume(AS_REGISTER);
  1102. { check for scaling ... }
  1103. case actasmtoken of
  1104. AS_RPAREN:
  1105. Begin
  1106. Consume_RParen;
  1107. exit;
  1108. end;
  1109. AS_COMMA:
  1110. Begin
  1111. Consume(AS_COMMA);
  1112. Consume_Scale;
  1113. Consume_RParen;
  1114. end;
  1115. else
  1116. Begin
  1117. Message(asmr_e_invalid_reference_syntax);
  1118. RecoverConsume(false);
  1119. end;
  1120. end; { end case }
  1121. end
  1122. else
  1123. Begin
  1124. Message(asmr_e_invalid_reference_syntax);
  1125. RecoverConsume(false);
  1126. end;
  1127. end; {end case }
  1128. AS_COMMA: { (, ... can either be scaling, or index }
  1129. Begin
  1130. Consume(AS_COMMA);
  1131. { Index }
  1132. if (actasmtoken=AS_REGISTER) then
  1133. Begin
  1134. opr.ref.index:=actasmregister;
  1135. Consume(AS_REGISTER);
  1136. { check for scaling ... }
  1137. case actasmtoken of
  1138. AS_RPAREN:
  1139. Begin
  1140. Consume_RParen;
  1141. exit;
  1142. end;
  1143. AS_COMMA:
  1144. Begin
  1145. Consume(AS_COMMA);
  1146. Consume_Scale;
  1147. Consume_RParen;
  1148. end;
  1149. else
  1150. Begin
  1151. Message(asmr_e_invalid_reference_syntax);
  1152. RecoverConsume(false);
  1153. end;
  1154. end; {end case }
  1155. end
  1156. { Scaling }
  1157. else
  1158. Begin
  1159. Consume_Scale;
  1160. Consume_RParen;
  1161. exit;
  1162. end;
  1163. end;
  1164. else
  1165. Begin
  1166. Message(asmr_e_invalid_reference_syntax);
  1167. RecoverConsume(false);
  1168. end;
  1169. end;
  1170. end;
  1171. Procedure T386ATTOperand.BuildConstant;
  1172. var
  1173. l : longint;
  1174. tempstr : string;
  1175. begin
  1176. BuildConstSymbolExpression(false,false,true,l,tempstr);
  1177. if tempstr<>'' then
  1178. begin
  1179. opr.typ:=OPR_SYMBOL;
  1180. opr.symofs:=l;
  1181. opr.symbol:=newasmsymbol(tempstr);
  1182. end
  1183. else
  1184. begin
  1185. opr.typ:=OPR_CONSTANT;
  1186. opr.val:=l;
  1187. end;
  1188. end;
  1189. Procedure T386ATTOperand.BuildOperand;
  1190. var
  1191. tempstr,tempstr2,
  1192. expr : string;
  1193. l,k : longint;
  1194. procedure AddLabelOperand(hl:pasmlabel);
  1195. begin
  1196. if not(actasmtoken in [AS_PLUS,AS_MINUS,AS_LPAREN]) and
  1197. is_calljmp(actopcode) then
  1198. begin
  1199. opr.typ:=OPR_SYMBOL;
  1200. opr.symbol:=hl;
  1201. end
  1202. else
  1203. begin
  1204. InitRef;
  1205. opr.ref.symbol:=hl;
  1206. end;
  1207. end;
  1208. procedure MaybeRecordOffset;
  1209. var
  1210. hasdot : boolean;
  1211. l,
  1212. toffset,
  1213. tsize : longint;
  1214. begin
  1215. if not(actasmtoken in [AS_DOT,AS_PLUS,AS_MINUS]) then
  1216. exit;
  1217. l:=0;
  1218. hasdot:=(actasmtoken=AS_DOT);
  1219. if hasdot then
  1220. begin
  1221. if expr<>'' then
  1222. begin
  1223. BuildRecordOffsetSize(expr,toffset,tsize);
  1224. inc(l,toffset);
  1225. SetSize(tsize,true);
  1226. end;
  1227. end;
  1228. if actasmtoken in [AS_PLUS,AS_MINUS] then
  1229. inc(l,BuildConstExpression(true,false));
  1230. if opr.typ=OPR_REFERENCE then
  1231. begin
  1232. if hasdot and (not hastype) and (opr.ref.options=ref_parafixup) then
  1233. Message(asmr_e_cannot_access_field_directly_for_parameters);
  1234. inc(opr.ref.offset,l)
  1235. end
  1236. else
  1237. inc(opr.val,l);
  1238. end;
  1239. function MaybeBuildReference:boolean;
  1240. { Try to create a reference, if not a reference is found then false
  1241. is returned }
  1242. begin
  1243. MaybeBuildReference:=true;
  1244. case actasmtoken of
  1245. AS_INTNUM,
  1246. AS_MINUS,
  1247. AS_PLUS:
  1248. Begin
  1249. opr.ref.offset:=BuildConstExpression(True,False);
  1250. if actasmtoken<>AS_LPAREN then
  1251. Message(asmr_e_invalid_reference_syntax)
  1252. else
  1253. BuildReference;
  1254. end;
  1255. AS_LPAREN:
  1256. BuildReference;
  1257. AS_ID: { only a variable is allowed ... }
  1258. Begin
  1259. tempstr:=actasmpattern;
  1260. Consume(AS_ID);
  1261. { typecasting? }
  1262. if (actasmtoken=AS_LPAREN) and
  1263. SearchType(tempstr) then
  1264. begin
  1265. hastype:=true;
  1266. Consume(AS_LPAREN);
  1267. tempstr2:=actasmpattern;
  1268. Consume(AS_ID);
  1269. Consume(AS_RPAREN);
  1270. if not SetupVar(tempstr2,false) then
  1271. Message1(sym_e_unknown_id,tempstr2);
  1272. end
  1273. else
  1274. if not SetupVar(tempstr,false) then
  1275. Message1(sym_e_unknown_id,tempstr);
  1276. { record.field ? }
  1277. if actasmtoken=AS_DOT then
  1278. begin
  1279. BuildRecordOffsetSize(tempstr,l,k);
  1280. inc(opr.ref.offset,l);
  1281. end;
  1282. case actasmtoken of
  1283. AS_END,
  1284. AS_SEPARATOR,
  1285. AS_COMMA: ;
  1286. AS_LPAREN: BuildReference;
  1287. else
  1288. Begin
  1289. Message(asmr_e_invalid_reference_syntax);
  1290. Consume(actasmtoken);
  1291. end;
  1292. end; {end case }
  1293. end;
  1294. else
  1295. MaybeBuildReference:=false;
  1296. end; { end case }
  1297. end;
  1298. var
  1299. tempreg : tregister;
  1300. hl : PAsmLabel;
  1301. Begin
  1302. expr:='';
  1303. case actasmtoken of
  1304. AS_LPAREN: { Memory reference or constant expression }
  1305. Begin
  1306. InitRef;
  1307. BuildReference;
  1308. end;
  1309. AS_DOLLAR: { Constant expression }
  1310. Begin
  1311. Consume(AS_DOLLAR);
  1312. BuildConstant;
  1313. end;
  1314. AS_INTNUM,
  1315. AS_MINUS,
  1316. AS_PLUS:
  1317. Begin
  1318. { Constant memory offset }
  1319. { This must absolutely be followed by ( }
  1320. InitRef;
  1321. opr.ref.offset:=BuildConstExpression(True,False);
  1322. if actasmtoken<>AS_LPAREN then
  1323. Message(asmr_e_invalid_reference_syntax)
  1324. else
  1325. BuildReference;
  1326. end;
  1327. AS_STAR: { Call from memory address }
  1328. Begin
  1329. Consume(AS_STAR);
  1330. if actasmtoken=AS_REGISTER then
  1331. begin
  1332. opr.typ:=OPR_REGISTER;
  1333. opr.reg:=actasmregister;
  1334. size:=reg_2_opsize[actasmregister];
  1335. Consume(AS_REGISTER);
  1336. end
  1337. else
  1338. begin
  1339. InitRef;
  1340. if not MaybeBuildReference then
  1341. Message(asmr_e_syn_operand);
  1342. end;
  1343. { this is only allowed for call's and jmp's }
  1344. if not is_calljmp(actopcode) then
  1345. Message(asmr_e_syn_operand);
  1346. end;
  1347. AS_ID: { A constant expression, or a Variable ref. }
  1348. Begin
  1349. { Local Label ? }
  1350. if is_locallabel(actasmpattern) then
  1351. begin
  1352. CreateLocalLabel(actasmpattern,hl,false);
  1353. Consume(AS_ID);
  1354. AddLabelOperand(hl);
  1355. end
  1356. else
  1357. { Check for label }
  1358. if SearchLabel(actasmpattern,hl,false) then
  1359. begin
  1360. Consume(AS_ID);
  1361. AddLabelOperand(hl);
  1362. end
  1363. else
  1364. { probably a variable or normal expression }
  1365. { or a procedure (such as in CALL ID) }
  1366. Begin
  1367. { is it a constant ? }
  1368. if SearchIConstant(actasmpattern,l) then
  1369. Begin
  1370. if not (opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  1371. Message(asmr_e_invalid_operand_type);
  1372. BuildConstant;
  1373. end
  1374. else
  1375. begin
  1376. InitRef;
  1377. expr:=actasmpattern;
  1378. Consume(AS_ID);
  1379. { typecasting? }
  1380. if (actasmtoken=AS_LPAREN) and
  1381. SearchType(expr) then
  1382. begin
  1383. hastype:=true;
  1384. Consume(AS_LPAREN);
  1385. tempstr:=actasmpattern;
  1386. Consume(AS_ID);
  1387. Consume(AS_RPAREN);
  1388. if SetupVar(tempstr,false) then
  1389. begin
  1390. MaybeRecordOffset;
  1391. { add a constant expression? }
  1392. if (actasmtoken=AS_PLUS) then
  1393. begin
  1394. l:=BuildConstExpression(true,false);
  1395. if opr.typ=OPR_CONSTANT then
  1396. inc(opr.val,l)
  1397. else
  1398. inc(opr.ref.offset,l);
  1399. end
  1400. end
  1401. else
  1402. Message1(sym_e_unknown_id,tempstr);
  1403. end
  1404. else
  1405. begin
  1406. if SetupVar(expr,false) then
  1407. begin
  1408. MaybeRecordOffset;
  1409. { add a constant expression? }
  1410. if (actasmtoken=AS_PLUS) then
  1411. begin
  1412. l:=BuildConstExpression(true,false);
  1413. if opr.typ=OPR_CONSTANT then
  1414. inc(opr.val,l)
  1415. else
  1416. inc(opr.ref.offset,l);
  1417. end
  1418. end
  1419. else
  1420. Begin
  1421. { look for special symbols ... }
  1422. if expr = '__RESULT' then
  1423. SetUpResult
  1424. else
  1425. if expr = '__SELF' then
  1426. SetupSelf
  1427. else
  1428. if expr = '__OLDEBP' then
  1429. SetupOldEBP
  1430. else
  1431. { check for direct symbolic names }
  1432. { only if compiling the system unit }
  1433. if (cs_compilesystem in aktmoduleswitches) then
  1434. begin
  1435. if not SetupDirectVar(expr) then
  1436. Begin
  1437. { not found, finally ... add it anyways ... }
  1438. Message1(asmr_w_id_supposed_external,expr);
  1439. opr.ref.symbol:=newasmsymbol(expr);
  1440. end;
  1441. end
  1442. else
  1443. Message1(sym_e_unknown_id,expr);
  1444. end;
  1445. end;
  1446. end;
  1447. end;
  1448. { Do we have a indexing reference, then parse it also }
  1449. if actasmtoken=AS_LPAREN then
  1450. begin
  1451. if (opr.typ=OPR_CONSTANT) then
  1452. begin
  1453. l:=opr.val;
  1454. opr.typ:=OPR_REFERENCE;
  1455. reset_reference(opr.Ref);
  1456. opr.Ref.Offset:=l;
  1457. end;
  1458. BuildReference;
  1459. end;
  1460. end;
  1461. AS_REGISTER: { Register, a variable reference or a constant reference }
  1462. Begin
  1463. { save the type of register used. }
  1464. tempreg:=actasmregister;
  1465. Consume(AS_REGISTER);
  1466. if actasmtoken = AS_COLON then
  1467. Begin
  1468. Consume(AS_COLON);
  1469. InitRef;
  1470. opr.ref.segment:=tempreg;
  1471. { This must absolutely be followed by a reference }
  1472. if not MaybeBuildReference then
  1473. Begin
  1474. Message(asmr_e_invalid_seg_override);
  1475. Consume(actasmtoken);
  1476. end;
  1477. end
  1478. { Simple register }
  1479. else if (actasmtoken in [AS_END,AS_SEPARATOR,AS_COMMA]) then
  1480. Begin
  1481. if not (opr.typ in [OPR_NONE,OPR_REGISTER]) then
  1482. Message(asmr_e_invalid_operand_type);
  1483. opr.typ:=OPR_REGISTER;
  1484. opr.reg:=tempreg;
  1485. size:=reg_2_opsize[tempreg];
  1486. end
  1487. else
  1488. Message(asmr_e_syn_operand);
  1489. end;
  1490. AS_END,
  1491. AS_SEPARATOR,
  1492. AS_COMMA: ;
  1493. else
  1494. Begin
  1495. Message(asmr_e_syn_operand);
  1496. Consume(actasmtoken);
  1497. end;
  1498. end; { end case }
  1499. end;
  1500. {*****************************************************************************
  1501. T386ATTInstruction
  1502. *****************************************************************************}
  1503. type
  1504. P386AttInstruction=^T386AttInstruction;
  1505. T386AttInstruction=object(T386Instruction)
  1506. procedure InitOperands;virtual;
  1507. procedure BuildOpcode;virtual;
  1508. end;
  1509. procedure T386AttInstruction.InitOperands;
  1510. var
  1511. i : longint;
  1512. begin
  1513. for i:=1to 3 do
  1514. Operands[i]:=new(P386AttOperand,Init);
  1515. end;
  1516. Procedure T386AttInstruction.BuildOpCode;
  1517. var
  1518. operandnum : longint;
  1519. PrefixOp,OverrideOp: tasmop;
  1520. Begin
  1521. PrefixOp:=A_None;
  1522. OverrideOp:=A_None;
  1523. { prefix seg opcode / prefix opcode }
  1524. repeat
  1525. if is_prefix(actopcode) then
  1526. begin
  1527. PrefixOp:=ActOpcode;
  1528. opcode:=ActOpcode;
  1529. condition:=ActCondition;
  1530. opsize:=ActOpsize;
  1531. ConcatInstruction(curlist);
  1532. Consume(AS_OPCODE);
  1533. end
  1534. else
  1535. if is_override(actopcode) then
  1536. begin
  1537. OverrideOp:=ActOpcode;
  1538. opcode:=ActOpcode;
  1539. condition:=ActCondition;
  1540. opsize:=ActOpsize;
  1541. ConcatInstruction(curlist);
  1542. Consume(AS_OPCODE);
  1543. end
  1544. else
  1545. break;
  1546. { allow for newline as in gas styled syntax }
  1547. while actasmtoken=AS_SEPARATOR do
  1548. Consume(AS_SEPARATOR);
  1549. until (actasmtoken<>AS_OPCODE);
  1550. { opcode }
  1551. if (actasmtoken <> AS_OPCODE) then
  1552. Begin
  1553. Message(asmr_e_invalid_or_missing_opcode);
  1554. RecoverConsume(true);
  1555. exit;
  1556. end;
  1557. { Fill the instr object with the current state }
  1558. Opcode:=ActOpcode;
  1559. condition:=ActCondition;
  1560. opsize:=ActOpsize;
  1561. { Valid combination of prefix/override and instruction ? }
  1562. if (prefixop<>A_NONE) and (NOT CheckPrefix(PrefixOp,actopcode)) then
  1563. Message1(asmr_e_invalid_prefix_and_opcode,actasmpattern);
  1564. if (overrideop<>A_NONE) and (NOT CheckOverride(OverrideOp,ActOpcode)) then
  1565. Message1(asmr_e_invalid_override_and_opcode,actasmpattern);
  1566. { We are reading operands, so opcode will be an AS_ID }
  1567. operandnum:=1;
  1568. Consume(AS_OPCODE);
  1569. { Zero operand opcode ? }
  1570. if actasmtoken in [AS_SEPARATOR,AS_END] then
  1571. begin
  1572. operandnum:=0;
  1573. exit;
  1574. end;
  1575. { Read the operands }
  1576. repeat
  1577. case actasmtoken of
  1578. AS_COMMA: { Operand delimiter }
  1579. Begin
  1580. if operandnum > MaxOperands then
  1581. Message(asmr_e_too_many_operands)
  1582. else
  1583. Inc(operandnum);
  1584. Consume(AS_COMMA);
  1585. end;
  1586. AS_SEPARATOR,
  1587. AS_END : { End of asm operands for this opcode }
  1588. begin
  1589. break;
  1590. end;
  1591. else
  1592. Operands[operandnum]^.BuildOperand;
  1593. end; { end case }
  1594. until false;
  1595. Ops:=operandnum;
  1596. end;
  1597. Procedure BuildConstant(maxvalue: longint);
  1598. var
  1599. asmsym,
  1600. expr: string;
  1601. value : longint;
  1602. Begin
  1603. Repeat
  1604. Case actasmtoken of
  1605. AS_STRING:
  1606. Begin
  1607. expr:=actasmpattern;
  1608. if length(expr) > 1 then
  1609. Message(asmr_e_string_not_allowed_as_const);
  1610. Consume(AS_STRING);
  1611. Case actasmtoken of
  1612. AS_COMMA: Consume(AS_COMMA);
  1613. AS_END,
  1614. AS_SEPARATOR: ;
  1615. else
  1616. Message(asmr_e_invalid_string_expression);
  1617. end; { end case }
  1618. ConcatString(curlist,expr);
  1619. end;
  1620. AS_INTNUM,
  1621. AS_PLUS,
  1622. AS_MINUS,
  1623. AS_LPAREN,
  1624. AS_NOT,
  1625. AS_ID :
  1626. Begin
  1627. BuildConstSymbolExpression(false,false,false,value,asmsym);
  1628. if asmsym<>'' then
  1629. begin
  1630. if maxvalue<>longint($ffffffff) then
  1631. Message(asmr_w_32bit_const_for_address);
  1632. ConcatConstSymbol(curlist,asmsym,value)
  1633. end
  1634. else
  1635. ConcatConstant(curlist,value,maxvalue);
  1636. end;
  1637. AS_COMMA:
  1638. Consume(AS_COMMA);
  1639. AS_END,
  1640. AS_SEPARATOR:
  1641. break;
  1642. else
  1643. begin
  1644. Message(asmr_e_syn_constant);
  1645. RecoverConsume(false);
  1646. end
  1647. end; { end case }
  1648. Until false;
  1649. end;
  1650. Procedure BuildRealConstant(typ : tfloattype);
  1651. var
  1652. expr : string;
  1653. r : bestreal;
  1654. code : integer;
  1655. negativ : boolean;
  1656. errorflag: boolean;
  1657. Begin
  1658. errorflag:=FALSE;
  1659. Repeat
  1660. negativ:=false;
  1661. expr:='';
  1662. if actasmtoken=AS_PLUS then
  1663. Consume(AS_PLUS)
  1664. else
  1665. if actasmtoken=AS_MINUS then
  1666. begin
  1667. negativ:=true;
  1668. consume(AS_MINUS);
  1669. end;
  1670. Case actasmtoken of
  1671. AS_INTNUM:
  1672. Begin
  1673. expr:=actasmpattern;
  1674. Consume(AS_INTNUM);
  1675. if negativ then
  1676. expr:='-'+expr;
  1677. val(expr,r,code);
  1678. if code<>0 then
  1679. Begin
  1680. r:=0;
  1681. Message(asmr_e_invalid_float_expr);
  1682. End;
  1683. ConcatRealConstant(curlist,r,typ);
  1684. end;
  1685. AS_REALNUM:
  1686. Begin
  1687. expr:=actasmpattern;
  1688. Consume(AS_REALNUM);
  1689. { in ATT syntax you have 0d in front of the real }
  1690. { should this be forced ? yes i think so, as to }
  1691. { conform to gas as much as possible. }
  1692. if (expr[1]='0') and (upper(expr[2])='D') then
  1693. Delete(expr,1,2);
  1694. if negativ then
  1695. expr:='-'+expr;
  1696. val(expr,r,code);
  1697. if code<>0 then
  1698. Begin
  1699. r:=0;
  1700. Message(asmr_e_invalid_float_expr);
  1701. End;
  1702. ConcatRealConstant(curlist,r,typ);
  1703. end;
  1704. AS_COMMA:
  1705. begin
  1706. Consume(AS_COMMA);
  1707. end;
  1708. AS_END,
  1709. AS_SEPARATOR:
  1710. begin
  1711. break;
  1712. end;
  1713. else
  1714. Begin
  1715. Consume(actasmtoken);
  1716. if not errorflag then
  1717. Message(asmr_e_invalid_float_expr);
  1718. errorflag:=TRUE;
  1719. end;
  1720. end;
  1721. Until false;
  1722. end;
  1723. Procedure BuildStringConstant(asciiz: boolean);
  1724. var
  1725. expr: string;
  1726. errorflag : boolean;
  1727. Begin
  1728. errorflag:=FALSE;
  1729. Repeat
  1730. Case actasmtoken of
  1731. AS_STRING:
  1732. Begin
  1733. expr:=actasmpattern;
  1734. if asciiz then
  1735. expr:=expr+#0;
  1736. ConcatPasString(curlist,expr);
  1737. Consume(AS_STRING);
  1738. end;
  1739. AS_COMMA:
  1740. begin
  1741. Consume(AS_COMMA);
  1742. end;
  1743. AS_END,
  1744. AS_SEPARATOR:
  1745. begin
  1746. break;
  1747. end;
  1748. else
  1749. Begin
  1750. Consume(actasmtoken);
  1751. if not errorflag then
  1752. Message(asmr_e_invalid_string_expression);
  1753. errorflag:=TRUE;
  1754. end;
  1755. end;
  1756. Until false;
  1757. end;
  1758. Function Assemble: tnode;
  1759. Var
  1760. hl : PAsmLabel;
  1761. commname : string;
  1762. lastsec : tsection;
  1763. l1,l2 : longint;
  1764. instr : T386ATTInstruction;
  1765. Begin
  1766. Message1(asmr_d_start_reading,'AT&T');
  1767. firsttoken:=TRUE;
  1768. if assigned(procinfo^.returntype.def) and
  1769. (is_fpu(procinfo^.returntype.def) or
  1770. ret_in_acc(procinfo^.returntype.def)) then
  1771. procinfo^.funcret_state:=vs_assigned;
  1772. { sets up all opcode and register tables in uppercase }
  1773. if not _asmsorted then
  1774. Begin
  1775. SetupTables;
  1776. _asmsorted:=TRUE;
  1777. end;
  1778. curlist:=new(paasmoutput,init);
  1779. lastsec:=sec_code;
  1780. { setup label linked list }
  1781. new(LocalLabelList,Init);
  1782. { start tokenizer }
  1783. c:=current_scanner^.asmgetchar;
  1784. gettoken;
  1785. { main loop }
  1786. repeat
  1787. case actasmtoken of
  1788. AS_LLABEL:
  1789. Begin
  1790. if CreateLocalLabel(actasmpattern,hl,true) then
  1791. ConcatLabel(curlist,hl);
  1792. Consume(AS_LLABEL);
  1793. end;
  1794. AS_LABEL:
  1795. Begin
  1796. if SearchLabel(upper(actasmpattern),hl,true) then
  1797. ConcatLabel(curlist,hl)
  1798. else
  1799. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  1800. Consume(AS_LABEL);
  1801. end;
  1802. AS_DW:
  1803. Begin
  1804. Consume(AS_DW);
  1805. BuildConstant($ffff);
  1806. end;
  1807. AS_DATA:
  1808. Begin
  1809. curlist^.Concat(new(pai_section,init(sec_data)));
  1810. lastsec:=sec_data;
  1811. Consume(AS_DATA);
  1812. end;
  1813. AS_TEXT:
  1814. Begin
  1815. curlist^.Concat(new(pai_section,init(sec_code)));
  1816. lastsec:=sec_code;
  1817. Consume(AS_TEXT);
  1818. end;
  1819. AS_DB:
  1820. Begin
  1821. Consume(AS_DB);
  1822. BuildConstant($ff);
  1823. end;
  1824. AS_DD:
  1825. Begin
  1826. Consume(AS_DD);
  1827. BuildConstant($ffffffff);
  1828. end;
  1829. AS_DQ:
  1830. Begin
  1831. Consume(AS_DQ);
  1832. BuildRealConstant(s64comp);
  1833. end;
  1834. AS_SINGLE:
  1835. Begin
  1836. Consume(AS_SINGLE);
  1837. BuildRealConstant(s32real);
  1838. end;
  1839. AS_DOUBLE:
  1840. Begin
  1841. Consume(AS_DOUBLE);
  1842. BuildRealConstant(s64real);
  1843. end;
  1844. AS_EXTENDED:
  1845. Begin
  1846. Consume(AS_EXTENDED);
  1847. BuildRealConstant(s80real);
  1848. end;
  1849. AS_GLOBAL:
  1850. Begin
  1851. Consume(AS_GLOBAL);
  1852. if actasmtoken=AS_ID then
  1853. ConcatPublic(curlist,actasmpattern);
  1854. Consume(AS_ID);
  1855. if actasmtoken<>AS_SEPARATOR then
  1856. Consume(AS_SEPARATOR);
  1857. end;
  1858. AS_ALIGN:
  1859. Begin
  1860. Consume(AS_ALIGN);
  1861. l1:=BuildConstExpression(false,false);
  1862. if (target_info.target in [target_i386_GO32V1,target_i386_GO32V2]) then
  1863. begin
  1864. l2:=1;
  1865. if (l1>=0) and (l1<=16) then
  1866. while (l1>0) do
  1867. begin
  1868. l2:=2*l2;
  1869. dec(l1);
  1870. end;
  1871. l1:=l2;
  1872. end;
  1873. ConcatAlign(curlist,l1);
  1874. Message(asmr_n_align_is_target_specific);
  1875. if actasmtoken<>AS_SEPARATOR then
  1876. Consume(AS_SEPARATOR);
  1877. end;
  1878. AS_BALIGN:
  1879. Begin
  1880. Consume(AS_BALIGN);
  1881. ConcatAlign(curlist,BuildConstExpression(false,false));
  1882. if actasmtoken<>AS_SEPARATOR then
  1883. Consume(AS_SEPARATOR);
  1884. end;
  1885. AS_P2ALIGN:
  1886. Begin
  1887. Consume(AS_P2ALIGN);
  1888. l1:=BuildConstExpression(false,false);
  1889. l2:=1;
  1890. if (l1>=0) and (l1<=16) then
  1891. while (l1>0) do
  1892. begin
  1893. l2:=2*l2;
  1894. dec(l1);
  1895. end;
  1896. l1:=l2;
  1897. ConcatAlign(curlist,l1);
  1898. if actasmtoken<>AS_SEPARATOR then
  1899. Consume(AS_SEPARATOR);
  1900. end;
  1901. AS_ASCIIZ:
  1902. Begin
  1903. Consume(AS_ASCIIZ);
  1904. BuildStringConstant(TRUE);
  1905. end;
  1906. AS_ASCII:
  1907. Begin
  1908. Consume(AS_ASCII);
  1909. BuildStringConstant(FALSE);
  1910. end;
  1911. AS_LCOMM:
  1912. Begin
  1913. Consume(AS_LCOMM);
  1914. commname:=actasmpattern;
  1915. Consume(AS_ID);
  1916. Consume(AS_COMMA);
  1917. ConcatLocalBss(commname,BuildConstExpression(false,false));
  1918. if actasmtoken<>AS_SEPARATOR then
  1919. Consume(AS_SEPARATOR);
  1920. end;
  1921. AS_COMM:
  1922. Begin
  1923. Consume(AS_COMM);
  1924. commname:=actasmpattern;
  1925. Consume(AS_ID);
  1926. Consume(AS_COMMA);
  1927. ConcatGlobalBss(commname,BuildConstExpression(false,false));
  1928. if actasmtoken<>AS_SEPARATOR then
  1929. Consume(AS_SEPARATOR);
  1930. end;
  1931. AS_OPCODE:
  1932. Begin
  1933. instr.init;
  1934. instr.BuildOpcode;
  1935. instr.AddReferenceSizes;
  1936. instr.SetInstructionOpsize;
  1937. instr.CheckOperandSizes;
  1938. instr.ConcatInstruction(curlist);
  1939. instr.done;
  1940. end;
  1941. AS_SEPARATOR:
  1942. Begin
  1943. Consume(AS_SEPARATOR);
  1944. end;
  1945. AS_END:
  1946. begin
  1947. break; { end assembly block }
  1948. end;
  1949. else
  1950. Begin
  1951. Message(asmr_e_syntax_error);
  1952. RecoverConsume(false);
  1953. end;
  1954. end;
  1955. until false;
  1956. { Check LocalLabelList }
  1957. LocalLabelList^.CheckEmitted;
  1958. dispose(LocalLabelList,Done);
  1959. { are we back in the code section? }
  1960. if lastsec<>sec_code then
  1961. begin
  1962. Message(asmr_w_assembler_code_not_returned_to_text);
  1963. curlist^.Concat(new(pai_section,init(sec_code)));
  1964. end;
  1965. { Return the list in an asmnode }
  1966. assemble:=casmnode.create(curlist);
  1967. Message1(asmr_d_finish_reading,'AT&T');
  1968. end;
  1969. {*****************************************************************************
  1970. Initialize
  1971. *****************************************************************************}
  1972. var
  1973. old_exit : pointer;
  1974. procedure ra386att_exit;
  1975. begin
  1976. exitproc:=old_exit;
  1977. if assigned(iasmops) then
  1978. dispose(iasmops,done);
  1979. if assigned(iasmregs) then
  1980. dispose(iasmregs);
  1981. end;
  1982. begin
  1983. old_exit:=exitproc;
  1984. exitproc:=@ra386att_exit;
  1985. end.
  1986. {
  1987. $Log$
  1988. Revision 1.1 2000-10-15 09:47:43 peter
  1989. * moved to i386/
  1990. Revision 1.6 2000/10/14 10:14:52 peter
  1991. * moehrendorf oct 2000 rewrite
  1992. Revision 1.5 2000/09/24 21:19:51 peter
  1993. * delphi compile fixes
  1994. Revision 1.4 2000/09/24 15:06:26 peter
  1995. * use defines.inc
  1996. Revision 1.3 2000/08/27 16:11:52 peter
  1997. * moved some util functions from globals,cobjects to cutils
  1998. * splitted files into finput,fmodule
  1999. Revision 1.2 2000/07/13 11:32:48 michael
  2000. + removed logs
  2001. }