[llvm-commits] [hlvm] r38274 - in /hlvm/trunk: docs/FAQ.html hlvm/AST/AST.cpp hlvm/AST/Block.cpp hlvm/AST/Bundle.cpp hlvm/AST/ContainerType.cpp hlvm/AST/Operator.cpp hlvm/Pass/Validate.cpp hlvm/Reader/XMLReader.cpp
Reid Spencer
reid at x10sys.com
Sat Jul 7 17:01:52 PDT 2007
Author: reid
Date: Sat Jul 7 19:01:52 2007
New Revision: 38274
URL: http://llvm.org/viewvc/llvm-project?rev=38274&view=rev
Log:
Implement more validation of AST and provide better AST construction asserts.
Modified:
hlvm/trunk/docs/FAQ.html
hlvm/trunk/hlvm/AST/AST.cpp
hlvm/trunk/hlvm/AST/Block.cpp
hlvm/trunk/hlvm/AST/Bundle.cpp
hlvm/trunk/hlvm/AST/ContainerType.cpp
hlvm/trunk/hlvm/AST/Operator.cpp
hlvm/trunk/hlvm/Pass/Validate.cpp
hlvm/trunk/hlvm/Reader/XMLReader.cpp
Modified: hlvm/trunk/docs/FAQ.html
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/docs/FAQ.html?rev=38274&r1=38273&r2=38274&view=diff
==============================================================================
--- hlvm/trunk/docs/FAQ.html (original)
+++ hlvm/trunk/docs/FAQ.html Sat Jul 7 19:01:52 2007
@@ -40,6 +40,7 @@
<td>TBD</td>
<td>TBD</td>
<td>TBD</td>
+ </tr>
<tr><td>Optimization</td>
<td>Offers a wide range of optimization levels from "none" to "life long".
Most of this is provided by LLVM and works today. LLVM is "state of the
Modified: hlvm/trunk/hlvm/AST/AST.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/AST.cpp?rev=38274&r1=38273&r2=38274&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul 7 19:01:52 2007
@@ -124,6 +124,10 @@
ASTImpl::insertChild(Node* child)
{
hlvmAssert(llvm::isa<Bundle>(child) && "Can't insert that here");
+#ifdef HLVM_ASSERT
+ for (const_iterator I = begin(), E = end(); I != E; ++I)
+ hlvmAssert((*I) != child && "Attempt to duplicate insertion of child");
+#endif
bundles.push_back(llvm::cast<Bundle>(child));
}
@@ -131,6 +135,7 @@
ASTImpl::removeChild(Node* child)
{
hlvmAssert(llvm::isa<Bundle>(child) && "Can't remove that here");
+ //FIXME: bundles.erase(llvm::cast<Bundle>(child));
}
Type*
@@ -269,6 +274,7 @@
Bundle* result = new Bundle();
result->setLocator(loc);
result->setName(id);
+ result->setParent(this);
return result;
}
Modified: hlvm/trunk/hlvm/AST/Block.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Block.cpp?rev=38274&r1=38273&r2=38274&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Block.cpp (original)
+++ hlvm/trunk/hlvm/AST/Block.cpp Sat Jul 7 19:01:52 2007
@@ -42,11 +42,11 @@
Block::insertChild(Node* child)
{
hlvmAssert(llvm::isa<Operator>(child));
+ MultiOperator::insertChild(child);
if (llvm::isa<AutoVarOp>(child)) {
AutoVarOp* av = llvm::cast<AutoVarOp>(child);
autovars[av->getName()] = av;
}
- MultiOperator::insertChild(child);
type = getResultType(); // update type to match type of thing just added
}
Modified: hlvm/trunk/hlvm/AST/Bundle.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Bundle.cpp?rev=38274&r1=38273&r2=38274&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.cpp (original)
+++ hlvm/trunk/hlvm/AST/Bundle.cpp Sat Jul 7 19:01:52 2007
@@ -41,6 +41,7 @@
void
Bundle::insertChild(Node* kid)
{
+ hlvmAssert(kid && "Null child!");
if (kid->isType())
types.insert(cast<Type>(kid)->getName(), kid);
else if (kid->is(VariableID))
Modified: hlvm/trunk/hlvm/AST/ContainerType.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/ContainerType.cpp?rev=38274&r1=38273&r2=38274&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.cpp (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.cpp Sat Jul 7 19:01:52 2007
@@ -101,6 +101,10 @@
DisparateContainerType::insertChild(Node* n)
{
hlvmAssert(isa<AliasType>(n) && "Can't insert those here");
+#ifdef HLVM_ASSERT
+ for (const_iterator I = begin(), E = end(); I != E; ++I)
+ hlvmAssert((*I) != n);
+#endif
contents.push_back(cast<AliasType>(n));
}
Modified: hlvm/trunk/hlvm/AST/Operator.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Operator.cpp?rev=38274&r1=38273&r2=38274&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Operator.cpp (original)
+++ hlvm/trunk/hlvm/AST/Operator.cpp Sat Jul 7 19:01:52 2007
@@ -102,6 +102,7 @@
UnaryOperator::insertChild(Node* child)
{
hlvmAssert(isa<Operator>(child));
+ hlvmAssert(child != op1 && "Re-insertion of child");
if (!op1)
op1 = cast<Operator>(child);
else
@@ -146,6 +147,7 @@
BinaryOperator::insertChild(Node* child)
{
hlvmAssert(isa<Operator>(child));
+ hlvmAssert(child != ops[0] && child != ops[1] && "Re-insertion of child");
if (!ops[0])
ops[0] = cast<Operator>(child);
else if (!ops[1])
@@ -194,6 +196,8 @@
TernaryOperator::insertChild(Node* child)
{
hlvmAssert(isa<Operator>(child));
+ hlvmAssert(child != ops[0] && child != ops[1] && child != ops[2] &&
+ "Re-insertion of child");
if (!ops[0])
ops[0] = cast<Operator>(child);
else if (!ops[1])
@@ -257,6 +261,10 @@
MultiOperator::insertChild(Node* child)
{
hlvmAssert(isa<Operator>(child));
+#ifdef HLVM_ASSERT
+ for (const_iterator I = begin(), E = end(); I != E; ++I)
+ hlvmAssert((*I) != child && "Re-insertion of child");
+#endif
ops.push_back(cast<Operator>(child));
}
Modified: hlvm/trunk/hlvm/Pass/Validate.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Pass/Validate.cpp?rev=38274&r1=38273&r2=38274&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Pass/Validate.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Validate.cpp Sat Jul 7 19:01:52 2007
@@ -156,7 +156,12 @@
bool
ValidateImpl::checkConstant(Constant* C,NodeIDs id)
{
- return checkValue(C,id);
+ if (checkValue(C,id)) {
+ if (C->getName().empty())
+ error(C,"Constants must not have empty name");
+ return false;
+ }
+ return true;
}
bool
@@ -283,6 +288,12 @@
}
template<> inline void
+ValidateImpl::validate(OpaqueType* n)
+{
+ checkType(n,OpaqueTypeID);
+}
+
+template<> inline void
ValidateImpl::validate(RangeType* n)
{
if (checkType(n,RangeTypeID))
@@ -313,9 +324,9 @@
}
template<> inline void
-ValidateImpl::validate(OpaqueType* n)
+ValidateImpl::validate(StringType* n)
{
- checkType(n,OpaqueTypeID);
+ checkType(n,StringTypeID);
}
template<> inline void
@@ -379,9 +390,55 @@
}
template<> inline void
+ValidateImpl::validate(ConstantBoolean* n)
+{
+ checkConstant(n,ConstantBooleanID);
+}
+
+template<> inline void
+ValidateImpl::validate(ConstantInteger* n)
+{
+ checkConstant(n,ConstantIntegerID);
+ // FIXME: validate that the constant value is in the right numeric base
+ // FIXME: validate that the constant value is in range for the type
+}
+
+template<> inline void
+ValidateImpl::validate(ConstantReal* n)
+{
+ checkConstant(n,ConstantRealID);
+ // FIXME: validate that the constant value is in range for the type
+}
+
+template<> inline void
+ValidateImpl::validate(ConstantString* n)
+{
+ if (checkConstant(n,ConstantStringID))
+ if (std::string::npos != n->getValue().find('\0'))
+ error(n,"String constants may not contain a null byte");
+}
+
+template<> inline void
+ValidateImpl::validate(ConstantAggregate* n)
+{
+ checkConstant(n,ConstantAggregateID);
+ // FIXME: validate fields vs. type
+}
+
+template<> inline void
+ValidateImpl::validate(ConstantExpression* n)
+{
+ checkConstant(n,ConstantExpressionID);
+ // FIXME: validate opcodes and operands
+}
+
+template<> inline void
ValidateImpl::validate(Variable* n)
{
- checkLinkageItem(n, VariableID);
+ if (checkLinkageItem(n, VariableID))
+ if (n->hasInitializer())
+ if (n->getType() != n->getInitializer()->getType())
+ error(n,"Variable and its initializer do not agree in type");
}
template<> inline void
@@ -537,8 +594,18 @@
const Type* Ty2 = n->getOperand(1)->getType();
if (!isa<PointerType>(Ty1))
error(n,"StoreOp expects first operand to be pointer type");
- else if (cast<PointerType>(Ty1)->getElementType() != Ty2)
+ else if (cast<PointerType>(Ty1)->getElementType() != Ty2) {
error(n,"StoreOp operands do not agree in type");
+ } else if (const ReferenceOp* ref =
+ dyn_cast<ReferenceOp>(n->getOperand(0))) {
+ const Value* R = ref->getReferent();
+ if (isa<Variable>(R) && cast<Variable>(R)->isConstant())
+ error(n,"Can't store to constant variable");
+ else if (isa<AutoVarOp>(R) && cast<AutoVarOp>(R)->isConstant())
+ error(n,"Can't store to constant automatic variable");
+ } else if (const IndexOp* ref = dyn_cast<IndexOp>(n)) {
+ /// FIXME: Implement this
+ }
}
}
@@ -555,6 +622,20 @@
}
template<> inline void
+ValidateImpl::validate(ReferenceOp* op)
+{
+ checkOperator(op,ReferenceOpID,0,true);
+ /// FIXME: check referent out
+}
+
+template<> inline void
+ValidateImpl::validate(ConstantReferenceOp* op)
+{
+ checkOperator(op,ConstantReferenceOpID,0,true);
+ /// FIXME: check referent out
+}
+
+template<> inline void
ValidateImpl::validate(NegateOp* n)
{
if (checkOperator(n,NegateOpID,1)) {
@@ -836,123 +917,177 @@
template<> inline void
ValidateImpl::validate(IsPInfOp* n)
{
- if (checkOperator(n,IsPInfOpID,1))
- ;
+ if (checkOperator(n,IsPInfOpID,1)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ if (!Ty1->isRealType())
+ error(n,"IsPInfoOp requires real number operand");
+ }
}
template<> inline void
ValidateImpl::validate(IsNInfOp* n)
{
- if (checkOperator(n,IsNInfOpID,1))
- ;
+ if (checkOperator(n,IsNInfOpID,1)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ if (!Ty1->isRealType())
+ error(n,"IsPInfoOp requires real number operand");
+ }
}
template<> inline void
ValidateImpl::validate(IsNanOp* n)
{
- if (checkOperator(n,IsNanOpID,1))
- ;
+ if (checkOperator(n,IsNanOpID,1)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ if (!Ty1->isRealType())
+ error(n,"IsNanOp requires real number operand");
+ }
}
template<> inline void
ValidateImpl::validate(TruncOp* n)
{
- if (checkOperator(n,TruncOpID,1))
- ;
+ if (checkOperator(n,TruncOpID,1)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ if (!Ty1->isRealType())
+ error(n,"TruncOp requires real number operand");
+ }
}
template<> inline void
ValidateImpl::validate(RoundOp* n)
{
- if (checkOperator(n,RoundOpID,1))
- ;
+ if (checkOperator(n,RoundOpID,1)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ if (!Ty1->isRealType())
+ error(n,"RoundOp requires real number operand");
+ }
}
template<> inline void
ValidateImpl::validate(FloorOp* n)
{
- if (checkOperator(n,FloorOpID,1))
- ;
+ if (checkOperator(n,FloorOpID,1)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ if (!Ty1->isRealType())
+ error(n,"FloorOp requires real number operand");
+ }
}
template<> inline void
ValidateImpl::validate(CeilingOp* n)
{
- if (checkOperator(n,CeilingOpID,1))
- ;
+ if (checkOperator(n,CeilingOpID,1)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ if (!Ty1->isRealType())
+ error(n,"CeilingOp requires real number operand");
+ }
}
template<> inline void
ValidateImpl::validate(LogEOp* n)
{
- if (checkOperator(n,LogEOpID,1))
- ;
+ if (checkOperator(n,LogEOpID,1)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ if (!Ty1->isRealType())
+ error(n,"LogEOpID requires real number operand");
+ }
}
template<> inline void
ValidateImpl::validate(Log2Op* n)
{
- if (checkOperator(n,Log2OpID,1))
- ;
+ if (checkOperator(n,Log2OpID,1)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ if (!Ty1->isRealType())
+ error(n,"Log2OpID requires real number operand");
+ }
}
template<> inline void
ValidateImpl::validate(Log10Op* n)
{
- if (checkOperator(n,Log10OpID,1))
- ;
+ if (checkOperator(n,Log10OpID,1)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ if (!Ty1->isRealType())
+ error(n,"Log10OpID requires real number operand");
+ }
}
template<> inline void
ValidateImpl::validate(SquareRootOp* n)
{
- if (checkOperator(n,SquareRootOpID,1))
- ;
+ if (checkOperator(n,SquareRootOpID,1)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ if (!Ty1->isRealType())
+ error(n,"SquareRootOp requires real number operand");
+ }
}
template<> inline void
ValidateImpl::validate(CubeRootOp* n)
{
- if (checkOperator(n,CubeRootOpID,1))
- ;
+ if (checkOperator(n,CubeRootOpID,1)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ if (!Ty1->isRealType())
+ error(n,"CubeRootOpID requires real number operand");
+ }
}
template<> inline void
ValidateImpl::validate(FactorialOp* n)
{
- if (checkOperator(n,FactorialOpID,1))
- ;
+ if (checkOperator(n,FactorialOpID,1)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ if (!Ty1->isRealType())
+ error(n,"FactorialOp requires real number operand");
+ }
}
template<> inline void
ValidateImpl::validate(PowerOp* n)
{
- if (checkOperator(n,PowerOpID,2))
- ;
+ if (checkOperator(n,PowerOpID,2)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ const Type* Ty2 = n->getOperand(1)->getType();
+ if (!Ty1->isRealType() || !Ty2->isRealType())
+ error(n,"LogEOpID requires two real number operands");
+ }
}
template<> inline void
ValidateImpl::validate(RootOp* n)
{
- if (checkOperator(n,RootOpID,2))
- ;
+ if (checkOperator(n,RootOpID,2)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ const Type* Ty2 = n->getOperand(1)->getType();
+ if (!Ty1->isRealType() || !Ty2->isRealType())
+ error(n,"RootOp requires two real number operands");
+ }
}
template<> inline void
ValidateImpl::validate(GCDOp* n)
{
- if (checkOperator(n,GCDOpID,2))
- ;
+ if (checkOperator(n,GCDOpID,2)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ const Type* Ty2 = n->getOperand(1)->getType();
+ if (!Ty1->isRealType() || !Ty2->isRealType())
+ error(n,"GCDOp requires two real number operands");
+ }
}
template<> inline void
ValidateImpl::validate(LCMOp* n)
{
- if (checkOperator(n,LCMOpID,2))
- ;
+ if (checkOperator(n,LCMOpID,2)) {
+ const Type* Ty1 = n->getOperand(0)->getType();
+ const Type* Ty2 = n->getOperand(1)->getType();
+ if (!Ty1->isRealType() || !Ty2->isRealType())
+ error(n,"LCMOp requires two real number operands");
+ }
}
-
template<> inline void
ValidateImpl::validate(OpenOp* n)
{
@@ -1007,43 +1142,15 @@
}
template<> inline void
-ValidateImpl::validate(ConstantBoolean* n)
-{
-}
-
-template<> inline void
-ValidateImpl::validate(ConstantInteger* n)
-{
-}
-
-template<> inline void
-ValidateImpl::validate(ConstantReal* n)
-{
-}
-
-template<> inline void
-ValidateImpl::validate(ConstantString* n)
-{
-}
-
-template<> inline void
-ValidateImpl::validate(ConstantAggregate* n)
-{
-}
-
-template<> inline void
-ValidateImpl::validate(ConstantExpression* n)
-{
-}
-
-template<> inline void
ValidateImpl::validate(Bundle* n)
{
+ // FIXME: checkNode(n);
}
template<> inline void
ValidateImpl::validate(Import* n)
{
+ // FIXME: checkNode(n);
}
void
@@ -1103,8 +1210,8 @@
case AllocateOpID: validate(cast<AllocateOp>(n)); break;
case DeallocateOpID: validate(cast<DeallocateOp>(n)); break;
case ReallocateOpID: /*validate(cast<ReallocateOp>(n));*/ break;
- case ReferenceOpID: /*validate(cast<ReferenceOp>(n));*/ break;
- case ConstantReferenceOpID: /*validate(cast<ConstantReferenceOp>(n));*/
+ case ReferenceOpID: validate(cast<ReferenceOp>(n)); break;
+ case ConstantReferenceOpID: validate(cast<ConstantReferenceOp>(n));
break;
case AutoVarOpID: validate(cast<AutoVarOp>(n)); break;
case NegateOpID: validate(cast<NegateOp>(n)); break;
@@ -1156,9 +1263,9 @@
case ReadOpID: validate(cast<ReadOp>(n)); break;
case WriteOpID: validate(cast<WriteOp>(n)); break;
case PositionOpID: /*validate(cast<PositionOp>(n));*/ break;
- case PInfOpID: /*validate(cast<PInfOp>(n));*/ break;
- case NInfOpID: /*validate(cast<NInfoOp>(n));*/ break;
- case NaNOpID: /*validate(cast<NaNOp>(n));*/ break;
+ case PInfOpID: /*validate(cast<PInfOp>(n)); */ break;
+ case NInfOpID: /*validate(cast<NInfoOp>(n)); */ break;
+ case NaNOpID: /*validate(cast<NaNOp>(n)); */ break;
case ConstantBooleanID: validate(cast<ConstantBoolean>(n)); break;
case ConstantIntegerID: validate(cast<ConstantInteger>(n)); break;
case ConstantRealID: validate(cast<ConstantReal>(n)); break;
Modified: hlvm/trunk/hlvm/Reader/XMLReader.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XMLReader.cpp?rev=38274&r1=38273&r2=38274&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Reader/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XMLReader.cpp Sat Jul 7 19:01:52 2007
@@ -1110,7 +1110,6 @@
cur = cur->children;
if (skipBlanks(cur)) {
Bundle* b = parse<Bundle>(cur);
- ast->addBundle(b);
}
}
More information about the llvm-commits
mailing list