本文整理汇总了C++中el_long函数的典型用法代码示例。如果您正苦于以下问题:C++ el_long函数的具体用法?C++ el_long怎么用?C++ el_long使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了el_long函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
/*********************************************
* Produce elem which increments the usage count for a particular line.
* Used to implement -cov switch (coverage analysis).
*/
elem *incUsageElem(IRState *irs, Loc loc)
{
unsigned linnum = loc.linnum;
if (!irs->blx->module->cov || !linnum ||
loc.filename != irs->blx->module->srcfile->toChars())
return NULL;
//printf("cov = %p, covb = %p, linnum = %u\n", irs->blx->module->cov, irs->blx->module->covb, p, linnum);
linnum--; // from 1-based to 0-based
/* Set bit in covb[] indicating this is a valid code line number
*/
unsigned *p = irs->blx->module->covb;
if (p) // covb can be NULL if it has already been written out to its .obj file
{
assert(linnum < irs->blx->module->numlines);
p += linnum / (sizeof(*p) * 8);
*p |= 1 << (linnum & (sizeof(*p) * 8 - 1));
}
elem *e;
e = el_ptr(irs->blx->module->cov);
e = el_bin(OPadd, TYnptr, e, el_long(TYuint, linnum * 4));
e = el_una(OPind, TYuint, e);
e = el_bin(OPaddass, TYuint, e, el_long(TYuint, 1));
return e;
}
示例2: el_var
elem *setEthis(Loc loc, IRState *irs, elem *ey, AggregateDeclaration *ad)
{
elem *ethis;
FuncDeclaration *thisfd = irs->getFunc();
int offset = 0;
Dsymbol *cdp = ad->toParent2(); // class/func we're nested in
//printf("setEthis(ad = %s, cdp = %s, thisfd = %s)\n", ad->toChars(), cdp->toChars(), thisfd->toChars());
if (cdp == thisfd)
{ /* Class we're new'ing is a local class in this function:
* void thisfd() { class ad { } }
*/
if (irs->sclosure)
ethis = el_var(irs->sclosure);
else if (irs->sthis)
{
if (thisfd->hasNestedFrameRefs())
{
ethis = el_ptr(irs->sthis);
}
else
ethis = el_var(irs->sthis);
}
else
{
ethis = el_long(TYnptr, 0);
if (thisfd->hasNestedFrameRefs())
{
ethis->Eoper = OPframeptr;
}
}
}
else if (thisfd->vthis &&
(cdp == thisfd->toParent2() ||
(cdp->isClassDeclaration() &&
cdp->isClassDeclaration()->isBaseOf(thisfd->toParent2()->isClassDeclaration(), &offset)
)
)
)
{ /* Class we're new'ing is at the same level as thisfd
*/
assert(offset == 0); // BUG: should handle this case
ethis = el_var(irs->sthis);
}
else
{
ethis = getEthis(loc, irs, ad->toParent2());
ethis = el_una(OPaddr, TYnptr, ethis);
}
ey = el_bin(OPadd, TYnptr, ey, el_long(TYsize_t, ad->vthis->offset));
ey = el_una(OPind, TYnptr, ey);
ey = el_bin(OPeq, TYnptr, ey, ethis);
return ey;
}
示例3: toSymbol
elem *Module::toEmodulename()
{
elem *efilename;
// Get filename
if (needModuleInfo())
{ Symbol *si;
/* Class ModuleInfo is defined in std.moduleinfo.
* The first member is the name of it, char name[],
* which will be at offset 8.
*/
si = toSymbol();
#if 1
// Use this instead so -fPIC will work
efilename = el_ptr(si);
efilename = el_bin(OPadd, TYnptr, efilename, el_long(TYuint, 8));
efilename = el_una(OPind, TYdarray, efilename);
#else
efilename = el_var(si);
efilename->Ety = TYdarray;
efilename->EV.sp.Voffset += 8;
#endif
}
else // generate our own filename
{
efilename = toEfilename();
}
return efilename;
}
示例4: el_long
/**************************************
* Given an expression e that is an array,
* determine and set the 'length' variable.
* Input:
* lengthVar Symbol of 'length' variable
* &e expression that is the array
* t1 Type of the array
* Output:
* e is rewritten to avoid side effects
* Returns:
* expression that initializes 'length'
*/
elem *resolveLengthVar(VarDeclaration *lengthVar, elem **pe, Type *t1)
{
//printf("resolveLengthVar()\n");
elem *einit = NULL;
if (lengthVar && !(lengthVar->storage_class & STCconst))
{
elem *elength;
Symbol *slength;
if (t1->ty == Tsarray)
{
TypeSArray *tsa = (TypeSArray *)t1;
dinteger_t length = tsa->dim->toInteger();
elength = el_long(TYsize_t, length);
goto L3;
}
else if (t1->ty == Tarray)
{
elength = *pe;
*pe = el_same(&elength);
elength = el_una(I64 ? OP128_64 : OP64_32, TYsize_t, elength);
L3:
slength = toSymbol(lengthVar);
//symbol_add(slength);
einit = el_bin(OPeq, TYsize_t, el_var(slength), elength);
}
}
return einit;
}
示例5: type_alloc
symbol *callFuncsAndGates(Module *m, symbols *sctors, StaticDtorDeclarations *ectorgates,
const char *id)
{
symbol *sctor = NULL;
if ((sctors && sctors->dim) ||
(ectorgates && ectorgates->dim))
{
static type *t;
if (!t)
{
/* t will be the type of the functions generated:
* extern (C) void func();
*/
t = type_alloc(TYnfunc);
t->Tflags |= TFprototype | TFfixed;
t->Tmangle = mTYman_c;
t->Tnext = tsvoid;
tsvoid->Tcount++;
}
localgot = NULL;
sctor = m->toSymbolX(id, SCglobal, t, "FZv");
cstate.CSpsymtab = &sctor->Sfunc->Flocsym;
elem *ector = NULL;
if (ectorgates)
{
for (size_t i = 0; i < ectorgates->dim; i++)
{ StaticDtorDeclaration *f = (*ectorgates)[i];
Symbol *s = f->vgate->toSymbol();
elem *e = el_var(s);
e = el_bin(OPaddass, TYint, e, el_long(TYint, 1));
ector = el_combine(ector, e);
}
}
if (sctors)
{
for (size_t i = 0; i < sctors->dim; i++)
{ symbol *s = (*sctors)[i];
elem *e = el_una(OPucall, TYvoid, el_var(s));
ector = el_combine(ector, e);
}
}
block *b = block_calloc();
b->BC = BCret;
b->Belem = ector;
sctor->Sfunc->Fstartline.Sfilename = m->arg;
sctor->Sfunc->Fstartblock = b;
writefunc(sctor);
}
return sctor;
}
示例6: symbol_debug
elem *nteh_setScopeTableIndex(Blockx *blx, int scope_index)
{
elem *e;
Symbol *s;
s = blx->context;
symbol_debug(s);
e = el_var(s);
e->EV.sp.Voffset = nteh_offset_sindex();
return el_bin(OPeq, TYint, e, el_long(TYint, scope_index));
}
示例7: visit
void visit(SwitchErrorStatement *s)
{
Blockx *blx = irs->blx;
//printf("SwitchErrorStatement::toIR()\n");
elem *efilename = el_ptr(toSymbol(blx->module));
elem *elinnum = el_long(TYint, s->loc.linnum);
elem *e = el_bin(OPcall, TYvoid, el_var(getRtlsym(RTLSYM_DSWITCHERR)), el_param(elinnum, efilename));
block_appendexp(blx->curblock, e);
}
示例8: el_ptr
void SwitchErrorStatement::toIR(IRState *irs)
{
Blockx *blx = irs->blx;
//printf("SwitchErrorStatement::toIR()\n");
elem *efilename = el_ptr(blx->module->toSymbol());
elem *elinnum = el_long(TYint, loc.linnum);
elem *e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_DSWITCHERR]), el_param(elinnum, efilename));
block_appendexp(blx->curblock, e);
}
示例9: strlen
elem *toEfilename(Module *m)
{
//printf("toEfilename(%s)\n", m->toChars());
const char *id = m->srcfile->toChars();
size_t len = strlen(id);
if (!m->sfilename)
{
// Put out as a static array
m->sfilename = toStringSymbol(id, len, 1);
}
// Turn static array into dynamic array
return el_pair(TYdarray, el_long(TYsize_t, len), el_ptr(m->sfilename));
}
示例10: getEthis
/*************************
* Initialize the hidden aggregate member, vthis, with
* the context pointer.
* Returns:
* *(ey + ad.vthis.offset) = this;
*/
elem *setEthis(Loc loc, IRState *irs, elem *ey, AggregateDeclaration *ad)
{
elem *ethis;
FuncDeclaration *thisfd = irs->getFunc();
int offset = 0;
Dsymbol *adp = ad->toParent2(); // class/func we're nested in
//printf("[%s] setEthis(ad = %s, adp = %s, thisfd = %s)\n", loc.toChars(), ad->toChars(), adp->toChars(), thisfd->toChars());
if (adp == thisfd)
{
ethis = getEthis(loc, irs, ad);
}
else if (thisfd->vthis &&
(adp == thisfd->toParent2() ||
(adp->isClassDeclaration() &&
adp->isClassDeclaration()->isBaseOf(thisfd->toParent2()->isClassDeclaration(), &offset)
)
)
)
{
/* Class we're new'ing is at the same level as thisfd
*/
assert(offset == 0); // BUG: should handle this case
ethis = el_var(irs->sthis);
}
else
{
ethis = getEthis(loc, irs, adp);
FuncDeclaration *fdp = adp->isFuncDeclaration();
if (fdp && fdp->hasNestedFrameRefs())
ethis = el_una(OPaddr, TYnptr, ethis);
}
ey = el_bin(OPadd, TYnptr, ey, el_long(TYsize_t, ad->vthis->offset));
ey = el_una(OPind, TYnptr, ey);
ey = el_bin(OPeq, TYnptr, ey, ethis);
return ey;
}
示例11: symbol_name
void FuncDeclaration::buildClosure(IRState *irs)
{
if (needsClosure())
{ // Generate closure on the heap
// BUG: doesn't capture variadic arguments passed to this function
#if DMDV2
/* BUG: doesn't handle destructors for the local variables.
* The way to do it is to make the closure variables the fields
* of a class object:
* class Closure
* { vtbl[]
* monitor
* ptr to destructor
* sthis
* ... closure variables ...
* ~this() { call destructor }
* }
*/
#endif
//printf("FuncDeclaration::buildClosure()\n");
Symbol *sclosure;
sclosure = symbol_name("__closptr",SCauto,Type::tvoidptr->toCtype());
sclosure->Sflags |= SFLtrue | SFLfree;
symbol_add(sclosure);
irs->sclosure = sclosure;
unsigned offset = PTRSIZE; // leave room for previous sthis
for (size_t i = 0; i < closureVars.dim; i++)
{ VarDeclaration *v = closureVars[i];
assert(v->isVarDeclaration());
#if DMDV2
if (v->needsAutoDtor())
/* Because the value needs to survive the end of the scope!
*/
v->error("has scoped destruction, cannot build closure");
if (v->isargptr)
/* See Bugzilla 2479
* This is actually a bug, but better to produce a nice
* message at compile time rather than memory corruption at runtime
*/
v->error("cannot reference variadic arguments from closure");
#endif
/* Align and allocate space for v in the closure
* just like AggregateDeclaration::addField() does.
*/
unsigned memsize;
unsigned memalignsize;
structalign_t xalign;
#if DMDV2
if (v->storage_class & STClazy)
{
/* Lazy variables are really delegates,
* so give same answers that TypeDelegate would
*/
memsize = PTRSIZE * 2;
memalignsize = memsize;
xalign = global.structalign;
}
else if (v->isRef() || v->isOut())
{ // reference parameters are just pointers
memsize = PTRSIZE;
memalignsize = memsize;
xalign = global.structalign;
}
else
#endif
{
memsize = v->type->size();
memalignsize = v->type->alignsize();
xalign = v->alignment;
}
AggregateDeclaration::alignmember(xalign, memalignsize, &offset);
v->offset = offset;
offset += memsize;
/* Can't do nrvo if the variable is put in a closure, since
* what the shidden points to may no longer exist.
*/
if (nrvo_can && nrvo_var == v)
{
nrvo_can = 0;
}
}
// offset is now the size of the closure
// Allocate memory for the closure
elem *e;
e = el_long(TYsize_t, offset);
e = el_bin(OPcall, TYnptr, el_var(rtlsym[RTLSYM_ALLOCMEMORY]), e);
// Assign block of memory to sclosure
// sclosure = allocmemory(sz);
e = el_bin(OPeq, TYvoid, el_var(sclosure), e);
// Set the first element to sthis
// *(sclosure + 0) = sthis;
elem *ethis;
if (irs->sthis)
//.........这里部分代码省略.........
示例12: optfunc
void optfunc()
{
#if !HTOD
block *b;
int iter; // iteration count
clock_t starttime;
cmes ("optfunc()\n");
dbg_optprint("optfunc\n");
#ifdef DEBUG
if (debugb)
{
dbg_printf("................Before optimization.........\n");
WRfunc();
}
#endif
iter = 0;
if (localgot)
{ // Initialize with:
// localgot = OPgot;
elem *e = el_long(TYnptr, 0);
e->Eoper = OPgot;
e = el_bin(OPeq, TYnptr, el_var(localgot), e);
startblock->Belem = el_combine(e, startblock->Belem);
}
// Each pass through the loop can reduce only one level of comma expression.
// The infinite loop check needs to take this into account.
int iterationLimit = 0;
for (b = startblock; b; b = b->Bnext)
{
if (!b->Belem)
continue;
int d = el_countCommas(b->Belem);
if (d > iterationLimit)
iterationLimit = d;
}
// Some functions can take enormous amounts of time to optimize.
// We try to put a lid on it.
starttime = clock();
do
{
//printf("iter = %d\n", iter);
#if TX86
if (++iter > 200)
{ assert(iter < iterationLimit); // infinite loop check
break;
}
#else
L1:
#endif
#if MARS
util_progress();
#else
file_progress();
#endif
//printf("optelem\n");
/* canonicalize the trees */
for (b = startblock; b; b = b->Bnext)
if (b->Belem)
{
#if DEBUG
if(debuge)
{
dbg_printf("before\n");
elem_print(b->Belem);
//el_check(b->Belem);
}
#endif
b->Belem = doptelem(b->Belem,bc_goal[b->BC] | GOALagain);
#if DEBUG
if(0 && debugf)
{
dbg_printf("after\n");
elem_print(b->Belem);
}
#endif
}
//printf("blockopt\n");
#if TX86
if (mfoptim & MFdc)
blockopt(0); // do block optimization
out_regcand(&globsym); // recompute register candidates
changes = 0; /* no changes yet */
if (mfoptim & MFcnp)
constprop(); /* make relationals unsigned */
if (mfoptim & (MFli | MFliv))
#else
if (config.optimized && (mfoptim & MFdc))
blockopt(0); // do block optimization
dbg_optprint("blockopt\n");
out_regcand(); // recompute register candidates
changes = 0; /* no changes yet */
dbg_optprint("constprop\n");
if (config.optimized && (mfoptim & MFcnp))
//.........这里部分代码省略.........
示例13: el_var
/******************************************
* 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.
* This routine is critical for implementing nested functions.
*/
elem *getEthis(Loc loc, IRState *irs, Dsymbol *fd)
{
elem *ethis;
FuncDeclaration *thisfd = irs->getFunc();
Dsymbol *fdparent = fd->toParent2();
Dsymbol *fdp = fdparent;
/* These two are compiler generated functions for the in and out contracts,
* and are called from an overriding function, not just the one they're
* nested inside, so this hack is so they'll pass
*/
if (fdparent != thisfd && (fd->ident == Id::require || fd->ident == Id::ensure))
{
FuncDeclaration *fdthis = thisfd;
for (size_t i = 0; ; )
{
if (i == fdthis->foverrides.dim)
{
if (i == 0)
break;
fdthis = fdthis->foverrides[0];
i = 0;
continue;
}
if (fdthis->foverrides[i] == fdp)
{
fdparent = thisfd;
break;
}
i++;
}
}
//printf("[%s] getEthis(thisfd = '%s', fd = '%s', fdparent = '%s')\n", loc.toChars(), thisfd->toPrettyChars(), fd->toPrettyChars(), fdparent->toPrettyChars());
if (fdparent == thisfd)
{
/* Going down one nesting level, i.e. we're calling
* a nested function from its enclosing function.
*/
if (irs->sclosure && !(fd->ident == Id::require || fd->ident == Id::ensure))
{
ethis = el_var(irs->sclosure);
}
else if (irs->sthis)
{
// We have a 'this' pointer for the current function
/* If no variables in the current function's frame are
* referenced by nested functions, then we can 'skip'
* adding this frame into the linked list of stack
* frames.
*/
if (thisfd->hasNestedFrameRefs())
{
/* Local variables are referenced, can't skip.
* Address of 'sthis' gives the 'this' for the nested
* function
*/
ethis = el_ptr(irs->sthis);
}
else
{
ethis = el_var(irs->sthis);
}
}
else
{
/* No 'this' pointer for current function,
*/
if (thisfd->hasNestedFrameRefs())
{
/* OPframeptr is an operator that gets the frame pointer
* for the current function, i.e. for the x86 it gets
* the value of EBP
*/
ethis = el_long(TYnptr, 0);
ethis->Eoper = OPframeptr;
}
else
{
/* Use NULL if no references to the current function's frame
*/
ethis = el_long(TYnptr, 0);
}
}
}
else
{
if (!irs->sthis) // if no frame pointer for this function
{
fd->error(loc, "is a nested function and cannot be accessed from %s", irs->getFunc()->toPrettyChars());
return el_long(TYnptr, 0); // error recovery
}
//.........这里部分代码省略.........
示例14: buildClosure
//.........这里部分代码省略.........
{
// reference parameters are just pointers
memsize = Target::ptrsize;
memalignsize = memsize;
xalign = STRUCTALIGN_DEFAULT;
}
else
{
memsize = v->type->size();
memalignsize = v->type->alignsize();
xalign = v->alignment;
}
AggregateDeclaration::alignmember(xalign, memalignsize, &offset);
v->offset = offset;
offset += memsize;
/* Set Sscope to closure */
Symbol *vsym = toSymbol(v);
assert(vsym->Sscope == NULL);
vsym->Sscope = sclosure;
/* Add variable as closure type member */
symbol_struct_addField(Closstru->Ttag, vsym->Sident, vsym->Stype, v->offset);
//printf("closure field %s: memalignsize: %i, offset: %i\n", vsym->Sident, memalignsize, v->offset);
/* Can't do nrvo if the variable is put in a closure, since
* what the shidden points to may no longer exist.
*/
if (fd->nrvo_can && fd->nrvo_var == v)
{
fd->nrvo_can = 0;
}
}
// offset is now the size of the closure
Closstru->Ttag->Sstruct->Sstructsize = offset;
// Allocate memory for the closure
elem *e = el_long(TYsize_t, offset);
e = el_bin(OPcall, TYnptr, el_var(getRtlsym(RTLSYM_ALLOCMEMORY)), e);
toTraceGC(irs, e, &fd->loc);
// Assign block of memory to sclosure
// sclosure = allocmemory(sz);
e = el_bin(OPeq, TYvoid, el_var(sclosure), e);
// Set the first element to sthis
// *(sclosure + 0) = sthis;
elem *ethis;
if (irs->sthis)
ethis = el_var(irs->sthis);
else
ethis = el_long(TYnptr, 0);
elem *ex = el_una(OPind, TYnptr, el_var(sclosure));
ex = el_bin(OPeq, TYnptr, ex, ethis);
e = el_combine(e, ex);
// Copy function parameters into closure
for (size_t i = 0; i < fd->closureVars.dim; i++)
{
VarDeclaration *v = fd->closureVars[i];
if (!v->isParameter())
continue;
tym_t tym = totym(v->type);
bool win64ref = ISWIN64REF(v);
if (win64ref)
{
if (v->storage_class & STClazy)
tym = TYdelegate;
}
else if (ISREF(v, NULL))
tym = TYnptr; // reference parameters are just pointers
else if (v->storage_class & STClazy)
tym = TYdelegate;
ex = el_bin(OPadd, TYnptr, el_var(sclosure), el_long(TYsize_t, v->offset));
ex = el_una(OPind, tym, ex);
elem *ev = el_var(toSymbol(v));
if (win64ref)
{
ev->Ety = TYnptr;
ev = el_una(OPind, tym, ev);
if (tybasic(ev->Ety) == TYstruct || tybasic(ev->Ety) == TYarray)
ev->ET = Type_toCtype(v->type);
}
if (tybasic(ex->Ety) == TYstruct || tybasic(ex->Ety) == TYarray)
{
::type *t = Type_toCtype(v->type);
ex->ET = t;
ex = el_bin(OPstreq, tym, ex, ev);
ex->ET = t;
}
else
ex = el_bin(OPeq, tym, ex, ev);
e = el_combine(e, ex);
}
block_appendexp(irs->blx->curblock, e);
}
}
示例15: incUsage
void ReturnStatement::toIR(IRState *irs)
{
Blockx *blx = irs->blx;
incUsage(irs, loc);
if (exp)
{ elem *e;
FuncDeclaration *func = irs->getFunc();
assert(func);
assert(func->type->ty == Tfunction);
TypeFunction *tf = (TypeFunction *)(func->type);
enum RET retmethod = tf->retStyle();
if (retmethod == RETstack)
{
elem *es;
/* If returning struct literal, write result
* directly into return value
*/
if (exp->op == TOKstructliteral)
{ StructLiteralExp *se = (StructLiteralExp *)exp;
char save[sizeof(StructLiteralExp)];
memcpy(save, se, sizeof(StructLiteralExp));
se->sym = irs->shidden;
se->soffset = 0;
se->fillHoles = 1;
e = exp->toElemDtor(irs);
memcpy(se, save, sizeof(StructLiteralExp));
}
else
e = exp->toElemDtor(irs);
assert(e);
if (exp->op == TOKstructliteral ||
(func->nrvo_can && func->nrvo_var))
{
// Return value via hidden pointer passed as parameter
// Write exp; return shidden;
es = e;
}
else
{
// Return value via hidden pointer passed as parameter
// Write *shidden=exp; return shidden;
int op;
tym_t ety;
ety = e->Ety;
es = el_una(OPind,ety,el_var(irs->shidden));
op = (tybasic(ety) == TYstruct) ? OPstreq : OPeq;
es = el_bin(op, ety, es, e);
if (op == OPstreq)
es->ET = exp->type->toCtype();
#if DMDV2
/* Call postBlit() on *shidden
*/
Type *tb = exp->type->toBasetype();
//if (tb->ty == Tstruct) exp->dump(0);
if ((exp->op == TOKvar || exp->op == TOKdotvar || exp->op == TOKstar || exp->op == TOKthis) &&
tb->ty == Tstruct)
{ StructDeclaration *sd = ((TypeStruct *)tb)->sym;
if (sd->postblit)
{ FuncDeclaration *fd = sd->postblit;
if (fd->storage_class & STCdisable)
{
fd->toParent()->error(loc, "is not copyable because it is annotated with @disable");
}
elem *ec = el_var(irs->shidden);
ec = callfunc(loc, irs, 1, Type::tvoid, ec, tb->pointerTo(), fd, fd->type, NULL, NULL);
es = el_bin(OPcomma, ec->Ety, es, ec);
}
#if 0
/* It has been moved, so disable destructor
*/
if (exp->op == TOKvar)
{ VarExp *ve = (VarExp *)exp;
VarDeclaration *v = ve->var->isVarDeclaration();
if (v && v->rundtor)
{
elem *er = el_var(v->rundtor->toSymbol());
er = el_bin(OPeq, TYint, er, el_long(TYint, 0));
es = el_bin(OPcomma, TYint, es, er);
}
}
#endif
}
#endif
}
e = el_var(irs->shidden);
e = el_bin(OPcomma, e->Ety, es, e);
}
#if DMDV2
else if (tf->isref)
{ // Reference return, so convert to a pointer
Expression *ae = exp->addressOf(NULL);
e = ae->toElemDtor(irs);
//.........这里部分代码省略.........