Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

Handles target-specific parameters
In order to allow for cross compilation, when the compiler produces a binary for a different platform than it is running on, target information needs to be abstracted. This is done in this module, primarily through Target.

Note While DMD itself does not support cross-compilation, GDC and LDC do. Hence, this module is (sometimes heavily) modified by them, and contributors should review how their changes affect them.


Source target.d

void addDefaultVersionIdentifiers(const ref Param params, const ref Target tgt);
Add default version identifier for dmd, and set the target platform in params.
Needs to be run after all arguments parsing (command line, DFLAGS environment variable and config file) in order to add final flags (such as X86_64 or the CRuntime used).
Param params which target to compile for (set by setTarget())
Target tgt target
struct Target;
Describes a back-end target. At present it is incomplete, but in the future it should grow to contain most or all target machine and target O/S specific information.
In many cases, calls to sizeof() can't be used directly for getting data type sizes since cross compiling is supported and would end up using the host sizes rather than the target sizes.
enum OS: ubyte;
Bit decoding of the Target.OS
ubyte ptrsize;
size of a pointer in bytes
ubyte realsize;
size a real consumes in memory
ubyte realpad;
padding added to the CPU real size to bring it up to realsize
ubyte realalignsize;
alignment for reals
ubyte classinfosize;
size of ClassInfo
ulong maxStaticDataSize;
maximum size of static data
TargetC c;
TargetCPP cpp;
TargetObjC objc;
Objective-C ABI
const(char)[] architectureName;
Architecture name
const(char)[] obj_ext;
extension for object files
const(char)[] lib_ext;
extension for static library files
const(char)[] dll_ext;
extension for dynamic library files
bool run_noext;
allow -run sources without extensions
struct FPTypeProperties(T);
Values representing all properties for floating point types
real_t max;
largest representable value that's not infinity
real_t min_normal;
smallest representable normalized value that's not 0
real_t nan;
NaN value
real_t infinity;
infinity value
real_t epsilon;
smallest increment to the value 1
long dig;
number of decimal digits of precision
long mant_dig;
number of bits in mantissa
long max_exp;
maximum int value such that 2max_exp-1 is representable
long min_exp;
minimum int value such that 2min_exp-1 is representable as a normalized value
long max_10_exp;
maximum int value such that 10max_10_exp is representable
long min_10_exp;
minimum int value such that 10min_10_exp is representable as a normalized value
FPTypeProperties!float FloatProperties;
FPTypeProperties!double DoubleProperties;
FPTypeProperties!real_t RealProperties;
void _init(const ref Param params);
Initialize the Target
@safe Target.ObjectFormat objectFormat();
Determine the object format to be used
@safe void setCPU();
Determine the instruction set to be used
@safe void deinitialize();
Deinitializes the global state of the compiler.
This can be used to restore the state set by _init to its original state.
uint alignsize(Type type);
Requested target memory alignment size of the given type.
Type type type to inspect
alignment in bytes
uint fieldalign(Type type);
Requested target field alignment size of the given type.
Type type type to inspect
alignment in bytes
Type va_listType(const ref Loc loc, Scope* sc);
Type for the va_list type for the target; e.g., required for _argptr declarations.

NOTE For Posix/x86_64 this returns the type which will really be used for passing an argument of type va_list.

