You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
6.7 KiB
HTML
142 lines
6.7 KiB
HTML
4 years ago
|
<html lang="en">
|
||
|
<head>
|
||
|
<title>Function Basics - GNU Compiler Collection (GCC) Internals</title>
|
||
|
<meta http-equiv="Content-Type" content="text/html">
|
||
|
<meta name="description" content="GNU Compiler Collection (GCC) Internals">
|
||
|
<meta name="generator" content="makeinfo 4.13">
|
||
|
<link title="Top" rel="start" href="index.html#Top">
|
||
|
<link rel="up" href="Functions.html#Functions" title="Functions">
|
||
|
<link rel="next" href="Function-Properties.html#Function-Properties" title="Function Properties">
|
||
|
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
|
||
|
<!--
|
||
|
Copyright (C) 1988-2015 Free Software Foundation, Inc.
|
||
|
|
||
|
Permission is granted to copy, distribute and/or modify this document
|
||
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
||
|
any later version published by the Free Software Foundation; with the
|
||
|
Invariant Sections being ``Funding Free Software'', the Front-Cover
|
||
|
Texts being (a) (see below), and with the Back-Cover Texts being (b)
|
||
|
(see below). A copy of the license is included in the section entitled
|
||
|
``GNU Free Documentation License''.
|
||
|
|
||
|
(a) The FSF's Front-Cover Text is:
|
||
|
|
||
|
A GNU Manual
|
||
|
|
||
|
(b) The FSF's Back-Cover Text is:
|
||
|
|
||
|
You have freedom to copy and modify this GNU Manual, like GNU
|
||
|
software. Copies published by the Free Software Foundation raise
|
||
|
funds for GNU development.-->
|
||
|
<meta http-equiv="Content-Style-Type" content="text/css">
|
||
|
<style type="text/css"><!--
|
||
|
pre.display { font-family:inherit }
|
||
|
pre.format { font-family:inherit }
|
||
|
pre.smalldisplay { font-family:inherit; font-size:smaller }
|
||
|
pre.smallformat { font-family:inherit; font-size:smaller }
|
||
|
pre.smallexample { font-size:smaller }
|
||
|
pre.smalllisp { font-size:smaller }
|
||
|
span.sc { font-variant:small-caps }
|
||
|
span.roman { font-family:serif; font-weight:normal; }
|
||
|
span.sansserif { font-family:sans-serif; font-weight:normal; }
|
||
|
--></style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div class="node">
|
||
|
<a name="Function-Basics"></a>
|
||
|
<p>
|
||
|
Next: <a rel="next" accesskey="n" href="Function-Properties.html#Function-Properties">Function Properties</a>,
|
||
|
Up: <a rel="up" accesskey="u" href="Functions.html#Functions">Functions</a>
|
||
|
<hr>
|
||
|
</div>
|
||
|
|
||
|
<h4 class="subsection">10.8.1 Function Basics</h4>
|
||
|
|
||
|
<p><a name="index-DECL_005fNAME-1967"></a><a name="index-DECL_005fASSEMBLER_005fNAME-1968"></a><a name="index-TREE_005fPUBLIC-1969"></a><a name="index-DECL_005fARTIFICIAL-1970"></a><a name="index-DECL_005fFUNCTION_005fSPECIFIC_005fTARGET-1971"></a><a name="index-DECL_005fFUNCTION_005fSPECIFIC_005fOPTIMIZATION-1972"></a>
|
||
|
A function has four core parts: the name, the parameters, the result,
|
||
|
and the body. The following macros and functions access these parts
|
||
|
of a <code>FUNCTION_DECL</code> as well as other basic features:
|
||
|
<dl>
|
||
|
<dt><code>DECL_NAME</code><a name="index-DECL_005fNAME-1973"></a><dd>This macro returns the unqualified name of the function, as an
|
||
|
<code>IDENTIFIER_NODE</code>. For an instantiation of a function template,
|
||
|
the <code>DECL_NAME</code> is the unqualified name of the template, not
|
||
|
something like <code>f<int></code>. The value of <code>DECL_NAME</code> is
|
||
|
undefined when used on a constructor, destructor, overloaded operator,
|
||
|
or type-conversion operator, or any function that is implicitly
|
||
|
generated by the compiler. See below for macros that can be used to
|
||
|
distinguish these cases.
|
||
|
|
||
|
<br><dt><code>DECL_ASSEMBLER_NAME</code><a name="index-DECL_005fASSEMBLER_005fNAME-1974"></a><dd>This macro returns the mangled name of the function, also an
|
||
|
<code>IDENTIFIER_NODE</code>. This name does not contain leading underscores
|
||
|
on systems that prefix all identifiers with underscores. The mangled
|
||
|
name is computed in the same way on all platforms; if special processing
|
||
|
is required to deal with the object file format used on a particular
|
||
|
platform, it is the responsibility of the back end to perform those
|
||
|
modifications. (Of course, the back end should not modify
|
||
|
<code>DECL_ASSEMBLER_NAME</code> itself.)
|
||
|
|
||
|
<p>Using <code>DECL_ASSEMBLER_NAME</code> will cause additional memory to be
|
||
|
allocated (for the mangled name of the entity) so it should be used
|
||
|
only when emitting assembly code. It should not be used within the
|
||
|
optimizers to determine whether or not two declarations are the same,
|
||
|
even though some of the existing optimizers do use it in that way.
|
||
|
These uses will be removed over time.
|
||
|
|
||
|
<br><dt><code>DECL_ARGUMENTS</code><a name="index-DECL_005fARGUMENTS-1975"></a><dd>This macro returns the <code>PARM_DECL</code> for the first argument to the
|
||
|
function. Subsequent <code>PARM_DECL</code> nodes can be obtained by
|
||
|
following the <code>TREE_CHAIN</code> links.
|
||
|
|
||
|
<br><dt><code>DECL_RESULT</code><a name="index-DECL_005fRESULT-1976"></a><dd>This macro returns the <code>RESULT_DECL</code> for the function.
|
||
|
|
||
|
<br><dt><code>DECL_SAVED_TREE</code><a name="index-DECL_005fSAVED_005fTREE-1977"></a><dd>This macro returns the complete body of the function.
|
||
|
|
||
|
<br><dt><code>TREE_TYPE</code><a name="index-TREE_005fTYPE-1978"></a><dd>This macro returns the <code>FUNCTION_TYPE</code> or <code>METHOD_TYPE</code> for
|
||
|
the function.
|
||
|
|
||
|
<br><dt><code>DECL_INITIAL</code><a name="index-DECL_005fINITIAL-1979"></a><dd>A function that has a definition in the current translation unit will
|
||
|
have a non-<code>NULL</code> <code>DECL_INITIAL</code>. However, back ends should not make
|
||
|
use of the particular value given by <code>DECL_INITIAL</code>.
|
||
|
|
||
|
<p>It should contain a tree of <code>BLOCK</code> nodes that mirrors the scopes
|
||
|
that variables are bound in the function. Each block contains a list
|
||
|
of decls declared in a basic block, a pointer to a chain of blocks at
|
||
|
the next lower scope level, then a pointer to the next block at the
|
||
|
same level and a backpointer to the parent <code>BLOCK</code> or
|
||
|
<code>FUNCTION_DECL</code>. So given a function as follows:
|
||
|
|
||
|
<pre class="smallexample"> void foo()
|
||
|
{
|
||
|
int a;
|
||
|
{
|
||
|
int b;
|
||
|
}
|
||
|
int c;
|
||
|
}
|
||
|
</pre>
|
||
|
<p>you would get the following:
|
||
|
|
||
|
<pre class="smallexample"> tree foo = FUNCTION_DECL;
|
||
|
tree decl_a = VAR_DECL;
|
||
|
tree decl_b = VAR_DECL;
|
||
|
tree decl_c = VAR_DECL;
|
||
|
tree block_a = BLOCK;
|
||
|
tree block_b = BLOCK;
|
||
|
tree block_c = BLOCK;
|
||
|
BLOCK_VARS(block_a) = decl_a;
|
||
|
BLOCK_SUBBLOCKS(block_a) = block_b;
|
||
|
BLOCK_CHAIN(block_a) = block_c;
|
||
|
BLOCK_SUPERCONTEXT(block_a) = foo;
|
||
|
BLOCK_VARS(block_b) = decl_b;
|
||
|
BLOCK_SUPERCONTEXT(block_b) = block_a;
|
||
|
BLOCK_VARS(block_c) = decl_c;
|
||
|
BLOCK_SUPERCONTEXT(block_c) = foo;
|
||
|
DECL_INITIAL(foo) = block_a;
|
||
|
</pre>
|
||
|
</dl>
|
||
|
|
||
|
<!-- -->
|
||
|
<!-- Function Properties -->
|
||
|
<!-- -->
|
||
|
</body></html>
|
||
|
|