Report a bug
If you spot a problem with this page, click here to create a GitHub issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

dmd.backend.el

Expression trees (intermediate representation)
Compiler implementation of the D programming language.
Authors:
struct elem;

Elems Elems are the basic tree element. They can be either terminal elems (leaves), unary elems (left subtree exists) or binary elems (left and right subtrees exist).

struct Stab;
Cache of strings that are referenced by a Symbol. Uses a rotating buffer, perhaps a hash table would be better?
nothrow @trusted void el_reset();
Initialize for another run through.
nothrow @trusted elem* el_calloc();
Allocate an element.
nothrow @trusted void el_free(elem* e);
Free element
nothrow @safe elem* el_combine(elem* e1, elem* e2);
Combine e1 and e2 with a comma-expression. Be careful about either or both being null.
nothrow @safe elem* el_param(elem* e1, elem* e2);
Combine e1 and e2 as parameters to a function. Be careful about either or both being null.
nothrow @trusted elem* el_params(elem* e1, ...);
Create parameter list, terminated by a null.
nothrow @trusted elem* el_params(void** args, int length);
Do an array of parameters as a balanced binary tree.
nothrow @trusted elem* el_combines(void** args, int length);
Do an array of parameters as a balanced binary tree.
nothrow @trusted size_t el_opN(const elem* e, OPER op);
Return number of op nodes
nothrow @trusted void el_opArray(elem*** parray, elem* e, OPER op);
Fill an array with the ops.
nothrow @trusted elem* el_opCombine(elem** args, size_t length, OPER op, tym_t ty);
Do an array of parameters as a tree
nothrow @safe int el_nparams(const elem* e);
Return a list of the parameters.
nothrow @trusted void el_paramArray(elem*** parray, elem* e);
Fill an array with the parameters.
nothrow @safe elem* el_pair(tym_t tym, elem* lo, elem* hi);
Create a quad word out of two dwords.
nothrow @trusted void el_copy(elem* to, const elem* from);
Copy an element (not the tree!).
nothrow @safe elem* el_alloctmp(tym_t ty);
Allocate a temporary, and return temporary elem.
nothrow @trusted elem* el_selecte1(elem* e);
Select the e1 child of e.
nothrow @trusted elem* el_selecte2(elem* e);
Select the e2 child of e.
nothrow @trusted elem* el_copytree(elem* e);
Create and return a duplicate of e, including its leaves. No CSEs.
nothrow @trusted elem* exp2_copytotemp(elem* e);
Replace (e) with ((stmp = e),stmp)
nothrow @trusted elem* el_same(ref elem* pe);
Similar to el_copytree(e). But if e has any side effects, it's replaced with (tmp = e) and tmp is returned.
nothrow @trusted elem* el_copytotmp(ref elem* pe);
Thin wrapper of exp2_copytotemp. Different from el_same, always makes a temporary.
nothrow @trusted int el_appears(const(elem)* e, const Symbol* s);
Does symbol s appear in tree e?
Returns:
1 yes 0 no
nothrow @trusted bool el_anydef(const elem* ed, const(elem)* e);
Does any definition of lvalue ed appear in e?
Returns:
true if there is one
nothrow @trusted elem* el_bin(OPER op, tym_t ty, elem* e1, elem* e2);
Make a binary operator node.
nothrow @trusted elem* el_una(OPER op, tym_t ty, elem* e1);
Make a unary operator node.
nothrow @trusted elem* el_vectorConst(tym_t ty, ulong val);
Create a const integer vector elem
Parameters:
tym_t ty type of the vector
ulong val value to broadcast to the vector elements
Returns:
created OPconst elem
nothrow @trusted bool el_sideeffect(const elem* e);
Returns:
true if elem has any side effects.
nothrow @trusted int el_depends(const(elem)* ea, const elem* eb);

Input ea lvalue (might be an OPbit)

Returns:
0 eb has no dependency on ea 1 eb might have a dependency on ea 2 eb definitely depends on ea
nothrow @trusted bool ERTOL(const elem* e);
Returns:
true elem evaluates right-to-left false elem evaluates left-to-right
nothrow @trusted bool el_returns(const(elem)* e);
Determine if expression may return. Does not detect all cases, errs on the side of saying it returns.
Parameters:
const(elem)* e tree
Returns:
false if expression never returns.
nothrow @trusted elem** el_scancommas(elem** pe);
Scan down commas and return the controlling elem. Extra layer of indirection so we can update (*ret)
nothrow @trusted int el_countCommas(const(elem)* e);
Count number of commas in the expression.
nothrow @trusted void shrinkLongDoubleConstantIfPossible(elem* e);
If e is a long double constant, and it is perfectly representable as a double constant, convert it to a double constant. Note that this must NOT be done in contexts where there are no further operations, since then it could change the type (eg, in the function call printf("%La", 2.0L); the 2.0 must stay as a long double).
nothrow @trusted elem* el_convert(ref GlobalOptimizer go, elem* e);
Run through a tree converting it to CODGEN.
nothrow @safe elem* el_const(tym_t ty, ref Vconst pconst);
Make a constant elem. ty = type of elem *pconst = union of constant data
nothrow @trusted elem* el_ctor_dtor(elem* ec, elem* ed, out elem* pedtor);
Create constructor/destructor pair of elems.

Caution The pattern generated here must match that detected in e2ir.c's visit(CallExp).

Parameters:
elem* ec code to construct (may be null)
elem* ed code to destruct
elem* pedtor set to destructor node
Returns:
constructor node
nothrow @trusted elem** el_parent(elem* e, return ref elem* pe);
Find and return pointer to parent of e starting at pe. Return null if can't find it.
nothrow @safe bool el_match(const elem* n1, const elem* n2);
Returns:
true if trees match.
nothrow @safe bool el_match5(const elem* n1, const elem* n2);
Kludge on el_match(). Same, but regard signed/unsigned as equivalent.
nothrow @trusted targ_llong el_tolong(elem* e);
Extract long value from constant elem.
nothrow @safe bool el_allbits(const elem* e, int bit);
Determine if constant e is all ones or all zeros.
Parameters:
elem* e elem to test
int bit 0: all zeros 1: 1 -1: all ones
Returns:
true if it is
nothrow @safe bool el_signx32(const elem* e);
Determine if constant e is a 32 bit or less value, or is a 32 bit value sign extended to 64 bits.
nothrow @safe uint el_alignsize(elem* e);
Returns:
alignment size of elem e
nothrow @trusted void elem_print(const elem* e, int nestlevel = 0);
Write out expression elem.