comparch.tex 180 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687
  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.5in}{|l@{\extracolsep{\fill}}lp{8.5cm}|}
  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{figure}
  1436. \ifpdf
  1437. \includegraphics{arch7.pdf}
  1438. %\epsfig{file=arch7.png,width=\textwidth}
  1439. \else
  1440. \includegraphics[width=4.39in,height=3.56in]{arch7.eps}
  1441. \fi
  1442. \caption{Type symbol and definition relations}
  1443. \label{fig7}
  1444. \end{figure}
  1445. \subsection{Definition types}
  1446. Definitions represent the type information for all possible symbols which
  1447. can be encountered by the parser. The definition types are associated with
  1448. symbols in the symbol table, and are used by the parsing process (among
  1449. other things) to perform type checking.
  1450. The current possible definition types are enumerated in \textsf{TDefType}
  1451. and can have one of the following symbolic values:
  1452. \begin{longtable}{|l|p{10cm}|}
  1453. \hline
  1454. deftype of TDef object & Description \\
  1455. \hline
  1456. \endhead
  1457. \hline
  1458. \endfoot
  1459. \textsf{AbstractDef} & \\
  1460. \textsf{ArrayDef} & array type definition \\
  1461. \textsf{RecordDef} & record type definition \\
  1462. \textsf{PointerDef} & pointer type definition \\
  1463. \textsf{OrdDef} & ordinal (numeric value) type definition \\
  1464. \textsf{StringDef} & string type definition \\
  1465. \textsf{EnumDef} & enumeration type definition \\
  1466. \textsf{ProcDef} & procedure type definition \\
  1467. \textsf{ObjectDef} & object or class type definition \\
  1468. \textsf{ErrorDef} & error definition (empty, used for error recovery) \\
  1469. \textsf{FileDef} & file type definition \\
  1470. \textsf{FormalDef} & \\
  1471. \textsf{SetDef} & set type definition \\
  1472. \textsf{ProcVarDef} & procedure variable type definition \\
  1473. \textsf{FloatDef} & floating point type definition \\
  1474. \textsf{ClassrefDef} & \\
  1475. \textsf{ForwardDef} & \\
  1476. \end{longtable}
  1477. \subsubsection{base definition (TDef)}
  1478. \label{subsubsec:mylabel5}
  1479. All type definitions are based on this object. Therefore all derived object
  1480. all posess the fields in this object in addition to their own private
  1481. fields.
  1482. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{7cm}|}
  1483. \hline
  1484. \textsf{TYPE} & & \\
  1485. \xspace pDef = & \^{} TDef; & \\
  1486. \xspace \textsf{TDef} = & \textbf{Object}(TSymTableEntry) & \\
  1487. &\textsf{TypeSym : pTypeSym;}&
  1488. Pointer to symbol table entry for this type definition \\
  1489. &\textsf{InitTable{\_}Label : pAsmLabel;}&
  1490. Label to initialization information (required for some complex types) \\
  1491. &\textsf{Rtti{\_}Label : pAsmLabel;}&
  1492. Label to the runtime type information. \\
  1493. &\textsf{NextGlobal : pDef;}& \\
  1494. &\textsf{PreviousGlobal : pDef;}& \\
  1495. &\textsf{SaveSize : Longint;}&
  1496. Size in bytes of the data definition \\
  1497. &\textsf{DefType : tDefType;}&
  1498. Indicates the definition type (see table \ref{tab5}). \\
  1499. &\textsf{Has{\_}InitTable : Boolean;}& \\
  1500. &\textsf{Has{\_}Rtti : Boolean;}& \\
  1501. &\textsf{Is{\_}Def{\_}Stab{\_}Written : TDefStabStatus}&
  1502. Can be one of the following states : (\textsf{Not{\_}Written,
  1503. written, Being{\_}Written}) which indicates if the debug information
  1504. for this type has been defined or not. \\
  1505. &\textsf{GlobalNb : Longint;}&
  1506. Internal stabs debug information type signature (each type definition has a
  1507. numeric signature). \\
  1508. &\textsf{end;}& \\
  1509. \hline
  1510. \end{tabular*}
  1511. \subsubsection{file definition (TFileDef)}
  1512. \label{subsubsec:mylabel6}
  1513. The file definition can occur in only some rare instances, when a
  1514. \textsf{file of }\textsf{\textit{type}} is parsed, a file definition of that
  1515. type will be created. Furthermore, internally, a definition for a
  1516. \textbf{Text} file type and \textbf{untyped} File type are created when the
  1517. system unit is loaded. These types are always defined when compiling any
  1518. unit or program.
  1519. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{8.5cm}|}
  1520. \hline
  1521. \textsf{TYPE}& & \\
  1522. \xspace pFileDef = & \^{} TFileDef; & \\
  1523. \xspace \textsf{TFileDef} = & \textbf{Object}(TDef) & \\
  1524. &\textsf{FileTyp : TFileTyp;}&
  1525. Indicates what type of file definition it is (\textsf{text},
  1526. \textsf{untyped} or \textsf{typed}). \\
  1527. &\textsf{TypedFileType : TType;}&
  1528. In the case of a typed file definition, definition of the type of
  1529. the file \\
  1530. &\textsf{end;}& \\
  1531. \hline
  1532. \end{tabular*}
  1533. \subsubsection{formal definition (TFormalDef)}
  1534. \label{subsubsec:formal}
  1535. \subsubsection{forward definition (TForwardDef)}
  1536. \label{subsubsec:forward}
  1537. The forward definition is created, when a type is declared before an actual
  1538. definition exists. This is the case, when, for example \textsf{type
  1539. pmyobject = \ tmyobject}, while \textsf{tmyobject} has yet to be defined.
  1540. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{6.5cm}|}
  1541. \hline
  1542. \textsf{TYPE} & & \\
  1543. \xspace pForwardDef = & \^{} TForwardDef; & \\
  1544. \xspace \textsf{TForwardDef} = & \textbf{Object}(TDef) & \\
  1545. &\textsf{toSymName : String;}&
  1546. The symbol name for this forward declaration (the actual real
  1547. definition does not exist yet) \\
  1548. &\textsf{ForwardPos : TFilePosInfo;}&
  1549. Indicates file position where this forward definition was declared. \\
  1550. &\textsf{end;}& \\
  1551. \hline
  1552. \end{tabular*}
  1553. \subsubsection{error definition (TErrorDef)}
  1554. \label{subsubsec:mylabel7}
  1555. This definition is actually an empty definition entry. When the parser
  1556. encounters an error when parsing a definition instead of putting nothing in
  1557. the type for a symbol, it puts this entry. This avoids illegal memory
  1558. accesses later in parsing.
  1559. \subsubsection{pointer definition (TPointerDef)}
  1560. \label{subsubsec:pointer}
  1561. The pointer definition is used for distinguishing between different types of
  1562. pointers in the compiler, and are created at each \textsf{\ typename}
  1563. parsing construct found.
  1564. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{9cm}|}
  1565. \hline
  1566. \textsf{TYPE} & & \\
  1567. \xspace pPointerDef = & \^{} TPointerDef; & \\
  1568. \xspace \textsf{TPointerDef} = & \textbf{Object}(TDef) & \\
  1569. &\textsf{Is{\_}Far : Boolean;}&
  1570. Used to indicate if this is a far pointer or not (this flag is
  1571. cpu-specific) \\
  1572. &\textsf{PointerType : TType;}&
  1573. This indicates to what type definition this pointer points to. \\
  1574. &\textsf{end;}& \\
  1575. \hline
  1576. \end{tabular*}
  1577. \subsubsection{object definition (TObjectDef)}
  1578. \label{subsubsec:object}
  1579. The object definition is created each time an object declaration is found in
  1580. the type declaration section.
  1581. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{5.5cm}|}
  1582. \hline
  1583. \textsf{TYPE}& & \\
  1584. \xspace pObjectDef = & \^{} TObjectDef; & \\
  1585. \xspace \textsf{TObjectDef} = & \textbf{Object}(TDef) & \\
  1586. &\textsf{ChildOf : pObjectDef;}&
  1587. This is a pointer to the parent object definition. It is set to nil,
  1588. if this object definition has no parent. \\
  1589. &\textsf{ObjName : pString;}&
  1590. This is the object name \\
  1591. &\textsf{SymTable : pSymTable;}&
  1592. This is a pointer to the symbol table entries within this object. \\
  1593. &\textsf{PbjectOptions : TObjectOptions;}&
  1594. The options for this object, see the following table for the
  1595. possible options for the object. \\
  1596. &\textsf{VMT{\_}Offset : Longint;}&
  1597. This is the offset from the start of the object image in memory
  1598. where the virtual method table is located. \\
  1599. &\textsf{Writing{\_}Class{\_}Record{\_}Stab : Boolean;}& \\
  1600. &\textsf{end;}& \\
  1601. \hline
  1602. \end{tabular*}
  1603. \begin{longtable}{|l|p{10cm}|}
  1604. \hline
  1605. Object Options(TObjectOptions) & Description \\
  1606. \hline
  1607. \endhead
  1608. \hline
  1609. \endfoot
  1610. \textsf{oo{\_}is{\_}class}&
  1611. This is a delphi styled class declaration, and not a Turbo Pascal
  1612. object. \\
  1613. \textsf{oo{\_}is{\_}forward}&
  1614. This flag is set to indicate that the object has been declared in a
  1615. type section, but there is no implementation yet. \\
  1616. \textsf{oo{\_}has{\_}virtual}&
  1617. This object / class contains virtual methods \\
  1618. \textsf{oo{\_}has{\_}private}&
  1619. This object / class contains private fields or methods \\
  1620. \textsf{oo{\_}has{\_}protected}&
  1621. This object / class contains protected fields or methods \\
  1622. \textsf{oo{\_}has{\_}constructor}&
  1623. This object / class has a constructor method \\
  1624. \textsf{oo{\_}has{\_}destructor}&
  1625. This object / class has a destructor method \\
  1626. \textsf{oo{\_}has{\_}vmt}&
  1627. This object / class has a virtual method table \\
  1628. \textsf{oo{\_}has{\_}msgstr}&
  1629. This object / class contains one or more message handlers \\
  1630. \textsf{oo{\_}has{\_}msgint}&
  1631. This object / class contains one or more message handlers \\
  1632. \textsf{oo{\_}has{\_}abstract}&
  1633. This object / class contains one or more abstract methods \\
  1634. \textsf{oo{\_}can{\_}have{\_}published}&
  1635. the class has runtime type information, i.e. you can publish
  1636. properties \\
  1637. \textsf{oo{\_}cpp{\_}class}&
  1638. the object/class uses an C++ compatible class layout \\
  1639. \textsf{oo{\_}interface}&
  1640. this class is a delphi styled interface
  1641. \end{longtable}
  1642. \subsubsection{class reference definition (TClassRefDef)}
  1643. \label{subsubsec:class}
  1644. \subsubsection{array definition (TArrayDef)}
  1645. \label{subsubsec:array}
  1646. This definition is created when an array type declaration is parsed. It
  1647. contains all the information necessary for array type checking and code
  1648. generation.
  1649. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{8.4cm}|}
  1650. \hline
  1651. \textsf{TYPE}& & \\
  1652. \xspace pArrayDef = & \^{} TArrayDef; & \\
  1653. \xspace \textsf{TArrayDef} = & \textbf{Object}(TDef) & \\
  1654. &\textsf{IsVariant : Boolean;}& \\
  1655. &\textsf{IsConstructor : Boolean;}& \\
  1656. &\textsf{RangeNr: Longint;}&
  1657. Label number associated with the index values when range checking is
  1658. on \\
  1659. &\textsf{LowRange : Longint;}&
  1660. The lower index range of the array definition \\
  1661. &\textsf{HighRange : Longint;}&
  1662. The higher index range of the array definition \\
  1663. &\textsf{ElementType : TType;}&
  1664. The type information for the elements of the array \\
  1665. &\textsf{RangeType : TType;}&
  1666. The type information for the index ranges of the array \\
  1667. &\textsf{IsArrayofConst : Boolean;}& \\
  1668. &\textsf{end;}& \\
  1669. \hline
  1670. \end{tabular*}
  1671. \subsubsection{record definition (TRecordDef)}
  1672. \label{subsubsec:record}
  1673. The record definition entry is created each time a record type declaration
  1674. is parsed. It contains the symbol table to the elements in the record.
  1675. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{8.7cm}|}
  1676. \hline
  1677. \textsf{TYPE} & & \\
  1678. \xspace pRecordDef = & \^{} TRecordDef; & \\
  1679. \xspace \textsf{TRecordDef} = & \textbf{Object}(TDef) & \\
  1680. &\textsf{SymTable : PSymTable;}&
  1681. This is a pointer to the symbol table entries within this record. \\
  1682. &\textsf{end;}& \\
  1683. \hline
  1684. \end{tabular*}
  1685. \subsubsection{ordinal definition (TOrdDef)}
  1686. \label{subsubsec:ordinal}
  1687. This type definition is the one used for all ordinal values such as char,
  1688. bytes and other numeric integer type values. Some of the predefined type
  1689. definitions are automatically created and loaded when the compiler starts.
  1690. Others are created at compile time, when declared.
  1691. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{9cm}|}
  1692. \hline
  1693. \textsf{TYPE} & & \\
  1694. \xspace pOrdDef = & \^{} TOrdDef; & \\
  1695. \xspace \textsf{TOrdDef} = & \textbf{Object}(TDef) & \\
  1696. &\textsf{Low : Longint;}&
  1697. The minimum value of this ordinal type \\
  1698. &\textsf{High : Longint;}&
  1699. The maximum value of this ordinal type \\
  1700. &\textsf{Typ : TBaseType;}&
  1701. The type of ordinal value (cf. table \ref{tbasetype}) \\
  1702. &\textsf{end;}& \\
  1703. \hline
  1704. \end{tabular*}
  1705. \begin{longtable}{|l|p{10cm}|}
  1706. \caption{Base types}\label{tbasetyp}\\
  1707. \hline
  1708. Base ordinal type (TBaseType) & Description \\
  1709. \hline
  1710. \endfirsthead
  1711. \caption{Base types (continued)}\\
  1712. \hline
  1713. Base ordinal type (TBaseType) & Description \\
  1714. \hline
  1715. \endhead
  1716. \hline
  1717. \endfoot
  1718. \textsf{uauto} & user defined ordinal type definition \\
  1719. \textsf{uvoid} & Represents a void return value or node \\
  1720. \textsf{uchar} & ASCII character (1 byte) \\
  1721. \textsf{u8bit} & unsigned 8-bit value \\
  1722. \textsf{u16bit}& unsigned 16-bit value \\
  1723. \textsf{u32bit}& unsigned 32-bit value \\
  1724. \textsf{s16bit}& signed 16-bit value \\
  1725. \textsf{s32bit}& signed 32-bit value \\
  1726. \textsf{bool8bit}& boolean 8-bit value \\
  1727. \textsf{bool16bit}& boolean 16-bit value \\
  1728. \textsf{bool32bit}& boolean 32-bit value \\
  1729. \textsf{\textit{u64bit}}&
  1730. \textit{unsigned 64-bit value (not fully supported/tested)} \\
  1731. \textsf{s64bit}& signed 64-bit value \\\textsf{\textit{uwidechar}}&
  1732. \textit{Currently not supported and unused} \\
  1733. \end{longtable}
  1734. \subsubsection{float definition (TFloatDef)}
  1735. \label{subsubsec:float}
  1736. This type definition is the one used for all floating point values such as
  1737. SINGLE, DOUBLE. Some of the predefined type definitions are automatically
  1738. created and loaded when the compiler starts.
  1739. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{9cm}|}
  1740. \hline
  1741. \textsf{TYPE} & & \\
  1742. \xspace pFloatDef = & \^{} TFloatDef; & \\
  1743. \xspace \textsf{TFloatDef} = & \textbf{Object}(TDef) & \\
  1744. &\textsf{Typ : TFloatType;}&
  1745. The type of floating point value (cf. table \ref{tfloattype}). \\
  1746. &\textsf{end;}& \\
  1747. \hline
  1748. \end{tabular*}
  1749. \begin{longtable}{|l|p{10cm}|}
  1750. \caption{Floating point types}\label{tfloattype}\\
  1751. \hline
  1752. Base floating point type (TFloatType) & Description \\
  1753. \hline
  1754. \endfirsthead
  1755. \hline
  1756. Base floating point type (TFloatType) & Description \\
  1757. \hline
  1758. \endhead
  1759. \hline
  1760. \endfoot
  1761. \textsf{s32real}& IEEE Single precision floating point value \\
  1762. \textsf{s64real}& IEEE Double precision floating point value \\
  1763. \textsf{s80real}&
  1764. Extended precision floating point value (cpu-specific,
  1765. usually maps to double) \\
  1766. \textsf{s64comp}& 63-bit signed value, using 1 bit for sign indication \\
  1767. \textsf{\textit{f16bit}}& \textit{Unsupported} \\
  1768. \textsf{\textit{f32bit}}& \textit{Unsupported} \\
  1769. \end{longtable}
  1770. \subsubsection{abstract procedure definition (tabstractprocdef)}
  1771. \label{subsubsec:abstract}
  1772. This is the base of all routine type definitions. This object is abstract,
  1773. and is not directly used in a useful way. The derived object of this object
  1774. are used for the actual parsing process.
  1775. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{5.2cm}|}
  1776. \hline
  1777. \textsf{TYPE}& & \\
  1778. \xspace pAbstractProcDef = & \^{} TAbstractProcDef; & \\
  1779. \xspace \textsf{TAbstractProcDef} = & \textbf{Object}(TDef) & \\
  1780. &\textsf{SymtableLevel : byte;}& \\
  1781. &\textsf{Fpu{\_}Used : Byte;}&
  1782. Number of floating point registers used in this routine \\
  1783. &\textsf{RetType : TType;}&
  1784. Type information for the return value \par (uvoid if it returns nothing) \\
  1785. &\textsf{ProcTypeOption : TProcTypeOption;} &
  1786. Indicates the type of routine it is (cf table \ref{tproctypeoption}). \\
  1787. &\textsf{ProcCallOptions : TProcCallOptions;} &
  1788. Indicates the calling convention of the routine (cf. table \ref{tproccalloptions}). \\
  1789. &\textsf{ProcOptions : TProcOptions;}&
  1790. Indicates general procedure options. \par (cf. table \ref{tprocoptions}). \\
  1791. &\textsf{Para : pLinkedList;}&
  1792. This is a linked list of parameters (pparaitem list) \\
  1793. &\textsf{end;}& \\
  1794. \hline
  1795. \end{tabular*}
  1796. \begin{longtable}{|l|p{10cm}|}
  1797. \caption{Procedure type options}\label{tproctypeoption}\\
  1798. \hline
  1799. Procedure options \par (TProcTypeOption)& Description \\
  1800. \hline
  1801. \endfirsthead
  1802. \caption{Procedure type options (continued)}\\
  1803. \hline
  1804. Procedure options \par (TProcTypeOption)& Description \\
  1805. \hline
  1806. \endhead
  1807. \hline
  1808. \endfoot
  1809. \textsf{poType{\_}ProgInit}&
  1810. Routine is the program entry point (defined as `\textsf{main}' in
  1811. the compiler). \\
  1812. \textsf{poType{\_}UnitInit}&
  1813. Routine is the unit initialization code \par (defined as
  1814. unitname\textsf{{\_}init} in the compiler \\
  1815. \textsf{poType{\_}UnitFinalize}&
  1816. Routine is the unit exit code \par (defined as
  1817. unitname\textsf{{\_}finalize} in the compiler) \\
  1818. \textsf{poType{\_}Constructor}&
  1819. Routine is an object or class constructor \\
  1820. \textsf{poType{\_}Destructor}&
  1821. Routine is an object or class destructor \\
  1822. \textsf{poType{\_}Operator}&
  1823. Procedure is an operator \\
  1824. \end{longtable}
  1825. \begin{longtable}{|l|p{10cm}|}
  1826. \caption{Procedure call options}\label{tproccalloptions}\\
  1827. \hline
  1828. call options \par (TProcCallOptions) & Description \\
  1829. \hline
  1830. \endfirsthead
  1831. \caption{Procedure call options (continued)}\\
  1832. \hline
  1833. call options \par (TProcCallOptions) & Description \\
  1834. \hline
  1835. \endhead
  1836. \hline
  1837. \endfoot
  1838. \textsf{pocall{\_}clearstack}&
  1839. The routine caller clears the stack upon return \\
  1840. \textsf{pocall{\_}leftright}&
  1841. Send parameters to routine from left to right \\
  1842. \textsf{pocall{\_}cdecl}&
  1843. Passing parameters is done using the GCC alignment scheme, passing
  1844. parameter values is directly copied into the stack space \\
  1845. \textsf{\textit{pocall{\_}register}}&
  1846. \textit{unused (Send parameters via registers)} \\
  1847. \textsf{pocall{\_}stdcall}&
  1848. Passing parameters is done using GCC alignment scheme, standard GCC registers
  1849. are saved \\
  1850. \textsf{\textit{pocall{\_}safecall}}&
  1851. Standard GCC registers are saved\\
  1852. \textsf{\textit{pocall{\_}palmsssyscall}}&
  1853. This is a special syscall macro for embedded system \\
  1854. \textsf{\textit{pocall{\_}system}}&
  1855. \textit{unused} \\
  1856. \textsf{pocall{\_}inline}&
  1857. Routine is an inline assembler macro (not a true call) \\
  1858. \textsf{pocall{\_}internproc}&
  1859. System unit code generator helper routine \\
  1860. \textsf{pocall{\_}internconst}&
  1861. System unit code generator helper macro routine \\
  1862. \end{longtable}
  1863. \begin{longtable}{|l|p{10cm}|}
  1864. \caption{Procedure options}\label{tprocoptions}\\
  1865. \hline
  1866. routine options (TProcOptions) & Description \\
  1867. \hline
  1868. \endfirsthead
  1869. \caption{Procedure options (continued)}\\
  1870. \hline
  1871. routine options (TProcOptions) & Description \\
  1872. \hline
  1873. \endhead
  1874. \hline
  1875. \endfoot
  1876. \textsf{po{\_}classmethod} & This is a class method \\
  1877. \textsf{po{\_}virtualmethod }& This is a virtual method \\
  1878. \textsf{po{\_}abstractmethod}& This is an abstract method \\
  1879. \textsf{po{\_}staticmethod} & This is a static method \\
  1880. \textsf{po{\_}overridingmethod}&
  1881. This is an overriden method (with po{\_}virtual flag usually) \\
  1882. \textsf{po{\_}methodpointer}&
  1883. This is a method pointer (not a normal routine pointer) \\
  1884. \textsf{po{\_}containsself}&
  1885. self is passed explicitly as a parameter to the method \\
  1886. \textsf{po{\_}interrupt}&
  1887. This routine is an interrupt handler \\
  1888. \textsf{po{\_}iocheck}&
  1889. IO checking should be done after a call to the procedure \\
  1890. \textsf{po{\_}assembler}&
  1891. The routine is in assembler \\
  1892. \textsf{po{\_}msgstr}&
  1893. method for string message handling \\
  1894. \textsf{po{\_}msgint}&
  1895. method for int message handling \\
  1896. \textsf{po{\_}exports}&
  1897. Routine has export directive \\
  1898. \textsf{po{\_}external}&
  1899. Routine is external (in other object or lib) \\
  1900. \textsf{po{\_}savestdregs}&
  1901. Routine entry should save all registers used by GCC \\
  1902. \textsf{po{\_}saveregisters}&
  1903. Routine entry should save all registers \\
  1904. \textsf{po{\_}overload}&
  1905. Routine is declared as being overloaded \\
  1906. \end{longtable}
  1907. \subsubsection{procedural variable definition (TProcVarDef)}
  1908. \label{subsubsec:procedural}
  1909. This definition is created when a procedure variable type is declared. It
  1910. gives information on the type of a procedure, and is used when assigning and
  1911. directly calling a routine through a pointer.
  1912. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{7.8cm}|}
  1913. \hline
  1914. \textsf{TYPE} & & \\
  1915. \xspace pProcVarDef = & \^{} TProcVarDef; & \\
  1916. \xspace \textsf{TProcVarDef} = & \textbf{Object}(TAbstractProcDef) & \\
  1917. & \textsf{end;}&\\
  1918. \hline
  1919. \end{tabular*}
  1920. \subsubsection{procedure definition (TProcDef)}
  1921. \label{subsubsec:mylabel8}
  1922. When a procedure head is parsed, the definition of the routine is created.
  1923. Thereafter, other fields containing information on the definition of the
  1924. routine are populated as required.
  1925. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{7.8cm}|}
  1926. \hline
  1927. \textsf{TYPE} & & \\
  1928. \xspace pProcDef = & \^{} TProcDef; & \\
  1929. \xspace \textsf{TProcDef} = & \textbf{Object}(TAbstractProcDef) & \\
  1930. &\textsf{ForwardDef : Boolean;}& TRUE if this is a forward definition \\
  1931. &\textsf{InterfaceDef: Boolean;} & \\
  1932. &\textsf{ExtNumber : Longint;} & \\
  1933. &\textsf{MessageInf : TMessageInf;} & \\
  1934. &\textsf{NextOverloaded : pProcDef;} & \\
  1935. &\textsf{FileInfo : TFilePosInfo;} &
  1936. Position in source code for the declaration of this routine. Used
  1937. for error management. \\
  1938. &\textsf{Localst : pSymTable;} & The local variables symbol table \\
  1939. &\textsf{Parast: pSymTable;}& The parameter symbol table \\
  1940. &\textsf{ProcSym : pProcSym;}& Points to owner of this definition \\
  1941. &\textsf{LastRef : pRef;}& \\
  1942. &\textsf{DefRef: pRef;}& \\
  1943. &\textsf{CrossRef : pRef;}& \\
  1944. &\textsf{LastWritten : pRef;}& \\
  1945. &\textsf{RefCount : Longint;}& \\
  1946. &\textsf{{\_}Class : ProbjectDef;}& \\
  1947. &\textsf{Code : Pointer;}&
  1948. The actual code for the routine (only for inlined routines) \\
  1949. &\textsf{UsedRegisters : TRegisterSet;}&
  1950. The set of registers used in this routine \\
  1951. &\textsf{HasForward : Boolean;}& \\
  1952. &\textsf{Count: Boolean;}& \\
  1953. &\textsf{Is{\_}Used : Boolean;}& \\
  1954. &\textsf{end;}& \\
  1955. \hline
  1956. \end{tabular*}
  1957. \subsubsection{string definition (TStringDef)}
  1958. \label{subsubsec:string}
  1959. This definition represents all string types as well as derived types. Some
  1960. of the default string type definitions are loaded when the compiler starts
  1961. up. Others are created at compile time as they are declared with a specific
  1962. length type.
  1963. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{8cm}|}
  1964. \hline
  1965. \textsf{TYPE}& & \\
  1966. \xspace pStringDef = & \^{} TStringDef; & \\
  1967. \xspace \textsf{TStringDef} = & \textbf{Object}(TDef) & \\
  1968. &\textsf{String{\_}Typ : TStringType;}&
  1969. Indicates the string type definition (cf. \ref{tstringtype}) \\
  1970. &\textsf{Len : Longint;}&
  1971. This is the maximum length which can have the string \\
  1972. &\textsf{end;}& \\
  1973. \hline
  1974. \end{tabular*}
  1975. \begin{longtable}{|l|p{10cm}|}
  1976. \caption{string types}\label{tstringtype}\\
  1977. \hline
  1978. String type \par (TStringType) & Description \\
  1979. \hline
  1980. \endfirsthead
  1981. \caption{string types (continued)}\\
  1982. \hline
  1983. String type \par (TStringType) & Description \\
  1984. \hline
  1985. \endhead
  1986. \hline
  1987. \endfoot
  1988. \textsf{st{\_}default}&
  1989. Depends on current compiler switches, can either be a
  1990. st{\_}ShortString or st{\_}AnsiString \\
  1991. \textsf{st{\_}shortstring}&
  1992. short string (length byte followed by actual ASCII characters (1
  1993. byte/char)) \\
  1994. \textsf{st{\_}longstring}&
  1995. long string (length longint followed by actual ASCII characters (1
  1996. byte/char)) \\
  1997. \textsf{st{\_}ansistring}&
  1998. long string garbage collected (pointer to a length, reference count
  1999. followed by actual ASCII characters (1 byte/char)) \\
  2000. \textsf{\textit{st{\_}widestring}}&
  2001. \textit{long string garbage collected (pointer to a length,
  2002. reference count followed by actual unicode characters (1
  2003. word/char (utf16)))} \\
  2004. \end{longtable}
  2005. \subsubsection{enumeration definition (TEnumDef)}
  2006. \label{subsubsec:mylabel9}
  2007. An enumeration definition is created each time an enumeration is declared
  2008. and parsed. Each element in the enumeration will be added to the linked list
  2009. of symbols associated with this enumeration, and this symbol table will then
  2010. be attached to the enumeration definition.
  2011. \begin{tabular*}{6,5in}{|l@{\extracolsep{\fill}}lp{6,5cm}|}
  2012. \hline
  2013. \textsf{TYPE} & & \\
  2014. \xspace \textsf{pEnumDef} &= \^{} \textbf{TEnumDef};& \\
  2015. \xspace \textsf{TEnumDef} &= \textbf{object}(TDef) & \\
  2016. &\textsf{\textit{Has{\_}Jumps : Boolean;}}&
  2017. \textit{Currently unused} \\
  2018. &\textsf{MinVal : Longint;}&
  2019. Value of the first element in the enumeration \\
  2020. &\textsf{MaxVal : Longint;}&
  2021. Value of the last element in the enumeration \\
  2022. &\textsf{FirstEnum : pEnumSym;}&
  2023. Pointer to a linked list of elements in the enumeration, each with
  2024. its name and value. \\
  2025. &\textsf{BaseDef : pEnumDef;}&
  2026. In the case where the enumeration is a subrange of another enumeration,
  2027. this gives information on the base range of the elements \\
  2028. &\textsf{end;}& \\
  2029. \hline
  2030. \end{tabular*}
  2031. \subsubsection{set definition (TSetDef)}
  2032. \label{subsubsec:mylabel10}
  2033. This definition is created when a set type construct is parsed (\textsf{set
  2034. of declaration}).
  2035. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{6,5cm}|}
  2036. \hline
  2037. \textsf{TYPE} & & \\
  2038. \xspace \textsf{pSetDef} &= \^{} \textbf{TSetDef};& \\
  2039. \xspace \textsf{TSetDef} &= \textbf{object}(TDef) & \\
  2040. &\textsf{SetType : TSetType;}&
  2041. Indicates the storage type of the set (Cf. table \ref{tsettype}). \\
  2042. &\textsf{ElementType : TType;}&
  2043. Points the type definition and symbol table to the elements in the set. \\
  2044. &\textsf{end;}& \\
  2045. \hline
  2046. \end{tabular*}
  2047. \begin{longtable}{|l|p{10cm}|}
  2048. \caption{set types}\label{tsettype}\\
  2049. \hline
  2050. set type (TSetType) & Description \\
  2051. \hline
  2052. \endfirsthead
  2053. \caption{set types (continued)}\\
  2054. \hline
  2055. set type (TSetType) & Description \\
  2056. \hline
  2057. \endhead
  2058. \hline
  2059. \endfoot
  2060. \textsf{NormSet}&
  2061. Normal set of up to 256 elements (32 byte storage space required) \\
  2062. \textsf{SmallSet}&
  2063. Small set of up to 32 elements (4 byte storage space) \\
  2064. \textsf{\textit{VarSet}}&
  2065. \textit{Variable number of element set (storage size is dependent on number
  2066. of elements) (currently unused and unsupported)} \\
  2067. \end{longtable}
  2068. \subsection{Definition interface}
  2069. \label{subsec:definition}
  2070. \subsubsection{routines}
  2071. \begin{function}{TDef.Size}
  2072. \Declaration
  2073. Function TDef.Size : Longint;
  2074. \Description
  2075. This method returns the true size of the memory space required in bytes for
  2076. this type definition (after alignment considerations).
  2077. \end{function}
  2078. \begin{function}{TDef.Alignment}
  2079. \Declaration
  2080. Function TDef.Alignment : Longint;
  2081. \Description
  2082. This method returns the alignment of the data for complex types such as
  2083. records and objects, otherwise returns 0 or 1 (no alignment).
  2084. \end{function}
  2085. \section{The parser}
  2086. \label{sec:mylabel5}
  2087. The task of the parser is to read the token fed by the scanner, and make
  2088. sure that the pascal syntax is respected. It also populates the symbol
  2089. table, and creates the intermediate nodes (the tree) which will be used by
  2090. the code generator.
  2091. An overview of the parsing process, as well as its relationship with the
  2092. tree the type checker and the code generator is shown in the following
  2093. diagram:
  2094. \subsection{Module information}
  2095. \label{subsec:module}
  2096. Each module being compiled, be it a library , unit or main program has some
  2097. information which is required. This is stored in the tmodule object in
  2098. memory. To avoid recompilation of already compiled module, the dependencies
  2099. of the modules is stored in a PPU file, which makes it easier to determine
  2100. which modules to recompile.
  2101. \begin{longtable}{|l@{\extracolsep{\fill}}lp{7cm}|}
  2102. \hline
  2103. \endhead
  2104. \hline
  2105. \endfoot
  2106. %\begin{tabular*}
  2107. \textsf{TYPE}& & \\
  2108. \xspace pModule = & \^{} TModule; & \\
  2109. \xspace \textsf{TModule} = & \textbf{Object}(TLinkedList\_Item) & \\
  2110. &\textsf{PPUFile : pPPUFile;}& Pointer to PPU file object (unit file) \\
  2111. &\textsf{Crc : Longint;}& CRC-32 bit of the whole PPU file \\
  2112. &\textsf{Interface{\_}CRC : Longint;}& CRC-32 bit of the interface part of the PPU file \\
  2113. &\textsf{Flags: Longint;}& Unit file flags \\
  2114. &\textsf{Compiled: Boolean;}& TRUE if module is already compiled \\
  2115. &\textsf{Do{\_}Reload : Boolean;} & TRUE if the PPU file must be reloaded \\
  2116. &\textsf{Do{\_}Assemble : Boolean;} & Only assemble, don't recompile unit \\
  2117. &\textsf{Sources{\_}Avail : Boolean;} & TRUE if all sources of module are available \\
  2118. &\textsf{Sources{\_}Checked : Boolean;} & TRUE if the sources has already been checked \\
  2119. &\textsf{Is{\_}Unit: Boolean;} & TRUE if this is a unit (otherwise a library or a main program) \\
  2120. &\textsf{In{\_}Compile: Boolean;} & module is currently being recompiled \\
  2121. &\textsf{In{\_}Second{\_}Compile: Boolean;}& module is being compiled for second time \\
  2122. &\textsf{In{\_}Second{\_}Load: Boolean;} & module is being reloaded a second time \\
  2123. &\textsf{In{\_}Implementation : Boolean;}& currently compiling implementation part (units only) \\
  2124. &\textsf{In{\_}Global : Boolean;} & currently compiling implementation part (units only) \\
  2125. &\textsf{Recompile{\_}Reason : TRecompile{\_}Reason;}& Reason why module should be recompiled \\
  2126. &\textsf{Islibrary : Boolean;}& TRUE if this module is a shared library \\
  2127. &\textsf{Map : pUnitMap;} & Map of all used units for this unit \\
  2128. &\textsf{Unitcount : Word;} & Internal identifier of unit (for GDB support) \\
  2129. &\textsf{Unit{\_}index : Eord;} & \\
  2130. &\textsf{Globalsymtable : Pointer;} & Symbol table for this module of externally visible symbols \\
  2131. &\textsf{Localsymtable : Pointer;} & Symbol table for this module of locally visible symbols \\
  2132. &\textsf{Scanner : Pointer;} & Scanner object pointer \\
  2133. &\textsf{Loaded{\_}From : pModule;} & Module which referred to this module \\
  2134. &\textsf{Uses{\_}Imports : Boolean;} & TRUE if this module imports symbols from a shared library \\
  2135. &\textsf{Imports : pLinkedList} & Linked list of imported symbols \\
  2136. &\textsf{{\_}Exports : pLinkedList;} & Linked list of exported symbols (libraries only) \\
  2137. &\textsf{SourceFiles : pFileManager;} & List of all source files for this module \\
  2138. &\textsf{ResourceFiles : TStringContainer;} & List of all resource files for this module \\
  2139. &\textsf{Used{\_}Units : TLinkedList; } & Information on units used by this module (pused{\_}unit) \\
  2140. &\textsf{Dependent{\_}Units : TLinkedList;}& \\
  2141. &\textsf{LocalUnitSearchPath,}& Search path for obtaining module source code \\
  2142. &\textsf{LocalObjectSearchPath,}& \\
  2143. &\textsf{LocalIncludeSearchPath,}& Search path for includes for this module \\
  2144. &\textsf{LocalLibrarySearchPath:TSearchPathList;}& \\
  2145. &\textsf{Path : pString;}& Path were module is located or created \\
  2146. &\textsf{OutputPath : pString;}& Path where object files (unit), executable (program) or shared library (library) is created \\
  2147. &\textsf{ModuleName : pString;}& Name of the module in uppercase \\
  2148. &\textsf{ObjFileName : pString;}& Full name of object file or executable file \\
  2149. &\textsf{AsmFileName : pString;}& Full name of the assembler file \\
  2150. &\textsf{PPUFileName : pString;}& Full name of the PPU file \\
  2151. &\textsf{StaticLibFilename : pString;}& Full name of the static library name (used when smart linking is used) \\
  2152. &\textsf{SharedLibFilename : pString;}& Filename of the output shared library (in the case of a library) \\
  2153. &\textsf{ExeFileName : pString;}& Filename of the output executable (in the case of a program) \\
  2154. &\textsf{AsmPrefix : pString;}& Filename prefix of output assembler files when using smartlinking \\
  2155. &\textsf{MainSource : pString;}& Name of the main source file \\
  2156. &\textsf{end;}& \\
  2157. %\end{tabular*}
  2158. \end{longtable}
  2159. \subsection{Parse types}
  2160. \label{subsec:parse}
  2161. \subsubsection{Entry}
  2162. \label{subsubsec:entry}
  2163. \begin{figure}
  2164. \begin{center}
  2165. \ifpdf
  2166. \includegraphics{arch8.pdf}
  2167. %\epsfig{file=arch8.png,width=\textwidth}
  2168. \else
  2169. \includegraphics[width=4.99in,height=8.36in]{arch8.eps}
  2170. \fi
  2171. \label{fig8}
  2172. \caption{Parser - Scanner flow}
  2173. \end{center}
  2174. \end{figure}
  2175. \subsubsection{program or library parsing }
  2176. \subsubsection{unit parsing }
  2177. \label{subsubsec:mylabel12}
  2178. \subsubsection{routine parsing }
  2179. \label{subsubsec:routine}
  2180. \subsubsection{label declarations }
  2181. \label{subsubsec:mylabel13}
  2182. \subsubsection{constant declarations}
  2183. \label{subsubsec:mylabel14}
  2184. \subsubsection{type declarations}
  2185. \label{subsubsec:mylabel15}
  2186. \subsubsection{variable declarations}
  2187. \label{subsubsec:mylabel16}
  2188. \subsubsection{thread variable declarations}
  2189. \label{subsubsec:thread}
  2190. \subsubsection{resource string declarations}
  2191. \label{subsubsec:resource}
  2192. \subsubsection{exports declaration}
  2193. \label{subsubsec:exports}
  2194. \subsubsection{expression parsing }
  2195. \label{subsubsec:expression}
  2196. \subsubsection{typed constant declarations}
  2197. \label{subsubsec:mylabel17}
  2198. \subsection{Parser interface}
  2199. \label{subsec:parser}
  2200. \subsubsection{variables}
  2201. \begin{variable}{AktProcSym}
  2202. \Declaration
  2203. Var AktProcSym : pProcSym;
  2204. \Description
  2205. Pointer to the symbol information for the routine currently being parsed.
  2206. \end{variable}
  2207. \begin{variable}{LexLevel}
  2208. \Declaration
  2209. var LexLevel : longint;
  2210. \Description
  2211. Level of code currently being parsed and compiled \par 0 = for main program
  2212. \par 1 = for subroutine \par 2 = for local / nested subroutines.
  2213. \end{variable}
  2214. \begin{variablel}{Current{\_}Module}{currentmodule}
  2215. \Declaration
  2216. Var Current{\_}Module : pModule;
  2217. \Description
  2218. Information on the current module (program, library or unit) being compiled.
  2219. \end{variablel}
  2220. The following variables are default type definitions which are created each
  2221. time compilation begins (default system-unit definitions), these definitions
  2222. should always be valid:
  2223. \begin{variable}{VoidDef}
  2224. \Declaration
  2225. Var VoidDef : pOrdDef;
  2226. \Description
  2227. Pointer to nothing type
  2228. \Notes
  2229. This is loaded as a default supported type for the compiler
  2230. \end{variable}
  2231. \begin{variable}{cCharDef}
  2232. \Declaration
  2233. Var cCharDef : pOrdDef;
  2234. \Description
  2235. Type definition for a character (\textsf{char})
  2236. \Notes
  2237. This is loaded as a default supported type for the compiler
  2238. \end{variable}
  2239. \begin{variable}{cWideCharDef}
  2240. \Declaration
  2241. Var cWideCharDef : pOrdDef;
  2242. \Description
  2243. Type definition for a unicode character (\textsf{widechar})
  2244. \Notes
  2245. This is loaded as a default supported type for the compiler
  2246. \end{variable}
  2247. \begin{variable}{BoolDef}
  2248. \Declaration
  2249. Var BoolDef : pOrdDef;
  2250. \Description
  2251. Type definition for a boolean value (\textsf{boolean})
  2252. \Notes
  2253. This is loaded as a default supported type for the compiler
  2254. \end{variable}
  2255. \begin{variable}{u8BitDef}
  2256. \Declaration
  2257. Var u8BitDef : pOrdDef;
  2258. \Description
  2259. Type definition for an 8-nit unsigned value (\textsf{byte})
  2260. \Notes
  2261. This is loaded as a default supported type for the compiler
  2262. \end{variable}
  2263. \begin{variable}{u16BitDef}
  2264. \Declaration
  2265. Var u16BitDef : pOrdDef;
  2266. \Description
  2267. Type definition for an unsigned 16-bit value (\textsf{word})
  2268. \Notes
  2269. This is loaded as a default supported type for the compiler
  2270. \end{variable}
  2271. \begin{variable}{u32BitDef}
  2272. \Declaration
  2273. Var u32BitDef : pOrdDef;
  2274. \Description
  2275. Type definition for an unsigned 32-bit value (\textsf{cardinal})
  2276. \Notes
  2277. This is loaded as a default supported type for the compiler
  2278. \end{variable}
  2279. \begin{variable}{s32BitDef}
  2280. \Declaration
  2281. Var s32BitDef : pOrdDef;
  2282. \Description
  2283. Type definition for a signed 32-bit value (\textsf{longint})
  2284. \Notes
  2285. This is loaded as a default supported type for the compiler
  2286. \end{variable}
  2287. \begin{variable}{cu64BitDef}
  2288. \Declaration
  2289. Var cu64BitDef : pOrdDef;
  2290. \Description
  2291. Type definition for an unsigned 64-bit value (\textsf{qword})
  2292. \Notes
  2293. This is loaded as a default supported type for the compiler
  2294. \end{variable}
  2295. \begin{variable}{cs64BitDef}
  2296. \Declaration
  2297. Var cs64BitDef : pOrdDef;
  2298. \Description
  2299. Type definition for a signed 64-bit value (\textsf{int64})
  2300. \Notes
  2301. This is loaded as a default supported type for the compiler
  2302. \end{variable}
  2303. The following variables are default type definitions which are created each
  2304. time compilation begins (default system-unit definitions), these definitions
  2305. should always be valid:
  2306. \begin{variable}{s64FloatDef}
  2307. \Declaration
  2308. Var s64FloatDef : pFloatDef;
  2309. \Description
  2310. Type definition for a 64-bit IEEE floating point type (\textsf{double})
  2311. \Notes
  2312. This is loaded as a default supported type for the compiler. This might not
  2313. actually really point to the double type if the cpu does not support it.
  2314. \end{variable}
  2315. \begin{variable}{s32FloatDef}
  2316. \Declaration
  2317. Var s32FloatDef : pFloatDef;
  2318. \Description
  2319. Type definition for a 32-bit IEEE floating point type (\textsf{single})
  2320. \Notes
  2321. This is loaded as a default supported type for the compiler. This might not
  2322. actually really point to the single type if the cpu does not support it.
  2323. \end{variable}
  2324. \begin{variable}{s80FloatDef}
  2325. \Declaration
  2326. Var s80FloatDef : pFloatDef;
  2327. \Description
  2328. Type definition for an extended floating point type (\textsf{extended})
  2329. \Notes
  2330. This is loaded as a default supported type for the compiler. This
  2331. might not actually really point to the extended type if the cpu does not
  2332. support it.
  2333. \end{variable}
  2334. \begin{variable}{s32FixedDef}
  2335. \Declaration
  2336. Var s32FixedDef : pFloatDef;
  2337. \Description
  2338. Type definition for a fixed point 32-bit value (\textsf{fixed})
  2339. \Notes
  2340. This is loaded as a default supported type for the compiler. This is
  2341. not supported officially in FPC 1.0
  2342. \end{variable}
  2343. The following variables are default type definitions which are created each
  2344. time compilation begins (default system-unit definitions), these definitions
  2345. should always be valid:
  2346. \begin{variable}{cShortStringDef}
  2347. \Declaration
  2348. Var cShortStringDef : pStringDef;
  2349. \Description
  2350. Type definition for a short string type (\textsf{shortstring})
  2351. \Notes
  2352. This is loaded as a default supported type for the compiler.
  2353. \end{variable}
  2354. \begin{variable}{cLongStringDef}
  2355. \Declaration
  2356. Var cLongStringDef : pStringDef;
  2357. \Description
  2358. Type definition for a long string type (\textsf{\textit{longstring}})
  2359. \Notes
  2360. This is loaded as a default supported type for the compiler.
  2361. \end{variable}
  2362. \begin{variable}{cAnsiStringDef}
  2363. \Declaration
  2364. Var cAnsiStringDef : pStringDef;
  2365. \Description
  2366. Type definition for an ansistring type (\textsf{ansistring})
  2367. \Notes
  2368. This is loaded as a default supported type for the compiler.
  2369. \end{variable}
  2370. \begin{variable}{cWideStringDef}
  2371. \Declaration
  2372. Var cWideStringDef : pStringDef;
  2373. \Description
  2374. Type definition for an wide string type (\textsf{\textit{widestring}})
  2375. \Notes
  2376. This is loaded as a default supported type for the compiler.
  2377. \end{variable}
  2378. \begin{variable}{OpenShortStringDef}
  2379. \Declaration
  2380. Var OpenShortStringDef : pStringDef;
  2381. \Description
  2382. Type definition for an open string type (\textsf{openstring})
  2383. \Notes
  2384. This is loaded as a default supported type for the compiler.
  2385. \end{variable}
  2386. \begin{variable}{OpenCharArrayDef}
  2387. \Declaration
  2388. Var OpenCharArrayDef : pArrayDef;
  2389. \Description
  2390. Type definition for an open char array type(\textsf{openchararray})
  2391. \Notes
  2392. This is loaded as a default supported type for the compiler.
  2393. \end{variable}
  2394. The following variables are default type definitions which are created each
  2395. time compilation begins (default system-unit definitions), these definitions
  2396. should always be valid:
  2397. \begin{variable}{VoidPointerDef}
  2398. \Declaration
  2399. Var VoidPointerDef : pPointerDef;
  2400. \Description
  2401. Type definition for a pointer which can point to anything (\textsf{pointer})
  2402. \Notes
  2403. This is loaded as a default supported type for the compiler
  2404. \end{variable}
  2405. \begin{variable}{CharPointerDef}
  2406. \Declaration
  2407. Var CharPointerDef : pPointerDef;
  2408. \Description
  2409. Type definition for a pointer which can point to characters (\textsf{pchar})
  2410. \Notes
  2411. This is loaded as a default supported type for the compiler
  2412. \end{variable}
  2413. \begin{variable}{VoidFarPointerDef}
  2414. \Declaration
  2415. Var VoidFarPointerDef : pPointerDef;
  2416. \Description
  2417. Type definition for a pointer which can point to anything
  2418. (intra-segment) (\textsf{far pointer})
  2419. \Notes
  2420. This is loaded as a default supported type for the compiler
  2421. \end{variable}
  2422. \begin{variable}{cFormalDef}
  2423. \Declaration
  2424. Var cFormalDef : pFormalDef;
  2425. \Notes
  2426. This is loaded as a default supported type for the compiler
  2427. \end{variable}
  2428. \begin{variable}{cfFileDef}
  2429. \Declaration
  2430. Var cfFileDef : pFileDef;
  2431. \Description This is the default file type (\textsf{file})
  2432. \Notes This is loaded as a default supported type for the compiler
  2433. \end{variable}
  2434. \section{The inline assembler parser}
  2435. \label{sec:mylabel6}
  2436. To be written.
  2437. \section{The code generator}
  2438. \label{sec:mylabel7}
  2439. \subsection{Introduction}
  2440. \label{subsec:introductioneratorer}
  2441. The code generator is responsible for creating the assembler output in form
  2442. of a linked list, taking as input the node created in the parser and the
  2443. 1$^{st}$ pass. Picture \seefig{fig9} shows an overview of the code generator
  2444. architecture:
  2445. \begin{figure}
  2446. \begin{center}
  2447. \ifpdf
  2448. \includegraphics{arch9.pdf}
  2449. %\epsfig{file=arch9.png,width=\textwidth}
  2450. \else
  2451. \includegraphics[width=5.68in,height=1.76in]{arch9.eps}
  2452. \fi
  2453. \label{fig:fig9}
  2454. \caption{Code generator architecture}
  2455. \end{center}
  2456. \end{figure}
  2457. The code generation is only done when a procedure body is parsed; the
  2458. interaction, between the 1$^{st}$ pass (type checking phase), the code
  2459. generation and the parsing process is show in the following diagram:
  2460. \begin{figure}
  2461. \ifpdf
  2462. \includegraphics{arch10.pdf}
  2463. %\epsfig{file=arch10.png,width=\textwidth}
  2464. \else
  2465. \includegraphics[width=6.95in,height=4.90in]{arch10.eps}
  2466. \fi
  2467. \label{fig:fig10}
  2468. \caption{Interaction between codegeneration and the parsing process}
  2469. \end{figure}
  2470. The \textsf{secondpass()} is actually a simple dispatcher. Each possible
  2471. tree type node (Cf. Tree types) is associated with
  2472. a second pass routine which is called using a dispatch table.
  2473. \subsection{Locations (cpubase.pas)}
  2474. \label{subsec:locations}
  2475. The code generator uses the tree location component to indicate the location
  2476. where the current node operands are located. This is then used by the code
  2477. generator to generate the appropriate instruction, all depending on the
  2478. location of the operand. The possible operand locations:
  2479. \begin{longtable}{|l|p{10cm}|}
  2480. \hline
  2481. Location define & Description \\
  2482. \hline
  2483. \endhead
  2484. \hline
  2485. \endfoot
  2486. \textsf{LOC{\_}INVALID}&
  2487. Invalid location (should never occur) \\
  2488. \textsf{LOC{\_}FPU}&
  2489. Floating point registers \\
  2490. \textsf{LOC{\_}REGISTER}&
  2491. Integer registers \\
  2492. \textsf{LOC{\_}MEM}&
  2493. Memory Location \\
  2494. \textsf{LOC{\_}REFERENCE}&
  2495. Constant node with constant value \\
  2496. \textsf{LOC{\_}JUMP}&
  2497. Label operand \\
  2498. \textsf{LOC{\_}FLAGS}&
  2499. Flags operand \\
  2500. \textsf{LOC{\_}CREGISTER}&
  2501. Constant integer register (when operand is in this
  2502. location, it should be considered as read-only) \\
  2503. \end{longtable}
  2504. Depending on the location type, a variable structure is defined indicating
  2505. more information on the operand. This is used by the code generator to
  2506. generate the exact instructions.
  2507. \subsubsection{LOC{\_}INVALID}
  2508. \label{subsubsec:mylabel18}
  2509. This location does not contain any related information, when this location
  2510. occurs, it indicates that the operand location was not initially allocated
  2511. correctly. This indicates a problem in the compiler.
  2512. \subsubsection{LOC{\_}FPU}
  2513. \label{subsubsec:mylabel19}
  2514. This indicates a location in the coprocessor; this is platform dependant.
  2515. \paragraph{Stack based FPU}
  2516. Only one CPU uses a stack based FPU architecture, this is the intel 80x86
  2517. family of processors. When the operand is on the top of the stack, the
  2518. operand is of type LOC{\_}FPU.
  2519. \paragraph{Register based FPU}
  2520. When the floating point co-processor is register based, the following
  2521. field(s) are defined in the structure to indicate the current location of
  2522. the operand:
  2523. \begin{longtable}{|l|p{7cm}|}
  2524. \hline
  2525. Field & Description \\
  2526. \hline
  2527. \endhead
  2528. \hline
  2529. \endfoot
  2530. \textsf{FpuRegister : TRegister;}&
  2531. Indicates in what register the operand is located (a general purpose
  2532. register in emulation mode, and a floating point register when floating
  2533. point hardware is present) \\
  2534. \textsf{FpuRegisterHigh, } \par
  2535. \textsf{FpuRegisterLow : TRegister;}&
  2536. Indicates in what registers the operand are located (for emulation
  2537. support - these are general purpose registers)
  2538. \end{longtable}
  2539. \subsubsection{LOC{\_}REGISTER}
  2540. \label{subsubsec:mylabel20}
  2541. This fields indicates that the operand is located in a CPU register. It is
  2542. possible to allocate more then one register, if trying to access 64-bit
  2543. values on 32-bit wide register machines.
  2544. \begin{longtable}{|l|p{10cm}|}
  2545. \hline
  2546. Field & Description \\
  2547. \hline
  2548. \endhead
  2549. \hline
  2550. \endfoot
  2551. \textsf{Register : TRegister}&
  2552. Indicates in what register the operand is located. \\
  2553. \textsf{RegisterHigh : TRegister;}&
  2554. High 32-bit of 64-bit virtual register (on 32-bit machines) \\
  2555. \textsf{RegisterLow : TRegister;}&
  2556. Low 32-bit of 64-bit virtual register (on 32-bit machines)
  2557. \end{longtable}
  2558. \subsubsection{LOC{\_}MEM, LOC{\_}REFERENCE}
  2559. \label{subsubsec:mylabel21}
  2560. This either indicates an operand in memory, or a constant integer numeric
  2561. value. The fields for this type of operand is as follows:
  2562. \begin{longtable}{|l|p{10cm}|}
  2563. \hline
  2564. Field & Description \\
  2565. \hline
  2566. \endhead
  2567. \hline
  2568. \endfoot
  2569. \textsf{Reference : TReference;}&
  2570. Information on the location in memory
  2571. \end{longtable}
  2572. References are the basic building blocks of the code generator, every load
  2573. and store in memory is done via a reference. A reference type can either
  2574. point to a symbolic name, an assembler expression (base register + index
  2575. register + offset)*scale factor, as well as simply giving information on a
  2576. numeric value.
  2577. The treference consists of the following:
  2578. \begin{tabular*}{6.5in}{|l@{\extracolsep{\fill}}lp{6,5cm}|}
  2579. \hline
  2580. \textsf{TYPE} & & \\
  2581. \xspace \textsf{pReference} &= \^{} \textbf{TReference};& \\
  2582. \xspace \textsf{TReference} &= \textbf{packed Record} & \\
  2583. &\textsf{Is{\_}Immediate : Boolean;}&
  2584. Indicates that this location points to a memory location, but to a
  2585. constant value (TRUE), which is located in the offset field. \\
  2586. &\textsf{Segment : TRegister;}& (cpu-specific) \\
  2587. &\textsf{Base : TRegister;}&
  2588. Base address register for assembler expression \\
  2589. &\textsf{Index : TRegister;}&
  2590. Index register for assembler expression \\
  2591. &\textsf{ScaleFactor : Byte;}&
  2592. Multiplication factor for assembler expression (this field is
  2593. cpu-specific) \\
  2594. &\textsf{Offset : Longint;}&
  2595. Either an offset from base assembler address expression to add (if
  2596. Is{\_}Constant = FALSE) otherwise the numeric value of the operand \\
  2597. &\textsf{Symbol : pAsmSymbol;}&
  2598. Pointer to the symbol name string of the reference in case where it is
  2599. a symbolic reference \\
  2600. &\textsf{OffsetFixup : Longint;}& \\
  2601. &\textsf{Options : TRefOptions;}& \\
  2602. &\textsf{END;}& \\
  2603. \hline
  2604. \end{tabular*}
  2605. \subsubsection{LOC{\_}JUMP}
  2606. \label{subsubsec:mylabel22}
  2607. There are no fields associated with this location, it simply indicates that
  2608. it is a boolean comparison which must be done to verify the succeeding
  2609. operations. (i.e the processor zero flag is valid and gives information on
  2610. the result of the last operation).
  2611. \subsubsection{LOC{\_}FLAGS}
  2612. \label{subsubsec:mylabel23}
  2613. The operand is in the flags register. From this operand, the conditional
  2614. jumps can be done. This is processor dependant, but normally the flags for
  2615. all different comparisons should be present.
  2616. \begin{longtable}{|l|p{10cm}|}
  2617. \hline
  2618. Field & Description \\
  2619. \hline
  2620. \endhead
  2621. \hline
  2622. \endfoot
  2623. \textsf{ResFlags : TResFlags;}&
  2624. This indicates the flag which must be verified for the actual jump
  2625. operation. \textsf{tresflags }is an enumeration of all possible
  2626. conditional flags which can be set by the processor. \\
  2627. \end{longtable}
  2628. \subsubsection{LOC{\_}CREGISTER}
  2629. \label{subsubsec:mylabel24}
  2630. This is a read-only register allocated somewhere else in the code generator.
  2631. It is used mainly for optimization purposes. It has the same fields as
  2632. LOC{\_}REGISTER, except that the registers associated with this location can
  2633. only be read from, and should never be modified directly.
  2634. \begin{longtable}{|l|p{10cm}|}
  2635. \hline
  2636. Field & Description \\
  2637. \hline
  2638. \endhead
  2639. \hline
  2640. \endfoot
  2641. \textsf{Register : TRegister}&
  2642. Indicates in what register the operand is located. \\
  2643. \textsf{RegisterHigh : TRegister;}&
  2644. High 32-bit of 64-bit virtual register (on 32-bit machines) \\
  2645. \textsf{RegisterLow : TRegister;}&
  2646. Low 32-bit of 64-bit virtual register (on 32-bit machines) \\
  2647. \end{longtable}
  2648. \subsubsection{LOCATION PUBLIC INTERFACE}
  2649. \label{subsubsec:location}
  2650. \begin{procedurel}{Del{\_}Location}{dellocation}
  2651. \Declaration
  2652. procedur Del{\_}Location(const L : TLocation);
  2653. \Description
  2654. If the location points to a LOC{\_}REGISTER or LOC{\_}CREGISTER, it frees up
  2655. the allocated register(s) associated with this location. If the location
  2656. points to LOC{\_}REFERENCE or LOC{\_}MEM, it frees up the the allocated base
  2657. and index registers associated with this node.
  2658. \end{procedurel}
  2659. \begin{procedurel}{Clear{\_}Location}{clearlocation}
  2660. \Declaration
  2661. procedure Clear{\_}location(var Loc : TLocation);
  2662. \Description
  2663. Sets the location to point to a LOC{\_}INVALID type.
  2664. \end{procedurel}
  2665. \begin{procedurel}{Set{\_}Location}{setlocation}
  2666. \Declaration
  2667. procedure Set{\_}Location(var Destloc,Sourceloc : TLocation);
  2668. \Description
  2669. The destination location now points to the destination location (now copy is
  2670. made, a simple pointer assignment)
  2671. \end{procedurel}
  2672. \begin{procedurel}{Swap{\_}Location}{swaplocation}
  2673. \Declaration
  2674. Procedure Swap{\_}Location(var Destloc,Sourceloc : TLocation);
  2675. \Description
  2676. Swap both location pointers.
  2677. \end{procedurel}
  2678. \subsection{Registers (cpubase.pas)}
  2679. \label{subsec:registers}
  2680. The code generator defines several types of registers which are categorized
  2681. by classes. All (except for the scratch register class) of these register
  2682. classes are allocated / freed on the fly, when the code is generated in the
  2683. code generator: The registers are defined in a special enumeration called
  2684. tregister. This enumeration contains all possible register defines for the
  2685. target architecture, and a possible definition could be as follows :
  2686. \begin{verbatim}
  2687. tregister = ( { general purpose registers }
  2688. R_NO,R_D0,R_D1,R_D2,R_D3,R_D4,R_D5,R_D6,R_D7,
  2689. { address registers }
  2690. R_A0,R_A1,R_A2,R_A3,R_A4,R_A5,R_A6,R_SP,
  2691. { PUSH/PULL- quick and dirty hack }
  2692. R_SPPUSH,R_SPPULL,
  2693. { misc. and floating point registers }
  2694. R_CCR,R_FP0,R_FP1,R_FP2,R_FP3,R_FP4,R_FP5,R_FP6,
  2695. R_FP7,R_FPCR,R_SR,R_SSP,R_DFC,R_SFC,R_VBR,R_FPSR,
  2696. { other - not used }
  2697. R_DEFAULT_SEG
  2698. );
  2699. \end{verbatim}
  2700. \subsubsection{integer registers}
  2701. \label{subsubsec:integer}
  2702. \textsf{intregs: array[1..maxintregs] of tregister;}
  2703. General purpose registers which can contain any data, usually integer
  2704. values. These can also be used, when no floating point coprocessor is
  2705. present, to hold values for floating point operations.
  2706. \subsubsection{address registers}
  2707. \label{subsubsec:address}
  2708. \textsf{addrregs: array[1..maxaddrregs] of tregister;}
  2709. Registers which are used to construct assembler address expressions, usually
  2710. the address registers are used as the base registers in these assembler
  2711. expressions.
  2712. \subsubsection{fpu registers}
  2713. \label{subsubsec:mylabel25}
  2714. \textsf{FpuRegs: array[1..MaxFpuRegs] of TRegister;}
  2715. Hardware floating point registers. These registers must at least be able to
  2716. load and store IEEE DOUBLE floating point values, otherwise they cannot be
  2717. considered as FPU registers. Not available on systems with no floating point
  2718. coprocessor.
  2719. \subsubsection{scratch registers}
  2720. \label{subsubsec:scratch}
  2721. \textsf{Scratch{\_}Regs: array[1..MaxScratchRegs] of TRegister;}
  2722. These registers are used as scratch, and can be used in assembler statement
  2723. in the pascal code, without being saved. They will always be valid across
  2724. routine calls. These registers are sometimes temporarily allocated inside
  2725. code generator nodes, and then immediately freed (always inside the same
  2726. routine).
  2727. \subsection{Special registers (cpubase.pas)}
  2728. \label{subsec:special}
  2729. The code generator has special uses for certain types of registers. These
  2730. special registers are of course CPU dependant, but as an indication, the
  2731. following sections explains the uses of these special registers and their
  2732. defines.
  2733. \subsubsection{Stack{\_}Pointer}
  2734. \label{subsubsec:stack}
  2735. \textsf{Const Stack{\_}Pointer = R{\_}A7}
  2736. This represents the stack pointer, an address register pointing to the
  2737. allocated stack area.
  2738. \subsubsection{Frame{\_}Pointer}
  2739. \label{subsubsec:frame}
  2740. \textsf{Const Frame{\_}Pointer = R{\_}A6}
  2741. This represents the frame register which is used to access values in the
  2742. stack. This is usually also an address register.
  2743. \subsubsection{Self{\_}Pointer}
  2744. \label{subsubsec:mylabel26}
  2745. \textsf{Const Self{\_}Pointer = R{\_}A5}
  2746. This represents the self register, which represents a pointer to the current
  2747. instance of a class or object.
  2748. \subsubsection{accumulator}
  2749. \label{subsubsec:accumulatorents}
  2750. \textsf{Const Accumulator = R{\_}D0}
  2751. The accumulator is used (except in the i386) as a scratch register, and also
  2752. for return value in functions (in the case where they are 32-bit or less).
  2753. In the case it is a 64-bit value (and the target processor only supports
  2754. 32-bit registers) , the result of the routine is stored in the accumulator
  2755. for the low 32-bit value, and in the scratch register
  2756. (\textsf{scratch{\_}register}) for the high 32-bit value.
  2757. \subsubsection{scratch register}
  2758. \label{subsubsec:mylabel27}
  2759. \textsf{const scratch{\_}reg = R{\_}D1}
  2760. This register is used in special circumstances by the code generator. It is
  2761. simply a define to one of the registers in the \textsf{scratch{\_}regs
  2762. }array.
  2763. \subsection{Instructions}
  2764. \label{subsec:instructionsr}
  2765. \subsection{Reference subsystem}
  2766. \label{subsec:reference}
  2767. \subsubsection{Architecture}
  2768. \label{subsubsec:architecturebsysteme}
  2769. As described before in the locations section, one of the possible locations
  2770. for an operand is a memory location, which is described in a special
  2771. structure \textsf{treference} (described earlier). This subsection describes
  2772. the interface available by the code generator for allocation and freeing
  2773. reference locations.
  2774. \subsubsection{Code generator interface}
  2775. \label{subsubsec:mylabel28}
  2776. %\lstinline!Function NewReference(Const R : TReference) : pReference;!
  2777. \begin{procedure}{DisposeReference}
  2778. \Declaration
  2779. Procedure DisposeReference(Var R : pReference);
  2780. \Description
  2781. Disposes of the reference \textsf{R} and sets r to \textsf{NIL}
  2782. \Notes
  2783. Does not verify if \textsf{R} is assigned first.
  2784. \end{procedure}
  2785. \begin{function}{NewReference}
  2786. \Declaration
  2787. Function NewReference(Const R : TReference) : pReference;
  2788. \Description
  2789. Allocates in the heap a copy of the reference \textsf{r} and returns that
  2790. allocated pointer.
  2791. \end{function}
  2792. \begin{functionl}{Del{\_}Reference}{delreference}
  2793. \Declaration
  2794. Procedure Del{\_}Reference(Const Ref : tReference);
  2795. \Description
  2796. Free up all address registers allocated in this reference for the index and
  2797. base (if required).
  2798. \Notes
  2799. Does not free the reference symbol if it exists.
  2800. \end{functionl}
  2801. \begin{functionl}{New{\_}Reference}{resetreference}
  2802. \Declaration
  2803. Function New{\_}Reference(Base : TRegister;Offset : Longint) : PReference;
  2804. \Description
  2805. Allocates a reference pointer, clears all the fields to zero, and sets the
  2806. offset to the offset field and the base to the base fields of the newly
  2807. allocated reference. Returns this newly allocated reference.
  2808. \end{functionl}
  2809. \begin{procedurel}{Reset{\_}Reference}{resetreference}
  2810. \Declaration
  2811. Procedure Reset{\_}Reference(Var Ref : TReference);
  2812. \Description
  2813. Clears all fields of the reference.
  2814. \end{procedurel}
  2815. \subsection{The register allocator subsystem}
  2816. \label{subsec:mylabel7}
  2817. \subsubsection{Architecture}
  2818. \label{subsubsec:architecture}
  2819. This system allocates and deallocates registers, from a pool of free
  2820. registers. Each time the code generator requires a register for generating
  2821. assembler instructions, it either calls the register allocator subsystem to
  2822. get a free register or directly uses the scratch registers (which are never
  2823. allocated in a pool except in the optimization phases of the compiler).
  2824. The code generator when no longer referencing the register should deallocate
  2825. it so it can be used once again.
  2826. \subsubsection{Code generator interface (tgen.pas)}
  2827. \label{subsubsec:mylabel29}
  2828. The following interface routines are used by the code generator to allocate
  2829. and deallocate registers from the different register pools available to code
  2830. generator.
  2831. \begin{function}{GetRegister32}
  2832. \Declaration
  2833. Function GetRegister32 : TRegister;
  2834. \Description
  2835. Allocates and returns a general purpose (integer) register which can be used
  2836. in the code generator. The register, when no longer used should be
  2837. deallocated with ungetregister32() or ungetregister()
  2838. \Notes
  2839. On non 32-bit machines, this routine should return the normal register for
  2840. this machine (eg : 64-bit machines will alloate and return a 64-bit
  2841. register).
  2842. \end{function}
  2843. \begin{procedure}{GetRegisterPair}
  2844. \Declaration
  2845. Procedure GetRegisterPair(Var Low, High : TRegister);
  2846. \Description
  2847. Returns a register pair to be used by the code generator when accessing
  2848. 64-bit values on 32-bit wide register machines.
  2849. \Notes
  2850. On machines which support 64-bit registers naturally, this routine should
  2851. never be used, it is intended for 32-bit machines only.par Some machines
  2852. support 64-bit integer operations using register 32-bit pairs in hardware,
  2853. but the allocated registers must be specific, this routine is here to
  2854. support these architectures.
  2855. \end{procedure}
  2856. \begin{procedure}{UngetRegister32}
  2857. \Declaration
  2858. Procedure UnGetRegister32(R : TRegister);
  2859. \Description
  2860. Deallocates a general purpose register which was previously allocated with
  2861. \seef{GetRegister32}().
  2862. \end{procedure}
  2863. \begin{function}{GetFloatRegister}
  2864. \Declaration
  2865. Function GetFloatRegister : TRegister;
  2866. \Description
  2867. Allocates and returns a floating point register which can be used in the
  2868. code generator. The register, when no longer used should be deallocated with
  2869. ungetregister(). The register returned is a true floating point register (if
  2870. supported).
  2871. \Notes
  2872. This routine should only be used when floating point hardware is present in
  2873. the system. For emulation of floating point, the general purpose register
  2874. allocator / deallocator routines should be used instead.
  2875. \end{function}
  2876. \begin{function}{IsFloatsRegister}
  2877. \Declaration
  2878. Function IsFloatsRegister(R : TRegister): Boolean;
  2879. \Description
  2880. Returns TRUE if the register r is actually a floating point register,
  2881. otherwise returns FALSE. This is used when the location is LOC{\_}FPU on
  2882. machines which do not support true floating point registers.
  2883. \end{function}
  2884. \begin{function}{GetAdressReg}
  2885. \Declaration
  2886. Function GetAddressReg : TRegister;
  2887. \Description
  2888. Allocates and returns an address register which can be used for address
  2889. related opcodes in the code generator. The register, when no longer used
  2890. should be deallocated with ungetregister()
  2891. \Notes
  2892. If there is no distinction between address registers, and general purpose
  2893. register in the architecture, this routine may simply call and return the
  2894. getregister32() result.
  2895. \end{function}
  2896. \begin{function}{IsAddressRegister}
  2897. \Declaration
  2898. Function IsAddressRegister(r : TRegister): Boolean;
  2899. \Description
  2900. Returns TRUE if the register r is actually an address register, otherwise
  2901. returns FALSE.
  2902. \Notes
  2903. If there is no distinction between address registers, and general purpose
  2904. register in the architecture, this routine may simply verify if this is a
  2905. general purpose register and return TRUE in that case.
  2906. \end{function}
  2907. \begin{procedure}{UngetRegister}
  2908. \Declaration
  2909. Procedure UngetRegister(r : TRegister);
  2910. \Description
  2911. Deallocates any register which was previously allocated with any of the
  2912. allocation register routines.
  2913. \end{procedure}
  2914. \begin{function}{SaveUsedRegisters}
  2915. \Declaration
  2916. Procedure SaveUsedRegisters(Var Saved : TSaved; ToSave: TRegisterset);
  2917. \Description
  2918. Saves in a temporary location all specified registers. On stack based
  2919. machines the registers are saved on the stack, otherwise they are saved in a
  2920. temporary memory location. The registers which were saved are stored in the
  2921. \textsf{saved} variable. The constant \textsf{ALL{\_}REGISTERS} passed to
  2922. the \textsf{tosave} parameter indicates to save all used registers.
  2923. \end{function}
  2924. \begin{function}{RestoreUsedRegisters}
  2925. \Declaration
  2926. procedure restoreusedregisters(Saved : TSaved);
  2927. \Description
  2928. Restores all saved registers from the stack (or a temporary memory
  2929. location). Free any temporary memory space allocated, if necessary.
  2930. \end{function}
  2931. \begin{function}{GetExplicitRegister32}
  2932. \Declaration
  2933. Function GetExplicitRegister32(R : TRegister): TRegister;
  2934. \Description
  2935. This routine allocates specifically the specified register \textsf{r} and
  2936. returns that register. The register to allocate can only be one of the
  2937. scratch registers.
  2938. \Notes
  2939. This routine is used for debugging purposes only. It should be used in
  2940. conjunctions with UnGetRegister32() to explicitly allocate and deallocate a
  2941. scratch register.
  2942. \end{function}
  2943. \subsection{Temporary memory allocator subsystem}
  2944. \label{subsec:temporary}
  2945. \subsubsection{Architecture}
  2946. \label{subsubsec:architecturemory}
  2947. Sometimes it is necessary to reserve temporary memory locations on the stack
  2948. to store intermediate results of statements. This is done by the temporary
  2949. management module.
  2950. Since entry and exit code for routines are added after the code for the
  2951. statements in the routine have been generated, temporary memory allocation
  2952. can be used `on the fly' in the case where temporary memory values are
  2953. required in the code generation phase of the routines being compiled. After
  2954. usage, the temporary memory space should be freed, so it can be reused if
  2955. necessary.
  2956. The temporary memory allocation is a linked list of entries containing
  2957. information where to access the data via a negative offset from the
  2958. Frame{\_}Pointer register. The linked list is only valid when compiling and
  2959. generating the code for the procedure bodies; it is reset and cleared each
  2960. time a new routine is compiled. There are currently three different types of
  2961. memory spaces in use : volatile (\textsf{tt{\_}Normal}) which can be
  2962. allocated and freed any time in the procedure body, ansistring, which is
  2963. currently the same as volatile, except it only stored references to
  2964. ansistring's, and persistent (\textsf{tt{\_}Persistent}) which are memory
  2965. blocks which are reserved throughout the routine duration; persistent
  2966. allocated space can never be reused in a procedure body, unless explicitly
  2967. released.
  2968. The temporary memory allocator guarantees to allocate memory space on the
  2969. stack at least on a 16-bit alignment boundary. The exact alignment depends
  2970. on the operating system required alignment.
  2971. \subsubsection{Temporary memory allocator interface (temp{\_}gen.pas)}
  2972. \label{subsubsec:temporary}
  2973. \begin{function}{GetTempOfSize}
  2974. \Declaration
  2975. Function GetTempOfSize(Size : Longint) : Longint;
  2976. \Description
  2977. Allocates at least \textsf{size} bytes of temporary volatile memory on the
  2978. stack. The return value is the negative offset from the frame pointer where
  2979. this memory was allocated.
  2980. \Notes
  2981. The return offset always has the required alignment for the target system,
  2982. and can be used as an offset from the Frame{\_}Pointer to access the
  2983. temporary space.
  2984. \end{function}
  2985. \begin{procedure}{GetTempOfSizeReference}
  2986. \Declaration
  2987. Procedure GetTempOfSizeReference(L : Longint;Var Ref : TReference);
  2988. \Description
  2989. This routine is used to assign and allocate extra temporary volatile memory
  2990. space on the stack from a reference. \textsf{l} is the size of the
  2991. persistent memory space to allocate, while \textsf{Ref} is a reference entry
  2992. which will be set to the correct offset from the Frame{\_}Pointer register
  2993. base. The \textsf{Offset} and \textsf{Base} fields of \textsf{Ref} will be
  2994. set appropriately in this routine, and can be considered valid on exit of
  2995. this routine.
  2996. \Notes
  2997. The return offset always has the required alignment for the target system.
  2998. \end{procedure}
  2999. \begin{procedure}{UnGetIfTemp}
  3000. \Declaration
  3001. Procedure UnGetIfTemp(Const Ref : TReference);
  3002. \Description
  3003. Frees a reference \textsf{Ref} which was allocated in the volatile temporary
  3004. memory space.
  3005. \Notes
  3006. The freed space can later be reallocated and reused.
  3007. \end{procedure}
  3008. \begin{procedure}{GetTempAnsiStringReference}
  3009. \Declaration
  3010. Procedure GetTempAnsiStringReference(Var Ref : TReference);
  3011. \Description
  3012. Allocates \textsf{Ref} on the volatile memory space and sets the
  3013. \textsf{Base} to the Frame{\_}Pointer register and \textsf{Offset} to the
  3014. correct offset to access this allocated memory space.
  3015. \Notes
  3016. The return offset always has the required alignment for the target system.
  3017. \end{procedure}
  3018. \begin{function}{GetTempOfSizePersistant}
  3019. \Declaration
  3020. Function GetTempOfSizePersistant(Size : Longint) :Longint;
  3021. \Description
  3022. Allocates persistent storage space on the stack. return value is the
  3023. negative offset from the frame pointer where this memory was allocated.
  3024. \Notes
  3025. The return offset always has the required alignment for the target system.
  3026. \end{function}
  3027. \begin{function}{UngetPersistantTemp}
  3028. \Declaration
  3029. Procedure UnGetPersistantTemp(Pos : Longint);
  3030. \Description
  3031. Frees space allocated as being persistent. This persistent space can then
  3032. later be used and reallocated. \textsf{Pos} is the offset relative to the
  3033. Frame{\_}Pointer of the persistent memory block to free.
  3034. \end{function}
  3035. \begin{procedure}{ResetTempGen}
  3036. \Declaration
  3037. Procedure ResetTempGen;
  3038. \Description
  3039. Clear and free the complete linked list of temporary memory locations. The
  3040. list is set to nil.
  3041. \Notes
  3042. This routine is called each time a routine has been fully compiled.
  3043. \end{procedure}
  3044. \begin{procedure}{SetFirstTemp}
  3045. \Declaration
  3046. Procedure SetFirstTemp(L : Longint);
  3047. \Description
  3048. This routine sets the start of the temporary local area (this value is a
  3049. negative offset from the Frame{\_}Pointer, which is located after the local
  3050. variables). Usually the start offset is the size of the local variables,
  3051. modified by any alignment requirements.
  3052. \Notes
  3053. This routine is called once before compiling a routine, it indicates the
  3054. start address where to allocate temporary memory space.
  3055. \end{procedure}
  3056. \begin{function}{GetFirstTempSize}
  3057. \Declaration
  3058. Function GetFirstTempSize : Longint;
  3059. \Description
  3060. Returns the total number of bytes allocated for local and temporary
  3061. allocated stack space. This value is aligned according to the target system
  3062. alignment requirements, even if the actual size is not aligned.
  3063. \Notes
  3064. This routine is used by the code generator to get the total number of bytes
  3065. to allocate locally (i.e the stackframe size) in the entry and exit code of
  3066. the routine being compiled.
  3067. \end{function}
  3068. \begin{function}{NormalTempToPersistant}
  3069. \Declaration
  3070. Procedure NormalTempToPersistant(Pos : Longint);
  3071. \Description
  3072. Searches the list of currently temporary memory allocated for the one with
  3073. the offset \textsf{Pos}, and if found converts this temporary memory space
  3074. as persistent (can never be freed and reallocated).
  3075. \end{function}
  3076. \begin{function}{PersistantTempToNormal}
  3077. \Declaration
  3078. Procedure PersistantTempToNormal(Pos : Longint);
  3079. \Description
  3080. Searches the list of currently allocated persistent memory space as the
  3081. specified address \textsf{Pos}, and if found converts this memory space to
  3082. normal volatile memory space which can be freed and reused.
  3083. \end{function}
  3084. \begin{function}{IsTemp}
  3085. \Declaration
  3086. Function IsTemp(const Ref : TReference): Boolean;
  3087. \Description
  3088. Returns TRUE if the reference \textsf{ref }is allocated in temporary
  3089. volatile memory space, otherwise returns FALSE.
  3090. \end{function}
  3091. \subsection{Assembler generation}
  3092. \label{subsec:mylabel8}
  3093. \subsubsection{Architecture}
  3094. \label{subsubsec:architectureneration}
  3095. The different architectures on the market today only support certain types
  3096. of operands as assembler instructions. The typical format of an assembler
  3097. instruction has the following format:
  3098. \begin{center}
  3099. \textsf{OPCODE [opr1,opr2[,opr3][\ldots ]]}
  3100. \end{center}
  3101. The opcode field is a mnemonic for a specific assembler instruction, such as
  3102. \textsf{MOV} on the 80x86, or \textsf{ADDX} on the 680x0. Furthermore, in
  3103. most cases, this mnemonic is followed by zero to three operands which can be
  3104. of the following types:
  3105. Possible Operand Types
  3106. \begin{itemize}
  3107. \item a LABEL or SYMBOL (to code or data)
  3108. \item a REGISTER (one of the predefined hardware registers)
  3109. \item a CONSTANT (an immediate value)
  3110. \item a MEMORY EXPRESSION (indirect addressing through offsets, symbols, and
  3111. address registers)
  3112. \end{itemize}
  3113. In the compiler, this concept of different operand types has been directly
  3114. defined for easier generation of assembler output. All opcodes generated by
  3115. the code generator are stored in a linked list of opcodes which contain
  3116. information on the operand types, The opcode and the size (which is
  3117. important to determine on what size the operand must be operated on) are
  3118. stored in that linked list.
  3119. The possible operand sizes for the code generator are as follows (a
  3120. enumeration of type \textsf{topsize}):
  3121. \begin{longtable}{|l|p{10cm}|}
  3122. \hline
  3123. Operand size enum (\textsf{topsize}) & Description \\
  3124. \hline
  3125. \endhead
  3126. \hline
  3127. \endfoot
  3128. \textsf{S{\_}B}& 8-bit integer operand \\
  3129. \textsf{S{\_}W}& 16-bit integer operand \\
  3130. \textsf{S{\_}L}& 32-bit integer operand \\
  3131. \textsf{S{\_}Q}& 64-bit integer operand \\
  3132. \textsf{S{\_}FS}& 32-bit IEEE 754 Single floating point operand \\
  3133. \textsf{S{\_}FL}& 64-bit IEEE 754 Double floating point operand \\
  3134. \textsf{S{\_}FX}& Extended point floating point operand (cpu-specific) \\
  3135. \textsf{S{\_}CPU}& A constant equal to one of the previous sizes (natural size of operands) \\
  3136. \end{longtable}
  3137. The possible operand types for the code generator are as follows (other
  3138. might be added as required by the target architecture):
  3139. \begin{longtable}{|l|p{10cm}|}
  3140. \hline
  3141. Operand type (\textsf{TOpType}) & Description \\
  3142. \hline
  3143. \endhead
  3144. \hline
  3145. \endfoot
  3146. \textsf{top{\_}None}& No operand \\
  3147. \textsf{top{\_}Reg}& Operand is a register \\
  3148. \textsf{top{\_}Ref}& Operand is a reference (\textsf{treference} type) \\
  3149. \textsf{top{\_}Symbol}& Operand is a symbol (reference or label) \\
  3150. \end{longtable}
  3151. The architecture specific opcodes are done in an enumeration of type
  3152. \textsf{tasmop}. An example of an enumeration for some of the opcodes of the
  3153. PowerPC 32-bit architecture is as follows:
  3154. \begin{lstlisting}{}
  3155. Type TAsmOp = (a_Add, a_Add_, a_Addo, a_Addo_, a_Addc, a_Addc_, a_Addco,
  3156. a_Addco_,a_Adde, a_Adde_, a_Addeo, a_Addeo_, a_Addi,
  3157. a_Addic, a_Addic_, a_Addis \ldots
  3158. \end{lstlisting}
  3159. \subsubsection{Generic instruction generation interface}
  3160. \label{subsubsec:generic}
  3161. To independently generate code for different architectures, wrappers for the
  3162. most used instructions in the code generator have been created which are
  3163. totally independent of the target system.
  3164. \begin{procedurel}{Emit\_Load\_Loc\_Reg}{EmitLoadLocReg}
  3165. \Declaration
  3166. Procedure Emit{\_}Load{\_}Loc{\_}Reg(Src:TLocation;Srcdef:pDef; DstDef : pDef; Dst : TRegister);
  3167. \Description
  3168. Loads an operand from the source location in \textsf{Src} into the
  3169. destination register \textsf{Dst} taking into account the source definition
  3170. and destination definition (sign-extension, zero extension depending on the
  3171. sign and size of the operands).
  3172. \Notes
  3173. The source location can only be in LOC{\_}REGISTER, LOC{\_}CREGISTER,
  3174. LOC{\_}MEM or LOC{\_}REFERENCE otherwise an internal error will occur. This
  3175. generic opcode does not work on floating point values, only integer values.
  3176. \end{procedurel}
  3177. \begin{procedure}{FloatLoad}
  3178. \Declaration
  3179. Procedure FloatLoad(t : tFloatType;Ref : TReference; Var Location:TLocation);
  3180. \Description
  3181. This routine is to be called each time a location must be set to LOC{\_}FPU
  3182. and a value loaded into a FPU register
  3183. \Notes
  3184. The routine sets up the register field of LOC{\_}FPU correctly. The source
  3185. location can only be : LOC{\_}MEM or LOC{\_}REFERENCE. The destination
  3186. location is set to LOC{\_}FPU.
  3187. \end{procedure}
  3188. \begin{function}{FloatStore}
  3189. \Declaration
  3190. Procedure FloatStore(t : TFloatType;Var Location:TLocation; Ref:TReference);
  3191. \Description
  3192. This routine is to be called when a value located in LOC{\_}FPU must be
  3193. stored into memory.
  3194. \Notes
  3195. The destination must be LOC{\_}REFERENCE or LOC{\_}MEM. This routine frees
  3196. the LOC{\_}FPU location \\
  3197. \end{function}
  3198. \begin{functionl}{emit{\_}mov{\_}ref{\_}reg64}{emitmovrefreg64}
  3199. \Declaration
  3200. Procedure Emit{\_}Mov{\_}Ref{\_}Reg64(r : TReference;rl,rh : TRegister);
  3201. \Description
  3202. This routine moves a 64-bit integer value stored in memory location
  3203. \textsf{r} into the low 32-bit register \textsf{rl} and the high 32-bit
  3204. register \textsf{rh}.
  3205. \end{functionl}
  3206. \begin{functionl}{Emit{\_}Lea{\_}Loc{\_}Ref}{emitlealocref}
  3207. \Declaration
  3208. Procedure Emit{\_}Lea{\_}Loc{\_}Ref(Const t:TLocation;Const Ref:TReference; FreeTemp:Boolean);
  3209. \Description
  3210. Loads the address of the location \textsf{loc }and stores the result into
  3211. \textsf{Ref}
  3212. \Notes
  3213. The store address \textsf{ref }should point to an allocated area at least
  3214. \textsf{sizeof(pointer)} bytes, otherwise unexpected code might be
  3215. generated.
  3216. \end{functionl}
  3217. \begin{functionl}{Emit{\_}Lea{\_}Loc{\_}Reg}{Emitlealocreg}
  3218. \Declaration
  3219. Procedure Emit{\_}Lea{\_}Loc{\_}Reg(const t:TLocation;Reg:TRegister;Freetemp:Boolean);
  3220. \Description
  3221. Loads the address of the location \textsf{loc }and stores the result into
  3222. ther target register \textsf{reg}
  3223. \end{functionl}
  3224. \begin{procedure}{GetLabel}
  3225. \Declaration
  3226. Procedure GetLabel(Var l : pAsmLabel);
  3227. \Description
  3228. Returns a label associated with code. This label can then be used with the
  3229. instructions output by the code generator using the instruction generation
  3230. templates which require labels as parameters. The label itself can be
  3231. emitted to the assembler source by calling the \seep{EmitLab} routine.
  3232. \end{procedure}
  3233. \begin{procedure}{EmitLab}
  3234. \Declaration
  3235. Procedure EmitLab(Var l : pAsmLabel);
  3236. \Description
  3237. Output the label \textsf{l} to the assembler instruction stream.
  3238. \Notes
  3239. The label should have been previously allocated with \textsf{GetLabel}, The
  3240. output label will be of the form label: in the instruction stream. This
  3241. label is usually a jump target.
  3242. \end{procedure}
  3243. \begin{procedure}{EmitLabeled}
  3244. \Declaration
  3245. Procedure EmitLabeled(op : TAsmOp; Var l : pAsmLabel);
  3246. \Description
  3247. Output the opcode \textsf{op} with the operand \textsf{l}
  3248. which is a previously allocated label.
  3249. \Notes
  3250. This routine is used to output jump instructions such as : jmp label, jne
  3251. label. The label should have been previously allocated with a call to
  3252. \textsf{GetLabel}
  3253. \end{procedure}
  3254. \begin{function}{EmitCall}
  3255. \Declaration
  3256. Procedure EmitCall(Const Routine:String);
  3257. \Description
  3258. Emit a call instruction to an internal routine
  3259. \Parameters
  3260. Routine = The name of the routine to call.
  3261. \end{function}
  3262. \begin{procedure}{ConcatCopy}
  3263. \Declaration
  3264. procedure ConcatCopy(Source,Dest : TReference;Size : Longint;DelSource : Boolean; loadref:boolean);
  3265. \Description
  3266. This routine copies \textsf{Size} data from the \textsf{Source} reference to
  3267. the destination \textsf{Dest} reference. \\
  3268. \Parameters
  3269. Source = Source reference to copy from \par
  3270. Dest = Depending on the value of loadref, either indicates a location where a pointer to the data to copy is
  3271. Stored, or this reference directly the address to copy to. \par
  3272. Size = Number of bytes to copy \par
  3273. DelSource = TRUE if the source reference should be freed in this routine \par
  3274. LoadRef = TRUE if the source reference contains a pointer to the address we
  3275. wish to copy to, otherwise the reference itself is the destination
  3276. location to copy to.
  3277. \end{procedure}
  3278. \begin{procedurel}{Emit{\_}Flag2Reg}{emitflag2reg}
  3279. \Declaration
  3280. Procedure Emit{\_}Flag2Reg(Flag:TResflags;HRegister:TRegister);
  3281. \Description
  3282. Sets the value of the register to 1 if the condition code flag in
  3283. \textsf{Flag} is TRUE, otherwise sets the register to zero.
  3284. \Notes
  3285. The operand should be zero extended to the natural register size for the
  3286. target architecture.
  3287. \end{procedurel}
  3288. %\subsubsection{Instruction generation interface}
  3289. %\label{subsubsec:instruction}
  3290. \section{The assembler output}
  3291. \label{sec:mylabel8}
  3292. All code is generated via special linked lists of instructions. The base of
  3293. this is a special object, an abstract assembler which implements all
  3294. directives which are usually implemented in the different assemblers
  3295. available on the market . When the code generator and parser generates the
  3296. final output, it is generated as a linked list for each of the sections
  3297. available for the output assembler. Each entry in the linked list is either
  3298. an instruction, or one of the abstract directives for the assembler.
  3299. \begin{figure}
  3300. \ifpdf
  3301. \includegraphics{arch11.pdf}
  3302. %\epsfig{file=arch11.png,width=\textwidth}
  3303. \else
  3304. \includegraphics[width=5.67in,height=2.17in]{arch11.eps}
  3305. \fi
  3306. \label{fig:fig11}
  3307. \caption{Assembler generation organisation}
  3308. \end{figure}
  3309. % FIXME
  3310. % If I don't do this, the assembler node table has a problem.
  3311. % untested for more recent versions (with less floats due to longtable)
  3312. \clearpage
  3313. The different possible sections which are output are as follows:
  3314. \begin{center}
  3315. Section lists for the assembler output
  3316. \end{center}
  3317. \begin{longtable}{|l|p{10cm}|}
  3318. \hline
  3319. Internal section name & Description \\
  3320. \hline
  3321. \endhead
  3322. \hline
  3323. \endfoot
  3324. ExparAsmList & temporary list \\
  3325. DataSegment & initialized variables \\
  3326. CodeSegment & instructions and general code directives \\
  3327. DebugList & debugging information \\
  3328. WithDebugList & ??????????????? \\
  3329. Consts & read only constants \\
  3330. ImportSection & imported symbols \\
  3331. ExportSection & exported symbols \\
  3332. ResourceSection & Resource data \\
  3333. RttiList & runtime type information data \\
  3334. ResourceStringList& resource string data
  3335. \end{longtable}
  3336. The following directives for the abstract assembler currently exist:
  3337. Abstract assembler node types:
  3338. \begin{longtable}{|l|p{10cm}|}
  3339. \hline
  3340. Node entry Type & Description \\
  3341. \hline
  3342. \endhead
  3343. \hline
  3344. \endfoot
  3345. Ait{\_}None&
  3346. This entry in the linked list is invalid (this should
  3347. normally never occur) \\
  3348. Ait{\_}Direct&
  3349. Direct output to the resulting assembler file (as string) \\
  3350. Ait{\_}String&
  3351. Shortstring with a predefined length \\
  3352. Ait{\_}Label&
  3353. Numbered assembler label used for jumps \\
  3354. Ait{\_}Comment&
  3355. Assembler output comment \\
  3356. Ait{\_}Instruction&
  3357. Processor specific instruction \\
  3358. Ait{\_}DataBlock&
  3359. Unitialized data block (BSS) \\
  3360. Ait{\_}Symbol&
  3361. Entry represents a symbol (exported, imported, or other public
  3362. symbol type) \newline
  3363. Possible symbol types : NONE, EXTERNAL, LOCAL and GLOBAL \newline
  3364. eg : A symbol followed by an Ait{\_}const{\_}32bit \\
  3365. Ait{\_}Symbol{\_}End &
  3366. Symbol end (for example the end of a routine) \\
  3367. Ait{\_}Const{\_}32bit&
  3368. Initialized 32-bit constant (without a symbol) \\
  3369. Ait{\_}Const{\_}16bit&
  3370. Initialized 16-bit constant (without a symbol) \\
  3371. Ait{\_}Const{\_}8bit&
  3372. Initialized 8-bit constant (without a symbol) \\
  3373. Ait{\_}Const{\_}symbol & ???????????? \\
  3374. Ait{\_}Real{\_}80bit (x86)&
  3375. Initialized 80-bit floating point constant (without symbol) \\
  3376. Ait{\_}Real{\_}64bit&
  3377. Initialized Double IEEE floating point constant (without symbol) \\
  3378. Ait{\_}Real{\_}32bit&
  3379. Initialized Single IEEE floating point constant (without symbol) \\
  3380. Ait{\_}Comp{\_}64bit (x86)&
  3381. Initialized 64-bit floating point integer (without symbol) \\
  3382. Ait{\_}Align&
  3383. Alignment directive \\
  3384. Ait{\_}Section&
  3385. Section directive \\
  3386. Ait{\_}const{\_}rva (Win32)& \\
  3387. Ait{\_}Stabn &
  3388. stabs debugging information (numerical value) \\
  3389. Ait{\_}Stabs &
  3390. stabs debugging information (string) \\
  3391. Ait{\_}Force{\_}Line&
  3392. stabs debugging line information \\
  3393. Ait{\_}Stab{\_}Function{\_}Name&
  3394. stabs debug information routine name \\
  3395. Ait{\_}Cut&
  3396. Cut in the assembler files (used for smartlinking) \\
  3397. Ait{\_}RegAlloc&
  3398. Debugging information for the register allocator \\
  3399. Ait{\_}Marker & ???????????? \\
  3400. Ait{\_}Frame (Alpha)& \\
  3401. Ait{\_}Ent (Alpha)& \\
  3402. Ait{\_}Labeled{\_}Instruction (m68k)& \\
  3403. Ait{\_}Dummy & Unused - should never appear
  3404. \end{longtable}
  3405. \section{The Runtime library}
  3406. \label{sec:mylabel9}
  3407. This section describes the requirements of the internal routines which MUST
  3408. be implemented for all relevant platforms to port the system unit to a new
  3409. architecture or operating system.
  3410. The following defines are available when compiling the runtime library:
  3411. \begin{longtable}{|l|p{10cm}|}
  3412. \hline
  3413. Define Name & Description \\
  3414. \hline
  3415. \endhead
  3416. \hline
  3417. \endfoot
  3418. i386 & Intel 80x86 family of processors (and compatibles) \\
  3419. m68k & Motorola 680x0 family of processors (excludes coldfire) \\
  3420. alpha & Alpha 21x64 family of processors \\
  3421. powerpc & Motorola / IBM 32-bit family of processors \\
  3422. sparc & SPARC v7 compatible processors
  3423. \end{longtable}
  3424. \begin{longtable}{|l|p{10cm}|}
  3425. \hline
  3426. Define name & Description \\
  3427. \hline
  3428. \endhead
  3429. \hline
  3430. \endfoot
  3431. RTLLITE&
  3432. Removes some extraneous routine from compilation (system unit
  3433. is minimal). Mvdv: Afaik the status of this is unknown \\
  3434. DEFAULT{\_}EXTENDED&
  3435. The runtime library routines dealing with fixed point values have the
  3436. \textsf{extended} type instead of the \textsf{real} type. \\
  3437. SUPPORT{\_}SINGLE&
  3438. The compiler supports the \textsf{single} floating point precision type \\
  3439. SUPPORT{\_}DOUBLE&
  3440. The compiler supports the \textsf{double }floating point precision type \\
  3441. SUPPORT{\_}EXTENDED&
  3442. The compiler supports the \textsf{extended }floating point
  3443. precision type \\
  3444. SUPPORT{\_}FIXED&
  3445. The compiler supports the \textsf{fixed} floating point precision type \\
  3446. HASWIDECHAR&
  3447. The compiler supported the \textsf{widechar} character type \\
  3448. INT64&
  3449. The compiler supports 64-bit integer operations \\
  3450. MAC{\_}LINEBREAK&
  3451. Text I/O uses Mac styled line break ({\#}13) instead of {\#}13{\#}10 \\
  3452. SHORT{\_}LINEBREAK&
  3453. Text I/O uses UNIX styled line breaks ({\#}10) instead of {\#}13{\#}10 \\
  3454. EOF{\_}CTRLZ&
  3455. A Ctrl-Z character in a text file is an EOF marker (UNIX mostly) \\
  3456. \end{longtable}
  3457. The following defines are used for fexpand definitions:
  3458. % FIXME Seem to miss a *nix symlink expand behaviour define.
  3459. \begin{longtable}{|l|p{10cm}|}
  3460. \hline
  3461. Define name & Description \\
  3462. \hline
  3463. \endhead
  3464. \hline
  3465. \endfoot
  3466. FPC{\_}EXPAND{\_}DRIVES&
  3467. Different devices with different names (as drives) are
  3468. supported \par (like DOS, Netware, etc\ldots ) \\
  3469. FPC{\_}EXPAND{\_}UNC&
  3470. Universal Naming convention support i.e \par $\backslash \backslash
  3471. < $server-name>$\backslash $<share-name>$\backslash $<directory/filename> \\
  3472. UNIX&
  3473. Unix style file names \\
  3474. FPC{\_}EXPAND{\_}VOLUMES&
  3475. Volume names (i.e. drive descriptions longer than 1
  3476. character) are supported. \\
  3477. FPC{\_}EXPAND{\_}TILDE&
  3478. Replaces the $\sim $ character, with the `HOME' directory
  3479. (mostly on UNIX platforms) \\
  3480. \end{longtable}
  3481. The following defines some debugging routines for the runtime library:
  3482. \begin{longtable}{|l|p{10cm}|}
  3483. \hline
  3484. Define Name & Description \\
  3485. \hline
  3486. \endhead
  3487. \hline
  3488. \endfoot
  3489. DEFINE NAME & Description \\
  3490. ANSISTRDEBUG & Add Debug routines for ansi string support \\
  3491. EXCDEBUG & Add Debug routines for exception debugging \\
  3492. LOGGING & Log the operations to a file \\
  3493. \end{longtable}
  3494. \subsection{Operating system hooks}
  3495. \label{subsec:operating}
  3496. This section contains information on all routines which should be hooked and
  3497. implemented to be able to compile and use the system unit for a new
  3498. operating system:
  3499. \begin{functionl}{System{\_}Exit}{systemexit}
  3500. \Declaration
  3501. Procedure System{\_}Exit;
  3502. \Description
  3503. This routine is internally called by the system unit when the application
  3504. exits.
  3505. \Notes
  3506. This routine should actually exit the application. It should exit with the
  3507. error code specified in the \textsf{ExitCode} variable.
  3508. \Algorithm
  3509. Exit application with ExitCode value.
  3510. \end{functionl}
  3511. \begin{function}{ParamCount}
  3512. \Declaration
  3513. Function ParamCount : Longint;
  3514. \Description
  3515. This routine is described in the Free Pascal reference manual.
  3516. \end{function}
  3517. \begin{procedure}{Randomize}
  3518. \Declaration
  3519. Procedure Randomize;
  3520. \Description
  3521. This routine should initialize the built-in random generator with a random value.
  3522. \Notes
  3523. This routine is used by random
  3524. \Algorithm
  3525. Randseed := pseudo random 32-bit value
  3526. \end{procedure}
  3527. \begin{function}{GetHeapStart}
  3528. \Declaration
  3529. Function GetHeapStart : Pointer;
  3530. \Description
  3531. This routine should return a pointer to the start of the heap area.
  3532. \Algorithm
  3533. GetHeapStart := address of start of heap.
  3534. \end{function}
  3535. \begin{function}{GetHeapSize}
  3536. \Declaration
  3537. Function GetHeapSize : Longint;
  3538. \Description
  3539. This routine should return the total heap size in bytes
  3540. \Algorithm
  3541. GetHeapSize := total size of the initial heap area.
  3542. \end{function}
  3543. \begin{function}{sbrk}
  3544. \Declaration
  3545. Function Sbrk(Size : Longint): Longint;
  3546. \Description
  3547. This routine should grow the heap by the number of bytes specified. If
  3548. the heap cannot be grown it should return -1, otherwise it should return
  3549. a pointer to the newly allocated area.
  3550. \Parameters
  3551. size = Number of bytes to allocate
  3552. \end{function}
  3553. \begin{procedurel}{Do{\_}Close}{doclose}
  3554. \Declaration
  3555. Procedure Do{\_}Close(Handle : Longint);
  3556. \Description
  3557. This closes the file specified of the specified handle number.
  3558. \Parameters
  3559. handle = file handle of file to close
  3560. \Notes
  3561. This routine should close the specified file.
  3562. \Notes
  3563. This routine should set InoutRes in case of error.
  3564. \end{procedurel}
  3565. \begin{procedurel}{Do{\_}Erase}{doerase}
  3566. \Declaration
  3567. Procedure Do{\_}Erase(p: pChar);
  3568. \Description
  3569. This erases the file specifed by p.
  3570. \Parameters
  3571. p = name of the file to erase
  3572. \Notes
  3573. This routine should set InoutRes in case of error.
  3574. \end{procedurel}
  3575. \begin{procedurel}{Do{\_}Truncate}{dotruncate}
  3576. \Declaration
  3577. Procedure Do{\_}Truncate(Handle, FPos : Longint);
  3578. \Description
  3579. This truncates the file at the specified position.
  3580. \Parameters
  3581. handle = file handle of file to truncate
  3582. fpos = file position where the truncate should occur
  3583. \Notes
  3584. This routine should set InoutRes in case of error.
  3585. \end{procedurel}
  3586. \begin{procedurel}{Do{\_}Rename}{dorename}
  3587. \Declaration
  3588. Procedure Do{\_}Rename(p1, p2 : pchar);
  3589. \Description
  3590. This renames the file specified.
  3591. \Parameters
  3592. p1 = old file name
  3593. p2 = new file name
  3594. \Notes
  3595. This routine should set InoutRes in case of error.
  3596. \end{procedurel}
  3597. \begin{functionl}{Do{\_}Write}{dowrite}
  3598. \Declaration
  3599. Function Do{\_}Write(Handle,Addr,Len:Longint):longint;
  3600. \Description
  3601. This writes to the specified file. Returns the number of bytes
  3602. actually written.
  3603. \Parameters
  3604. handle = file handle of file to write to
  3605. addr = address of buffer containing the data to write
  3606. len = number of bytes to write
  3607. \Notes
  3608. This routine should set InoutRes in case of error.
  3609. \end{functionl}
  3610. \begin{functionl}{Do{\_}Read}{doread}
  3611. \Declaration
  3612. Function Do{\_}Read(Handle,Addr,Len:Longint):Longint;
  3613. \Description
  3614. Reads from a file. Returns the number of bytes read.
  3615. \Parameters
  3616. handle = file handle of file to read from
  3617. addr = address of buffer containing the data to read
  3618. len = number of bytes to read
  3619. \Notes
  3620. This routine should set InoutRes in case of error.
  3621. \end{functionl}
  3622. \begin{functionl}{Do{\_}FilePos}{dofilepos}
  3623. \Declaration
  3624. function Do{\_}FilePos(Handle: Longint):longint;
  3625. \Description
  3626. Returns the file pointer position
  3627. \Parameters
  3628. handle = file handle of file to get file position on
  3629. \Notes
  3630. This routine should set InoutRes in case of error.
  3631. \end{functionl}
  3632. \begin{procedurel}{Do{\_}Seek}{doseek}
  3633. \Declaration
  3634. Procedure Do{\_}Seek(Handle,Pos:Longint);
  3635. \Description
  3636. Set file pointer of file to a new position
  3637. \Parameters
  3638. handle = file handle of file to seek in
  3639. pos = new position of file pointer (from start of file)
  3640. \Notes
  3641. This routine should set InoutRes in case of error.
  3642. \end{procedurel}
  3643. \begin{functionl}{Do{\_}Seekend}{doseekend}
  3644. \Declaration
  3645. Function Do{\_}SeekEnd(Handle:Longint): Longint;
  3646. \Description
  3647. Seeks to the end of the file. Returns the
  3648. new file pointer position.
  3649. \Parameters
  3650. handle = file handle of file to seek to end of file
  3651. \Notes
  3652. This routine should set InoutRes in case of error.
  3653. \end{functionl}
  3654. \begin{functionl}{Do{\_}FileSize}{dofilesize}
  3655. \Declaration
  3656. Function Do{\_}FileSize(Handle:Longint): Longint;
  3657. \Description
  3658. Returns the filesize in bytes.
  3659. \Parameters
  3660. handle = file handle of file to get the file size
  3661. \Notes
  3662. This routine should set InoutRes in case of error.
  3663. \end{functionl}
  3664. \begin{functionl}{Do{\_}IsDevice}{doisdevice}
  3665. \Declaration
  3666. Function Do{\_}ISDevice(Handle:Longint): boolean;
  3667. \Description
  3668. Returns TRUE if the file handle points to a device
  3669. instead of a file.
  3670. \Parameters
  3671. handle = file handle to gtet status on
  3672. \Notes
  3673. This routine should set InoutRes in case of error.
  3674. \end{functionl}
  3675. \begin{procedurel}{Do{\_}Open}{doopen}
  3676. \Declaration
  3677. Procedure Do{\_}Open(var f;p:pchar;flags:longint);
  3678. \Description
  3679. Opens a file in the specified mode, and sets the
  3680. \var{mode} and \var{handle} fields of the \var{f}
  3681. structure parameter.
  3682. \Parameters
  3683. f = pointer to \var{textrec} or \var{filerec} structure
  3684. p = name and path of file to open
  3685. flags = access mode to open the file with
  3686. \Notes
  3687. This routine should set InoutRes in case of error.
  3688. \end{procedurel}
  3689. \begin{procedurel}{ChDir}{chdir}
  3690. \Declaration
  3691. Procedure ChDir(Const s: String);[IOCheck];
  3692. \Description
  3693. Changes to the specified directory. . and ..
  3694. should also be supported by this call.
  3695. \Parameters
  3696. s = new directory to change to
  3697. \Notes
  3698. This routine should set InoutRes in case of error.
  3699. \end{procedurel}
  3700. \begin{procedurel}{MkDir}{mkdir}
  3701. \Declaration
  3702. Procedure MkDir(Const s: String);[IOCheck];
  3703. \Description
  3704. Creates the specified directory.
  3705. \Parameters
  3706. s = name of directory to create
  3707. \Notes
  3708. This routine should set InoutRes in case of error.
  3709. \end{procedurel}
  3710. \begin{procedurel}{RmDir}{rmdir}
  3711. \Declaration
  3712. Procedure RmDir(Const s: String);[IOCheck];
  3713. \Description
  3714. Removes the specified directory.
  3715. \Parameters
  3716. s = name of directory to remove
  3717. \Notes
  3718. This routine should set InoutRes in case of error.
  3719. \end{procedurel}
  3720. The following variables should also be defined for each new operating
  3721. system, they are used by external units:
  3722. \noindent
  3723. argc : The number of command line arguments of the program
  3724. \noindent
  3725. argv : A pointer to each of the command line arguments (an array of pchar
  3726. pointers)
  3727. \subsection{CPU specific hooks}
  3728. \label{subsec:mylabel9}
  3729. The following routines must absolutely be implemented for each processor, as
  3730. they are dependent on the processor:
  3731. \subsubsection{FPC{\_}SETJMP}
  3732. \label{subsubsec:mylabel30}
  3733. \begin{function}{SetJmp}
  3734. \Declaration
  3735. Function SetJmp (Var S : Jmp{\_}Buf) : Longint;
  3736. \Description
  3737. A call to SetJmp(), saves the calling environment in its \textsf{s} argument
  3738. for later use by \textsf{longjmp()}. Called by the code generator in
  3739. exception handling code. The return value should be zero.
  3740. \Notes
  3741. This routine should save / restore all used registers (except the
  3742. accumulator which should be cleared).
  3743. \end{function}
  3744. \subsubsection{FPC{\_}LONGJMP}
  3745. \label{subsubsec:mylabel31}
  3746. \subsubsection{function SPtr()}
  3747. \label{subsubsec:function}
  3748. \subsubsection{function Get{\_}Caller{\_}Frame(framebp:longint):longint;}
  3749. \label{subsubsec:mylabel32}
  3750. \subsubsection{function Get{\_}Caller{\_}Addr(framebp:longint):longint;}
  3751. \label{subsubsec:mylabel33}
  3752. \subsubsection{function Get{\_}Frame:longint;}
  3753. \label{subsubsec:mylabel34}
  3754. \subsubsection{function Trunc()}
  3755. \label{subsubsec:mylabel35}
  3756. \subsection{String related}
  3757. \label{subsec:string}
  3758. \subsubsection{FPC{\_}SHORTSTR{\_}COPY}
  3759. \label{subsubsec:mylabel36}
  3760. \begin{procedurel}{Int{\_}StrCopy}{intstrcopy}
  3761. \Declaration
  3762. Procedure Int{\_}StrCopy(Len:Longint;SStr,DStr:pointer);
  3763. \Description
  3764. This routine copies the string pointed to by the address in sstr, to the
  3765. string pointed in the destination. The old string is overwritten, and the
  3766. source string will be truncated to make it fit in destination if the length
  3767. of the source is greater then destination string len (the len parameter).
  3768. \Parameters
  3769. Len = maximum length to copy (the destination string length) \par
  3770. SStr = pointer to source shortstring \par
  3771. DStr = point to destination shortstring
  3772. \Notes
  3773. Called by code generator when a string is assigned to another string.
  3774. \end{procedurel}
  3775. \subsubsection{FPC{\_}SHORTSTR{\_}COMPARE}
  3776. \label{subsubsec:mylabel37}
  3777. \begin{functionl}{Int{\_}StrCmp}{intstrcmp}
  3778. \Declaration
  3779. Function Int{\_}StrCmp(DStr,SStr:Pointer) : Longint;
  3780. \Description
  3781. The routine compares two shortstrings, and returns 0 if both are equal, 1 if
  3782. \textsf{DStr} is greater then \textsf{SSrc}, otherwise it returns --1.
  3783. \Notes
  3784. Both pointers must point to shortstrings. Length checking must be performed
  3785. in the routine.
  3786. \end{functionl}
  3787. \subsubsection{FPC{\_}SHORTSTR{\_}CONCAT}
  3788. \label{subsubsec:mylabel38}
  3789. \begin{procedurel}{Int{\_}StrConcat}{intstrconcat}
  3790. \Declaration
  3791. Procedure Int{\_}StrConcat(Src,Dest:Pointer);
  3792. \Description
  3793. This routine appends the string pointed to by \textsf{Src} to the end of the
  3794. string pointed to by \textsf{Dest}.
  3795. \Parameters
  3796. Src = pointer to shortstring to append to dest \par
  3797. Dest = pointer to shortstring to receive appended string
  3798. \Notes
  3799. Both pointers must point to shortstrings. In the case where the src string
  3800. length does not fit in dest, it is truncated.
  3801. \Algorithm
  3802. \begin{lstlisting}{}
  3803. if src =nil or dest = nil then
  3804. exit routine;
  3805. if (src string length + dest string length) > 255 then
  3806. number of bytes to copy = 255 -- dest string length
  3807. else
  3808. number of bytes to copy = src string length;
  3809. copy the string data (except the length byte)
  3810. dest string length = dest string length + number of bytes to copied
  3811. \end{lstlisting}
  3812. \end{procedurel}
  3813. \subsubsection{FPC{\_}ANSISTR{\_}CONCAT}
  3814. \label{subsubsec:mylabel39}
  3815. \begin{procedurel}{AnsiStr{\_}Concat}{ansistrconcat}
  3816. \Declaration
  3817. Procedure AnsiStr{\_}Concat(s1,s2:Pointer;var s3:Pointer);
  3818. \Description
  3819. This routine appends \textsf{s1}+\textsf{s2} and stores the result at the
  3820. address pointed to by \textsf{s3}.
  3821. \Notes
  3822. All pointers must point to ansistrings.
  3823. \end{procedurel}
  3824. \subsubsection{FPC{\_}ANSISTR{\_}COMPARE}
  3825. \label{subsubsec:mylabel40}
  3826. \begin{functionl}{AnsiStr{\_}Compare}{ansistrcompare}
  3827. \Declaration
  3828. Function AnsiStr{\_}Compare(s1,s2 : Pointer): Longint;
  3829. \Description
  3830. The routine compares two ansistrings, and returns 0 if both are equal, 1 if
  3831. \textsf{s1} is greater then \textsf{s2}, otherwise it returns --1.
  3832. \Parameters
  3833. Both pointers must point to ansistrings.
  3834. \end{functionl}
  3835. \subsubsection{FPC{\_}ANSISTR{\_}INCR{\_}REF }
  3836. \label{subsubsec:mylabel41}
  3837. \begin{procedurel}{AnsiStr{\_}Incr{\_}Ref}{ansistrincrref}
  3838. \Declaration
  3839. procedure AnsiStr{\_}Incr{\_}Ref (var s : Pointer);
  3840. \Description
  3841. This routine simply increments the ANSI string reference count, which is
  3842. used for garbage collection of ANSI strings.
  3843. \Parameters
  3844. s = pointer to the ansi string (including the header structure)
  3845. \end{procedurel}
  3846. \subsubsection{FPC{\_}ANSISTR{\_}DECR{\_}REF }
  3847. \label{subsubsec:mylabel42}
  3848. \begin{procedurel}{AnsiStr{\_}Decr{\_}Ref}{ansistrdecrref}
  3849. \Declaration
  3850. procedure AnsiStr{\_}Decr{\_}Ref (Var S : Pointer);
  3851. \Parameters
  3852. s = pointer to the ansi string (including the header structure)
  3853. \Algorithm
  3854. Decreases the internal reference count of this non constant ansistring; If
  3855. the reference count is zero, the string is deallocated from the
  3856. heap.
  3857. \end{procedurel}
  3858. \subsubsection{FPC{\_}ANSISTR{\_}ASSIGN }
  3859. \label{subsubsec:mylabel43}
  3860. \begin{functionl}{AnsiStr{\_}Assign}{ansistrassign}
  3861. \Declaration
  3862. Procedure AnsiStr{\_}Assign (var s1 : Pointer;s2 : Pointer);
  3863. \Parameters
  3864. s1 = address of ANSI string to be assigned to \par
  3865. s2 = address of ANSI string which will be assigned
  3866. \Algorithm
  3867. Assigns S2 to S1 (S1:=S2), also by the time decreasing the reference count
  3868. to S1 (it is no longer used by this variable).
  3869. \end{functionl}
  3870. \subsubsection{FPC{\_}PCHAR{\_}TO{\_}SHORTSTR}
  3871. \label{subsubsec:mylabel44}
  3872. \begin{function}{StrPas}
  3873. \Declaration
  3874. Function StrPas(p:pChar):ShortString;
  3875. \Description
  3876. Copies and converts a null-terminated string (pchar) to a shortstring with
  3877. length checking.
  3878. \Parameters
  3879. p = pointer to null terminated string to copy
  3880. \Notes
  3881. Length checking is performed. Verifies also p=nil, and if so sets the
  3882. shortstring length to zero. Called by the type conversion generated code of
  3883. code generator.
  3884. \Algorithm
  3885. \begin{lstlisting}{}
  3886. if p=nil then
  3887. string length =0
  3888. else
  3889. string length =string length(p)
  3890. if string length>255 then
  3891. string length = 255
  3892. if string length>0 then
  3893. Copy all characters of pchar array to string (except length byte)
  3894. \end{lstlisting}
  3895. \end{function}
  3896. \subsubsection{FPC{\_}SHORTSTR{\_}TO{\_}ANSISTR}
  3897. \label{subsubsec:mylabel45}
  3898. \begin{functionl}{FPC{\_}ShortStr{\_}To{\_}AnsiStr}{fpcshortstrtoansistr}
  3899. \Notes
  3900. Called by the type conversion generated code of code generator.
  3901. \end{functionl}
  3902. \subsubsection{FPC{\_}STR{\_}TO{\_}CHARARRAY}
  3903. \label{subsubsec:mylabel46}
  3904. \begin{procedurel}{Str{\_}To{\_}CharArray}{strtochararray}
  3905. \Declaration
  3906. procedure Str{\_}To{\_}CharArray(StrTyp, ArraySize: Longint; src,dest: pChar);
  3907. \Description
  3908. 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.
  3909. \Parameters
  3910. strtyp = Indicates the conversion type to do (0 = shortstring, 1 =
  3911. ansistring, 2 = longstring, 3 = widestring) \\
  3912. arraysize = size of the destination array \par
  3913. src = pointer to source string \par
  3914. dest = pointer to character array
  3915. \Notes
  3916. Called by the type conversion generated code of code generator when
  3917. converting a string to an array of char. If the size of the string is less
  3918. then the size of the array, the rest of the array is filled with zeros.
  3919. \end{procedurel}
  3920. \subsubsection{FPC{\_}CHARARRAY{\_}TO{\_}SHORTSTR}
  3921. \label{subsubsec:mylabel47}
  3922. \begin{function}{StrCharArray}
  3923. \Declaration
  3924. Function StrCharArray(p:pChar; l : Longint):ShortString;
  3925. \Description
  3926. Copies a character array to a shortstring with length checking (upto 255
  3927. characters are copied)
  3928. \Parameters
  3929. p = Character array pointer \par
  3930. l = size of the array
  3931. \Notes
  3932. Called by the type conversion generated code of code generator when
  3933. converting an array of char to a shortstring.
  3934. \Algorithm
  3935. \begin{lstlisting}{}
  3936. if size of array >= 256 then
  3937. length of string =255
  3938. else
  3939. if size of array < 0 then
  3940. length of string = 0
  3941. else
  3942. length of string = size of array
  3943. Copy all characters from array to shortstring
  3944. \end{lstlisting}
  3945. \end{function}
  3946. \subsubsection{FPC{\_}CHARARRAY{\_}TO{\_}ANSISTR}
  3947. \label{subsubsec:mylabel48}
  3948. \begin{functionl}{Fpc{\_}Chararray{\_}To{\_}AnsiStr}{chararraytoansistr}
  3949. \Notes
  3950. Called by the type conversion generated code of code generator when converting an array of char to an ansistring.
  3951. \end{functionl}
  3952. \subsubsection{FPC{\_}CHAR{\_}TO{\_}ANSISTR}
  3953. \label{subsubsec:mylabel49}
  3954. \begin{functionl}{Fpc{\_}Char{\_}To{\_}AnsiStr}{fpcchartoansistr}
  3955. \Notes
  3956. Called by the type conversion generated code of code generator when
  3957. converting a char to an ansistring.
  3958. \end{functionl}
  3959. \subsubsection{FPC{\_}PCHAR{\_}TO{\_}ANSISTR}
  3960. \label{subsubsec:mylabel50}
  3961. \begin{functionl}{Fpc{\_}pChar{\_}To{\_}AnsiStr}{fpcpchartoansistr}
  3962. \Notes
  3963. Called by the type conversion generated code of code generator when
  3964. converting a pchar to an ansistring.
  3965. \end{functionl}
  3966. \subsection{Compiler runtime checking}
  3967. \label{subsec:compiler}
  3968. \subsubsection{FPC{\_}STACKCHECK}
  3969. \label{subsubsec:mylabel51}
  3970. \begin{procedurel}{Int{\_}StackCheck}{intstackcheck}
  3971. \Declaration
  3972. procedure int{\_}stackcheck (stack{\_}size:longint);
  3973. \Description
  3974. This routine is used to check if there will be a stack overflow when trying
  3975. to allocate stack space from the operating system. The routine must preserve
  3976. all registers. In the case the stack limit is reached, the routine calls the
  3977. appropriate error handler.
  3978. \Parameters
  3979. stack{\_}size = The amount of stack we wish to allocate
  3980. \Notes
  3981. Inserted in the entry code of a routine in the {\{}{\$}S+{\}} state by the code generator
  3982. \Algorithm
  3983. \begin{lstlisting}{}
  3984. if ((StackPointer - stack_size) < System.StackLimit) then
  3985. Throw a Runtime error with error code 202 (stack overflow)
  3986. \end{lstlisting}
  3987. \end{procedurel}
  3988. \subsubsection{FPC{\_}RANGEERROR}
  3989. \label{subsubsec:mylabel52}
  3990. \begin{procedurel}{Int{\_}RangeError}{intrangerror}
  3991. \Declaration
  3992. procedure Int{\_}RangeError;
  3993. \Description
  3994. This routine is called when a range check error is detected when executing
  3995. the compiled code. This usually simply calls the default error handler, with
  3996. the correct runtime error code to produce.
  3997. \Parameters
  3998. Inserted in code generator when a Runtime error 201 {\{}{\$}R+{\}} should be
  3999. generated
  4000. \end{procedurel}
  4001. \subsubsection{FPC{\_}BOUNDCHECK}
  4002. \label{subsubsec:mylabel53}
  4003. \begin{procedurel}{Int{\_}BoundCheck}{intboundcheck}
  4004. \Declaration
  4005. procedure Int{\_}BoundCheck(l : Longint; Range : Pointer);
  4006. \Description
  4007. This routine is called at runtime in {\$}R+ mode to check if accessing
  4008. indexes in a string or array is out of bounds. In this case, the default
  4009. error handler is called, with the correct runtime error code to produce.
  4010. \Parameters
  4011. l = Index we need to check \par
  4012. range = pointer to a structure containing the minimum and maximum allowed
  4013. indexes (points to two 32-bit signed values which are the limits of the
  4014. array to verify).
  4015. \Notes
  4016. Inserted in the generated code after assignments, and array indexing to
  4017. verify if the result of operands is within range (in the {\{}{\$}R+{\}}
  4018. state)
  4019. \end{procedurel}
  4020. \subsubsection{FPC{\_}OVERFLOW}
  4021. \label{subsubsec:mylabel54}
  4022. \begin{procedurel}{Int{\_}OverFlow}{intoverflow}
  4023. \Declaration
  4024. procedure Int{\_}OverFlow;
  4025. \Description
  4026. This routine is called when an overflow is detected when executing the
  4027. compiled code. This usually simply calls the default error handler, with the
  4028. correct runtime error code to produce.
  4029. \Parameters
  4030. Inserted in code generator when a Runtime error 215 {\{}{\$}Q+{\}} should be
  4031. generated.
  4032. \end{procedurel}
  4033. \subsubsection{FPC{\_}CHECK{\_}OBJECT}
  4034. \label{subsubsec:mylabel55}
  4035. \begin{procedurel}{Int{\_}Check{\_}Object}{intcheckobject}
  4036. \Declaration
  4037. procedure Int{\_}Check{\_}Object(vmt : Pointer);
  4038. \Description
  4039. This routine is called at runtime in the {\$}R+ state each time a virtual
  4040. method is called. It verifies that the object constructor has been called
  4041. first to build the VMT of the object, otherwise it throws an Runtime error 210.
  4042. \Parameters
  4043. vmt = Current value of the SELF register
  4044. \Notes
  4045. Call inserted by the code generator before calling the virtual method. This
  4046. routine should save / restore all used registers.
  4047. \Algorithm
  4048. \begin{lstlisting}{}
  4049. if vmt = nil or size of method table =0 then
  4050. Throw a Runtime error with error code 210 (object not initialized)
  4051. \end{lstlisting}
  4052. \end{procedurel}
  4053. \subsubsection{FPC{\_}CHECK{\_}OBJECT{\_}EXT}
  4054. \label{subsubsec:mylabel56}
  4055. \begin{procedurel}{Int{\_}Check{\_}Object{\_}Ext}{intcheckobjectext}
  4056. \Declaration
  4057. procedure Int{\_}Check{\_}Object{\_}Ext(vmt, expvmt : pointer);
  4058. \Description
  4059. 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 220.
  4060. \Parameters
  4061. vmt = Current value of the SELF register \par
  4062. expvmt = Pointer to TRUE object definition
  4063. \Notes
  4064. Call inserted by the code generator before calling the virtual method. \par
  4065. This routine should save / restore all used registers.
  4066. \Algorithm
  4067. \begin{lstlisting}{}
  4068. if vmt = nil or size of method table =0 then
  4069. Throw a Runtime error with error code 210 (object not initialized)
  4070. Repeat
  4071. If SELF (VMT) <> VMT Address (expvmt) Then
  4072. Get Parent VMT Address
  4073. Else
  4074. Exit;
  4075. until no more ent;
  4076. Throw a Runtime error with error code 220 (Incorrect object reference)
  4077. \end{lstlisting}
  4078. \end{procedurel}
  4079. \subsubsection{FPC{\_}IO{\_}CHECK}
  4080. \label{subsubsec:mylabel57}
  4081. \begin{procedurel}{Int{\_}IOCheck}{intiocheck}
  4082. \Declaration
  4083. procedure Int{\_}IOCheck(addr : longint);
  4084. \Description
  4085. This routine is called after an I/O operation to verify the success of the
  4086. operation when the code is compiled in the {\$}I+ state.
  4087. \Parameters
  4088. addr = currently unused
  4089. \Algorithm
  4090. Check last I/O was successful, if not call error handler.
  4091. \end{procedurel}
  4092. \subsubsection{FPC{\_}HANDLEERROR}
  4093. \label{subsubsec:mylabel58}
  4094. \begin{procedure}{HandleError}
  4095. \Declaration
  4096. procedure HandleError (Errno : longint);
  4097. \Description
  4098. This routine should be called to generate a runtime error either from one of
  4099. the system unit routines or the code generator.
  4100. \Parameters
  4101. Errno = Runtime error to generate
  4102. \Notes
  4103. This routine calls the appropriate existing error handler with the specified
  4104. error code.
  4105. \Algorithm
  4106. \end{procedure}
  4107. \subsubsection{FPC{\_}ASSERT}
  4108. \label{subsubsec:mylabel59}
  4109. \begin{procedurel}{Int{\_}Assert}{intassert}
  4110. \Declaration
  4111. procedure Int{\_}Assert(Const Msg,FName:Shortstring;LineNo,ErrorAddr:Longint);
  4112. \Description
  4113. This routine is called by the code generator in an assert statement. When
  4114. the assertion fails, this routine is called.
  4115. \Parameters
  4116. msg = string to print \par
  4117. Fname = Current filename of source \par
  4118. LineNo = Current line number of source \par
  4119. ErrorAddr = Address of assertion failure
  4120. \end{procedurel}
  4121. \subsection{Exception handling}
  4122. \label{subsec:exception}
  4123. \subsubsection{FPC{\_}RAISEEXCEPTION}
  4124. \label{subsubsec:mylabel60}
  4125. \begin{function}{RaiseExcept}
  4126. \Declaration
  4127. function RaiseExcept (Obj : Tobject; AnAddr,AFrame : Pointer) : Tobject;
  4128. \Description
  4129. Called by the code generator in the raise statement to raise an exception.
  4130. \Parameters
  4131. Obj = Instance of class exception handler \par
  4132. AnAddr = Address of exception \par
  4133. Aframe = Exception frame address
  4134. \Notes
  4135. REGISTERS NOT SAVED???????????
  4136. \end{function}
  4137. \subsubsection{FPC{\_}PUSHEXCEPTADDR}
  4138. \label{subsubsec:mylabel61}
  4139. \begin{function}{PushExceptAddr}
  4140. \Declaration
  4141. function PushExceptAddr (Ft: Longint): PJmp{\_}buf ;
  4142. \Description
  4143. This routine should be called to save the current caller context to be used
  4144. for exception handling, usually called in the context where ANSI strings are
  4145. used (they can raise exceptions), or in a try..finally or on statements to
  4146. save the current context.
  4147. \Parameters
  4148. Ft = Indicates the frame type on the stack (1= Exception frame or 2=Finalize
  4149. frame)
  4150. \Algorithm
  4151. Adds this item to the linked list of stack frame context information saved.
  4152. Allocates a buffer for the jump statement and returns it.
  4153. \end{function}
  4154. \subsubsection{FPC{\_}RERAISE}
  4155. \label{subsubsec:mylabel62}
  4156. \begin{procedure}{ReRaise}
  4157. \Declaration
  4158. procedure ReRaise;
  4159. \Notes
  4160. REGISTERS NOT SAVED???????????
  4161. \end{procedure}
  4162. \subsubsection{FPC{\_}POPOBJECTSTACK}
  4163. \label{subsubsec:mylabel63}
  4164. \begin{function}{PopObjectStack}
  4165. \Declaration
  4166. function PopObjectStack : TObject;
  4167. \Description
  4168. This is called by the code generator when an exception occurs, it is used to
  4169. retrieve the exception handler object from the context information.
  4170. \Notes
  4171. REGISTERS NOT SAVED???????????
  4172. \end{function}
  4173. \subsubsection{FPC{\_}POPSECONDOBJECTSTACK}
  4174. \label{subsubsec:mylabel64}
  4175. \begin{function}{PopSecondObjectStack}
  4176. \Declaration
  4177. function PopSecondObjectStack : TObject;
  4178. \Description
  4179. This is called by the code generator when a double exception occurs, it is
  4180. used to retrieve the second exception handler object from the context
  4181. information.
  4182. \Notes
  4183. REGISTERS NOT SAVED???????????
  4184. \end{function}
  4185. \subsubsection{FPC{\_}DESTROYEXCEPTION}
  4186. \label{subsubsec:mylabel65}
  4187. \begin{procedure}{DestroyException}
  4188. \Declaration
  4189. Procedure DestroyException(o : TObject);
  4190. \Description
  4191. This routine is called by the code generator after the exception handling
  4192. code is complete to destroy the exception object.
  4193. \Parameters
  4194. o = Exception handler object reference
  4195. \Notes
  4196. REGISTERS NOT SAVED?????????????
  4197. \end{procedure}
  4198. \subsubsection{FPC{\_}POPADDRSTACK}
  4199. \label{subsubsec:mylabel66}
  4200. \begin{procedure}{PopAddrStack}
  4201. \Declaration
  4202. procedure PopAddrStack;
  4203. \Description
  4204. Called by the code generator in the finally part of a try statement to
  4205. restore the stackframe and dispose of all the saved context information.
  4206. \Notes
  4207. REGISTERS NOT SAVED??????????
  4208. \end{procedure}
  4209. \subsubsection{FPC{\_}CATCHES}
  4210. \label{subsubsec:mylabel67}
  4211. \begin{function}{Catches}
  4212. \Declaration
  4213. function Catches(Objtype : TExceptObjectClass) : TObject;
  4214. \Description
  4215. This routine is called by the code generator to get the exception handler
  4216. object. ?????????????????
  4217. \Parameters
  4218. ObjType = The exception type class
  4219. \Notes
  4220. REGISTERS NOT SAVED??????????
  4221. \end{function}
  4222. \subsubsection{FPC{\_}GETRESOURCESTRING}
  4223. \label{subsubsec:mylabel68}
  4224. \begin{function}{GetResourceString}
  4225. \Declaration
  4226. function GetResourceString(Const TheTable: TResourceStringTable;Index : longint) : AnsiString;
  4227. \Description
  4228. Called by code generator when a reference to a resource string is made. This
  4229. routine loads the correct string from the resource string section and
  4230. returns the found string (or `' if not found).
  4231. \Parameters
  4232. TheTable = pointer to the resource string table \par
  4233. Index = Index in the resource string table.
  4234. \end{function}
  4235. \subsection{Runtime type information}
  4236. \label{subsec:runtime}
  4237. \subsubsection{FPC{\_}DO{\_}IS}
  4238. \label{subsubsec:mylabel69}
  4239. \begin{functionl}{Int{\_}Do{\_}Is}{intdois}
  4240. \Declaration
  4241. Function Int{\_}Do{\_}Is(AClass : TClass;AObject : TObject) : Boolean;
  4242. \Description
  4243. If \textsf{aclass} is of type \textsf{aobject}, returns TRUE otherwise
  4244. returns FALSE.
  4245. \Parameters
  4246. aclass = class type reference \par
  4247. aobject = Object instance to compare against
  4248. \Notes
  4249. This is called by the code generator when the \textsf{is} operator is used.
  4250. \Algorithm
  4251. \end{functionl}
  4252. \subsubsection{FPC{\_}DO{\_}AS}
  4253. \label{subsubsec:mylabel70}
  4254. \begin{procedurel}{Int{\_}Do{\_}As}{intdoas}
  4255. \Declaration
  4256. Procedure Int{\_}Do{\_}As(AClass : TClass;AObject : TObject)
  4257. \Description
  4258. Typecasts \textsf{aclass} as \textsf{aobject}, with dynamic type checking.
  4259. If the object is not from the correct type class, a runtime error 219 is
  4260. generated. Called by the code generator for the \textsf{as} statement.
  4261. \Parameters
  4262. aclass = Class to typecast to \par
  4263. aobject = Object to typecast
  4264. \end{procedurel}
  4265. \subsubsection{FPC{\_}INITIALIZE }
  4266. \label{subsubsec:mylabel71}
  4267. \begin{procedure}{Initialize}
  4268. \Declaration
  4269. Procedure Initialize (Data,TypeInfo : Pointer);
  4270. \Description
  4271. \Parameters
  4272. data = pointer to the data to initialize \par
  4273. typeinfo = pointer to the type information for this data
  4274. \Notes
  4275. This routine should save / restore all used registers.
  4276. \Algorithm
  4277. Initializes the class data for runtime typed values
  4278. \end{procedure}
  4279. \subsubsection{FPC{\_}FINALIZE}
  4280. \label{subsubsec:mylabel72}
  4281. \begin{procedure}{Finalize}
  4282. \Declaration
  4283. procedure Finalize (Data,TypeInfo: Pointer);
  4284. \Description
  4285. Called by code generator if and only if the reference to finalize <> nil.
  4286. \Parameters
  4287. data = point to the data to finalize \par
  4288. typeinfo = Pointer to the type information of this data
  4289. \Notes
  4290. This routine should save / restore all used registers. Finalizes and frees
  4291. the heap class data for runtime typed values (decrements the reference
  4292. count)
  4293. \end{procedure}
  4294. \subsubsection{FPC{\_}ADDREF}
  4295. \label{subsubsec:mylabel73}
  4296. \begin{procedure}{AddRef}
  4297. \Declaration
  4298. Procedure AddRef (Data,TypeInfo : Pointer);
  4299. \Description
  4300. Called by the code generator for class parameters (property support) of type
  4301. const or value in parameters, to increment the reference count of ANSI
  4302. strings.
  4303. \Notes
  4304. This routine should save / restore all used registers. This routine can be
  4305. called recursively with a very deep nesting level, an assembler
  4306. implementation in suggested.
  4307. \end{procedure}
  4308. \subsubsection{FPC{\_}DECREF}
  4309. \label{subsubsec:mylabel74}
  4310. \begin{procedure}{DecRef}
  4311. \Declaration
  4312. Procedure DecRef (Data, TypeInfo : Pointer);
  4313. \Description
  4314. Called by the code generator for class parameters (property support) of type
  4315. const or value parameters, to decrement the reference count. of ANSI
  4316. strings.
  4317. \Parameters
  4318. \Notes
  4319. This routine should save / restore all used registers. This routine can be
  4320. called recursively with a very deep nesting level, an assembler
  4321. implementation in suggested.
  4322. \end{procedure}
  4323. \subsection{Memory related}
  4324. \label{subsec:memory}
  4325. \subsubsection{FPC{\_}GETMEM}
  4326. \label{subsubsec:mylabel75}
  4327. \begin{procedure}{GetMem}
  4328. \Declaration
  4329. procedure GetMem(Var p:Pointer;Size:Longint);
  4330. \end{procedure}
  4331. \subsubsection{FPC{\_}FREEMEM}
  4332. \label{subsubsec:mylabel76}
  4333. \begin{procedure}{FreeMem}
  4334. \Declaration
  4335. Procedure FreeMem(Var P:Pointer;Size:Longint);
  4336. \end{procedure}
  4337. \subsubsection{FPC{\_}CHECKPOINTER}
  4338. \label{subsubsec:mylabel77}
  4339. \begin{function}{CheckPointer}
  4340. \Declaration
  4341. Procedure CheckPointer(p : Pointer);
  4342. \Description
  4343. Called by the code generator when a pointer is referenced in heap debug
  4344. mode. Verifies that the pointer actually points in the heap area.
  4345. \Parameters
  4346. p = pointer to check
  4347. \Notes
  4348. This routine should save /restore all used registers.
  4349. \end{function}
  4350. \subsubsection{FPC{\_}DO{\_}EXIT}
  4351. \label{subsubsec:mylabel78}
  4352. \begin{procedurel}{Do{\_}Exit}{doexit}
  4353. \Declaration
  4354. procedure Do{\_}Exit;
  4355. \Description
  4356. Called by code generator at the end of the program entry point.
  4357. \Notes
  4358. Called to terminate the program
  4359. \Algorithm
  4360. Call all unit exit handlers. \par
  4361. Finalize all units which have a finalization section \par
  4362. Print runtime error in case of error\par
  4363. Call OS-dependant system{\_}exit routine
  4364. \end{procedurel}
  4365. \subsubsection{FPC{\_}ABSTRACTERROR}
  4366. \label{subsubsec:mylabel79}
  4367. \begin{function}{AbstractError}
  4368. \Declaration
  4369. procedure AbstractError;
  4370. \Description
  4371. The code generator allocates a VMT entry equal to this routine address when
  4372. a method of a class is declared as being abstract. This routine simply calls
  4373. the default error handler.
  4374. \Algorithm
  4375. Throw a Runtime error with error code 211 (Abstract call)
  4376. \end{function}
  4377. \subsubsection{FPC{\_}INITIALIZEUNITS}
  4378. \label{subsubsec:mylabel80}
  4379. \begin{function}{InitializeUnits}
  4380. \Declaration
  4381. \Description
  4382. Called by the code generator in the main program, this is only available if
  4383. an \textsf{initialization} section exists in one of the units used by the
  4384. program.
  4385. \end{function}
  4386. \subsubsection{FPC{\_}NEW{\_}CLASS (assembler)}
  4387. \label{subsubsec:mylabel81}
  4388. \begin{procedurel}{int{\_}new{\_}class}{intnewclass}
  4389. \Description
  4390. This routine will call the TObject.InitInstance() routine to
  4391. instantiate a class (Delphi-styled class) and allocate the memory for all
  4392. fields of the class.
  4393. On entry the self{\_}register should be valid, and should point either to
  4394. nil, for a non-initialized class, or to the current instance of the class.
  4395. The first parameter on the top of the stack should be a pointer to the VMT
  4396. table for this class(????).
  4397. \end{procedurel}
  4398. \subsubsection{FPC{\_}HELP{\_}DESTRUCTOR}
  4399. \label{subsubsec:mylabel82}
  4400. Could be implemented in ASM directly with register parameter passing.
  4401. \begin{procedurel}{Int{\_}Help{\_}Destructor}{inthelpdestructor}
  4402. \Declaration
  4403. Procedure Int{\_}Help{\_}Destructor(Var {\_}Self : Pointer; Vmt : Pointer; Vmt{\_}Pos : Cardinal);
  4404. \Description
  4405. Frees the memory allocated for the object fields, and if the object had a
  4406. VMT field, sets it to nil.
  4407. \Parameters
  4408. self = pointer to the object field image in memory \par
  4409. vmt = pointer to the the actual vmt table (used to get the size of the object) \par
  4410. vmt{\_}pos = offset in the object field image to the vmt pointer field
  4411. \Notes
  4412. This routine should / save restore all used registers.
  4413. \Algorithm
  4414. \begin{lstlisting}{}
  4415. if self = nil then
  4416. exit
  4417. set VMT field in object field image ,if present, to nil
  4418. Free the allocated heap memory for the field objects
  4419. set Self = nil
  4420. \end{lstlisting}
  4421. \end{procedurel}
  4422. \subsubsection{FPC{\_}HELP{\_}CONSTRUCTOR}
  4423. \label{subsubsec:mylabel83}
  4424. Could be implemented in ASM directly with register parameter passing.
  4425. \begin{functionl}{Int{\_}Help{\_}Constructor}{inthelpconstructor}
  4426. \Declaration
  4427. function Int{\_}Help{\_}Constructor(Var {\_}self : Pointer; Var VMT : Pointer; Vmt{\_}Pos : Cardinal):Pointer;
  4428. \Description
  4429. Allocates the memory for an object's field, and fills the object fields with
  4430. zeros. Returns the newly allocated self{\_}pointer
  4431. \Parameters
  4432. self = pointer to the object field image in memory \par
  4433. vmt = pointer to the the actual vmt table (used to get the size of the object) \par
  4434. vmt{\_}pos = offset in the object field image to the vmt pointer field
  4435. \Notes
  4436. The self{\_}pointer register should be set appropriately by the code
  4437. generator to the allocated memory (self parameter)
  4438. \Algorithm
  4439. Self = Allocate Memory block for object fields \par
  4440. Fill the object field image with zeros\par
  4441. Set the VMT field in allocated object to VMT pointer
  4442. \end{functionl}
  4443. \subsubsection{FPC{\_}HELP{\_}FAIL{\_}CLASS}
  4444. \label{subsubsec:mylabel84}
  4445. \begin{functionl}{Help{\_}Fail{\_}Class}{inthelpfileclass}
  4446. \Description
  4447. Inserted by code generator after constructor call. If the constructor failed
  4448. to allocate the memory for its fields, this routine will be called.
  4449. \end{functionl}
  4450. \subsubsection{FPC{\_}HELP{\_}FAIL}
  4451. \label{subsubsec:mylabel85}
  4452. \begin{functionl}{Help{\_}Fail}{HelpFail}
  4453. \Description
  4454. Inserted by code generator after constructor call. If the constructor failed
  4455. to allocate the memory for its fields, this routine will be called.
  4456. \end{functionl}
  4457. \subsection{Set handling}
  4458. \label{subsec:mylabel10}
  4459. \subsubsection{FPC{\_}SET{\_}COMP{\_}SETS}
  4460. \label{subsubsec:mylabel86}
  4461. \begin{functionl}{Do{\_}Comp{\_}Sets}{docompsets}
  4462. \Declaration
  4463. function Do{\_}Comp{\_}Sets(Set1,Set2 : Pointer): Boolean;
  4464. \Description
  4465. This routine compares if set1 and set2 are exactly equal and returns 1 if
  4466. so, otherwise it returns false.
  4467. \Parameters
  4468. set1 = Pointer to 32 byte set to compare \par
  4469. set2 = Pointer to 32 byte set to compare
  4470. \Notes
  4471. Both pointers must point to normal sets.
  4472. \end{functionl}
  4473. \subsubsection{FPC{\_}SET{\_}CONTAINS{\_}SET}
  4474. \label{subsubsec:mylabel87}
  4475. \begin{procedurel}{Do{\_}Contains{\_}Sets}{docontainssets}
  4476. \Declaration
  4477. Procedure Do{\_}Contains{\_}Sets(Set1,Set2 : Pointer): Boolean;
  4478. \Description
  4479. Returns 1 if set2 contains set1 (That is all elements of set2 are in set1).
  4480. \Parameters
  4481. set1 = Pointer to 32 byte set to verify \par
  4482. set2 = Pointer to 32 byte set to verify
  4483. \Notes
  4484. Both pointers must point to normal sets.
  4485. \end{procedurel}
  4486. \subsubsection{FPC{\_}SET{\_}CREATE{\_}ELEMENT}
  4487. \label{subsubsec:mylabel88}
  4488. \begin{procedurel}{Do{\_}Create{\_}Element}{docreateelement}
  4489. \Declaration
  4490. procedure Do{\_}Create{\_}Element(p : Pointer; b : Byte);
  4491. \Description
  4492. Create a new normal set in the area pointed to by \textsf{p} and add the
  4493. element value \textsf{b} in that set.
  4494. \Parameters
  4495. p = pointer to area where the 32 byte set will be created \par
  4496. b = bit value within that set which must be set
  4497. \Notes
  4498. This works on normal sets only.
  4499. \Algorithm
  4500. Zero the area pointed to by p \par
  4501. Set the bit number b to 1
  4502. \end{procedurel}
  4503. \subsubsection{FPC{\_}SET{\_}SET{\_}RANGE}
  4504. \label{subsubsec:mylabel89}
  4505. \begin{procedurel}{Do{\_}Set{\_}Range}{dosetrange}
  4506. \Declaration
  4507. Procedure Do{\_}Set{\_}Range(P : Pointer;l,h : Byte);
  4508. \Description
  4509. Sets the bit values within the \textsf{l} and \textsf{h }bit ranges in the
  4510. normal set pointed to by \textsf{p}
  4511. \Parameters
  4512. p = pointer to area where the 32 bytes of the set will be updated \par
  4513. l = low bit number value to set \par
  4514. h = high bit number value to set
  4515. \Notes
  4516. This works on normal sets only.
  4517. \Algorithm
  4518. Set all bit numbers from l to h in set p
  4519. \end{procedurel}
  4520. \subsubsection{FPC{\_}SET{\_}SET{\_}BYTE}
  4521. \label{subsubsec:mylabel90}
  4522. \begin{procedurel}{Do{\_}Set{\_}Byte}{dosetbyte}
  4523. \Declaration
  4524. procedure Do{\_}Set{\_}Byte(P : Pointer;B : byte);
  4525. \Description
  4526. Add the element \textsf{b} in the normal set pointed to by \textsf{p}
  4527. \Parameters
  4528. p = pointer to 32 byte set \par
  4529. b = bit number to set
  4530. \Notes
  4531. This works on normal sets only. The intel 80386 version of the compiler does
  4532. not save the used registers, therefore, in that case, it must be done in the
  4533. routine itself.
  4534. \Algorithm
  4535. Set bit number b in p
  4536. \end{procedurel}
  4537. \subsubsection{FPC{\_}SET{\_}SUB{\_}SETS}
  4538. \label{subsubsec:mylabel91}
  4539. \begin{procedurel}{Do{\_}Sub{\_}Sets}{dosubsets}
  4540. \Declaration
  4541. Procedure Do{\_}Sub{\_}Sets(Set1,Set2,Dest:Pointer);
  4542. \Description
  4543. Calculate the difference between \textsf{set1} and \textsf{set2}, setting
  4544. the result in \textsf{dest}.
  4545. \Parameters
  4546. set1 = pointer to 32 byte set \par
  4547. set2 = pointer to 32 byte set \par
  4548. dest = pointer to 32 byte set which will receive the result
  4549. \Notes
  4550. This works on normal sets only.
  4551. \Algorithm
  4552. \begin{lstlisting}{}
  4553. For each bit in the set do
  4554. dest bit = set1 bit AND NOT set2 bit
  4555. \end{lstlisting}
  4556. \end{procedurel}
  4557. \subsubsection{FPC{\_}SET{\_}MUL{\_}SETS}
  4558. \label{subsubsec:mylabel92}
  4559. \begin{procedurel}{Do{\_}Mul{\_}Sets}{domulsets}
  4560. \Declaration
  4561. procedure Do{\_}Mul{\_}Sets(Set1,Set2,Dest:Pointer);
  4562. \Description
  4563. Calculate the multiplication between \textsf{set1} and \textsf{set2},
  4564. setting the result in \textsf{dest}.
  4565. \Parameters
  4566. set1 = pointer to 32 byte set \par
  4567. set2 = pointer to 32 byte set \par
  4568. dest = pointer to 32 byte set which will receive the result
  4569. \Notes
  4570. This works on normal sets only.
  4571. \Algorithm
  4572. \begin{lstlisting}{}
  4573. For each bit in the set do
  4574. dest bit = set1 bit AND set2 bit
  4575. \end{lstlisting}
  4576. \end{procedurel}
  4577. \subsubsection{FPC{\_}SET{\_}SYMDIF{\_}SETS}
  4578. \label{subsubsec:mylabel93}
  4579. \begin{procedurel}{Do{\_}Symdif{\_}Sets}{dosymdifssets}
  4580. \Declaration
  4581. Procedure Do{\_}Symdif{\_}Sets(Set1,Set2,Dest:Pointer);
  4582. \Description
  4583. Calculate the symmetric between \textsf{set1} and \textsf{set2}, setting the
  4584. result in \textsf{dest}.
  4585. \Parameters
  4586. set1 = pointer to 32 byte set \par
  4587. set2 = pointer to 32 byte set \par
  4588. dest = pointer to 32 byte set which will receive the result
  4589. \Notes
  4590. This works on normal sets only.
  4591. \Algorithm
  4592. \begin{lstlisting}{}
  4593. For each bit in the set do
  4594. dest bit = set1 bit XOR set2 bit
  4595. \end{lstlisting}
  4596. \end{procedurel}
  4597. \subsubsection{FPC{\_}SET{\_}ADD{\_}SETS}
  4598. \label{subsubsec:mylabel94}
  4599. \begin{procedurel}{Do{\_}Add{\_}Sets}{doaddsets}
  4600. \Declaration
  4601. procedure Do{\_}Add{\_}Sets(Set1,Set2,Dest : Pointer);
  4602. \Description
  4603. Calculate the addition between \textsf{set1} and \textsf{set2}, setting the
  4604. result in \textsf{dest}.
  4605. \Parameters
  4606. set1 = pointer to 32 byte set \par
  4607. set2 = pointer to 32 byte set \par
  4608. dest = pointer to 32 byte set which will receive the result
  4609. \Notes
  4610. This works on normal sets only.
  4611. \Algorithm
  4612. \begin{lstlisting}{}
  4613. For each bit in the set do
  4614. dest bit = set1 bit OR set2 bit
  4615. \end{lstlisting}
  4616. \end{procedurel}
  4617. \subsubsection{FPC{\_}SET{\_}LOAD{\_}SMALL}
  4618. \label{subsubsec:mylabel95}
  4619. \begin{procedurel}{Do{\_}Load{\_}Small}{doloadsmall}
  4620. \Declaration
  4621. Procedure Do{\_}Load{\_}Small(P : Pointer;L:Longint);
  4622. \Description
  4623. Load a small set into a 32-byte normal set.
  4624. \Parameters
  4625. p = pointer to 32 byte set \par
  4626. l = value of the small set
  4627. \Notes
  4628. Called by code generator (type conversion) from small set to large set.
  4629. Apart from the first 32 bits of the 32 byte set, other bits are not
  4630. modified.
  4631. \Algorithm
  4632. \begin{lstlisting}{}
  4633. For n = bit 0 to bit 31 of l do
  4634. p bit n = l bit n
  4635. \end{lstlisting}
  4636. \end{procedurel}
  4637. \subsubsection{FPC{\_}SET{\_}UNSET{\_}BYTE}
  4638. \label{subsubsec:mylabel96}
  4639. \begin{procedurel}{Do{\_}Unset{\_}Byte}{dounsetbyte}
  4640. \Declaration
  4641. Procedure Do{\_}Unset{\_}Byte(P : Pointer;B : Byte);
  4642. \Description
  4643. Called by code generator to exclude element b from a big 32-byte set pointed
  4644. to by p.
  4645. \Parameters
  4646. p = pointer to 32 byte set \par b = element number to exclude
  4647. \Notes
  4648. The intel 80386 version of the compiler does not save the used registers,
  4649. therefore, in that case, it must be done in the routine itself.
  4650. \Algorithm
  4651. Clear bit number b in p
  4652. \end{procedurel}
  4653. \subsubsection{FPC{\_}SET{\_}IN{\_}BYTE}
  4654. \label{subsubsec:mylabel97}
  4655. \begin{functionl}{Do{\_}In{\_}Byte}{doinbyte}
  4656. \Declaration
  4657. Function Do{\_}In{\_}Byte(P : Pointer;B : Byte):boolean;
  4658. \Description
  4659. Called by code generator to verify the existence of an element in a set.
  4660. Returns TRUE if b is in the set pointed to by p, otherwise returns FALSE.
  4661. \Parameters
  4662. p = pointer to 32 byte set \par b = element number to verify
  4663. \Notes
  4664. This routine should save / restore all used registers.
  4665. \Algorithm
  4666. Clear bit number b in p
  4667. \end{functionl}
  4668. \subsection{Optional internal routines}
  4669. \label{subsec:optional}
  4670. These routines are dependant on the target architecture. They are present in
  4671. software if the hardware does not support these features.
  4672. They could be implemented in assembler directly with register parameter
  4673. passing.
  4674. \subsubsection{FPC{\_}MUL{\_}INT64}
  4675. \label{subsubsec:mylabel98}
  4676. \begin{function}{MulInt64}
  4677. \Declaration
  4678. function MulInt64(f1,f2 : Int64;CheckOverflow : LongBool) : Int64;
  4679. \Description
  4680. Called by the code generator to multiply two int64 values, when the hardware
  4681. does not support this type of operation. The value returned is the result of
  4682. the multiplication.
  4683. \Parameters
  4684. f1 = first operand \par
  4685. f2 = second operand \par
  4686. checkoverflow = TRUE if overflow checking should be done
  4687. \end{function}
  4688. \subsubsection{FPC{\_}DIV{\_}INT64}
  4689. \label{subsubsec:mylabel99}
  4690. \begin{function}{DivInt64}
  4691. \Declaration
  4692. function DivInt64(n,z : Int64) : Int64;
  4693. \Description
  4694. Called by the code generator to get the division two int64 values, when the
  4695. hardware does not support this type of operation. The value returned is the
  4696. result of the division.
  4697. \Parameters
  4698. n =numerator \par
  4699. z = denominator
  4700. \end{function}
  4701. \subsubsection{FPC{\_}MOD{\_}INT64}
  4702. \label{subsubsec:mylabel100}
  4703. \begin{function}{ModInt64}
  4704. \Declaration
  4705. function ModInt64(n,z : Int64) : Int64;
  4706. \Description
  4707. Called by the code generator to get the modulo two int64 values, when the
  4708. architecture does not support this type of operation. The value returned is
  4709. the result of the modulo.
  4710. \Parameters
  4711. n = numerator \par
  4712. z = denominator
  4713. \end{function}
  4714. \subsubsection{FPC{\_}SHL{\_}INT64}
  4715. \label{subsubsec:mylabel101}
  4716. \begin{function}{ShlInt64}
  4717. \Declaration
  4718. Function ShlInt64(Cnt : Longint; Low, High: Longint): Int64;
  4719. \Description
  4720. Called by the code generator to shift left a 64-bit integer by the specified
  4721. amount cnt, when this is not directly supported by the hardware. Returns the
  4722. shifted value.
  4723. \Parameters
  4724. low,high = value to shift (low / high 32-bit value) \par
  4725. cnt = shift count
  4726. \end{function}
  4727. \subsubsection{FPC{\_}SHR{\_}INT64}
  4728. \label{subsubsec:mylabel102}
  4729. \begin{function}{ShrInt64}
  4730. \Declaration
  4731. function ShrInt64(Cnt : Longint; Low, High: Longint): Int64;
  4732. \Description
  4733. Called by the code generator to shift left a 64-bit integer by the specified
  4734. amount cnt, when this is not directly supported by the hardware. Returns the
  4735. shifted value.
  4736. \Parameters
  4737. low,high = value to shift (low/high 32-bit values) \par
  4738. cnt = shift count
  4739. \end{function}
  4740. \subsubsection{FPC{\_}MUL{\_}LONGINT}
  4741. \label{subsubsec:mylabel103}
  4742. \begin{function}{MulLong}
  4743. \Declaration
  4744. Function MulLong: Longint;
  4745. \Description
  4746. 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.
  4747. \Parameters
  4748. Parameters are passed in registers.
  4749. \Notes
  4750. This routine should save / restore all used registers.
  4751. \end{function}
  4752. \subsubsection{FPC{\_}REM{\_}LONGINT}
  4753. \label{subsubsec:mylabel104}
  4754. \begin{function}{RemLong}
  4755. \Declaration
  4756. Function RemLong: Longint;
  4757. \Description
  4758. Called by the code generator to get the modulo two longint values, when the
  4759. hardware does not support this type of operation. The value returned is the
  4760. result of the modulo.
  4761. \Parameters
  4762. Parameters are passed in registers.
  4763. \Notes
  4764. This routine should save / restore all used registers.
  4765. \end{function}
  4766. \subsubsection{FPC{\_}DIV{\_}LONGINT}
  4767. \label{subsubsec:mylabel105}
  4768. \begin{function}{DivLong}
  4769. \Declaration
  4770. Function DivLong: Longint;
  4771. \Description
  4772. Called by the code generator to get the division two longint values, when
  4773. the hardware does not support this type of operation. The value returned is
  4774. the result of the division.
  4775. \Parameters
  4776. Parameters are passed in registers.
  4777. \Notes
  4778. This routine should save / restore all used registers.
  4779. \end{function}
  4780. \subsubsection{FPC{\_}MUL{\_}LONGINT}
  4781. \label{subsubsec:mylabel106}
  4782. \begin{function}{MulCardinal}
  4783. \Declaration
  4784. Function MulCardinal: Cardinal;
  4785. \Description
  4786. Called by the code generator to multiply two cardinal values, when the
  4787. hardware does not support this type of operation. The value returned is the
  4788. result of the multiplication.
  4789. \Parameters
  4790. Parameters are passed in registers.
  4791. \Notes
  4792. This routine should save / restore all used registers.
  4793. \end{function}
  4794. \subsubsection{FPC{\_}REM{\_}CARDINAL}
  4795. \label{subsubsec:mylabel107}
  4796. \begin{function}{RemCardinal}
  4797. \Declaration
  4798. Function RemCardinal : Cardinal;
  4799. \Description
  4800. Called by the code generator to get the modulo two cardinal values, when the
  4801. hardware does not support this type of operation. The value returned is the
  4802. result of the modulo.
  4803. \Parameters
  4804. Parameters are passed in registers.
  4805. \Notes
  4806. This routine should save / restore all used registers.
  4807. \end{function}
  4808. \subsubsection{FPC{\_}DIV{\_}CARDINAL}
  4809. \label{subsubsec:mylabel108}
  4810. \begin{function}{DivCardinal}
  4811. \Declaration
  4812. Function DivCardinal: Cardinal;
  4813. \Description
  4814. Called by the code generator to get the division two cardinal values, when
  4815. the hardware does not support this type of operation. The value returned is
  4816. the result of the division.
  4817. \Parameters
  4818. Parameters are passed in registers.
  4819. \Notes
  4820. This routine should save / restore all used registers.
  4821. \end{function}
  4822. \subsubsection{FPC{\_}LONG{\_}TO{\_}SINGLE}
  4823. \label{subsubsec:mylabel109}
  4824. \begin{function}{LongSingle}
  4825. \Declaration
  4826. Function LongSingle: Single;
  4827. \Description
  4828. Called by the code generator to convert a longint to a single IEEE floating
  4829. point value.
  4830. \Parameters
  4831. Parameters are passed in registers
  4832. \Notes
  4833. This routine should save / restore all used registers.
  4834. \end{function}
  4835. FPC{\_}ADD{\_}SINGLE
  4836. FPC{\_}SUB{\_}SINGLE
  4837. FPC{\_}MUL{\_}SINGLE
  4838. FPC{\_}REM{\_}SINGLE
  4839. FPC{\_}DIV{\_}SINGLE
  4840. FPC{\_}CMP{\_}SINGLE
  4841. FPC{\_}SINGLE{\_}TO{\_}LONGINT
  4842. \section{Optimizing your code}
  4843. \label{sec:optimizing}
  4844. \subsection{Simple types}
  4845. \label{subsec:simple}
  4846. Use the most simple types, when defining and declaring variables, they
  4847. require less overhead. Classes, and complex string types (ansi strings and
  4848. wide strings) posess runtime type information, as well as more overhead for
  4849. operating on them then simple types such as shortstring and simple ordinal
  4850. types.
  4851. \subsection{constant duplicate merging}
  4852. \label{subsec:constant}
  4853. When duplicates of constant strings, sets or floating point values are found
  4854. in the code, they are replaced by only once instance of the same string, set
  4855. or floating point constant which reduces the size of the final executable.
  4856. \subsection{inline routines}
  4857. \label{subsec:inline}
  4858. The following routines of the system unit are directly inlined by the
  4859. compiler, and generate more efficient code:
  4860. \begin{longtable}{|l|l|}
  4861. \hline
  4862. Prototype& Definition and notes \\
  4863. \hline
  4864. \endhead
  4865. \hline
  4866. \endfoot
  4867. \textsf{function pi : extended;}& \\
  4868. \textsf{function abs(d : extended) : extended;}& \\
  4869. \textsf{function sqr(d : extended) : extended;}& \\
  4870. \textsf{function sqrt(d : extended) : extended;}& \\
  4871. \textsf{function arctan(d : extended) : extended;}& \\
  4872. \textsf{function ln(d : extended) : extended;}& \\
  4873. \textsf{function sin(d : extended) : extended;}& \\
  4874. \textsf{function cos(d : extended) : extended;}& \\
  4875. \textsf{function ord(X): longint;}&
  4876. Changes node type to be type compatible \\
  4877. \textsf{function lo(X) : byte or word;}&
  4878. Generates 2-3 instruction sequence inline \\
  4879. \textsf{function hi(X) : byte or word;}&
  4880. Generates 2-3 instruction sequence inline \\
  4881. \textsf{function chr(b : byte) : Char;}&
  4882. Changes node type to be type compatible \\
  4883. \textsf{function Length(s : string) : byte;}&
  4884. Generate 2-3 instruction sequence \\
  4885. \textsf{function Length(c : char) : byte;}&
  4886. Generates 1 instruction sequence (appx.) \\
  4887. \textsf{procedure Reset(var f : TypedFile);}&
  4888. Calls FPC{\_}RESET{\_}TYPED \\
  4889. \textsf{procedure rewrite(var f : TypedFile);}&
  4890. Calls FPC{\_}REWRITE{\_}TYPED \\
  4891. \textsf{procedure settextbuf(var F : Text; var Buf);}&
  4892. Calls SetTextBuf of runtime library \\
  4893. \textsf{procedure writen;}&
  4894. Calls FPC{\_}WRITE{\_}XXXX routines \\
  4895. \textsf{procedure writeln;}&
  4896. Calls FPC{\_}WRITE{\_}XXXX routines \\
  4897. \textsf{procedure read;}&
  4898. Calls FPC{\_}READ{\_}XXXX routines \\
  4899. \textsf{procedure readln;}&
  4900. Calls FPC{\_}READ{\_}XXXX routines \\
  4901. \textsf{procedure concat;}&
  4902. Generates a TREE NODES of type addn \\
  4903. \textsf{function assigned(var p): boolean;}&
  4904. Generates 1-2 instruction sequence inline \\
  4905. \textsf{procedure str(X :[Width [:Decimals]]; var S);}& \\
  4906. \textsf{}& \\
  4907. \textsf{function sizeof(X): longint;}&
  4908. Generates 2-3 instruction sequence inline \\
  4909. \textsf{function typeof(X): pointer;}&
  4910. Generates 2-3 instruction sequence inline \\
  4911. \textsf{procedure val(S;var V; var Code: integer);}& \\
  4912. \textsf{function seg(X): longint;}& \\
  4913. \textsf{function High(X)}&
  4914. Generates a TREE NODE of type ordconstn \\
  4915. \textsf{function Low(X)}&
  4916. Generates a TREE NODE of type ordconstn \\
  4917. \textsf{function pred(x)}&
  4918. Generates 2-3 instruction sequence inline \\
  4919. \textsf{function succ(X)}&
  4920. Generates 2-3 instruction sequence inline \\
  4921. \textsf{procedure inc(var X [ ; N: longint]);}&
  4922. Generate 2-3 instruction sequence inline \\
  4923. \textsf{procedure dec(var X [; N:longint]);}&
  4924. Generate 2-3 instruction sequence inline \\
  4925. \textsf{procedure include(var s: set of T; I: T);}&
  4926. In the case of a small set : Generates 2-3 instruction sequence inline,
  4927. otherwise calls FPC{\_}SET{\_}SET{\_}BYTE \\
  4928. \textsf{procedure exclude(var S : set of T; I: T);}&
  4929. In the case of a small set : Generates 2-3 instruction sequence inline,
  4930. otherwise calls FPC{\_}SET{\_}UNSET{\_}BYTE \\
  4931. \textsf{procedure assert(expr : Boolean [; const msg: string]);}&
  4932. Calls the internal routine FPC{\_}ASSERT in the case where the assert fails.\\
  4933. \textsf{function addr(X): pointer;}&
  4934. Generates a TREE NODE of type addrn \\
  4935. \textsf{function typeInfo(typeIdent): pointer;}&
  4936. Generates 1 instruction sequence inline \\
  4937. \end{longtable}
  4938. \subsection{temporary memory allocation reuse}
  4939. \label{subsec:mylabel11}
  4940. When routines are very complex , they may require temporary allocated space
  4941. on the stack to store intermediate results. The temporary memory space can
  4942. be reused for several different operations if other space is required on the
  4943. stack.
  4944. \section{Appendix A}
  4945. \label{sec:appendix}
  4946. This appendix describes the temporary defines when compiling software under
  4947. the compiler:
  4948. The following defines are defined in FreePascal for v1.0.x, but they will be
  4949. removed in future versions, they are used for debugging purposes only:
  4950. \begin{itemize}
  4951. \item INT64
  4952. \item HASRESOURCESTRINGS
  4953. \item NEWVMTOFFSET
  4954. \item HASINTERNMATH
  4955. \item SYSTEMVARREC
  4956. \item INCLUDEOK
  4957. \item NEWMM
  4958. \item HASWIDECHAR
  4959. \item INT64FUNCRESOK
  4960. \item CORRECTFLDCW
  4961. \item ENHANCEDRAISE
  4962. \item PACKENUMFIXED
  4963. \end{itemize}
  4964. NOTE: Currently, the only possible stack alignment are either 2 or 4 if the
  4965. target operating system pushes parameters on the stack directly in assembler
  4966. (because for example if pushing a long value on the stack while the required
  4967. stack alignment is 8 will give out wrong access to data in the actual
  4968. routine -- the offset will be wrong).
  4969. \printindex
  4970. \end{document}