[llvm-commits] [hlvm] r38344 - in /hlvm/trunk: hlvm/AST/AST.cpp hlvm/AST/Type.h hlvm/Pass/Validate.cpp tools/hlvm-gentestcase/Generate.cpp
Reid Spencer
reid at x10sys.com
Sat Jul 7 17:02:31 PDT 2007
Author: reid
Date: Sat Jul 7 19:02:31 2007
New Revision: 38344
URL: http://llvm.org/viewvc/llvm-project?rev=38344&view=rev
Log:
Fix the test case generator to produce better code.
Fix validation errors identified by test case generator.
Modified:
hlvm/trunk/hlvm/AST/AST.cpp
hlvm/trunk/hlvm/AST/Type.h
hlvm/trunk/hlvm/Pass/Validate.cpp
hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp
Modified: hlvm/trunk/hlvm/AST/AST.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/AST.cpp?rev=38344&r1=38343&r2=38344&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul 7 19:02:31 2007
@@ -700,7 +700,6 @@
E = vals.end(); I != E; ++I )
{
hlvmAssert(STI != ST->end());
- hlvmAssert((*I)->getType() == (*STI)->getType());
result->addConstant(*I);
++STI;
}
Modified: hlvm/trunk/hlvm/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Type.h?rev=38344&r1=38343&r2=38344&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Type.h (original)
+++ hlvm/trunk/hlvm/AST/Type.h Sat Jul 7 19:02:31 2007
@@ -274,7 +274,7 @@
/// @brief Methods to support type inquiry via isa, cast, dyn_cast
static inline bool classof(const IntegerType*) { return true; }
- static inline bool classof(const Node* T) { return T->isIntegralType(); }
+ static inline bool classof(const Node* T) { return T->isIntegerType(); }
/// @}
/// @name Mutators
Modified: hlvm/trunk/hlvm/Pass/Validate.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Pass/Validate.cpp?rev=38344&r1=38343&r2=38344&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Pass/Validate.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Validate.cpp Sat Jul 7 19:02:31 2007
@@ -486,27 +486,35 @@
ValidateImpl::validate(ConstantInteger* CI)
{
if (checkConstant(CI,ConstantIntegerID)) {
- const IntegerType* Ty = cast<IntegerType>(CI->getType());
- // Check that it can be converted to binary
const char* startp = CI->getValue().c_str();
char* endp = 0;
int64_t val = strtoll(startp,&endp,CI->getBase());
+ // Check that it can be converted to binary
if (!endp || startp == endp || *endp != '\0')
error(CI,"Invalid integer constant. Conversion failed.");
- else if (val < 0 && !Ty->isSigned()) {
- error(CI,"Invalid integer constant. "
- "Signed value not accepted by unsigned type");
+ else if (llvm::itostr(val) != CI->getValue())
+ error(CI,"Invalid integer constant, not losslessly convertible");
+ else if (const IntegerType* Ty = dyn_cast<IntegerType>(CI->getType())) {
+ if (val < 0 && !Ty->isSigned()) {
+ error(CI,"Invalid integer constant. "
+ "Signed value not accepted by unsigned type");
+ } else {
+ // It converted to binary okay, check that it is in range
+ uint64_t uval = (val < 0) ? -val : val;
+ unsigned leading_zeros = llvm::CountLeadingZeros_64(uval);
+ unsigned bits_required = (sizeof(uint64_t)*8 - leading_zeros) +
+ unsigned(Ty->isSigned());
+ unsigned bits_allowed = Ty->getBits();
+ if (bits_required > bits_allowed)
+ error(CI, "Invalid integer constant. Value requires " +
+ utostr(bits_required) + " bits, but type only holds " +
+ utostr(bits_allowed) + " bits.");
+ }
+ } else if (const RangeType* Ty = dyn_cast<RangeType>(CI->getType())) {
+ if (val < Ty->getMin() || val > Ty->getMax())
+ error(CI, "Integer constant out of range of RangeType");
} else {
- // It converted to binary okay, check that it is in range
- uint64_t uval = (val < 0) ? -val : val;
- unsigned leading_zeros = llvm::CountLeadingZeros_64(uval);
- unsigned bits_required = (sizeof(uint64_t)*8 - leading_zeros) +
- unsigned(Ty->isSigned());
- unsigned bits_allowed = Ty->getBits();
- if (bits_required > bits_allowed)
- error(CI, "Invalid integer constant. Value requires " +
- utostr(bits_required) + " bits, but type only holds " +
- utostr(bits_allowed) + " bits.");
+ error(CI,"Unknown integer constant type");
}
}
}
@@ -539,26 +547,23 @@
error(CR,"Invalid floating point type");
return;
}
- bool isValid = false;
if (numBits <= sizeof(float)*8) {
float x = val;
long double x2 = x;
- isValid = (val <= FLT_MAX && val >= FLT_MIN && val == x2);
+ if (val != x2)
+ error(CR,"Real constant out of range for real requiring " +
+ utostr(numBits) + " bits");
}
else if (numBits <= sizeof(double)*8)
{
double x = val;
long double x2 = x;
- isValid = (val <= DBL_MAX && val >= DBL_MIN && val == x2);
+ if (val != x2)
+ error(CR,"Real constant out of range for real requiring " +
+ utostr(numBits) + " bits");
}
else if (numBits > sizeof(long double)*8)
- {
warning(CR,"Don't know how to check range of real type > 128 bits");
- isValid = true;
- }
- if (!isValid)
- error(CR,"Real constant out of range for real requiring " +
- utostr(numBits) + " bits");
}
}
}
Modified: hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp?rev=38344&r1=38343&r2=38344&view=diff
==============================================================================
--- hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp (original)
+++ hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp Sat Jul 7 19:02:31 2007
@@ -78,13 +78,23 @@
inline
int64_t randRange(int64_t low, int64_t high)
{
- return int64_t(random()) % (high-low) + low;
+ if (high > low)
+ return int64_t(random()) % (high-low) + low;
+ else if (low > high)
+ return int64_t(random()) % (low-high) + high;
+ else
+ return 1;
}
inline
uint64_t randRange(uint64_t low, uint64_t high, bool discriminate)
{
- return uint64_t(random()) % (high-low) + low;
+ if (high > low)
+ return uint64_t(random()) % (high-low) + low;
+ else if (low > high)
+ return uint64_t(random()) % (low-high) + high;
+ else
+ return 1;
}
hlvm::Type*
@@ -112,8 +122,9 @@
case Float44TypeID:
case Float64TypeID:
case Float80TypeID:
- case Float128TypeID:
return ast->getPrimitiveType(id);
+ case Float128TypeID:
+ return ast->getPrimitiveType(Float64TypeID);
case AnyTypeID:
case StringTypeID:
@@ -160,9 +171,7 @@
}
case PointerTypeID:
{
- Locator* loc = getLocator();
- std::string name = "ptr_" + utostr(line);
- result = ast->new_PointerType(name,genTypeLimited(limit),loc);
+ result = ast->getPointerTo(genTypeLimited(limit));
break;
}
case ArrayTypeID:
@@ -284,7 +293,7 @@
case SInt8TypeID:
{
int8_t val = int8_t(randRange(-128,127));
- std::string val_str(utostr(val));
+ std::string val_str(itostr(val));
C = ast->new_ConstantInteger(
std::string("cs8_")+utostr(line),val_str,10,Ty,loc);
break;
@@ -292,7 +301,7 @@
case SInt16TypeID:
{
int16_t val = int16_t(randRange(-32768,32767));
- std::string val_str(utostr(val));
+ std::string val_str(itostr(val));
C = ast->new_ConstantInteger(
std::string("cs16_")+utostr(line),val_str,10,Ty,loc);
break;
@@ -300,7 +309,7 @@
case SInt32TypeID:
{
int32_t val = int32_t(randRange(-2000000000,2000000000));
- std::string val_str(utostr(val));
+ std::string val_str(itostr(val));
C = ast->new_ConstantInteger(
std::string("cs32_")+utostr(line),val_str,10,Ty,loc);
break;
@@ -310,7 +319,7 @@
case SInt64TypeID:
{
int64_t val = int64_t(randRange(-2000000000,2000000000));
- std::string val_str(utostr(val));
+ std::string val_str(itostr(val));
C = ast->new_ConstantInteger(
std::string("cs64_")+utostr(line),val_str,10,Ty,loc);
break;
@@ -321,7 +330,7 @@
case Float80TypeID:
case Float128TypeID:
{
- double val = double(randRange(-2000000000,2000000000));
+ double val = double(randRange(-10000000,10000000));
std::string val_str(ftostr(val));
C = ast->new_ConstantReal(
std::string("cf32_")+utostr(line),val_str,Ty,loc);
@@ -386,7 +395,7 @@
}
case RealTypeID:
{
- double val = double(randRange(-2000000000,2000000000));
+ double val = double(randRange(-10000000,10000000));
std::string val_str(ftostr(val));
C = ast->new_ConstantReal(
std::string("cf32_")+utostr(line),val_str,Ty,loc);
@@ -562,5 +571,15 @@
call->setParent(blk);
}
+ // Get the function result and return instruction
+ Value* V = genValue(program->getResultType());
+ Operator* O = ast->new_ReferenceOp(V,getLocator());
+ if (isa<Linkable>(V))
+ O = ast->new_UnaryOp<LoadOp>(O,getLocator());
+ ResultOp* rslt = ast->new_UnaryOp<ResultOp>(O,getLocator());
+ rslt->setParent(blk);
+
+ ReturnOp* ret = ast->new_NilaryOp<ReturnOp>(getLocator());
+ ret->setParent(blk);
return ast;
}
More information about the llvm-commits
mailing list