本文整理汇总了C++中SymbolRef::getLabel方法的典型用法代码示例。如果您正苦于以下问题:C++ SymbolRef::getLabel方法的具体用法?C++ SymbolRef::getLabel怎么用?C++ SymbolRef::getLabel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolRef
的用法示例。
在下文中一共展示了SymbolRef::getLabel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
bool
BinOutput::ConvertValueToBytes(Value& value,
Location loc,
NumericOutput& num_out)
{
// Binary objects we need to resolve against object, not against section.
if (value.isRelative())
{
Location label_loc;
IntNum ssymval;
Expr syme;
SymbolRef rel = value.getRelative();
if (rel->isAbsoluteSymbol())
syme = Expr(0);
else if (rel->getLabel(&label_loc) && label_loc.bc->getContainer())
syme = Expr(rel);
else if (getBinSSymValue(*rel, &ssymval))
syme = Expr(ssymval);
else
goto done;
// Handle PC-relative
if (value.getSubLocation(&label_loc) && label_loc.bc->getContainer())
syme -= label_loc;
// Add into absolute portion
value.AddAbs(syme);
value.ClearRelative();
}
done:
// Simplify absolute portion of value, transforming symrecs
if (Expr* abs = value.getAbs())
{
BinSimplify(*abs);
abs->Simplify(getDiagnostics());
}
// Output
IntNum intn;
m_object.getArch()->setEndian(num_out.getBytes());
if (value.OutputBasic(num_out, &intn, getDiagnostics()))
return true;
// Couldn't output, assume it contains an external reference.
Diag(value.getSource().getBegin(), diag::err_bin_extern_ref);
return false;
}
示例2: if
// Transforms instances of Symbol-Symbol [Symbol+(-1*Symbol)] into single
// ExprTerms if possible. Uses a simple n^2 algorithm because n is usually
// quite small. Also works for loc-loc (or Symbol-loc, loc-Symbol).
static void
TransformDistBase(Expr& e, int pos,
const TR1::function<bool (ExprTerm& term,
Location loc1,
Location loc2)> func)
{
ExprTerms& terms = e.getTerms();
if (pos < 0)
pos += static_cast<int>(terms.size());
ExprTerm& root = terms[pos];
if (!root.isOp(Op::ADD))
return;
// Handle symrec-symrec by checking for (-1*symrec)
// and symrec term pairs (where both symrecs are in the same
// segment).
llvm::SmallVector<int, 3> relpos, subpos, subneg1, subroot;
// Scan for symrec and (-1*symrec) terms (or location equivalents)
int n = pos-1;
while (n >= 0)
{
ExprTerm& child = terms[n];
if (child.isEmpty())
{
--n;
continue;
}
if (child.m_depth <= root.m_depth)
break;
if (child.m_depth != root.m_depth+1)
{
--n;
continue;
}
// Remember symrec terms
if (child.isType(ExprTerm::SYM | ExprTerm::LOC))
{
relpos.push_back(pos-n);
--n;
continue;
}
int curpos = n;
int sym, neg1;
// Remember (-1*symrec) terms
if (isNeg1Sym(e, &sym, &neg1, &n, true))
{
subpos.push_back(pos-sym);
subneg1.push_back(pos-neg1);
subroot.push_back(pos-curpos);
continue;
}
--n;
}
// Match additive and subtractive symbols.
for (size_t i=0; i<relpos.size(); ++i)
{
ExprTerm& relterm = terms[pos-relpos[i]];
SymbolRef rel = relterm.getSymbol();
for (size_t j=0; j<subpos.size(); ++j)
{
if (subpos[j] == 0xff)
continue; // previously matched
ExprTerm& subterm = terms[pos-subpos[j]];
SymbolRef sub = subterm.getSymbol();
// If it's the same symbol, even if it's external,
// they should cancel out.
if (rel && rel == sub)
{
relterm.Zero();
terms[pos-subpos[j]].Clear();
terms[pos-subneg1[j]].Clear();
terms[pos-subroot[j]].Zero();
subpos[j] = 0xff; // mark as matched
break;
}
Location rel_loc;
if (rel)
{
if (!rel->getLabel(&rel_loc))
continue; // external
}
else if (const Location* loc = relterm.getLocation())
rel_loc = *loc;
else
assert(false);
Location sub_loc;
if (sub)
//.........这里部分代码省略.........
示例3: if
void
ElfSymbol::Finalize(Symbol& sym, Diagnostic& diags)
{
// If symbol is a weakrefr, make it weak at this point.
if (m_weak_refr)
{
if (!sym.isDefined() &&
(sym.getVisibility() & (Symbol::GLOBAL | Symbol::COMMON)) == 0)
{
if (sym.isUsed())
{
setInTable(true);
sym.Declare(Symbol::GLOBAL);
setBinding(STB_WEAK);
}
else
{
setInTable(false);
return;
}
}
else if (!sym.isDefined() &&
(sym.getVisibility() & Symbol::GLOBAL) != 0)
{
setBinding(STB_GLOBAL);
}
}
// Don't put the LHS of weakrefs into the symbol table unless they're
// specifically requested.
if (m_weak_ref && (sym.getVisibility() == Symbol::DLOCAL ||
sym.getVisibility() == Symbol::LOCAL))
{
setInTable(false);
return;
}
// If symbol is in a TLS section, force its type to TLS.
Location loc;
Section* sect;
ElfSection* elfsect;
if (sym.getLabel(&loc) &&
(sect = loc.bc->getContainer()->AsSection()) &&
(elfsect = sect->getAssocData<ElfSection>()) &&
(elfsect->getFlags() & SHF_TLS))
{
m_type = STT_TLS;
}
// get size (if specified); expr overrides stored integer
if (!m_size.isEmpty())
{
if (!ExpandEqu(m_size))
{
diags.Report(m_size_source, diag::err_equ_circular_reference);
return;
}
SimplifyCalcDist(m_size, diags);
if (!m_size.isIntNum())
diags.Report(m_size_source, diag::err_size_integer);
}
// get EQU value for constants
const Expr* equ_expr_c = sym.getEqu();
if (equ_expr_c != 0)
{
Expr equ_expr = *equ_expr_c;
if (!ExpandEqu(equ_expr))
{
diags.Report(sym.getDefSource(), diag::err_equ_circular_reference);
return;
}
SimplifyCalcDist(equ_expr, diags);
// trivial case: simple integer
if (equ_expr.isIntNum())
{
m_index = SHN_ABS;
m_value = equ_expr.getIntNum();
return;
}
// otherwise might contain relocatable value (e.g. symbol alias)
std::auto_ptr<Expr> equ_expr_p(new Expr);
equ_expr_p->swap(equ_expr);
Value val(64, equ_expr_p);
val.setSource(sym.getDefSource());
if (!val.Finalize(diags, diag::err_equ_too_complex))
return;
if (val.isComplexRelative())
{
diags.Report(sym.getDefSource(), diag::err_equ_too_complex);
return;
}
// set section appropriately based on if value is relative
if (val.isRelative())
{
SymbolRef rel = val.getRelative();
//.........这里部分代码省略.........
示例4: if
void
CoffSymbol::Write(Bytes& bytes,
const Symbol& sym,
DiagnosticsEngine& diags,
StringTable& strtab) const
{
int vis = sym.getVisibility();
IntNum value = 0;
unsigned int scnum = 0xfffe; // -2 = debugging symbol
unsigned long scnlen = 0; // for sect auxent
unsigned long nreloc = 0; // for sect auxent
// Look at symrec for value/scnum/etc.
Location loc;
if (sym.getLabel(&loc))
{
Section* sect = 0;
if (loc.bc)
sect = loc.bc->getContainer()->getSection();
// it's a label: get value and offset.
// If there is not a section, leave as debugging symbol.
if (sect)
{
CoffSection* coffsect = sect->getAssocData<CoffSection>();
assert(coffsect != 0);
scnum = coffsect->m_scnum;
scnlen = coffsect->m_size;
nreloc = sect->getRelocs().size();
value = sect->getVMA();
if (loc.bc)
value += loc.getOffset();
}
}
else if (const Expr* equ_expr_c = sym.getEqu())
{
Expr equ_expr = *equ_expr_c;
if (!ExpandEqu(equ_expr))
{
diags.Report(sym.getDefSource(), diag::err_equ_circular_reference);
return;
}
SimplifyCalcDist(equ_expr, diags);
// trivial case: simple integer
if (equ_expr.isIntNum())
{
scnum = 0xffff; // -1 = absolute symbol
value = equ_expr.getIntNum();
}
else
{
// otherwise might contain relocatable value (e.g. symbol alias)
std::auto_ptr<Expr> equ_expr_p(new Expr);
equ_expr_p->swap(equ_expr);
Value val(64, equ_expr_p);
val.setSource(sym.getDefSource());
if (!val.Finalize(diags, diag::err_equ_too_complex))
return;
if (val.isComplexRelative())
{
diags.Report(sym.getDefSource(), diag::err_equ_too_complex);
return;
}
// set section appropriately based on if value is relative
if (val.isRelative())
{
SymbolRef rel = val.getRelative();
Location loc;
if (!rel->getLabel(&loc) || !loc.bc)
{
// Referencing an undefined label?
// GNU as silently allows this... but doesn't gen the symbol?
// We make it an error instead.
diags.Report(sym.getDefSource(), diag::err_equ_too_complex);
return;
}
Section* sect = loc.bc->getContainer()->getSection();
CoffSection* coffsect = sect->getAssocData<CoffSection>();
assert(coffsect != 0);
scnum = coffsect->m_scnum;
value = sect->getVMA() + loc.getOffset();
}
else
{
scnum = 0xffff; // -1 = absolute symbol
value = 0;
}
// add in any remaining absolute portion
if (Expr* abs = val.getAbs())
{
SimplifyCalcDist(*abs, diags);
if (abs->isIntNum())
value += abs->getIntNum();
else
diags.Report(sym.getDefSource(), diag::err_equ_not_integer);
//.........这里部分代码省略.........