344 lines
7.9 KiB
HTML
344 lines
7.9 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
|
|
<TITLE> GCC Frontend HOWTO: Getting started </TITLE>
|
|
<LINK HREF="GCC-Frontend-HOWTO-7.html" REL=next>
|
|
<LINK HREF="GCC-Frontend-HOWTO-5.html" REL=previous>
|
|
<LINK HREF="GCC-Frontend-HOWTO.html#toc6" REL=contents>
|
|
</HEAD>
|
|
<BODY>
|
|
<A HREF="GCC-Frontend-HOWTO-7.html">Next</A>
|
|
<A HREF="GCC-Frontend-HOWTO-5.html">Previous</A>
|
|
<A HREF="GCC-Frontend-HOWTO.html#toc6">Contents</A>
|
|
<HR>
|
|
<H2><A NAME="s6">6. Getting started </A></H2>
|
|
|
|
<P>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').
|
|
<P>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.
|
|
<P>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.
|
|
<P>Makefile.in is used to create the make file in the language
|
|
directory. It is included in the language directory.
|
|
<P>The third file expected by the gcc is config-lang.in. It is
|
|
used by the file srcdir/gcc/configure (a shell script).
|
|
<P>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.
|
|
<P>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.
|
|
<P>All the information provided are from my observation
|
|
and sometimes there may be variations in the above details.
|
|
<P>
|
|
<H2><A NAME="ss6.1">6.1 Call back routines </A>
|
|
</H2>
|
|
|
|
<P>
|
|
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.
|
|
<P>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.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<PRE>
|
|
type_for_size(unsigned precision, int unsignedp)
|
|
</PRE>
|
|
|
|
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.
|
|
<P>
|
|
<PRE>
|
|
init_parse(char *filename)
|
|
</PRE>
|
|
|
|
It initialize parsing.
|
|
<P>
|
|
<PRE>
|
|
finish_parse()
|
|
</PRE>
|
|
|
|
It does the parsing cleanup.
|
|
<P>
|
|
<PRE>
|
|
lang_init_options()
|
|
</PRE>
|
|
|
|
Language specific initialization option processing.
|
|
<P>
|
|
<PRE>
|
|
lang_print_xnode(FILE *file,tree t,int i)
|
|
</PRE>
|
|
|
|
Required by gcc. Don't know what exactly it does.
|
|
<P>
|
|
<PRE>
|
|
type_for_mode(enum machine_mode mode,int unsignedp)
|
|
</PRE>
|
|
|
|
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.
|
|
<P>
|
|
<PRE>
|
|
unsigned_type(tree type_node)
|
|
</PRE>
|
|
|
|
Returns the unsigned version of type_node.
|
|
<P>
|
|
<PRE>
|
|
signed_type(tree type_node)
|
|
</PRE>
|
|
|
|
Returns the signed version of type_node.
|
|
<P>
|
|
<PRE>
|
|
signed_or_unsigned_type(int unsignedp, tree type)
|
|
</PRE>
|
|
|
|
Returns signed or unsigned tree node depending upon unsignedp.
|
|
<P>
|
|
<PRE>
|
|
global_bindings_p()
|
|
</PRE>
|
|
|
|
Returns nonzero if we are currently in the global binding level.
|
|
<P>
|
|
<PRE>
|
|
getdecls()
|
|
</PRE>
|
|
|
|
Returns the list of declarations in the current level, but in reverse
|
|
order.
|
|
<P>
|
|
<PRE>
|
|
kept_level_p()
|
|
</PRE>
|
|
|
|
It is nonzero when a 'BLOCK' must be created for the current
|
|
level of symbol table.
|
|
<P>
|
|
<PRE>
|
|
pushlevel(int ignore)
|
|
</PRE>
|
|
|
|
Enter a new binding level. A symbol name used before in
|
|
another binding level is covered when entered into a new level.
|
|
<P>
|
|
<PRE>
|
|
poplevel(int keep, int reverse, int functionbody)
|
|
</PRE>
|
|
|
|
Removes a new level created by pushlevel. The symbol table
|
|
status is regained (which was present before the pushlevel).
|
|
<P>
|
|
<PRE>
|
|
insert_block(tree block)
|
|
</PRE>
|
|
|
|
Insert block at the end of the list of subblocks of the current
|
|
binding level.
|
|
<P>
|
|
<PRE>
|
|
set_block(tree block)
|
|
</PRE>
|
|
|
|
Sets the block for the current scope.
|
|
<P>
|
|
<PRE>
|
|
pushdecl(tree decl)
|
|
</PRE>
|
|
|
|
Inserts the declaration, decl into the symbol table and
|
|
returns the tree back.
|
|
<P>
|
|
<PRE>
|
|
init_decl_processing()
|
|
</PRE>
|
|
|
|
Initializes the symbol table. It sets global variables and
|
|
inserts other variables into the symbol table.
|
|
<P>
|
|
<PRE>
|
|
lang_decode_option(int a, char **p)
|
|
</PRE>
|
|
|
|
It decodes all language specific options that cannot be decoded
|
|
by the GCC. Returns 1 if successful, otherwise 0.
|
|
<P>
|
|
<PRE>
|
|
lang_init()
|
|
</PRE>
|
|
|
|
Performs all the initialization steps required by the front end.
|
|
It includes setting certain global variables.
|
|
<P>
|
|
<PRE>
|
|
lang_finish()
|
|
</PRE>
|
|
|
|
Performs all front end specific clean up.
|
|
<P>
|
|
<PRE>
|
|
lang_identify()
|
|
</PRE>
|
|
|
|
Returns a short string identifying the language to the
|
|
debugger.
|
|
<P>
|
|
<PRE>
|
|
maybe_build_cleanup(tree decl)
|
|
</PRE>
|
|
|
|
Creates a tree node, which represents an automatic cleanup
|
|
action.
|
|
<P>
|
|
<PRE>
|
|
incomplete_type_error(tree value, tree type)
|
|
</PRE>
|
|
|
|
Prints an error message for invalid use of incomplete type.
|
|
<P>
|
|
<PRE>
|
|
truthvalue_conversion(tree expr)
|
|
</PRE>
|
|
|
|
It returns the same expr, but in a type which represents
|
|
truthvalues.
|
|
<P>
|
|
<PRE>
|
|
mark_addressable(tree expr)
|
|
</PRE>
|
|
|
|
Marks expr as a construct which need an address in storage.
|
|
<P>
|
|
<PRE>
|
|
print_lang_statics()
|
|
</PRE>
|
|
|
|
Prints any language-specific compilation statics.
|
|
<P>
|
|
<PRE>
|
|
copy_lang_decl(tree node)
|
|
</PRE>
|
|
|
|
It copies the declarations if DECL_LANG_SPECIFIC is nonzero.
|
|
<P>
|
|
<PRE>
|
|
print_lang_decl(FILE *file, tree node, int indent)
|
|
</PRE>
|
|
|
|
Outputs the declaration for node with indentation depth
|
|
indent to the file, file.
|
|
<P>
|
|
<PRE>
|
|
print_lang_type(FILE *file, tree node, int indent)
|
|
</PRE>
|
|
|
|
Outputs the type for node with indentation depth
|
|
indent to the file, file.
|
|
<P>
|
|
<PRE>
|
|
print_lang_identifier(FILE *file, tree node, int indent)
|
|
</PRE>
|
|
|
|
Outputs the identifier for node with indentation depth
|
|
indent to the file, file.
|
|
<P>
|
|
<PRE>
|
|
int_lex()
|
|
</PRE>
|
|
|
|
Performs whatever initialization steps are required by the
|
|
language dependent lexical analyzer.
|
|
<P>
|
|
<PRE>
|
|
set_yydebug()
|
|
</PRE>
|
|
|
|
Sets some debug flags for the parser.
|
|
<P>
|
|
<PRE>
|
|
yyerror(char *s)
|
|
</PRE>
|
|
|
|
Routine to print parse error message.
|
|
<P>
|
|
<PRE>
|
|
language_string
|
|
</PRE>
|
|
|
|
A character string to hold the name of our language. say,
|
|
demo.
|
|
<P>
|
|
<PRE>
|
|
flag_traditional
|
|
</PRE>
|
|
|
|
A variable needed by the file dwarfout.c
|
|
<P>
|
|
<PRE>
|
|
error_mark_node
|
|
</PRE>
|
|
|
|
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.
|
|
<P>
|
|
<PRE>
|
|
integer_type_node, char_type_node, void_type_node
|
|
</PRE>
|
|
|
|
Clear from the names.
|
|
<P>
|
|
<PRE>
|
|
integer_zero_node, integer_one_node
|
|
</PRE>
|
|
|
|
Constants of type integer_type_node with values 0 and 1
|
|
respectively.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<HR>
|
|
<A HREF="GCC-Frontend-HOWTO-7.html">Next</A>
|
|
<A HREF="GCC-Frontend-HOWTO-5.html">Previous</A>
|
|
<A HREF="GCC-Frontend-HOWTO.html#toc6">Contents</A>
|
|
</BODY>
|
|
</HTML>
|