Compiler implementation of the D programming language.

Walter Bright
Boost License 1.0
elem* incUsageElem(IRState* irs, ref const Loc loc);

Produce elem which increments the usage count for a particular line. Sets corresponding bit in bitmap m.covb[linnum]. Used to implement -cov switch (coverage analysis).

IRState* irs context
Loc loc line and file of what line to show usage for
elem that increments the line count
elem* getEthis(ref const Loc loc, IRState* irs, Dsymbol fd, Dsymbol fdp = null, Dsymbol origSc = null);

Return elem that evaluates to the static frame pointer for function fd. If fd is a member function, the returned expression will compute the value of fd's 'this' variable. 'fdp' is the parent of 'fd' if the frame pointer is being used to call 'fd'. 'origSc' is the original scope we inlined from. This routine is critical for implementing nested functions.

elem* fixEthis2(elem* ethis, FuncDeclaration fd, bool ctxt2 = false);

Select one context pointer from a dual-context array

*(ethis + offset);
elem* setEthis(ref const Loc loc, IRState* irs, elem* ey, AggregateDeclaration ad, bool setthis2 = false);

Initialize the hidden aggregate member, vthis, with the context pointer.

*(ey + (ethis2 ? ad.vthis2 : ad.vthis).offset) = this;
int intrinsic_op(FuncDeclaration fd);

Convert intrinsic function to operator.

that operator, NotIntrinsic if not an intrinsic function.
elem* resolveLengthVar(VarDeclaration lengthVar, elem** pe, Type t1);

Given an expression e that is an array, determine and set the 'length' variable.

lengthVar Symbol of 'length' variable &e expression that is the array t1 Type of the array
e is rewritten to avoid side effects
expression that initializes 'length'
TYPE* getParentClosureType(Symbol* sthis, FuncDeclaration fd);

for a nested function 'fd' return the type of the closure of an outer function or aggregate. If the function is a member function the 'this' type is expected to be stored in 'sthis.Sthis'. It is always returned if it is not a void pointer. buildClosure() must have been called on the outer function before.

Symbol* sthis the symbol of the current 'this' derived from fd.vthis
FuncDeclaration fd the nested function
void setClosureVarOffset(FuncDeclaration fd);

Go through the variables in function fd that are to be allocated in a closure, and set the .offset fields for those variables to their positions relative to the start of the closure instance. Also turns off nrvo for closure variables.

FuncDeclaration fd function
void buildClosure(FuncDeclaration fd, IRState* irs);

Closures are implemented by taking the local variables that need to survive the scope of the function, and copying them into a gc allocated chuck of memory. That chunk, called the closure here, is inserted into the linked list of stack frames instead of the usual stack frame.

buildClosure() inserts code just after the function prolog is complete. It allocates memory for the closure, allocates a local variable (sclosure) to point to it, inserts into it the link to the enclosing frame, and copies into it the parameters that are referred to in nested functions. In VarExp::toElem and SymOffExp::toElem, when referring to a variable that is in a closure, takes the offset from sclosure rather than from the frame pointer.

getEthis() and NewExp::toElem need to use sclosure, if set, rather than the current frame pointer.

void buildCapture(FuncDeclaration fd);

build a debug info struct for variables captured by nested functions, but not in a closure. must be called after generating the function to fill stack offsets

FuncDeclaration fd function
RET retStyle(TypeFunction tf, bool needsThis);

Determine return style of function - whether in registers or through a hidden pointer to the caller's stack.

TypeFunction tf function type to check
bool needsThis true if the function type is for a non-static member function
RET.stack if return value from function is on the stack, RET.regs otherwise

© 1999–2019 The D Language Foundation
Licensed under the Boost License 1.0.