decompiler  1.0.0
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
HighVariable Class Reference

A high-level variable modeled as a list of low-level variables, each written once. More...

#include <variable.hh>

Public Types

enum  {
  flagsdirty = 1, namerepdirty = 2, typedirty = 4, coverdirty = 8,
  symboldirty = 0x10, copy_in1 = 0x20, copy_in2 = 0x40, type_finalized = 0x80,
  unmerged = 0x100
}
 Dirtiness flags for a HighVariable. More...
 

Public Member Functions

 HighVariable (Varnode *vn)
 Construct a HighVariable with a single member Varnode. More...
 
DatatypegetType (void) const
 Get the data-type.
 
SymbolgetSymbol (void) const
 Get the Symbol associated with this or null.
 
SymbolEntrygetSymbolEntry (void) const
 
int4 getSymbolOffset (void) const
 Get the SymbolEntry mapping to this or null. More...
 
int4 numInstances (void) const
 Get the number of member Varnodes this has.
 
VarnodegetInstance (int4 i) const
 Get the i-th member Varnode.
 
void finalizeDatatype (Datatype *tp)
 Set a final datatype for this variable. More...
 
void printCover (ostream &s) const
 Print details of the cover for this (for debug purposes) More...
 
void printInfo (ostream &s) const
 Print information about this HighVariable to stream. More...
 
bool hasName (void) const
 Check if this HighVariable can be named. More...
 
VarnodegetTiedVarnode (void) const
 Find the first address tied member Varnode. More...
 
VarnodegetInputVarnode (void) const
 Find (the) input member Varnode. More...
 
VarnodegetTypeRepresentative (void) const
 Get a member Varnode with the strongest data-type. More...
 
VarnodegetNameRepresentative (void) const
 Get a member Varnode that dictates the naming of this HighVariable. More...
 
int4 getNumMergeClasses (void) const
 Get the number of speculative merges for this.
 
bool isMapped (void) const
 Return true if this is mapped.
 
bool isPersist (void) const
 Return true if this is a global variable.
 
bool isAddrTied (void) const
 Return true if this is address ties.
 
bool isInput (void) const
 Return true if this is an input variable.
 
bool isImplied (void) const
 Return true if this is an implied variable.
 
bool isSpacebase (void) const
 Return true if this is a spacebase.
 
bool isConstant (void) const
 Return true if this is a constant.
 
bool isUnaffected (void) const
 Return true if this is an unaffected register.
 
bool isExtraOut (void) const
 Return true if this is an extra output.
 
void setMark (void) const
 Set the mark on this variable.
 
void clearMark (void) const
 Clear the mark on this variable.
 
bool isMark (void) const
 Return true if this is marked.
 
bool isUnmerged (void) const
 Return true if this has merge problems.
 
bool hasCover (void) const
 Determine if this HighVariable has an associated cover. More...
 
bool isUnattached (void) const
 Return true if this has no member Varnode.
 
bool isTypeLock (void) const
 Return true if this is typelocked.
 
bool isNameLock (void) const
 Return true if this is namelocked.
 
void saveXml (ostream &s) const
 Save the variable to stream as an XML <high> tag. More...
 

Static Public Member Functions

static bool compareName (Varnode *vn1, Varnode *vn2)
 Determine which given Varnode is most nameable. More...
 
static bool compareJustLoc (const Varnode *a, const Varnode *b)
 Compare based on storage location. More...
 

Private Member Functions

int4 instanceIndex (const Varnode *vn) const
 Find the index of a specific Varnode member. More...
 
void updateFlags (void) const
 (Re)derive boolean properties of this from the member Varnodes More...
 
void updateCover (void) const
 (Re)derive the cover of this from the member Varnodes More...
 
void updateType (void) const
 (Re)derive the data-type for this from the member Varnodes More...
 
void updateSymbol (void) const
 (Re)derive the Symbol and offset for this from member Varnodes
 
void setCopyIn1 (void) const
 Mark the existence of one COPY into this.
 
void setCopyIn2 (void) const
 Mark the existence of two COPYs into this.
 
void clearCopyIns (void) const
 Clear marks indicating COPYs into this.
 
bool hasCopyIn1 (void) const
 Is there at least one COPY into this.
 
bool hasCopyIn2 (void) const
 Is there at least two COPYs into this.
 
void remove (Varnode *vn)
 Remove a member Varnode from this. More...
 
