Skip to content

Commit e574f16

Browse files
committed
Packagise the glue layer
1 parent c2c8c3d commit e574f16

File tree

16 files changed

+276
-320
lines changed

16 files changed

+276
-320
lines changed

compiler/src/build.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,10 +1558,10 @@ auto sourceFiles()
15581558
}
15591559
DmdSources dmd = {
15601560
glue: fileArray(env["D"], "
1561-
dmsc.d e2ir.d iasm/dmdx86.d iasm/dmdaarch64.d glue.d objc_glue.d
1562-
s2ir.d tocsym.d toctype.d tocvdebug.d todt.d toir.d toobj.d
1561+
dmsc.d iasm/dmdx86.d iasm/dmdaarch64.d glue/package.d glue/e2ir.d glue/objc_glue.d
1562+
glue/s2ir.d glue/tocsym.d glue/toctype.d glue/tocvdebug.d glue/todt.d glue/toir.d glue/toobj.d
15631563
"),
1564-
driver: fileArray(env["D"], "dinifile.d dmdparams.d gluelayer.d lib/package.d lib/elf.d lib/mach.d lib/mscoff.d
1564+
driver: fileArray(env["D"], "dinifile.d dmdparams.d lib/package.d lib/elf.d lib/mach.d lib/mscoff.d
15651565
link.d mars.d main.d sarif.d lib/scanelf.d lib/scanmach.d lib/scanmscoff.d timetrace.d vsoptions.d
15661566
"),
15671567
frontend: fileArray(env["D"], "

compiler/src/dmd/README.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Note that these groups have no strict meaning, the category assignments are a bi
3535
| [mars.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/mars.d) | Argument parsing, path manipulation. |
3636
| [cli.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/cli.d) | Define the command line interface |
3737
| [dmdparams.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/dmdparams.d) | DMD-specific parameters |
38+
| [dmsc.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/dmsc.d) | Configures and initializes the back-end |
3839
| [globals.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/globals.d) | Define a structure storing command line options |
3940
| [dinifile.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/dinifile.d) | Parse settings from .ini file (`sc.ini` / `dmd.conf`) |
4041
| [vsoptions.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/vsoptions.d) | Detect the Microsoft Visual Studio toolchain for linking |
@@ -209,27 +210,28 @@ Note that these groups have no strict meaning, the category assignments are a bi
209210
| [lib/scanmach.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/lib/scanmach.d) | Extract symbol names from a library in Mach-O format |
210211
| [lib/scanmscoff.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/lib/scanmscoff.d) | Extract symbol names from a library in COFF format |
211212

213+
214+
### ABI
215+
| File | Purpose |
216+
| [argtypes_x86.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/argtypes_x86.d) | Convert a D type into simple (register) types for the 32-bit x86 ABI |
217+
| [argtypes_sysv_x64.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/argtypes_sysv_x64.d) | 'argtypes' for the x86_64 System V ABI |
218+
| [argtypes_aarch64.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/argtypes_aarch64.d) | 'argtypes' for the AArch64 ABI |
212219
### Code generation / back-end interfacing
213220

214221
| File | Purpose |
215222
|---------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------|
216-
| [dmsc.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/dmsc.d) | Configures and initializes the back-end |
217-
| [toobj.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/toobj.d) | Convert an AST that went through all semantic phases into an object file |
218-
| [toir.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/toir.d) | Convert Dsymbols intermediate representation |
219-
| [e2ir.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/e2ir.d) | Convert Expressions to intermediate representation |
220-
| [s2ir.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/s2ir.d) | Convert Statements to intermediate representation |
221-
| [stmtstate.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/stmtstate.d) | Used to help transform statement AST into flow graph |
222-
| [toctype.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/toctype.d) | Convert a D type to a type the back-end understands |
223-
| [tocsym.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/tocsym.d) | Convert a D symbol to a symbol the linker understands (with mangled name) |
224-
| [argtypes_x86.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/argtypes_x86.d) | Convert a D type into simple (register) types for the 32-bit x86 ABI |
225-
| [argtypes_sysv_x64.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/argtypes_sysv_x64.d) | 'argtypes' for the x86_64 System V ABI |
226-
| [argtypes_aarch64.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/argtypes_aarch64.d) | 'argtypes' for the AArch64 ABI |
227-
| [glue.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/glue.d) | Generate the object file for function declarations |
228-
| [gluelayer.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/gluelayer.d) | Declarations for back-end functions that the front-end invokes |
229-
| [todt.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/todt.d) | Convert initializers into structures that the back-end will add to the data segment |
230-
| [tocvdebug.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/tovcdebug.d) | Generate debug info in the CV4 debug format. |
231-
| [objc.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/objc.d) | Objective-C interfacing |
232-
| [objc_glue.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/objc_glue.d) | Glue code for Objective-C interop. |
223+
| [stmtstate.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/stmtstate.d) | Used to help transform statement AST into flow graph |
224+
| [objc.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/objc.d) | Objective-C interfacing |
225+
| [glue/toobj.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/glue/toobj.d) | Convert an AST that went through all semantic phases into an object file|
226+
| [glue/toir.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/glue/toir.d) | Convert Dsymbols intermediate representation |
227+
| [glue/e2ir.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/glue/e2ir.d) | Convert Expressions to intermediate representation |
228+
| [glue/s2ir.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/glue/s2ir.d) | Convert Statements to intermediate representation |
229+
| [glue/toctype.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/glue/toctype.d) | Convert a D type to a type the back-end understands |
230+
| [glue/tocsym.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/glue/tocsym.d) | Convert a D symbol to a symbol the linker understands (with mangled name) |
231+
| [glue/package.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/glue/package.d) | Generate the object file for function declarations |
232+
| [glue/todt.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/glue/todt.d) | Convert initializers into structures that the back-end will add to the data segment |
233+
| [glue/tocvdebug.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/glue/tovcdebug.d)| Generate debug info in the CV4 debug format. |
234+
| [glue/objc_glue.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/glue/objc_glue.d)| Glue code for Objective-C interop. |
233235

234236
**Name mangling**
235237

compiler/src/dmd/e2ir.d renamed to compiler/src/dmd/glue/e2ir.d

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
* Copyright: Copyright (C) 1999-2025 by The D Language Foundation, All Rights Reserved
55
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
66
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
7-
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/compiler/src/dmd/e2ir.d, _e2ir.d)
8-
* Documentation: https://dlang.org/phobos/dmd_e2ir.html
9-
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/e2ir.d
7+
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/compiler/src/dmd/glue/e2ir.d, _e2ir.d)
8+
* Documentation: https://dlang.org/phobos/dmd_glue_e2ir.html
9+
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/glue/e2ir.d
1010
*/
1111

12-
module dmd.e2ir;
12+
module dmd.glue.e2ir;
1313

1414
import core.stdc.stdio;
1515
import core.stdc.stddef;
@@ -22,6 +22,14 @@ import dmd.root.rmem;
2222
import dmd.rootobject;
2323
import dmd.root.stringtable;
2424

25+
import dmd.glue;
26+
import dmd.glue.s2ir;
27+
import dmd.glue.tocsym;
28+
import dmd.glue.toctype;
29+
import dmd.glue.toir;
30+
import dmd.glue.objc_glue;
31+
import dmd.glue.toobj;
32+
2533
import dmd.aggregate;
2634
import dmd.arraytypes;
2735
import dmd.astenums;
@@ -42,23 +50,16 @@ import dmd.dtemplate;
4250
import dmd.expression;
4351
import dmd.expressionsem : fill;
4452
import dmd.func;
45-
import dmd.glue;
4653
import dmd.hdrgen;
4754
import dmd.id;
4855
import dmd.init;
4956
import dmd.location;
5057
import dmd.mtype;
51-
import dmd.objc_glue;
5258
import dmd.printast;
53-
import dmd.s2ir;
5459
import dmd.sideeffect;
5560
import dmd.statement;
5661
import dmd.target;
57-
import dmd.tocsym;
58-
import dmd.toctype;
59-
import dmd.toir;
6062
import dmd.tokens;
61-
import dmd.toobj;
6263
import dmd.typinf;
6364
import dmd.typesem;
6465
import dmd.visitor;
@@ -80,6 +81,8 @@ import dmd.backend.type;
8081

8182
import dmd.backend.x86.code_x86;
8283

84+
package(dmd.glue):
85+
8386
alias Elems = Array!(elem *);
8487

8588
import dmd.backend.util2 : mem_malloc2;
@@ -630,6 +633,15 @@ Symbol* toExtSymbol(Dsymbol s)
630633
return toSymbol(s);
631634
}
632635

636+
private elem* toEfilenamePtr(Module m)
637+
{
638+
//printf("toEfilenamePtr(%s)\n", m.toChars());
639+
const(char)* id = m.srcfile.toChars();
640+
size_t len = strlen(id);
641+
Symbol* s = toStringSymbol(id, len, 1);
642+
return el_ptr(s);
643+
}
644+
633645
/*********************************************
634646
* Convert Expression to backend elem.
635647
* Params:

compiler/src/dmd/objc_glue.d renamed to compiler/src/dmd/glue/objc_glue.d

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44
* Copyright: Copyright (C) 2015-2025 by The D Language Foundation, All Rights Reserved
55
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
66
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
7-
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/compiler/src/dmd/objc_glue.d, _objc_glue.d)
8-
* Documentation: https://dlang.org/phobos/dmd_objc_glue.html
9-
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/objc_glue.d
7+
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/compiler/src/dmd/glue/objc_glue.d, _objc_glue.d)
8+
* Documentation: https://dlang.org/phobos/dmd_glue_objc_glue.html
9+
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/glue/objc_glue.d
1010
*/
1111

12-
module dmd.objc_glue;
12+
module dmd.glue.objc_glue;
1313

1414
import core.stdc.stdio;
1515
import core.stdc.stdlib;
1616
import core.stdc.string;
1717

18+
import dmd.glue;
19+
1820
import dmd.aggregate;
1921
import dmd.arraytypes;
2022
import dmd.astenums;
@@ -24,7 +26,6 @@ import dmd.dmodule;
2426
import dmd.dsymbol;
2527
import dmd.expression;
2628
import dmd.func;
27-
import dmd.glue;
2829
import dmd.identifier;
2930
import dmd.mtype;
3031
import dmd.objc;
@@ -44,6 +45,16 @@ import dmd.backend.type;
4445
import dmd.backend.mach;
4546
import dmd.backend.obj;
4647

48+
public void ObjcGlue_initialize()
49+
{
50+
if (target.objc.supported)
51+
_objc = new Supported;
52+
else
53+
_objc = new Unsupported;
54+
}
55+
56+
package(dmd.glue):
57+
4758
private __gshared ObjcGlue _objc;
4859

4960
ObjcGlue objc()
@@ -60,13 +71,6 @@ extern(C++) abstract class ObjcGlue
6071
elem* ethis;
6172
}
6273

63-
static void initialize()
64-
{
65-
if (target.objc.supported)
66-
_objc = new Supported;
67-
else
68-
_objc = new Unsupported;
69-
}
7074

7175
/// Resets the Objective-C glue layer.
7276
abstract void reset();
@@ -204,7 +208,7 @@ extern(C++) final class Supported : ObjcGlue
204208
override ElemResult setupMethodCall(FuncDeclaration fd, TypeFunction tf,
205209
bool directcall, elem* ec, elem* ehidden, elem* ethis)
206210
{
207-
import dmd.e2ir : addressElem;
211+
import dmd.glue.e2ir : addressElem;
208212

209213
if (directcall) // super call
210214
{

0 commit comments

Comments
 (0)