Skip to content

Commit

Permalink
Evaluate(): Take ArrayRef instead of pointer+size.
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Sep 1, 2012
1 parent b9f8ca4 commit 502925a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
20 changes: 8 additions & 12 deletions include/yasmx/Location_util.h
Expand Up @@ -29,6 +29,7 @@
/// POSSIBILITY OF SUCH DAMAGE.
/// @endlicense
///
#include "yasmx/Basic/LLVM.h"
#include "yasmx/Config/export.h"
#include "yasmx/Config/functional.h"

Expand Down Expand Up @@ -80,28 +81,23 @@ int SubstDist(Expr& e, DiagnosticsEngine& diags,
/// Substitutions must be integer or float terms.
/// If null, any substitution in the expr will result in
/// evaluation failure and a false return
/// @param nsubst size of substitution terms array
/// @param valueloc replace symbols and locations with their values
/// @param zeroreg replace registers with zero?
/// @return True if successful.
YASM_LIB_EXPORT
bool Evaluate(const Expr& e,
DiagnosticsEngine& diags,
ExprTerm* result,
const ExprTerm* subst,
unsigned int nsubst,
ArrayRef<ExprTerm> subst,
bool valueloc=true,
bool zeroreg=false);

inline bool
Evaluate(const Expr& e,
DiagnosticsEngine& diags,
ExprTerm* result,
bool valueloc=true,
bool zeroreg=false)
{
return Evaluate(e, diags, result, 0, 0, valueloc, zeroreg);
}
YASM_LIB_EXPORT
bool Evaluate(const Expr& e,
DiagnosticsEngine& diags,
ExprTerm* result,
bool valueloc=true,
bool zeroreg=false);

} // namespace yasm

Expand Down
16 changes: 13 additions & 3 deletions lib/yasmx/Location_util.cpp
Expand Up @@ -27,6 +27,7 @@
#include "yasmx/Location_util.h"

#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "yasmx/Bytecode.h"
#include "yasmx/Expr.h"
Expand Down Expand Up @@ -261,8 +262,7 @@ bool
yasm::Evaluate(const Expr& e,
DiagnosticsEngine& diags,
ExprTerm* result,
const ExprTerm* subst,
unsigned int nsubst,
ArrayRef<ExprTerm> subst,
bool valueloc,
bool zeroreg)
{
Expand Down Expand Up @@ -362,7 +362,7 @@ yasm::Evaluate(const Expr& e,
case ExprTerm::SUBST:
{
unsigned int substindex = *term.getSubst();
if (!subst || substindex >= nsubst)
if (substindex >= subst.size())
return false;
assert((subst[substindex].getType() == ExprTerm::INT ||
subst[substindex].getType() == ExprTerm::FLOAT) &&
Expand Down Expand Up @@ -403,3 +403,13 @@ yasm::Evaluate(const Expr& e,
result->swap(stack.back());
return true;
}

bool
yasm::Evaluate(const Expr& e,
DiagnosticsEngine& diags,
ExprTerm* result,
bool valueloc,
bool zeroreg)
{
return Evaluate(e, diags, result, ArrayRef<ExprTerm>(), valueloc, zeroreg);
}
5 changes: 3 additions & 2 deletions lib/yasmx/Optimizer.cpp
Expand Up @@ -34,6 +34,7 @@
#include <memory>
#include <vector>

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Statistic.h"
Expand Down Expand Up @@ -445,8 +446,8 @@ Span::RecalcNormal(DiagnosticsEngine& diags)
for (Terms::iterator i=m_span_terms.begin(), end=m_span_terms.end();
i != end; ++i)
*m_expr_terms[i->m_subst].getIntNum() = i->m_new_val;
if (!Evaluate(*m_depval.getAbs(), diags, &result, &m_expr_terms[0],
m_expr_terms.size(), false, false)
if (!Evaluate(*m_depval.getAbs(), diags, &result, m_expr_terms, false,
false)
|| !result.isType(ExprTerm::INT))
m_new_val = LONG_MAX; // too complex; force to longest form
else
Expand Down

0 comments on commit 502925a

Please sign in to comment.