ra386att.pas 60 KB

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