1 /* d-frontend.cc -- D frontend interface to the gcc back-end.
2 Copyright (C) 2013-2023 Free Software Foundation, Inc.
4 GCC is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
9 GCC is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with GCC; see the file COPYING3. If not see
16 <http://www.gnu.org/licenses/>. */
20 #include "coretypes.h"
22 #include "dmd/aggregate.h"
23 #include "dmd/declaration.h"
24 #include "dmd/expression.h"
25 #include "dmd/module.h"
26 #include "dmd/mtype.h"
27 #include "dmd/scope.h"
30 #include "fold-const.h"
31 #include "diagnostic.h"
34 #include "d-frontend.h"
36 /* Implements back-end specific interfaces used by the frontend. */
38 /* Determine if function FD is a builtin one that we can evaluate in CTFE. */
41 isBuiltin (FuncDeclaration
*fd
)
43 if (fd
->builtin
!= BUILTIN::unknown
)
46 maybe_set_intrinsic (fd
);
51 /* Evaluate builtin D function FD whose argument list is ARGUMENTS.
52 Return result; NULL if cannot evaluate it. */
55 eval_builtin (const Loc
&loc
, FuncDeclaration
*fd
, Expressions
*arguments
)
57 if (fd
->builtin
== BUILTIN::unimp
)
60 tree decl
= get_symbol_decl (fd
);
61 gcc_assert (fndecl_built_in_p (decl
)
62 || DECL_INTRINSIC_CODE (decl
) != INTRINSIC_NONE
);
64 TypeFunction
*tf
= fd
->type
->toTypeFunction ();
66 input_location
= make_location_t (loc
);
68 tree result
= d_build_call (tf
, decl
, NULL
, arguments
);
69 result
= fold (result
);
71 /* Builtin should be successfully evaluated.
72 Will only return NULL if we can't convert it. */
73 if (TREE_CONSTANT (result
) && TREE_CODE (result
) != CALL_EXPR
)
74 e
= d_eval_constant_expression (loc
, result
);
79 /* Build and return typeinfo type for TYPE. */
82 getTypeInfoType (const Loc
&loc
, Type
*type
, Scope
*sc
, bool genObjCode
)
84 gcc_assert (type
->ty
!= TY::Terror
);
85 check_typeinfo_type (loc
, sc
);
86 create_typeinfo (type
, sc
? sc
->_module
->importedFrom
: NULL
, genObjCode
);
87 return type
->vtinfo
->type
;
91 toObjFile (Dsymbol
*ds
, bool)