Skip to content

Commit 4ecb7cf

Browse files
WalterBrightthewilsonator
authored andcommitted
split toobj.d into above and below the fold
1 parent acf912c commit 4ecb7cf

1 file changed

Lines changed: 58 additions & 46 deletions

File tree

compiler/src/dmd/glue/toobj.d

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ import dmd.backend.type;
8585

8686
package(dmd.glue):
8787

88+
private:
89+
8890
/* ================================================================== */
8991

9092
/*****************************************
@@ -95,6 +97,7 @@ package(dmd.glue):
9597
* s = symbol that contains the data
9698
* offset = offset of the data inside the Symbol's memory
9799
*/
100+
package(dmd.glue)
98101
void write_pointers(Type type, Symbol* s, uint offset)
99102
{
100103
uint ty = type.toBasetype().ty;
@@ -112,6 +115,7 @@ void write_pointers(Type type, Symbol* s, uint offset)
112115
* s = symbol that contains the data
113116
* offset = offset of the data inside the Symbol's memory
114117
*/
118+
package(dmd.glue)
115119
void write_instance_pointers(Type type, Symbol* s, uint offset)
116120
{
117121
import dmd.typesem : hasPointers;
@@ -147,6 +151,7 @@ void write_instance_pointers(Type type, Symbol* s, uint offset)
147151
* loc = the location for reporting line numbers in errors
148152
* t = the type to generate the `TypeInfo` object for
149153
*/
154+
package(dmd.glue)
150155
void TypeInfo_toObjFile(Expression e, Loc loc, Type t)
151156
{
152157
// printf("TypeInfo_toObjFIle() %s\n", torig.toChars());
@@ -159,6 +164,7 @@ void TypeInfo_toObjFile(Expression e, Loc loc, Type t)
159164

160165
/* ================================================================== */
161166

167+
package(dmd.glue)
162168
void toObjFile(Dsymbol ds, bool multiobj)
163169
{
164170
//printf("toObjFile(%s %s)\n", ds.kind(), ds.toChars());
@@ -1016,6 +1022,57 @@ void toObjFile(Dsymbol ds, bool multiobj)
10161022
}
10171023

10181024

1025+
/******************************************
1026+
* Get offset of base class's vtbl[] initializer from start of csym.
1027+
* Returns ~0 if not this csym.
1028+
*/
1029+
1030+
package(dmd.glue)
1031+
uint baseVtblOffset(ClassDeclaration cd, BaseClass* bc)
1032+
{
1033+
//printf("ClassDeclaration.baseVtblOffset('%s', bc = %p)\n", cd.toChars(), bc);
1034+
uint csymoffset = classInfoSize(); // must be ClassInfo.size
1035+
//printf("classInfoSize(): %d\n", csymoffset);
1036+
csymoffset += cd.vtblInterfaces.length * (4 * target.ptrsize);
1037+
1038+
for (size_t i = 0; i < cd.vtblInterfaces.length; i++)
1039+
{
1040+
BaseClass* b = (*cd.vtblInterfaces)[i];
1041+
1042+
if (b == bc)
1043+
return csymoffset;
1044+
csymoffset += b.sym.vtbl.length * target.ptrsize;
1045+
}
1046+
1047+
// Put out the overriding interface vtbl[]s.
1048+
// This must be mirrored with ClassDeclaration.baseVtblOffset()
1049+
//printf("putting out overriding interface vtbl[]s for '%s' at offset x%x\n", toChars(), offset);
1050+
ClassDeclaration cd2;
1051+
1052+
for (cd2 = cd.baseClass; cd2; cd2 = cd2.baseClass)
1053+
{
1054+
foreach (k; 0 .. cd2.vtblInterfaces.length)
1055+
{
1056+
BaseClass* bs = (*cd2.vtblInterfaces)[k];
1057+
if (bs.fillVtbl(cd, null, 0))
1058+
{
1059+
if (bc == bs)
1060+
{
1061+
//printf("\tcsymoffset = x%x\n", csymoffset);
1062+
return csymoffset;
1063+
}
1064+
csymoffset += bs.sym.vtbl.length * target.ptrsize;
1065+
}
1066+
}
1067+
}
1068+
1069+
return ~0;
1070+
}
1071+
1072+
/**********************************************************************************/
1073+
/* private */
1074+
/**********************************************************************************/
1075+
10191076
/*********************************
10201077
* Finish semantic analysis of functions in vtbl[].
10211078
* Params:
@@ -1084,6 +1141,7 @@ private bool finishVtbl(ClassDeclaration cd)
10841141
}
10851142

10861143
/// Returns: classInstanceSize of TypeInfo_Class for `cd`
1144+
private
10871145
uint classInfoSize()
10881146
{
10891147
auto obj = ClassDeclaration.object;
@@ -1094,52 +1152,6 @@ uint classInfoSize()
10941152
return 0x4C + 12 + (hasMonitor ? 4 : 0); // 92 with monitor
10951153
}
10961154

1097-
/******************************************
1098-
* Get offset of base class's vtbl[] initializer from start of csym.
1099-
* Returns ~0 if not this csym.
1100-
*/
1101-
1102-
uint baseVtblOffset(ClassDeclaration cd, BaseClass* bc)
1103-
{
1104-
//printf("ClassDeclaration.baseVtblOffset('%s', bc = %p)\n", cd.toChars(), bc);
1105-
uint csymoffset = classInfoSize(); // must be ClassInfo.size
1106-
//printf("classInfoSize(): %d\n", csymoffset);
1107-
csymoffset += cd.vtblInterfaces.length * (4 * target.ptrsize);
1108-
1109-
for (size_t i = 0; i < cd.vtblInterfaces.length; i++)
1110-
{
1111-
BaseClass* b = (*cd.vtblInterfaces)[i];
1112-
1113-
if (b == bc)
1114-
return csymoffset;
1115-
csymoffset += b.sym.vtbl.length * target.ptrsize;
1116-
}
1117-
1118-
// Put out the overriding interface vtbl[]s.
1119-
// This must be mirrored with ClassDeclaration.baseVtblOffset()
1120-
//printf("putting out overriding interface vtbl[]s for '%s' at offset x%x\n", toChars(), offset);
1121-
ClassDeclaration cd2;
1122-
1123-
for (cd2 = cd.baseClass; cd2; cd2 = cd2.baseClass)
1124-
{
1125-
foreach (k; 0 .. cd2.vtblInterfaces.length)
1126-
{
1127-
BaseClass* bs = (*cd2.vtblInterfaces)[k];
1128-
if (bs.fillVtbl(cd, null, 0))
1129-
{
1130-
if (bc == bs)
1131-
{
1132-
//printf("\tcsymoffset = x%x\n", csymoffset);
1133-
return csymoffset;
1134-
}
1135-
csymoffset += bs.sym.vtbl.length * target.ptrsize;
1136-
}
1137-
}
1138-
}
1139-
1140-
return ~0;
1141-
}
1142-
11431155
/*******************
11441156
* Emit the vtbl[] to static data
11451157
* Params:

0 commit comments

Comments
 (0)