Type that represents va_list.
@safe int isVectorTypeSupported(int sz, Type type);
Checks whether the target supports a vector type.
int sz vector type size in bytes
Type type vector element type
0 vector type is supported, 1 vector type is not supported on the target at all 2 vector element type is not supported 3 vector size is not supported
bool isVectorOpSupported(Type type, EXP op, Type t2 = null);
Checks whether the target supports the given operation for vectors.
Type type target type of operation
EXP op the unary or binary op being done on the type
Type t2 type of second operand if op is a binary operation
true if the operation is supported or type is not a vector
@safe LINK systemLinkage();
Default system linkage for the target.
LINK to use for extern(System)
TypeTuple toArgTypes(Type t);
Describes how an argument type is passed to a function on target.
Type t type to break down
tuple of types if type is passed in one or more registers empty tuple if type is always passed on the stack null if the type is a void or argtypes aren't supported by the target
bool isReturnOnStack(TypeFunction tf, bool needsThis);
Determine return style of function - whether in registers or through a hidden pointer to the caller's stack.
TypeFunction tf function type to check
bool needsThis true if the function type is for a non-static member function
true if return value from function is on the stack
bool preferPassByRef(Type t);
Decides whether an in parameter of the specified POD type is to be passed by reference or by value. To be used with -preview=in only!
Type t type of the in parameter, must be a POD
true if the in parameter is to be passed by reference
Expression getTargetInfo(const(char)* name, const ref Loc loc);
Get targetInfo by key
const(char)* name name of targetInfo to get
Loc loc location to use for error messages
Expression for the requested targetInfo
@safe bool isCalleeDestroyingArgs(TypeFunction tf);
TypeFunction tf type of function being called
true if the callee invokes destructors for arguments.
bool libraryObjectMonitors(FuncDeclaration fd, Statement fbody);
Returns true if the implementation for object monitors is always defined in the D runtime library (rt/monitor_.d).
FuncDeclaration fd function with synchronized storage class.
Statement fbody entire function body of fd
false if the target backend handles synchronizing monitors.
const @safe bool supportsLinkerDirective();
Returns true if the target supports pragma(linkerDirective).
false if the target does not support pragma(linkerDirective).
@safe bool isXmmSupported();
true if xmm usage is supported
const nothrow @nogc @property scope @safe bool isPOSIX();
true if generating code for POSIX
@safe uint stackAlign();
alignment of the stack
struct TargetC;
Functions and variables specific to interfacing with extern(C) ABI.
bool crtDestructorsSupported;
Not all platforms support crt_destructor
ubyte boolsize;
size of a C _Bool type
ubyte shortsize;
size of a C short or unsigned short type
ubyte intsize;
size of a C int or unsigned int type
ubyte longsize;
size of a C long or unsigned long type
ubyte long_longsize;
size of a C long long or unsigned long long type
ubyte long_doublesize;
size of a C long double
ubyte wchar_tsize;
size of a C wchar_t type
Runtime runtime;
vendor of the C runtime to link against
BitFieldStyle bitFieldStyle;
different C compilers do it differently
struct TargetCPP;
Functions and variables specific to interface with extern(C++) ABI.
bool reverseOverloads;
set if overloaded functions are grouped and in reverse order (such as in dmc and cl)
bool exceptions;
set if catching C++ exceptions is supported
bool twoDtorInVtable;
target C++ ABI puts deleting and non-deleting destructor into vtable
bool splitVBasetable;
set if C++ ABI uses separate tables for virtual functions and virtual bases
bool wrapDtorInExternD;
set if C++ dtors require a D wrapper to be callable from runtime
Runtime runtime;
vendor of the C++ runtime to link against
const(char)* toMangle(Dsymbol s);
Mangle the given symbol for C++ ABI.
Dsymbol s declaration with C++ linkage
string mangling of symbol
const(char)* typeInfoMangle(ClassDeclaration cd);
Get RTTI mangling of the given class declaration for C++ ABI.
ClassDeclaration cd class with C++ linkage
string mangling of C++ typeinfo
const(char)* thunkMangle(FuncDeclaration fd, int offset);
Get mangle name of a this-adjusting thunk to the given function declaration for C++ ABI.
FuncDeclaration fd function with C++ linkage
int offset call offset to the vptr
string mangling of C++ thunk, or null if unhandled
const(char)* typeMangle(Type t);
Gets vendor-specific type mangling for C++ ABI.
Type t type to inspect
string if type is mangled specially on target null if unhandled
Type parameterType(Type t);
Get the type that will really be used for passing the given argument to an extern(C++) function, or null if unhandled.
Type t type to be passed.
Type to use for type t.
bool fundamentalType(const Type t, ref bool isFundamental);
Checks whether type is a vendor-specific fundamental type.
Type t type to inspect
bool isFundamental where to store result
true if isFundamental was set by function
uint derivedClassOffset(ClassDeclaration baseClass);
Get the starting offset position for fields of an extern(C++) class that is derived from the given base class.
ClassDeclaration baseClass base class with C++ linkage
starting offset to lay out derived class fields
struct TargetObjC;
Functions and variables specific to interface with extern(Objective-C) ABI.
bool supported;
set if compiler can interface with Objective-C
Target target;