void merge (HighVariable *tv2, bool isspeculative)
 Merge another HighVariable into this. More...
 
void setSymbol (Varnode *vn) const
 Update Symbol information for this from the given member Varnode. More...
 
void setSymbolReference (Symbol *sym, int4 off)
 Attach a reference to a Symbol to this. More...
 
void flagsDirty (void) const
 Mark the boolean properties as dirty.
 
void coverDirty (void) const
 Mark the cover as dirty.
 
void typeDirty (void) const
 Mark the data-type as dirty.
 
void setUnmerged (void) const
 Mark this as having merge problems.
 

Private Attributes

vector< Varnode * > inst
 The member Varnode objects making up this HighVariable.
 
int4 numMergeClasses
 Number of different speculative merge classes in this.
 
uint4 highflags
 Dirtiness flags.
 
uint4 flags
 Boolean properties inherited from Varnode members.
 
Datatypetype
 The data-type for this.
 
VarnodenameRepresentative
 The storage location used to generate a Symbol name.
 
Cover wholecover
 The ranges of code addresses covered by this HighVariable.
 
Symbolsymbol
 The Symbol this HighVariable is tied to.
 
int4 symboloffset
 -1=perfect symbol match >=0, offset
 

Friends

class Varnode
 
class Merge
 

Detailed Description

A high-level variable modeled as a list of low-level variables, each written once.

In the Static Single Assignment (SSA) representation of a function's data-flow, the Varnode object represents a variable node. This is a low-level variable: it is written to at most once, and there is 1 or more reads. A high-level variable, in the source language may be written to multiple times. We model this idea as a list of Varnode objects, where a different Varnode holds the value of the variable for different parts of the code. The range(s) of code for which a single Varnode holds the high-level variable's value is the cover or range of that Varnode and is modeled by the class Cover. Within a high-level variable, HighVariable, the covers of member Varnode objects should not intersect, as that represents the variable holding two or more different values at the same place in the code. The HighVariable inherits a cover which is the union of the covers of its Varnodes.

Member Enumeration Documentation

anonymous enum

Dirtiness flags for a HighVariable.

The HighVariable inherits its Cover, its data-type, and other boolean properties from its Varnodes. The object holds these explicitly, but the values may become stale as the data-flow transforms. So we keep track of when these inherited values are dirty

Enumerator
flagsdirty 

Boolean properties for the HighVariable are dirty.

namerepdirty 

The name representative for the HighVariable is dirty.

typedirty 

The data-type for the HighVariable is dirty.

coverdirty 

The cover for the HighVariable is dirty.

symboldirty 

The symbol attachment is dirty.

copy_in1 

There exists at least 1 COPY into this HighVariable from other HighVariables.

copy_in2 

There exists at least 2 COPYs into this HighVariable from other HighVariables.

type_finalized 

Set if a final data-type is locked in and dirtying is disabled.

unmerged 

Set if part of a multi-entry Symbol but did not get merged with other SymbolEntrys.

Constructor & Destructor Documentation

HighVariable::HighVariable ( Varnode vn)

Construct a HighVariable with a single member Varnode.

The new instance starts off with no associate Symbol and all properties marked as dirty.

Parameters
vnis the single Varnode member

References coverdirty, flags, flagsdirty, Varnode::getSymbolEntry(), highflags, inst, namerepdirty, nameRepresentative, numMergeClasses, Varnode::setHigh(), setSymbol(), symbol, symboloffset, type, and typedirty.

Referenced by setUnmerged().

Member Function Documentation

bool HighVariable::compareJustLoc ( const Varnode a,
const Varnode b 
)
static

Compare based on storage location.

Compare two Varnode objects based just on their storage address

Parameters
ais the first Varnode to compare
bis the second Varnode
Returns
true if the first Varnode should be ordered before the second

References Varnode::getAddr().

Referenced by isNameLock(), merge(), and remove().

bool HighVariable::compareName ( Varnode vn1,
Varnode vn2 
)
static

Determine which given Varnode is most nameable.

Given two Varnode (members), sort them based on naming properties:

Returns
true if the second Varnode's name would override the first's

References Varnode::getDef(), Varnode::getSpace(), PcodeOp::getTime(), AddrSpace::getType(), IPTR_INTERNAL, Varnode::isAddrTied(), Varnode::isInput(), Varnode::isNameLock(), Varnode::isPersist(), Varnode::isUnaffected(), and Varnode::isWritten().

