1 /**
2  * Declarations for back-end functions that the front-end invokes.
3  *
4  * This 'glues' either the DMC or GCC back-end to the front-end.
5  *
6  * Copyright:   Copyright (C) 1999-2020 by The D Language Foundation, All Rights Reserved
7  * Authors:     $(LINK2 http://www.digitalmars.com, Walter Bright)
8  * License:     $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
9  * Source:      $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/gluelayer.d, _gluelayer.d)
10  * Documentation:  https://dlang.org/phobos/dmd_gluelayer.html
11  * Coverage:    https://codecov.io/gh/dlang/dmd/src/master/src/dmd/gluelayer.d
12  */
13 
14 module dmd.gluelayer;
15 
16 import dmd.dmodule;
17 import dmd.dscope;
18 import dmd.dsymbol;
19 import dmd.mtype;
20 import dmd.statement;
21 import dmd.root.file;
22 
23 version (NoBackend)
24 {
25     struct Symbol;
26     struct code;
27     struct block;
28     struct Blockx;
29     struct elem;
30     struct TYPE;
31     alias type = TYPE;
32 
33     extern (C++)
34     {
35         version (NoMain) {} else
36         {
37             import dmd.lib : Library;
38 
39             // glue
40             void obj_write_deferred(Library library)        {}
41             void obj_start(const(char)* srcfile)            {}
42             void obj_end(Library library, const(char)* objfilename) {}
43             void genObjFile(Module m, bool multiobj)        {}
44 
45             // msc
46             void backend_init() {}
47             void backend_term() {}
48         }
49 
50         // iasm
51         Statement asmSemantic(AsmStatement s, Scope* sc)
52         {
53             sc.func.hasReturnExp = 8;
54             return null;
55         }
56 
57         // toir
58         void toObjFile(Dsymbol ds, bool multiobj)   {}
59 
60         extern(C++) abstract class ObjcGlue
61         {
62             static void initialize() {}
63         }
64     }
65 }
66 else version (MARS)
67 {
68     import dmd.lib : Library;
69 
70     public import dmd.backend.cc : block, Blockx, Symbol;
71     public import dmd.backend.type : type;
72     public import dmd.backend.el : elem;
73     public import dmd.backend.code_x86 : code;
74 
75     extern (C++)
76     {
77         void obj_write_deferred(Library library);
78         void obj_start(const(char)* srcfile);
79         void obj_end(Library library, const(char)* objfilename);
80         void genObjFile(Module m, bool multiobj);
81 
82         void backend_init();
83         void backend_term();
84 
85         Statement asmSemantic(AsmStatement s, Scope* sc);
86 
87         void toObjFile(Dsymbol ds, bool multiobj);
88 
89         extern(C++) abstract class ObjcGlue
90         {
91             static void initialize();
92         }
93     }
94 }
95 else version (IN_GCC)
96 {
97     extern (C++) union tree_node;
98 
99     alias Symbol = tree_node;
100     alias code = tree_node;
101     alias type = tree_node;
102 
103     extern (C++)
104     {
105         Statement asmSemantic(AsmStatement s, Scope* sc);
106     }
107 
108     // stubs
109     extern(C++) abstract class ObjcGlue
110     {
111         static void initialize() {}
112     }
113 }
114 else
115     static assert(false, "Unsupported compiler backend");