]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/d/d-frontend.cc
Update copyright years.
[thirdparty/gcc.git] / gcc / d / d-frontend.cc
CommitLineData
b4c522fa 1/* d-frontend.cc -- D frontend interface to the gcc back-end.
a945c346 2 Copyright (C) 2013-2024 Free Software Foundation, Inc.
b4c522fa
IB
3
4GCC is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 3, or (at your option)
7any later version.
8
9GCC is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with GCC; see the file COPYING3. If not see
16<http://www.gnu.org/licenses/>. */
17
18#include "config.h"
19#include "system.h"
20#include "coretypes.h"
21
22#include "dmd/aggregate.h"
b4c522fa 23#include "dmd/declaration.h"
b4c522fa 24#include "dmd/expression.h"
b4c522fa
IB
25#include "dmd/module.h"
26#include "dmd/mtype.h"
27#include "dmd/scope.h"
b4c522fa
IB
28
29#include "tree.h"
b4c522fa
IB
30#include "fold-const.h"
31#include "diagnostic.h"
b4c522fa
IB
32
33#include "d-tree.h"
0fb57034 34#include "d-frontend.h"
b4c522fa 35
b4c522fa
IB
36/* Implements back-end specific interfaces used by the frontend. */
37
b4c522fa
IB
38/* Determine if function FD is a builtin one that we can evaluate in CTFE. */
39
40BUILTIN
41isBuiltin (FuncDeclaration *fd)
42{
5fee5ec3 43 if (fd->builtin != BUILTIN::unknown)
b4c522fa
IB
44 return fd->builtin;
45
46 maybe_set_intrinsic (fd);
47
48 return fd->builtin;
49}
50
51/* Evaluate builtin D function FD whose argument list is ARGUMENTS.
52 Return result; NULL if cannot evaluate it. */
53
54Expression *
0fb57034 55eval_builtin (const Loc &loc, FuncDeclaration *fd, Expressions *arguments)
b4c522fa 56{
5fee5ec3 57 if (fd->builtin == BUILTIN::unimp)
b4c522fa
IB
58 return NULL;
59
60 tree decl = get_symbol_decl (fd);
61 gcc_assert (fndecl_built_in_p (decl)
62 || DECL_INTRINSIC_CODE (decl) != INTRINSIC_NONE);
63
6c4db916 64 TypeFunction *tf = fd->type->toTypeFunction ();
b4c522fa
IB
65 Expression *e = NULL;
66 input_location = make_location_t (loc);
67
68 tree result = d_build_call (tf, decl, NULL, arguments);
69 result = fold (result);
70
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)
ac78516b 74 e = d_eval_constant_expression (loc, result);
b4c522fa
IB
75
76 return e;
77}
78
79/* Build and return typeinfo type for TYPE. */
80
81Type *
8da8c7d3 82getTypeInfoType (const Loc &loc, Type *type, Scope *sc, bool genObjCode)
b4c522fa 83{
5fee5ec3 84 gcc_assert (type->ty != TY::Terror);
5ae4a730 85 check_typeinfo_type (loc, sc);
8da8c7d3 86 create_typeinfo (type, sc ? sc->_module->importedFrom : NULL, genObjCode);
b4c522fa
IB
87 return type->vtinfo->type;
88}
0fb57034
IB
89
90void
91toObjFile (Dsymbol *ds, bool)
92{
93 build_decl_tree (ds);
94}