Referenced by getNameRepresentative(), and isNameLock().

void HighVariable::finalizeDatatype ( Datatype tp)

Set a final datatype for this variable.

The data-type its dirtying mechanism is disabled. The data-type will not change, unless this method is called again.

Parameters
tpis the data-type to set

References highflags, type, and type_finalized.

Referenced by getInstance(), and Funcdata::syncVarnodesWithSymbol().

Varnode * HighVariable::getInputVarnode ( void  ) const

Find (the) input member Varnode.

This should only be called if isInput() returns true. If there is no input member, this will throw an exception.

Returns
the input Varnode member

References inst, and isInput().

Referenced by hasName(), Merge::mergeTestAdjacent(), and printCover().

Varnode * HighVariable::getNameRepresentative ( void  ) const

Get a member Varnode that dictates the naming of this HighVariable.

Members are scored based the properties that are most dominating in choosing a name.

Returns
the highest scoring Varnode member

References compareName(), highflags, inst, namerepdirty, and nameRepresentative.

Referenced by ActionNameVars::linkSymbols(), printCover(), PrintLanguage::pushVnExplicit(), PrintLanguage::pushVnLHS(), and saveXml().

SymbolEntry * HighVariable::getSymbolEntry ( void  ) const

Assuming there is a Symbol attached to this, run through the Varnode members until we find one with a SymbolEntry corresponding to the Symbol and return it.

Returns
the SymbolEntry that mapped the Symbol to this or null if no Symbol is attached

References SymbolEntry::getSymbol(), inst, and symbol.

Referenced by getSymbol(), and PrintC::pushSymbol().

int4 HighVariable::getSymbolOffset ( void  ) const
inline

Get the SymbolEntry mapping to this or null.

Get the Symbol offset associated with this

References symboloffset.

Referenced by ActionNameVars::linkSymbols(), Merge::mergeTestRequired(), PrintC::opPtrsub(), PrintLanguage::pushVnExplicit(), and PrintLanguage::pushVnLHS().

Varnode * HighVariable::getTiedVarnode ( void  ) const

Find the first address tied member Varnode.

This should only be called if isAddrTied() returns true. If there is no address tied member, this will throw an exception.

Returns
the first address tied member

References inst, and isAddrTied().

Referenced by MapState::gatherHighs(), Merge::markInternalCopies(), Merge::mergeTestRequired(), and printCover().

Varnode * HighVariable::getTypeRepresentative ( void  ) const

Get a member Varnode with the strongest data-type.

Find the member Varnode with the most specialized data-type, handling bool specially. Boolean data-types are specialized in the data-type lattice, but not all byte values are boolean values. Within the Varnode/PcodeOp tree, the bool data-type can only propagate to a Varnode if it is verified to only take the boolean values 0 and 1. Since the data-type representative represents the type of all instances, if any instance is not boolean, then the HighVariable cannot be boolean, even though bool is more specialized. This method uses Datatype::typeOrderBool() to implement the special handling.

Returns
the representative member

References Varnode::getType(), inst, Varnode::isTypeLock(), and Datatype::typeOrderBool().

Referenced by printCover(), and updateType().

bool HighVariable::hasCover ( void  ) const
inline

Determine if this HighVariable has an associated cover.

Constant and annotation variables do not have a cover

Returns
true if this has a cover

References Varnode::annotation, Varnode::constant, Varnode::insert, and updateFlags().

Referenced by Merge::mergeTest(), and updateCover().

bool HighVariable::hasName ( void  ) const

Check if this HighVariable can be named.

All Varnode objects are assigned a HighVariable, including those that don't get names like indirect variables, constants, and annotations. Determine if this, as inherited from its member Varnodes, can have a name.

Returns
true if this can have a name

References getInputVarnode(), Varnode::hasCover(), inst, Varnode::isIllegalInput(), Varnode::isImplied(), Varnode::isIndirectOnly(), isInput(), Varnode::isSpacebase(), and isUnaffected().

Referenced by ActionNameVars::linkSymbols(), and printCover().

int4 HighVariable::instanceIndex ( const Varnode vn) const
private

Find the index of a specific Varnode member.

Find the index, for use with getInstance(), that will retrieve the given Varnode member

Parameters
vnis the given Varnode member
Returns
the index of the member or -1 if it is not a member

