Files
ldc/glue.c
Alexey Prokhin f2237662df Squashed 'dmd2/' changes from 10017d5..3443f38
3443f38 Fix issue 7493  Initialization of void[][N]
0b371da foreach can run semantic again
7216e2a fix Issue 7735 - Functions with variadic void[][]... arguments corrupt passed data
4fb2b2a Merge pull request #850 from 9rnsr/fix7773
9c59931 Merge pull request #851 from donc/ctfe7785pointerToVar
407f7e4 Merge pull request #852 from donc/segfault7639
9370f83 Fix issue 7380 Crash trying to use address of variable in struct constructor at module level
240866b Fix issue 7639 Undefined enum AA key crashes compiler
19b7096 Fix issue 7785 [CTFE] ICE when slicing pointer to variable
d9b11f6 fix Issue 7773 - UCFS syntax on built-in attributes too?
296d812 Merge pull request #846 from donc/ctfe7781segfault
65aca2d Merge pull request #848 from donc/regression7751
5576737 Merge pull request #849 from donc/bug7794
0310838 Merge pull request #828 from 9rnsr/fix7751
4027e4f Fix issue 7794 Sea of errors when calling regex() after compile error
59cc12d Fix issue 7781 [CTFE] Segmentation fault on 'mixin({return;}());'
3430947 fix seg fault in fail91.d
948274e Merge pull request #824 from donc/regression7745
22ac4b1 Merge pull request #826 from 9rnsr/fix6659
1c15841 Merge pull request #823 from redstar/mscclean
5f54752 Merge pull request #827 from 9rnsr/fix7694
399e4a3 Merge pull request #844 from donc/regression7782
516f49b Fix issue 7789 [CTFE] null pointer exception on setting array length
d74b354 Fix issue 7782 Regression: ICE with wrong import syntax
0269194 Fix issue 7751 [ICE] (Regression 2.059head) From auto and forward reference
42ad236 Merge pull request #830 from 9rnsr/fix_ufcs
67bf025 Merge pull request #832 from 9rnsr/fix7608
d13f107 Merge pull request #829 from 9rnsr/fix7754
e25cbe2 Merge pull request #834 from 9rnsr/fix2367
7fac235 merge D2 pull #842
c836773 Merge pull request #836 from 9rnsr/fix7757
a2754c5 Merge pull request #839 from 9rnsr/fix7768
4948836 fix Issue 7694 - Internal error: e2ir.c 1251 when calling member function inside struct via alias param
9f23335 Merge pull request #838 from 9rnsr/fix7621
92eba60 Merge pull request #840 from 9rnsr/fix7769
8fae3c2 fix issue 7742 - 'More initializers than fields' error with correct number of fields
6c2d706 to enum
35e4f08 fix Issue 7769 - relax inout rule doesn't work for template function
96a0105 fix Issue 7768 - More readable template error messages
8012d58 Merge pull request #831 from 9rnsr/fix7743
9c0cbdd fix Issue 7621 - Immutable type equivalence problem
f67f313 Merge pull request #833 from 9rnsr/fix7731
29754dd Merge pull request #837 from braddr/cleanup-backend2
374109a restore original binary() function and re-fix the new version
78c04aa fix Issue 7757 - Inout function with lazy inout parameter doesn't compile
50c34e9 fix Issue 7754 - static this() in template is stripped during header gen
11acdff Fix auto tester breaking.
f0b7157 fix Issue 7755 - regression(2.059head): ICE in glue.c
cfceb77 fix Issue 7751 - [ICE] From auto and forward reference
7a86807 fix Issue 2367 - Overloading error with string literals
6039c40 fix Issue 7731 - Assertion failure: 't' on line 7911 in file 'mtype.c'
aea3a39 fix Issue 7608 - __traits(allMembers) is broken
f46f07a fix Issue 7743 - Parsing problem with nothrow delegate
fa9d29f Revert "Revert "Refactor for UFCS property getter/setter resolution.""
d9698d8 Revert "Revert "fix Issue 7722 - Refuse normal functions to be used as properties""
0fbc772 Revert "Revert "Allow property function has two arguments""
07a3b09 fix Issue 6659 - Destructor in range foreach called after initialization
e499d4d Fix issue 7745 Regression(2.059beta) Methods defined in external object files when a pointer to it is taken
79a74e1 Fixes an unknown pragma warning.
2b12052 Fix issue 176 [module] message "module and package have the same name"
90e89a4 Merge pull request #814 from 9rnsr/fix7713
3ab0e79 Merge pull request #818 from donc/assoc7732
b3360e9 Fix issue 7732 [CTFE] wrong code for a struct called AssociativeArray
05f0b08 Merge pull request #779 from 9rnsr/fix7534
867e567 Revert "Allow property function has two arguments"
9171aeb Revert "fix Issue 7722 - Refuse normal functions to be used as properties"
989ced7 Revert "Refactor for UFCS property getter/setter resolution."
e9b5292 Refactor for UFCS property getter/setter resolution.
761d000 fix Issue 7722 - Refuse normal functions to be used as properties
9f5956b Allow property function has two arguments
1a11862 Revert "Allow property function has two arguments"
32f57e5 Revert "fix Issue 7722 - Refuse normal functions to be used as properties"
6489bb4 Revert "Refactor for UFCS property getter/setter resolution."
214296f Merge pull request #817 from 9rnsr/fix_ufcs
c3c7f2a Merge pull request #816 from donc/voidctfe6438
185d031 Refactor for UFCS property getter/setter resolution.
08bf89d fix Issue 7722 - Refuse normal functions to be used as properties
f0e3433 Allow property function has two arguments
1b67ac9 Direct check by Type::reliesOnTident
a3cd7d9 fix Issue 7713 - lambda inference doesn't work on template function argument
1762112 Fix issue 6438 - [CTFE] wrong error "value used before set" when slicing =void array
ace1eca fix complex constant folding
76f9b22 Consider return type covariance.
f700dbc fix Issue 7534 - Allow attribute-overloading of an overridden method
cba8f5c Merge pull request #763 from 9rnsr/fix7578
392d93f Merge pull request #815 from dawgfoto/fixSegFault
e48aba2 merge part of pull #769
d72a17e revert dd5a543
24d860b error(Loc loc,) doesn't abort program
4c79117 Use correct opcodes for moving cfloat from st->xmm and xmm->st
af875ff Merge pull request #785 from braddr/cleanup-backend2
9d3021a remove debugging printfs
b3df5ee Merge pull request #807 from dawgfoto/fix7698
f005537 Merge pull request #802 from dawgfoto/fixVC
65a145d Merge pull request #803 from donc/ctfeunion6681yebblies
1cf39ca Merge pull request #812 from 9rnsr/fix_ufcs
d846c3c Merge pull request #808 from 9rnsr/fix7702
fd0a492 fix Issue 7670 - UFCS problem with @property and structs
1ad35b2 Fix for UFCS with property syntax, and add exhaustive test
96f15a1 Resolve broken build after merging
4712aab fix regression
4e05482 Merge pull request #805 from donc/regression7681
245a107 dt_ functions aren't x86 specific
b35f43a another missing loc in an error() call
001addb minor cleanups
2fb1e46 make util_assert take a const string
907da39 cleanup whitespace in binary(), add binary() that takes the length of the string to search for
59d0425 Merge pull request #804 from braddr/nearsighted
d725eed Merge pull request #806 from donc/ctfe7633equalmsg
12a5c26 Merge pull request #811 from donc/bug7699
4279d5e revert the revert
c895c3b revert pull #809
865fb20 fix Issue 5733 - Calling opDispatch As Template Results in Compiler Infinite Loop
96e16d3 fix Issue 7702 - opDispatch goes into infinite loop
5e343c0 Remove special case for DotIdExp and opDispatch semantic, it isn't need anymore
1a9d607 Fix issue 7699 - Cannot get frame pointer to in contract when compiling with -inline
d1476eb Merge pull request #809 from 9rnsr/fix_funclit
afc7c60 allow out-of-order semantic analysis of fields
17da3a0 fix Issue 7705 - lambda syntax doesn't allow some valid signatures
e29d06d fix issue 7698
911d053 Fix issue 7633 - Missing CTFE error message
3802dde Fix issue 7681 Regression(2.059head):ICE:opCatAssign(delegate) to undefined identifier
8da4121 near-ectomy
cd6dc83 fix Library::error()s format string to take a const char*
f3f03c6 switch to apply()
faf873a fix Issue 3510 - Cannot forward reference a templated type from within a template mixin
23aa2be fix Issue 3509 - Cannot forward reference a template mixin's members in a compile-time context
e81309b Add missing 'loc' to error message.
b6898e3 Fix issue 6681 - struct constructor call is converted to struct literal that breaks union initialization
b79afba long double => longdouble
e48c319 Merge pull request #742 from yebblies/issue5879
d74485a Merge pull request #787 from eco/ddoc-srcfilename
3038cb9 Merge pull request #795 from dawgfoto/fixComment
89a039a Merge pull request #801 from dawgfoto/fix4507
c17c2d8 fix issue 4507
dd86c72 Merge pull request #796 from dawgfoto/fixVC
a516588 Merge pull request #797 from 9rnsr/fix7682
1b9839a Merge pull request #799 from 9rnsr/fix6982
4596774 Merge pull request #800 from 9rnsr/fix_type_deduction
b68d546 forgot about @system
bfe1083 add attributes to toHash
8f819d6 Stop special case in mutableOf/makeMutable with inout type.
319b1a3 Fix the lacks of type merging in Type::mutableOf() and uhSharedOf()
cfe7450 fix Issue 7671 - Broken inout deduction of shared(inout(T[n])) from immutable(int[3])
aca5c37 Stop too eager call of TypeAArray::getImpl() When implicitConvTo(non aa Tstruct => Taarray)
50b2a97 fix Issue 6982 - immutability isn't respected on associative array assignment
a5daa5e fix Issue 7684 - IFTI and shared overload doesn't work
e43fbac fix Issue 7682 - shared array type and "cast() is not an lvalue" error
8191801 cpp_prettyident only needed for C++
4487f75 fix ldval
525647c tparam is the specialization
f893925 fix issue 7592 d847c1c2dd
108b25d Merge pull request #780 from 9rnsr/fix7641
105a51f Merge pull request #784 from 9rnsr/fix7110
8b5b67f Merge pull request #792 from donc/bug7667
f72f237 fix Issue 3682 - Regression(2.038) is expression fails to match types
436b711 Fix issue 7667. ICE(interpret.c): 'ctfeStack.stackPointer() == 0'
9005276 Merge pull request #679 from yebblies/issue783
350a3ce Merge pull request #582 from 9rnsr/fix3382_ufcs
5f020c3 Merge pull request #788 from braddr/cleanup-backend3
6aa91cf Merge pull request #790 from p0nce/master
351d595 remove tls bracketing
a137d72 Fix bug #6391
6ce219c remove some of the bracketing
aec4c13 fix Issue 7578 - ICE on indexing result of vararg opDispatch
95e3dc1 Fix unintended infinite loop in Phobos build
b66196a fix Issue 3382 - [tdpl] Implement uniform function call syntax
ee2fe6c Fix 977 is with counting end-of-lines towards msot advanced lexer peeking
7790b16 fix Issue 7650 - Bad lambda inference in associative array literal
c03484e fix Issue 7649 - Bad lambda inference in default function argument
f293a10 fix Issue 7499 - [ICE] ('cast.c line 1495) with lambda array
9f0622c Expression::inferType() and remove FuncExp::setType()
cfc67b7 refactor lambda inference process
6d49586 more de-TX86'ing in relation to a bunch of OP codes
2efbf6a TX86-ectomy in evalu8.c
953f6d7 rip TX86 conditionals out of el.c
d5663c7 fix Issue 7595 - Data being overwritten.
449c165 Add predefined Ddoc macro SRCFILENAME
5c5da66 fix uninitialized field
29cde54 Merge pull request #783 from 9rnsr/fix7038
06d65ab fix Issue 7038 - Type mismatch with const struct
b77e2c9 fix Issue 7110 - opSlice() & opIndex functions works unstable as template arguments
a65f02f Merge pull request #781 from braddr/fix
08d6cd5 Merge pull request #782 from braddr/fixiasm
2492332 fix latent bug with Lexer::peek and recently introduced bug in Lexer::scan
ec1888e initialize popndTmp rather than rely on carefulness when usNumops == 0 and emitting a vector instruction, popndTmp is left uninitialized and is later dereferenced.
1d4a742 Merge pull request #766 from 9rnsr/fix7563
e1cd535 refactor
90f8dcf fix Issue 7641 - std.typecons.Proxy incorrectly allows implicit conversion to class
83a93cf Merge pull request #778 from dawgfoto/MoreSpellCorrection
7f0bcde 2nd go at fix issue 5590
567d7df fix Issue 5590 - Regression(2.036) ICE(e2ir.c): when using .values on enum which is associative array
48ea951 fix Issue 4820 - Regression(1.058, 2.044) in DStress caused by changeset 452
e8f9f3b more spell correction
afd9a45 fix Issue 7618 - delegate/function pointer call bypass parameter storage class
dabcdfb Merge pull request #773 from 9rnsr/fix7583
9846bb2 Merge pull request #774 from donc/ctfe7568
8c20445 Merge pull request #775 from donc/_error6785
d41e58e Avoiding shallow copy is more better.
cccef09 Revert "fix Issue 7585 - functions in templates inferred as delegate"
fc8dfc0 6785 Wrong error message from pragma(msg) of failed instantiation
61ec04d 7568 pragma(msg) segfaults with an aggregate including a class.
4d86d39 Merge pull request #767 from 9rnsr/fix7585
207d351 fix Issue 7583 - [CTFE] ICE with tuple and alias this
53bafa2 fix Issue 7411 - Deduce base type from vector types in templates
5ab1bd9 fix Issue 7518 - std.array.empty doesn't work for shared arrays
a1030d3 fix Issue 7554 - Immutable function pointer arguments too
5e96900 Merge pull request #771 from donc/bug7589
2287ebc fix Issue 7547 - -deps output lists object as a top level module
e611781 7589 __traits(compiles) does not work with a template that fails to compile
0113cde fix Issue 7585 - functions in templates inferred as delegate
4b978d5 fix Issue 7563 - Class members with default template arguments have no type
4d68981 fix Issue 7500 - [ICE] (template.c line 5287) with immutable lambda function
1a39c3c missed a line
6dd89ca Merge pull request #765 from 9rnsr/fix7525
8d6dcac fix Issue 7502 - 2.056 regression: Assigning .init takes forever to compile for large structs
042096e fix Issue 7525 - Broken return type inference for delegate returns
c5affa5 fix Issue 7582 - Untyped nested delegate literals don't compile
121677c fix Issue 7580 - Identity assignment of Nullable crashes dmd
adc0502 Small refactoring to resolve alias this.
1f52383 Merge pull request #671 from yebblies/issue4958
2a12345 fix build breakage
8755819 fix build
ba86204 fix vcbuild
464c664 fix linux build
31197c8 tweaked command line moved some inline asm to C-function to not interfere with optimizations build with VS2011
4dcdc9c increase stack size for win64 build
77262aa add missing include to root
56afe3f batch to build through win32.mak
5a0fd30 build through win32.mak
a5b5190 long_double -> longdouble remove C99 printf add Win64 support
9640110 vcbuild
b619171 Merge pull request #761 from donc/ctfe7473structref
7756328 Merge pull request #725 from kennytm/bug7399-import-too-fatal
bbac9e4 Merge pull request #759 from yebblies/issue1149
d1ff23b 7473 [CTFE] Non-ref argument behaves as if it's a ref argument
ab5cb18 Fix OPmsw codegen - integer only is too restrictive.
a00833b Merge pull request #743 from yebblies/issue3354
b006e11 Merge pull request #757 from 9rnsr/fix7562
3bccbb0 fix Issue 7562 - DMD crashes by using TemplateThisParameter
a7dc50e Merge pull request #749 from yebblies/issue1149
a873c5f Merge pull request #758 from 9rnsr/fix5525
5d639ec fix Issue 5525 - Eponymous templates should allow for overloaded eponymous members
f50852c Merge pull request #729 from donc/gag4269
de02523 fix Issue 3927 - array.length++; is an error, but ++array.length compiles
1dc5bfd Merge pull request #680 from yebblies/issue3812
cf887ba move errors to Dsymbol
fc4acf5 Merge pull request #755 from donc/seaOfErrors7557
be2f3a9 7557b soldier on through dottemplate expressions
8cec825 7557 Sea of errors after template failure
37ec6d6 A small fixup to call Type::defaultInitLiteral
7b5e2cb Revert "Revert "Merge pull request #41 from 9rnsr/rvalue-struct-literal""
3d8f09a Merge branch 'master' of github.com:D-Programming-Language/dmd
7dfb4cc Merge pull request #752 from braddr/cleanup-backend2
1b28f51 Merge branch 'master' of github.com:D-Programming-Language/dmd
31ad73c Merge pull request #746 from yebblies/issue5554
25f770d Change lexer to support # as a token, preserving #line's original behavior
dd8d20a Revert "Merge pull request #41 from 9rnsr/rvalue-struct-literal"
ee2fdf9 Merge pull request #41 from 9rnsr/rvalue-struct-literal
f94fdbf Merge pull request #750 from yebblies/issue3630
61f5fcf Improve codegen for OPmsw
05a3fa4 Merge pull request #744 from Safety0ff/avx-fix
0231d6a Merge pull request #748 from 9rnsr/fix7552
9a97979 Merge pull request #751 from donc/ctfe7536
e091e6e 7536 ctfeAdrOnStack triggered
c9edaf4 fix Issue 7552 - Cannot get and combine a part of overloaded functions
1edeba9 Fix Issue 3630 - bad error location in "has no effect in expression" error
7d0fb72 Fix Issue 5554 - [qtd] Covariance detection failure
4f36aca fix Issue 7550 - Missing AVX instruction VPMULDQ
0b82dfe Fix Issue 5879 - Not all frontend errors use stderr
963a41a Merge pull request #695 from yebblies/refactor_expression
3f06690 Fix Issue 3354 - asm fld x, ST(6); accepted
713f69f Merge pull request #677 from yebblies/issue4241
cf22ce3 Merge pull request #711 from yebblies/issue3559
56ca73c Merge pull request #700 from kennytm/bug7452_lazy_safe
c4dc723 Merge pull request #736 from ibuclaw/in_gcc
121c9b9 Merge pull request #737 from yebblies/issue7544
cedcb3c Merge pull request #740 from yebblies/issue7545
fb3e8f2 Merge pull request #741 from dawgfoto/DMCWarning
5d26c1e Merge pull request #735 from 9rnsr/fix7105
734a921 dmc warning
1e1cfbc Fix Issue 7545 - ICE(cast.c) Merge integral types through alias this
6b135be Fix Issue 7544 - ICE(interpret.c) Catching an exception with a null catch block
c5336f9 Update already existing gdc-specific code, harmonise headers.
44b8d59 Merge pull request #703 from kennytm/bug435_template_ctor
6b368e1 Merge pull request #707 from yebblies/issue3822
8439e07 Merge pull request #717 from yebblies/issue6611
2b4502e fix Issue 7105 - relax inout rules
ac4463a wildsubparam isn't need anymore, because it works properly.
f77879a Issue 6611 - better error message for array post increment/decrement
7393395 Merge pull request #716 from yebblies/issue6685
77568f0 Merge pull request #719 from yebblies/issue4536
9accb04 tired of tdata()
5fbd5a2 Merge pull request #732 from dawgfoto/fix5412
41a901a Revert "hide private/package module level symbols"
23d5e14 Merge pull request #733 from dawgfoto/HideModuleMembers
e2f8a23 hide private/package module level symbols
ae75287 detect collisions with renamed imports
75a2442 fix Dsymbol::search_correct
50e122a Merge pull request #723 from kennytm/bug7504_null_array
c5b7601 Revert "fix 7494 - selective imports in function scope"
aa6f4d9 Revert "fix Protection"
5be660e Revert "fix Imports"
040371b Revert "detect collisions with renamed imports"
0159818 Revert "find private symbols during spell correction"
0c95c45 find private symbols during spell correction
ca22fb2 detect collisions with renamed imports
0dca0af fix Imports
37d4fda fix Protection
16a2e7e fix 7494 - selective imports in function scope
c16f5b2 Merge pull request #667 from 9rnsr/fix7406
f776617 explanatory comments belong in the code, not bugzilla
bfa2060 Merge pull request #704 from donc/_error6699
f46705c fix fail222 regression
28d9635 Merge pull request #708 from donc/soldieron7481
2c2a7af Merge pull request #715 from 9rnsr/fix6738
98cfa64 Merge pull request #722 from 9rnsr/fix7353
b040567 revert pull 724
0e84f63 revert part of pull 724
400f702 Merge pull request #724 from yebblies/issue3632
d82cc74 Merge pull request #720 from yebblies/issue3279
2da3bed Merge pull request #718 from yebblies/fixdebugmsg
f6627ec 7527 [CTFE] Segfault when slicing a pointer at compile time
c8f09bf 4269a Regression(2.031): invalid type accepted if evaluated while errors are gagged
d10fba0 implement const/purity/nothrow/@safe inheritance
ad689fb Fix bug 7399: Broken import statement in trySemantic() causes silent compiler error
eb0c643 Add global.speculativeGag
c18220a Refactor isSpeculativeFunction into Dsymbol
f5c56d8 Issue 3632 - modify float is float to do a bitwise compare
af1cab4 Issue 7353 - NRVO not properly working with inferred return type
03ee438 Fix bug 7504: Cannot assign an object of type 'typeof(null)' to an array
dfb941c Remove debug printing in code that generates errors.
62118e3 Issue 4536 - Typetuples (T...) should have an .init member
989da7b Issue 3279 - Confusing error message when comparing types
36e8045 Issue 6685 - Allow using "with" with rvalues
60cbc6f fix issue 6738 revisited
4e20e7d Issue 3822 - Invalid optimization of alloca called with constant size
b37bf8c Fixes bug 435: Constructors should be templatized
ad8157d Issue 3559 - DMD 1.048+ fails to take function pointer from overloaded member functions
838cd06 7481 Compiler should 'soldier on' after template errors
673063e Simplify fix for 6699
1a0b199 6699a __error when instantiating function template
b6d072d 6699b __error in alias expression
df16ffa 6699c __error in synchronized error message
338f804 7462 Error message with _error_ in overridden function
0f60bd3 7463 Duplicated error message with bad template value parameter
f43e93a 6699E: _error inside error msg for bad base class
5109a5a Fixes bug 7452.
04d888f Refactor XxxAssignExp semantic
73973d6 Issue 3812 - Missing line number for implicit cast of variadic function to array
f0bbf18 Issue 3927 - array.length++; is an error, but ++array.length compiles
24576c2 Issue 783 - Cannot use an array w/ const or variable index as new[] size argument.
7e4cd4b Issue 4241 - duplicate union initialization error doesn't give a file location
9987127 Issue 4958 - Floating point enums should check for total loss of precision
60287fd Issue 7406 - tuple foreach doesn't work with mixed tuples
633d88e Issue 5889 - Struct literal/construction should be rvalue
5d5f78a Now function overloading with ref and non-ref parameter is legal for struct type

git-subtree-dir: dmd2
git-subtree-split: 3443f38fc4c17807a0f36005a05d598cfc7301db
2012-04-05 11:45:25 +04:00

1260 lines
33 KiB
C

// Compiler implementation of the D programming language
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
#include <stdio.h>
#include <stddef.h>
#include <time.h>
#include <assert.h>
#if __sun&&__SVR4
#include <alloca.h>
#endif
#include "mars.h"
#include "module.h"
#include "mtype.h"
#include "declaration.h"
#include "statement.h"
#include "enum.h"
#include "aggregate.h"
#include "init.h"
#include "attrib.h"
#include "id.h"
#include "import.h"
#include "template.h"
#include "lib.h"
#include "rmem.h"
#include "cc.h"
#include "global.h"
#include "oper.h"
#include "code.h"
#include "type.h"
#include "dt.h"
#include "cgcv.h"
#include "outbuf.h"
#include "irstate.h"
struct Environment;
Environment *benv;
void slist_add(Symbol *s);
void slist_reset();
void clearStringTab();
#define STATICCTOR 0
typedef ArrayBase<symbol> symbols;
elem *eictor;
symbol *ictorlocalgot;
symbols sctors;
StaticDtorDeclarations ectorgates;
symbols sdtors;
symbols stests;
symbols ssharedctors;
SharedStaticDtorDeclarations esharedctorgates;
symbols sshareddtors;
int dtorcount;
int shareddtorcount;
char *lastmname;
/**************************************
* Append s to list of object files to generate later.
*/
Dsymbols obj_symbols_towrite;
void obj_append(Dsymbol *s)
{
obj_symbols_towrite.push(s);
}
void obj_write_deferred(Library *library)
{
for (size_t i = 0; i < obj_symbols_towrite.dim; i++)
{ Dsymbol *s = obj_symbols_towrite.tdata()[i];
Module *m = s->getModule();
char *mname;
if (m)
{ mname = m->srcfile->toChars();
lastmname = mname;
}
else
{
//mname = s->ident->toChars();
mname = lastmname;
assert(mname);
}
obj_start(mname);
static int count;
count++; // sequence for generating names
/* Create a module that's a doppelganger of m, with just
* enough to be able to create the moduleinfo.
*/
OutBuffer idbuf;
idbuf.printf("%s.%d", m ? m->ident->toChars() : mname, count);
char *idstr = idbuf.toChars();
idbuf.data = NULL;
Identifier *id = new Identifier(idstr, TOKidentifier);
Module *md = new Module(mname, id, 0, 0);
md->members = new Dsymbols();
md->members->push(s); // its only 'member' is s
if (m)
{
md->doppelganger = 1; // identify this module as doppelganger
md->md = m->md;
md->aimports.push(m); // it only 'imports' m
md->massert = m->massert;
md->munittest = m->munittest;
md->marray = m->marray;
}
md->genobjfile(0);
/* Set object file name to be source name with sequence number,
* as mangled symbol names get way too long.
*/
char *fname = FileName::removeExt(mname);
OutBuffer namebuf;
unsigned hash = 0;
for (char *p = s->toChars(); *p; p++)
hash += *p;
namebuf.printf("%s_%x_%x.%s", fname, count, hash, global.obj_ext);
namebuf.writeByte(0);
mem.free(fname);
fname = (char *)namebuf.extractData();
//printf("writing '%s'\n", fname);
File *objfile = new File(fname);
obj_end(library, objfile);
}
obj_symbols_towrite.dim = 0;
}
/***********************************************
* Generate function that calls array of functions and gates.
*/
symbol *callFuncsAndGates(Module *m, symbols *sctors, StaticDtorDeclarations *ectorgates,
const char *id)
{
symbol *sctor = NULL;
if ((sctors && sctors->dim) ||
(ectorgates && ectorgates->dim))
{
static type *t;
if (!t)
{
/* t will be the type of the functions generated:
* extern (C) void func();
*/
t = type_alloc(TYnfunc);
t->Tflags |= TFprototype | TFfixed;
t->Tmangle = mTYman_c;
t->Tnext = tsvoid;
tsvoid->Tcount++;
}
localgot = NULL;
sctor = m->toSymbolX(id, SCglobal, t, "FZv");
cstate.CSpsymtab = &sctor->Sfunc->Flocsym;
elem *ector = NULL;
if (ectorgates)
{
for (size_t i = 0; i < ectorgates->dim; i++)
{ StaticDtorDeclaration *f = (*ectorgates)[i];
Symbol *s = f->vgate->toSymbol();
elem *e = el_var(s);
e = el_bin(OPaddass, TYint, e, el_long(TYint, 1));
ector = el_combine(ector, e);
}
}
if (sctors)
{
for (size_t i = 0; i < sctors->dim; i++)
{ symbol *s = (*sctors)[i];
elem *e = el_una(OPucall, TYvoid, el_var(s));
ector = el_combine(ector, e);
}
}
block *b = block_calloc();
b->BC = BCret;
b->Belem = ector;
sctor->Sfunc->Fstartline.Sfilename = m->arg;
sctor->Sfunc->Fstartblock = b;
writefunc(sctor);
}
return sctor;
}
/**************************************
* Prepare for generating obj file.
*/
Outbuffer objbuf;
void obj_start(char *srcfile)
{
//printf("obj_start()\n");
rtlsym_reset();
slist_reset();
clearStringTab();
obj_init(&objbuf, srcfile, NULL);
el_reset();
#if TX86
cg87_reset();
#endif
out_reset();
}
void obj_end(Library *library, File *objfile)
{
obj_term();
if (library)
{
// Transfer image to library
library->addObject(objfile->name->toChars(), objbuf.buf, objbuf.p - objbuf.buf);
objbuf.buf = NULL;
}
else
{
// Transfer image to file
objfile->setbuffer(objbuf.buf, objbuf.p - objbuf.buf);
objbuf.buf = NULL;
char *p = FileName::path(objfile->name->toChars());
FileName::ensurePathExists(p);
//mem.free(p);
//printf("write obj %s\n", objfile->name->toChars());
objfile->writev();
}
objbuf.pend = NULL;
objbuf.p = NULL;
objbuf.len = 0;
objbuf.inc = 0;
}
/**************************************
* Generate .obj file for Module.
*/
void Module::genobjfile(int multiobj)
{
//EEcontext *ee = env->getEEcontext();
//printf("Module::genobjfile(multiobj = %d) %s\n", multiobj, toChars());
lastmname = srcfile->toChars();
obj_initfile(lastmname, NULL, toPrettyChars());
eictor = NULL;
ictorlocalgot = NULL;
sctors.setDim(0);
ectorgates.setDim(0);
sdtors.setDim(0);
ssharedctors.setDim(0);
esharedctorgates.setDim(0);
sshareddtors.setDim(0);
stests.setDim(0);
dtorcount = 0;
shareddtorcount = 0;
if (doppelganger)
{
/* Generate a reference to the moduleinfo, so the module constructors
* and destructors get linked in.
*/
Module *m = aimports.tdata()[0];
assert(m);
if (m->sictor || m->sctor || m->sdtor || m->ssharedctor || m->sshareddtor)
{
Symbol *s = m->toSymbol();
//objextern(s);
//if (!s->Sxtrnnum) objextdef(s->Sident);
if (!s->Sxtrnnum)
{
//printf("%s\n", s->Sident);
#if 0 /* This should work, but causes optlink to fail in common/newlib.asm */
objextdef(s->Sident);
#else
#if ELFOBJ || MACHOBJ
int nbytes = reftoident(DATA, Offset(DATA), s, 0, I64 ? (CFoff | CFoffset64) : CFoff);
#else
int nbytes = reftoident(DATA, Doffset, s, 0, CFoff);
Doffset += nbytes;
#endif
#endif
}
}
}
if (global.params.cov)
{
/* Create coverage identifier:
* private uint[numlines] __coverage;
*/
cov = symbol_calloc("__coverage");
cov->Stype = type_fake(TYint);
cov->Stype->Tmangle = mTYman_c;
cov->Stype->Tcount++;
cov->Sclass = SCstatic;
cov->Sfl = FLdata;
#if ELFOBJ || MACHOBJ
cov->Sseg = UDATA;
#endif
dtnzeros(&cov->Sdt, 4 * numlines);
outdata(cov);
slist_add(cov);
covb = (unsigned *)calloc((numlines + 32) / 32, sizeof(*covb));
}
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *member = members->tdata()[i];
member->toObjFile(multiobj);
}
if (global.params.cov)
{
/* Generate
* bit[numlines] __bcoverage;
*/
Symbol *bcov = symbol_calloc("__bcoverage");
bcov->Stype = type_fake(TYuint);
bcov->Stype->Tcount++;
bcov->Sclass = SCstatic;
bcov->Sfl = FLdata;
#if ELFOBJ || MACHOBJ
bcov->Sseg = DATA;
#endif
dtnbytes(&bcov->Sdt, (numlines + 32) / 32 * sizeof(*covb), (char *)covb);
outdata(bcov);
free(covb);
covb = NULL;
/* Generate:
* _d_cover_register(uint[] __coverage, BitArray __bcoverage, string filename);
* and prepend it to the static constructor.
*/
/* t will be the type of the functions generated:
* extern (C) void func();
*/
type *t = type_alloc(TYnfunc);
t->Tflags |= TFprototype | TFfixed;
t->Tmangle = mTYman_c;
t->Tnext = tsvoid;
tsvoid->Tcount++;
sictor = toSymbolX("__modictor", SCglobal, t, "FZv");
cstate.CSpsymtab = &sictor->Sfunc->Flocsym;
localgot = ictorlocalgot;
elem *e;
e = el_params(el_pair(TYdarray, el_long(TYsize_t, numlines), el_ptr(cov)),
el_pair(TYdarray, el_long(TYsize_t, numlines), el_ptr(bcov)),
toEfilename(),
NULL);
e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_DCOVER]), e);
eictor = el_combine(e, eictor);
ictorlocalgot = localgot;
}
// If coverage / static constructor / destructor / unittest calls
if (eictor || sctors.dim || ectorgates.dim || sdtors.dim ||
ssharedctors.dim || esharedctorgates.dim || sshareddtors.dim || stests.dim)
{
if (eictor)
{
localgot = ictorlocalgot;
block *b = block_calloc();
b->BC = BCret;
b->Belem = eictor;
sictor->Sfunc->Fstartline.Sfilename = arg;
sictor->Sfunc->Fstartblock = b;
writefunc(sictor);
}
sctor = callFuncsAndGates(this, &sctors, &ectorgates, "__modctor");
sdtor = callFuncsAndGates(this, &sdtors, NULL, "__moddtor");
#if DMDV2
ssharedctor = callFuncsAndGates(this, &ssharedctors, (StaticDtorDeclarations *)&esharedctorgates, "__modsharedctor");
sshareddtor = callFuncsAndGates(this, &sshareddtors, NULL, "__modshareddtor");
#endif
stest = callFuncsAndGates(this, &stests, NULL, "__modtest");
if (doppelganger)
genmoduleinfo();
}
if (doppelganger)
{
obj_termfile();
return;
}
if (global.params.multiobj)
{ /* This is necessary because the main .obj for this module is written
* first, but determining whether marray or massert or munittest are needed is done
* possibly later in the doppelganger modules.
* Another way to fix it is do the main one last.
*/
toModuleAssert();
toModuleUnittest();
toModuleArray();
}
#if 1
// Always generate module info, because of templates and -cov
if (1 || needModuleInfo())
genmoduleinfo();
#endif
// If module assert
for (int i = 0; i < 3; i++)
{
Symbol *ma;
unsigned rt;
unsigned bc;
switch (i)
{
case 0: ma = marray; rt = RTLSYM_DARRAY; bc = BCexit; break;
case 1: ma = massert; rt = RTLSYM_DASSERTM; bc = BCexit; break;
case 2: ma = munittest; rt = RTLSYM_DUNITTESTM; bc = BCret; break;
default: assert(0);
}
if (ma)
{
elem *elinnum;
localgot = NULL;
// Call dassert(filename, line)
// Get sole parameter, linnum
{
Symbol *sp = symbol_calloc("linnum");
sp->Stype = type_fake(TYint);
sp->Stype->Tcount++;
sp->Sclass = SCfastpar;
sp->Spreg = I64 ? DI : AX;
sp->Sflags &= ~SFLspill;
sp->Sfl = FLpara; // FLauto?
cstate.CSpsymtab = &ma->Sfunc->Flocsym;
symbol_add(sp);
elinnum = el_var(sp);
}
elem *efilename = el_ptr(toSymbol());
elem *e = el_var(rtlsym[rt]);
e = el_bin(OPcall, TYvoid, e, el_param(elinnum, efilename));
block *b = block_calloc();
b->BC = bc;
b->Belem = e;
ma->Sfunc->Fstartline.Sfilename = arg;
ma->Sfunc->Fstartblock = b;
ma->Sclass = SCglobal;
ma->Sfl = 0;
ma->Sflags |= rtlsym[rt]->Sflags & SFLexit;
writefunc(ma);
}
}
obj_termfile();
}
/* ================================================================== */
void FuncDeclaration::toObjFile(int multiobj)
{
FuncDeclaration *func = this;
ClassDeclaration *cd = func->parent->isClassDeclaration();
int reverse;
int has_arguments;
//printf("FuncDeclaration::toObjFile(%p, %s.%s)\n", func, parent->toChars(), func->toChars());
//if (type) printf("type = %s\n", func->type->toChars());
#if 0
//printf("line = %d\n",func->getWhere() / LINEINC);
EEcontext *ee = env->getEEcontext();
if (ee->EEcompile == 2)
{
if (ee->EElinnum < (func->getWhere() / LINEINC) ||
ee->EElinnum > (func->endwhere / LINEINC)
)
return; // don't compile this function
ee->EEfunc = func->toSymbol();
}
#endif
if (semanticRun >= PASSobj) // if toObjFile() already run
return;
// If errors occurred compiling it, such as bugzilla 6118
if (type && type->ty == Tfunction && ((TypeFunction *)type)->next->ty == Terror)
return;
if (!func->fbody)
{
return;
}
if (func->isUnitTestDeclaration() && !global.params.useUnitTests)
return;
if (multiobj && !isStaticDtorDeclaration() && !isStaticCtorDeclaration())
{ obj_append(this);
return;
}
assert(semanticRun == PASSsemantic3done);
semanticRun = PASSobj;
if (global.params.verbose)
printf("function %s\n",func->toChars());
Symbol *s = func->toSymbol();
func_t *f = s->Sfunc;
#if TARGET_WINDOS
/* This is done so that the 'this' pointer on the stack is the same
* distance away from the function parameters, so that an overriding
* function can call the nested fdensure or fdrequire of its overridden function
* and the stack offsets are the same.
*/
if (isVirtual() && (fensure || frequire))
f->Fflags3 |= Ffakeeh;
#endif
#if TARGET_OSX
s->Sclass = SCcomdat;
#else
s->Sclass = SCglobal;
#endif
for (Dsymbol *p = parent; p; p = p->parent)
{
if (p->isTemplateInstance())
{
s->Sclass = SCcomdat;
break;
}
}
/* Vector operations should be comdat's
*/
if (isArrayOp)
s->Sclass = SCcomdat;
if (isNested())
{
// if (!(config.flags3 & CFG3pic))
// s->Sclass = SCstatic;
f->Fflags3 |= Fnested;
}
else
{
const char *libname = (global.params.symdebug)
? global.params.debuglibname
: global.params.defaultlibname;
// Pull in RTL startup code
if (func->isMain())
{ objextdef("_main");
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
obj_ehsections(); // initialize exception handling sections
#endif
#if TARGET_WINDOS
objextdef("__acrtused_con");
#endif
obj_includelib(libname);
s->Sclass = SCglobal;
}
else if (strcmp(s->Sident, "main") == 0 && linkage == LINKc)
{
#if TARGET_WINDOS
objextdef("__acrtused_con"); // bring in C startup code
obj_includelib("snn.lib"); // bring in C runtime library
#endif
s->Sclass = SCglobal;
}
else if (func->isWinMain())
{
objextdef("__acrtused");
obj_includelib(libname);
s->Sclass = SCglobal;
}
// Pull in RTL startup code
else if (func->isDllMain())
{
objextdef("__acrtused_dll");
obj_includelib(libname);
s->Sclass = SCglobal;
}
}
cstate.CSpsymtab = &f->Flocsym;
// Find module m for this function
Module *m = NULL;
for (Dsymbol *p = parent; p; p = p->parent)
{
m = p->isModule();
if (m)
break;
}
IRState irs(m, func);
Dsymbols deferToObj; // write these to OBJ file later
irs.deferToObj = &deferToObj;
TypeFunction *tf;
enum RET retmethod;
symbol *shidden = NULL;
Symbol *sthis = NULL;
tym_t tyf;
tyf = tybasic(s->Stype->Tty);
//printf("linkage = %d, tyf = x%x\n", linkage, tyf);
reverse = tyrevfunc(s->Stype->Tty);
assert(func->type->ty == Tfunction);
tf = (TypeFunction *)(func->type);
has_arguments = (tf->linkage == LINKd) && (tf->varargs == 1);
retmethod = tf->retStyle();
if (retmethod == RETstack)
{
// If function returns a struct, put a pointer to that
// as the first argument
::type *thidden = tf->next->pointerTo()->toCtype();
char hiddenparam[5+4+1];
static int hiddenparami; // how many we've generated so far
sprintf(hiddenparam,"__HID%d",++hiddenparami);
shidden = symbol_name(hiddenparam,SCparameter,thidden);
shidden->Sflags |= SFLtrue | SFLfree;
#if DMDV1
if (func->nrvo_can && func->nrvo_var && func->nrvo_var->nestedref)
#else
if (func->nrvo_can && func->nrvo_var && func->nrvo_var->nestedrefs.dim)
#endif
type_setcv(&shidden->Stype, shidden->Stype->Tty | mTYvolatile);
irs.shidden = shidden;
this->shidden = shidden;
}
else
{ // Register return style cannot make nrvo.
// Auto functions keep the nrvo_can flag up to here,
// so we should eliminate it before entering backend.
nrvo_can = 0;
}
if (vthis)
{
assert(!vthis->csym);
sthis = vthis->toSymbol();
irs.sthis = sthis;
if (!(f->Fflags3 & Fnested))
f->Fflags3 |= Fmember;
}
Symbol **params;
unsigned pi;
// Estimate number of parameters, pi
pi = (v_arguments != NULL);
if (parameters)
pi += parameters->dim;
// Allow extra 2 for sthis and shidden
params = (Symbol **)alloca((pi + 2) * sizeof(Symbol *));
// Get the actual number of parameters, pi, and fill in the params[]
pi = 0;
if (v_arguments)
{
params[pi] = v_arguments->toSymbol();
pi += 1;
}
if (parameters)
{
for (size_t i = 0; i < parameters->dim; i++)
{ VarDeclaration *v = parameters->tdata()[i];
if (v->csym)
{
error("compiler error, parameter '%s', bugzilla 2962?", v->toChars());
assert(0);
}
params[pi + i] = v->toSymbol();
}
pi += parameters->dim;
}
if (reverse)
{ // Reverse params[] entries
for (size_t i = 0; i < pi/2; i++)
{
Symbol *sptmp = params[i];
params[i] = params[pi - 1 - i];
params[pi - 1 - i] = sptmp;
}
}
if (shidden)
{
#if 0
// shidden becomes last parameter
params[pi] = shidden;
#else
// shidden becomes first parameter
memmove(params + 1, params, pi * sizeof(params[0]));
params[0] = shidden;
#endif
pi++;
}
if (sthis)
{
#if 0
// sthis becomes last parameter
params[pi] = sthis;
#else
// sthis becomes first parameter
memmove(params + 1, params, pi * sizeof(params[0]));
params[0] = sthis;
#endif
pi++;
}
if ((global.params.isLinux || global.params.isOSX || global.params.isFreeBSD || global.params.isSolaris) &&
linkage != LINKd && shidden && sthis)
{
/* swap shidden and sthis
*/
Symbol *sp = params[0];
params[0] = params[1];
params[1] = sp;
}
for (size_t i = 0; i < pi; i++)
{ Symbol *sp = params[i];
sp->Sclass = SCparameter;
sp->Sflags &= ~SFLspill;
sp->Sfl = FLpara;
symbol_add(sp);
}
// Determine register assignments
if (pi)
{
if (global.params.is64bit)
{
// Order of assignment of pointer or integer parameters
static const unsigned char argregs[6] = { DI,SI,DX,CX,R8,R9 };
int r = 0;
int xmmcnt = XMM0;
for (size_t i = 0; i < pi; i++)
{ Symbol *sp = params[i];
tym_t ty = tybasic(sp->Stype->Tty);
// BUG: doesn't work for structs
if (r < sizeof(argregs)/sizeof(argregs[0]))
{
if (type_jparam(sp->Stype))
{
sp->Sclass = SCfastpar;
sp->Spreg = argregs[r];
sp->Sfl = FLauto;
++r;
}
}
if (xmmcnt <= XMM7)
{
if (tyxmmreg(ty))
{
sp->Sclass = SCfastpar;
sp->Spreg = xmmcnt;
sp->Sfl = FLauto;
++xmmcnt;
}
}
}
}
else
{
// First parameter goes in register
Symbol *sp = params[0];
if ((tyf == TYjfunc || tyf == TYmfunc) &&
type_jparam(sp->Stype))
{ sp->Sclass = SCfastpar;
sp->Spreg = (tyf == TYjfunc) ? AX : CX;
sp->Sfl = FLauto;
//printf("'%s' is SCfastpar\n",sp->Sident);
}
}
}
if (func->fbody)
{ block *b;
Blockx bx;
Statement *sbody;
localgot = NULL;
sbody = func->fbody;
memset(&bx,0,sizeof(bx));
bx.startblock = block_calloc();
bx.curblock = bx.startblock;
bx.funcsym = s;
bx.scope_index = -1;
bx.classdec = cd;
bx.member = func;
bx.module = getModule();
irs.blx = &bx;
#if DMDV2
buildClosure(&irs);
#endif
#if 0
if (func->isSynchronized())
{
if (cd)
{ elem *esync;
if (func->isStatic())
{ // monitor is in ClassInfo
esync = el_ptr(cd->toSymbol());
}
else
{ // 'this' is the monitor
esync = el_var(sthis);
}
if (func->isStatic() || sbody->usesEH() ||
!(config.flags2 & CFG2seh))
{ // BUG: what if frequire or fensure uses EH?
sbody = new SynchronizedStatement(func->loc, esync, sbody);
}
else
{
#if TARGET_WINDOS
if (config.flags2 & CFG2seh)
{
/* The "jmonitor" uses an optimized exception handling frame
* which is a little shorter than the more general EH frame.
* It isn't strictly necessary.
*/
s->Sfunc->Fflags3 |= Fjmonitor;
}
#endif
el_free(esync);
}
}
else
{
error("synchronized function %s must be a member of a class", func->toChars());
}
}
#elif TARGET_WINDOS
if (func->isSynchronized() && cd && config.flags2 & CFG2seh &&
!func->isStatic() && !sbody->usesEH())
{
/* The "jmonitor" hack uses an optimized exception handling frame
* which is a little shorter than the more general EH frame.
*/
s->Sfunc->Fflags3 |= Fjmonitor;
}
#endif
sbody->toIR(&irs);
bx.curblock->BC = BCret;
f->Fstartblock = bx.startblock;
// einit = el_combine(einit,bx.init);
if (isCtorDeclaration())
{
assert(sthis);
for (b = f->Fstartblock; b; b = b->Bnext)
{
if (b->BC == BCret)
{
b->BC = BCretexp;
b->Belem = el_combine(b->Belem, el_var(sthis));
}
}
}
}
// If static constructor
#if DMDV2
if (isSharedStaticCtorDeclaration()) // must come first because it derives from StaticCtorDeclaration
{
ssharedctors.push(s);
}
else
#endif
if (isStaticCtorDeclaration())
{
sctors.push(s);
}
// If static destructor
#if DMDV2
if (isSharedStaticDtorDeclaration()) // must come first because it derives from StaticDtorDeclaration
{
SharedStaticDtorDeclaration *f = isSharedStaticDtorDeclaration();
assert(f);
if (f->vgate)
{ /* Increment destructor's vgate at construction time
*/
esharedctorgates.push(f);
}
sshareddtors.shift(s);
}
else
#endif
if (isStaticDtorDeclaration())
{
StaticDtorDeclaration *f = isStaticDtorDeclaration();
assert(f);
if (f->vgate)
{ /* Increment destructor's vgate at construction time
*/
ectorgates.push(f);
}
sdtors.shift(s);
}
// If unit test
if (isUnitTestDeclaration())
{
stests.push(s);
}
if (global.errors)
return;
writefunc(s);
if (isExport())
obj_export(s, Poffset);
for (size_t i = 0; i < irs.deferToObj->dim; i++)
{
Dsymbol *s = (*irs.deferToObj)[i];
FuncDeclaration *fd = s->isFuncDeclaration();
if (fd)
{ FuncDeclaration *fdp = fd->toParent2()->isFuncDeclaration();
if (fdp && fdp->semanticRun < PASSobj)
{ /* Bugzilla 7595
* FuncDeclaration::buildClosure() relies on nested functions
* being toObjFile'd after the outer function. Otherwise, the
* v->offset's for the closure variables are wrong.
* So, defer fd until after fdp is done.
*/
fdp->deferred.push(fd);
continue;
}
}
s->toObjFile(0);
}
for (size_t i = 0; i < deferred.dim; i++)
{
FuncDeclaration *fd = deferred[i];
fd->toObjFile(0);
}
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
// A hack to get a pointer to this function put in the .dtors segment
if (ident && memcmp(ident->toChars(), "_STD", 4) == 0)
obj_staticdtor(s);
#endif
#if DMDV2
if (irs.startaddress)
{
printf("Setting start address\n");
obj_startaddress(irs.startaddress);
}
#endif
}
/* ================================================================== */
/*****************************
* Return back end type corresponding to D front end type.
*/
unsigned Type::totym()
{ unsigned t;
switch (ty)
{
case Tvoid: t = TYvoid; break;
case Tint8: t = TYschar; break;
case Tuns8: t = TYuchar; break;
case Tint16: t = TYshort; break;
case Tuns16: t = TYushort; break;
case Tint32: t = TYint; break;
case Tuns32: t = TYuint; break;
case Tint64: t = TYllong; break;
case Tuns64: t = TYullong; break;
case Tfloat32: t = TYfloat; break;
case Tfloat64: t = TYdouble; break;
case Tfloat80: t = TYldouble; break;
case Timaginary32: t = TYifloat; break;
case Timaginary64: t = TYidouble; break;
case Timaginary80: t = TYildouble; break;
case Tcomplex32: t = TYcfloat; break;
case Tcomplex64: t = TYcdouble; break;
case Tcomplex80: t = TYcldouble; break;
case Tbool: t = TYbool; break;
case Tchar: t = TYchar; break;
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
case Twchar: t = TYwchar_t; break;
case Tdchar: t = TYdchar; break;
#else
case Twchar: t = TYwchar_t; break;
case Tdchar:
t = (global.params.symdebug == 1) ? TYdchar : TYulong;
break;
#endif
case Taarray: t = TYaarray; break;
case Tclass:
case Treference:
case Tpointer: t = TYnptr; break;
case Tdelegate: t = TYdelegate; break;
case Tarray: t = TYdarray; break;
#if SARRAYVALUE
case Tsarray: t = TYstruct; break;
#else
case Tsarray: t = TYarray; break;
#endif
case Tstruct: t = TYstruct; break;
case Tenum:
case Ttypedef:
t = toBasetype()->totym();
break;
case Tident:
case Ttypeof:
error(0, "forward reference of %s", toChars());
t = TYint;
break;
case Tnull:
t = TYnptr;
break;
case Tvector:
{ TypeVector *tv = (TypeVector *)this;
TypeBasic *tb = tv->elementType();
switch (tb->ty)
{ case Tvoid:
case Tint8: t = TYschar16; break;
case Tuns8: t = TYuchar16; break;
case Tint16: t = TYshort8; break;
case Tuns16: t = TYushort8; break;
case Tint32: t = TYlong4; break;
case Tuns32: t = TYulong4; break;
case Tint64: t = TYllong2; break;
case Tuns64: t = TYullong2; break;
case Tfloat32: t = TYfloat4; break;
case Tfloat64: t = TYdouble2; break;
default:
assert(0);
break;
}
break;
}
default:
#ifdef DEBUG
printf("ty = %d, '%s'\n", ty, toChars());
halt();
#endif
assert(0);
}
#if DMDV2
// Add modifiers
switch (mod)
{
case 0:
break;
case MODconst:
case MODwild:
t |= mTYconst;
break;
case MODimmutable:
t |= mTYimmutable;
break;
case MODshared:
t |= mTYshared;
break;
case MODshared | MODwild:
case MODshared | MODconst:
t |= mTYshared | mTYconst;
break;
default:
assert(0);
}
#endif
return t;
}
unsigned TypeFunction::totym()
{
tym_t tyf;
//printf("TypeFunction::totym(), linkage = %d\n", linkage);
switch (linkage)
{
case LINKwindows:
tyf = (varargs == 1) ? TYnfunc : TYnsfunc;
break;
case LINKpascal:
tyf = (varargs == 1) ? TYnfunc : TYnpfunc;
break;
case LINKc:
tyf = TYnfunc;
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
if (I32 && retStyle() == RETstack)
tyf = TYhfunc;
#endif
break;
case LINKd:
tyf = (varargs == 1) ? TYnfunc : TYjfunc;
break;
case LINKcpp:
tyf = TYnfunc;
break;
default:
printf("linkage = %d\n", linkage);
assert(0);
}
#if DMDV2
if (isnothrow)
tyf |= mTYnothrow;
#endif
return tyf;
}
/**************************************
*/
Symbol *Type::toSymbol()
{
assert(0);
return NULL;
}
Symbol *TypeClass::toSymbol()
{
return sym->toSymbol();
}
/*************************************
* Generate symbol in data segment for critical section.
*/
Symbol *Module::gencritsec()
{
Symbol *s;
type *t;
t = Type::tint32->toCtype();
s = symbol_name("critsec", SCstatic, t);
s->Sfl = FLdata;
/* Must match D_CRITICAL_SECTION in phobos/internal/critical.c
*/
dtnzeros(&s->Sdt, PTRSIZE + (I64 ? os_critsecsize64() : os_critsecsize32()));
#if ELFOBJ || MACHOBJ // Burton
s->Sseg = DATA;
#endif
outdata(s);
return s;
}
/**************************************
* Generate elem that is a pointer to the module file name.
*/
elem *Module::toEfilename()
{ elem *efilename;
if (!sfilename)
{
dt_t *dt = NULL;
char *id;
int len;
id = srcfile->toChars();
len = strlen(id);
dtsize_t(&dt, len);
dtabytes(&dt,TYnptr, 0, len + 1, id);
sfilename = symbol_generate(SCstatic,type_fake(TYdarray));
sfilename->Sdt = dt;
sfilename->Sfl = FLdata;
#if ELFOBJ
sfilename->Sseg = CDATA;
#endif
#if MACHOBJ
// Because of PIC and CDATA being in the _TEXT segment, cannot
// have pointers in CDATA
sfilename->Sseg = DATA;
#endif
outdata(sfilename);
}
efilename = el_var(sfilename);
return efilename;
}