[llvm-commits] [hlvm] r38242 - in /hlvm/trunk: hlvm/AST/AST.cpp hlvm/AST/AST.h hlvm/AST/Arithmetic.cpp hlvm/AST/Arithmetic.h hlvm/AST/Constants.cpp hlvm/AST/Constants.h hlvm/AST/ControlFlow.cpp hlvm/AST/ControlFlow.h hlvm/AST/Node.h hlvm/CodeGen/LLVMGenerator.cpp hlvm/Pass/Validate.cpp hlvm/Reader/HLVM.rng hlvm/Reader/XMLReader.cpp hlvm/Writer/XMLWriter.cpp test/xml2xml/break.hlx test/xml2xml/continue.hlx test/xml2xml/loop.hlx test/xml2xml/select.hlx test/xml2xml/switch.hlx
Reid Spencer
reid at x10sys.com
Sat Jul 7 17:01:32 PDT 2007
Author: reid
Date: Sat Jul 7 19:01:32 2007
New Revision: 38242
URL: http://llvm.org/viewvc/llvm-project?rev=38242&view=rev
Log:
Add parsing support for the Control Flow operators: select, switch, loop, break
continue, and noop.
Added:
hlvm/trunk/test/xml2xml/break.hlx
hlvm/trunk/test/xml2xml/continue.hlx
hlvm/trunk/test/xml2xml/loop.hlx
hlvm/trunk/test/xml2xml/select.hlx
hlvm/trunk/test/xml2xml/switch.hlx
Modified:
hlvm/trunk/hlvm/AST/AST.cpp
hlvm/trunk/hlvm/AST/AST.h
hlvm/trunk/hlvm/AST/Arithmetic.cpp
hlvm/trunk/hlvm/AST/Arithmetic.h
hlvm/trunk/hlvm/AST/Constants.cpp
hlvm/trunk/hlvm/AST/Constants.h
hlvm/trunk/hlvm/AST/ControlFlow.cpp
hlvm/trunk/hlvm/AST/ControlFlow.h
hlvm/trunk/hlvm/AST/Node.h
hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
hlvm/trunk/hlvm/Pass/Validate.cpp
hlvm/trunk/hlvm/Reader/HLVM.rng
hlvm/trunk/hlvm/Reader/XMLReader.cpp
hlvm/trunk/hlvm/Writer/XMLWriter.cpp
Modified: hlvm/trunk/hlvm/AST/AST.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/AST.cpp?rev=38242&r1=38241&r2=38242&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul 7 19:01:32 2007
@@ -61,7 +61,8 @@
SInt64Singleton(0), SInt128Singleton(0), Float32Singleton(0),
Float44Singleton(0), Float64Singleton(0), Float80Singleton(0),
Float128Singleton(0), TextTypeSingleton(0), StreamTypeSingleton(0),
- BufferTypeSingleton(0), ProgramTypeSingleton(0)
+ BufferTypeSingleton(0), ProgramTypeSingleton(0),
+ BooleanTrueSingleton(0), BooleanFalseSingleton(0)
{
pool = Pool::create("ASTPool",0,false,1024,4,0);
}
@@ -101,6 +102,8 @@
StreamType* StreamTypeSingleton;
BufferType* BufferTypeSingleton;
SignatureType* ProgramTypeSingleton;
+ ConstantBoolean* BooleanTrueSingleton;
+ ConstantBoolean* BooleanFalseSingleton;
public:
Type* resolveType(const std::string& name);
@@ -467,6 +470,21 @@
return result;
}
+ConstantBoolean*
+AST::new_ConstantBoolean(bool t_or_f, const Locator* loc)
+{
+ ASTImpl* ast = static_cast<ASTImpl*>(this);
+ if (t_or_f) {
+ if (!ast->BooleanTrueSingleton)
+ ast->BooleanTrueSingleton = new ConstantBoolean(true);
+ return ast->BooleanTrueSingleton;
+ } else {
+ if (!ast->BooleanFalseSingleton)
+ ast->BooleanFalseSingleton = new ConstantBoolean(false);
+ return ast->BooleanFalseSingleton;
+ }
+}
+
ConstantZero*
AST::new_ConstantZero(const Type* Ty, const Locator* loc)
{
@@ -577,9 +595,31 @@
return result;
}
+template<class OpClass>
+OpClass*
+AST::new_MultiOp(const Locator* loc)
+{
+ OpClass* result = new OpClass();
+ result->setLocator(loc);
+ return result;
+}
+
// Control Flow Operators
+template NoOperator*
+AST::new_NilaryOp<NoOperator>(const Locator*loc);
+template SelectOp*
+AST::new_TernaryOp<SelectOp>(Value*op1,Value*op2,Value*op3,const Locator* loc);
+template LoopOp*
+AST::new_TernaryOp<LoopOp>(Value*op1,Value*op2,Value*op3,const Locator* loc);
+template SwitchOp*
+AST::new_MultiOp<SwitchOp>(const Locator* loc);
+template BreakOp*
+AST::new_NilaryOp<BreakOp>(const Locator*loc);
+template ContinueOp*
+AST::new_NilaryOp<ContinueOp>(const Locator*loc);
template ReturnOp*
AST::new_UnaryOp<ReturnOp>(Value*op1,const Locator*loc);
+
// Memory Operators
template StoreOp*
AST::new_BinaryOp<StoreOp>(Value*op1,Value*op2,const Locator*loc);
Modified: hlvm/trunk/hlvm/AST/AST.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/AST.h?rev=38242&r1=38241&r2=38242&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/AST.h (original)
+++ hlvm/trunk/hlvm/AST/AST.h Sat Jul 7 19:01:32 2007
@@ -52,6 +52,7 @@
class Import;
class Locator;
class Variable;
+class ConstantBoolean;
class ConstantInteger;
class ConstantReal;
class ConstantText;
@@ -416,6 +417,11 @@
const Type* ty, ///< The type of the variable
const Locator* loc = 0 ///< The source locator
);
+ /// Createa new ConstantBoolean node
+ ConstantBoolean* new_ConstantBoolean(
+ bool t_or_f, ///< The value for the constant
+ const Locator* loc = 0 ///< The source locator
+ );
/// Create a new ConstantZero node
ConstantZero* new_ConstantZero(
const Type* Ty, ///< The type for the constant zero
@@ -482,6 +488,11 @@
const Locator* loc = 0 ///< The source locator
);
+ template<class OpClass>
+ OpClass* new_MultiOp(
+ const Locator* loc = 0 ///< The source locator
+ );
+
/// Create a new ReturnOp node. The ReturnOp is an operator that returns
/// immediately from the enclosing function, possibly with a result value.
ReturnOp* new_ReturnOp(
Modified: hlvm/trunk/hlvm/AST/Arithmetic.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Arithmetic.cpp?rev=38242&r1=38241&r2=38242&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Arithmetic.cpp (original)
+++ hlvm/trunk/hlvm/AST/Arithmetic.cpp Sat Jul 7 19:01:32 2007
@@ -46,5 +46,6 @@
BAndOp::~BAndOp() {}
BOrOp::~BOrOp() {}
BXorOp::~BXorOp() {}
+BNorOp::~BNorOp() {}
} // end hlvm namespace
Modified: hlvm/trunk/hlvm/AST/Arithmetic.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Arithmetic.h?rev=38242&r1=38241&r2=38242&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Arithmetic.h (original)
+++ hlvm/trunk/hlvm/AST/Arithmetic.h Sat Jul 7 19:01:32 2007
@@ -360,6 +360,29 @@
friend class AST;
};
+/// This class provides an Abstract Syntax Tree node that represents a bitwise
+/// not or operator. The BNorOp is a binary operator that computes the
+/// bitwise nor of its two operands and returns that value.
+/// @brief AST Bitwise Nor Operator Node
+class BNorOp : public BinaryOperator
+{
+ /// @name Constructors
+ /// @{
+ protected:
+ BNorOp() : BinaryOperator(BNorOpID) {}
+ virtual ~BNorOp();
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ static inline bool classof(const BNorOp*) { return true; }
+ static inline bool classof(const Node* N) { return N->is(BNorOpID); }
+
+ /// @}
+ friend class AST;
+};
+
} // end hlvm namespace
#endif
Modified: hlvm/trunk/hlvm/AST/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Constants.cpp?rev=38242&r1=38241&r2=38242&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Constants.cpp (original)
+++ hlvm/trunk/hlvm/AST/Constants.cpp Sat Jul 7 19:01:32 2007
@@ -32,20 +32,13 @@
namespace hlvm {
-ConstantInteger::~ConstantInteger()
-{
-}
+ConstantBoolean::~ConstantBoolean() { }
+ConstantInteger::~ConstantInteger() { }
-ConstantReal::~ConstantReal()
-{
-}
+ConstantReal::~ConstantReal() { }
-ConstantText::~ConstantText()
-{
-}
+ConstantText::~ConstantText() { }
-ConstantZero::~ConstantZero()
-{
-}
+ConstantZero::~ConstantZero() { }
}
Modified: hlvm/trunk/hlvm/AST/Constants.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Constants.h?rev=38242&r1=38241&r2=38242&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Constants.h (original)
+++ hlvm/trunk/hlvm/AST/Constants.h Sat Jul 7 19:01:32 2007
@@ -36,6 +36,34 @@
{
/// This class provides an Abstract Syntax Tree node that yields a
+/// constant boolean value.
+/// @brief AST Constant Boolean Node
+class ConstantBoolean: public Constant
+{
+ /// @name Constructors
+ /// @{
+ protected:
+ ConstantBoolean(bool val) : Constant(ConstantBooleanID), value(val) {}
+ virtual ~ConstantBoolean();
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ static inline bool classof(const ConstantBoolean*) { return true; }
+ static inline bool classof(const Node* N)
+ { return N->is(ConstantBooleanID); }
+
+ /// @}
+ /// @name Data
+ /// @{
+ public:
+ bool value;
+ /// @}
+ friend class AST;
+};
+
+/// This class provides an Abstract Syntax Tree node that yields a
/// constant integer value. This kind of constant can represent integer valued
/// constants of any of the signed or unsigned integer types of any bitsize.
/// @see IntegerType
@@ -59,7 +87,7 @@
{ return N->is(ConstantIntegerID); }
/// @}
- /// @name Accessors
+ /// @name Mutators
/// @{
public:
void setValue(uint64_t v) { value.u = v; }
Modified: hlvm/trunk/hlvm/AST/ControlFlow.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/ControlFlow.cpp?rev=38242&r1=38241&r2=38242&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/ControlFlow.cpp (original)
+++ hlvm/trunk/hlvm/AST/ControlFlow.cpp Sat Jul 7 19:01:32 2007
@@ -31,6 +31,7 @@
namespace hlvm {
+NoOperator::~NoOperator() {}
SelectOp::~SelectOp() {}
SwitchOp::~SwitchOp() {}
LoopOp::~LoopOp() {}
Modified: hlvm/trunk/hlvm/AST/ControlFlow.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/ControlFlow.h?rev=38242&r1=38241&r2=38242&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/ControlFlow.h (original)
+++ hlvm/trunk/hlvm/AST/ControlFlow.h Sat Jul 7 19:01:32 2007
@@ -35,6 +35,28 @@
namespace hlvm
{
+/// This class provides an Abstract Syntax Tree node for the "noop" operator
+/// that does nothing.
+/// @brief AST NoOp Operator
+class NoOperator : public NilaryOperator
+{
+ /// @name Constructors
+ /// @{
+ protected:
+ NoOperator() : NilaryOperator(NoOperatorID) {}
+ virtual ~NoOperator();
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ static inline bool classof(const NoOperator*) { return true; }
+ static inline bool classof(const Node* N) { return N->is(NoOperatorID); }
+
+ /// @}
+ friend class AST;
+};
+
/// This class provides an Abstract Syntax Tree node that represents a select
/// operator. The select operator is a ternary operator that evaluates its first
/// operand as a boolean. If the result is true, the second operand is evaluated
Modified: hlvm/trunk/hlvm/AST/Node.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Node.h?rev=38242&r1=38241&r2=38242&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Node.h (original)
+++ hlvm/trunk/hlvm/AST/Node.h Sat Jul 7 19:01:32 2007
@@ -134,6 +134,7 @@
ConstantZeroID, ///< A zero-filled constant of any type
FirstValueID = ConstantZeroID,
FirstConstantID = ConstantZeroID,
+ ConstantBooleanID, ///< A constant boolean value
ConstantIntegerID, ///< A constant integer value
ConstantRealID, ///< A constant real value
ConstantTextID, ///< A constant text value
@@ -164,8 +165,9 @@
LastNilaryOperatorID = ReferenceOpID,
// Control Flow Unary Operators
+ NoOperatorID, ///< The "do nothing" NoOp Operators
+FirstUnaryOperatorID = NoOperatorID,
ReturnOpID, ///< The Return A Value Operator
-FirstUnaryOperatorID = ReturnOpID,
ThrowOpID, ///< The Throw an Exception Operator
// Integer Arithmetic Unary Operators
@@ -216,6 +218,7 @@
BAndOpID, ///< Bitwise And Binary Operator
BOrOpID, ///< Bitwise Or Binary Operator
BXorOpID, ///< Bitwise XOr Binary Operator
+ BNorOpID, ///< Bitwise Nor Binary Operator
// Boolean Binary Operators
AndOpID, ///< And Binary Boolean Operator
Modified: hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp?rev=38242&r1=38241&r2=38242&view=diff
==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp (original)
+++ hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp Sat Jul 7 19:01:32 2007
@@ -36,6 +36,9 @@
#include <hlvm/AST/ControlFlow.h>
#include <hlvm/AST/MemoryOps.h>
#include <hlvm/AST/InputOutput.h>
+#include <hlvm/AST/Arithmetic.h>
+#include <hlvm/AST/RealMath.h>
+#include <hlvm/AST/BooleanOps.h>
#include <hlvm/AST/Constants.h>
#include <hlvm/Base/Assert.h>
#include <hlvm/Pass/Pass.h>
Modified: hlvm/trunk/hlvm/Pass/Validate.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Pass/Validate.cpp?rev=38242&r1=38241&r2=38242&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Pass/Validate.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Validate.cpp Sat Jul 7 19:01:32 2007
@@ -198,6 +198,11 @@
}
template<> inline void
+ValidateImpl::validate(NoOperator* n)
+{
+}
+
+template<> inline void
ValidateImpl::validate(ReturnOp* n)
{
}
@@ -567,9 +572,10 @@
case DispatchOpID: /*validate(cast<DispatchOp>(n));*/ break;
case CreateContOpID: /*validate(cast<CreateContOp>(n));*/ break;
case CallWithContOpID: /*validate(cast<CallWithContOp>(n));*/ break;
- case ReturnOpID: validate(cast<ReturnOp>(n)); break;
case ThrowOpID: /*validate(cast<ThrowOp>(n));*/ break;
- case ContinueOpID: /*validate(cast<ContinueOp>(n));*/ break;
+ case NoOperatorID: validate(cast<NoOperator>(n)); break;
+ case ReturnOpID: validate(cast<ReturnOp>(n)); break;
+ case ContinueOpID: validate(cast<ContinueOp>(n)); break;
case BreakOpID: validate(cast<BreakOp>(n)); break;
case SelectOpID: validate(cast<SelectOp>(n)); break;
case LoopOpID: validate(cast<LoopOp>(n)); break;
Modified: hlvm/trunk/hlvm/Reader/HLVM.rng
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/HLVM.rng?rev=38242&r1=38241&r2=38242&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Reader/HLVM.rng (original)
+++ hlvm/trunk/hlvm/Reader/HLVM.rng Sat Jul 7 19:01:32 2007
@@ -694,7 +694,7 @@
<define name="Operators.pat">
<choice>
- <ref name="autovar.elem"/>
+ <ref name="noop.elem"/>
<ref name="ComparisonOperators.pat"/>
<ref name="UnaryArithmeticOperators.pat"/>
<ref name="BinaryArithmeticOperators.pat"/>
@@ -706,11 +706,32 @@
</choice>
</define>
- <define name="cast.elem">
- <empty/>
+ <define name="UnaryOperator.pat">
+ <ref name="Documentation.pat"/>
+ <ref name="Value.pat"/>
</define>
- <define name="select.elem">
+
+ <define name="BinaryOperator.pat">
+ <ref name="Documentation.pat"/>
+ <ref name="Value.pat"/>
+ <ref name="Value.pat"/>
+ </define>
+
+ <define name="TernaryOperator.pat">
+ <ref name="Documentation.pat"/>
+ <ref name="Value.pat"/>
+ <ref name="Value.pat"/>
+ <ref name="Value.pat"/>
+ </define>
+
+ <define name="noop.elem">
+ <element name="noop">
+ <empty/>
+ </element>
+ </define>
+
+ <define name="cast.elem">
<empty/>
</define>
@@ -734,17 +755,7 @@
<empty/>
</define>
- <define name="autovar.elem">
- <element name="autovar">
- <ref name="Named_Typed_Element.pat"/>
- <choice>
- <ref name="Constant.pat"/>
- <element name="zero">
- <empty/>
- </element>
- </choice>
- </element>
- </define>
+ <!-- MEMORY OPERATORS -->
<define name="MemoryOps.pat">
<choice>
@@ -752,6 +763,7 @@
<ref name="store.elem"/>
<ref name="index.elem"/>
<ref name="length.elem"/>
+ <ref name="autovar.elem"/>
</choice>
</define>
@@ -787,6 +799,20 @@
</element>
</define>
+ <define name="autovar.elem">
+ <element name="autovar">
+ <ref name="Named_Typed_Element.pat"/>
+ <choice>
+ <ref name="Constant.pat"/>
+ <element name="zero">
+ <empty/>
+ </element>
+ </choice>
+ </element>
+ </define>
+
+ <!-- INPUT/OUTPUT OPERATORS -->
+
<define name="InputOutputOps.pat">
<choice>
<ref name="open.elem"/>
@@ -829,6 +855,8 @@
</element>
</define>
+ <!-- UNARY ARITHMETIC OPERATORS -->
+
<define name="UnaryArithmeticOperators.pat">
<choice>
<ref name="neg.elem"/>
@@ -838,38 +866,55 @@
<define name="neg.elem">
<element name="neg">
- <ref name="Documentation.pat"/>
- <ref name="Value.pat"/>
+ <ref name="UnaryOperator.pat"/>
</element>
</define>
<define name="cmpl.elem">
<element name="cmpl">
- <ref name="Documentation.pat"/>
- <ref name="Value.pat"/>
+ <ref name="UnaryOperator.pat"/>
</element>
</define>
+ <!-- BINARY ARITHMETIC OPERATORS -->
+
<define name="BinaryArithmeticOperators.pat">
<choice>
<ref name="add.elem"/>
<ref name="sub.elem"/>
+ <ref name="mul.elem"/>
+ <ref name="div.elem"/>
+ <ref name="mod.elem"/>
</choice>
</define>
<define name="add.elem">
<element name="add">
- <ref name="Documentation.pat"/>
- <ref name="Value.pat"/>
- <ref name="Value.pat"/>
+ <ref name="BinaryOperator.pat"/>
</element>
</define>
<define name="sub.elem">
<element name="sub">
- <ref name="Documentation.pat"/>
- <ref name="Value.pat"/>
- <ref name="Value.pat"/>
+ <ref name="BinaryOperator.pat"/>
+ </element>
+ </define>
+
+ <define name="mul.elem">
+ <element name="mul">
+ <ref name="BinaryOperator.pat"/>
+ </element>
+ </define>
+
+ <define name="div.elem">
+ <element name="div">
+ <ref name="BinaryOperator.pat"/>
+ </element>
+ </define>
+
+ <define name="mod.elem">
+ <element name="mod">
+ <ref name="BinaryOperator.pat"/>
</element>
</define>
@@ -877,22 +922,25 @@
<choice>
<ref name="bor.elem"/>
<ref name="band.elem"/>
+ <ref name="bxor.elem"/>
</choice>
</define>
<define name="bor.elem">
<element name="bor">
- <ref name="Documentation.pat"/>
- <ref name="Value.pat"/>
- <ref name="Value.pat"/>
+ <ref name="BinaryOperator.pat"/>
</element>
</define>
<define name="band.elem">
<element name="band">
- <ref name="Documentation.pat"/>
- <ref name="Value.pat"/>
- <ref name="Value.pat"/>
+ <ref name="BinaryOperator.pat"/>
+ </element>
+ </define>
+
+ <define name="bxor.elem">
+ <element name="bxor">
+ <ref name="BinaryOperator.pat"/>
</element>
</define>
@@ -905,29 +953,98 @@
<define name="eq.elem">
<element name="eq">
- <ref name="Documentation.pat"/>
- <ref name="Value.pat"/>
- <ref name="Value.pat"/>
+ <ref name="BinaryOperator.pat"/>
</element>
</define>
<define name="ne.elem">
<element name="ne">
- <ref name="Documentation.pat"/>
- <ref name="Value.pat"/>
- <ref name="Value.pat"/>
+ <ref name="BinaryOperator.pat"/>
+ </element>
+ </define>
+
+ <define name="lt.elem">
+ <element name="lt">
+ <ref name="BinaryOperator.pat"/>
+ </element>
+ </define>
+
+ <define name="gt.elem">
+ <element name="gt">
+ <ref name="BinaryOperator.pat"/>
+ </element>
+ </define>
+
+ <define name="le.elem">
+ <element name="le">
+ <ref name="BinaryOperator.pat"/>
+ </element>
+ </define>
+
+ <define name="ge.elem">
+ <element name="ge">
+ <ref name="BinaryOperator.pat"/>
</element>
</define>
<define name="ControlFlowOps.pat">
<choice>
+ <ref name="select.elem"/>
+ <ref name="switch.elem"/>
+ <ref name="loop.elem"/>
+ <ref name="break.elem"/>
+ <ref name="continue.elem"/>
<ref name="ret.elem"/>
</choice>
</define>
+ <define name="select.elem">
+ <element name="select">
+ <ref name="Documentation.pat"/>
+ <ref name="Value.pat"/>
+ <ref name="Operators.pat"/>
+ <ref name="Operators.pat"/>
+ </element>
+ </define>
+
+ <define name="switch.elem">
+ <element name="switch">
+ <ref name="Documentation.pat"/>
+ <ref name="Value.pat"/> <!-- Control Expression -->
+ <ref name="Operators.pat"/> <!-- Default Case -->
+ <zeroOrMore>
+ <ref name="Operators.pat"/> <!-- Case Expression -->
+ <ref name="Operators.pat"/> <!-- Case Block -->
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="loop.elem">
+ <element name="loop">
+ <ref name="Documentation.pat"/>
+ <ref name="Operators.pat"/> <!-- Pre-Loop Test -->
+ <ref name="Operators.pat"/> <!-- Loop Body -->
+ <ref name="Operators.pat"/> <!-- Post-Loop Test -->
+ </element>
+ </define>
+
+ <define name="break.elem">
+ <element name="break">
+ <ref name="Documentation.pat"/>
+ </element>
+ </define>
+
+ <define name="continue.elem">
+ <element name="continue">
+ <ref name="Documentation.pat"/>
+ </element>
+ </define>
+
<define name="ret.elem">
<element name="ret">
+ <ref name="Documentation.pat"/>
<ref name="Operators.pat"/>
</element>
</define>
+
</grammar>
Modified: hlvm/trunk/hlvm/Reader/XMLReader.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XMLReader.cpp?rev=38242&r1=38241&r2=38242&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Reader/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XMLReader.cpp Sat Jul 7 19:01:32 2007
@@ -137,6 +137,9 @@
OpClass* parseBinaryOp(xmlNodePtr& cur);
template<class OpClass>
OpClass* parseTernaryOp(xmlNodePtr& cur);
+ template<class OpClass>
+ OpClass* parseMultiOp(xmlNodePtr& cur);
+
private:
};
@@ -564,7 +567,7 @@
cur = cur->next;
return result;
}
- else
+ else if (cur != 0)
hlvmDeadCode("Expecting a value");
return 0;
}
@@ -814,6 +817,21 @@
return ast->AST::new_TernaryOp<OpClass>(oprnd1,oprnd2,oprnd3,loc);
}
+template<class OpClass>
+OpClass*
+XMLReaderImpl::parseMultiOp(xmlNodePtr& cur)
+{
+ Locator* loc = getLocator(cur);
+ OpClass* result = ast->AST::new_MultiOp<OpClass>(loc);
+ xmlNodePtr child = cur->children;
+ Value* operand = getValue(child);
+ while (operand != 0) {
+ operand->setParent(result);
+ operand = getValue(child);
+ }
+ return result;
+}
+
template<> Block*
XMLReaderImpl::parse<Block>(xmlNodePtr& cur)
{
@@ -1020,6 +1038,8 @@
case TKN_flt: C = parseFloat(cur); break;
case TKN_dbl: C = parseDouble(cur); break;
case TKN_text: C = parseText(cur); break;
+ case TKN_false: C = ast->new_ConstantBoolean(false); break;
+ case TKN_true: C = ast->new_ConstantBoolean(true); break;
case TKN_zero: C = parseZero(cur,Ty); break;
default:
hlvmAssert(!"Invalid kind of constant");
@@ -1040,6 +1060,12 @@
{
Operator* op = 0;
switch (tkn) {
+ case TKN_noop: op = parseNilaryOp<NoOperator>(cur); break;
+ case TKN_select: op = parseTernaryOp<SelectOp>(cur); break;
+ case TKN_switch: op = parseMultiOp<SwitchOp>(cur); break;
+ case TKN_loop: op = parseTernaryOp<LoopOp>(cur); break;
+ case TKN_break: op = parseNilaryOp<BreakOp>(cur); break;
+ case TKN_continue: op = parseNilaryOp<ContinueOp>(cur); break;
case TKN_ret: op = parseUnaryOp<ReturnOp>(cur); break;
case TKN_block: op = parse<Block>(cur); break;
case TKN_store: op = parseBinaryOp<StoreOp>(cur); break;
@@ -1075,8 +1101,16 @@
case TKN_dbl:
case TKN_text:
case TKN_zero:
+ case TKN_false:
+ case TKN_true:
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_open:
case TKN_write:
Modified: hlvm/trunk/hlvm/Writer/XMLWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Writer/XMLWriter.cpp?rev=38242&r1=38241&r2=38242&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Writer/XMLWriter.cpp (original)
+++ hlvm/trunk/hlvm/Writer/XMLWriter.cpp Sat Jul 7 19:01:32 2007
@@ -446,6 +446,47 @@
putDoc(av);
}
+template<> void
+XMLWriterImpl::WriterPass::put<NoOperator>(NoOperator* op)
+{
+ startElement("noop");
+}
+
+template<> void
+XMLWriterImpl::WriterPass::put<SelectOp>(SelectOp* op)
+{
+ startElement("select");
+ putDoc(op);
+}
+
+template<> void
+XMLWriterImpl::WriterPass::put<SwitchOp>(SwitchOp* op)
+{
+ startElement("switch");
+ putDoc(op);
+}
+
+template<> void
+XMLWriterImpl::WriterPass::put<LoopOp>(LoopOp* op)
+{
+ startElement("loop");
+ putDoc(op);
+}
+
+template<> void
+XMLWriterImpl::WriterPass::put<BreakOp>(BreakOp* op)
+{
+ startElement("break");
+ putDoc(op);
+}
+
+template<> void
+XMLWriterImpl::WriterPass::put<ContinueOp>(ContinueOp* op)
+{
+ startElement("continue");
+ putDoc(op);
+}
+
template<> void
XMLWriterImpl::WriterPass::put<ReturnOp>(ReturnOp* r)
{
@@ -540,6 +581,12 @@
case ProgramID: put(cast<Program>(n)); break;
case BlockID: put(cast<Block>(n)); break;
case AutoVarOpID: put(cast<AutoVarOp>(n)); break;
+ case NoOperatorID: put(cast<NoOperator>(n)); break;
+ case SelectOpID: put(cast<SelectOp>(n)); break;
+ case SwitchOpID: put(cast<SwitchOp>(n)); break;
+ case LoopOpID: put(cast<LoopOp>(n)); break;
+ case BreakOpID: put(cast<BreakOp>(n)); break;
+ case ContinueOpID: put(cast<ContinueOp>(n)); break;
case ReturnOpID: put(cast<ReturnOp>(n)); break;
case StoreOpID: put(cast<StoreOp>(n)); break;
case LoadOpID: put(cast<LoadOp>(n)); break;
Added: hlvm/trunk/test/xml2xml/break.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/break.hlx?rev=38242&view=auto
==============================================================================
--- hlvm/trunk/test/xml2xml/break.hlx (added)
+++ hlvm/trunk/test/xml2xml/break.hlx Sat Jul 7 19:01:32 2007
@@ -0,0 +1,10 @@
+<?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/return.hlx">
+ <bundle id="return">
+ <program id="return">
+ <block>
+ <break/>
+ </block>
+ </program>
+ </bundle>
+</hlvm>
Added: hlvm/trunk/test/xml2xml/continue.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/continue.hlx?rev=38242&view=auto
==============================================================================
--- hlvm/trunk/test/xml2xml/continue.hlx (added)
+++ hlvm/trunk/test/xml2xml/continue.hlx Sat Jul 7 19:01:32 2007
@@ -0,0 +1,10 @@
+<?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/return.hlx">
+ <bundle id="return">
+ <program id="return">
+ <block>
+ <continue/>
+ </block>
+ </program>
+ </bundle>
+</hlvm>
Added: hlvm/trunk/test/xml2xml/loop.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/loop.hlx?rev=38242&view=auto
==============================================================================
--- hlvm/trunk/test/xml2xml/loop.hlx (added)
+++ hlvm/trunk/test/xml2xml/loop.hlx Sat Jul 7 19:01:32 2007
@@ -0,0 +1,16 @@
+<?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/return.hlx">
+ <bundle id="return">
+ <program id="return">
+ <block>
+ <ret>
+ <loop>
+ <dec>1</dec>
+ <dec>0</dec>
+ <noop/>
+ </loop>
+ </ret>
+ </block>
+ </program>
+ </bundle>
+</hlvm>
Added: hlvm/trunk/test/xml2xml/select.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/select.hlx?rev=38242&view=auto
==============================================================================
--- hlvm/trunk/test/xml2xml/select.hlx (added)
+++ hlvm/trunk/test/xml2xml/select.hlx Sat Jul 7 19:01:32 2007
@@ -0,0 +1,16 @@
+<?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/return.hlx">
+ <bundle id="return">
+ <program id="return">
+ <block>
+ <ret>
+ <select>
+ <dec>0</dec>
+ <dec>42</dec>
+ <dec>21</dec>
+ </select>
+ </ret>
+ </block>
+ </program>
+ </bundle>
+</hlvm>
Added: hlvm/trunk/test/xml2xml/switch.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/switch.hlx?rev=38242&view=auto
==============================================================================
--- hlvm/trunk/test/xml2xml/switch.hlx (added)
+++ hlvm/trunk/test/xml2xml/switch.hlx Sat Jul 7 19:01:32 2007
@@ -0,0 +1,27 @@
+<?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/return.hlx">
+ <bundle id="return">
+ <program id="return">
+ <block>
+ <ret>
+ <switch>
+ <dec>6</dec>
+ <dec>0</dec>
+ <dec>1</dec>
+ <dec>1</dec>
+ <dec>2</dec>
+ <dec>2</dec>
+ <dec>3</dec>
+ <dec>3</dec>
+ <dec>4</dec>
+ <dec>4</dec>
+ <dec>5</dec>
+ <dec>5</dec>
+ <dec>42</dec>
+ <dec>21</dec>
+ </switch>
+ </ret>
+ </block>
+ </program>
+ </bundle>
+</hlvm>
More information about the llvm-commits
mailing list