References inst.

void HighVariable::merge ( HighVariable tv2,
bool  isspeculative 
)
private

Merge another HighVariable into this.

The lists of members are merged and the other HighVariable is deleted.

Parameters
tv2is the other HighVariable to merge into this
isspeculativeis true to keep the new members in separate merge classes

References compareJustLoc(), coverdirty, flagsdirty, Varnode::getMergeGroup(), highflags, inst, Cover::merge(), namerepdirty, numMergeClasses, Varnode::setHigh(), symbol, symboldirty, symboloffset, typedirty, and wholecover.

Referenced by Merge::buildDominantCopy(), hasCopyIn2(), and Merge::merge().

void HighVariable::printCover ( ostream &  s) const
inline

Print details of the cover for this (for debug purposes)

Parameters
sis the output stream

References coverdirty, getInputVarnode(), getNameRepresentative(), getTiedVarnode(), getTypeRepresentative(), hasName(), Cover::print(), and printInfo().

void HighVariable::printInfo ( ostream &  s) const

Print information about this HighVariable to stream.

This is generally used for debug purposes.

Parameters
sis the output stream

References Varnode::getMergeGroup(), Symbol::getName(), inst, Varnode::printInfo(), Datatype::printRaw(), symbol, symboloffset, type, and updateType().

Referenced by printCover().

void HighVariable::remove ( Varnode vn)
private

Remove a member Varnode from this.

Search for the given Varnode and cut it out of the list, marking all properties as dirty.

Parameters
vnis the given Varnode member to remove

References compareJustLoc(), coverdirty, flagsdirty, Varnode::getSymbolEntry(), highflags, inst, namerepdirty, symboldirty, and typedirty.

Referenced by Merge::buildDominantCopy(), and Varnode::~Varnode().

void HighVariable::saveXml ( ostream &  s) const

Save the variable to stream as an XML <high> tag.

Parameters
sis the output stream to write XML to

References a_v(), a_v_b(), a_v_i(), a_v_u(), Symbol::getCategory(), Varnode::getCreateIndex(), Symbol::getId(), getNameRepresentative(), isAddrTied(), isConstant(), isImplied(), isPersist(), isSpacebase(), isTypeLock(), symbol, and symboloffset.

Referenced by isNameLock(), and Funcdata::saveXmlHigh().

void HighVariable::setSymbol ( Varnode vn) const
private
void HighVariable::setSymbolReference ( Symbol sym,
int4  off 
)
private

Attach a reference to a Symbol to this.

Link information to this from a Symbol that is not attached to a member Varnode. This only works for a HighVariable with a constant member Varnode. This used when there is a constant address reference to the Symbol and the Varnode holds the reference, not the actual value of the Symbol.

Parameters
symis the given Symbol to attach
offis the byte offset into the Symbol of the reference

References highflags, symbol, symboldirty, and symboloffset.

Referenced by hasCopyIn2().

void HighVariable::updateCover ( void  ) const
private

(Re)derive the cover of this from the member Varnodes

Only update if the cover is marked as dirty. Merge the covers of all Varnode instances. This is only called by the Merge class which knows when to call it properly.

References Cover::clear(), coverdirty, hasCover(), highflags, inst, Cover::merge(), and wholecover.

Referenced by Merge::merge(), and Merge::updateHigh().

void HighVariable::updateFlags ( void  ) const
private

(Re)derive boolean properties of this from the member Varnodes

Only update if flags are marked as dirty. Generally if any member Varnode possesses the property, this HighVariable should inherit it. The Varnode::typelock field is not set here, but in updateType().

References Varnode::directwrite, flags, flagsdirty, highflags, inst, Varnode::mark, and Varnode::typelock.

Referenced by hasCover(), isAddrTied(), isConstant(), isExtraOut(), isImplied(), isInput(), isMapped(), isNameLock(), isPersist(), isSpacebase(), and isUnaffected().

void HighVariable::updateType ( void  ) const
private

(Re)derive the data-type for this from the member Varnodes

Only update if the data-type is marked as dirty. Get the most locked, most specific data-type from member Varnode objects.

References flags, Varnode::getType(), getTypeRepresentative(), highflags, Varnode::isTypeLock(), type, type_finalized, typedirty, and Varnode::typelock.

Referenced by getType(), isTypeLock(), and printInfo().


The documentation for this class was generated from the following files: