📚 LinuxDocs
Topics:
All Pages8021X HOWTOACP ModemACPI HOWTOADSL Bandwidth Man..ATA RAID HOWTOATM Linux HOWTOAX25 HOWTOAccessibility Dev ..Accessibility HOWTOAdv Bash Scr HOWTOAdv Routing HOWTOAntares RAID sparc..Apache Compile HOWTOApache WebDAV LDAP..Assembly HOWTOAstronomy HOWTOAthlon Powersaving..Authentication Gat..Autodir HOWTOAviation HOWTOAvr Microcontrolle..BRIDGE STP HOWTOBTTVBackspaceDeleteBandwidth Limiting..Bangla HOWTOBash Prompt HOWTOBattery PoweredBelarusian HOWTOBelgian HOWTOBeowulf HOWTOBocaBogoMipsBootdisk HOWTOBridgeC++ dlopenC C++Beautifier HO..C editing with VIM..CDROM HOWTOCDServer HOWTOCable ModemCaudium HOWTOClone HOWTOCompaq Remote Insi..Compaq T1500 HOWTOConexant+Rockwell ..Cryptoloop HOWTODB2 HOWTODHCPDSL HOWTODVD Playback HOWTODebian Binary Pack..Debian JigdoDebian and Windows..Disk Encryption HO..Disk on Chip HOWTODocBook Demystific..DocBook InstallDocBook OpenJade S..Ecology HOWTOEmacspeak HOWTOEncourage Women Li..Encrypted Root Fil..Euro Char SupportEvent HOWTOFedora Multimedia ..Finnish HOWTOFirewall PiercingFlash Memory HOWTOFont HOWTOFramebuffer HOWTOGCC HOWTOGIS GRASSGlibc Install HOWTOHOWTO HOWTOHOWTO INDEXHP HOWTOHandspring VisorHard Disk UpgradeHardware HOWTOHighQuality Apps H..Home Electrical Co..IBM7248 HOWTOIO Perf HOWTOIP AliasIP Masquerade HOWTOIRCImplement Sys Call..Indic Fonts HOWTOInfrared HOWTOIngresII HOWTOInstall StrategiesInstallation HOWTOInstallfest HOWTOIntkeybItalian HOWTOJabber Server Farm..JavaStation HOWTOKerberos Infrastru..Kernel HOWTOKerneldKodak Digitalcam H..LDAP HOWTOLDP Reviewer HOWTOLILO crash rescue ..LVM HOWTOLeased LineLegoLinksys Blue Box R..Linux+Win95Linux+Win9x+Grub H..Linux+Windows HOWTOLinux Complete Bac..Linux Crash HOWTOLinux Gamers HOWTOLinux Modem SharingLinux Promise RAID..Linux i386 Boot Co..LinuxGL QuakeWorld..Lotus DominoR5MILO HOWTOMMBase Inst HOWTOMP3 CD BurningMail User HOWTOMajordomo MajorCoo..Man PageMasquerading Simpl..Medicine HOWTOMindTerm SSH HOWTOMobile IPv6 HOWTOMock MainframeModule HOWTOModulesMotorola Surfboard..Mozilla OptimizationMulti Distro DevNCURSES Programmin..NFS HOWTONFS Root Client mi..NIS HOWTONetMeeting HOWTONetwork boot HOWTONvidia OpenGL Conf..OLSR IPv6 HOWTOOnline Troubleshoo..Oracle 9i Fedora 3..PA RISC Linux Boot..PCTel MicroModem C..PHP Nuke HOWTOPPP HOWTOPagerPalmOS HOWTOPartitionPartition Mass Sto..Partition Mass Sto..Partition RescuePine ExchangePortSlavePost Installation ..Postfix Cyrus Web ..Pre Installation C..Print2WinPrinting HOWTOProcess AccountingProgram Library HO..Proxy ARP SubnetQmail ClamAV HOWTOQmail VMailMgr Cou..Querying libiptc H..RPM HOWTOReading List HOWTORedHat CD HOWTOReliance HOWTORemote BridgingRemote Serial Cons..SCSI 2.4 HOWTOSCSI Generic HOWTOSLIP PPP EmulatorSRM HOWTOSSL Certificates H..Scanner HOWTOScientific Computi..Scripting GUI TclTkSecure CVS PserverSecure Programs HO..Security HOWTOSecurity Quickstar..Security Quickstar..Serial Laplink HOWTOSerial Programming..Slovak HOWTOSmall MemorySmart Card HOWTOSoftware Proj Mgmt..Software Release P..Sound HOWTOSpam Filtering for..Speech Recognition..SquashFS HOWTOSybase ASA HOWTOSybase ASE HOWTOSybase PHP ApacheTCP Keepalive HOWTOTamil Linux HOWTOTimePrecision HOWTOTimeSys Linux Inst..Token RingTraffic Control HO..Traffic Control tc..UPS HOWTOUnix Hardware Buye..Unix and Internet ..UpgradeUsenet News HOWTOUser Authenticatio..VB6 to TclVMS to Linux HOWTOVPN HOWTOValgrind HOWTOVideoLAN HOWTOVim HOWTOVirtual WebWebcam HOWTOWikiText HOWTOWindows Newsreader..Wireless Link sys ..Wireless Sync HOWTOXDM XtermXDMCP HOWTOXFree Local multi ..XFree86 HOWTOXFree86 R200XFree86 Second MouseXFree86 Video Timi..XML RPC HOWTOXWindow Overview H..XWindow User HOWTOXinerama HOWTOXterminalsHtml singleI810 HOWTOLibdc1394 HOWTOOpenMosix HOWTOPhhttpd HOWTOPpp sshText
Next Previous Contents

6. Getting started

According to the formal GNU philosophy, each language that is present in the GCC (ie. for languages having separate front ends) should have a subdirectory of its own. So the first thing the GCC expects from us is a separate directory . Let us create a new subdirectory in the srcdir/gcc with the name of our language (say 'demo').

As explained before gcc expects a number of files and functions. In our directory also there should be some files present. The first thing that should be present is a make file. It is divided into two, Make-lang.in and Makefile.in. Both are part of the main make file of gcc.

Make-lang.in is actually included in the main make file of the gcc and from there (objdir/gcc) it calls the make in the language directory. So the filenames should be provided with full path names. Don't try to give relative ones. The file gives information about the source files of our language. So it is here that we should specify the files that is required for our language.

Makefile.in is used to create the make file in the language directory. It is included in the language directory. .:: pg88pg88.studio.site ::.

The third file expected by the gcc is config-lang.in. It is used by the file srcdir/gcc/configure (a shell script).

The fourth file gcc expects is lang-specs.h. This file helps in the modification of the gcc driver program. The driver has to understand the presence of our new language. This is neatly accomplished by this file. It is here that the details like extensions of our language exists. You can specify them according to your taste.

Now the most important thing. No one is expecting you to create all these files from scratch. The best method is to copy these files from any existing directory and make the relevant changes. The changes may include some modifications in the name of the language, the files used by us, the extensions of our choice etc.

All the information provided are from my observation and sometimes there may be variations in the above details.

6.1 Call back routines

As already explained we are going to use a major part of the gcc for compiling our language. So it is our responsibility to define some functions and variables which are used by the back end. Most of them are of no direct help to us. But back end expects it, so we should provide it.

As in the above case it is better to copy from some existing front ends. But let's have a general idea of what each function is. If you find this section boring you can skip this section but don't skip the inclusion of these routines in your program.

type_for_size(unsigned precision, int unsignedp)
It returns a tree of integer type with number of bits given by the argument precision. If unsignedp is nonzero, then it is unsigned type, else it is signed type. [REST History]

init_parse(char *filename)
It initialize parsing.

finish_parse()
It does the parsing cleanup.

lang_init_options()
Language specific initialization option processing.

lang_print_xnode(FILE *file,tree t,int i)
Required by gcc. Don't know what exactly it does.

type_for_mode(enum machine_mode mode,int unsignedp)
It returns a tree type of the desired mode given by us. mode represents machine data type like whole number. unsignedp, as usual is used for obtaining an unsigned type or else a signed type is returned. .:: telegra.ph ::.

unsigned_type(tree type_node)
Returns the unsigned version of type_node.

signed_type(tree type_node)
Returns the signed version of type_node.

signed_or_unsigned_type(int unsignedp, tree type)
Returns signed or unsigned tree node depending upon unsignedp.

global_bindings_p()
Returns nonzero if we are currently in the global binding level.

getdecls()
Returns the list of declarations in the current level, but in reverse order.

kept_level_p()
It is nonzero when a 'BLOCK' must be created for the current level of symbol table.

pushlevel(int ignore)
Enter a new binding level. A symbol name used before in another binding level is covered when entered into a new level. .:: telegra.ph ::.

poplevel(int keep, int reverse, int functionbody) 
Removes a new level created by pushlevel. The symbol table status is regained (which was present before the pushlevel). .:: docs.google.com ::.

insert_block(tree block)
Insert block at the end of the list of subblocks of the current binding level.

set_block(tree block)
Sets the block for the current scope.

pushdecl(tree decl)
Inserts the declaration, decl into the symbol table and returns the tree back.

init_decl_processing()
Initializes the symbol table. It sets global variables and inserts other variables into the symbol table.

lang_decode_option(int a, char **p)
It decodes all language specific options that cannot be decoded by the GCC. Returns 1 if successful, otherwise 0.

lang_init()
Performs all the initialization steps required by the front end. It includes setting certain global variables. [Research on Swift]

lang_finish()
Performs all front end specific clean up.

lang_identify()
Returns a short string identifying the language to the debugger.

maybe_build_cleanup(tree decl)
Creates a tree node, which represents an automatic cleanup action.

incomplete_type_error(tree value, tree type)
Prints an error message for invalid use of incomplete type.

truthvalue_conversion(tree expr)
It returns the same expr, but in a type which represents truthvalues.

mark_addressable(tree expr)
Marks expr as a construct which need an address in storage.

print_lang_statics()
Prints any language-specific compilation statics.

copy_lang_decl(tree node)
It copies the declarations if DECL_LANG_SPECIFIC is nonzero. .:: vetstate.ru ::.

print_lang_decl(FILE *file, tree node, int indent)
Outputs the declaration for node with indentation depth indent to the file, file.

print_lang_type(FILE *file, tree node, int indent)
Outputs the type for node with indentation depth indent to the file, file.

print_lang_identifier(FILE *file, tree node, int indent)
Outputs the identifier for node with indentation depth indent to the file, file.

int_lex()
Performs whatever initialization steps are required by the language dependent lexical analyzer.

set_yydebug()
Sets some debug flags for the parser.

yyerror(char *s)
Routine to print parse error message.

language_string
A character string to hold the name of our language. say, demo.

flag_traditional
A variable needed by the file dwarfout.c

error_mark_node
A tree node used to define errors. It represents a partial tree. It is of great help when some errors occur in the syntax analysis phase.

integer_type_node, char_type_node, void_type_node 
Clear from the names.

integer_zero_node, integer_one_node 
Constants of type integer_type_node with values 0 and 1 respectively.


Next Previous Contents

Share or Research:

Share on FB Post to X LinkedIn 🤖 Ask AI about this