comparch.tex 180 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685
  1. \documentclass [a4paper,12pt]{article}
  2. \usepackage {graphicx}
  3. \usepackage {intfpc}
  4. \usepackage {longtable}
  5. %\usepackage {float}
  6. \usepackage{listings}
  7. \lstset{language=Delphi}
  8. \lstset{basicstyle=\sffamily\small}
  9. \lstset{commentstyle=\itshape}
  10. \lstset{keywordstyle=\bfseries}
  11. \lstset{frame=tb}
  12. % eats mem for longtable, but speeds up. Set to 10 for minimal mem req.
  13. \setcounter{LTchunksize}{200}
  14. % right aligned longtables
  15. \setlength\LTleft{0pt}
  16. \setlength\LTright\fill
  17. %\restylefloat{table}
  18. %\restylefloat{longtable}
  19. %\squeezetable
  20. \setcounter{totalnumber}{10}
  21. % This comes from the MDWTOOLS package and should discourage floating.
  22. \def\textfraction{0.1}
  23. \def\topfraction{0.9}
  24. \def\bottomfraction{0.9}
  25. \def\floatpagefraction{0.7}
  26. \def\fps@figure{htbp}
  27. \def\fpc@longtable{h}
  28. \title{FREE PASCAL}
  29. \title{Free Pascal 1.0.x Internal documentation\\version 1.0}
  30. \author{Carl Eric Cod\`{e}re}
  31. \makeindex
  32. \begin{document}
  33. \maketitle
  34. \tableofcontents
  35. \newpage
  36. \listoffigures
  37. \newpage
  38. \textbf{TODO:}
  39. \begin{itemize}
  40. \item Describe in detail tsymtable, including all methods and fields
  41. \item Describe in detail procinfo (tprocinfo)
  42. \item Explain how a symbol is inserted into the symbol table (and how alignment requirements are met)
  43. \item Explain pparaitem
  44. \item Explain all symbol table fields
  45. \item Finish all internal routines definitions
  46. \item Architecture of the assembler generators + API
  47. \item Architecture of the PPU file and information
  48. \item Explain systems.pas
  49. \item routine parsing and code generation algorithm
  50. \item (MvdV) OS specific stuff (like hardcoded linker includedirs)
  51. \end{itemize}
  52. \section{Introduction}
  53. \label{sec:introductionappendix}
  54. This document describes the internal architecture of the Free Pascal
  55. Compiler version 1.0 release. This document is meant to be used as a guide
  56. for those who wish to understand how the compiler was created. Most of the
  57. architecture of the compiler described herein is based on the m68k version
  58. on the compiler, the i386 version of the compiler ressembles closely the
  59. m68k version, but there are subtle differences in the different interfaces.
  60. The architecture, and the different passes of the compiler are shown in
  61. figure \seefig{passesfig}.
  62. \begin{figure}
  63. \ifpdf
  64. % \epsfig{file=arch1d.pdf,width=\textwidth}
  65. \includegraphics{arch1.pdf}
  66. \else
  67. \includegraphics[width=6.45in,height=4.95in]{arch1.eps}
  68. \fi
  69. \caption{compiler overview}
  70. \label{passesfig}
  71. \end{figure}
  72. \section{Scanner / Tokenizer}
  73. The scanner and tokenizer is used to construct an input stream of tokens
  74. which will be fed to the parser. It is in this stage that the preprocessing
  75. is done, that all read compiler directives change the internal state
  76. variables of the compiler, and that all illegal characters found in the
  77. input stream cause an error.
  78. \subsection{Architecture}
  79. \label{subsec:architectureand}
  80. The general architecture of the scanner is shown in figure \ref{fig2}
  81. \begin{figure}
  82. \ifpdf
  83. %\epsfig{file=arch2.png,width=\textwidth}
  84. \includegraphics{arch2.pdf}
  85. \else
  86. \includegraphics[width=5.87in,height=6.90in]{arch2.eps}
  87. \fi
  88. \caption{scanner interface overview}
  89. \label{fig2}
  90. \end{figure}
  91. Several types can be read from the input stream, a string, handled by
  92. \var{readstring()}, a numeric value, handled by \var{readnumeric()}, comments , compiler
  93. and preprocessor directives.
  94. \subsubsection{Input stream}
  95. \label{subsubsec:input}
  96. The input data is handled via the standard way of handling all the I/O in
  97. the compiler. That is to say, that it is a hook which can be overriden in
  98. \textbf{comphook.pas (do{\_}openinputfile)}, in case where another I/O
  99. method wants to be used.
  100. The default hook uses a non-buffered dos stream contained in
  101. \textbf{files.pas}
  102. \subsubsection{Preprocessor}
  103. \label{subsubsec:preprocessorhook}
  104. The scanner resolves all preprocessor directives and only gives to the
  105. parser the visible parts of the code (such as those which are included in
  106. conditional compilation). Compiler switches and directives are also saved in
  107. global variables while in the preprocessor, therefore this is part is
  108. completely independent of the parser.
  109. \paragraph{Conditional compilation (scandir.inc, scanner.pas)}
  110. The conditional compilation is handled via a preprocessor stack, where each
  111. directive is pushed on a stack, and popped when it is resolved. The actual
  112. implementation of the stack is a linked list of preprocessor directive
  113. items.
  114. \paragraph{Compiler switches (scandir.inc, switches.pas)}
  115. The compiler switches are handled via a lookup table which is linearly
  116. searched. Then another lookup table takes care of setting the appropriate
  117. bit flags and variables in the switches for this compilation process.
  118. \subsection{Scanner interface}
  119. \label{subsec:scanner}
  120. The parser only receives tokens as its input, where a token is a enumeration
  121. which indicates the type of the token, either a reserved word, a special
  122. character, an operator, a numeric constant, string, or an identifier.
  123. Resolution of the string into a token is done via lookup which searches the
  124. string table to find the equivalent token. This search is done using a
  125. binary search algorithm through the string table.
  126. In the case of identifiers, constants (including numeric values), the value
  127. is returned in the \textbf{pattern} string variable , with the appropriate
  128. return value of the token (numeric values are also returned as non-converted
  129. strings, with any special prefix included). In the case of operators, and
  130. reserved words, only the token itself must be assumed to be preserved. The
  131. read input string is assmued to be lost.
  132. Therefore the interface with the parser is with the \textbf{readtoken()}
  133. routine and the \textbf{pattern} variable.
  134. \subsubsection{Routines}
  135. \label{subsubsec:routinese}
  136. \begin{procedure}{ReadToken}
  137. \Declaration
  138. Procedure ReadToken;
  139. \Description
  140. Sets the global variable \textsf{token} to the current token read, and sets
  141. the \textsf{pattern} variable appropriately (if required).
  142. \end{procedure}
  143. % ?? :
  144. %\caption{: Symbol tables in memory}
  145. %\label{tab2}
  146. \subsubsection{Variables}
  147. \label{subsubsec:variablesglobal}
  148. \begin{variable}{Token}
  149. \Description
  150. Var Token : TToken;
  151. \Description
  152. Contains the contain token which was last read by a call to \seep{ReadToken}
  153. \SeeAlso
  154. \seep{ReadToken}
  155. \end{variable}
  156. %\caption{: Possible symbol table types (tsymboltabletype)}
  157. %\label{tab3}
  158. %\end{table}
  159. \begin{variable}{Pattern}
  160. \Declaration
  161. var Pattern : String;
  162. \Description
  163. Contains the string of the last pattern read by a call to
  164. \seep{ReadToken}
  165. \SeeAlso
  166. \seep{ReadToken}
  167. \end{variable}
  168. %\caption{: Symbol entry relationships (tsym)}
  169. %\label{tab4}
  170. \subsection{Assembler parser interface}
  171. \label{subsec:assembler}
  172. The inline assembler parser is completely separate from the pascal parser,
  173. therefore its scanning process is also completely independent. The scanner
  174. only takes care of the preprocessor part and comments, all the rest is
  175. passed character per character to the assembler parser via the
  176. \seef{AsmGetChar}() scanner routine.
  177. \subsubsection{routines}
  178. \begin{function}{AsmGetChar}
  179. \Declaration
  180. Function AsmGetChar: Char;
  181. \Description
  182. Returns the next character in the input stream.
  183. \end{function}
  184. %\caption{Possible symbol types (TSymTyp)}
  185. %\label{tab5}
  186. \section{The tree}
  187. \label{sec:mylabel2}
  188. \subsection{Architecture}
  189. \label{subsec:architecturenext}
  190. The tree is the basis of the compiler. When the compiler parses statements
  191. and blocks of code, they are converted to a tree representation. This tree
  192. representation is actually a doubly linked list. From this tree the code
  193. generation can easily be implemented.
  194. Assuming that you have the following pascal syntax:
  195. %\lstinline!x := x * y + (6 shl x);!
  196. \begin{center}
  197. $ x := x * y + (6\; shl \; x);$
  198. \end{center}
  199. The tree structure in picture \ref{fig3} will be built in memory, where each
  200. circle represents an element (a node ) in the tree:
  201. \begin{figure}
  202. \begin{center}
  203. \ifpdf
  204. %\epsfig{file=arch3.png,width=\textwidth}
  205. \includegraphics{arch3.pdf}
  206. \else
  207. \includegraphics[width=3.88in,height=3.65in]{arch3.eps}
  208. \fi
  209. \caption{Example tree structure}
  210. \label{fig3}
  211. \end{center}
  212. \end{figure}
  213. \subsection{Tree types}
  214. The following tree nodes are possible (of type \textsf{TTreeTyp):}
  215. \begin{longtable}{|l|p{10cm}|}
  216. \caption{Possible node types (ttreetyp)}\label{tab6}\\
  217. \hline
  218. Tree type definition& Description \\
  219. \hline
  220. \endfirsthead
  221. %{|p{125pt}|p{316pt}|}
  222. \caption{Possible node types (ttreetyp) - continued}\\
  223. \hline
  224. \hline
  225. Tree type definition&
  226. Description \\
  227. \hline
  228. \endhead
  229. \hline
  230. \endfoot
  231. \textsf{addn}&
  232. \textsf{Represents the + operator} \\
  233. \textsf{muln}&
  234. \textsf{Represents the * operator} \\
  235. \textsf{subn}&
  236. \textsf{Represents the }\textsf{\textbf{-}}\textsf{ operator} \\
  237. \textsf{divn}&
  238. \textsf{Represents the }\textsf{\textbf{div}}\textsf{ operator} \\
  239. \textsf{symdifn}&
  240. \textsf{Represents the }\textsf{\textbf{><}}\textsf{ operator} \\
  241. \textsf{modn}&
  242. \textsf{Represents the }\textsf{\textbf{mod}}\textsf{ operator} \\
  243. \textsf{assignn}&
  244. \textsf{Represents the }\textsf{\textbf{:=}}\textsf{ operator (assignment)} \\
  245. \textsf{loadn}&
  246. \textsf{Represents the use of a variable} \\
  247. \textsf{rangen}&
  248. \textsf{Represents a numeric range (i.e 0..9)} \\
  249. \textsf{ltn}&
  250. \textsf{Represents the }\textsf{\textbf{<}}\textsf{ operator} \\
  251. \textsf{lten}&
  252. \textsf{Represents the }\textsf{\textbf{<=}}\textsf{ operator} \\
  253. \textsf{gtn}&
  254. \textsf{Represents the }\textsf{\textbf{>}}\textsf{ operator} \\
  255. \textsf{gten}&
  256. \textsf{Represents the }\textsf{\textbf{>=}}\textsf{ operator} \\
  257. \textsf{equaln}&
  258. \textsf{Represents the = operator} \\
  259. \textsf{unequaln}&
  260. \textsf{Represents the }\textsf{\textbf{<>}}\textsf{ operator} \\
  261. \textsf{inn}&
  262. \textsf{Represents the }\textsf{\textbf{in}}\textsf{ operator} \\
  263. \textsf{orn}&
  264. \textsf{Represents the }\textsf{\textbf{or}}\textsf{ operator} \\
  265. \textsf{xorn}&
  266. \textsf{Represents the }\textsf{\textbf{xor}}\textsf{ operator} \\
  267. \textsf{shrn}&
  268. \textsf{Represents the }\textsf{\textbf{shr}}\textsf{ operator} \\
  269. \textsf{shln}&
  270. \textsf{Represents the }\textsf{\textbf{shl}}\textsf{ operator} \\
  271. \textsf{slashn}&
  272. \textsf{Represents the / operator} \\
  273. \textsf{andn}&
  274. \textsf{Represents the }\textsf{\textbf{and}}\textsf{ operator} \\
  275. \textsf{subscriptn}&
  276. \textsf{Represents a field in an object or record} \\
  277. \textsf{derefn}&
  278. \textsf{Represents a pointer reference (such as the }\textsf{\textbf{\^}}\textsf{ operator)} \\
  279. \textsf{addrn}&
  280. \textsf{Represents the }\textsf{\textbf{@}}\textsf{ operator} \\
  281. \textsf{doubleaddrn}&
  282. \textsf{Represents the }\textsf{\textbf{@@}}\textsf{ operator} \\
  283. \textsf{ordconstn}&
  284. \textsf{Represents an ordinal constant} \\
  285. \textsf{typeconvn}&
  286. \textsf{Represents a typecast / type conversion} \\
  287. \textsf{calln}&
  288. \textsf{Represents a routine call} \\
  289. \textsf{callparan}&
  290. \textsf{Represents a parameter passed to a routine} \\
  291. \textsf{realconstn}&
  292. \textsf{Represents a floating point constant} \\
  293. \textsf{fixconstn}&
  294. \textsf{Represents a fixed point constant} \\
  295. \textsf{unaryminusn}&
  296. \textsf{Represents a sign change (e.g : -)} \\
  297. \textsf{asmn}&
  298. \textsf{Represents an assembler statement node} \\
  299. \textsf{vecn}&
  300. \textsf{Represents array indexing} \\
  301. \textsf{pointerconstn}&
  302. \textsf{Represents a pointer constant} \\
  303. \textsf{stringconstn}&
  304. \textsf{Represents a string constant} \\
  305. \textsf{funcretn}&
  306. \textsf{Represents the return function result variable (not loadn)} \\
  307. \textsf{selfn}&
  308. \textsf{Represents the self parameter} \\
  309. \textsf{notn}&
  310. \textsf{Represents the }\textsf{\textbf{not}}\textsf{ operator} \\
  311. \textsf{inlinen}&
  312. \textsf{Represents one of the internal routines (writeln,ord, etc.)} \\
  313. \textsf{niln}&
  314. \textsf{Represents the }\textsf{\textbf{nil}}\textsf{ pointer } \\
  315. \textsf{erron}&
  316. \textsf{Represents error in parsing this node (used for error detection and correction)} \\
  317. \textsf{typen}&
  318. \textsf{Represents a type name (i.e typeof(obj))} \\
  319. \textsf{hnewn}&
  320. \textsf{Represents the }\textsf{\textbf{new }}\textsf{routine call on objects} \\
  321. \textsf{hdisposen}&
  322. \textsf{Represents the }\textsf{\textbf{dispose}}\textsf{ routine call on objects} \\
  323. \textsf{newn}&
  324. \textsf{Represents the }\textsf{\textbf{new}}\textsf{ routine call on non-objects} \\
  325. \textsf{simpledisposen}&
  326. \textsf{Represents the }\textsf{\textbf{dispose}}\textsf{ routine call on non-objects} \\
  327. \textsf{setelementn}&
  328. \textsf{Represents set elements (i.e : [a..b], [a,b,c]) (non-constant)} \\
  329. \textsf{setconstn}&
  330. \textsf{Represents set element constants i.e : [1..9], [1,2,3])} \\
  331. \textsf{blockn}&
  332. \textsf{Represents a block of statements} \\
  333. \textsf{statementn}&
  334. \textsf{One statement in a block of nodes} \\
  335. \textsf{loopn}&
  336. \textsf{Represents a loop (for, while, repeat) node} \\
  337. \textsf{ifn}&
  338. \textsf{Represents an }\textsf{\textbf{if}}\textsf{ statement} \\
  339. \textsf{breakn}&
  340. \textsf{Represents a }\textsf{\textbf{break}}\textsf{ statement} \\
  341. \textsf{continuen}&
  342. \textsf{Represents a }\textsf{\textbf{continue}}\textsf{ statement} \\
  343. \textsf{repeatn}&
  344. \textsf{Represents a }\textsf{\textbf{repeat }}\textsf{statement} \\
  345. \textsf{whilen}&
  346. \textsf{Represents a }\textsf{\textbf{while}}\textsf{ statement} \\
  347. \textsf{forn}&
  348. \textsf{Represents a }\textsf{\textbf{for}}\textsf{ statement} \\
  349. \textsf{exitn}&
  350. \textsf{Represents an }\textsf{\textbf{exit}}\textsf{ statement} \\
  351. \textsf{withn}&
  352. \textsf{Represents a }\textsf{\textbf{with}}\textsf{ statement} \\
  353. \textsf{casen}&
  354. \textsf{Represents a }\textsf{\textbf{case}}\textsf{ statement} \\
  355. \textsf{labeln}&
  356. \textsf{Represents a label statement} \\
  357. \textsf{goton}&
  358. \textsf{Represents a }\textsf{\textbf{goto}}\textsf{ statement} \\
  359. \textsf{simplenewn}&
  360. \textsf{Represents a }\textsf{\textbf{new}}\textsf{ statement } \\
  361. \textsf{tryexceptn}&
  362. \textsf{Represents a }\textsf{\textbf{try}}\textsf{ statement} \\
  363. \textsf{raisen}&
  364. \textsf{Represents a }\textsf{\textbf{raise}}\textsf{ statement} \\
  365. \textsf{\textit{switchesn}}&
  366. \textsf{\textit{Unused}} \\
  367. \textsf{tryfinallyn}&
  368. \textsf{Represents a }\textsf{\textbf{try..finally}}\textsf{ statement} \\
  369. \textsf{onn}&
  370. \textsf{Represents an }\textsf{\textbf{on..do}}\textsf{ statement} \\
  371. \textsf{isn}&
  372. \textsf{Represents the }\textsf{\textbf{is}}\textsf{ operator} \\
  373. \textsf{asn}&
  374. \textsf{Represents the }\textsf{\textbf{as}}\textsf{ typecast operator} \\
  375. \textsf{caretn}&
  376. \textsf{Represents the \ operator} \\
  377. \textsf{failn}&
  378. \textsf{Represents the }\textsf{\textbf{fail}}\textsf{ statement} \\
  379. \textsf{starstarn}&
  380. \textsf{Represents the }\textsf{\textbf{**}}\textsf{ operator (exponentiation)} \\
  381. \textsf{procinlinen}&
  382. \textsf{Represents an }\textsf{\textbf{inline}}\textsf{ routine} \\
  383. \textsf{arrayconstrucn}&
  384. \textsf{Represents a }\textsf{\textbf{[..]}}\textsf{ statement (array or sets)} \\
  385. \textsf{arrayconstructrangen}&
  386. \textsf{Represents ranges in [..] statements (array or sets)} \\
  387. \textsf{nothingn}&
  388. \textsf{Empty node} \\
  389. \textsf{loadvmtn}&
  390. \textsf{Load method table register} \\
  391. \hline
  392. \end{longtable}
  393. \subsection{Tree structure fields (tree.pas)}
  394. \label{subsec:mylabel2}
  395. Each element in a node is a pointer to a TTree structure, which is summarily
  396. explained and defined as follows:
  397. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{8.0cm}|}
  398. \hline
  399. \textsf{TYPE}& & \\
  400. \xspace pTree = & \^{} TTree; & \\
  401. \xspace \textsf{TTree} = & \textbf{RECORD}& \\
  402. & \textsf{Error : boolean;}& Set to TRUE if there was an error parsing this node\\
  403. &\textsf{DisposeTyp : tdisposetyp;}&
  404. \\
  405. &\textsf{Swaped : boolean;}&
  406. Set to TRUE if the left and right nodes (fields) of this node have been swaped. \\
  407. & \textsf{VarStateSet : boolean;}&
  408. \\
  409. & \textsf{Location : tlocation;}&
  410. Location information for this information (cf. Code generator) \\
  411. & \textsf{Registers32 : longint;}&
  412. Minimum number of general purpose registers required to evaluate this node \\
  413. & \textsf{RegistersFpu : longint;}&
  414. Minimum number of floating point registers required to evaluate this node \\
  415. & \textsf{Left : pTree;}&
  416. LEFT leaf of this node \\
  417. & \textsf{Right : pTree;}&
  418. RIGHT leaf of this node \\
  419. & \textsf{ResultType : pDef;}&
  420. Result type of this node \par (cf. Type definitions) \\
  421. & \textsf{FileInfo : TFilePosInfo;}&
  422. Line number information for this node creation in the original source code (for error management) \\
  423. & \textsf{LocalSwitches : tlocalswitches;}&
  424. Local compiler switches used for code generation \par (Cf. \ref{tlocalswitches}) \\
  425. & \textsf{IsProperty : boolean;}&
  426. TRUE if this is a property \\
  427. & \textsf{TreeType : ttreetyp;}&
  428. Type of this tree (cf. \ref{tab1}) \\
  429. & \textsf{END;}& \\
  430. \hline
  431. \end{tabular*}
  432. %\caption{Possible definition types (tdeftype)}
  433. \begin{longtable}{|l|l|p{10cm}|}
  434. % p{126pt}|p{45pt}|p{319pt}|}
  435. \caption{local compiler switches (tlocalswitches)}\label{tlocalswitches}\\
  436. \hline
  437. tlocalswitches & Switch & Description \\
  438. \hline
  439. \endfirsthead
  440. \hline
  441. tlocalswitches & Switch & Description \\
  442. \hline
  443. \endhead
  444. \hline
  445. \endfoot
  446. \textsf{cs{\_}check{\_}overflow} & {\{}{\$}Q+{\}}&
  447. Code generator should emit overflow checking code \\
  448. \textsf{cs{\_}check{\_}range} & {\{}{\$}R+{\}}&
  449. Code generator should emit range checking code \\
  450. \textsf{cs{\_}check{\_}IO} & {\{}{\$}I+{\}}&
  451. Code generator should emit I/O checking code \\
  452. \textsf{cs{\_}check{\_}object{\_}ext} & N/A&
  453. Code generator should emit extended object access checks \\
  454. \textsf{\textit{cs{\_}omitstackframe}} & $N/A$ &
  455. \textit{Code generator should not emit frame{\_}pointer setup code
  456. in entry code} \\
  457. \textsf{cs{\_}do{\_}assertion} & {\{}{\$}C+{\}} &
  458. Code generator supports using the assert inline routine \\
  459. \textsf{cs{\_}generate{\_}rtti} & {\{}{\$}M+{\}} &
  460. Code generator should emit runtime type information \\
  461. \textsf{cs{\_}typed{\_}addresses} & {\{}{\$}T+{\}}&
  462. Parser emits typed pointer using the @ operator \\
  463. \textsf{cs{\_}ansistrings} & {\{}{\$}H+{\}}&
  464. Parser creates an \textsf{ansistring} when an unspecified
  465. \textsf{String} type is declared instead of the default
  466. \textsf{ShortString} \\
  467. \textsf{cs{\_}strict{\_}var{\_}strings} & {\{}{\$}V+{\}}&
  468. String types must be identical (same length) to be compatible \\
  469. \hline
  470. \end{longtable}
  471. \subsubsection{Additional fields}
  472. \label{subsubsec:additional}
  473. Depending on the tree type, some additional fields may be present in the
  474. tree node. This section describes these additional fields. Before accessing
  475. these additional fields, a check on the \textsf{treetype} should always be
  476. done to verify if not reading invalid memory ranges.
  477. \paragraph{AddN}\mbox{}
  478. \begin{longtable}{|l|p{10cm}|}
  479. \hline
  480. Field & Description \\
  481. \hline
  482. \endhead
  483. \hline
  484. \endfoot
  485. \textsf{\textit{Use{\_}StrConcat : Boolean;}}&
  486. \textit{Currently unused (use for optimizations in future versions)} \\
  487. \hline
  488. \textsf{String{\_}Typ: TStringType;}&
  489. In the case where the + operator is applied on a string, this field indicates the string type. \\
  490. \hline
  491. \end{longtable}
  492. \paragraph{CallParaN}\mbox{}
  493. \begin{longtable}{|l|p{10cm}|}
  494. \hline
  495. Field & Description \\
  496. \hline
  497. \endhead
  498. \hline
  499. \endfoot
  500. \textsf{Is{\_}Colon{\_}Para : Boolean;}&
  501. Used for internal routines which can use optional format parameters
  502. (using colons). Is set to TRUE if this parameter was preceded by a
  503. colon (i.e : :1) \\
  504. \textsf{Exact{\_}Match{\_}Found : Boolean;}&
  505. Set to TRUE if the parameter type is exactly the same as the one
  506. expected by the routine. \\
  507. \textsf{ConvLevel1Found : Boolean;}&
  508. Set to TRUE if the parameter type requires a level 1 type conversion
  509. to conform to the parameter expected by the routine. \\
  510. \textsf{ConvLevel2Found : Boolean;}&
  511. Set to TRUE if the parameter type requires a level 2 type conversion
  512. to conform to the parameter expected by the routine. \\
  513. \textsf{HighTree : pTree;}& \\
  514. \hline
  515. \end{longtable}
  516. \paragraph{AssignN}\mbox{}
  517. \begin{longtable}{|l|p{10cm}|}
  518. \hline
  519. Field & Description \\
  520. \hline
  521. \endhead
  522. \hline
  523. \endfoot
  524. \textsf{\textit{AssignTyp : TAssignTyp;}}&
  525. \textit{Currently unused (Used to be used for C-like assigns)} \\
  526. \textsf{\textit{Concat{\_}String : Boolean;}}&
  527. \textit{Currently unused (use for optimizations in future versions)}\\
  528. \hline
  529. \end{longtable}
  530. \paragraph{LoadN}\mbox{}
  531. \begin{longtable}{|l|p{10cm}|}
  532. \hline
  533. Field & Description \\
  534. \hline
  535. \endhead
  536. \hline
  537. \endfoot
  538. \textsf{SymTableEntry : pSym;}&
  539. Symbol table entry for this symbol \\
  540. \textsf{SymTable : pSymTable;}&
  541. Symbol table in which this symbol is stored \\
  542. \textsf{Is{\_}Absolute : Boolean;}&
  543. set to TRUE if this variable is absolute \\
  544. \textsf{Is{\_}First : Boolean;}&
  545. set to TRUE if this is the first occurrence of the load for this
  546. variable (used with the varstate variable for optimizations) \\
  547. \hline
  548. \end{longtable}
  549. \paragraph{CallN}\mbox{}
  550. \begin{longtable}{|l|p{10cm}|}
  551. \hline
  552. Field & Description \\
  553. \hline
  554. \endhead
  555. \hline
  556. \endfoot
  557. \textsf{SymTableProcEntry : pProcSym;}&
  558. Symbol table entry for this routine \\
  559. \textsf{SymTableProc : pSymTable;}&
  560. Symbol table associated with a call (object symbol table or routine
  561. symbol table) \\
  562. \textsf{ProcDefinition : pAbstractProcDef;}&
  563. Type definition for this routine \\
  564. \textsf{MethodPointer : pTree;}&
  565. ????????? \\
  566. \textsf{\textit{No{\_}Check : Boolean;}}&
  567. \textit{Currently unused} \\
  568. \textsf{Unit{\_}Specific : Boolean;}&
  569. set to TRUE if the routine is imported in a unit specific way (for
  570. example: system.writeln()) \\
  571. \textsf{Return{\_}Value{\_}Used : Boolean}&
  572. set to TRUE if the routine is a function and that the return value
  573. is not used (in extended syntax parsing - {\$}X+) \\
  574. \textsf{\textit{Static{\_}Call : Boolean;}}&
  575. \textit{unused} \\
  576. \hline
  577. \end{longtable}
  578. \paragraph{addrn}\mbox{}
  579. \begin{longtable}{|l|p{10cm}|}
  580. \hline
  581. Field & Description \\
  582. \hline
  583. \endhead
  584. \hline
  585. \endfoot
  586. \textsf{ProcVarLoad : Boolean;}&
  587. Set to TRUE if this is a procedural variable call \\
  588. \hline
  589. \end{longtable}
  590. \paragraph{OrdConstN}\mbox{}
  591. \begin{longtable}{|l|p{10cm}|}
  592. \hline
  593. Field & Description \\
  594. \hline
  595. \endhead
  596. \hline
  597. \endfoot
  598. \textsf{Value : Longint;}&
  599. The numeric value of this constant node \\
  600. \hline
  601. \end{longtable}
  602. \paragraph{RealConstN}\mbox{}
  603. \begin{longtable}{|l|p{10cm}|}
  604. \hline
  605. Field & Description \\
  606. \hline
  607. \endhead
  608. \hline
  609. \endfoot
  610. \textsf{Value{\_}Real : Best{\_}Real;}&
  611. The numeric value of this constant node \\
  612. \textsf{Lab{\_}Real : pAsmLabel;}&
  613. The assembler label reference to this constant \\
  614. \hline
  615. \end{longtable}
  616. \paragraph{FixConstN}\mbox{}
  617. \begin{longtable}{|l|p{10cm}|}
  618. \hline
  619. Field & Description \\
  620. \hline
  621. \endhead
  622. \hline
  623. \endfoot
  624. \textsf{Value{\_}Fix : Longint;}&
  625. The numeric value of this constant node \\
  626. \hline
  627. \end{longtable}
  628. \paragraph{FuncRetN}\mbox{}
  629. \begin{longtable}{|l|p{10cm}|}
  630. \hline
  631. Field & Description \\
  632. \hline
  633. \endhead
  634. \hline
  635. \endfoot
  636. \textsf{FuncRetProcInfo : Pointer; (pProcInfo)}&
  637. Pointer to procedure information \\
  638. \textsf{RetType : TType;}& Indicates the return type of the function \\
  639. \textsf{Is{\_}First{\_}FuncRet : Boolean;}& \\
  640. \hline
  641. \end{longtable}
  642. \paragraph{SubscriptN}\mbox{}
  643. \begin{longtable}{|l|p{10cm}|}
  644. \hline
  645. Field & Description \\
  646. \hline
  647. \endhead
  648. \hline
  649. \endfoot
  650. \textsf{vs : pVarSym;}&
  651. Symbol table entry for this variable (a field of
  652. object/class/record) \\
  653. \hline
  654. \end{longtable}
  655. \paragraph{RaiseN}\mbox{}
  656. \begin{longtable}{|l|p{10cm}|}
  657. \hline
  658. Field & Description \\
  659. \hline
  660. \endhead
  661. \hline
  662. \endfoot
  663. \textsf{FrameTree : pTree;} & Exception frame tree (code in Raise statement)
  664. \end{longtable}
  665. \paragraph{VecN}\mbox{}
  666. \begin{longtable}{|l|p{10cm}|}
  667. \hline
  668. Field & Description \\
  669. \hline
  670. \endhead
  671. \hline
  672. \endfoot
  673. \textsf{MemIndex : Boolean;} & Set to TRUE if Mem[Seg:Ofs] directive is parsed \\
  674. \textsf{MemSeg : Boolean;} & Set to TRUE if Mem[Seg:Ofs] directive is parsed \\
  675. \textsf{CallUnique: Boolean;} &
  676. \end{longtable}
  677. \paragraph{StringConstN}\mbox{}
  678. \begin{longtable}{|l|p{10cm}|}
  679. \hline
  680. Field & Description \\
  681. \hline
  682. \endhead
  683. \hline
  684. \endfoot
  685. \textsf{Value{\_}Str : pChar;} & The constant value of the string \\
  686. \textsf{Length : Longint;} & Length of the string in bytes (or in characters???) \\
  687. \textsf{Lab{\_}Str : pAsmLabel;} & The assembler label reference to this constant \\
  688. \textsf{StringType : TStringType;}& The string type (short, long, ansi, wide)
  689. \end{longtable}
  690. \paragraph{TypeConvN}\mbox{}
  691. \begin{longtable}{|l|p{10cm}|}
  692. \hline
  693. Field & Description \\
  694. \hline
  695. \endhead
  696. \hline
  697. \endfoot
  698. \textsf{ConvType: TConvertType;}& Indicates the conversion type to do \\
  699. \textsf{Explizit : Boolean;}&
  700. set to TRUE if this was an explicit conversion (with explicit
  701. typecast, or calling one of the internal conversion routines)
  702. \end{longtable}
  703. \paragraph{TypeN}\mbox{}
  704. \begin{longtable}{|l|p{10cm}|}
  705. \hline
  706. Field & Description \\
  707. \hline
  708. \endhead
  709. \hline
  710. \endfoot
  711. \textsf{TypeNodeType : pDef;}& The type definition for this node \\
  712. \textsf{TypeNodeSym : pTypeSym;}& The type symbol information
  713. \label{tab24}
  714. \end{longtable}
  715. \paragraph{InlineN}\mbox{}
  716. \begin{longtable}{|l|p{10cm}|}
  717. \hline
  718. Field & Description \\
  719. \hline
  720. \endhead
  721. \hline
  722. \endfoot
  723. \textsf{InlineNumber: Byte;} & Indicates the internal routine called (Cf. code generator) \\
  724. \textsf{InlineConst : Boolean;} &
  725. One or more of the parameters to this inline routine call contains
  726. constant values
  727. \label{tab25}
  728. \end{longtable}
  729. \paragraph{ProcInlineN}\mbox{}
  730. Inline nodes are created when a routine is declared as being inline. The
  731. routine is actually inlined when the following conditions are satisfied:
  732. It is called within the same module
  733. The appropriate compiler switch to support inline is activated
  734. It is a non-method routine (a standard procedure or function)
  735. Otherwise a normal call is made, ignoring the inline directive. In the case
  736. where a routine is inlined, all parameters , return values and local
  737. variables of the inlined routine are actually allocated in the stack space
  738. of the routine which called the inline routine.
  739. \begin{longtable}{|l|p{10cm}|}
  740. \hline
  741. Field & Description \\
  742. \hline
  743. \endhead
  744. \hline
  745. \endfoot
  746. \textsf{InlineTree : pTree;}&
  747. The complete tree for this inline procedure \\
  748. \textsf{InlineProcsym : pProcSym;}&
  749. Symbol table entry for this procedure \\
  750. \textsf{RetOffset : Longint;}&
  751. Return offset in parent routine stack space \\
  752. \textsf{Para{\_}Offset : Longint;}&
  753. Parameter start offset in parent routine stack space \\
  754. \textsf{Para{\_}Size : Longint;}&
  755. Parameter size in the parent routine stack space
  756. \label{tab26}
  757. \end{longtable}
  758. \paragraph{SetConstN}\mbox{}
  759. \begin{longtable}{|l|p{10cm}|}
  760. \hline
  761. Field & Description \\
  762. \hline
  763. \endhead
  764. \hline
  765. \endfoot
  766. \textsf{Value{\_}Set : pConstSet;}& The numeric value of this constant node \\
  767. \textsf{Lab{\_}Set : pAsmLabel;} & The assembler label reference to this constant
  768. \label{tab27}
  769. \end{longtable}
  770. \paragraph{LoopN}\mbox{}
  771. \begin{longtable}{|l|p{10cm}|}
  772. \hline
  773. Field & Description \\
  774. \hline
  775. \endhead
  776. \hline
  777. \endfoot
  778. & \\
  779. & \\
  780. &
  781. \end{longtable}
  782. \paragraph{AsmN}\mbox{}
  783. \begin{longtable}{|l|p{10cm}|}
  784. \hline
  785. Field & Description \\
  786. \hline
  787. \endhead
  788. \hline
  789. \endfoot
  790. \textsf{p{\_}Asm : pAasmOutput;}&
  791. The instruction tree created by the assembler parser \\
  792. \textsf{Object{\_}Preserved : Boolean;}&
  793. set to FALSE if the Self{\_}Register was modified in the asm statement.
  794. \label{tab29}
  795. \end{longtable}
  796. \paragraph{CaseN}\mbox{}
  797. \begin{longtable}{|l|p{10cm}|}
  798. \hline
  799. Field & Description \\
  800. \hline
  801. \endhead
  802. \hline
  803. \endfoot
  804. \textsf{Nodes : pCaserecord;}&
  805. Tree for each of the possible case in the case statement \\
  806. \textsf{ElseBlock : pTree;}&
  807. Else statement block tree
  808. \label{tab30}
  809. \end{longtable}
  810. \paragraph{LabelN, GotoN}\mbox{}
  811. \begin{longtable}{|l|p{10cm}|}
  812. \hline
  813. Field & Description \\
  814. \hline
  815. \endhead
  816. \hline
  817. \endfoot
  818. \textsf{LabelNr : pAsmLabel;} & Assembler label associated with this statement \\
  819. \textsf{ExceptionBlock : ptree;}& ? \\
  820. \textsf{LabSym : pLabelSym;} & Symbol table entry for this label
  821. \label{tab31}
  822. \end{longtable}
  823. \paragraph{WithN}\mbox{}
  824. \begin{longtable}{|l|p{10cm}|}
  825. \hline
  826. Field & Description \\
  827. \hline
  828. \endhead
  829. \hline
  830. \endfoot
  831. \textsf{WithSymTables : pWithSymTable;} & \\
  832. \textsf{TableCount : Longint;} & \\
  833. \textsf{WithReference : pReference;} & \\
  834. \textsf{IsLocal : Boolean;} &
  835. \label{tab32}
  836. \end{longtable}
  837. \paragraph{OnN}\mbox{}
  838. \begin{longtable}{|l|p{10cm}|}
  839. \hline
  840. Field & Description \\
  841. \hline
  842. \endhead
  843. \hline
  844. \endfoot
  845. \textsf{ExceptSymTable : pSymtable;}& \\
  846. \textsf{ExceptType : pObjectdef;}&
  847. \label{tab33}
  848. \end{longtable}
  849. \paragraph{ArrayConstructorN}\mbox{}
  850. \begin{longtable}{|l|p{10cm}|}
  851. \hline
  852. Field & Description \\
  853. \hline
  854. \endhead
  855. \hline
  856. \endfoot
  857. \textsf{CArgs : Boolean;} & \\
  858. \textsf{CArgSwap : Boolean;} & \\
  859. \textsf{ForceVaria : Boolean;} & \\
  860. \textsf{NoVariaAllowed : Boolean;} & \\
  861. \textsf{ConstructorDef : pDef;} &
  862. \label{tab34}
  863. \end{longtable}
  864. \section{Symbol tables}
  865. \label{sec:symbol}
  866. \subsection{Architecture}
  867. \label{subsec:architecturesructord}
  868. The symbol table contains all definitions for all symbols in the compiler.
  869. It also contains all type information for all symbols encountered during the
  870. parsing process. All symbols and definitions are streamable, and are used
  871. within PPU files to avoid recompiling everything to verify if all symbols are valid.
  872. There are different types of symbol tables, all of which maybe active at one
  873. time or another depending on the context of the parser.
  874. An architectural overview of the interaction between the symbol tables, the
  875. symbol entries and the definition entries is displayed in figure \ref{fig4}
  876. \begin{figure}
  877. \ifpdf
  878. \includegraphics{arch4.pdf}
  879. %\epsfig{file=arch4.png,width=\textwidth}
  880. \else
  881. \includegraphics[width=6.29in,height=3.29in]{arch4.eps}
  882. \fi
  883. \label{fig4}
  884. \caption{Interactions between symbol tables}
  885. \end{figure}
  886. As can be seen, the symbol table entries in the symbol table are done using
  887. the fast hashing algorithm with a hash dictionary.
  888. \subsection{The Symbol table object}
  889. \label{subsec:mylabel3}
  890. All symbol tables in the compiler are from this type of object, which
  891. contains fields for the total size of the data in the symbol table, and
  892. methods to read and write the symbol table into a stream. The start of the
  893. linked list of active symbol tables is the \textbf{symtablestack} variable.
  894. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{6,5cm}|}
  895. \hline
  896. \textsf{TYPE} & & \\
  897. \xspace \textsf{pSymTable} &= \^{} \textbf{TSymTable};& \\
  898. \xspace \textsf{TSymTable} &= \textbf{object} & \\
  899. & \textsf{Name : pString;}& \\
  900. & \textsf{DataSize : Longint;}&
  901. The total size of all the data in this symbol table (after the data has been aligned). Only valid for certain types of symbol tables. \\
  902. & \textsf{DataAlignment : Longint;}& \\
  903. & \textsf{SymIndex : pIndexArray;}& \\
  904. & \textsf{DefIndex : pIndexArray;}& \\
  905. & \textsf{SymSearch : pDictionary;}& \\
  906. & \textsf{Next : pSymtable;}&
  907. Points to the next symbol table in the linked list of active symbol tables. \\
  908. & \textsf{DefOwner : pDef;}&
  909. The owner definition (only valid in the cases of objects and records, this points to the definition of that object or record). \\
  910. & \textsf{Address{\_}Fixup : Longint}& \\
  911. & \textsf{UnitId : Word;}& \\
  912. & \textsf{SymTableLevel : Byte;}& \\
  913. & \textsf{SymTableType :TSymTableType;}&
  914. Indicates the type of this symbol table (\ref{fig2}). \\
  915. &\textsf{end;}& \\
  916. \hline
  917. \end{tabular*}
  918. The type of possible symbol tables are shown in the following table:
  919. \begin{longtable}{|l|p{10cm}|}
  920. \hline
  921. TSymTableType& Description \\
  922. \hline
  923. \endhead
  924. \hline
  925. \endfoot
  926. \textsf{InvalidSymTable}&
  927. Default value when the symbol table is created and its type is not defined. Used for debugging purposes \\
  928. \textsf{WithSymTable}&
  929. All symbols accessed in a with statement \\
  930. \textsf{StaticSymTable}& \\
  931. \textsf{GlobalSymTable}& \\
  932. \textsf{UnitSymTable}&
  933. Linked list of units symbol used (all or unit?). The linked list is
  934. composed of \textsf{tunitsym} structures. \\
  935. \textsf{ObjectSymTable}& \\
  936. \textsf{RecordSymTable}&
  937. Contains all symbols within a record statement \\
  938. \textsf{MacroSymTable}&
  939. Holds all macros currently in scope. \\
  940. \textsf{LocalSymTable}&
  941. Hold symbols for all local variables of a routine \\
  942. \textsf{ParaSymTable}&
  943. Holds symbols for all parameters of a routine (the actual parameter declaration symbols) \\
  944. \textsf{InlineParaSymTable}&
  945. Holds all parameter symbols for the current inline routine \\
  946. \textsf{InlineLocalSymTable}&
  947. Holds all local symbols for the current inline routine \\
  948. \textsf{Stt{\_}ExceptSymTable}& \\
  949. \textsf{StaticPPUSymTable}&
  950. \label{tab36}
  951. \end{longtable}
  952. \subsection{Inserting symbols into a symbol table}
  953. \label{subsec:inserting}
  954. To add a symbol into a specific symbol table, that's symbol table's
  955. \textsf{Insert} method is called, which in turns call the
  956. \textsf{Insert{\_}In{\_}Data} method of that symbol.
  957. \textsf{Insert{\_}In{\_}Data}, depending on the symbol type, adjusts the
  958. alignment and sizes of the data and actually creates the data entry in the
  959. correct segment.
  960. \begin{figure}
  961. \begin{center}
  962. \ifpdf
  963. %\epsfig{file=arch5.png,width=\textwidth}
  964. \includegraphics{arch5.pdf}
  965. \else
  966. \includegraphics[width=1.51in,height=5.51in]{arch5.eps}
  967. \fi
  968. \label{fig5}
  969. \caption{Inserting into the symbol table}
  970. \end{center}
  971. \end{figure}
  972. \subsection{Symbol table interface}
  973. \subsubsection{Routines}
  974. \label{subsubsec:routinesable}
  975. \begin{functionl}{Search{\_}a{\_}Symtable}{searchasymtable}
  976. \Declaration
  977. Function Search{\_}a{\_}Symtable(Const Symbol:String; \\
  978. SymTableType : TSymTableType):pSym;
  979. \Description
  980. Search for a symbol \textsf{Symbol} in a specified symbol table
  981. \textsf{SymTableType}. Returns \textsf{NIL} if the symbol table is not
  982. found, and also if the symbol cannot be found in the desired symbol table.
  983. \end{functionl}
  984. \begin{procedure}{GetSym}
  985. \Declaration
  986. Procedure GetSym(Const S : StringId; NotFoundError: Boolean);
  987. \Description
  988. Search all the active symbol tables for the symbol \textsf{s},setting the
  989. global variable \textsf{SrSym} to the found symbol, or to \textsf{nil} if
  990. the symbol was not found. \textsf{notfounderror} should be set to TRUE if
  991. the routine must give out an error when the symbol is not found.
  992. \end{procedure}
  993. \begin{function}{GlobalDef}
  994. \Declaration
  995. Function GlobalDef(Const S : String) : pDef;
  996. \Description
  997. Returns a pointer to the definition of the fully qualified type symbol
  998. \textsf{S}, or \textsf{NIL} if not found.
  999. \Notes
  1000. It is fully qualified, in that the symbol \textsf{system.byte}, for example,
  1001. will be fully resolved to a unit and byte type component The symbol must
  1002. have a global scope, and it must be a type symbol, otherwise \textsf{NIL}
  1003. will be returned..
  1004. \end{function}
  1005. \subsubsection{Variables}
  1006. \label{subsubsec:variablesly}
  1007. \begin{variable}{SrSym}
  1008. \Declaration
  1009. Var SrSym : pSym;
  1010. \Description
  1011. This points to the symbol entry found, when calling \textsf{getsym}.
  1012. \end{variable}
  1013. \begin{variable}{SrSymTable}
  1014. \Declaration
  1015. Var SrSymTable : pSymTable;
  1016. \Description
  1017. This points to the symbol table of the symbol \seevar{SrSym} when calling
  1018. \seep{GetSym}.
  1019. \end{variable}
  1020. \section{Symbol entries}
  1021. \label{sec:mylabel3}
  1022. \subsection{Architecture}
  1023. \label{subsec:architecturees}
  1024. There are different possible types of symbols, each one having different
  1025. fields then the others. Each symbol type has a specific signature to
  1026. indicate what kind of entry it is. Each entry in the symbol table is
  1027. actually one of the symbol entries described in the following sections. The
  1028. relationship between a symbol entry, a type definition, and the type name
  1029. symbol entry is shown in figure \ref{fig6}.
  1030. \begin{figure}
  1031. \begin{center}
  1032. \ifpdf
  1033. \includegraphics{arch6.pdf}
  1034. %\epsfig{file=arch6.png,width=\textwidth}
  1035. \else
  1036. \includegraphics[width=5.51in,height=4.51in]{arch6.eps}
  1037. \fi
  1038. \label{fig6}
  1039. \caption{relation between symbol entry and type definition and name}
  1040. \end{center}
  1041. \end{figure}
  1042. \subsection{Symbol entry types}
  1043. \label{subsec:symbol}
  1044. \subsubsection{Base symbol type (TSym)}
  1045. \label{subsubsec:mylabel1}
  1046. All entries in the symbol table are derived from this base object which
  1047. contains information on the symbol type as well as information on the owner
  1048. of this symbol entry.
  1049. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{9cm}|}
  1050. \hline
  1051. \textsf{TYPE} & & \\
  1052. \xspace pSym = & \^{} TSym; & \\
  1053. \xspace \textsf{TSym} = & \textbf{Object}(TSymTableEntry) & \\
  1054. & \textsf{SymOptions : TSymOptions;}& Indicate the access scope of the symbol \\
  1055. & \textsf{FileInfo : tFilePosInfo;}& \\
  1056. & \textsf{Refs : Longint;}&
  1057. Indicates how many times this label is refered in the parsed code (is only used with variable and assembler label symbols). \\
  1058. &\textsf{LastRef : pRef;}& \\
  1059. &\textsf{DefRef : pRef;}& \\
  1060. &\textsf{LastWritten : pRef;}& \\
  1061. &\textsf{RefCount : Longint;}& Browser information indicating the reference count\\
  1062. &\textsf{Typ : tSymTyp;}& Indicates the symbol type \\
  1063. &\textsf{IsStabWritten : Boolean;}& Set to TRUE if the stabs debugging information has been written for this symbol.\\
  1064. &\textsf{end; }&\\
  1065. \hline
  1066. \end{tabular*}
  1067. \begin{longtable}{|l|p{10cm}|}
  1068. \caption{tsymtyp}\label{tsymtyp}\\
  1069. \hline
  1070. TSymTyp & Description \\
  1071. \hline
  1072. \endfirsthead
  1073. \hline
  1074. TSymTyp & Description \\
  1075. \hline
  1076. \endhead
  1077. \hline
  1078. \endfoot
  1079. \textsf{AbstractSym}&
  1080. This is a special abstract symbol (this should never occur) \\
  1081. \textsf{VarSym}&
  1082. This symbol is a variable declaration in the \textsf{var} section, or a \textsf{var} parameter. \\
  1083. \textsf{TypeSym}&
  1084. This symbol is a type name \\
  1085. \textsf{ProcSym}&
  1086. This symbol is a routine or method name \\
  1087. \textsf{UnitSym}&
  1088. This symbol is a unit name \\
  1089. \textsf{\textit{ProgramSym}}&
  1090. \textit{This symbol is the main program name} \\
  1091. \textsf{ConstSym}&
  1092. This symbol is a constant \\
  1093. \textsf{EnumSym}&
  1094. This symbol is an enumeration symbol (an element in an enumeration) \\
  1095. \textsf{TypedConstSym}&
  1096. This symbol is pre-initialized variable (pascal typed constant) \\
  1097. \textsf{ErrorSym}&
  1098. This symbol is created for error generation \\
  1099. \textsf{SysSym}&
  1100. This symbol represents an inlined system unit routine \\
  1101. \textsf{LabelSym}&
  1102. This symbol represents a label in a \textsf{label} pascal declaration \\
  1103. \textsf{AbsoluteSym}&
  1104. This symbol represents an the symbol following an \textsf{absolute} variable declaration \\
  1105. \textsf{PropertySym}&
  1106. This symbol is a property name \\
  1107. \textsf{FuncRetSym}&
  1108. This symbol is the name of the return value for functions \\
  1109. \textsf{MacroSym}&
  1110. This symbol is a macro symbol (just like {\#}define in C)
  1111. \end{longtable}
  1112. \subsubsection{label symbol (TLabelSym)}
  1113. \label{subsubsec:label}
  1114. The label symbol table entry is only created when a pascal label is declared
  1115. via the label keyword. The object has the following fields which are
  1116. available for use publicly:
  1117. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{9cm}|}
  1118. \hline
  1119. \textsf{TYPE} & & \\
  1120. \xspace pLabelSym = & \^{} TLabelSym; & \\
  1121. \xspace \textsf{TLabelSym} = & \textbf{Object}(TSym) & \\
  1122. & \textsf{Used : Boolean}&
  1123. Set to TRUE if this pascal label is used using a \textsf{goto} or in an assembler statement \\
  1124. & \textsf{Defined: Boolean}&
  1125. Set to TRUE if this label has been declared \\
  1126. & \textsf{Lab : pAsmLabel}&
  1127. Points to the actual assembler label structure which will be emitted by the code generator \\
  1128. & \textsf{Code : Pointer}& \\
  1129. & \textsf{end;}& \\
  1130. \hline
  1131. \end{tabular*}
  1132. \subsubsection{unit symbol (TUnitSym)}
  1133. \label{subsubsec:mylabel2}
  1134. The unit symbol is created and added to the symbol table each time that the
  1135. uses clause is parsed and a unit name is found, it is also used when
  1136. compiling a unit, with the first entry in that symbol table being the unit
  1137. name being compiled. The unit symbol entry is actual part of a linked list
  1138. which is used in the unit symbol table.
  1139. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{7cm}|}
  1140. \hline
  1141. \textsf{TYPE} & & \\
  1142. \xspace pUnitSym = & \^{} TUnitSym; & \\
  1143. \xspace \textsf{TUnitSym} = & \textbf{Object}(TSym) & \\
  1144. & \textsf{UnitSymTable:pUnitSymTable}&
  1145. Pointer to the global symbol table for that unit, containing entries for each public? symbol in that unit \\
  1146. & \textsf{PrevSym : pUnitSym}&
  1147. Pointer to previous entry in the linked list \\
  1148. & \textsf{end;}& \\
  1149. \hline
  1150. \end{tabular*}
  1151. \subsubsection{macro symbol (TMacroSym)}
  1152. \label{subsubsec:macro}
  1153. The macro synbols are used in the preprocessor for conditional compilation
  1154. statements. There is one such entry created for each {\$}define directive,
  1155. it contains the value of the define (stored as a string).
  1156. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{6cm}|}
  1157. \hline
  1158. \textsf{TYPE}& & \\
  1159. \xspace pMacroSym = & \^{} TMacroSym; & \\
  1160. \xspace \textsf{TMacroSym} = & \textbf{Object}(TSym) & \\
  1161. & \textsf{Defined : Boolean;}&
  1162. TRUE if the symbol has been defined with a \textsf{{\$}define}
  1163. directive, or false if it has been undefined with a
  1164. \textsf{{\$}undef} directive \\
  1165. & \textsf{Defined{\_}At{\_}Startup : Boolean;}&
  1166. TRUE if the symbol is a system wide define \\
  1167. & \textsf{Is{\_}Used: Boolean;}&
  1168. TRUE if the define has been used such as in a \textsf{{\$}ifdef}
  1169. directive. \\
  1170. & \textsf{BufText : pChar;}&
  1171. The actual string text of the define \\
  1172. & \textsf{BufLength : Longint;}&
  1173. The actual string length of the define \\
  1174. & \textsf{end;}& \\
  1175. \hline
  1176. \end{tabular*}
  1177. \subsubsection{error symbol (TErrorSym)}
  1178. \label{subsubsec:error}
  1179. This symbol is actually an empty symbol table entry. When the parser
  1180. encounters an error when parsing a symbol, instead of putting nothing in the
  1181. symbol table, it puts this symbol entry. This avoids illegal memory accesses
  1182. later in parsing.
  1183. \subsubsection{procedure symbol (TProcSym)}
  1184. \label{subsubsec:procedure}
  1185. The procedure symbol is created each time a routine is defined in the code.
  1186. This can be either a forward definition or the actual implementation of the
  1187. routine. After creation, the symbol is added into the appropriate symbol
  1188. table stack.
  1189. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{8cm}|}
  1190. \hline
  1191. \textsf{TYPE}& & \\
  1192. \xspace pProcSym = & \^{} TProcSym; & \\
  1193. \xspace \textsf{TProcSym} = & \textbf{Object}(TSym) & \\
  1194. & \textsf{Is{\_}Global : Boolean}&
  1195. Set if the routine is exported by the unit \\
  1196. & \textsf{Definition : pProcDef}&
  1197. Procedure definition, including parameter information and return
  1198. values \\
  1199. & \textsf{end;}& \\
  1200. \hline
  1201. \end{tabular*}
  1202. \subsubsection{type symbol (TTypeSym)}
  1203. \label{subsubsec:mylabel3}
  1204. The type symbol is created each time a new type declaration is done, the
  1205. current symbol table stack is then inserted with this symbol. Furthermore,
  1206. each time the compiler compiles a module, the default base types are
  1207. initialized and added into the symbol table (\textbf{psystem.pas}) The type
  1208. symbol contains the name of a type, as well as a pointer to its type
  1209. definition.
  1210. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{9cm}|}
  1211. \hline
  1212. \textsf{TYPE}& & \\
  1213. \xspace pTypeSym = & \^{} TTypeSym; & \\
  1214. \xspace \textsf{TTypeSym} = & \textbf{Object}(TSym) & \\
  1215. & \textsf{ResType : TType}&
  1216. Contains base type information as well as the type definition \\
  1217. & \textsf{end;}& \\
  1218. \hline
  1219. \end{tabular*}
  1220. \subsubsection{variable symbol (TVarSym)}
  1221. \label{subsubsec:variable}
  1222. Variable declarations, as well as parameters which are passed onto routines
  1223. are declared as variable symbol types. Access information, as well as type
  1224. information and optimization information are stored in this symbol type.
  1225. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{8.5cm}|}
  1226. \hline
  1227. \textsf{TYPE}& & \\
  1228. \xspace pVarSym = & \^{} TVarSym; & \\
  1229. \xspace \textsf{TVarSym} = & \textbf{Object}(TSym) & \\
  1230. & \textsf{Reg: TRegister;}&
  1231. If the value is a register variable, the \textsf{reg} field will be
  1232. different then R{\_}NO \\
  1233. & \textsf{VarSpez : TVarSpez;}&
  1234. Indicates the variable type (parameters only) (Cf. \ref{tvarspez}). \\
  1235. & \textsf{Address : Longint;}&
  1236. In the case where the variable is a routine parameter, this
  1237. indicates the positive offset from the \textsf{frame{\_}pointer }to
  1238. access this variable. In the case of a local variable, this field
  1239. indicates the negative offset from the \textsf{frame{\_}pointer}. to
  1240. access this variable. \\
  1241. & \textsf{LocalVarSym : pVarSym;}& \\
  1242. & \textsf{VarType : TType;}&
  1243. Contains base type information as well as the type definition \\
  1244. & \textsf{VarOptions : TVarOptions;}&
  1245. Flags for this variable (Cf. \ref{tvaroptions}) \\
  1246. & \textsf{VarState : TVarState}&
  1247. Indicates the state of the variable, if it's used or declared \\
  1248. & \textsf{end;}& \\
  1249. \hline
  1250. \end{tabular*}
  1251. \begin{longtable}{|l|p{10cm}|}
  1252. \caption{tvaroptions}\label{tvaroptions}\\
  1253. \hline
  1254. TVarOptions & Description \\
  1255. \hline
  1256. \endfirsthead
  1257. \caption{tvaroptions (continued)}\\
  1258. \hline
  1259. TVarOptions & Description \\
  1260. \hline
  1261. \endhead
  1262. \hline
  1263. \endfoot
  1264. \textsf{vo{\_}regable}&
  1265. The variable can be put into a hardware general purpose register \\
  1266. \textsf{vo{\_}is{\_}c{\_}var}&
  1267. The variable is imported from a C module \\
  1268. \textsf{vo{\_}is{\_}external}&
  1269. The variable is declared external \\
  1270. \textsf{vo{\_}is{\_}Dll{\_}var}&
  1271. The variable is a shared library variable \\
  1272. \textsf{vo{\_}is{\_}thread{\_}var}&
  1273. The variable is declared as being thread safe \\
  1274. \textsf{vo{\_}fpuregable}&
  1275. The variable can be put into a hardware floating point register \\
  1276. \textsf{vo{\_}is{\_}local{\_}copy}& \\
  1277. \textsf{\textit{vo{\_}is{\_}const}}&
  1278. \textit{unused and useless} \\
  1279. \textsf{vo{\_}is{\_}exported}&
  1280. The variable is declared as exported in a dynamic link library
  1281. \end{longtable}
  1282. \begin{longtable}{|l|p{10cm}|}
  1283. \caption{parameter type}\label{tvarspez}\\
  1284. \hline
  1285. TVarSpez & Description \\
  1286. \hline
  1287. \endfirsthead
  1288. \caption{parameter type (continued)}\\
  1289. \hline
  1290. TVarSpez & Description \\
  1291. \hline
  1292. \endhead
  1293. \hline
  1294. \endfoot
  1295. \textsf{vs{\_}value}&
  1296. This is a value parameter \\
  1297. \textsf{vs{\_}const}&
  1298. This is a constant parameter, property or array \\
  1299. \textsf{vs{\_}var}&
  1300. This is a variable parameter
  1301. \end{longtable}
  1302. \subsubsection{property symbol (TPropertySym)}
  1303. \label{subsubsec:property}
  1304. \begin{tabular*}{6.25in}{|l@{\extracolsep{\fill}}lp{4cm}|}
  1305. \hline
  1306. \textsf{TYPE}& & \\
  1307. \xspace pPropertySym = & \^{} TPropertySym; & \\
  1308. \xspace \textsf{TPropertySym} = & \textbf{Object}(TSym) & \\
  1309. & \textsf{propoptions: tpropertyoptions;}&
  1310. ??? \\
  1311. & \textsf{proptype : ttype;}&
  1312. Indicates the type of the property\\
  1313. & \textsf{propoverriden : ppropertysym;}&
  1314. ??? \\
  1315. & \textsf{indextype : ttype;}& \\
  1316. & \textsf{index : longint;}&
  1317. ???? \\
  1318. & \textsf{default : longint}&
  1319. ??? \\
  1320. & \textsf{readaccess : psymlist}&
  1321. ??? \\
  1322. & \textsf{writeaccess : psymlist}&
  1323. ??? \\
  1324. & \textsf{storedaccess : psymlist}&
  1325. ??? \\
  1326. & \textsf{end;}& \\
  1327. \hline
  1328. \end{tabular*}
  1329. \subsubsection{return value of function symbol}
  1330. \label{subsubsec:return}
  1331. \subsubsection{absolute declared symbol (TAbsoluteSym)}
  1332. \label{subsubsec:absolute}
  1333. This symbol represents a variable declared with the \var{absolute} keyword. The
  1334. \var{address} of the \var{TVarSym} object holds the address of the variable
  1335. in the case of an absolute address variable.
  1336. The possible types of absolute symbols, are from an external object
  1337. reference, an absolute address (for certain targets only), or on top
  1338. of another declared variable. For the possible types, \ref{tabsolutetyp}.
  1339. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{8.5cm}|}
  1340. \hline
  1341. \textsf{TYPE}& & \\
  1342. \xspace pAbsoluteSym = & \^{} TAbsoluteSym; & \\
  1343. \xspace \textsf{TAbsoluteSym} = & \textbf{Object}(TVarSym) & \\
  1344. & \textsf{abstyp : absolutetyp;}&
  1345. Indicates the type of absolute symbol it is (Cf. \ref{tabsolutetyp}) \\
  1346. & \textsf{absseg : boolean;}&
  1347. ???\\
  1348. & \textsf{ref : psym;}&
  1349. In case \var{abstyp} is \var{tovar}, this field indicates
  1350. the symbol which is overlaid with this symbol. Otherwise
  1351. this field is unused.\\
  1352. & \textsf{asmname : pstring;}& In case \var{abstyp} is \var{toasm},
  1353. this field indicates label name for the variable.\\
  1354. \hline
  1355. \end{tabular*}
  1356. \begin{longtable}{|l|p{10cm}|}
  1357. \caption{possible absolute variable types}\label{tabsolutetyp}\\
  1358. \hline
  1359. tabsolutetyp & Description \\
  1360. \hline
  1361. \endfirsthead
  1362. \hline
  1363. tabsolutetyp & Description \\
  1364. \hline
  1365. \endhead
  1366. \hline
  1367. \endfoot
  1368. \textsf{tovar}&
  1369. The symbol will be declared on top of another symbol (variable or typed constant)\\
  1370. \textsf{toasm}&
  1371. The variable is imported from an external module \\
  1372. \textsf{toaddr}&
  1373. The variable is declared as being at an absolute address \\
  1374. \end{longtable}
  1375. \subsubsection{typed constant symbol}
  1376. \label{subsubsec:typed}
  1377. \subsubsection{constant symbol (TConstSym)}
  1378. \label{subsubsec:constant}
  1379. This symbol type will contain all constants defined and encountered
  1380. during the parsing. The values of the constants are also set in
  1381. this symbol type entry.
  1382. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{8.5cm}|}
  1383. \hline
  1384. \textsf{TYPE}& & \\
  1385. \xspace pConstSym = & \^{} TConstSym; & \\
  1386. \xspace \textsf{TConstSym} = & \textbf{Object}(TSym) & \\
  1387. & \textsf{consttype : ttype;}&
  1388. Type information for this constant (?). \\
  1389. & \textsf{consttyp : tconsttyp}&
  1390. Indicates the type of the constant\\
  1391. & \textsf{resstrindex : longint}& If this is a resource
  1392. string constant, it indicates the index in the resource
  1393. table \\
  1394. & \textsf{value : longint}& In certain cases, contains
  1395. the value of the constant \\
  1396. & \textsf{len : longint}&
  1397. \\
  1398. \hline
  1399. \end{tabular*}
  1400. \subsubsection{enumeration symbol}
  1401. \label{subsubsec:enumeration}
  1402. \subsubsection{program symbol}
  1403. \label{subsubsec:program}
  1404. The program symbol type (\var{tprogramsym}) is used to store the name
  1405. of the program, which is declared using \var{program} in the pascal source.
  1406. This symbol type is currently unused in FreePascal.
  1407. \subsubsection{sys symbol}
  1408. \label{subsubsec:mylabel4}
  1409. The \var{tsyssym} symbol type is used to load indexes into the symbol
  1410. table of the internal routines which are inlined directly by the compiler.
  1411. It has a single field, which is the index of the inline routine.
  1412. \subsection{Symbol interface}
  1413. \label{subsec:mylabel5}
  1414. \section{Type information}
  1415. \label{sec:mylabel4}
  1416. \subsection{Architecture}
  1417. \label{subsec:architecturetionolbo}
  1418. A type declaration , which is the basis for the symbol table, since
  1419. inherently everything comes down to a type after parsing is a special
  1420. structure with two principal fields, which point to a symbol table entry
  1421. which is the type name, and the actual definition which gives the
  1422. information on other symbols in the type, the size of the type and other
  1423. such information.
  1424. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{9cm}|}
  1425. \hline
  1426. \textsf{TYPE} & & \\
  1427. \xspace \textsf{TType} = & \textbf{Object} & \\
  1428. &\textsf{Sym : pSym;}&
  1429. Points to the symbol table of this type \\
  1430. & \textsf{Def : pDef;}&
  1431. Points to the actual definition of this type \\
  1432. &\textsf{end;}& \\
  1433. \hline
  1434. \end{tabular*}
  1435. \begin{center}
  1436. \begin{figure}
  1437. \ifpdf
  1438. \includegraphics{arch7.pdf}
  1439. %\epsfig{file=arch7.png,width=\textwidth}
  1440. \else
  1441. \includegraphics[width=4.39in,height=3.56in]{arch7.eps}
  1442. \fi
  1443. \caption{Type symbol and definition relations}
  1444. \label{fig7}
  1445. \end{figure}
  1446. \end{center}
  1447. \subsection{Definition types}
  1448. Definitions represent the type information for all possible symbols which
  1449. can be encountered by the parser. The definition types are associated with
  1450. symbols in the symbol table, and are used by the parsing process (among
  1451. other things) to perform type checking.
  1452. The current possible definition types are enumerated in \textsf{TDefType}
  1453. and can have one of the following symbolic values:
  1454. \begin{longtable}{|l|p{10cm}|}
  1455. \hline
  1456. deftype of TDef object & Description \\
  1457. \hline
  1458. \endhead
  1459. \hline
  1460. \endfoot
  1461. \textsf{AbstractDef} & \\
  1462. \textsf{ArrayDef} & array type definition \\
  1463. \textsf{RecordDef} & record type definition \\
  1464. \textsf{PointerDef} & pointer type definition \\
  1465. \textsf{OrdDef} & ordinal (numeric value) type definition \\
  1466. \textsf{StringDef} & string type definition \\
  1467. \textsf{EnumDef} & enumeration type definition \\
  1468. \textsf{ProcDef} & procedure type definition \\
  1469. \textsf{ObjectDef} & object or class type definition \\
  1470. \textsf{ErrorDef} & error definition (empty, used for error recovery) \\
  1471. \textsf{FileDef} & file type definition \\
  1472. \textsf{FormalDef} & \\
  1473. \textsf{SetDef} & set type definition \\
  1474. \textsf{ProcVarDef} & procedure variable type definition \\
  1475. \textsf{FloatDef} & floating point type definition \\
  1476. \textsf{ClassrefDef} & \\
  1477. \textsf{ForwardDef} & \\
  1478. \end{longtable}
  1479. \subsubsection{base definition (TDef)}
  1480. \label{subsubsec:mylabel5}
  1481. All type definitions are based on this object. Therefore all derived object
  1482. all posess the fields in this object in addition to their own private
  1483. fields.
  1484. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{7cm}|}
  1485. \hline
  1486. \textsf{TYPE} & & \\
  1487. \xspace pDef = & \^{} TDef; & \\
  1488. \xspace \textsf{TDef} = & \textbf{Object}(TSymTableEntry) & \\
  1489. &\textsf{TypeSym : pTypeSym;}&
  1490. Pointer to symbol table entry for this type definition \\
  1491. &\textsf{InitTable{\_}Label : pAsmLabel;}&
  1492. Label to initialization information (required for some complex types) \\
  1493. &\textsf{Rtti{\_}Label : pAsmLabel;}&
  1494. Label to the runtime type information. \\
  1495. &\textsf{NextGlobal : pDef;}& \\
  1496. &\textsf{PreviousGlobal : pDef;}& \\
  1497. &\textsf{SaveSize : Longint;}&
  1498. Size in bytes of the data definition \\
  1499. &\textsf{DefType : tDefType;}&
  1500. Indicates the definition type (see table \ref{tab5}). \\
  1501. &\textsf{Has{\_}InitTable : Boolean;}& \\
  1502. &\textsf{Has{\_}Rtti : Boolean;}& \\
  1503. &\textsf{Is{\_}Def{\_}Stab{\_}Written : TDefStabStatus}&
  1504. Can be one of the following states : (\textsf{Not{\_}Written,
  1505. written, Being{\_}Written}) which indicates if the debug information
  1506. for this type has been defined or not. \\
  1507. &\textsf{GlobalNb : Longint;}&
  1508. Internal stabs debug information type signature (each type definition has a
  1509. numeric signature). \\
  1510. &\textsf{end;}& \\
  1511. \hline
  1512. \end{tabular*}
  1513. \subsubsection{file definition (TFileDef)}
  1514. \label{subsubsec:mylabel6}
  1515. The file definition can occur in only some rare instances, when a
  1516. \textsf{file of }\textsf{\textit{type}} is parsed, a file definition of that
  1517. type will be created. Furthermore, internally, a definition for a
  1518. \textbf{Text} file type and \textbf{untyped} File type are created when the
  1519. system unit is loaded. These types are always defined when compiling any
  1520. unit or program.
  1521. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{8.5cm}|}
  1522. \hline
  1523. \textsf{TYPE}& & \\
  1524. \xspace pFileDef = & \^{} TFileDef; & \\
  1525. \xspace \textsf{TFileDef} = & \textbf{Object}(TDef) & \\
  1526. &\textsf{FileTyp : TFileTyp;}&
  1527. Indicates what type of file definition it is (\textsf{text},
  1528. \textsf{untyped} or \textsf{typed}). \\
  1529. &\textsf{TypedFileType : TType;}&
  1530. In the case of a typed file definition, definition of the type of
  1531. the file \\
  1532. &\textsf{end;}& \\
  1533. \hline
  1534. \end{tabular*}
  1535. \subsubsection{formal definition (TFormalDef)}
  1536. \label{subsubsec:formal}
  1537. \subsubsection{forward definition (TForwardDef)}
  1538. \label{subsubsec:forward}
  1539. The forward definition is created, when a type is declared before an actual
  1540. definition exists. This is the case, when, for example \textsf{type
  1541. pmyobject = \ tmyobject}, while \textsf{tmyobject} has yet to be defined.
  1542. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{6.5cm}|}
  1543. \hline
  1544. \textsf{TYPE} & & \\
  1545. \xspace pForwardDef = & \^{} TForwardDef; & \\
  1546. \xspace \textsf{TForwardDef} = & \textbf{Object}(TDef) & \\
  1547. &\textsf{toSymName : String;}&
  1548. The symbol name for this forward declaration (the actual real
  1549. definition does not exist yet) \\
  1550. &\textsf{ForwardPos : TFilePosInfo;}&
  1551. Indicates file position where this forward definition was declared. \\
  1552. &\textsf{end;}& \\
  1553. \hline
  1554. \end{tabular*}
  1555. \subsubsection{error definition (TErrorDef)}
  1556. \label{subsubsec:mylabel7}
  1557. This definition is actually an empty definition entry. When the parser
  1558. encounters an error when parsing a definition instead of putting nothing in
  1559. the type for a symbol, it puts this entry. This avoids illegal memory
  1560. accesses later in parsing.
  1561. \subsubsection{pointer definition (TPointerDef)}
  1562. \label{subsubsec:pointer}
  1563. The pointer definition is used for distinguishing between different types of
  1564. pointers in the compiler, and are created at each \textsf{\ typename}
  1565. parsing construct found.
  1566. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{9cm}|}
  1567. \hline
  1568. \textsf{TYPE} & & \\
  1569. \xspace pPointerDef = & \^{} TPointerDef; & \\
  1570. \xspace \textsf{TPointerDef} = & \textbf{Object}(TDef) & \\
  1571. &\textsf{Is{\_}Far : Boolean;}&
  1572. Used to indicate if this is a far pointer or not (this flag is
  1573. cpu-specific) \\
  1574. &\textsf{PointerType : TType;}&
  1575. This indicates to what type definition this pointer points to. \\
  1576. &\textsf{end;}& \\
  1577. \hline
  1578. \end{tabular*}
  1579. \subsubsection{object definition (TObjectDef)}
  1580. \label{subsubsec:object}
  1581. The object definition is created each time an object declaration is found in
  1582. the type declaration section.
  1583. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{5.5cm}|}
  1584. \hline
  1585. \textsf{TYPE}& & \\
  1586. \xspace pObjectDef = & \^{} TObjectDef; & \\
  1587. \xspace \textsf{TObjectDef} = & \textbf{Object}(TDef) & \\
  1588. &\textsf{ChildOf : pObjectDef;}&
  1589. This is a pointer to the parent object definition. It is set to nil,
  1590. if this object definition has no parent. \\
  1591. &\textsf{ObjName : pString;}&
  1592. This is the object name \\
  1593. &\textsf{SymTable : pSymTable;}&
  1594. This is a pointer to the symbol table entries within this object. \\
  1595. &\textsf{PbjectOptions : TObjectOptions;}&
  1596. The options for this object, see the following table for the
  1597. possible options for the object. \\
  1598. &\textsf{VMT{\_}Offset : Longint;}&
  1599. This is the offset from the start of the object image in memory
  1600. where the virtual method table is located. \\
  1601. &\textsf{Writing{\_}Class{\_}Record{\_}Stab : Boolean;}& \\
  1602. &\textsf{end;}& \\
  1603. \hline
  1604. \end{tabular*}
  1605. \begin{longtable}{|l|p{10cm}|}
  1606. \hline
  1607. Object Options(TObjectOptions) & Description \\
  1608. \hline
  1609. \endhead
  1610. \hline
  1611. \endfoot
  1612. \textsf{oo{\_}is{\_}class}&
  1613. This is a delphi styled class declaration, and not a Turbo Pascal
  1614. object. \\
  1615. \textsf{oo{\_}is{\_}forward}&
  1616. This flag is set to indicate that the object has been declared in a
  1617. type section, but there is no implementation yet. \\
  1618. \textsf{oo{\_}has{\_}virtual}&
  1619. This object / class contains virtual methods \\
  1620. \textsf{oo{\_}has{\_}private}&
  1621. This object / class contains private fields or methods \\
  1622. \textsf{oo{\_}has{\_}protected}&
  1623. This object / class contains protected fields or methods \\
  1624. \textsf{oo{\_}has{\_}constructor}&
  1625. This object / class has a constructor method \\
  1626. \textsf{oo{\_}has{\_}destructor}&
  1627. This object / class has a destructor method \\
  1628. \textsf{oo{\_}has{\_}vmt}&
  1629. This object / class has a virtual method table \\
  1630. \textsf{oo{\_}has{\_}msgstr}&
  1631. This object / class contains one or more message handlers \\
  1632. \textsf{oo{\_}has{\_}msgint}&
  1633. This object / class contains one or more message handlers \\
  1634. \textsf{oo{\_}has{\_}abstract}&
  1635. This object / class contains one or more abstract methods \\
  1636. \textsf{oo{\_}can{\_}have{\_}published}&
  1637. the class has runtime type information, i.e. you can publish
  1638. properties \\
  1639. \textsf{oo{\_}cpp{\_}class}&
  1640. the object/class uses an C++ compatible class layout \\
  1641. \textsf{oo{\_}interface}&
  1642. this class is a delphi styled interface
  1643. \end{longtable}
  1644. \subsubsection{class reference definition (TClassRefDef)}
  1645. \label{subsubsec:class}
  1646. \subsubsection{array definition (TArrayDef)}
  1647. \label{subsubsec:array}
  1648. This definition is created when an array type declaration is parsed. It
  1649. contains all the information necessary for array type checking and code
  1650. generation.
  1651. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{8.4cm}|}
  1652. \hline
  1653. \textsf{TYPE}& & \\
  1654. \xspace pArrayDef = & \^{} TArrayDef; & \\
  1655. \xspace \textsf{TArrayDef} = & \textbf{Object}(TDef) & \\
  1656. &\textsf{IsVariant : Boolean;}& \\
  1657. &\textsf{IsConstructor : Boolean;}& \\
  1658. &\textsf{RangeNr: Longint;}&
  1659. Label number associated with the index values when range checking is
  1660. on \\
  1661. &\textsf{LowRange : Longint;}&
  1662. The lower index range of the array definition \\
  1663. &\textsf{HighRange : Longint;}&
  1664. The higher index range of the array definition \\
  1665. &\textsf{ElementType : TType;}&
  1666. The type information for the elements of the array \\
  1667. &\textsf{RangeType : TType;}&
  1668. The type information for the index ranges of the array \\
  1669. &\textsf{IsArrayofConst : Boolean;}& \\
  1670. &\textsf{end;}& \\
  1671. \hline
  1672. \end{tabular*}
  1673. \subsubsection{record definition (TRecordDef)}
  1674. \label{subsubsec:record}
  1675. The record definition entry is created each time a record type declaration
  1676. is parsed. It contains the symbol table to the elements in the record.
  1677. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{8.7cm}|}
  1678. \hline
  1679. \textsf{TYPE} & & \\
  1680. \xspace pRecordDef = & \^{} TRecordDef; & \\
  1681. \xspace \textsf{TRecordDef} = & \textbf{Object}(TDef) & \\
  1682. &\textsf{SymTable : PSymTable;}&
  1683. This is a pointer to the symbol table entries within this record. \\
  1684. &\textsf{end;}& \\
  1685. \hline
  1686. \end{tabular*}
  1687. \subsubsection{ordinal definition (TOrdDef)}
  1688. \label{subsubsec:ordinal}
  1689. This type definition is the one used for all ordinal values such as char,
  1690. bytes and other numeric integer type values. Some of the predefined type
  1691. definitions are automatically created and loaded when the compiler starts.
  1692. Others are created at compile time, when declared.
  1693. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{9cm}|}
  1694. \hline
  1695. \textsf{TYPE} & & \\
  1696. \xspace pOrdDef = & \^{} TOrdDef; & \\
  1697. \xspace \textsf{TOrdDef} = & \textbf{Object}(TDef) & \\
  1698. &\textsf{Low : Longint;}&
  1699. The minimum value of this ordinal type \\
  1700. &\textsf{High : Longint;}&
  1701. The maximum value of this ordinal type \\
  1702. &\textsf{Typ : TBaseType;}&
  1703. The type of ordinal value (cf. table \ref{tbasetype}) \\
  1704. &\textsf{end;}& \\
  1705. \hline
  1706. \end{tabular*}
  1707. \begin{longtable}{|l|p{10cm}|}
  1708. \caption{Base types}\label{tbasetyp}\\
  1709. \hline
  1710. Base ordinal type (TBaseType) & Description \\
  1711. \hline
  1712. \endfirsthead
  1713. \caption{Base types (continued)}\\
  1714. \hline
  1715. Base ordinal type (TBaseType) & Description \\
  1716. \hline
  1717. \endhead
  1718. \hline
  1719. \endfoot
  1720. \textsf{uauto} & user defined ordinal type definition \\
  1721. \textsf{uvoid} & Represents a void return value or node \\
  1722. \textsf{uchar} & ASCII character (1 byte) \\
  1723. \textsf{u8bit} & unsigned 8-bit value \\
  1724. \textsf{u16bit}& unsigned 16-bit value \\
  1725. \textsf{u32bit}& unsigned 32-bit value \\
  1726. \textsf{s16bit}& signed 16-bit value \\
  1727. \textsf{s32bit}& signed 32-bit value \\
  1728. \textsf{bool8bit}& boolean 8-bit value \\
  1729. \textsf{bool16bit}& boolean 16-bit value \\
  1730. \textsf{bool32bit}& boolean 32-bit value \\
  1731. \textsf{\textit{u64bit}}&
  1732. \textit{unsigned 64-bit value (not fully supported/tested)} \\
  1733. \textsf{s64bit}& signed 64-bit value \\\textsf{\textit{uwidechar}}&
  1734. \textit{Currently not supported and unused} \\
  1735. \end{longtable}
  1736. \subsubsection{float definition (TFloatDef)}
  1737. \label{subsubsec:float}
  1738. This type definition is the one used for all floating point values such as
  1739. SINGLE, DOUBLE. Some of the predefined type definitions are automatically
  1740. created and loaded when the compiler starts.
  1741. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{9cm}|}
  1742. \hline
  1743. \textsf{TYPE} & & \\
  1744. \xspace pFloatDef = & \^{} TFloatDef; & \\
  1745. \xspace \textsf{TFloatDef} = & \textbf{Object}(TDef) & \\
  1746. &\textsf{Typ : TFloatType;}&
  1747. The type of floating point value (cf. table \ref{tfloattype}). \\
  1748. &\textsf{end;}& \\
  1749. \hline
  1750. \end{tabular*}
  1751. \begin{longtable}{|l|p{10cm}|}
  1752. \caption{Floating point types}\label{tfloattype}\\
  1753. \hline
  1754. Base floating point type (TFloatType) & Description \\
  1755. \hline
  1756. \endfirsthead
  1757. \hline
  1758. Base floating point type (TFloatType) & Description \\
  1759. \hline
  1760. \endhead
  1761. \hline
  1762. \endfoot
  1763. \textsf{s32real}& IEEE Single precision floating point value \\
  1764. \textsf{s64real}& IEEE Double precision floating point value \\
  1765. \textsf{s80real}&
  1766. Extended precision floating point value (cpu-specific,
  1767. usually maps to double) \\
  1768. \textsf{s64comp}& 63-bit signed value, using 1 bit for sign indication \\
  1769. \textsf{\textit{f16bit}}& \textit{Unsupported} \\
  1770. \textsf{\textit{f32bit}}& \textit{Unsupported} \\
  1771. \end{longtable}
  1772. \subsubsection{abstract procedure definition (tabstractprocdef)}
  1773. \label{subsubsec:abstract}
  1774. This is the base of all routine type definitions. This object is abstract,
  1775. and is not directly used in a useful way. The derived object of this object
  1776. are used for the actual parsing process.
  1777. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{5.2cm}|}
  1778. \hline
  1779. \textsf{TYPE}& & \\
  1780. \xspace pAbstractProcDef = & \^{} TAbstractProcDef; & \\
  1781. \xspace \textsf{TAbstractProcDef} = & \textbf{Object}(TDef) & \\
  1782. &\textsf{SymtableLevel : byte;}& \\
  1783. &\textsf{Fpu{\_}Used : Byte;}&
  1784. Number of floating point registers used in this routine \\
  1785. &\textsf{RetType : TType;}&
  1786. Type information for the return value \par (uvoid if it returns nothing) \\
  1787. &\textsf{ProcTypeOption : TProcTypeOption;} &
  1788. Indicates the type of routine it is (cf table \ref{tproctypeoption}). \\
  1789. &\textsf{ProcCallOptions : TProcCallOptions;} &
  1790. Indicates the calling convention of the routine (cf. table \ref{tproccalloptions}). \\
  1791. &\textsf{ProcOptions : TProcOptions;}&
  1792. Indicates general procedure options. \par (cf. table \ref{tprocoptions}). \\
  1793. &\textsf{Para : pLinkedList;}&
  1794. This is a linked list of parameters (pparaitem list) \\
  1795. &\textsf{end;}& \\
  1796. \hline
  1797. \end{tabular*}
  1798. \begin{longtable}{|l|p{10cm}|}
  1799. \caption{Procedure type options}\label{tproctypeoption}\\
  1800. \hline
  1801. Procedure options \par (TProcTypeOption)& Description \\
  1802. \hline
  1803. \endfirsthead
  1804. \caption{Procedure type options (continued)}\\
  1805. \hline
  1806. Procedure options \par (TProcTypeOption)& Description \\
  1807. \hline
  1808. \endhead
  1809. \hline
  1810. \endfoot
  1811. \textsf{poType{\_}ProgInit}&
  1812. Routine is the program entry point (defined as `\textsf{main}' in
  1813. the compiler). \\
  1814. \textsf{poType{\_}UnitInit}&
  1815. Routine is the unit initialization code \par (defined as
  1816. unitname\textsf{{\_}init} in the compiler \\
  1817. \textsf{poType{\_}UnitFinalize}&
  1818. Routine is the unit exit code \par (defined as
  1819. unitname\textsf{{\_}finalize} in the compiler) \\
  1820. \textsf{poType{\_}Constructor}&
  1821. Routine is an object or class constructor \\
  1822. \textsf{poType{\_}Destructor}&
  1823. Routine is an object or class destructor \\
  1824. \textsf{poType{\_}Operator}&
  1825. Procedure is an operator \\
  1826. \end{longtable}
  1827. \begin{longtable}{|l|p{10cm}|}
  1828. \caption{Procedure call options}\label{tproccalloptions}\\
  1829. \hline
  1830. call options \par (TProcCallOptions) & Description \\
  1831. \hline
  1832. \endfirsthead
  1833. \caption{Procedure call options (continued)}\\
  1834. \hline
  1835. call options \par (TProcCallOptions) & Description \\
  1836. \hline
  1837. \endhead
  1838. \hline
  1839. \endfoot
  1840. \textsf{pocall{\_}clearstack}&
  1841. The routine caller clears the stack upon return \\
  1842. \textsf{pocall{\_}leftright}&
  1843. Send parameters to routine from left to right \\
  1844. \textsf{pocall{\_}cdecl}&
  1845. Passing parameters is done using the GCC alignment scheme, passing
  1846. parameter values is directly copied into the stack space \\
  1847. \textsf{\textit{pocall{\_}register}}&
  1848. \textit{unused (Send parameters via registers)} \\
  1849. \textsf{pocall{\_}stdcall}&
  1850. Passing parameters is done using GCC alignment scheme, standard GCC registers
  1851. are saved \\
  1852. \textsf{\textit{pocall{\_}safecall}}&
  1853. Standard GCC registers are saved\\
  1854. \textsf{\textit{pocall{\_}palmsssyscall}}&
  1855. This is a special syscall macro for embedded system \\
  1856. \textsf{\textit{pocall{\_}system}}&
  1857. \textit{unused} \\
  1858. \textsf{pocall{\_}inline}&
  1859. Routine is an inline assembler macro (not a true call) \\
  1860. \textsf{pocall{\_}internproc}&
  1861. System unit code generator helper routine \\
  1862. \textsf{pocall{\_}internconst}&
  1863. System unit code generator helper macro routine \\
  1864. \end{longtable}
  1865. \begin{longtable}{|l|p{10cm}|}
  1866. \caption{Procedure options}\label{tprocoptions}\\
  1867. \hline
  1868. routine options (TProcOptions) & Description \\
  1869. \hline
  1870. \endfirsthead
  1871. \caption{Procedure options (continued)}\\
  1872. \hline
  1873. routine options (TProcOptions) & Description \\
  1874. \hline
  1875. \endhead
  1876. \hline
  1877. \endfoot
  1878. \textsf{po{\_}classmethod} & This is a class method \\
  1879. \textsf{po{\_}virtualmethod }& This is a virtual method \\
  1880. \textsf{po{\_}abstractmethod}& This is an abstract method \\
  1881. \textsf{po{\_}staticmethod} & This is a static method \\
  1882. \textsf{po{\_}overridingmethod}&
  1883. This is an overriden method (with po{\_}virtual flag usually) \\
  1884. \textsf{po{\_}methodpointer}&
  1885. This is a method pointer (not a normal routine pointer) \\
  1886. \textsf{po{\_}containsself}&
  1887. self is passed explicitly as a parameter to the method \\
  1888. \textsf{po{\_}interrupt}&
  1889. This routine is an interrupt handler \\
  1890. \textsf{po{\_}iocheck}&
  1891. IO checking should be done after a call to the procedure \\
  1892. \textsf{po{\_}assembler}&
  1893. The routine is in assembler \\
  1894. \textsf{po{\_}msgstr}&
  1895. method for string message handling \\
  1896. \textsf{po{\_}msgint}&
  1897. method for int message handling \\
  1898. \textsf{po{\_}exports}&
  1899. Routine has export directive \\
  1900. \textsf{po{\_}external}&
  1901. Routine is external (in other object or lib) \\
  1902. \textsf{po{\_}savestdregs}&
  1903. Routine entry should save all registers used by GCC \\
  1904. \textsf{po{\_}saveregisters}&
  1905. Routine entry should save all registers \\
  1906. \textsf{po{\_}overload}&
  1907. Routine is declared as being overloaded \\
  1908. \end{longtable}
  1909. \subsubsection{procedural variable definition (TProcVarDef)}
  1910. \label{subsubsec:procedural}
  1911. This definition is created when a procedure variable type is declared. It
  1912. gives information on the type of a procedure, and is used when assigning and
  1913. directly calling a routine through a pointer.
  1914. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{7.8cm}|}
  1915. \hline
  1916. \textsf{TYPE} & & \\
  1917. \xspace pProcVarDef = & \^{} TProcVarDef; & \\
  1918. \xspace \textsf{TProcVarDef} = & \textbf{Object}(TAbstractProcDef) & \\
  1919. & \textsf{end;}&\\
  1920. \hline
  1921. \end{tabular*}
  1922. \subsubsection{procedure definition (TProcDef)}
  1923. \label{subsubsec:mylabel8}
  1924. When a procedure head is parsed, the definition of the routine is created.
  1925. Thereafter, other fields containing information on the definition of the
  1926. routine are populated as required.
  1927. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{7.8cm}|}
  1928. \hline
  1929. \textsf{TYPE} & & \\
  1930. \xspace pProcDef = & \^{} TProcDef; & \\
  1931. \xspace \textsf{TProcDef} = & \textbf{Object}(TAbstractProcDef) & \\
  1932. &\textsf{ForwardDef : Boolean;}& TRUE if this is a forward definition \\
  1933. &\textsf{InterfaceDef: Boolean;} & \\
  1934. &\textsf{ExtNumber : Longint;} & \\
  1935. &\textsf{MessageInf : TMessageInf;} & \\
  1936. &\textsf{NextOverloaded : pProcDef;} & \\
  1937. &\textsf{FileInfo : TFilePosInfo;} &
  1938. Position in source code for the declaration of this routine. Used
  1939. for error management. \\
  1940. &\textsf{Localst : pSymTable;} & The local variables symbol table \\
  1941. &\textsf{Parast: pSymTable;}& The parameter symbol table \\
  1942. &\textsf{ProcSym : pProcSym;}& Points to owner of this definition \\
  1943. &\textsf{LastRef : pRef;}& \\
  1944. &\textsf{DefRef: pRef;}& \\
  1945. &\textsf{CrossRef : pRef;}& \\
  1946. &\textsf{LastWritten : pRef;}& \\
  1947. &\textsf{RefCount : Longint;}& \\
  1948. &\textsf{{\_}Class : ProbjectDef;}& \\
  1949. &\textsf{Code : Pointer;}&
  1950. The actual code for the routine (only for inlined routines) \\
  1951. &\textsf{UsedRegisters : TRegisterSet;}&
  1952. The set of registers used in this routine \\
  1953. &\textsf{HasForward : Boolean;}& \\
  1954. &\textsf{Count: Boolean;}& \\
  1955. &\textsf{Is{\_}Used : Boolean;}& \\
  1956. &\textsf{end;}& \\
  1957. \hline
  1958. \end{tabular*}
  1959. \subsubsection{string definition (TStringDef)}
  1960. \label{subsubsec:string}
  1961. This definition represents all string types as well as derived types. Some
  1962. of the default string type definitions are loaded when the compiler starts
  1963. up. Others are created at compile time as they are declared with a specific
  1964. length type.
  1965. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{8cm}|}
  1966. \hline
  1967. \textsf{TYPE}& & \\
  1968. \xspace pStringDef = & \^{} TStringDef; & \\
  1969. \xspace \textsf{TStringDef} = & \textbf{Object}(TDef) & \\
  1970. &\textsf{String{\_}Typ : TStringType;}&
  1971. Indicates the string type definition (cf. \ref{tstringtype}) \\
  1972. &\textsf{Len : Longint;}&
  1973. This is the maximum length which can have the string \\
  1974. &\textsf{end;}& \\
  1975. \hline
  1976. \end{tabular*}
  1977. \begin{longtable}{|l|p{10cm}|}
  1978. \caption{string types}\label{tstringtype}\\
  1979. \hline
  1980. String type \par (TStringType) & Description \\
  1981. \hline
  1982. \endfirsthead
  1983. \caption{string types (continued)}\\
  1984. \hline
  1985. String type \par (TStringType) & Description \\
  1986. \hline
  1987. \endhead
  1988. \hline
  1989. \endfoot
  1990. \textsf{st{\_}default}&
  1991. Depends on current compiler switches, can either be a
  1992. st{\_}ShortString or st{\_}AnsiString \\
  1993. \textsf{st{\_}shortstring}&
  1994. short string (length byte followed by actual ASCII characters (1
  1995. byte/char)) \\
  1996. \textsf{st{\_}longstring}&
  1997. long string (length longint followed by actual ASCII characters (1
  1998. byte/char)) \\
  1999. \textsf{st{\_}ansistring}&
  2000. long string garbage collected (pointer to a length, reference count
  2001. followed by actual ASCII characters (1 byte/char)) \\
  2002. \textsf{\textit{st{\_}widestring}}&
  2003. \textit{long string garbage collected (pointer to a length,
  2004. reference count followed by actual unicode characters (1
  2005. word/char (utf16)))} \\
  2006. \end{longtable}
  2007. \subsubsection{enumeration definition (TEnumDef)}
  2008. \label{subsubsec:mylabel9}
  2009. An enumeration definition is created each time an enumeration is declared
  2010. and parsed. Each element in the enumeration will be added to the linked list
  2011. of symbols associated with this enumeration, and this symbol table will then
  2012. be attached to the enumeration definition.
  2013. \begin{tabular*}{6,5in}{|l@{\extracolsep{\fill}}lp{6,5cm}|}
  2014. \hline
  2015. \textsf{TYPE} & & \\
  2016. \xspace \textsf{pEnumDef} &= \^{} \textbf{TEnumDef};& \\
  2017. \xspace \textsf{TEnumDef} &= \textbf{object}(TDef) & \\
  2018. &\textsf{\textit{Has{\_}Jumps : Boolean;}}&
  2019. \textit{Currently unused} \\
  2020. &\textsf{MinVal : Longint;}&
  2021. Value of the first element in the enumeration \\
  2022. &\textsf{MaxVal : Longint;}&
  2023. Value of the last element in the enumeration \\
  2024. &\textsf{FirstEnum : pEnumSym;}&
  2025. Pointer to a linked list of elements in the enumeration, each with
  2026. its name and value. \\
  2027. &\textsf{BaseDef : pEnumDef;}&
  2028. In the case where the enumeration is a subrange of another enumeration,
  2029. this gives information on the base range of the elements \\
  2030. &\textsf{end;}& \\
  2031. \hline
  2032. \end{tabular*}
  2033. \subsubsection{set definition (TSetDef)}
  2034. \label{subsubsec:mylabel10}
  2035. This definition is created when a set type construct is parsed (\textsf{set
  2036. of declaration}).
  2037. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{6,5cm}|}
  2038. \hline
  2039. \textsf{TYPE} & & \\
  2040. \xspace \textsf{pSetDef} &= \^{} \textbf{TSetDef};& \\
  2041. \xspace \textsf{TSetDef} &= \textbf{object}(TDef) & \\
  2042. &\textsf{SetType : TSetType;}&
  2043. Indicates the storage type of the set (Cf. table \ref{tsettype}). \\
  2044. &\textsf{ElementType : TType;}&
  2045. Points the type definition and symbol table to the elements in the set. \\
  2046. &\textsf{end;}& \\
  2047. \hline
  2048. \end{tabular*}
  2049. \begin{longtable}{|l|p{10cm}|}
  2050. \caption{set types}\label{tsettype}\\
  2051. \hline
  2052. set type (TSetType) & Description \\
  2053. \hline
  2054. \endfirsthead
  2055. \caption{set types (continued)}\\
  2056. \hline
  2057. set type (TSetType) & Description \\
  2058. \hline
  2059. \endhead
  2060. \hline
  2061. \endfoot
  2062. \textsf{NormSet}&
  2063. Normal set of up to 256 elements (32 byte storage space required) \\
  2064. \textsf{SmallSet}&
  2065. Small set of up to 32 elements (4 byte storage space) \\
  2066. \textsf{\textit{VarSet}}&
  2067. \textit{Variable number of element set (storage size is dependent on number
  2068. of elements) (currently unused and unsupported)} \\
  2069. \end{longtable}
  2070. \subsection{Definition interface}
  2071. \label{subsec:definition}
  2072. \subsubsection{routines}
  2073. \begin{function}{TDef.Size}
  2074. \Declaration
  2075. Function TDef.Size : Longint;
  2076. \Description
  2077. This method returns the true size of the memory space required in bytes for
  2078. this type definition (after alignment considerations).
  2079. \end{function}
  2080. \begin{function}{TDef.Alignment}
  2081. \Declaration
  2082. Function TDef.Alignment : Longint;
  2083. \Description
  2084. This method returns the alignment of the data for complex types such as
  2085. records and objects, otherwise returns 0 or 1 (no alignment).
  2086. \end{function}
  2087. \section{The parser}
  2088. \label{sec:mylabel5}
  2089. The task of the parser is to read the token fed by the scanner, and make
  2090. sure that the pascal syntax is respected. It also populates the symbol
  2091. table, and creates the intermediate nodes (the tree) which will be used by
  2092. the code generator.
  2093. An overview of the parsing process, as well as its relationship with the
  2094. tree the type checker and the code generator is shown in the following
  2095. diagram:
  2096. \subsection{Module information}
  2097. \label{subsec:module}
  2098. Each module being compiled, be it a library , unit or main program has some
  2099. information which is required. This is stored in the tmodule object in
  2100. memory. To avoid recompilation of already compiled module, the dependencies
  2101. of the modules is stored in a PPU file, which makes it easier to determine
  2102. which modules to recompile.
  2103. \begin{longtable}{|l@{\extracolsep{\fill}}lp{6cm}|}
  2104. \hline
  2105. \endhead
  2106. \hline
  2107. \endfoot
  2108. %\begin{tabular*}
  2109. \textsf{TYPE}& & \\
  2110. \xspace pModule = & \^{} TModule; & \\
  2111. \xspace \textsf{TModule} = & \textbf{Object}(TLinkedList\_Item) & \\
  2112. &\textsf{PPUFile : pPPUFile;}& Pointer to PPU file object (unit file) \\
  2113. &\textsf{Crc : Longint;}& CRC-32 bit of the whole PPU file \\
  2114. &\textsf{Interface{\_}CRC : Longint;}& CRC-32 bit of the interface part of the PPU file \\
  2115. &\textsf{Flags: Longint;}& Unit file flags \\
  2116. &\textsf{Compiled: Boolean;}& TRUE if module is already compiled \\
  2117. &\textsf{Do{\_}Reload : Boolean;} & TRUE if the PPU file must be reloaded \\
  2118. &\textsf{Do{\_}Assemble : Boolean;} & Only assemble, don't recompile unit \\
  2119. &\textsf{Sources{\_}Avail : Boolean;} & TRUE if all sources of module are available \\
  2120. &\textsf{Sources{\_}Checked : Boolean;} & TRUE if the sources has already been checked \\
  2121. &\textsf{Is{\_}Unit: Boolean;} & TRUE if this is a unit (otherwise a library or a main program) \\
  2122. &\textsf{In{\_}Compile: Boolean;} & module is currently being recompiled \\
  2123. &\textsf{In{\_}Second{\_}Compile: Boolean;}& module is being compiled for second time \\
  2124. &\textsf{In{\_}Second{\_}Load: Boolean;} & module is being reloaded a second time \\
  2125. &\textsf{In{\_}Implementation : Boolean;}& currently compiling implementation part (units only) \\
  2126. &\textsf{In{\_}Global : Boolean;} & currently compiling implementation part (units only) \\
  2127. &\textsf{Recompile{\_}Reason : TRecompile{\_}Reason;}& Reason why module should be recompiled \\
  2128. &\textsf{Islibrary : Boolean;}& TRUE if this module is a shared library \\
  2129. &\textsf{Map : pUnitMap;} & Map of all used units for this unit \\
  2130. &\textsf{Unitcount : Word;} & Internal identifier of unit (for GDB support) \\
  2131. &\textsf{Unit{\_}index : Eord;} & \\
  2132. &\textsf{Globalsymtable : Pointer;} & Symbol table for this module of externally visible symbols \\
  2133. &\textsf{Localsymtable : Pointer;} & Symbol table for this module of locally visible symbols \\
  2134. &\textsf{Scanner : Pointer;} & Scanner object pointer \\
  2135. &\textsf{Loaded{\_}From : pModule;} & Module which referred to this module \\
  2136. &\textsf{Uses{\_}Imports : Boolean;} & TRUE if this module imports symbols from a shared library \\
  2137. &\textsf{Imports : pLinkedList} & Linked list of imported symbols \\
  2138. &\textsf{{\_}Exports : pLinkedList;} & Linked list of exported symbols (libraries only) \\
  2139. &\textsf{SourceFiles : pFileManager;} & List of all source files for this module \\
  2140. &\textsf{ResourceFiles : TStringContainer;} & List of all resource files for this module \\
  2141. &\textsf{Used{\_}Units : TLinkedList; } & Information on units used by this module (pused{\_}unit) \\
  2142. &\textsf{Dependent{\_}Units : TLinkedList;}& \\
  2143. &\textsf{LocalUnitSearchPath,}& Search path for obtaining module source code \\
  2144. &\textsf{LocalObjectSearchPath,}& \\
  2145. &\textsf{LocalIncludeSearchPath,}& Search path for includes for this module \\
  2146. &\textsf{LocalLibrarySearchPath:TSearchPathList;}& \\
  2147. &\textsf{Path : pString;}& Path were module is located or created \\
  2148. &\textsf{OutputPath : pString;}& Path where object files (unit), executable (program) or shared library (library) is created \\
  2149. &\textsf{ModuleName : pString;}& Name of the module in uppercase \\
  2150. &\textsf{ObjFileName : pString;}& Full name of object file or executable file \\
  2151. &\textsf{AsmFileName : pString;}& Full name of the assembler file \\
  2152. &\textsf{PPUFileName : pString;}& Full name of the PPU file \\
  2153. &\textsf{StaticLibFilename : pString;}& Full name of the static library name (used when smart linking is used) \\
  2154. &\textsf{SharedLibFilename : pString;}& Filename of the output shared library (in the case of a library) \\
  2155. &\textsf{ExeFileName : pString;}& Filename of the output executable (in the case of a program) \\
  2156. &\textsf{AsmPrefix : pString;}& Filename prefix of output assembler files when using smartlinking \\
  2157. &\textsf{MainSource : pString;}& Name of the main source file \\
  2158. &\textsf{end;}& \\
  2159. %\end{tabular*}
  2160. \end{longtable}
  2161. \subsection{Parse types}
  2162. \label{subsec:parse}
  2163. \subsubsection{Entry}
  2164. \label{subsubsec:entry}
  2165. \begin{figure}
  2166. \begin{center}
  2167. \ifpdf
  2168. \includegraphics{arch8.pdf}
  2169. %\epsfig{file=arch8.png,width=\textwidth}
  2170. \else
  2171. \includegraphics[width=4.99in,height=8.36in]{arch8.eps}
  2172. \fi
  2173. \label{fig8}
  2174. \caption{Parser - Scanner flow}
  2175. \end{center}
  2176. \end{figure}
  2177. \subsubsection{program or library parsing }
  2178. \subsubsection{unit parsing }
  2179. \label{subsubsec:mylabel12}
  2180. \subsubsection{routine parsing }
  2181. \label{subsubsec:routine}
  2182. \subsubsection{label declarations }
  2183. \label{subsubsec:mylabel13}
  2184. \subsubsection{constant declarations}
  2185. \label{subsubsec:mylabel14}
  2186. \subsubsection{type declarations}
  2187. \label{subsubsec:mylabel15}
  2188. \subsubsection{variable declarations}
  2189. \label{subsubsec:mylabel16}
  2190. \subsubsection{thread variable declarations}
  2191. \label{subsubsec:thread}
  2192. \subsubsection{resource string declarations}
  2193. \label{subsubsec:resource}
  2194. \subsubsection{exports declaration}
  2195. \label{subsubsec:exports}
  2196. \subsubsection{expression parsing }
  2197. \label{subsubsec:expression}
  2198. \subsubsection{typed constant declarations}
  2199. \label{subsubsec:mylabel17}
  2200. \subsection{Parser interface}
  2201. \label{subsec:parser}
  2202. \subsubsection{variables}
  2203. \begin{variable}{AktProcSym}
  2204. \Declaration
  2205. Var AktProcSym : pProcSym;
  2206. \Description
  2207. Pointer to the symbol information for the routine currently being parsed.
  2208. \end{variable}
  2209. \begin{variable}{LexLevel}
  2210. \Declaration
  2211. var LexLevel : longint;
  2212. \Description
  2213. Level of code currently being parsed and compiled \par 0 = for main program
  2214. \par 1 = for subroutine \par 2 = for local / nested subroutines.
  2215. \end{variable}
  2216. \begin{variablel}{Current{\_}Module}{currentmodule}
  2217. \Declaration
  2218. Var Current{\_}Module : pModule;
  2219. \Description
  2220. Information on the current module (program, library or unit) being compiled.
  2221. \end{variablel}
  2222. The following variables are default type definitions which are created each
  2223. time compilation begins (default system-unit definitions), these definitions
  2224. should always be valid:
  2225. \begin{variable}{VoidDef}
  2226. \Declaration
  2227. Var VoidDef : pOrdDef;
  2228. \Description
  2229. Pointer to nothing type
  2230. \Notes
  2231. This is loaded as a default supported type for the compiler
  2232. \end{variable}
  2233. \begin{variable}{cCharDef}
  2234. \Declaration
  2235. Var cCharDef : pOrdDef;
  2236. \Description
  2237. Type definition for a character (\textsf{char})
  2238. \Notes
  2239. This is loaded as a default supported type for the compiler
  2240. \end{variable}
  2241. \begin{variable}{cWideCharDef}
  2242. \Declaration
  2243. Var cWideCharDef : pOrdDef;
  2244. \Description
  2245. Type definition for a unicode character (\textsf{widechar})
  2246. \Notes
  2247. This is loaded as a default supported type for the compiler
  2248. \end{variable}
  2249. \begin{variable}{BoolDef}
  2250. \Declaration
  2251. Var BoolDef : pOrdDef;
  2252. \Description
  2253. Type definition for a boolean value (\textsf{boolean})
  2254. \Notes
  2255. This is loaded as a default supported type for the compiler
  2256. \end{variable}
  2257. \begin{variable}{u8BitDef}
  2258. \Declaration
  2259. Var u8BitDef : pOrdDef;
  2260. \Description
  2261. Type definition for an 8-nit unsigned value (\textsf{byte})
  2262. \Notes
  2263. This is loaded as a default supported type for the compiler
  2264. \end{variable}
  2265. \begin{variable}{u16BitDef}
  2266. \Declaration
  2267. Var u16BitDef : pOrdDef;
  2268. \Description
  2269. Type definition for an unsigned 16-bit value (\textsf{word})
  2270. \Notes
  2271. This is loaded as a default supported type for the compiler
  2272. \end{variable}
  2273. \begin{variable}{u32BitDef}
  2274. \Declaration
  2275. Var u32BitDef : pOrdDef;
  2276. \Description
  2277. Type definition for an unsigned 32-bit value (\textsf{cardinal})
  2278. \Notes
  2279. This is loaded as a default supported type for the compiler
  2280. \end{variable}
  2281. \begin{variable}{s32BitDef}
  2282. \Declaration
  2283. Var s32BitDef : pOrdDef;
  2284. \Description
  2285. Type definition for a signed 32-bit value (\textsf{longint})
  2286. \Notes
  2287. This is loaded as a default supported type for the compiler
  2288. \end{variable}
  2289. \begin{variable}{cu64BitDef}
  2290. \Declaration
  2291. Var cu64BitDef : pOrdDef;
  2292. \Description
  2293. Type definition for an unsigned 64-bit value (\textsf{qword})
  2294. \Notes
  2295. This is loaded as a default supported type for the compiler
  2296. \end{variable}
  2297. \begin{variable}{cs64BitDef}
  2298. \Declaration
  2299. Var cs64BitDef : pOrdDef;
  2300. \Description
  2301. Type definition for a signed 64-bit value (\textsf{int64})
  2302. \Notes
  2303. This is loaded as a default supported type for the compiler
  2304. \end{variable}
  2305. The following variables are default type definitions which are created each
  2306. time compilation begins (default system-unit definitions), these definitions
  2307. should always be valid:
  2308. \begin{variable}{s64FloatDef}
  2309. \Declaration
  2310. Var s64FloatDef : pFloatDef;
  2311. \Description
  2312. Type definition for a 64-bit IEEE floating point type (\textsf{double})
  2313. \Notes
  2314. This is loaded as a default supported type for the compiler. This might not
  2315. actually really point to the double type if the cpu does not support it.
  2316. \end{variable}
  2317. \begin{variable}{s32FloatDef}
  2318. \Declaration
  2319. Var s32FloatDef : pFloatDef;
  2320. \Description
  2321. Type definition for a 32-bit IEEE floating point type (\textsf{single})
  2322. \Notes
  2323. This is loaded as a default supported type for the compiler. This might not
  2324. actually really point to the single type if the cpu does not support it.
  2325. \end{variable}
  2326. \begin{variable}{s80FloatDef}
  2327. \Declaration
  2328. Var s80FloatDef : pFloatDef;
  2329. \Description
  2330. Type definition for an extended floating point type (\textsf{extended})
  2331. \Notes
  2332. This is loaded as a default supported type for the compiler. This
  2333. might not actually really point to the extended type if the cpu does not
  2334. support it.
  2335. \end{variable}
  2336. \begin{variable}{s32FixedDef}
  2337. \Declaration
  2338. Var s32FixedDef : pFloatDef;
  2339. \Description
  2340. Type definition for a fixed point 32-bit value (\textsf{fixed})
  2341. \Notes
  2342. This is loaded as a default supported type for the compiler. This is
  2343. not supported officially in FPC 1.0
  2344. \end{variable}
  2345. The following variables are default type definitions which are created each
  2346. time compilation begins (default system-unit definitions), these definitions
  2347. should always be valid:
  2348. \begin{variable}{cShortStringDef}
  2349. \Declaration
  2350. Var cShortStringDef : pStringDef;
  2351. \Description
  2352. Type definition for a short string type (\textsf{shortstring})
  2353. \Notes
  2354. This is loaded as a default supported type for the compiler.
  2355. \end{variable}
  2356. \begin{variable}{cLongStringDef}
  2357. \Declaration
  2358. Var cLongStringDef : pStringDef;
  2359. \Description
  2360. Type definition for a long string type (\textsf{\textit{longstring}})
  2361. \Notes
  2362. This is loaded as a default supported type for the compiler.
  2363. \end{variable}
  2364. \begin{variable}{cAnsiStringDef}
  2365. \Declaration
  2366. Var cAnsiStringDef : pStringDef;
  2367. \Description
  2368. Type definition for an ansistring type (\textsf{ansistring})
  2369. \Notes
  2370. This is loaded as a default supported type for the compiler.
  2371. \end{variable}
  2372. \begin{variable}{cWideStringDef}
  2373. \Declaration
  2374. Var cWideStringDef : pStringDef;
  2375. \Description
  2376. Type definition for an wide string type (\textsf{\textit{widestring}})
  2377. \Notes
  2378. This is loaded as a default supported type for the compiler.
  2379. \end{variable}
  2380. \begin{variable}{OpenShortStringDef}
  2381. \Declaration
  2382. Var OpenShortStringDef : pStringDef;
  2383. \Description
  2384. Type definition for an open string type (\textsf{openstring})
  2385. \Notes
  2386. This is loaded as a default supported type for the compiler.
  2387. \end{variable}
  2388. \begin{variable}{OpenCharArrayDef}
  2389. \Declaration
  2390. Var OpenCharArrayDef : pArrayDef;
  2391. \Description
  2392. Type definition for an open char array type(\textsf{openchararray})
  2393. \Notes
  2394. This is loaded as a default supported type for the compiler.
  2395. \end{variable}
  2396. The following variables are default type definitions which are created each
  2397. time compilation begins (default system-unit definitions), these definitions
  2398. should always be valid:
  2399. \begin{variable}{VoidPointerDef}
  2400. \Declaration
  2401. Var VoidPointerDef : pPointerDef;
  2402. \Description
  2403. Type definition for a pointer which can point to anything (\textsf{pointer})
  2404. \Notes
  2405. This is loaded as a default supported type for the compiler
  2406. \end{variable}
  2407. \begin{variable}{CharPointerDef}
  2408. \Declaration
  2409. Var CharPointerDef : pPointerDef;
  2410. \Description
  2411. Type definition for a pointer which can point to characters (\textsf{pchar})
  2412. \Notes
  2413. This is loaded as a default supported type for the compiler
  2414. \end{variable}
  2415. \begin{variable}{VoidFarPointerDef}
  2416. \Declaration
  2417. Var VoidFarPointerDef : pPointerDef;
  2418. \Description
  2419. Type definition for a pointer which can point to anything
  2420. (intra-segment) (\textsf{far pointer})
  2421. \Notes
  2422. This is loaded as a default supported type for the compiler
  2423. \end{variable}
  2424. \begin{variable}{cFormalDef}
  2425. \Declaration
  2426. Var cFormalDef : pFormalDef;
  2427. \Notes
  2428. This is loaded as a default supported type for the compiler
  2429. \end{variable}
  2430. \begin{variable}{cfFileDef}
  2431. \Declaration
  2432. Var cfFileDef : pFileDef;
  2433. \Description This is the default file type (\textsf{file})
  2434. \Notes This is loaded as a default supported type for the compiler
  2435. \end{variable}
  2436. \section{The inline assembler parser}
  2437. \label{sec:mylabel6}
  2438. To be written.
  2439. \section{The code generator}
  2440. \label{sec:mylabel7}
  2441. \subsection{Introduction}
  2442. \label{subsec:introductioneratorer}
  2443. The code generator is responsible for creating the assembler output in form
  2444. of a linked list, taking as input the node created in the parser and the
  2445. 1$^{st}$ pass. Picture \seefig{fig9} shows an overview of the code generator
  2446. architecture:
  2447. \begin{figure}
  2448. \begin{center}
  2449. \ifpdf
  2450. \includegraphics{arch9.pdf}
  2451. %\epsfig{file=arch9.png,width=\textwidth}
  2452. \else
  2453. \includegraphics[width=5.68in,height=1.76in]{arch9.eps}
  2454. \fi
  2455. \label{fig:fig9}
  2456. \caption{Code generator architecture}
  2457. \end{center}
  2458. \end{figure}
  2459. The code generation is only done when a procedure body is parsed; the
  2460. interaction, between the 1$^{st}$ pass (type checking phase), the code
  2461. generation and the parsing process is show in the following diagram:
  2462. \begin{figure}
  2463. \ifpdf
  2464. \includegraphics{arch10.pdf}
  2465. %\epsfig{file=arch10.png,width=\textwidth}
  2466. \else
  2467. \includegraphics[width=6.95in,height=4.90in]{arch10.eps}
  2468. \fi
  2469. \label{fig:fig10}
  2470. \caption{Interaction between codegeneration and the parsing process}
  2471. \end{figure}
  2472. The \textsf{secondpass()} is actually a simple dispatcher. Each possible
  2473. tree type node (Cf. Tree types) is associated with
  2474. a second pass routine which is called using a dispatch table.
  2475. \subsection{Locations (cpubase.pas)}
  2476. \label{subsec:locations}
  2477. The code generator uses the tree location component to indicate the location
  2478. where the current node operands are located. This is then used by the code
  2479. generator to generate the appropriate instruction, all depending on the
  2480. location of the operand. The possible operand locations:
  2481. \begin{longtable}{|l|p{10cm}|}
  2482. \hline
  2483. Location define & Description \\
  2484. \hline
  2485. \endhead
  2486. \hline
  2487. \endfoot
  2488. \textsf{LOC{\_}INVALID}&
  2489. Invalid location (should never occur) \\
  2490. \textsf{LOC{\_}FPU}&
  2491. Floating point registers \\
  2492. \textsf{LOC{\_}REGISTER}&
  2493. Integer registers \\
  2494. \textsf{LOC{\_}MEM}&
  2495. Memory Location \\
  2496. \textsf{LOC{\_}REFERENCE}&
  2497. Constant node with constant value \\
  2498. \textsf{LOC{\_}JUMP}&
  2499. Label operand \\
  2500. \textsf{LOC{\_}FLAGS}&
  2501. Flags operand \\
  2502. \textsf{LOC{\_}CREGISTER}&
  2503. Constant integer register (when operand is in this
  2504. location, it should be considered as read-only) \\
  2505. \end{longtable}
  2506. Depending on the location type, a variable structure is defined indicating
  2507. more information on the operand. This is used by the code generator to
  2508. generate the exact instructions.
  2509. \subsubsection{LOC{\_}INVALID}
  2510. \label{subsubsec:mylabel18}
  2511. This location does not contain any related information, when this location
  2512. occurs, it indicates that the operand location was not initially allocated
  2513. correctly. This indicates a problem in the compiler.
  2514. \subsubsection{LOC{\_}FPU}
  2515. \label{subsubsec:mylabel19}
  2516. This indicates a location in the coprocessor; this is platform dependant.
  2517. \paragraph{Stack based FPU}
  2518. Only one CPU uses a stack based FPU architecture, this is the intel 80x86
  2519. family of processors. When the operand is on the top of the stack, the
  2520. operand is of type LOC{\_}FPU.
  2521. \paragraph{Register based FPU}
  2522. When the floating point co-processor is register based, the following
  2523. field(s) are defined in the structure to indicate the current location of
  2524. the operand:
  2525. \begin{longtable}{|l|p{7cm}|}
  2526. \hline
  2527. Field & Description \\
  2528. \hline
  2529. \endhead
  2530. \hline
  2531. \endfoot
  2532. \textsf{FpuRegister : TRegister;}&
  2533. Indicates in what register the operand is located (a general purpose
  2534. register in emulation mode, and a floating point register when floating
  2535. point hardware is present) \\
  2536. \textsf{FpuRegisterHigh, } \par
  2537. \textsf{FpuRegisterLow : TRegister;}&
  2538. Indicates in what registers the operand are located (for emulation
  2539. support - these are general purpose registers)
  2540. \end{longtable}
  2541. \subsubsection{LOC{\_}REGISTER}
  2542. \label{subsubsec:mylabel20}
  2543. This fields indicates that the operand is located in a CPU register. It is
  2544. possible to allocate more then one register, if trying to access 64-bit
  2545. values on 32-bit wide register machines.
  2546. \begin{longtable}{|l|p{10cm}|}
  2547. \hline
  2548. Field & Description \\
  2549. \hline
  2550. \endhead
  2551. \hline
  2552. \endfoot
  2553. \textsf{Register : TRegister}&
  2554. Indicates in what register the operand is located. \\
  2555. \textsf{RegisterHigh : TRegister;}&
  2556. High 32-bit of 64-bit virtual register (on 32-bit machines) \\
  2557. \textsf{RegisterLow : TRegister;}&
  2558. Low 32-bit of 64-bit virtual register (on 32-bit machines)
  2559. \end{longtable}
  2560. \subsubsection{LOC{\_}MEM, LOC{\_}REFERENCE}
  2561. \label{subsubsec:mylabel21}
  2562. This either indicates an operand in memory, or a constant integer numeric
  2563. value. The fields for this type of operand is as follows:
  2564. \begin{longtable}{|l|p{10cm}|}
  2565. \hline
  2566. Field & Description \\
  2567. \hline
  2568. \endhead
  2569. \hline
  2570. \endfoot
  2571. \textsf{Reference : TReference;}&
  2572. Information on the location in memory
  2573. \end{longtable}
  2574. References are the basic building blocks of the code generator, every load
  2575. and store in memory is done via a reference. A reference type can either
  2576. point to a symbolic name, an assembler expression (base register + index
  2577. register + offset)*scale factor, as well as simply giving information on a
  2578. numeric value.
  2579. The treference consists of the following:
  2580. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{6,5cm}|}
  2581. \hline
  2582. \textsf{TYPE} & & \\
  2583. \xspace \textsf{pReference} &= \^{} \textbf{TReference};& \\
  2584. \xspace \textsf{TReference} &= \textbf{packed Record} & \\
  2585. &\textsf{Is{\_}Immediate : Boolean;}&
  2586. Indicates that this location points to a memory location, but to a
  2587. constant value (TRUE), which is located in the offset field. \\
  2588. &\textsf{Segment : TRegister;}& (cpu-specific) \\
  2589. &\textsf{Base : TRegister;}&
  2590. Base address register for assembler expression \\
  2591. &\textsf{Index : TRegister;}&
  2592. Index register for assembler expression \\
  2593. &\textsf{ScaleFactor : Byte;}&
  2594. Multiplication factor for assembler expression (this field is
  2595. cpu-specific) \\
  2596. &\textsf{Offset : Longint;}&
  2597. Either an offset from base assembler address expression to add (if
  2598. Is{\_}Constant = FALSE) otherwise the numeric value of the operand \\
  2599. &\textsf{Symbol : pAsmSymbol;}&
  2600. Pointer to the symbol name string of the reference in case where it is
  2601. a symbolic reference \\
  2602. &\textsf{OffsetFixup : Longint;}& \\
  2603. &\textsf{Options : TRefOptions;}& \\
  2604. &\textsf{END;}& \\
  2605. \hline
  2606. \end{tabular*}
  2607. \subsubsection{LOC{\_}JUMP}
  2608. \label{subsubsec:mylabel22}
  2609. There are no fields associated with this location, it simply indicates that
  2610. it is a boolean comparison which must be done to verify the succeeding
  2611. operations. (i.e the processor zero flag is valid and gives information on
  2612. the result of the last operation).
  2613. \subsubsection{LOC{\_}FLAGS}
  2614. \label{subsubsec:mylabel23}
  2615. The operand is in the flags register. From this operand, the conditional
  2616. jumps can be done. This is processor dependant, but normally the flags for
  2617. all different comparisons should be present.
  2618. \begin{longtable}{|l|p{10cm}|}
  2619. \hline
  2620. Field & Description \\
  2621. \hline
  2622. \endhead
  2623. \hline
  2624. \endfoot
  2625. \textsf{ResFlags : TResFlags;}&
  2626. This indicates the flag which must be verified for the actual jump
  2627. operation. \textsf{tresflags }is an enumeration of all possible
  2628. conditional flags which can be set by the processor. \\
  2629. \end{longtable}
  2630. \subsubsection{LOC{\_}CREGISTER}
  2631. \label{subsubsec:mylabel24}
  2632. This is a read-only register allocated somewhere else in the code generator.
  2633. It is used mainly for optimization purposes. It has the same fields as
  2634. LOC{\_}REGISTER, except that the registers associated with this location can
  2635. only be read from, and should never be modified directly.
  2636. \begin{longtable}{|l|p{10cm}|}
  2637. \hline
  2638. Field & Description \\
  2639. \hline
  2640. \endhead
  2641. \hline
  2642. \endfoot
  2643. \textsf{Register : TRegister}&
  2644. Indicates in what register the operand is located. \\
  2645. \textsf{RegisterHigh : TRegister;}&
  2646. High 32-bit of 64-bit virtual register (on 32-bit machines) \\
  2647. \textsf{RegisterLow : TRegister;}&
  2648. Low 32-bit of 64-bit virtual register (on 32-bit machines) \\
  2649. \end{longtable}
  2650. \subsubsection{LOCATION PUBLIC INTERFACE}
  2651. \label{subsubsec:location}
  2652. \begin{procedurel}{Del{\_}Location}{dellocation}
  2653. \Declaration
  2654. procedur Del{\_}Location(const L : TLocation);
  2655. \Description
  2656. If the location points to a LOC{\_}REGISTER or LOC{\_}CREGISTER, it frees up
  2657. the allocated register(s) associated with this location. If the location
  2658. points to LOC{\_}REFERENCE or LOC{\_}MEM, it frees up the the allocated base
  2659. and index registers associated with this node.
  2660. \end{procedurel}
  2661. \begin{procedurel}{Clear{\_}Location}{clearlocation}
  2662. \Declaration
  2663. procedure Clear{\_}location(var Loc : TLocation);
  2664. \Description
  2665. Sets the location to point to a LOC{\_}INVALID type.
  2666. \end{procedurel}
  2667. \begin{procedurel}{Set{\_}Location}{setlocation}
  2668. \Declaration
  2669. procedure Set{\_}Location(var Destloc,Sourceloc : TLocation);
  2670. \Description
  2671. The destination location now points to the destination location (now copy is
  2672. made, a simple pointer assignment)
  2673. \end{procedurel}
  2674. \begin{procedurel}{Swap{\_}Location}{swaplocation}
  2675. \Declaration
  2676. Procedure Swap{\_}Location(var Destloc,Sourceloc : TLocation);
  2677. \Description
  2678. Swap both location pointers.
  2679. \end{procedurel}
  2680. \subsection{Registers (cpubase.pas)}
  2681. \label{subsec:registers}
  2682. The code generator defines several types of registers which are categorized
  2683. by classes. All (except for the scratch register class) of these register
  2684. classes are allocated / freed on the fly, when the code is generated in the
  2685. code generator: The registers are defined in a special enumeration called
  2686. tregister. This enumeration contains all possible register defines for the
  2687. target architecture, and a possible definition could be as follows :
  2688. \begin{verbatim}
  2689. tregister = ( { general purpose registers }
  2690. R_NO,R_D0,R_D1,R_D2,R_D3,R_D4,R_D5,R_D6,R_D7,
  2691. { address registers }
  2692. R_A0,R_A1,R_A2,R_A3,R_A4,R_A5,R_A6,R_SP,
  2693. { PUSH/PULL- quick and dirty hack }
  2694. R_SPPUSH,R_SPPULL,
  2695. { misc. and floating point registers }
  2696. R_CCR,R_FP0,R_FP1,R_FP2,R_FP3,R_FP4,R_FP5,R_FP6,
  2697. R_FP7,R_FPCR,R_SR,R_SSP,R_DFC,R_SFC,R_VBR,R_FPSR,
  2698. { other - not used }
  2699. R_DEFAULT_SEG
  2700. );
  2701. \end{verbatim}
  2702. \subsubsection{integer registers}
  2703. \label{subsubsec:integer}
  2704. \textsf{intregs: array[1..maxintregs] of tregister;}
  2705. General purpose registers which can contain any data, usually integer
  2706. values. These can also be used, when no floating point coprocessor is
  2707. present, to hold values for floating point operations.
  2708. \subsubsection{address registers}
  2709. \label{subsubsec:address}
  2710. \textsf{addrregs: array[1..maxaddrregs] of tregister;}
  2711. Registers which are used to construct assembler address expressions, usually
  2712. the address registers are used as the base registers in these assembler
  2713. expressions.
  2714. \subsubsection{fpu registers}
  2715. \label{subsubsec:mylabel25}
  2716. \textsf{FpuRegs: array[1..MaxFpuRegs] of TRegister;}
  2717. Hardware floating point registers. These registers must at least be able to
  2718. load and store IEEE DOUBLE floating point values, otherwise they cannot be
  2719. considered as FPU registers. Not available on systems with no floating point
  2720. coprocessor.
  2721. \subsubsection{scratch registers}
  2722. \label{subsubsec:scratch}
  2723. \textsf{Scratch{\_}Regs: array[1..MaxScratchRegs] of TRegister;}
  2724. These registers are used as scratch, and can be used in assembler statement
  2725. in the pascal code, without being saved. They will always be valid across
  2726. routine calls. These registers are sometimes temporarily allocated inside
  2727. code generator nodes, and then immediately freed (always inside the same
  2728. routine).
  2729. \subsection{Special registers (cpubase.pas)}
  2730. \label{subsec:special}
  2731. The code generator has special uses for certain types of registers. These
  2732. special registers are of course CPU dependant, but as an indication, the
  2733. following sections explains the uses of these special registers and their
  2734. defines.
  2735. \subsubsection{Stack{\_}Pointer}
  2736. \label{subsubsec:stack}
  2737. \textsf{Const Stack{\_}Pointer = R{\_}A7}
  2738. This represents the stack pointer, an address register pointing to the
  2739. allocated stack area.
  2740. \subsubsection{Frame{\_}Pointer}
  2741. \label{subsubsec:frame}
  2742. \textsf{Const Frame{\_}Pointer = R{\_}A6}
  2743. This represents the frame register which is used to access values in the
  2744. stack. This is usually also an address register.
  2745. \subsubsection{Self{\_}Pointer}
  2746. \label{subsubsec:mylabel26}
  2747. \textsf{Const Self{\_}Pointer = R{\_}A5}
  2748. This represents the self register, which represents a pointer to the current
  2749. instance of a class or object.
  2750. \subsubsection{accumulator}
  2751. \label{subsubsec:accumulatorents}
  2752. \textsf{Const Accumulator = R{\_}D0}
  2753. The accumulator is used (except in the i386) as a scratch register, and also
  2754. for return value in functions (in the case where they are 32-bit or less).
  2755. In the case it is a 64-bit value (and the target processor only supports
  2756. 32-bit registers) , the result of the routine is stored in the accumulator
  2757. for the low 32-bit value, and in the scratch register
  2758. (\textsf{scratch{\_}register}) for the high 32-bit value.
  2759. \subsubsection{scratch register}
  2760. \label{subsubsec:mylabel27}
  2761. \textsf{const scratch{\_}reg = R{\_}D1}
  2762. This register is used in special circumstances by the code generator. It is
  2763. simply a define to one of the registers in the \textsf{scratch{\_}regs
  2764. }array.
  2765. \subsection{Instructions}
  2766. \label{subsec:instructionsr}
  2767. \subsection{Reference subsystem}
  2768. \label{subsec:reference}
  2769. \subsubsection{Architecture}
  2770. \label{subsubsec:architecturebsysteme}
  2771. As described before in the locations section, one of the possible locations
  2772. for an operand is a memory location, which is described in a special
  2773. structure \textsf{treference} (described earlier). This subsection describes
  2774. the interface available by the code generator for allocation and freeing
  2775. reference locations.
  2776. \subsubsection{Code generator interface}
  2777. \label{subsubsec:mylabel28}
  2778. %\lstinline!Function NewReference(Const R : TReference) : pReference;!
  2779. \begin{procedure}{DisposeReference}
  2780. \Declaration
  2781. Procedure DisposeReference(Var R : pReference);
  2782. \Description
  2783. Disposes of the reference \textsf{R} and sets r to \textsf{NIL}
  2784. \Notes
  2785. Does not verify if \textsf{R} is assigned first.
  2786. \end{procedure}
  2787. \begin{function}{NewReference}
  2788. \Declaration
  2789. Function NewReference(Const R : TReference) : pReference;
  2790. \Description
  2791. Allocates in the heap a copy of the reference \textsf{r} and returns that
  2792. allocated pointer.
  2793. \end{function}
  2794. \begin{functionl}{Del{\_}Reference}{delreference}
  2795. \Declaration
  2796. Procedure Del{\_}Reference(Const Ref : tReference);
  2797. \Description
  2798. Free up all address registers allocated in this reference for the index and
  2799. base (if required).
  2800. \Notes
  2801. Does not free the reference symbol if it exists.
  2802. \end{functionl}
  2803. \begin{functionl}{New{\_}Reference}{resetreference}
  2804. \Declaration
  2805. Function New{\_}Reference(Base : TRegister;Offset : Longint) : PReference;
  2806. \Description
  2807. Allocates a reference pointer, clears all the fields to zero, and sets the
  2808. offset to the offset field and the base to the base fields of the newly
  2809. allocated reference. Returns this newly allocated reference.
  2810. \end{functionl}
  2811. \begin{procedurel}{Reset{\_}Reference}{resetreference}
  2812. \Declaration
  2813. Procedure Reset{\_}Reference(Var Ref : TReference);
  2814. \Description
  2815. Clears all fields of the reference.
  2816. \end{procedurel}
  2817. \subsection{The register allocator subsystem}
  2818. \label{subsec:mylabel7}
  2819. \subsubsection{Architecture}
  2820. \label{subsubsec:architecture}
  2821. This system allocates and deallocates registers, from a pool of free
  2822. registers. Each time the code generator requires a register for generating
  2823. assembler instructions, it either calls the register allocator subsystem to
  2824. get a free register or directly uses the scratch registers (which are never
  2825. allocated in a pool except in the optimization phases of the compiler).
  2826. The code generator when no longer referencing the register should deallocate
  2827. it so it can be used once again.
  2828. \subsubsection{Code generator interface (tgen.pas)}
  2829. \label{subsubsec:mylabel29}
  2830. The following interface routines are used by the code generator to allocate
  2831. and deallocate registers from the different register pools available to code
  2832. generator.
  2833. \begin{function}{GetRegister32}
  2834. \Declaration
  2835. Function GetRegister32 : TRegister;
  2836. \Description
  2837. Allocates and returns a general purpose (integer) register which can be used
  2838. in the code generator. The register, when no longer used should be
  2839. deallocated with ungetregister32() or ungetregister()
  2840. \Notes
  2841. On non 32-bit machines, this routine should return the normal register for
  2842. this machine (eg : 64-bit machines will alloate and return a 64-bit
  2843. register).
  2844. \end{function}
  2845. \begin{procedure}{GetRegisterPair}
  2846. \Declaration
  2847. Procedure GetRegisterPair(Var Low, High : TRegister);
  2848. \Description
  2849. Returns a register pair to be used by the code generator when accessing
  2850. 64-bit values on 32-bit wide register machines.
  2851. \Notes
  2852. On machines which support 64-bit registers naturally, this routine should
  2853. never be used, it is intended for 32-bit machines only.par Some machines
  2854. support 64-bit integer operations using register 32-bit pairs in hardware,
  2855. but the allocated registers must be specific, this routine is here to
  2856. support these architectures.
  2857. \end{procedure}
  2858. \begin{procedure}{UngetRegister32}
  2859. \Declaration
  2860. Procedure UnGetRegister32(R : TRegister);
  2861. \Description
  2862. Deallocates a general purpose register which was previously allocated with
  2863. \seef{GetRegister32}().
  2864. \end{procedure}
  2865. \begin{function}{GetFloatRegister}
  2866. \Declaration
  2867. Function GetFloatRegister : TRegister;
  2868. \Description
  2869. Allocates and returns a floating point register which can be used in the
  2870. code generator. The register, when no longer used should be deallocated with
  2871. ungetregister(). The register returned is a true floating point register (if
  2872. supported).
  2873. \Notes
  2874. This routine should only be used when floating point hardware is present in
  2875. the system. For emulation of floating point, the general purpose register
  2876. allocator / deallocator routines should be used instead.
  2877. \end{function}
  2878. \begin{function}{IsFloatsRegister}
  2879. \Declaration
  2880. Function IsFloatsRegister(R : TRegister): Boolean;
  2881. \Description
  2882. Returns TRUE if the register r is actually a floating point register,
  2883. otherwise returns FALSE. This is used when the location is LOC{\_}FPU on
  2884. machines which do not support true floating point registers.
  2885. \end{function}
  2886. \begin{function}{GetAdressReg}
  2887. \Declaration
  2888. Function GetAddressReg : TRegister;
  2889. \Description
  2890. Allocates and returns an address register which can be used for address
  2891. related opcodes in the code generator. The register, when no longer used
  2892. should be deallocated with ungetregister()
  2893. \Notes
  2894. If there is no distinction between address registers, and general purpose
  2895. register in the architecture, this routine may simply call and return the
  2896. getregister32() result.
  2897. \end{function}
  2898. \begin{function}{IsAddressRegister}
  2899. \Declaration
  2900. Function IsAddressRegister(r : TRegister): Boolean;
  2901. \Description
  2902. Returns TRUE if the register r is actually an address register, otherwise
  2903. returns FALSE.
  2904. \Notes
  2905. If there is no distinction between address registers, and general purpose
  2906. register in the architecture, this routine may simply verify if this is a
  2907. general purpose register and return TRUE in that case.
  2908. \end{function}
  2909. \begin{procedure}{UngetRegister}
  2910. \Declaration
  2911. Procedure UngetRegister(r : TRegister);
  2912. \Description
  2913. Deallocates any register which was previously allocated with any of the
  2914. allocation register routines.
  2915. \end{procedure}
  2916. \begin{function}{SaveUsedRegisters}
  2917. \Declaration
  2918. Procedure SaveUsedRegisters(Var Saved : TSaved; ToSave: TRegisterset);
  2919. \Description
  2920. Saves in a temporary location all specified registers. On stack based
  2921. machines the registers are saved on the stack, otherwise they are saved in a
  2922. temporary memory location. The registers which were saved are stored in the
  2923. \textsf{saved} variable. The constant \textsf{ALL{\_}REGISTERS} passed to
  2924. the \textsf{tosave} parameter indicates to save all used registers.
  2925. \end{function}
  2926. \begin{function}{RestoreUsedRegisters}
  2927. \Declaration
  2928. procedure restoreusedregisters(Saved : TSaved);
  2929. \Description
  2930. Restores all saved registers from the stack (or a temporary memory
  2931. location). Free any temporary memory space allocated, if necessary.
  2932. \end{function}
  2933. \begin{function}{GetExplicitRegister32}
  2934. \Declaration
  2935. Function GetExplicitRegister32(R : TRegister): TRegister;
  2936. \Description
  2937. This routine allocates specifically the specified register \textsf{r} and
  2938. returns that register. The register to allocate can only be one of the
  2939. scratch registers.
  2940. \Notes
  2941. This routine is used for debugging purposes only. It should be used in
  2942. conjunctions with UnGetRegister32() to explicitly allocate and deallocate a
  2943. scratch register.
  2944. \end{function}
  2945. \subsection{Temporary memory allocator subsystem}
  2946. \label{subsec:temporary}
  2947. \subsubsection{Architecture}
  2948. \label{subsubsec:architecturemory}
  2949. Sometimes it is necessary to reserve temporary memory locations on the stack
  2950. to store intermediate results of statements. This is done by the temporary
  2951. management module.
  2952. Since entry and exit code for routines are added after the code for the
  2953. statements in the routine have been generated, temporary memory allocation
  2954. can be used `on the fly' in the case where temporary memory values are
  2955. required in the code generation phase of the routines being compiled. After
  2956. usage, the temporary memory space should be freed, so it can be reused if
  2957. necessary.
  2958. The temporary memory allocation is a linked list of entries containing
  2959. information where to access the data via a negative offset from the
  2960. Frame{\_}Pointer register. The linked list is only valid when compiling and
  2961. generating the code for the procedure bodies; it is reset and cleared each
  2962. time a new routine is compiled. There are currently three different types of
  2963. memory spaces in use : volatile (\textsf{tt{\_}Normal}) which can be
  2964. allocated and freed any time in the procedure body, ansistring, which is
  2965. currently the same as volatile, except it only stored references to
  2966. ansistring's, and persistent (\textsf{tt{\_}Persistent}) which are memory
  2967. blocks which are reserved throughout the routine duration; persistent
  2968. allocated space can never be reused in a procedure body, unless explicitly
  2969. released.
  2970. The temporary memory allocator guarantees to allocate memory space on the
  2971. stack at least on a 16-bit alignment boundary. The exact alignment depends
  2972. on the operating system required alignment.
  2973. \subsubsection{Temporary memory allocator interface (temp{\_}gen.pas)}
  2974. \label{subsubsec:temporary}
  2975. \begin{function}{GetTempOfSize}
  2976. \Declaration
  2977. Function GetTempOfSize(Size : Longint) : Longint;
  2978. \Description
  2979. Allocates at least \textsf{size} bytes of temporary volatile memory on the
  2980. stack. The return value is the negative offset from the frame pointer where
  2981. this memory was allocated.
  2982. \Notes
  2983. The return offset always has the required alignment for the target system,
  2984. and can be used as an offset from the Frame{\_}Pointer to access the
  2985. temporary space.
  2986. \end{function}
  2987. \begin{procedure}{GetTempOfSizeReference}
  2988. \Declaration
  2989. Procedure GetTempOfSizeReference(L : Longint;Var Ref : TReference);
  2990. \Description
  2991. This routine is used to assign and allocate extra temporary volatile memory
  2992. space on the stack from a reference. \textsf{l} is the size of the
  2993. persistent memory space to allocate, while \textsf{Ref} is a reference entry
  2994. which will be set to the correct offset from the Frame{\_}Pointer register
  2995. base. The \textsf{Offset} and \textsf{Base} fields of \textsf{Ref} will be
  2996. set appropriately in this routine, and can be considered valid on exit of
  2997. this routine.
  2998. \Notes
  2999. The return offset always has the required alignment for the target system.
  3000. \end{procedure}
  3001. \begin{procedure}{UnGetIfTemp}
  3002. \Declaration
  3003. Procedure UnGetIfTemp(Const Ref : TReference);
  3004. \Description
  3005. Frees a reference \textsf{Ref} which was allocated in the volatile temporary
  3006. memory space.
  3007. \Notes
  3008. The freed space can later be reallocated and reused.
  3009. \end{procedure}
  3010. \begin{procedure}{GetTempAnsiStringReference}
  3011. \Declaration
  3012. Procedure GetTempAnsiStringReference(Var Ref : TReference);
  3013. \Description
  3014. Allocates \textsf{Ref} on the volatile memory space and sets the
  3015. \textsf{Base} to the Frame{\_}Pointer register and \textsf{Offset} to the
  3016. correct offset to access this allocated memory space.
  3017. \Notes
  3018. The return offset always has the required alignment for the target system.
  3019. \end{procedure}
  3020. \begin{function}{GetTempOfSizePersistant}
  3021. \Declaration
  3022. Function GetTempOfSizePersistant(Size : Longint) :Longint;
  3023. \Description
  3024. Allocates persistent storage space on the stack. return value is the
  3025. negative offset from the frame pointer where this memory was allocated.
  3026. \Notes
  3027. The return offset always has the required alignment for the target system.
  3028. \end{function}
  3029. \begin{function}{UngetPersistantTemp}
  3030. \Declaration
  3031. Procedure UnGetPersistantTemp(Pos : Longint);
  3032. \Description
  3033. Frees space allocated as being persistent. This persistent space can then
  3034. later be used and reallocated. \textsf{Pos} is the offset relative to the
  3035. Frame{\_}Pointer of the persistent memory block to free.
  3036. \end{function}
  3037. \begin{procedure}{ResetTempGen}
  3038. \Declaration
  3039. Procedure ResetTempGen;
  3040. \Description
  3041. Clear and free the complete linked list of temporary memory locations. The
  3042. list is set to nil.
  3043. \Notes
  3044. This routine is called each time a routine has been fully compiled.
  3045. \end{procedure}
  3046. \begin{procedure}{SetFirstTemp}
  3047. \Declaration
  3048. Procedure SetFirstTemp(L : Longint);
  3049. \Description
  3050. This routine sets the start of the temporary local area (this value is a
  3051. negative offset from the Frame{\_}Pointer, which is located after the local
  3052. variables). Usually the start offset is the size of the local variables,
  3053. modified by any alignment requirements.
  3054. \Notes
  3055. This routine is called once before compiling a routine, it indicates the
  3056. start address where to allocate temporary memory space.
  3057. \end{procedure}
  3058. \begin{function}{GetFirstTempSize}
  3059. \Declaration
  3060. Function GetFirstTempSize : Longint;
  3061. \Description
  3062. Returns the total number of bytes allocated for local and temporary
  3063. allocated stack space. This value is aligned according to the target system
  3064. alignment requirements, even if the actual size is not aligned.
  3065. \Notes
  3066. This routine is used by the code generator to get the total number of bytes
  3067. to allocate locally (i.e the stackframe size) in the entry and exit code of
  3068. the routine being compiled.
  3069. \end{function}
  3070. \begin{function}{NormalTempToPersistant}
  3071. \Declaration
  3072. Procedure NormalTempToPersistant(Pos : Longint);
  3073. \Description
  3074. Searches the list of currently temporary memory allocated for the one with
  3075. the offset \textsf{Pos}, and if found converts this temporary memory space
  3076. as persistent (can never be freed and reallocated).
  3077. \end{function}
  3078. \begin{function}{PersistantTempToNormal}
  3079. \Declaration
  3080. Procedure PersistantTempToNormal(Pos : Longint);
  3081. \Description
  3082. Searches the list of currently allocated persistent memory space as the
  3083. specified address \textsf{Pos}, and if found converts this memory space to
  3084. normal volatile memory space which can be freed and reused.
  3085. \end{function}
  3086. \begin{function}{IsTemp}
  3087. \Declaration
  3088. Function IsTemp(const Ref : TReference): Boolean;
  3089. \Description
  3090. Returns TRUE if the reference \textsf{ref }is allocated in temporary
  3091. volatile memory space, otherwise returns FALSE.
  3092. \end{function}
  3093. \subsection{Assembler generation}
  3094. \label{subsec:mylabel8}
  3095. \subsubsection{Architecture}
  3096. \label{subsubsec:architectureneration}
  3097. The different architectures on the market today only support certain types
  3098. of operands as assembler instructions. The typical format of an assembler
  3099. instruction has the following format:
  3100. \begin{center}
  3101. \textsf{OPCODE [opr1,opr2[,opr3][\ldots ]]}
  3102. \end{center}
  3103. The opcode field is a mnemonic for a specific assembler instruction, such as
  3104. \textsf{MOV} on the 80x86, or \textsf{ADDX} on the 680x0. Furthermore, in
  3105. most cases, this mnemonic is followed by zero to three operands which can be
  3106. of the following types:
  3107. Possible Operand Types
  3108. \begin{itemize}
  3109. \item a LABEL or SYMBOL (to code or data)
  3110. \item a REGISTER (one of the predefined hardware registers)
  3111. \item a CONSTANT (an immediate value)
  3112. \item a MEMORY EXPRESSION (indirect addressing through offsets, symbols, and
  3113. address registers)
  3114. \end{itemize}
  3115. In the compiler, this concept of different operand types has been directly
  3116. defined for easier generation of assembler output. All opcodes generated by
  3117. the code generator are stored in a linked list of opcodes which contain
  3118. information on the operand types, The opcode and the size (which is
  3119. important to determine on what size the operand must be operated on) are
  3120. stored in that linked list.
  3121. The possible operand sizes for the code generator are as follows (a
  3122. enumeration of type \textsf{topsize}):
  3123. \begin{longtable}{|l|p{10cm}|}
  3124. \hline
  3125. Operand size enum (\textsf{topsize}) & Description \\
  3126. \hline
  3127. \endhead
  3128. \hline
  3129. \endfoot
  3130. \textsf{S{\_}B}& 8-bit integer operand \\
  3131. \textsf{S{\_}W}& 16-bit integer operand \\
  3132. \textsf{S{\_}L}& 32-bit integer operand \\
  3133. \textsf{S{\_}Q}& 64-bit integer operand \\
  3134. \textsf{S{\_}FS}& 32-bit IEEE 754 Single floating point operand \\
  3135. \textsf{S{\_}FL}& 64-bit IEEE 754 Double floating point operand \\
  3136. \textsf{S{\_}FX}& Extended point floating point operand (cpu-specific) \\
  3137. \textsf{S{\_}CPU}& A constant equal to one of the previous sizes (natural size of operands) \\
  3138. \end{longtable}
  3139. The possible operand types for the code generator are as follows (other
  3140. might be added as required by the target architecture):
  3141. \begin{longtable}{|l|p{10cm}|}
  3142. \hline
  3143. Operand type (\textsf{TOpType}) & Description \\
  3144. \hline
  3145. \endhead
  3146. \hline
  3147. \endfoot
  3148. \textsf{top{\_}None}& No operand \\
  3149. \textsf{top{\_}Reg}& Operand is a register \\
  3150. \textsf{top{\_}Ref}& Operand is a reference (\textsf{treference} type) \\
  3151. \textsf{top{\_}Symbol}& Operand is a symbol (reference or label) \\
  3152. \end{longtable}
  3153. The architecture specific opcodes are done in an enumeration of type
  3154. \textsf{tasmop}. An example of an enumeration for some of the opcodes of the
  3155. PowerPC 32-bit architecture is as follows:
  3156. \begin{lstlisting}{}
  3157. Type TAsmOp = (a_Add, a_Add_, a_Addo, a_Addo_, a_Addc, a_Addc_, a_Addco,
  3158. a_Addco_,a_Adde, a_Adde_, a_Addeo, a_Addeo_, a_Addi,
  3159. a_Addic, a_Addic_, a_Addis \ldots
  3160. \end{lstlisting}
  3161. \subsubsection{Generic instruction generation interface}
  3162. \label{subsubsec:generic}
  3163. To independently generate code for different architectures, wrappers for the
  3164. most used instructions in the code generator have been created which are
  3165. totally independent of the target system.
  3166. \begin{procedurel}{Emit\_Load\_Loc\_Reg}{EmitLoadLocReg}
  3167. \Declaration
  3168. Procedure Emit{\_}Load{\_}Loc{\_}Reg(Src:TLocation;Srcdef:pDef; DstDef : pDef; Dst : TRegister);
  3169. \Description
  3170. Loads an operand from the source location in \textsf{Src} into the
  3171. destination register \textsf{Dst} taking into account the source definition
  3172. and destination definition (sign-extension, zero extension depending on the
  3173. sign and size of the operands).
  3174. \Notes
  3175. The source location can only be in LOC{\_}REGISTER, LOC{\_}CREGISTER,
  3176. LOC{\_}MEM or LOC{\_}REFERENCE otherwise an internal error will occur. This
  3177. generic opcode does not work on floating point values, only integer values.
  3178. \end{procedurel}
  3179. \begin{procedure}{FloatLoad}
  3180. \Declaration
  3181. Procedure FloatLoad(t : tFloatType;Ref : TReference; Var Location:TLocation);
  3182. \Description
  3183. This routine is to be called each time a location must be set to LOC{\_}FPU
  3184. and a value loaded into a FPU register
  3185. \Notes
  3186. The routine sets up the register field of LOC{\_}FPU correctly. The source
  3187. location can only be : LOC{\_}MEM or LOC{\_}REFERENCE. The destination
  3188. location is set to LOC{\_}FPU.
  3189. \end{procedure}
  3190. \begin{function}{FloatStore}
  3191. \Declaration
  3192. Procedure FloatStore(t : TFloatType;Var Location:TLocation; Ref:TReference);
  3193. \Description
  3194. This routine is to be called when a value located in LOC{\_}FPU must be
  3195. stored into memory.
  3196. \Notes
  3197. The destination must be LOC{\_}REFERENCE or LOC{\_}MEM. This routine frees
  3198. the LOC{\_}FPU location \\
  3199. \end{function}
  3200. \begin{functionl}{emit{\_}mov{\_}ref{\_}reg64}{emitmovrefreg64}
  3201. \Declaration
  3202. Procedure Emit{\_}Mov{\_}Ref{\_}Reg64(r : TReference;rl,rh : TRegister);
  3203. \Description
  3204. This routine moves a 64-bit integer value stored in memory location
  3205. \textsf{r} into the low 32-bit register \textsf{rl} and the high 32-bit
  3206. register \textsf{rh}.
  3207. \end{functionl}
  3208. \begin{functionl}{Emit{\_}Lea{\_}Loc{\_}Ref}{emitlealocref}
  3209. \Declaration
  3210. Procedure Emit{\_}Lea{\_}Loc{\_}Ref(Const t:TLocation;Const Ref:TReference; FreeTemp:Boolean);
  3211. \Description
  3212. Loads the address of the location \textsf{loc }and stores the result into
  3213. \textsf{Ref}
  3214. \Notes
  3215. The store address \textsf{ref }should point to an allocated area at least
  3216. \textsf{sizeof(pointer)} bytes, otherwise unexpected code might be
  3217. generated.
  3218. \end{functionl}
  3219. \begin{functionl}{Emit{\_}Lea{\_}Loc{\_}Reg}{Emitlealocreg}
  3220. \Declaration
  3221. Procedure Emit{\_}Lea{\_}Loc{\_}Reg(const t:TLocation;Reg:TRegister;Freetemp:Boolean);
  3222. \Description
  3223. Loads the address of the location \textsf{loc }and stores the result into
  3224. ther target register \textsf{reg}
  3225. \end{functionl}
  3226. \begin{procedure}{GetLabel}
  3227. \Declaration
  3228. Procedure GetLabel(Var l : pAsmLabel);
  3229. \Description
  3230. Returns a label associated with code. This label can then be used with the
  3231. instructions output by the code generator using the instruction generation
  3232. templates which require labels as parameters. The label itself can be
  3233. emitted to the assembler source by calling the \seep{EmitLab} routine.
  3234. \end{procedure}
  3235. \begin{procedure}{EmitLab}
  3236. \Declaration
  3237. Procedure EmitLab(Var l : pAsmLabel);
  3238. \Description
  3239. Output the label \textsf{l} to the assembler instruction stream.
  3240. \Notes
  3241. The label should have been previously allocated with \textsf{GetLabel}, The
  3242. output label will be of the form label: in the instruction stream. This
  3243. label is usually a jump target.
  3244. \end{procedure}
  3245. \begin{procedure}{EmitLabeled}
  3246. \Declaration
  3247. Procedure EmitLabeled(op : TAsmOp; Var l : pAsmLabel);
  3248. \Description
  3249. Output the opcode \textsf{op} with the operand \textsf{l}
  3250. which is a previously allocated label.
  3251. \Notes
  3252. This routine is used to output jump instructions such as : jmp label, jne
  3253. label. The label should have been previously allocated with a call to
  3254. \textsf{GetLabel}
  3255. \end{procedure}
  3256. \begin{function}{EmitCall}
  3257. \Declaration
  3258. Procedure EmitCall(Const Routine:String);
  3259. \Description
  3260. Emit a call instruction to an internal routine
  3261. \Parameters
  3262. Routine = The name of the routine to call.
  3263. \end{function}
  3264. \begin{procedure}{ConcatCopy}
  3265. \Declaration
  3266. procedure ConcatCopy(Source,Dest : TReference;Size : Longint;DelSource : Boolean; loadref:boolean);
  3267. \Description
  3268. This routine copies \textsf{Size} data from the \textsf{Source} reference to
  3269. the destination \textsf{Dest} reference. \\
  3270. \Parameters
  3271. Source = Source reference to copy from \par
  3272. Dest = Depending on the value of loadref, either indicates a location where a pointer to the data to copy is
  3273. Stored, or this reference directly the address to copy to. \par
  3274. Size = Number of bytes to copy \par
  3275. DelSource = TRUE if the source reference should be freed in this routine \par
  3276. LoadRef = TRUE if the source reference contains a pointer to the address we
  3277. wish to copy to, otherwise the reference itself is the destination
  3278. location to copy to.
  3279. \end{procedure}
  3280. \begin{procedurel}{Emit{\_}Flag2Reg}{emitflag2reg}
  3281. \Declaration
  3282. Procedure Emit{\_}Flag2Reg(Flag:TResflags;HRegister:TRegister);
  3283. \Description
  3284. Sets the value of the register to 1 if the condition code flag in
  3285. \textsf{Flag} is TRUE, otherwise sets the register to zero.
  3286. \Notes
  3287. The operand should be zero extended to the natural register size for the
  3288. target architecture.
  3289. \end{procedurel}
  3290. %\subsubsection{Instruction generation interface}
  3291. %\label{subsubsec:instruction}
  3292. \section{The assembler output}
  3293. \label{sec:mylabel8}
  3294. All code is generated via special linked lists of instructions. The base of
  3295. this is a special object, an abstract assembler which implements all
  3296. directives which are usually implemented in the different assemblers
  3297. available on the market . When the code generator and parser generates the
  3298. final output, it is generated as a linked list for each of the sections
  3299. available for the output assembler. Each entry in the linked list is either
  3300. an instruction, or one of the abstract directives for the assembler.
  3301. \begin{figure}
  3302. \ifpdf
  3303. \includegraphics{arch11.pdf}
  3304. %\epsfig{file=arch11.png,width=\textwidth}
  3305. \else
  3306. \includegraphics[width=5.67in,height=2.17in]{arch11.eps}
  3307. \fi
  3308. \label{fig:fig11}
  3309. \caption{Assembler generation organisation}
  3310. \end{figure}
  3311. % FIXME
  3312. % If I don't do this, the assembler node table has a problem.
  3313. % untested for more recent versions (with less floats due to longtable)
  3314. \clearpage
  3315. The different possible sections which are output are as follows:
  3316. \begin{center}
  3317. Section lists for the assembler output
  3318. \end{center}
  3319. \begin{longtable}{|l|p{10cm}|}
  3320. \hline
  3321. Internal section name & Description \\
  3322. \hline
  3323. \endhead
  3324. \hline
  3325. \endfoot
  3326. ExparAsmList & temporary list \\
  3327. DataSegment & initialized variables \\
  3328. CodeSegment & instructions and general code directives \\
  3329. DebugList & debugging information \\
  3330. WithDebugList & ??????????????? \\
  3331. Consts & read only constants \\
  3332. ImportSection & imported symbols \\
  3333. ExportSection & exported symbols \\
  3334. ResourceSection & Resource data \\
  3335. RttiList & runtime type information data \\
  3336. ResourceStringList& resource string data
  3337. \end{longtable}
  3338. The following directives for the abstract assembler currently exist:
  3339. Abstract assembler node types:
  3340. \begin{longtable}{|l|p{10cm}|}
  3341. \hline
  3342. Node entry Type & Description \\
  3343. \hline
  3344. \endhead
  3345. \hline
  3346. \endfoot
  3347. Ait{\_}None&
  3348. This entry in the linked list is invalid (this should
  3349. normally never occur) \\
  3350. Ait{\_}Direct&
  3351. Direct output to the resulting assembler file (as string) \\
  3352. Ait{\_}String&
  3353. Shortstring with a predefined length \\
  3354. Ait{\_}Label&
  3355. Numbered assembler label used for jumps \\
  3356. Ait{\_}Comment&
  3357. Assembler output comment \\
  3358. Ait{\_}Instruction&
  3359. Processor specific instruction \\
  3360. Ait{\_}DataBlock&
  3361. Unitialized data block (BSS) \\
  3362. Ait{\_}Symbol&
  3363. Entry represents a symbol (exported, imported, or other public
  3364. symbol type) \newline
  3365. Possible symbol types : NONE, EXTERNAL, LOCAL and GLOBAL \newline
  3366. eg : A symbol followed by an Ait{\_}const{\_}32bit \\
  3367. Ait{\_}Symbol{\_}End &
  3368. Symbol end (for example the end of a routine) \\
  3369. Ait{\_}Const{\_}32bit&
  3370. Initialized 32-bit constant (without a symbol) \\
  3371. Ait{\_}Const{\_}16bit&
  3372. Initialized 16-bit constant (without a symbol) \\
  3373. Ait{\_}Const{\_}8bit&
  3374. Initialized 8-bit constant (without a symbol) \\
  3375. Ait{\_}Const{\_}symbol & ???????????? \\
  3376. Ait{\_}Real{\_}80bit (x86)&
  3377. Initialized 80-bit floating point constant (without symbol) \\
  3378. Ait{\_}Real{\_}64bit&
  3379. Initialized Double IEEE floating point constant (without symbol) \\
  3380. Ait{\_}Real{\_}32bit&
  3381. Initialized Single IEEE floating point constant (without symbol) \\
  3382. Ait{\_}Comp{\_}64bit (x86)&
  3383. Initialized 64-bit floating point integer (without symbol) \\
  3384. Ait{\_}Align&
  3385. Alignment directive \\
  3386. Ait{\_}Section&
  3387. Section directive \\
  3388. Ait{\_}const{\_}rva (Win32)& \\
  3389. Ait{\_}Stabn &
  3390. stabs debugging information (numerical value) \\
  3391. Ait{\_}Stabs &
  3392. stabs debugging information (string) \\
  3393. Ait{\_}Force{\_}Line&
  3394. stabs debugging line information \\
  3395. Ait{\_}Stab{\_}Function{\_}Name&
  3396. stabs debug information routine name \\
  3397. Ait{\_}Cut&
  3398. Cut in the assembler files (used for smartlinking) \\
  3399. Ait{\_}RegAlloc&
  3400. Debugging information for the register allocator \\
  3401. Ait{\_}Marker & ???????????? \\
  3402. Ait{\_}Frame (Alpha)& \\
  3403. Ait{\_}Ent (Alpha)& \\
  3404. Ait{\_}Labeled{\_}Instruction (m68k)& \\
  3405. Ait{\_}Dummy & Unused - should never appear
  3406. \end{longtable}
  3407. \section{The Runtime library}
  3408. \label{sec:mylabel9}
  3409. This section describes the requirements of the internal routines which MUST
  3410. be implemented for all relevant platforms to port the system unit to a new
  3411. architecture or operating system.
  3412. The following defines are available when compiling the runtime library:
  3413. \begin{longtable}{|l|p{10cm}|}
  3414. \hline
  3415. Define Name & Description \\
  3416. \hline
  3417. \endhead
  3418. \hline
  3419. \endfoot
  3420. i386 & Intel 80x86 family of processors (and compatibles) \\
  3421. m68k & Motorola 680x0 family of processors (excludes coldfire) \\
  3422. alpha & Alpha 21x64 family of processors \\
  3423. powerpc & Motorola / IBM 32-bit family of processors \\
  3424. sparc & SPARC v7 compatible processors
  3425. \end{longtable}
  3426. \begin{longtable}{|l|p{10cm}|}
  3427. \hline
  3428. Define name & Description \\
  3429. \hline
  3430. \endhead
  3431. \hline
  3432. \endfoot
  3433. RTLLITE&
  3434. Removes some extraneous routine from compilation (system unit
  3435. is minimal). Mvdv: Afaik the status of this is unknown \\
  3436. DEFAULT{\_}EXTENDED&
  3437. The runtime library routines dealing with fixed point values have the
  3438. \textsf{extended} type instead of the \textsf{real} type. \\
  3439. SUPPORT{\_}SINGLE&
  3440. The compiler supports the \textsf{single} floating point precision type \\
  3441. SUPPORT{\_}DOUBLE&
  3442. The compiler supports the \textsf{double }floating point precision type \\
  3443. SUPPORT{\_}EXTENDED&
  3444. The compiler supports the \textsf{extended }floating point
  3445. precision type \\
  3446. SUPPORT{\_}FIXED&
  3447. The compiler supports the \textsf{fixed} floating point precision type \\
  3448. HASWIDECHAR&
  3449. The compiler supported the \textsf{widechar} character type \\
  3450. INT64&
  3451. The compiler supports 64-bit integer operations \\
  3452. MAC{\_}LINEBREAK&
  3453. Text I/O uses Mac styled line break ({\#}13) instead of {\#}13{\#}10 \\
  3454. SHORT{\_}LINEBREAK&
  3455. Text I/O uses UNIX styled line breaks ({\#}10) instead of {\#}13{\#}10 \\
  3456. EOF{\_}CTRLZ&
  3457. A Ctrl-Z character in a text file is an EOF marker (UNIX mostly) \\
  3458. \end{longtable}
  3459. The following defines are used for fexpand definitions:
  3460. % FIXME Seem to miss a *nix symlink expand behaviour define.
  3461. \begin{longtable}{|l|p{10cm}|}
  3462. \hline
  3463. Define name & Description \\
  3464. \hline
  3465. \endhead
  3466. \hline
  3467. \endfoot
  3468. FPC{\_}EXPAND{\_}DRIVES&
  3469. Different devices with different names (as drives) are
  3470. supported \par (like DOS, Netware, etc\ldots ) \\
  3471. FPC{\_}EXPAND{\_}UNC&
  3472. Universal Naming convention support i.e \par $\backslash \backslash
  3473. < $server-name>$\backslash $<share-name>$\backslash $<directory/filename> \\
  3474. UNIX&
  3475. Unix style file names \\
  3476. FPC{\_}EXPAND{\_}VOLUMES&
  3477. Volume names (i.e. drive descriptions longer than 1
  3478. character) are supported. \\
  3479. FPC{\_}EXPAND{\_}TILDE&
  3480. Replaces the $\sim $ character, with the `HOME' directory
  3481. (mostly on UNIX platforms) \\
  3482. \end{longtable}
  3483. The following defines some debugging routines for the runtime library:
  3484. \begin{longtable}{|l|p{10cm}|}
  3485. \hline
  3486. Define Name & Description \\
  3487. \hline
  3488. \endhead
  3489. \hline
  3490. \endfoot
  3491. DEFINE NAME & Description \\
  3492. ANSISTRDEBUG & Add Debug routines for ansi string support \\
  3493. EXCDEBUG & Add Debug routines for exception debugging \\
  3494. LOGGING & Log the operations to a file \\
  3495. \end{longtable}
  3496. \subsection{Operating system hooks}
  3497. \label{subsec:operating}
  3498. This section contains information on all routines which should be hooked and
  3499. implemented to be able to compile and use the system unit for a new
  3500. operating system:
  3501. \begin{functionl}{System{\_}Exit}{systemexit}
  3502. \Declaration
  3503. Procedure System{\_}Exit;
  3504. \Description
  3505. This routine is internally called by the system unit when the application
  3506. exits.
  3507. \Notes
  3508. This routine should actually exit the application. It should exit with the
  3509. error code specified in the \textsf{ExitCode} variable.
  3510. \Algorithm
  3511. Exit application with ExitCode value.
  3512. \end{functionl}
  3513. \begin{function}{ParamCount}
  3514. \Declaration
  3515. Function ParamCount : Longint;
  3516. \Description
  3517. This routine is described in the Free Pascal reference manual.
  3518. \end{function}
  3519. \begin{procedure}{Randomize}
  3520. \Declaration
  3521. Procedure Randomize;
  3522. \Description
  3523. This routine should initialize the built-in random generator with a random value.
  3524. \Notes
  3525. This routine is used by random
  3526. \Algorithm
  3527. Randseed := pseudo random 32-bit value
  3528. \end{procedure}
  3529. \begin{function}{GetHeapStart}
  3530. \Declaration
  3531. Function GetHeapStart : Pointer;
  3532. \Description
  3533. This routine should return a pointer to the start of the heap area.
  3534. \Algorithm
  3535. GetHeapStart := address of start of heap.
  3536. \end{function}
  3537. \begin{function}{GetHeapSize}
  3538. \Declaration
  3539. Function GetHeapSize : Longint;
  3540. \Description
  3541. This routine should return the total heap size in bytes
  3542. \Algorithm
  3543. GetHeapSize := total size of the initial heap area.
  3544. \end{function}
  3545. \begin{function}{sbrk}
  3546. \Declaration
  3547. Function Sbrk(Size : Longint): Longint;
  3548. \Description
  3549. This routine should grow the heap by the number of bytes specified. If
  3550. the heap cannot be grown it should return -1, otherwise it should return
  3551. a pointer to the newly allocated area.
  3552. \Parameters
  3553. size = Number of bytes to allocate
  3554. \end{function}
  3555. \begin{procedurel}{Do{\_}Close}{doclose}
  3556. \Declaration
  3557. Procedure Do{\_}Close(Handle : Longint);
  3558. \Description
  3559. This closes the file specified of the specified handle number.
  3560. \Parameters
  3561. handle = file handle of file to close
  3562. \Notes
  3563. This routine should close the specified file.
  3564. \Notes
  3565. This routine should set InoutRes in case of error.
  3566. \end{procedurel}
  3567. \begin{procedurel}{Do{\_}Erase}{doerase}
  3568. \Declaration
  3569. Procedure Do{\_}Erase(p: pChar);
  3570. \Description
  3571. This erases the file specifed by p.
  3572. \Parameters
  3573. p = name of the file to erase
  3574. \Notes
  3575. This routine should set InoutRes in case of error.
  3576. \end{procedurel}
  3577. \begin{procedurel}{Do{\_}Truncate}{dotruncate}
  3578. \Declaration
  3579. Procedure Do{\_}Truncate(Handle, FPos : Longint);
  3580. \Description
  3581. This truncates the file at the specified position.
  3582. \Parameters
  3583. handle = file handle of file to truncate
  3584. fpos = file position where the truncate should occur
  3585. \Notes
  3586. This routine should set InoutRes in case of error.
  3587. \end{procedurel}
  3588. \begin{procedurel}{Do{\_}Rename}{dorename}
  3589. \Declaration
  3590. Procedure Do{\_}Rename(p1, p2 : pchar);
  3591. \Description
  3592. This renames the file specified.
  3593. \Parameters
  3594. p1 = old file name
  3595. p2 = new file name
  3596. \Notes
  3597. This routine should set InoutRes in case of error.
  3598. \end{procedurel}
  3599. \begin{functionl}{Do{\_}Write}{dowrite}
  3600. \Declaration
  3601. Function Do{\_}Write(Handle,Addr,Len:Longint):longint;
  3602. \Description
  3603. This writes to the specified file. Returns the number of bytes
  3604. actually written.
  3605. \Parameters
  3606. handle = file handle of file to write to
  3607. addr = address of buffer containing the data to write
  3608. len = number of bytes to write
  3609. \Notes
  3610. This routine should set InoutRes in case of error.
  3611. \end{functionl}
  3612. \begin{functionl}{Do{\_}Read}{doread}
  3613. \Declaration
  3614. Function Do{\_}Read(Handle,Addr,Len:Longint):Longint;
  3615. \Description
  3616. Reads from a file. Returns the number of bytes read.
  3617. \Parameters
  3618. handle = file handle of file to read from
  3619. addr = address of buffer containing the data to read
  3620. len = number of bytes to read
  3621. \Notes
  3622. This routine should set InoutRes in case of error.
  3623. \end{functionl}
  3624. \begin{functionl}{Do{\_}FilePos}{dofilepos}
  3625. \Declaration
  3626. function Do{\_}FilePos(Handle: Longint):longint;
  3627. \Description
  3628. Returns the file pointer position
  3629. \Parameters
  3630. handle = file handle of file to get file position on
  3631. \Notes
  3632. This routine should set InoutRes in case of error.
  3633. \end{functionl}
  3634. \begin{procedurel}{Do{\_}Seek}{doseek}
  3635. \Declaration
  3636. Procedure Do{\_}Seek(Handle,Pos:Longint);
  3637. \Description
  3638. Set file pointer of file to a new position
  3639. \Parameters
  3640. handle = file handle of file to seek in
  3641. pos = new position of file pointer (from start of file)
  3642. \Notes
  3643. This routine should set InoutRes in case of error.
  3644. \end{procedurel}
  3645. \begin{functionl}{Do{\_}Seekend}{doseekend}
  3646. \Declaration
  3647. Function Do{\_}SeekEnd(Handle:Longint): Longint;
  3648. \Description
  3649. Seeks to the end of the file. Returns the
  3650. new file pointer position.
  3651. \Parameters
  3652. handle = file handle of file to seek to end of file
  3653. \Notes
  3654. This routine should set InoutRes in case of error.
  3655. \end{functionl}
  3656. \begin{functionl}{Do{\_}FileSize}{dofilesize}
  3657. \Declaration
  3658. Function Do{\_}FileSize(Handle:Longint): Longint;
  3659. \Description
  3660. Returns the filesize in bytes.
  3661. \Parameters
  3662. handle = file handle of file to get the file size
  3663. \Notes
  3664. This routine should set InoutRes in case of error.
  3665. \end{functionl}
  3666. \begin{functionl}{Do{\_}IsDevice}{doisdevice}
  3667. \Declaration
  3668. Function Do{\_}ISDevice(Handle:Longint): boolean;
  3669. \Description
  3670. Returns TRUE if the file handle points to a device
  3671. instead of a file.
  3672. \Parameters
  3673. handle = file handle to gtet status on
  3674. \Notes
  3675. This routine should set InoutRes in case of error.
  3676. \end{functionl}
  3677. \begin{procedurel}{Do{\_}Open}{doopen}
  3678. \Declaration
  3679. Procedure Do{\_}Open(var f;p:pchar;flags:longint);
  3680. \Description
  3681. Opens a file in the specified mode, and sets the
  3682. \var{mode} and \var{handle} fields of the \var{f}
  3683. structure parameter.
  3684. \Parameters
  3685. f = pointer to \var{textrec} or \var{filerec} structure
  3686. p = name and path of file to open
  3687. flags = access mode to open the file with
  3688. \Notes
  3689. This routine should set InoutRes in case of error.
  3690. \end{procedurel}
  3691. \begin{procedurel}{ChDir}{chdir}
  3692. \Declaration
  3693. Procedure ChDir(Const s: String);[IOCheck];
  3694. \Description
  3695. Changes to the specified directory. . and ..
  3696. should also be supported by this call.
  3697. \Parameters
  3698. s = new directory to change to
  3699. \Notes
  3700. This routine should set InoutRes in case of error.
  3701. \end{procedurel}
  3702. \begin{procedurel}{MkDir}{mkdir}
  3703. \Declaration
  3704. Procedure MkDir(Const s: String);[IOCheck];
  3705. \Description
  3706. Creates the specified directory.
  3707. \Parameters
  3708. s = name of directory to create
  3709. \Notes
  3710. This routine should set InoutRes in case of error.
  3711. \end{procedurel}
  3712. \begin{procedurel}{RmDir}{rmdir}
  3713. \Declaration
  3714. Procedure RmDir(Const s: String);[IOCheck];
  3715. \Description
  3716. Removes the specified directory.
  3717. \Parameters
  3718. s = name of directory to remove
  3719. \Notes
  3720. This routine should set InoutRes in case of error.
  3721. \end{procedurel}
  3722. The following variables should also be defined for each new operating
  3723. system, they are used by external units:
  3724. \noindent
  3725. argc : The number of command line arguments of the program
  3726. \noindent
  3727. argv : A pointer to each of the command line arguments (an array of pchar
  3728. pointers)
  3729. \subsection{CPU specific hooks}
  3730. \label{subsec:mylabel9}
  3731. The following routines must absolutely be implemented for each processor, as
  3732. they are dependent on the processor:
  3733. \subsubsection{FPC{\_}SETJMP}
  3734. \label{subsubsec:mylabel30}
  3735. \begin{function}{SetJmp}
  3736. \Declaration
  3737. Function SetJmp (Var S : Jmp{\_}Buf) : Longint;
  3738. \Description
  3739. A call to SetJmp(), saves the calling environment in its \textsf{s} argument
  3740. for later use by \textsf{longjmp()}. Called by the code generator in
  3741. exception handling code. The return value should be zero.
  3742. \Notes
  3743. This routine should save / restore all used registers (except the
  3744. accumulator which should be cleared).
  3745. \end{function}
  3746. \subsubsection{FPC{\_}LONGJMP}
  3747. \label{subsubsec:mylabel31}
  3748. \subsubsection{function SPtr()}
  3749. \label{subsubsec:function}
  3750. \subsubsection{function Get{\_}Caller{\_}Frame(framebp:longint):longint;}
  3751. \label{subsubsec:mylabel32}
  3752. \subsubsection{function Get{\_}Caller{\_}Addr(framebp:longint):longint;}
  3753. \label{subsubsec:mylabel33}
  3754. \subsubsection{function Get{\_}Frame:longint;}
  3755. \label{subsubsec:mylabel34}
  3756. \subsubsection{function Trunc()}
  3757. \label{subsubsec:mylabel35}
  3758. \subsection{String related}
  3759. \label{subsec:string}
  3760. \subsubsection{FPC{\_}SHORTSTR{\_}COPY}
  3761. \label{subsubsec:mylabel36}
  3762. \begin{procedurel}{Int{\_}StrCopy}{intstrcopy}
  3763. \Declaration
  3764. Procedure Int{\_}StrCopy(Len:Longint;SStr,DStr:pointer);
  3765. \Description
  3766. This routine copies the string pointed to by the address in sstr, to the
  3767. string pointed in the destination. The old string is overwritten, and the
  3768. source string will be truncated to make it fit in destination if the length
  3769. of the source is greater then destination string len (the len parameter).
  3770. \Parameters
  3771. Len = maximum length to copy (the destination string length) \par
  3772. SStr = pointer to source shortstring \par
  3773. DStr = point to destination shortstring
  3774. \Notes
  3775. Called by code generator when a string is assigned to another string.
  3776. \end{procedurel}
  3777. \subsubsection{FPC{\_}SHORTSTR{\_}COMPARE}
  3778. \label{subsubsec:mylabel37}
  3779. \begin{functionl}{Int{\_}StrCmp}{intstrcmp}
  3780. \Declaration
  3781. Function Int{\_}StrCmp(DStr,SStr:Pointer) : Longint;
  3782. \Description
  3783. The routine compares two shortstrings, and returns 0 if both are equal, 1 if
  3784. \textsf{DStr} is greater then \textsf{SSrc}, otherwise it returns --1.
  3785. \Notes
  3786. Both pointers must point to shortstrings. Length checking must be performed
  3787. in the routine.
  3788. \end{functionl}
  3789. \subsubsection{FPC{\_}SHORTSTR{\_}CONCAT}
  3790. \label{subsubsec:mylabel38}
  3791. \begin{procedurel}{Int{\_}StrConcat}{intstrconcat}
  3792. \Declaration
  3793. Procedure Int{\_}StrConcat(Src,Dest:Pointer);
  3794. \Description
  3795. This routine appends the string pointed to by \textsf{Src} to the end of the
  3796. string pointed to by \textsf{Dest}.
  3797. \Parameters
  3798. Src = pointer to shortstring to append to dest \par
  3799. Dest = pointer to shortstring to receive appended string
  3800. \Notes
  3801. Both pointers must point to shortstrings. In the case where the src string
  3802. length does not fit in dest, it is truncated.
  3803. \Algorithm
  3804. \begin{lstlisting}{}
  3805. if src =nil or dest = nil then
  3806. exit routine;
  3807. if (src string length + dest string length) > 255 then
  3808. number of bytes to copy = 255 -- dest string length
  3809. else
  3810. number of bytes to copy = src string length;
  3811. copy the string data (except the length byte)
  3812. dest string length = dest string length + number of bytes to copied
  3813. \end{lstlisting}
  3814. \end{procedurel}
  3815. \subsubsection{FPC{\_}ANSISTR{\_}CONCAT}
  3816. \label{subsubsec:mylabel39}
  3817. \begin{procedurel}{AnsiStr{\_}Concat}{ansistrconcat}
  3818. \Declaration
  3819. Procedure AnsiStr{\_}Concat(s1,s2:Pointer;var s3:Pointer);
  3820. \Description
  3821. This routine appends \textsf{s1}+\textsf{s2} and stores the result at the
  3822. address pointed to by \textsf{s3}.
  3823. \Notes
  3824. All pointers must point to ansistrings.
  3825. \end{procedurel}
  3826. \subsubsection{FPC{\_}ANSISTR{\_}COMPARE}
  3827. \label{subsubsec:mylabel40}
  3828. \begin{functionl}{AnsiStr{\_}Compare}{ansistrcompare}
  3829. \Declaration
  3830. Function AnsiStr{\_}Compare(s1,s2 : Pointer): Longint;
  3831. \Description
  3832. The routine compares two ansistrings, and returns 0 if both are equal, 1 if
  3833. \textsf{s1} is greater then \textsf{s2}, otherwise it returns --1.
  3834. \Parameters
  3835. Both pointers must point to ansistrings.
  3836. \end{functionl}
  3837. \subsubsection{FPC{\_}ANSISTR{\_}INCR{\_}REF }
  3838. \label{subsubsec:mylabel41}
  3839. \begin{procedurel}{AnsiStr{\_}Incr{\_}Ref}{ansistrincrref}
  3840. \Declaration
  3841. procedure AnsiStr{\_}Incr{\_}Ref (var s : Pointer);
  3842. \Description
  3843. This routine simply increments the ANSI string reference count, which is
  3844. used for garbage collection of ANSI strings.
  3845. \Parameters
  3846. s = pointer to the ansi string (including the header structure)
  3847. \end{procedurel}
  3848. \subsubsection{FPC{\_}ANSISTR{\_}DECR{\_}REF }
  3849. \label{subsubsec:mylabel42}
  3850. \begin{procedurel}{AnsiStr{\_}Decr{\_}Ref}{ansistrdecrref}
  3851. \Declaration
  3852. procedure AnsiStr{\_}Decr{\_}Ref (Var S : Pointer);
  3853. \Parameters
  3854. s = pointer to the ansi string (including the header structure)
  3855. \Algorithm
  3856. Decreases the internal reference count of this non constant ansistring; If
  3857. the reference count is zero, the string is deallocated from the
  3858. heap.
  3859. \end{procedurel}
  3860. \subsubsection{FPC{\_}ANSISTR{\_}ASSIGN }
  3861. \label{subsubsec:mylabel43}
  3862. \begin{functionl}{AnsiStr{\_}Assign}{ansistrassign}
  3863. \Declaration
  3864. Procedure AnsiStr{\_}Assign (var s1 : Pointer;s2 : Pointer);
  3865. \Parameters
  3866. s1 = address of ANSI string to be assigned to \par
  3867. s2 = address of ANSI string which will be assigned
  3868. \Algorithm
  3869. Assigns S2 to S1 (S1:=S2), also by the time decreasing the reference count
  3870. to S1 (it is no longer used by this variable).
  3871. \end{functionl}
  3872. \subsubsection{FPC{\_}PCHAR{\_}TO{\_}SHORTSTR}
  3873. \label{subsubsec:mylabel44}
  3874. \begin{function}{StrPas}
  3875. \Declaration
  3876. Function StrPas(p:pChar):ShortString;
  3877. \Description
  3878. Copies and converts a null-terminated string (pchar) to a shortstring with
  3879. length checking.
  3880. \Parameters
  3881. p = pointer to null terminated string to copy
  3882. \Notes
  3883. Length checking is performed. Verifies also p=nil, and if so sets the
  3884. shortstring length to zero. Called by the type conversion generated code of
  3885. code generator.
  3886. \Algorithm
  3887. \begin{lstlisting}{}
  3888. if p=nil then
  3889. string length =0
  3890. else
  3891. string length =string length(p)
  3892. if string length>255 then
  3893. string length = 255
  3894. if string length>0 then
  3895. Copy all characters of pchar array to string (except length byte)
  3896. \end{lstlisting}
  3897. \end{function}
  3898. \subsubsection{FPC{\_}SHORTSTR{\_}TO{\_}ANSISTR}
  3899. \label{subsubsec:mylabel45}
  3900. \begin{functionl}{FPC{\_}ShortStr{\_}To{\_}AnsiStr}{fpcshortstrtoansistr}
  3901. \Notes
  3902. Called by the type conversion generated code of code generator.
  3903. \end{functionl}
  3904. \subsubsection{FPC{\_}STR{\_}TO{\_}CHARARRAY}
  3905. \label{subsubsec:mylabel46}
  3906. \begin{procedurel}{Str{\_}To{\_}CharArray}{strtochararray}
  3907. \Declaration
  3908. procedure Str{\_}To{\_}CharArray(StrTyp, ArraySize: Longint; src,dest: pChar);
  3909. \Description
  3910. Converts a string to a character array (currently supports both shortstring and ansistring types). Length checking is performed, and copies up to \textsf{arraysize} elements to dest.
  3911. \Parameters
  3912. strtyp = Indicates the conversion type to do (0 = shortstring, 1 =
  3913. ansistring, 2 = longstring, 3 = widestring) \\
  3914. arraysize = size of the destination array \par
  3915. src = pointer to source string \par
  3916. dest = pointer to character array
  3917. \Notes
  3918. Called by the type conversion generated code of code generator when
  3919. converting a string to an array of char. If the size of the string is less
  3920. then the size of the array, the rest of the array is filled with zeros.
  3921. \end{procedurel}
  3922. \subsubsection{FPC{\_}CHARARRAY{\_}TO{\_}SHORTSTR}
  3923. \label{subsubsec:mylabel47}
  3924. \begin{function}{StrCharArray}
  3925. \Declaration
  3926. Function StrCharArray(p:pChar; l : Longint):ShortString;
  3927. \Description
  3928. Copies a character array to a shortstring with length checking (upto 255
  3929. characters are copied)
  3930. \Parameters
  3931. p = Character array pointer \par
  3932. l = size of the array
  3933. \Notes
  3934. Called by the type conversion generated code of code generator when
  3935. converting an array of char to a shortstring.
  3936. \Algorithm
  3937. \begin{lstlisting}{}
  3938. if size of array >= 256 then
  3939. length of string =255
  3940. else
  3941. if size of array < 0 then
  3942. length of string = 0
  3943. else
  3944. length of string = size of array
  3945. Copy all characters from array to shortstring
  3946. \end{lstlisting}
  3947. \end{function}
  3948. \subsubsection{FPC{\_}CHARARRAY{\_}TO{\_}ANSISTR}
  3949. \label{subsubsec:mylabel48}
  3950. \begin{functionl}{Fpc{\_}Chararray{\_}To{\_}AnsiStr}{chararraytoansistr}
  3951. \Notes
  3952. Called by the type conversion generated code of code generator when converting an array of char to an ansistring.
  3953. \end{functionl}
  3954. \subsubsection{FPC{\_}CHAR{\_}TO{\_}ANSISTR}
  3955. \label{subsubsec:mylabel49}
  3956. \begin{functionl}{Fpc{\_}Char{\_}To{\_}AnsiStr}{fpcchartoansistr}
  3957. \Notes
  3958. Called by the type conversion generated code of code generator when
  3959. converting a char to an ansistring.
  3960. \end{functionl}
  3961. \subsubsection{FPC{\_}PCHAR{\_}TO{\_}ANSISTR}
  3962. \label{subsubsec:mylabel50}
  3963. \begin{functionl}{Fpc{\_}pChar{\_}To{\_}AnsiStr}{fpcpchartoansistr}
  3964. \Notes
  3965. Called by the type conversion generated code of code generator when
  3966. converting a pchar to an ansistring.
  3967. \end{functionl}
  3968. \subsection{Compiler runtime checking}
  3969. \label{subsec:compiler}
  3970. \subsubsection{FPC{\_}STACKCHECK}
  3971. \label{subsubsec:mylabel51}
  3972. \begin{procedurel}{Int{\_}StackCheck}{intstackcheck}
  3973. \Declaration
  3974. procedure int{\_}stackcheck (stack{\_}size:longint);
  3975. \Description
  3976. This routine is used to check if there will be a stack overflow when trying
  3977. to allocate stack space from the operating system. The routine must preserve
  3978. all registers. In the case the stack limit is reached, the routine calls the
  3979. appropriate error handler.
  3980. \Parameters
  3981. stack{\_}size = The amount of stack we wish to allocate
  3982. \Notes
  3983. Inserted in the entry code of a routine in the {\{}{\$}S+{\}} state by the code generator
  3984. \Algorithm
  3985. \begin{lstlisting}{}
  3986. if ((StackPointer - stack_size) < System.StackLimit) then
  3987. Throw a Runtime error with error code 202 (stack overflow)
  3988. \end{lstlisting}
  3989. \end{procedurel}
  3990. \subsubsection{FPC{\_}RANGEERROR}
  3991. \label{subsubsec:mylabel52}
  3992. \begin{procedurel}{Int{\_}RangeError}{intrangerror}
  3993. \Declaration
  3994. procedure Int{\_}RangeError;
  3995. \Description
  3996. This routine is called when a range check error is detected when executing
  3997. the compiled code. This usually simply calls the default error handler, with
  3998. the correct runtime error code to produce.
  3999. \Parameters
  4000. Inserted in code generator when a Runtime error 201 {\{}{\$}R+{\}} should be
  4001. generated
  4002. \end{procedurel}
  4003. \subsubsection{FPC{\_}BOUNDCHECK}
  4004. \label{subsubsec:mylabel53}
  4005. \begin{procedurel}{Int{\_}BoundCheck}{intboundcheck}
  4006. \Declaration
  4007. procedure Int{\_}BoundCheck(l : Longint; Range : Pointer);
  4008. \Description
  4009. This routine is called at runtime in {\$}R+ mode to check if accessing
  4010. indexes in a string or array is out of bounds. In this case, the default
  4011. error handler is called, with the correct runtime error code to produce.
  4012. \Parameters
  4013. l = Index we need to check \par
  4014. range = pointer to a structure containing the minimum and maximum allowed
  4015. indexes (points to two 32-bit signed values which are the limits of the
  4016. array to verify).
  4017. \Notes
  4018. Inserted in the generated code after assignments, and array indexing to
  4019. verify if the result of operands is within range (in the {\{}{\$}R+{\}}
  4020. state)
  4021. \end{procedurel}
  4022. \subsubsection{FPC{\_}OVERFLOW}
  4023. \label{subsubsec:mylabel54}
  4024. \begin{procedurel}{Int{\_}OverFlow}{intoverflow}
  4025. \Declaration
  4026. procedure Int{\_}OverFlow;
  4027. \Description
  4028. This routine is called when an overflow is detected when executing the
  4029. compiled code. This usually simply calls the default error handler, with the
  4030. correct runtime error code to produce.
  4031. \Parameters
  4032. Inserted in code generator when a Runtime error 215 {\{}{\$}Q+{\}} should be
  4033. generated.
  4034. \end{procedurel}
  4035. \subsubsection{FPC{\_}CHECK{\_}OBJECT}
  4036. \label{subsubsec:mylabel55}
  4037. \begin{procedurel}{Int{\_}Check{\_}Object}{intcheckobject}
  4038. \Declaration
  4039. procedure Int{\_}Check{\_}Object(vmt : Pointer);
  4040. \Description
  4041. This routine is called at runtime in the {\$}R+ state each time a virtual
  4042. method is called. It verifies that the object constructor has been called
  4043. first to build the VMT of the object, otherwise it throws an Runtime error 210.
  4044. \Parameters
  4045. vmt = Current value of the SELF register
  4046. \Notes
  4047. Call inserted by the code generator before calling the virtual method. This
  4048. routine should save / restore all used registers.
  4049. \Algorithm
  4050. \begin{lstlisting}{}
  4051. if vmt = nil or size of method table =0 then
  4052. Throw a Runtime error with error code 210 (object not initialized)
  4053. \end{lstlisting}
  4054. \end{procedurel}
  4055. \subsubsection{FPC{\_}CHECK{\_}OBJECT{\_}EXT}
  4056. \label{subsubsec:mylabel56}
  4057. \begin{procedurel}{Int{\_}Check{\_}Object{\_}Ext}{intcheckobjectext}
  4058. \Declaration
  4059. procedure Int{\_}Check{\_}Object{\_}Ext(vmt, expvmt : pointer);
  4060. \Description
  4061. This routine is called at runtime when extended object checking is enabled (on the command line) and a virtual method is called. It verifies that the object constructor has been called first to build the VMT of the object, otherwise it throws an Runtime error 210, and furthermore it check that the object is actually a descendant of the parent object, otherwise it returns a Runtime error 219.
  4062. \Parameters
  4063. vmt = Current value of the SELF register \par
  4064. expvmt = Pointer to TRUE object definition
  4065. \Notes
  4066. Call inserted by the code generator before calling the virtual method. \par
  4067. This routine should save / restore all used registers.
  4068. \Algorithm
  4069. \begin{lstlisting}{}
  4070. if vmt = nil or size of method table =0 then
  4071. Throw a Runtime error with error code 210 (object not initialized)
  4072. Repeat
  4073. If SELF (VMT) <> VMT Address (expvmt) Then
  4074. Get Parent VMT Address
  4075. Else
  4076. Exit;
  4077. until no more ent;
  4078. Throw a Runtime error with error code 220 (Incorrect object reference)
  4079. \end{lstlisting}
  4080. \end{procedurel}
  4081. \subsubsection{FPC{\_}IO{\_}CHECK}
  4082. \label{subsubsec:mylabel57}
  4083. \begin{procedurel}{Int{\_}IOCheck}{intiocheck}
  4084. \Declaration
  4085. procedure Int{\_}IOCheck(addr : longint);
  4086. \Description
  4087. This routine is called after an I/O operation to verify the success of the
  4088. operation when the code is compiled in the {\$}I+ state.
  4089. \Parameters
  4090. addr = currently unused
  4091. \Algorithm
  4092. Check last I/O was successful, if not call error handler.
  4093. \end{procedurel}
  4094. \subsubsection{FPC{\_}HANDLEERROR}
  4095. \label{subsubsec:mylabel58}
  4096. \begin{procedure}{HandleError}
  4097. \Declaration
  4098. procedure HandleError (Errno : longint);
  4099. \Description
  4100. This routine should be called to generate a runtime error either from one of
  4101. the system unit routines or the code generator.
  4102. \Parameters
  4103. Errno = Runtime error to generate
  4104. \Notes
  4105. This routine calls the appropriate existing error handler with the specified
  4106. error code.
  4107. \Algorithm
  4108. \end{procedure}
  4109. \subsubsection{FPC{\_}ASSERT}
  4110. \label{subsubsec:mylabel59}
  4111. \begin{procedurel}{Int{\_}Assert}{intassert}
  4112. \Declaration
  4113. procedure Int{\_}Assert(Const Msg,FName:Shortstring;LineNo,ErrorAddr:Longint);
  4114. \Description
  4115. This routine is called by the code generator in an assert statement. When
  4116. the assertion fails, this routine is called.
  4117. \Parameters
  4118. msg = string to print \par
  4119. Fname = Current filename of source \par
  4120. LineNo = Current line number of source \par
  4121. ErrorAddr = Address of assertion failure
  4122. \end{procedurel}
  4123. \subsection{Exception handling}
  4124. \label{subsec:exception}
  4125. \subsubsection{FPC{\_}RAISEEXCEPTION}
  4126. \label{subsubsec:mylabel60}
  4127. \begin{function}{RaiseExcept}
  4128. \Declaration
  4129. function RaiseExcept (Obj : Tobject; AnAddr,AFrame : Pointer) : Tobject;
  4130. \Description
  4131. Called by the code generator in the raise statement to raise an exception.
  4132. \Parameters
  4133. Obj = Instance of class exception handler \par
  4134. AnAddr = Address of exception \par
  4135. Aframe = Exception frame address
  4136. \Notes
  4137. REGISTERS NOT SAVED???????????
  4138. \end{function}
  4139. \subsubsection{FPC{\_}PUSHEXCEPTADDR}
  4140. \label{subsubsec:mylabel61}
  4141. \begin{function}{PushExceptAddr}
  4142. \Declaration
  4143. function PushExceptAddr (Ft: Longint): PJmp{\_}buf ;
  4144. \Description
  4145. This routine should be called to save the current caller context to be used
  4146. for exception handling, usually called in the context where ANSI strings are
  4147. used (they can raise exceptions), or in a try..finally or on statements to
  4148. save the current context.
  4149. \Parameters
  4150. Ft = Indicates the frame type on the stack (1= Exception frame or 2=Finalize
  4151. frame)
  4152. \Algorithm
  4153. Adds this item to the linked list of stack frame context information saved.
  4154. Allocates a buffer for the jump statement and returns it.
  4155. \end{function}
  4156. \subsubsection{FPC{\_}RERAISE}
  4157. \label{subsubsec:mylabel62}
  4158. \begin{procedure}{ReRaise}
  4159. \Declaration
  4160. procedure ReRaise;
  4161. \Notes
  4162. REGISTERS NOT SAVED???????????
  4163. \end{procedure}
  4164. \subsubsection{FPC{\_}POPOBJECTSTACK}
  4165. \label{subsubsec:mylabel63}
  4166. \begin{function}{PopObjectStack}
  4167. \Declaration
  4168. function PopObjectStack : TObject;
  4169. \Description
  4170. This is called by the code generator when an exception occurs, it is used to
  4171. retrieve the exception handler object from the context information.
  4172. \Notes
  4173. REGISTERS NOT SAVED???????????
  4174. \end{function}
  4175. \subsubsection{FPC{\_}POPSECONDOBJECTSTACK}
  4176. \label{subsubsec:mylabel64}
  4177. \begin{function}{PopSecondObjectStack}
  4178. \Declaration
  4179. function PopSecondObjectStack : TObject;
  4180. \Description
  4181. This is called by the code generator when a double exception occurs, it is
  4182. used to retrieve the second exception handler object from the context
  4183. information.
  4184. \Notes
  4185. REGISTERS NOT SAVED???????????
  4186. \end{function}
  4187. \subsubsection{FPC{\_}DESTROYEXCEPTION}
  4188. \label{subsubsec:mylabel65}
  4189. \begin{procedure}{DestroyException}
  4190. \Declaration
  4191. Procedure DestroyException(o : TObject);
  4192. \Description
  4193. This routine is called by the code generator after the exception handling
  4194. code is complete to destroy the exception object.
  4195. \Parameters
  4196. o = Exception handler object reference
  4197. \Notes
  4198. REGISTERS NOT SAVED?????????????
  4199. \end{procedure}
  4200. \subsubsection{FPC{\_}POPADDRSTACK}
  4201. \label{subsubsec:mylabel66}
  4202. \begin{procedure}{PopAddrStack}
  4203. \Declaration
  4204. procedure PopAddrStack;
  4205. \Description
  4206. Called by the code generator in the finally part of a try statement to
  4207. restore the stackframe and dispose of all the saved context information.
  4208. \Notes
  4209. REGISTERS NOT SAVED??????????
  4210. \end{procedure}
  4211. \subsubsection{FPC{\_}CATCHES}
  4212. \label{subsubsec:mylabel67}
  4213. \begin{function}{Catches}
  4214. \Declaration
  4215. function Catches(Objtype : TExceptObjectClass) : TObject;
  4216. \Description
  4217. This routine is called by the code generator to get the exception handler
  4218. object. ?????????????????
  4219. \Parameters
  4220. ObjType = The exception type class
  4221. \Notes
  4222. REGISTERS NOT SAVED??????????
  4223. \end{function}
  4224. \subsubsection{FPC{\_}GETRESOURCESTRING}
  4225. \label{subsubsec:mylabel68}
  4226. \begin{function}{GetResourceString}
  4227. \Declaration
  4228. function GetResourceString(Const TheTable: TResourceStringTable;Index : longint) : AnsiString;
  4229. \Description
  4230. Called by code generator when a reference to a resource string is made. This
  4231. routine loads the correct string from the resource string section and
  4232. returns the found string (or `' if not found).
  4233. \Parameters
  4234. TheTable = pointer to the resource string table \par
  4235. Index = Index in the resource string table.
  4236. \end{function}
  4237. \subsection{Runtime type information}
  4238. \label{subsec:runtime}
  4239. \subsubsection{FPC{\_}DO{\_}IS}
  4240. \label{subsubsec:mylabel69}
  4241. \begin{functionl}{Int{\_}Do{\_}Is}{intdois}
  4242. \Declaration
  4243. Function Int{\_}Do{\_}Is(AClass : TClass;AObject : TObject) : Boolean;
  4244. \Description
  4245. If \textsf{aclass} is of type \textsf{aobject}, returns TRUE otherwise
  4246. returns FALSE.
  4247. \Parameters
  4248. aclass = class type reference \par
  4249. aobject = Object instance to compare against
  4250. \Notes
  4251. This is called by the code generator when the \textsf{is} operator is used.
  4252. \Algorithm
  4253. \end{functionl}
  4254. \subsubsection{FPC{\_}DO{\_}AS}
  4255. \label{subsubsec:mylabel70}
  4256. \begin{procedurel}{Int{\_}Do{\_}As}{intdoas}
  4257. \Declaration
  4258. Procedure Int{\_}Do{\_}As(AClass : TClass;AObject : TObject)
  4259. \Description
  4260. Typecasts \textsf{aclass} as \textsf{aobject}, with dynamic type checking.
  4261. If the object is not from the correct type class, a runtime error 219 is
  4262. generated. Called by the code generator for the \textsf{as} statement.
  4263. \Parameters
  4264. aclass = Class to typecast to \par
  4265. aobject = Object to typecast
  4266. \end{procedurel}
  4267. \subsubsection{FPC{\_}INITIALIZE }
  4268. \label{subsubsec:mylabel71}
  4269. \begin{procedure}{Initialize}
  4270. \Declaration
  4271. Procedure Initialize (Data,TypeInfo : Pointer);
  4272. \Description
  4273. \Parameters
  4274. data = pointer to the data to initialize \par
  4275. typeinfo = pointer to the type information for this data
  4276. \Notes
  4277. This routine should save / restore all used registers.
  4278. \Algorithm
  4279. Initializes the class data for runtime typed values
  4280. \end{procedure}
  4281. \subsubsection{FPC{\_}FINALIZE}
  4282. \label{subsubsec:mylabel72}
  4283. \begin{procedure}{Finalize}
  4284. \Declaration
  4285. procedure Finalize (Data,TypeInfo: Pointer);
  4286. \Description
  4287. Called by code generator if and only if the reference to finalize <> nil.
  4288. \Parameters
  4289. data = point to the data to finalize \par
  4290. typeinfo = Pointer to the type information of this data
  4291. \Notes
  4292. This routine should save / restore all used registers. Finalizes and frees
  4293. the heap class data for runtime typed values (decrements the reference
  4294. count)
  4295. \end{procedure}
  4296. \subsubsection{FPC{\_}ADDREF}
  4297. \label{subsubsec:mylabel73}
  4298. \begin{procedure}{AddRef}
  4299. \Declaration
  4300. Procedure AddRef (Data,TypeInfo : Pointer);
  4301. \Description
  4302. Called by the code generator for class parameters (property support) of type
  4303. const or value in parameters, to increment the reference count of ANSI
  4304. strings.
  4305. \Notes
  4306. This routine should save / restore all used registers. This routine can be
  4307. called recursively with a very deep nesting level, an assembler
  4308. implementation in suggested.
  4309. \end{procedure}
  4310. \subsubsection{FPC{\_}DECREF}
  4311. \label{subsubsec:mylabel74}
  4312. \begin{procedure}{DecRef}
  4313. \Declaration
  4314. Procedure DecRef (Data, TypeInfo : Pointer);
  4315. \Description
  4316. Called by the code generator for class parameters (property support) of type
  4317. const or value parameters, to decrement the reference count. of ANSI
  4318. strings.
  4319. \Parameters
  4320. \Notes
  4321. This routine should save / restore all used registers. This routine can be
  4322. called recursively with a very deep nesting level, an assembler
  4323. implementation in suggested.
  4324. \end{procedure}
  4325. \subsection{Memory related}
  4326. \label{subsec:memory}
  4327. \subsubsection{FPC{\_}GETMEM}
  4328. \label{subsubsec:mylabel75}
  4329. \begin{procedure}{GetMem}
  4330. \Declaration
  4331. procedure GetMem(Var p:Pointer;Size:Longint);
  4332. \end{procedure}
  4333. \subsubsection{FPC{\_}FREEMEM}
  4334. \label{subsubsec:mylabel76}
  4335. \begin{procedure}{FreeMem}
  4336. \Declaration
  4337. Procedure FreeMem(Var P:Pointer;Size:Longint);
  4338. \end{procedure}
  4339. \subsubsection{FPC{\_}CHECKPOINTER}
  4340. \label{subsubsec:mylabel77}
  4341. \begin{function}{CheckPointer}
  4342. \Declaration
  4343. Procedure CheckPointer(p : Pointer);
  4344. \Description
  4345. Called by the code generator when a pointer is referenced in heap debug
  4346. mode. Verifies that the pointer actually points in the heap area.
  4347. \Parameters
  4348. p = pointer to check
  4349. \Notes
  4350. This routine should save /restore all used registers.
  4351. \end{function}
  4352. \subsubsection{FPC{\_}DO{\_}EXIT}
  4353. \label{subsubsec:mylabel78}
  4354. \begin{procedurel}{Do{\_}Exit}{doexit}
  4355. \Declaration
  4356. procedure Do{\_}Exit;
  4357. \Description
  4358. Called by code generator at the end of the program entry point.
  4359. \Notes
  4360. Called to terminate the program
  4361. \Algorithm
  4362. Call all unit exit handlers. \par
  4363. Finalize all units which have a finalization section \par
  4364. Print runtime error in case of error\par
  4365. Call OS-dependant system{\_}exit routine
  4366. \end{procedurel}
  4367. \subsubsection{FPC{\_}ABSTRACTERROR}
  4368. \label{subsubsec:mylabel79}
  4369. \begin{function}{AbstractError}
  4370. \Declaration
  4371. procedure AbstractError;
  4372. \Description
  4373. The code generator allocates a VMT entry equal to this routine address when
  4374. a method of a class is declared as being abstract. This routine simply calls
  4375. the default error handler.
  4376. \Algorithm
  4377. Throw a Runtime error with error code 211 (Abstract call)
  4378. \end{function}
  4379. \subsubsection{FPC{\_}INITIALIZEUNITS}
  4380. \label{subsubsec:mylabel80}
  4381. \begin{function}{InitializeUnits}
  4382. \Declaration
  4383. \Description
  4384. Called by the code generator in the main program, this is only available if
  4385. an \textsf{initialization} section exists in one of the units used by the
  4386. program.
  4387. \end{function}
  4388. \subsubsection{FPC{\_}NEW{\_}CLASS (assembler)}
  4389. \label{subsubsec:mylabel81}
  4390. \begin{procedurel}{int{\_}new{\_}class}{intnewclass}
  4391. \Description
  4392. This routine will call the TObject.InitInstance() routine to
  4393. instantiate a class (Delphi-styled class) and allocate the memory for all
  4394. fields of the class.
  4395. On entry the self{\_}register should be valid, and should point either to
  4396. nil, for a non-initialized class, or to the current instance of the class.
  4397. The first parameter on the top of the stack should be a pointer to the VMT
  4398. table for this class(????).
  4399. \end{procedurel}
  4400. \subsubsection{FPC{\_}HELP{\_}DESTRUCTOR}
  4401. \label{subsubsec:mylabel82}
  4402. Could be implemented in ASM directly with register parameter passing.
  4403. \begin{procedurel}{Int{\_}Help{\_}Destructor}{inthelpdestructor}
  4404. \Declaration
  4405. Procedure Int{\_}Help{\_}Destructor(Var {\_}Self : Pointer; Vmt : Pointer; Vmt{\_}Pos : Cardinal);
  4406. \Description
  4407. Frees the memory allocated for the object fields, and if the object had a
  4408. VMT field, sets it to nil.
  4409. \Parameters
  4410. self = pointer to the object field image in memory \par
  4411. vmt = pointer to the the actual vmt table (used to get the size of the object) \par
  4412. vmt{\_}pos = offset in the object field image to the vmt pointer field
  4413. \Notes
  4414. This routine should / save restore all used registers.
  4415. \Algorithm
  4416. \begin{lstlisting}{}
  4417. if self = nil then
  4418. exit
  4419. set VMT field in object field image ,if present, to nil
  4420. Free the allocated heap memory for the field objects
  4421. set Self = nil
  4422. \end{lstlisting}
  4423. \end{procedurel}
  4424. \subsubsection{FPC{\_}HELP{\_}CONSTRUCTOR}
  4425. \label{subsubsec:mylabel83}
  4426. Could be implemented in ASM directly with register parameter passing.
  4427. \begin{functionl}{Int{\_}Help{\_}Constructor}{inthelpconstructor}
  4428. \Declaration
  4429. function Int{\_}Help{\_}Constructor(Var {\_}self : Pointer; Var VMT : Pointer; Vmt{\_}Pos : Cardinal):Pointer;
  4430. \Description
  4431. Allocates the memory for an object's field, and fills the object fields with
  4432. zeros. Returns the newly allocated self{\_}pointer
  4433. \Parameters
  4434. self = pointer to the object field image in memory \par
  4435. vmt = pointer to the the actual vmt table (used to get the size of the object) \par
  4436. vmt{\_}pos = offset in the object field image to the vmt pointer field
  4437. \Notes
  4438. The self{\_}pointer register should be set appropriately by the code
  4439. generator to the allocated memory (self parameter)
  4440. \Algorithm
  4441. Self = Allocate Memory block for object fields \par
  4442. Fill the object field image with zeros\par
  4443. Set the VMT field in allocated object to VMT pointer
  4444. \end{functionl}
  4445. \subsubsection{FPC{\_}HELP{\_}FAIL{\_}CLASS}
  4446. \label{subsubsec:mylabel84}
  4447. \begin{functionl}{Help{\_}Fail{\_}Class}{inthelpfileclass}
  4448. \Description
  4449. Inserted by code generator after constructor call. If the constructor failed
  4450. to allocate the memory for its fields, this routine will be called.
  4451. \end{functionl}
  4452. \subsubsection{FPC{\_}HELP{\_}FAIL}
  4453. \label{subsubsec:mylabel85}
  4454. \begin{functionl}{Help{\_}Fail}{HelpFail}
  4455. \Description
  4456. Inserted by code generator after constructor call. If the constructor failed
  4457. to allocate the memory for its fields, this routine will be called.
  4458. \end{functionl}
  4459. \subsection{Set handling}
  4460. \label{subsec:mylabel10}
  4461. \subsubsection{FPC{\_}SET{\_}COMP{\_}SETS}
  4462. \label{subsubsec:mylabel86}
  4463. \begin{functionl}{Do{\_}Comp{\_}Sets}{docompsets}
  4464. \Declaration
  4465. function Do{\_}Comp{\_}Sets(Set1,Set2 : Pointer): Boolean;
  4466. \Description
  4467. This routine compares if set1 and set2 are exactly equal and returns 1 if
  4468. so, otherwise it returns false.
  4469. \Parameters
  4470. set1 = Pointer to 32 byte set to compare \par
  4471. set2 = Pointer to 32 byte set to compare
  4472. \Notes
  4473. Both pointers must point to normal sets.
  4474. \end{functionl}
  4475. \subsubsection{FPC{\_}SET{\_}CONTAINS{\_}SET}
  4476. \label{subsubsec:mylabel87}
  4477. \begin{procedurel}{Do{\_}Contains{\_}Sets}{docontainssets}
  4478. \Declaration
  4479. Procedure Do{\_}Contains{\_}Sets(Set1,Set2 : Pointer): Boolean;
  4480. \Description
  4481. Returns 1 if set2 contains set1 (That is all elements of set2 are in set1).
  4482. \Parameters
  4483. set1 = Pointer to 32 byte set to verify \par
  4484. set2 = Pointer to 32 byte set to verify
  4485. \Notes
  4486. Both pointers must point to normal sets.
  4487. \end{procedurel}
  4488. \subsubsection{FPC{\_}SET{\_}CREATE{\_}ELEMENT}
  4489. \label{subsubsec:mylabel88}
  4490. \begin{procedurel}{Do{\_}Create{\_}Element}{docreateelement}
  4491. \Declaration
  4492. procedure Do{\_}Create{\_}Element(p : Pointer; b : Byte);
  4493. \Description
  4494. Create a new normal set in the area pointed to by \textsf{p} and add the
  4495. element value \textsf{b} in that set.
  4496. \Parameters
  4497. p = pointer to area where the 32 byte set will be created \par
  4498. b = bit value within that set which must be set
  4499. \Notes
  4500. This works on normal sets only.
  4501. \Algorithm
  4502. Zero the area pointed to by p \par
  4503. Set the bit number b to 1
  4504. \end{procedurel}
  4505. \subsubsection{FPC{\_}SET{\_}SET{\_}RANGE}
  4506. \label{subsubsec:mylabel89}
  4507. \begin{procedurel}{Do{\_}Set{\_}Range}{dosetrange}
  4508. \Declaration
  4509. Procedure Do{\_}Set{\_}Range(P : Pointer;l,h : Byte);
  4510. \Description
  4511. Sets the bit values within the \textsf{l} and \textsf{h }bit ranges in the
  4512. normal set pointed to by \textsf{p}
  4513. \Parameters
  4514. p = pointer to area where the 32 bytes of the set will be updated \par
  4515. l = low bit number value to set \par
  4516. h = high bit number value to set
  4517. \Notes
  4518. This works on normal sets only.
  4519. \Algorithm
  4520. Set all bit numbers from l to h in set p
  4521. \end{procedurel}
  4522. \subsubsection{FPC{\_}SET{\_}SET{\_}BYTE}
  4523. \label{subsubsec:mylabel90}
  4524. \begin{procedurel}{Do{\_}Set{\_}Byte}{dosetbyte}
  4525. \Declaration
  4526. procedure Do{\_}Set{\_}Byte(P : Pointer;B : byte);
  4527. \Description
  4528. Add the element \textsf{b} in the normal set pointed to by \textsf{p}
  4529. \Parameters
  4530. p = pointer to 32 byte set \par
  4531. b = bit number to set
  4532. \Notes
  4533. This works on normal sets only. The intel 80386 version of the compiler does
  4534. not save the used registers, therefore, in that case, it must be done in the
  4535. routine itself.
  4536. \Algorithm
  4537. Set bit number b in p
  4538. \end{procedurel}
  4539. \subsubsection{FPC{\_}SET{\_}SUB{\_}SETS}
  4540. \label{subsubsec:mylabel91}
  4541. \begin{procedurel}{Do{\_}Sub{\_}Sets}{dosubsets}
  4542. \Declaration
  4543. Procedure Do{\_}Sub{\_}Sets(Set1,Set2,Dest:Pointer);
  4544. \Description
  4545. Calculate the difference between \textsf{set1} and \textsf{set2}, setting
  4546. the result in \textsf{dest}.
  4547. \Parameters
  4548. set1 = pointer to 32 byte set \par
  4549. set2 = pointer to 32 byte set \par
  4550. dest = pointer to 32 byte set which will receive the result
  4551. \Notes
  4552. This works on normal sets only.
  4553. \Algorithm
  4554. \begin{lstlisting}{}
  4555. For each bit in the set do
  4556. dest bit = set1 bit AND NOT set2 bit
  4557. \end{lstlisting}
  4558. \end{procedurel}
  4559. \subsubsection{FPC{\_}SET{\_}MUL{\_}SETS}
  4560. \label{subsubsec:mylabel92}
  4561. \begin{procedurel}{Do{\_}Mul{\_}Sets}{domulsets}
  4562. \Declaration
  4563. procedure Do{\_}Mul{\_}Sets(Set1,Set2,Dest:Pointer);
  4564. \Description
  4565. Calculate the multiplication between \textsf{set1} and \textsf{set2},
  4566. setting the result in \textsf{dest}.
  4567. \Parameters
  4568. set1 = pointer to 32 byte set \par
  4569. set2 = pointer to 32 byte set \par
  4570. dest = pointer to 32 byte set which will receive the result
  4571. \Notes
  4572. This works on normal sets only.
  4573. \Algorithm
  4574. \begin{lstlisting}{}
  4575. For each bit in the set do
  4576. dest bit = set1 bit AND set2 bit
  4577. \end{lstlisting}
  4578. \end{procedurel}
  4579. \subsubsection{FPC{\_}SET{\_}SYMDIF{\_}SETS}
  4580. \label{subsubsec:mylabel93}
  4581. \begin{procedurel}{Do{\_}Symdif{\_}Sets}{dosymdifssets}
  4582. \Declaration
  4583. Procedure Do{\_}Symdif{\_}Sets(Set1,Set2,Dest:Pointer);
  4584. \Description
  4585. Calculate the symmetric between \textsf{set1} and \textsf{set2}, setting the
  4586. result in \textsf{dest}.
  4587. \Parameters
  4588. set1 = pointer to 32 byte set \par
  4589. set2 = pointer to 32 byte set \par
  4590. dest = pointer to 32 byte set which will receive the result
  4591. \Notes
  4592. This works on normal sets only.
  4593. \Algorithm
  4594. \begin{lstlisting}{}
  4595. For each bit in the set do
  4596. dest bit = set1 bit XOR set2 bit
  4597. \end{lstlisting}
  4598. \end{procedurel}
  4599. \subsubsection{FPC{\_}SET{\_}ADD{\_}SETS}
  4600. \label{subsubsec:mylabel94}
  4601. \begin{procedurel}{Do{\_}Add{\_}Sets}{doaddsets}
  4602. \Declaration
  4603. procedure Do{\_}Add{\_}Sets(Set1,Set2,Dest : Pointer);
  4604. \Description
  4605. Calculate the addition between \textsf{set1} and \textsf{set2}, setting the
  4606. result in \textsf{dest}.
  4607. \Parameters
  4608. set1 = pointer to 32 byte set \par
  4609. set2 = pointer to 32 byte set \par
  4610. dest = pointer to 32 byte set which will receive the result
  4611. \Notes
  4612. This works on normal sets only.
  4613. \Algorithm
  4614. \begin{lstlisting}{}
  4615. For each bit in the set do
  4616. dest bit = set1 bit OR set2 bit
  4617. \end{lstlisting}
  4618. \end{procedurel}
  4619. \subsubsection{FPC{\_}SET{\_}LOAD{\_}SMALL}
  4620. \label{subsubsec:mylabel95}
  4621. \begin{procedurel}{Do{\_}Load{\_}Small}{doloadsmall}
  4622. \Declaration
  4623. Procedure Do{\_}Load{\_}Small(P : Pointer;L:Longint);
  4624. \Description
  4625. Load a small set into a 32-byte normal set.
  4626. \Parameters
  4627. p = pointer to 32 byte set \par
  4628. l = value of the small set
  4629. \Notes
  4630. Called by code generator (type conversion) from small set to large set.
  4631. Apart from the first 32 bits of the 32 byte set, other bits are not
  4632. modified.
  4633. \Algorithm
  4634. \begin{lstlisting}{}
  4635. For n = bit 0 to bit 31 of l do
  4636. p bit n = l bit n
  4637. \end{lstlisting}
  4638. \end{procedurel}
  4639. \subsubsection{FPC{\_}SET{\_}UNSET{\_}BYTE}
  4640. \label{subsubsec:mylabel96}
  4641. \begin{procedurel}{Do{\_}Unset{\_}Byte}{dounsetbyte}
  4642. \Declaration
  4643. Procedure Do{\_}Unset{\_}Byte(P : Pointer;B : Byte);
  4644. \Description
  4645. Called by code generator to exclude element b from a big 32-byte set pointed
  4646. to by p.
  4647. \Parameters
  4648. p = pointer to 32 byte set \par b = element number to exclude
  4649. \Notes
  4650. The intel 80386 version of the compiler does not save the used registers,
  4651. therefore, in that case, it must be done in the routine itself.
  4652. \Algorithm
  4653. Clear bit number b in p
  4654. \end{procedurel}
  4655. \subsubsection{FPC{\_}SET{\_}IN{\_}BYTE}
  4656. \label{subsubsec:mylabel97}
  4657. \begin{functionl}{Do{\_}In{\_}Byte}{doinbyte}
  4658. \Declaration
  4659. Function Do{\_}In{\_}Byte(P : Pointer;B : Byte):boolean;
  4660. \Description
  4661. Called by code generator to verify the existence of an element in a set.
  4662. Returns TRUE if b is in the set pointed to by p, otherwise returns FALSE.
  4663. \Parameters
  4664. p = pointer to 32 byte set \par b = element number to verify
  4665. \Notes
  4666. This routine should save / restore all used registers.
  4667. \Algorithm
  4668. Clear bit number b in p
  4669. \end{functionl}
  4670. \subsection{Optional internal routines}
  4671. \label{subsec:optional}
  4672. These routines are dependant on the target architecture. They are present in
  4673. software if the hardware does not support these features.
  4674. They could be implemented in assembler directly with register parameter
  4675. passing.
  4676. \subsubsection{FPC{\_}MUL{\_}INT64}
  4677. \label{subsubsec:mylabel98}
  4678. \begin{function}{MulInt64}
  4679. \Declaration
  4680. function MulInt64(f1,f2 : Int64;CheckOverflow : LongBool) : Int64;
  4681. \Description
  4682. Called by the code generator to multiply two int64 values, when the hardware
  4683. does not support this type of operation. The value returned is the result of
  4684. the multiplication.
  4685. \Parameters
  4686. f1 = first operand \par
  4687. f2 = second operand \par
  4688. checkoverflow = TRUE if overflow checking should be done
  4689. \end{function}
  4690. \subsubsection{FPC{\_}DIV{\_}INT64}
  4691. \label{subsubsec:mylabel99}
  4692. \begin{function}{DivInt64}
  4693. \Declaration
  4694. function DivInt64(n,z : Int64) : Int64;
  4695. \Description
  4696. Called by the code generator to get the division two int64 values, when the
  4697. hardware does not support this type of operation. The value returned is the
  4698. result of the division.
  4699. \Parameters
  4700. n =numerator \par
  4701. z = denominator
  4702. \end{function}
  4703. \subsubsection{FPC{\_}MOD{\_}INT64}
  4704. \label{subsubsec:mylabel100}
  4705. \begin{function}{ModInt64}
  4706. \Declaration
  4707. function ModInt64(n,z : Int64) : Int64;
  4708. \Description
  4709. Called by the code generator to get the modulo two int64 values, when the
  4710. architecture does not support this type of operation. The value returned is
  4711. the result of the modulo.
  4712. \Parameters
  4713. n = numerator \par
  4714. z = denominator
  4715. \end{function}
  4716. \subsubsection{FPC{\_}SHL{\_}INT64}
  4717. \label{subsubsec:mylabel101}
  4718. \begin{function}{ShlInt64}
  4719. \Declaration
  4720. Function ShlInt64(Cnt : Longint; Low, High: Longint): Int64;
  4721. \Description
  4722. Called by the code generator to shift left a 64-bit integer by the specified
  4723. amount cnt, when this is not directly supported by the hardware. Returns the
  4724. shifted value.
  4725. \Parameters
  4726. low,high = value to shift (low / high 32-bit value) \par
  4727. cnt = shift count
  4728. \end{function}
  4729. \subsubsection{FPC{\_}SHR{\_}INT64}
  4730. \label{subsubsec:mylabel102}
  4731. \begin{function}{ShrInt64}
  4732. \Declaration
  4733. function ShrInt64(Cnt : Longint; Low, High: Longint): Int64;
  4734. \Description
  4735. Called by the code generator to shift left a 64-bit integer by the specified
  4736. amount cnt, when this is not directly supported by the hardware. Returns the
  4737. shifted value.
  4738. \Parameters
  4739. low,high = value to shift (low/high 32-bit values) \par
  4740. cnt = shift count
  4741. \end{function}
  4742. \subsubsection{FPC{\_}MUL{\_}LONGINT}
  4743. \label{subsubsec:mylabel103}
  4744. \begin{function}{MulLong}
  4745. \Declaration
  4746. Function MulLong: Longint;
  4747. \Description
  4748. Called by the code generator to multiply two longint values, when the hardware does not support this type of operation. The value returned is the result of the multiplication.
  4749. \Parameters
  4750. Parameters are passed in registers.
  4751. \Notes
  4752. This routine should save / restore all used registers.
  4753. \end{function}
  4754. \subsubsection{FPC{\_}REM{\_}LONGINT}
  4755. \label{subsubsec:mylabel104}
  4756. \begin{function}{RemLong}
  4757. \Declaration
  4758. Function RemLong: Longint;
  4759. \Description
  4760. Called by the code generator to get the modulo two longint values, when the
  4761. hardware does not support this type of operation. The value returned is the
  4762. result of the modulo.
  4763. \Parameters
  4764. Parameters are passed in registers.
  4765. \Notes
  4766. This routine should save / restore all used registers.
  4767. \end{function}
  4768. \subsubsection{FPC{\_}DIV{\_}LONGINT}
  4769. \label{subsubsec:mylabel105}
  4770. \begin{function}{DivLong}
  4771. \Declaration
  4772. Function DivLong: Longint;
  4773. \Description
  4774. Called by the code generator to get the division two longint values, when
  4775. the hardware does not support this type of operation. The value returned is
  4776. the result of the division.
  4777. \Parameters
  4778. Parameters are passed in registers.
  4779. \Notes
  4780. This routine should save / restore all used registers.
  4781. \end{function}
  4782. \subsubsection{FPC{\_}MUL{\_}LONGINT}
  4783. \label{subsubsec:mylabel106}
  4784. \begin{function}{MulCardinal}
  4785. \Declaration
  4786. Function MulCardinal: Cardinal;
  4787. \Description
  4788. Called by the code generator to multiply two cardinal values, when the
  4789. hardware does not support this type of operation. The value returned is the
  4790. result of the multiplication.
  4791. \Parameters
  4792. Parameters are passed in registers.
  4793. \Notes
  4794. This routine should save / restore all used registers.
  4795. \end{function}
  4796. \subsubsection{FPC{\_}REM{\_}CARDINAL}
  4797. \label{subsubsec:mylabel107}
  4798. \begin{function}{RemCardinal}
  4799. \Declaration
  4800. Function RemCardinal : Cardinal;
  4801. \Description
  4802. Called by the code generator to get the modulo two cardinal values, when the
  4803. hardware does not support this type of operation. The value returned is the
  4804. result of the modulo.
  4805. \Parameters
  4806. Parameters are passed in registers.
  4807. \Notes
  4808. This routine should save / restore all used registers.
  4809. \end{function}
  4810. \subsubsection{FPC{\_}DIV{\_}CARDINAL}
  4811. \label{subsubsec:mylabel108}
  4812. \begin{function}{DivCardinal}
  4813. \Declaration
  4814. Function DivCardinal: Cardinal;
  4815. \Description
  4816. Called by the code generator to get the division two cardinal values, when
  4817. the hardware does not support this type of operation. The value returned is
  4818. the result of the division.
  4819. \Parameters
  4820. Parameters are passed in registers.
  4821. \Notes
  4822. This routine should save / restore all used registers.
  4823. \end{function}
  4824. \subsubsection{FPC{\_}LONG{\_}TO{\_}SINGLE}
  4825. \label{subsubsec:mylabel109}
  4826. \begin{function}{LongSingle}
  4827. \Declaration
  4828. Function LongSingle: Single;
  4829. \Description
  4830. Called by the code generator to convert a longint to a single IEEE floating
  4831. point value.
  4832. \Parameters
  4833. Parameters are passed in registers
  4834. \Notes
  4835. This routine should save / restore all used registers.
  4836. \end{function}
  4837. FPC{\_}ADD{\_}SINGLE
  4838. FPC{\_}SUB{\_}SINGLE
  4839. FPC{\_}MUL{\_}SINGLE
  4840. FPC{\_}REM{\_}SINGLE
  4841. FPC{\_}DIV{\_}SINGLE
  4842. FPC{\_}CMP{\_}SINGLE
  4843. FPC{\_}SINGLE{\_}TO{\_}LONGINT
  4844. \section{Optimizing your code}
  4845. \label{sec:optimizing}
  4846. \subsection{Simple types}
  4847. \label{subsec:simple}
  4848. Use the most simple types, when defining and declaring variables, they
  4849. require less overhead. Classes, and complex string types (ansi strings and
  4850. wide strings) posess runtime type information, as well as more overhead for
  4851. operating on them then simple types such as shortstring and simple ordinal
  4852. types.
  4853. \subsection{constant duplicate merging}
  4854. \label{subsec:constant}
  4855. When duplicates of constant strings, sets or floating point values are found
  4856. in the code, they are replaced by only once instance of the same string, set
  4857. or floating point constant which reduces the size of the final executable.
  4858. \subsection{inline routines}
  4859. \label{subsec:inline}
  4860. The following routines of the system unit are directly inlined by the
  4861. compiler, and generate more efficient code:
  4862. \begin{longtable}{|l|l|}
  4863. \hline
  4864. Prototype& Definition and notes \\
  4865. \hline
  4866. \endhead
  4867. \hline
  4868. \endfoot
  4869. \textsf{function pi : extended;}& \\
  4870. \textsf{function abs(d : extended) : extended;}& \\
  4871. \textsf{function sqr(d : extended) : extended;}& \\
  4872. \textsf{function sqrt(d : extended) : extended;}& \\
  4873. \textsf{function arctan(d : extended) : extended;}& \\
  4874. \textsf{function ln(d : extended) : extended;}& \\
  4875. \textsf{function sin(d : extended) : extended;}& \\
  4876. \textsf{function cos(d : extended) : extended;}& \\
  4877. \textsf{function ord(X): longint;}&
  4878. Changes node type to be type compatible \\
  4879. \textsf{function lo(X) : byte or word;}&
  4880. Generates 2-3 instruction sequence inline \\
  4881. \textsf{function hi(X) : byte or word;}&
  4882. Generates 2-3 instruction sequence inline \\
  4883. \textsf{function chr(b : byte) : Char;}&
  4884. Changes node type to be type compatible \\
  4885. \textsf{function Length(s : string) : byte;}&
  4886. Generate 2-3 instruction sequence \\
  4887. \textsf{function Length(c : char) : byte;}&
  4888. Generates 1 instruction sequence (appx.) \\
  4889. \textsf{procedure Reset(var f : TypedFile);}&
  4890. Calls FPC{\_}RESET{\_}TYPED \\
  4891. \textsf{procedure rewrite(var f : TypedFile);}&
  4892. Calls FPC{\_}REWRITE{\_}TYPED \\
  4893. \textsf{procedure settextbuf(var F : Text; var Buf);}&
  4894. Calls SetTextBuf of runtime library \\
  4895. \textsf{procedure writen;}&
  4896. Calls FPC{\_}WRITE{\_}XXXX routines \\
  4897. \textsf{procedure writeln;}&
  4898. Calls FPC{\_}WRITE{\_}XXXX routines \\
  4899. \textsf{procedure read;}&
  4900. Calls FPC{\_}READ{\_}XXXX routines \\
  4901. \textsf{procedure readln;}&
  4902. Calls FPC{\_}READ{\_}XXXX routines \\
  4903. \textsf{procedure concat;}&
  4904. Generates a TREE NODES of type addn \\
  4905. \textsf{function assigned(var p): boolean;}&
  4906. Generates 1-2 instruction sequence inline \\
  4907. \textsf{procedure str(X :[Width [:Decimals]]; var S);}& \\
  4908. \textsf{}& \\
  4909. \textsf{function sizeof(X): longint;}&
  4910. Generates 2-3 instruction sequence inline \\
  4911. \textsf{function typeof(X): pointer;}&
  4912. Generates 2-3 instruction sequence inline \\
  4913. \textsf{procedure val(S;var V; var Code: integer);}& \\
  4914. \textsf{function seg(X): longint;}& \\
  4915. \textsf{function High(X)}&
  4916. Generates a TREE NODE of type ordconstn \\
  4917. \textsf{function Low(X)}&
  4918. Generates a TREE NODE of type ordconstn \\
  4919. \textsf{function pred(x)}&
  4920. Generates 2-3 instruction sequence inline \\
  4921. \textsf{function succ(X)}&
  4922. Generates 2-3 instruction sequence inline \\
  4923. \textsf{procedure inc(var X [ ; N: longint]);}&
  4924. Generate 2-3 instruction sequence inline \\
  4925. \textsf{procedure dec(var X [; N:longint]);}&
  4926. Generate 2-3 instruction sequence inline \\
  4927. \textsf{procedure include(var s: set of T; I: T);}& \\
  4928. \textsf{procedure exclude(var S : set of T; I: T);}& \\
  4929. \textsf{procedure assert(expr : Boolean);}&
  4930. Calls routine FPC{\_}ASSERT if the assert fails.\\
  4931. \textsf{function addr(X): pointer;}&
  4932. Generates a TREE NODE of type addrn \\
  4933. \textsf{function typeInfo(typeIdent): pointer;}&
  4934. Generates 1 instruction sequence inline \\
  4935. \end{longtable}
  4936. \subsection{temporary memory allocation reuse}
  4937. \label{subsec:mylabel11}
  4938. When routines are very complex , they may require temporary allocated space
  4939. on the stack to store intermediate results. The temporary memory space can
  4940. be reused for several different operations if other space is required on the
  4941. stack.
  4942. \section{Appendix A}
  4943. \label{sec:appendix}
  4944. This appendix describes the temporary defines when compiling software under
  4945. the compiler:
  4946. The following defines are defined in FreePascal for v1.0.x, but they will be
  4947. removed in future versions, they are used for debugging purposes only:
  4948. \begin{itemize}
  4949. \item INT64
  4950. \item HASRESOURCESTRINGS
  4951. \item NEWVMTOFFSET
  4952. \item HASINTERNMATH
  4953. \item SYSTEMVARREC
  4954. \item INCLUDEOK
  4955. \item NEWMM
  4956. \item HASWIDECHAR
  4957. \item INT64FUNCRESOK
  4958. \item CORRECTFLDCW
  4959. \item ENHANCEDRAISE
  4960. \item PACKENUMFIXED
  4961. \end{itemize}
  4962. NOTE: Currently, the only possible stack alignment are either 2 or 4 if the
  4963. target operating system pushes parameters on the stack directly in assembler
  4964. (because for example if pushing a long value on the stack while the required
  4965. stack alignment is 8 will give out wrong access to data in the actual
  4966. routine -- the offset will be wrong).
  4967. \printindex
  4968. \end{document}