Difference between revisions of "Using GDC"

From D Wiki
Jump to: navigation, search
(Added section for attributes. Will document soon)
(Added known attributes)
Line 142: Line 142:
  
 
=== Attributes ===
 
=== Attributes ===
{coming soon}
+
GDC supports a small subset of the [http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html GCC attributes].  Please see the linked GCC attribute for details about an individual attribute.
 +
 
 +
{|class="wikitable"
 +
! GDC Attribute
 +
! GCC Attribute
 +
|-
 +
| flatten || [http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html flatten]
 +
|-
 +
| forceinline* || [http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html always_inline]
 +
|-
 +
| noinline* || [http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html noinline]
 +
|-
 +
| target || {Not sure how this relates to GCC attributes.  If you know please update this wiki}
 +
|}
 +
 
 +
* Being backend attributes, you can't enforce that these attributes actually take effect in user code (no static asserts!) - but you have some guarantee in that the backend will complain if it can't apply the attribute
  
 
== Known Issues ==
 
== Known Issues ==

Revision as of 06:54, 16 March 2014


User Documentation

Usage of GDC

Simple Compilation

Creating an executable is quite easy.

gdc main.d -o main

This will attempt to compile and link the file 'main.d' and place the output into the file 'main'. If you do not use the -o switch, then your executable will be called 'a.out'.

On a typical Unix system, you can execute the resulting program with "./main" or "./a.out". On Windows, you can run the program with "main" or "a.out".(?)

To help make a transition from DMD to GDC easier, there is a script called 'gdmd' which maps DMD's command line options to GDC. To see the available options for gdmd, type 'gdmd' or 'gdmd -help' on the command line.


Command line switches

A list of the available command line switches in GDC:

Switch Description
-I<dir> Add <dir> to the end of the main include path.
-J<dir> Add <dir> to the end of the string import path.
-fdeprecated Allow use of deprecated features.
-fassert Generate runtime code for assert()'s
-frelease Compile release version
-f[no-]bounds-check Controls array bounds checking
-funittest Compile in unittest code
-fversion=<level/ident> Compile in version code >= <level> or identified by <ident>
-fdebug,-fdebug=<level>,-fdebug=<ident> Compile in debug code, code <= level, or code identified by ident
-fdebug Compile in debug code
-fdebug-c With -g, generate C debug information for debugger compatibility
-fdeps=<filename> Write module dependencies to filename
-fd-verbose Print information about D language processing to stdout
-fd-version=1 Compile as D language version 1
-f[no-]emit-templates Controls whether or not template code is emitted.
-f[no-]emit-moduleinfo Controls whether or not ModuleInfo is emitted.
-fall-sources For each source file on the command line, semantically process each file preceding it. Use this if compilation errors occur due to complicated circular module references. This will slow compilation noticeably
-nostdinc Do not search standard system include directories
-fonly= Process all modules specified on the command line, but only generate code for the module specified by the argument.
-fod=<directory> Specify the object output directory. Note: this is actually a driver option; the backend ignores it.
-fop Specify that the source file's parent directories should be appended to the object output directory. Note: this is actually a driver option; the backend ignores it.
-fignore-unknown-pragmas Ignore unsupported pragmas
-fintfc Generate D interface files
-fintfc-dir=<dir> Write D interface files to directory <dir>
-fintfc-file=<filename> Write D interface file to <filename>
-fdoc Generate documentation
-fdoc-dir=<docdir> Write documentation file to docdir directory
-fdoc-file=<filename> Write documentation file to filename
-fdoc-inc=<filename> Include a Ddoc macro file
-fmultilib-dir=<dir> Select header multilib subdirectory
-Wsign-compare Warn about signed-unsigned comparisons
-fdump-source Dump decoded UTF-8 text and source from HTML to <file>.utf-8 and <file>.d.utf-8
-fbuiltin Recognize built-in functions
-funsigned-char Make "char" unsigned by default (silently ignored in D)
-fsigned-char Make "char" signed by default (silently ignored in D)
-iprefix <path> Specify <path> as a prefix for next two options
-isysroot <dir> Set <dir> to be the system root directory
-isystem <dir> Add <dir> to the start of the system include path
-Wall Enable most warning messages
-Werror Error out the compiler on warnings


Many of the options in GCC may also be applicable to GDC, such as optimization flags, -O1, -O2, -Os, -O3, or flags such as -c, which compiles a file, but does not link it, and will send the object file to "main.o", if you file is main.d


Extensions

Extended Assembler

GDC implements a GCC extension that allows inline assembler with D expression operands. It is available on nearly all targets, not just i386. The syntax differs from the C language extension in the following ways:

  • Statements start with 'asm { ...', just like the regular DMD inline assembler.
  • It is not necesary to put parentheses around operands.
  • Instruction templates can be compile-time string constants, not just string literals. If the template is not a string literal, use parenthesis to indicate that it is not an opcode.

Unlike i386 inline assembler statements, extended assembler statements do not prevent a function from being inlined.

See the GCC manual for more information about this extension.

Example:

uint invert(uint v)
{
    uint result;
    version(X86)
       asm{ "notl %[iov]" : [iov] "=r" result : "0" v; }
    else version(PPC)
       asm{ "nor %[oresult],%[iv],%[iv]" : [oresult] "=r" result : [iv] "r" v; }
    return result;
}

Attributes

GDC supports a small subset of the GCC attributes. Please see the linked GCC attribute for details about an individual attribute.

GDC Attribute GCC Attribute
flatten flatten
forceinline* always_inline
noinline* noinline
target {Not sure how this relates to GCC attributes. If you know please update this wiki}
  • Being backend attributes, you can't enforce that these attributes actually take effect in user code (no static asserts!) - but you have some guarantee in that the backend will complain if it can't apply the attribute

Known Issues

See bugzilla to see bugs that have been reported to GDC.

More bugs may be found here.

Some more known issues, taken from here:

  • See DStress for known failing cases. (Again, may be irrelevant)
  • Debugging information may have a few problems. For D symbol name demangling you need at least gdb 7.2.
  • Some targets do not support once-only linking. A workaround is to manually control template emission. See the -femit-templates option below. For Darwin, Apple's GCC 3.x compiler supports one-only linking, but GDC does not build with those sources. There are no problems with the stock GCC 4.x on Darwin.
  • Complex floating point operations may not work the same as DMD.
  • Some math functions behave differently due to different implementations of the extended floating-point type.
  • Volatile statements may not always do the right thing.
  • Because of a problem on AIX, the linker will pull in more modules than needed.
  • Some C libraries (Cygwin, MinGW, AIX) don't handle floating-point formatting and parsing in a standard way.