[llvm-commits] [hlvm] r38249 - in /hlvm/trunk: hlvm/AST/AST.cpp hlvm/AST/AST.h hlvm/AST/Block.cpp hlvm/AST/Bundle.cpp hlvm/AST/LinkageItems.cpp hlvm/AST/LinkageItems.h hlvm/AST/Node.cpp hlvm/AST/Node.h hlvm/AST/Operator.cpp hlvm/AST/Operator.h hlvm/AST/Type.cpp hlvm/AST/Type.h hlvm/Pass/Pass.cpp hlvm/Pass/Pass.h hlvm/Pass/Validate.cpp hlvm/Reader/XMLReader.cpp test/return0/complement.hlx
Reid Spencer
reid at x10sys.com
Sat Jul 7 17:01:37 PDT 2007
Author: reid
Date: Sat Jul 7 19:01:37 2007
New Revision: 38249
URL: http://llvm.org/viewvc/llvm-project?rev=38249&view=rev
Log:
Implement some more validation and ensure the test suite will pass
the validation checks implemented so far.
Added:
hlvm/trunk/test/return0/complement.hlx
Modified:
hlvm/trunk/hlvm/AST/AST.cpp
hlvm/trunk/hlvm/AST/AST.h
hlvm/trunk/hlvm/AST/Block.cpp
hlvm/trunk/hlvm/AST/Bundle.cpp
hlvm/trunk/hlvm/AST/LinkageItems.cpp
hlvm/trunk/hlvm/AST/LinkageItems.h
hlvm/trunk/hlvm/AST/Node.cpp
hlvm/trunk/hlvm/AST/Node.h
hlvm/trunk/hlvm/AST/Operator.cpp
hlvm/trunk/hlvm/AST/Operator.h
hlvm/trunk/hlvm/AST/Type.cpp
hlvm/trunk/hlvm/AST/Type.h
hlvm/trunk/hlvm/Pass/Pass.cpp
hlvm/trunk/hlvm/Pass/Pass.h
hlvm/trunk/hlvm/Pass/Validate.cpp
hlvm/trunk/hlvm/Reader/XMLReader.cpp
Modified: hlvm/trunk/hlvm/AST/AST.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/AST.cpp?rev=38249&r1=38248&r2=38249&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul 7 19:01:37 2007
@@ -596,11 +596,10 @@
return result;
}
-Block*
-AST::new_Block(const std::string& label, const Locator* loc)
+Block*
+AST::new_Block( const Locator* loc)
{
Block* result = new Block();
- result->setLabel(label);
result->setLocator(loc);
return result;
}
@@ -926,6 +925,12 @@
AST::new_BinaryOp<InequalityOp>(Value* op1,Value* op2,const Locator* loc);
// Control Flow Operators
+template Block*
+AST::new_MultiOp<Block>(
+ const Type* Ty, const std::vector<Value*>& ops, const Locator*loc);
+template Block*
+AST::new_MultiOp<Block>(const std::vector<Value*>& ops, const Locator*loc);
+
template NoOperator*
AST::new_NilaryOp<NoOperator>(const Type* Ty, const Locator*loc);
template NoOperator*
Modified: hlvm/trunk/hlvm/AST/AST.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/AST.h?rev=38249&r1=38248&r2=38249&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/AST.h (original)
+++ hlvm/trunk/hlvm/AST/AST.h Sat Jul 7 19:01:37 2007
@@ -189,11 +189,6 @@
const std::string& id, ///< The name of the program
const Locator* loc = 0 ///< The source locator
);
- /// Create a new Block node. A block is a sequence of operators.
- Block* new_Block(
- const std::string& id, ///< The name (label) of the block
- const Locator* loc = 0 ///< The source locator
- );
/// Create a new IntegerType node. This is a general interface for creating
/// integer types. By default it creates a signed 32-bit integer.
IntegerType* new_IntegerType(
@@ -459,6 +454,12 @@
const Locator* loc = 0 ///< The source locator
);
+ /// Create a new Block. You can also create Blocks with new_MulitOp<Block>
+ /// interface. This one allows you to create the block before creating its
+ /// content, for situations where that matters (like XML parsing).
+ Block* new_Block(
+ const Locator* loc ///< The source locator
+ );
/// Create a new AutoVarOp. This one is a little unusual because it
/// requires the user to know the type. Other operators can deduce the
/// type from the operands.
Modified: hlvm/trunk/hlvm/AST/Block.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Block.cpp?rev=38249&r1=38248&r2=38249&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Block.cpp (original)
+++ hlvm/trunk/hlvm/AST/Block.cpp Sat Jul 7 19:01:37 2007
@@ -47,6 +47,7 @@
autovars[av->getName()] = av;
}
MultiOperator::insertChild(child);
+ type = getResultType(); // update type to match type of thing just added
}
void
Modified: hlvm/trunk/hlvm/AST/Bundle.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Bundle.cpp?rev=38249&r1=38248&r2=38249&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.cpp (original)
+++ hlvm/trunk/hlvm/AST/Bundle.cpp Sat Jul 7 19:01:37 2007
@@ -80,19 +80,25 @@
Type*
Bundle::type_find(const std::string& name) const
{
- return llvm::cast<Type>(types.lookup(name));
+ if (Node* result = types.lookup(name))
+ return llvm::cast<Type>(result);
+ return 0;
}
Function*
Bundle::func_find(const std::string& name) const
{
- return llvm::cast<Function>(funcs.lookup(name));
+ if (Node* result = funcs.lookup(name))
+ return llvm::cast<Function>(result);
+ return 0;
}
Variable*
Bundle::var_find(const std::string& name) const
{
- return llvm::cast<Variable>(vars.lookup(name));
+ if (Node* result = vars.lookup(name))
+ return llvm::cast<Variable>(result);
+ return 0;
}
Import::~Import()
Modified: hlvm/trunk/hlvm/AST/LinkageItems.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/LinkageItems.cpp?rev=38249&r1=38248&r2=38249&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/LinkageItems.cpp (original)
+++ hlvm/trunk/hlvm/AST/LinkageItems.cpp Sat Jul 7 19:01:37 2007
@@ -44,14 +44,16 @@
{
}
+const SignatureType*
+Function::getSignature() const
+{
+ return cast<SignatureType>(type);
+}
+
void
Function::insertChild(Node* kid)
{
- if (isa<SignatureType>(kid)) {
- if (signature)
- signature->setParent(0);
- signature = cast<SignatureType>(kid);
- } else if (isa<Block>(kid)) {
+ if (isa<Block>(kid)) {
if (block)
block->setParent(0);
block = cast<Block>(kid);
@@ -63,10 +65,10 @@
void
Function::removeChild(Node* kid)
{
- if (isa<SignatureType>(kid)) {
- } else if (isa<Block>(kid)) {
+ if (isa<Block>(kid) && kid == block) {
+ block = 0;
} else {
- hlvmAssert(!"Can't insert one of those here");
+ hlvmAssert(!"Can't remove one of those here");
}
}
Modified: hlvm/trunk/hlvm/AST/LinkageItems.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/LinkageItems.h?rev=38249&r1=38248&r2=38249&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/LinkageItems.h (original)
+++ hlvm/trunk/hlvm/AST/LinkageItems.h Sat Jul 7 19:01:37 2007
@@ -106,7 +106,7 @@
public:
Function(
NodeIDs id = FunctionID
- ) : LinkageItem(id), block(0), signature(0) {}
+ ) : LinkageItem(id), block(0) {}
virtual ~Function();
/// @}
@@ -114,7 +114,7 @@
/// @{
public:
Block* getBlock() const { return block; }
- SignatureType* getSignature() { return signature; }
+ const SignatureType* getSignature() const;
static inline bool classof(const Function*) { return true; }
static inline bool classof(const Node* N) { return N->isFunction(); }
@@ -124,7 +124,7 @@
public:
virtual void insertChild(Node* kid);
virtual void removeChild(Node* kid);
- void setSignature(SignatureType* sig) { signature = sig; }
+ void setSignature(SignatureType* sig) { type = sig; }
void setBlock(Block* blk) { blk->setParent(this); }
/// @}
@@ -132,7 +132,6 @@
/// @{
protected:
Block * block; ///< The code block to be executed
- SignatureType* signature; ///< The function signature.
/// @}
friend class AST;
};
Modified: hlvm/trunk/hlvm/AST/Node.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Node.cpp?rev=38249&r1=38248&r2=38249&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Node.cpp (original)
+++ hlvm/trunk/hlvm/AST/Node.cpp Sat Jul 7 19:01:37 2007
@@ -65,14 +65,14 @@
void
Node::setParent(Node* p)
{
- if (p == 0)
+ if (parent != 0)
{
parent->removeChild(this);
}
parent = p;
- if (p != 0)
+ if (parent != 0)
{
- p->insertChild(this);
+ parent->insertChild(this);
}
}
Modified: hlvm/trunk/hlvm/AST/Node.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Node.h?rev=38249&r1=38248&r2=38249&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Node.h (original)
+++ hlvm/trunk/hlvm/AST/Node.h Sat Jul 7 19:01:37 2007
@@ -317,10 +317,12 @@
return id >= FirstTypeID &&
id <= LastTypeID; }
+ inline bool isIntegerType() const {
+ return (id >= UInt8TypeID && id <= SInt128TypeID) || id == IntegerTypeID;}
+
inline bool isIntegralType() const {
- return (id >= UInt8TypeID && id <= UInt128TypeID) ||
- (id == IntegerTypeID) || (id == RangeTypeID) ||
- (id == EnumerationTypeID); }
+ return isIntegerType() || (id == RangeTypeID) ||
+ (id == EnumerationTypeID) || (id == BooleanTypeID); }
inline bool isRealType() const {
return (id >= Float32TypeID && id <= Float128TypeID) ||
Modified: hlvm/trunk/hlvm/AST/Operator.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Operator.cpp?rev=38249&r1=38248&r2=38249&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Operator.cpp (original)
+++ hlvm/trunk/hlvm/AST/Operator.cpp Sat Jul 7 19:01:37 2007
@@ -248,6 +248,16 @@
}
void
+MultiOperator::addOperands(const OprndList& oprnds)
+{
+ for (const_iterator I = oprnds.begin(), E = oprnds.end(); I != E; ++I )
+ {
+ hlvmAssert(isa<Value>(*I));
+ (*I)->setParent(this);
+ }
+}
+
+void
MultiOperator::insertChild(Node* child)
{
hlvmAssert(isa<Value>(child));
Modified: hlvm/trunk/hlvm/AST/Operator.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Operator.h?rev=38249&r1=38248&r2=38249&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Operator.h (original)
+++ hlvm/trunk/hlvm/AST/Operator.h Sat Jul 7 19:01:37 2007
@@ -284,9 +284,7 @@
public:
virtual void setOperand(unsigned opnum, Value* oprnd);
void addOperand(Value* v) { v->setParent(this); }
- void addOperands(const OprndList& new_ops) {
- ops.insert(ops.end(),new_ops.begin(),new_ops.end());
- }
+ void addOperands(const OprndList& new_ops);
protected:
virtual void insertChild(Node* child);
virtual void removeChild(Node* child);
Modified: hlvm/trunk/hlvm/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Type.cpp?rev=38249&r1=38248&r2=38249&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Type.cpp (original)
+++ hlvm/trunk/hlvm/AST/Type.cpp Sat Jul 7 19:01:37 2007
@@ -82,14 +82,6 @@
{
}
-IntegerType*
-IntegerType::clone(const std::string& newname)
-{
- IntegerType* result = new IntegerType(*this);
- result->setName(newname);
- return result;
-}
-
const char*
IntegerType::getPrimitiveName() const
{
Modified: hlvm/trunk/hlvm/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Type.h?rev=38249&r1=38248&r2=38249&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Type.h (original)
+++ hlvm/trunk/hlvm/AST/Type.h Sat Jul 7 19:01:37 2007
@@ -244,7 +244,6 @@
public:
virtual ~IntegerType();
- IntegerType* clone(const std::string& newname);
/// @}
/// @name Accessors
Modified: hlvm/trunk/hlvm/Pass/Pass.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Pass/Pass.cpp?rev=38249&r1=38248&r2=38249&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Pass/Pass.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Pass.cpp Sat Jul 7 19:01:37 2007
@@ -185,7 +185,7 @@
{
// Call the initializers
std::vector<Pass*>::iterator PI = all.begin(), PE = all.end();
- while (PI != PE) { (*PI)->handleInitialize(); ++PI; }
+ while (PI != PE) { (*PI)->handleInitialize(tree); ++PI; }
// Just a little optimization for empty pass managers
if (pre.empty() && post.empty())
@@ -207,7 +207,7 @@
}
void
-Pass::handleInitialize()
+Pass::handleInitialize(AST* tree)
{
}
Modified: hlvm/trunk/hlvm/Pass/Pass.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Pass/Pass.h?rev=38249&r1=38248&r2=38249&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Pass/Pass.h (original)
+++ hlvm/trunk/hlvm/Pass/Pass.h Sat Jul 7 19:01:37 2007
@@ -86,7 +86,7 @@
public:
/// Handle initialization. This is called before any other handle method
/// is called. Default implementation does nothing
- virtual void handleInitialize();
+ virtual void handleInitialize(AST* tree);
/// Handle any kind of node. Subclasses should override this; the default
/// implementation does nothing. This handler is only called if the
Modified: hlvm/trunk/hlvm/Pass/Validate.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Pass/Validate.cpp?rev=38249&r1=38248&r2=38249&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Pass/Validate.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Validate.cpp Sat Jul 7 19:01:37 2007
@@ -29,9 +29,8 @@
#include <hlvm/Pass/Pass.h>
#include <hlvm/Base/Assert.h>
+#include <hlvm/AST/AST.h>
#include <hlvm/AST/Bundle.h>
-#include <hlvm/AST/ContainerType.h>
-#include <hlvm/AST/RuntimeType.h>
#include <hlvm/AST/ControlFlow.h>
#include <hlvm/AST/MemoryOps.h>
#include <hlvm/AST/InputOutput.h>
@@ -49,36 +48,29 @@
namespace {
class ValidateImpl : public Pass
{
+ AST* ast;
public:
- ValidateImpl() : Pass(0,Pass::PostOrderTraversal) {}
+ ValidateImpl() : Pass(0,Pass::PostOrderTraversal), ast(0) {}
+ virtual void handleInitialize(AST* tree) { ast = tree; }
virtual void handle(Node* b,Pass::TraversalKinds k);
inline void error(Node*n, const char* msg);
- inline void validateName(Node*n, const std::string& name);
inline bool checkNonPointer(Value*n);
- inline bool checkNumOperands(Operator*n,unsigned num, bool exact = true);
+ inline bool checkNode(Node*);
+ inline bool checkType(Type*,NodeIDs id);
+ inline bool checkValue(Value*,NodeIDs id);
+ inline bool checkConstant(Constant*,NodeIDs id);
+ inline bool checkOperator(
+ Operator*,NodeIDs id,unsigned numOps, bool exact = true);
+ inline bool checkUniformContainer(UniformContainerType* T, NodeIDs id);
+ inline bool checkDisparateContainer(DisparateContainerType* T, NodeIDs id);
+ inline bool checkLinkageItem(LinkageItem* LI, NodeIDs id);
template <class NodeClass>
inline void validate(NodeClass* C);
};
bool
-ValidateImpl::checkNumOperands(Operator*n, unsigned num, bool exact)
-{
- if (n->getType() == 0) {
- error(n,"Operator has no type");
- return false;
- } else if (num > n->getNumOperands()) {
- error(n,"Too few operands");
- return false;
- } else if (exact && num != n->getNumOperands()) {
- error(n, "Too many operands");
- return false;
- }
- return true;
-}
-
-bool
-ValidateImpl::checkNonPointer(Value*n)
+ValidateImpl::checkNonPointer(Value* n)
{
const Type* Ty = n->getType();
if (Ty) {
@@ -90,6 +82,131 @@
return true;
}
+bool
+ValidateImpl::checkNode(Node* n)
+{
+ bool result = true;
+ if (n->getParent() == 0) {
+ error(n,"Node has no parent");
+ result = false;
+ }
+ if (n->getID() < FirstNodeID || n->getID() > LastNodeID) {
+ error(n,"Node ID out of range");
+ result = false;
+ }
+ return result;;
+}
+
+bool
+ValidateImpl::checkType(Type* t,NodeIDs id)
+{
+ bool result = checkNode(t);
+ if (t->getID() != id) {
+ error(t,"Unexpected NodeID for Type");
+ result = false;
+ } else if (!t->isType()) {
+ error(t,"Bad ID for a Type");
+ result = false;
+ }
+ if (t->getName().empty()) {
+ error(t, "Empty type name");
+ result = false;
+ }
+ return result;
+}
+
+bool
+ValidateImpl::checkValue(Value* v, NodeIDs id)
+{
+ bool result = checkNode(v);
+ if (v->getID() != id) {
+ error(v,"Unexpected NodeID for Value");
+ result = false;
+ } else if (!v->isValue()) {
+ error(v,"Bad ID for a Value");
+ result = false;
+ }
+ if (v->getType() == 0) {
+ error(v,"Value with no type");
+ result = false;
+ }
+ return result;
+}
+
+bool
+ValidateImpl::checkConstant(Constant* C,NodeIDs id)
+{
+ return checkValue(C,id);
+}
+
+bool
+ValidateImpl::checkOperator(Operator*n, NodeIDs id, unsigned num, bool exact)
+{
+ bool result = checkValue(n,id);
+ if (result)
+ if (num > n->getNumOperands()) {
+ error(n,"Too few operands");
+ result = false;
+ } else if (exact && num != n->getNumOperands()) {
+ error(n, "Too many operands");
+ result = false;
+ }
+ return result;
+}
+
+bool
+ValidateImpl::checkUniformContainer(UniformContainerType* n, NodeIDs id)
+{
+ bool result = true;
+ if (!checkType(n,id))
+ result = false;
+ else if (n->getElementType() == 0) {
+ error(n,"UniformContainerType without element type");
+ result = false;
+ } else if (n->getElementType() == n) {
+ error(n,"Self-referential UniformContainerType");
+ result = false;
+ } else if (n->getName() == n->getElementType()->getName()) {
+ error(n,"UniformCOontainerType has same name as its element type");
+ result = false;
+ }
+ return result;
+}
+
+bool
+ValidateImpl::checkDisparateContainer(DisparateContainerType* n, NodeIDs id)
+{
+ bool result = true;
+ if (!checkType(n,id))
+ result = false;
+ else if (n->size() == 0) {
+ error(n,"DisparateContainerType without elements");
+ result = false;
+ } else
+ for (DisparateContainerType::iterator I = n->begin(), E = n->end();
+ I != E; ++I)
+ result &= checkUniformContainer(*I, AliasTypeID);
+ return result;
+}
+
+bool
+ValidateImpl::checkLinkageItem(LinkageItem* LI, NodeIDs id)
+{
+ bool result = checkConstant(LI,id);
+ if (result) {
+ if (LI->getLinkageKind() < ExternalLinkage ||
+ LI->getLinkageKind() > InternalLinkage) {
+ error(LI,"Invalid LinkageKind for LinkageItem");
+ result = false;
+ }
+ if (LI->getName().length() == 0) {
+ error(LI,"Zero length name for LinkageItem");
+ result = false;
+ }
+ }
+ return result;
+}
+
void
ValidateImpl::error(Node* n, const char* msg)
{
@@ -107,187 +224,246 @@
passed_ = false;
}
-inline void
-ValidateImpl::validateName(Node*n, const std::string& name)
-{
- if (name.empty()) {
- error(n,"Empty Name");
- }
-}
-
template<> inline void
ValidateImpl::validate(VoidType* n)
{
+ checkType(n,VoidTypeID);
}
template<> inline void
ValidateImpl::validate(AnyType* n)
{
+ checkType(n,AnyTypeID);
}
template<> inline void
ValidateImpl::validate(BooleanType* n)
{
+ checkType(n,BooleanTypeID);
}
template<> inline void
ValidateImpl::validate(CharacterType* n)
{
+ checkType(n,CharacterTypeID);
}
template<> inline void
ValidateImpl::validate(OctetType* n)
{
+ checkType(n,OctetTypeID);
}
template<> inline void
ValidateImpl::validate(IntegerType* n)
{
- validateName(n,n->getName());
- if (n->getBits() == 0) {
- error(n,"Invalid number of bits");
- }
+ if (checkNode(n))
+ if (!n->isIntegerType())
+ error(n,"Bad ID for IntegerType");
+ else if (n->getBits() == 0)
+ error(n,"Invalid number of bits");
}
template<> inline void
ValidateImpl::validate(RangeType* n)
{
+ if (checkType(n,RangeTypeID))
+ if (n->getMin() > n->getMax())
+ error(n,"RangeType has negative range");
}
template<> inline void
ValidateImpl::validate(EnumerationType* n)
{
+ if (checkType(n,EnumerationTypeID))
+ for (EnumerationType::iterator I = n->begin(), E = n->end(); I != E; ++I )
+ if ((I)->length() == 0)
+ error(n,"Enumerator with zero length");
}
template<> inline void
ValidateImpl::validate(RealType* n)
{
+ if (checkNode(n))
+ if (!n->isRealType())
+ error(n,"Bad ID for RealType");
+ else {
+ uint64_t bits = n->getMantissa() + n->getExponent();
+ if (bits > UINT32_MAX)
+ error(n,"Too many bits in RealType");
+ }
}
template<> inline void
ValidateImpl::validate(OpaqueType* n)
{
+ checkType(n,OpaqueTypeID);
}
template<> inline void
ValidateImpl::validate(TextType* n)
{
+ checkType(n,TextTypeID);
}
template<> inline void
ValidateImpl::validate(StreamType* n)
{
+ checkType(n,StreamTypeID);
}
template<> inline void
ValidateImpl::validate(BufferType* n)
{
+ checkType(n,BufferTypeID);
}
template<> inline void
ValidateImpl::validate(AliasType* n)
{
+ checkUniformContainer(n, AliasTypeID);
}
template<> inline void
ValidateImpl::validate(PointerType* n)
{
+ checkUniformContainer(n, PointerTypeID);
}
template<> inline void
ValidateImpl::validate(ArrayType* n)
{
+ checkUniformContainer(n, ArrayTypeID);
}
template<> inline void
ValidateImpl::validate(VectorType* n)
{
+ checkUniformContainer(n, VectorTypeID);
}
template<> inline void
ValidateImpl::validate(StructureType* n)
{
+ checkDisparateContainer(n, StructureTypeID);
}
template<> inline void
ValidateImpl::validate(ContinuationType* n)
{
+ checkDisparateContainer(n, ContinuationTypeID);
}
template<> inline void
ValidateImpl::validate(SignatureType* n)
{
+ checkDisparateContainer(n, SignatureTypeID);
}
template<> inline void
ValidateImpl::validate(Variable* n)
{
+ checkLinkageItem(n, VariableID);
}
template<> inline void
-ValidateImpl::validate(Function* n)
+ValidateImpl::validate(Function* F)
{
+ if (checkLinkageItem(F, FunctionID)) {
+ if (F->getSignature() == 0)
+ error(F,"Function without signature");
+ else if (F->getSignature()->getID() != SignatureTypeID)
+ error(F,"Function does not have SignatureType signature");
+ if (F->getLinkageKind() != ExternalLinkage && F->getBlock() == 0)
+ error(F,"Non-external Function without defining block");
+ }
}
template<> inline void
-ValidateImpl::validate(Program* n)
+ValidateImpl::validate(Program* P)
{
+ if (checkLinkageItem(P, ProgramID)) {
+ if (P->getSignature() == 0)
+ error(P,"Program without signature");
+ else if (P->getSignature()->getID() != SignatureTypeID)
+ error(P,"Program does not have SignatureType signature");
+ else if (P->getSignature() != ast->getProgramType())
+ error(P,"Program has wrong signature");
+ if (P->getLinkageKind() != ExternalLinkage && P->getBlock() == 0)
+ error(P,"Non-external Program without defining block");
+ }
}
template<> inline void
ValidateImpl::validate(Block* n)
{
+ if (checkValue(n,BlockID))
+ if (n->getNumOperands() == 0)
+ error(n,"Block with no operands");
+ else
+ for (MultiOperator::iterator I = n->begin(), E = n->end(); I != E; ++I)
+ if (!llvm::isa<Operator>(*I))
+ error(n,"Block contains non-operator");
}
template<> inline void
ValidateImpl::validate(NoOperator* n)
{
+ checkOperator(n,NoOperatorID,0);
}
template<> inline void
ValidateImpl::validate(ReturnOp* n)
{
+ checkOperator(n,ReturnOpID,1);
}
template<> inline void
ValidateImpl::validate(BreakOp* n)
{
+ checkOperator(n,BreakOpID,0);
}
template<> inline void
ValidateImpl::validate(ContinueOp* n)
{
+ checkOperator(n,ContinueOpID,0);
}
template<> inline void
ValidateImpl::validate(SelectOp* n)
{
+ checkOperator(n,SelectOpID,3);
}
template<> inline void
ValidateImpl::validate(LoopOp* n)
{
+ checkOperator(n,LoopOpID,3);
}
template<> inline void
ValidateImpl::validate(SwitchOp* n)
{
+ checkOperator(n,SwitchOpID,2,false);
}
template<> inline void
ValidateImpl::validate(AllocateOp* n)
{
+ checkOperator(n,AllocateOpID,2);
}
template<> inline void
ValidateImpl::validate(DeallocateOp* n)
{
+ checkOperator(n,DeallocateOpID,1);
}
template<> inline void
ValidateImpl::validate(LoadOp* n)
{
- if (checkNumOperands(n,1)) {
+ if (checkOperator(n,LoadOpID,1)) {
Value* oprnd = n->getOperand(0);
if (!isa<PointerType>(oprnd->getType()))
error(n,"LoadOp expects a pointer type operand");
@@ -300,7 +476,7 @@
template<> inline void
ValidateImpl::validate(StoreOp* n)
{
- if (checkNumOperands(n,2)) {
+ if (checkOperator(n,StoreOpID,2)) {
Value* op1 = n->getOperand(0);
Value* op2 = n->getOperand(1);
if (!isa<PointerType>(op1->getType()))
@@ -314,304 +490,308 @@
template<> inline void
ValidateImpl::validate(AutoVarOp* n)
{
+ if (checkOperator(n,AutoVarOpID,0,false))
+ ;
}
template<> inline void
ValidateImpl::validate(NegateOp* n)
{
+ if (checkOperator(n,NegateOpID,1))
+ ;
}
template<> inline void
ValidateImpl::validate(ComplementOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,ComplementOpID,1))
checkNonPointer(n->getOperand(0));
}
template<> inline void
ValidateImpl::validate(PreIncrOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,PreIncrOpID,1))
;
}
template<> inline void
ValidateImpl::validate(PostIncrOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,PostIncrOpID,1))
;
}
template<> inline void
ValidateImpl::validate(PreDecrOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,PreDecrOpID,1))
;
}
template<> inline void
ValidateImpl::validate(PostDecrOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,PostDecrOpID,1))
;
}
template<> inline void
ValidateImpl::validate(AddOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,AddOpID,2))
;
}
template<> inline void
ValidateImpl::validate(SubtractOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,SubtractOpID,2))
;
}
template<> inline void
ValidateImpl::validate(MultiplyOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,MultiplyOpID,2))
;
}
template<> inline void
ValidateImpl::validate(DivideOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,DivideOpID,2))
;
}
template<> inline void
ValidateImpl::validate(ModuloOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,ModuloOpID,2))
;
}
template<> inline void
ValidateImpl::validate(BAndOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,BAndOpID,2))
;
}
template<> inline void
ValidateImpl::validate(BOrOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,BOrOpID,2))
;
}
template<> inline void
ValidateImpl::validate(BXorOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,BXorOpID,2))
;
}
template<> inline void
ValidateImpl::validate(BNorOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,BNorOpID,2))
;
}
template<> inline void
ValidateImpl::validate(NotOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,NotOpID,1))
;
}
template<> inline void
ValidateImpl::validate(AndOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,AndOpID,2))
;
}
template<> inline void
ValidateImpl::validate(OrOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,OrOpID,2))
;
}
template<> inline void
ValidateImpl::validate(NorOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,NorOpID,2))
;
}
template<> inline void
ValidateImpl::validate(XorOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,XorOpID,2))
;
}
template<> inline void
ValidateImpl::validate(LessThanOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,LessThanOpID,2))
;
}
template<> inline void
ValidateImpl::validate(GreaterThanOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,GreaterThanOpID,2))
;
}
template<> inline void
ValidateImpl::validate(LessEqualOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,LessEqualOpID,2))
;
}
template<> inline void
ValidateImpl::validate(GreaterEqualOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,GreaterEqualOpID,2))
;
}
template<> inline void
ValidateImpl::validate(EqualityOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,EqualityOpID,2))
;
}
template<> inline void
ValidateImpl::validate(InequalityOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,InequalityOpID,2))
;
}
template<> inline void
ValidateImpl::validate(IsPInfOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,IsPInfOpID,1))
;
}
template<> inline void
ValidateImpl::validate(IsNInfOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,IsNInfOpID,1))
;
}
template<> inline void
ValidateImpl::validate(IsNanOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,IsNanOpID,1))
;
}
template<> inline void
ValidateImpl::validate(TruncOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,TruncOpID,1))
;
}
template<> inline void
ValidateImpl::validate(RoundOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,RoundOpID,1))
;
}
template<> inline void
ValidateImpl::validate(FloorOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,FloorOpID,1))
;
}
template<> inline void
ValidateImpl::validate(CeilingOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,CeilingOpID,1))
;
}
template<> inline void
ValidateImpl::validate(LogEOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,LogEOpID,1))
;
}
template<> inline void
ValidateImpl::validate(Log2Op* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,Log2OpID,1))
;
}
template<> inline void
ValidateImpl::validate(Log10Op* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,Log10OpID,1))
;
}
template<> inline void
ValidateImpl::validate(SquareRootOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,SquareRootOpID,1))
;
}
template<> inline void
ValidateImpl::validate(CubeRootOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,CubeRootOpID,1))
;
}
template<> inline void
ValidateImpl::validate(FactorialOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,FactorialOpID,1))
;
}
template<> inline void
ValidateImpl::validate(PowerOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,PowerOpID,2))
;
}
template<> inline void
ValidateImpl::validate(RootOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,RootOpID,2))
;
}
template<> inline void
ValidateImpl::validate(GCDOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,GCDOpID,2))
;
}
template<> inline void
ValidateImpl::validate(LCMOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,LCMOpID,2))
;
}
@@ -619,28 +799,28 @@
template<> inline void
ValidateImpl::validate(OpenOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,OpenOpID,1))
;
}
template<> inline void
ValidateImpl::validate(CloseOp* n)
{
- if (checkNumOperands(n,1))
+ if (checkOperator(n,CloseOpID,1))
;
}
template<> inline void
ValidateImpl::validate(ReadOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,ReadOpID,2))
;
}
template<> inline void
ValidateImpl::validate(WriteOp* n)
{
- if (checkNumOperands(n,2))
+ if (checkOperator(n,WriteOpID,2))
;
}
Modified: hlvm/trunk/hlvm/Reader/XMLReader.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XMLReader.cpp?rev=38249&r1=38248&r2=38249&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Reader/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XMLReader.cpp Sat Jul 7 19:01:37 2007
@@ -774,7 +774,7 @@
referent = av;
break;
}
- if (llvm::isa<Block>(blk->getParent()))
+ if (blk->getParent() && llvm::isa<Block>(blk->getParent()))
blk = llvm::cast<Block>(blk->getParent());
else
blk = 0;
@@ -869,18 +869,18 @@
XMLReaderImpl::parse<Block>(xmlNodePtr& cur)
{
hlvmAssert(getToken(cur->name) == TKN_block && "Expecting block element");
+ hlvmAssert(func != 0);
Locator* loc = getLocator(cur);
const char* label = getAttribute(cur, "label",false);
- if (label)
- block = ast->new_Block(label,loc);
- else
- block = ast->new_Block("",loc);
- hlvmAssert(func != 0);
- block->setParent(func);
xmlNodePtr child = cur->children;
+ MultiOperator::OprndList ops;
+ block = ast->new_Block(loc);
+ block->setParent(func);
+ if (label)
+ block->setLabel(label);
while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE)
{
- Value* op = parseOperator(child);
+ Operator* op = parseOperator(child);
block->addOperand(op);
child = child->next;
}
@@ -1165,30 +1165,48 @@
v = parseConstant(cur,0,tkn);
break;
case TKN_noop:
- case TKN_select:
- case TKN_switch:
- case TKN_loop:
- case TKN_break:
- case TKN_continue:
- case TKN_ret:
case TKN_neg:
- case TKN_cmpl:
- case TKN_preinc:
- case TKN_predec:
+ case TKN_cmpl:
+ case TKN_preinc:
+ case TKN_predec:
case TKN_postinc:
case TKN_postdec:
- case TKN_open:
- case TKN_write:
- case TKN_close:
- case TKN_store:
- case TKN_load:
- case TKN_ref:
- case TKN_autovar:
+ case TKN_add:
+ case TKN_sub:
+ case TKN_mul:
+ case TKN_div:
+ case TKN_mod:
+ case TKN_band:
+ case TKN_bor:
+ case TKN_bxor:
+ case TKN_bnor:
+ case TKN_not:
+ case TKN_and:
+ case TKN_or:
+ case TKN_nor:
+ case TKN_xor:
+ case TKN_eq:
+ case TKN_ne:
+ case TKN_lt:
+ case TKN_gt:
+ case TKN_ge:
+ case TKN_le:
+ case TKN_select:
+ case TKN_switch:
+ case TKN_loop:
+ case TKN_break:
+ case TKN_continue:
+ case TKN_ret:
+ case TKN_store:
+ case TKN_load:
+ case TKN_open:
+ case TKN_write:
+ case TKN_close:
+ case TKN_ref:
+ case TKN_autovar:
+ case TKN_block:
v = parseOperator(cur,tkn);
break;
- case TKN_block:
- v = parse<Block>(cur);
- break;
case TKN_program:
v = parse<Program>(cur);
break;
Added: hlvm/trunk/test/return0/complement.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/return0/complement.hlx?rev=38249&view=auto
==============================================================================
--- hlvm/trunk/test/return0/complement.hlx (added)
+++ hlvm/trunk/test/return0/complement.hlx Sat Jul 7 19:01:37 2007
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="http://hlvm.org/src/hlvm/test/xml2xml/complement.hlx">
+ <bundle id="complement">
+ <program id="complement">
+ <block>
+ <autovar id="v" type="s32"><zero/></autovar>
+ <ret>
+ <cmpl><cmpl><load><ref id="v"/></load></cmpl></cmpl>
+ </ret>
+ </block>
+ </program>
+ </bundle>
+</hlvm>
More information about the llvm-commits
mailing list