[llvm-commits] [hlvm] r38247 - in /hlvm/trunk: build/ hlvm/AST/ hlvm/Base/ hlvm/CodeGen/ hlvm/Pass/ hlvm/Reader/ hlvm/Writer/ test/xml2xml/ tools/hlvm-compiler/ tools/hlvm-xml2xml/

Reid Spencer reid at x10sys.com
Sat Jul 7 17:01:35 PDT 2007


Author: reid
Date: Sat Jul  7 19:01:35 2007
New Revision: 38247

URL: http://llvm.org/viewvc/llvm-project?rev=38247&view=rev
Log:
General improvements in AST construction centering around ensuring all
operators have a type. Some implementation of the validator. CodeGen
fixes for arithmetic operators. 

Modified:
    hlvm/trunk/build/check.py
    hlvm/trunk/hlvm/AST/AST.cpp
    hlvm/trunk/hlvm/AST/AST.h
    hlvm/trunk/hlvm/AST/Block.h
    hlvm/trunk/hlvm/AST/ContainerType.cpp
    hlvm/trunk/hlvm/AST/ContainerType.h
    hlvm/trunk/hlvm/AST/LinkageItem.h
    hlvm/trunk/hlvm/AST/Locator.cpp
    hlvm/trunk/hlvm/AST/Locator.h
    hlvm/trunk/hlvm/AST/MemoryOps.h
    hlvm/trunk/hlvm/AST/Operator.cpp
    hlvm/trunk/hlvm/AST/Operator.h
    hlvm/trunk/hlvm/Base/Memory.cpp
    hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
    hlvm/trunk/hlvm/Pass/Pass.cpp
    hlvm/trunk/hlvm/Pass/Pass.h
    hlvm/trunk/hlvm/Pass/Validate.cpp
    hlvm/trunk/hlvm/Reader/HLVM.rng
    hlvm/trunk/hlvm/Reader/XMLReader.cpp
    hlvm/trunk/hlvm/Writer/XMLWriter.cpp
    hlvm/trunk/test/xml2xml/arithmetic.hlx
    hlvm/trunk/test/xml2xml/booleanops.hlx
    hlvm/trunk/test/xml2xml/helloworld.hlx
    hlvm/trunk/tools/hlvm-compiler/hlvm-compiler.cpp
    hlvm/trunk/tools/hlvm-xml2xml/hlvm-xml2xml.cpp

Modified: hlvm/trunk/build/check.py
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/build/check.py?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/build/check.py (original)
+++ hlvm/trunk/build/check.py Sat Jul  7 19:01:35 2007
@@ -69,9 +69,9 @@
   sitexpBuilder = env.Builder(action=sitexpAction,suffix='exp')
   env.Append(BUILDERS = {'Check':checkBuilder,'SiteExp':sitexpBuilder})
   env.SiteExp('#test/site.exp',[])
+  env.SetOption('num_jobs',1)
   for dir in dirs:
     env.Check(['#test/' + dir + '.sum','#test/' + dir + '.log'],
               getTestCases(dir,env)+['#test/site.exp'])
     env.Alias('check','#test/' + dir + '.log')
   return 1
-

Modified: hlvm/trunk/hlvm/AST/AST.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/AST.cpp?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul  7 19:01:35 2007
@@ -210,6 +210,24 @@
   return ast->ProgramTypeSingleton;
 }
 
+PointerType* 
+AST::getPointerTo(const Type* Ty)
+{
+  hlvmAssert(Ty != 0);
+  ASTImpl* ast = const_cast<ASTImpl*>(static_cast<const ASTImpl*>(this));
+  std::string ptr_name = Ty->getName() + "*";
+  Node* n = ast->types.lookup(ptr_name);
+  if (n && llvm::isa<PointerType>(n))
+    return llvm::cast<PointerType>(n);
+
+  // Okay, type doesn't exist already, create it a new
+  PointerType* PT = new PointerType();
+  PT->setElementType(Ty);
+  PT->setName(ptr_name);
+  ast->types.insert(ptr_name,Ty);
+  return PT;
+}
+
 Locator*
 AST::new_Locator(const URI* uri, uint32_t line, uint32_t col, uint32_t line2,
     uint32_t col2)
@@ -229,6 +247,14 @@
   return 0;
 }
 
+Documentation* 
+AST::new_Documentation(const Locator* loc)
+{
+  Documentation* result = new Documentation();
+  result->setLocator(loc);
+  return result;
+}
+
 Bundle*
 AST::new_Bundle(const std::string& id, const Locator* loc)
 {
@@ -323,6 +349,36 @@
   return result;
 }
 
+BufferType* 
+AST::new_BufferType(const std::string& id, const Locator* loc)
+{
+  BufferType* result = new BufferType();
+  result->setLocator(loc);
+  result->setName(id);
+  static_cast<ASTImpl*>(this)->addType(result);
+  return result;
+}
+
+TextType* 
+AST::new_TextType( const std::string& id, const Locator* loc)
+{
+  TextType* result = new TextType();
+  result->setLocator(loc);
+  result->setName(id);
+  static_cast<ASTImpl*>(this)->addType(result);
+  return result;
+}
+
+StreamType* 
+AST::new_StreamType(const std::string& id,  const Locator* loc)
+{
+  StreamType* result = new StreamType();
+  result->setLocator(loc);
+  result->setName(id);
+  static_cast<ASTImpl*>(this)->addType(result);
+  return result;
+}
+
 CharacterType* 
 AST::new_CharacterType(const std::string& id, const Locator* loc)
 {
@@ -507,6 +563,16 @@
   return result;
 }
 
+Argument* 
+AST::new_Argument(const std::string& id, Type* ty , const Locator* loc)
+{
+  Argument* result = new Argument();
+  result->setLocator(loc);
+  result->setName(id);
+  result->setElementType(ty);
+  return result;
+}
+
 Function*
 AST::new_Function(const std::string& id, const Locator* loc)
 {
@@ -539,206 +605,425 @@
   return result;
 }
 
-template<class OpClass> 
-OpClass* 
+AutoVarOp*
+AST::new_AutoVarOp(
+    const std::string& name, const Type* Ty, Constant* op1,const Locator* loc)
+{
+  hlvmAssert(Ty != 0 && "AutoVarOp must have a Type!");
+  AutoVarOp* result = new AutoVarOp();
+  result->setType(Ty);
+  result->setLocator(loc);
+  result->setInitializer(op1);
+  result->setName(name);
+  return result;
+}
+
+ReferenceOp* 
+AST::new_ReferenceOp(const Value* V, const Locator*loc)
+{
+  hlvmAssert(V != 0 && "ReferenceOp must have a Value to reference");
+  hlvmAssert(llvm::isa<Variable>(V) || llvm::isa<AutoVarOp>(V));
+  const Type* elemType = V->getType();
+  PointerType* PT = getPointerTo(elemType);
+  ReferenceOp* result = new ReferenceOp();
+  result->setLocator(loc);
+  result->setReferent(V);
+  result->setType(PT);
+  return result;
+}
+
+template<class OpClass> OpClass* 
 AST::new_NilaryOp(
+  const Type* Ty,    ///< Result type of the operator
   const Locator* loc ///< The source locator
 )
 {
+  hlvmAssert(Ty != 0 && "Need a type to instantiate a NilaryOp");
   OpClass* result = new OpClass();
   result->setLocator(loc);
+  result->setType(Ty);
   return result;
 }
 
+template<class OpClass> OpClass* 
+AST::new_NilaryOp(
+  const Locator* loc ///< The source locator
+)
+{
+  return new_NilaryOp<OpClass>(getPrimitiveType(VoidTypeID),loc);
+}
+
 /// Provide a template function for creating a unary operator
-template<class OpClass>
-OpClass* 
+template<class OpClass> OpClass* 
 AST::new_UnaryOp(
+  const Type* Ty,    ///< Result type of the operator
   Value* oprnd1,     ///< The first operand
   const Locator* loc ///< The source locator
 )
 {
+  hlvmAssert(Ty != 0 && "Need a type to instantiate a UnaryOp");
+  hlvmAssert(oprnd1 != 0 && "Invalid Operand for UnaryOp");
   OpClass* result = new OpClass();
   result->setLocator(loc);
+  result->setType(Ty);
   result->setOperand(0,oprnd1);
   return result;
 }
 
+template<class OpClass> OpClass* 
+AST::new_UnaryOp(
+  Value* oprnd1,     ///< The first operand
+  const Locator* loc ///< The source locator
+)
+{
+  return new_UnaryOp<OpClass>(oprnd1->getType(),oprnd1,loc);
+}
+
 /// Provide a template function for creating a binary operator
-template<class OpClass>
-OpClass* 
+template<class OpClass> OpClass* 
 AST::new_BinaryOp(
+  const Type* Ty,    ///< Result type of the operator
   Value* oprnd1,     ///< The first operand
   Value* oprnd2,     ///< The second operand
   const Locator* loc ///< The source locator
 )
 {
+  hlvmAssert(Ty != 0 && "Need a type to instantiate a BinaryOp");
+  hlvmAssert(oprnd1 != 0 && "Invalid Operand for BinaryOp");
+  hlvmAssert(oprnd2 != 0 && "Invalid Operand for BinUnaryOp");
   OpClass* result = new OpClass();
   result->setLocator(loc);
+  result->setType(Ty);
   result->setOperand(0,oprnd1);
   result->setOperand(1,oprnd2);
   return result;
 }
 
+/// Provide a template function for creating a binary operator
+template<class OpClass> OpClass* 
+AST::new_BinaryOp(
+  Value* oprnd1,     ///< The first operand
+  Value* oprnd2,     ///< The second operand
+  const Locator* loc ///< The source locator
+)
+{
+  return new_BinaryOp<OpClass>(oprnd1->getType(),oprnd1,oprnd2,loc);
+}
+
 /// Provide a template function for creating a ternary operator
-template<class OpClass>
-OpClass* 
+template<class OpClass> OpClass* 
 AST::new_TernaryOp(
+  const Type* Ty,    ///< Result type of the operator
   Value* oprnd1,     ///< The first operand
   Value* oprnd2,     ///< The second operand
   Value* oprnd3,     ///< The third operand
   const Locator* loc ///< The source locator
 )
 {
+  hlvmAssert(Ty != 0 && "Need a type to instantiate a TernaryOp");
+  hlvmAssert(oprnd1 != 0 && "Invalid Operand for TernaryOp");
+  hlvmAssert(oprnd2 != 0 && "Invalid Operand for TernUnaryOp");
+  hlvmAssert(oprnd3 != 0 && "Invalid Operand for TernUnaryOp");
   OpClass* result = new OpClass();
   result->setLocator(loc);
+  result->setType(Ty);
   result->setOperand(0,oprnd1);
   result->setOperand(1,oprnd2);
   result->setOperand(2,oprnd3);
   return result;
 }
 
-template<class OpClass>
-OpClass* 
-AST::new_MultiOp(const Locator* loc) 
+template<class OpClass> OpClass* 
+AST::new_TernaryOp(
+  Value* oprnd1,     ///< The first operand
+  Value* oprnd2,     ///< The second operand
+  Value* oprnd3,     ///< The third operand
+  const Locator* loc ///< The source locator
+)
+{
+  return new_TernaryOp<OpClass>(oprnd1->getType(),oprnd1,oprnd2,oprnd3,loc);
+}
+
+template<class OpClass> OpClass* 
+AST::new_MultiOp(
+  const Type* Ty,         ///< Result type of the operator
+  const std::vector<Value*>& oprnds,
+  const Locator* loc
+) 
 {
+  hlvmAssert(Ty != 0 && "Need a type to instantiate a MultiOp");
   OpClass* result = new OpClass();
   result->setLocator(loc);
+  result->setType(Ty);
+  result->addOperands(oprnds);
   return result;
 }
 
+template<class OpClass> OpClass* 
+AST::new_MultiOp(
+  const std::vector<Value*>& oprnds,
+  const Locator* loc
+)
+{
+  return new_MultiOp<OpClass>(oprnds[0]->getType(),oprnds,loc);
+}
+
 // Arithmetic Operators
 template NegateOp*
+AST::new_UnaryOp<NegateOp>(
+    const Type* Ty, Value* op1, const Locator* loc);
+template NegateOp*
 AST::new_UnaryOp<NegateOp>(Value* op1, const Locator* loc);
+
+template ComplementOp*
+AST::new_UnaryOp<ComplementOp>(
+    const Type* Ty, Value* op1, const Locator* loc);
 template ComplementOp*
 AST::new_UnaryOp<ComplementOp>(Value* op1, const Locator* loc);
+
+template PreIncrOp*
+AST::new_UnaryOp<PreIncrOp>(
+    const Type* Ty, Value* op1, const Locator* loc);
 template PreIncrOp*
 AST::new_UnaryOp<PreIncrOp>(Value* op1, const Locator* loc);
+
+template PreDecrOp*
+AST::new_UnaryOp<PreDecrOp>(
+    const Type* Ty, Value* op1, const Locator* loc);
 template PreDecrOp*
 AST::new_UnaryOp<PreDecrOp>(Value* op1, const Locator* loc);
+
+template PostIncrOp*
+AST::new_UnaryOp<PostIncrOp>(
+    const Type* Ty, Value* op1, const Locator* loc);
 template PostIncrOp*
 AST::new_UnaryOp<PostIncrOp>(Value* op1, const Locator* loc);
+
+template PostDecrOp*
+AST::new_UnaryOp<PostDecrOp>(
+    const Type* Ty, Value* op1, const Locator* loc);
 template PostDecrOp*
 AST::new_UnaryOp<PostDecrOp>(Value* op1, const Locator* loc);
+
+template AddOp*
+AST::new_BinaryOp<AddOp>(
+    const Type* Ty, Value* op1, Value* op2, const Locator* loc);
 template AddOp*
 AST::new_BinaryOp<AddOp>(Value* op1, Value* op2, const Locator* loc);
+
+template SubtractOp*
+AST::new_BinaryOp<SubtractOp>(
+    const Type* Ty, Value* op1, Value* op2, const Locator* loc);
 template SubtractOp*
 AST::new_BinaryOp<SubtractOp>(Value* op1, Value* op2, const Locator* loc);
+
+template MultiplyOp*
+AST::new_BinaryOp<MultiplyOp>(
+    const Type* Ty, Value* op1, Value* op2, const Locator* loc);
 template MultiplyOp*
 AST::new_BinaryOp<MultiplyOp>(Value* op1, Value* op2, const Locator* loc);
+
+template DivideOp*
+AST::new_BinaryOp<DivideOp>(
+    const Type* Ty, Value* op1, Value* op2, const Locator* loc);
 template DivideOp*
 AST::new_BinaryOp<DivideOp>(Value* op1, Value* op2, const Locator* loc);
+
+template ModuloOp*
+AST::new_BinaryOp<ModuloOp>(
+    const Type* Ty, Value* op1, Value* op2, const Locator* loc);
 template ModuloOp*
 AST::new_BinaryOp<ModuloOp>(Value* op1, Value* op2, const Locator* loc);
+
+template BAndOp*
+AST::new_BinaryOp<BAndOp>(
+    const Type* Ty, Value* op1, Value* op2, const Locator* loc);
 template BAndOp*
 AST::new_BinaryOp<BAndOp>(Value* op1, Value* op2, const Locator* loc);
+
+template BOrOp*
+AST::new_BinaryOp<BOrOp>(
+    const Type* Ty, Value* op1, Value* op2, const Locator* loc);
 template BOrOp*
 AST::new_BinaryOp<BOrOp>(Value* op1, Value* op2, const Locator* loc);
+
+template BXorOp*
+AST::new_BinaryOp<BXorOp>(
+    const Type* Ty, Value* op1, Value* op2, const Locator* loc);
 template BXorOp*
 AST::new_BinaryOp<BXorOp>(Value* op1, Value* op2, const Locator* loc);
+
+template BNorOp*
+AST::new_BinaryOp<BNorOp>(
+    const Type* Ty, Value* op1, Value* op2, const Locator* loc);
 template BNorOp*
 AST::new_BinaryOp<BNorOp>(Value* op1, Value* op2, const Locator* loc);
 
 // Boolean Operators
 template NotOp*
+AST::new_UnaryOp<NotOp>(const Type* Ty, Value* op1, const Locator* loc);
+template NotOp*
 AST::new_UnaryOp<NotOp>(Value* op1, const Locator* loc);
+
+template AndOp*
+AST::new_BinaryOp<AndOp>(
+    const Type* Ty, Value* op1, Value* op2, const Locator* loc);
 template AndOp*
 AST::new_BinaryOp<AndOp>(Value* op1, Value* op2, const Locator* loc);
+
+template OrOp*
+AST::new_BinaryOp<OrOp>(
+    const Type* Ty, Value* op1, Value* op2, const Locator* loc);
 template OrOp*
 AST::new_BinaryOp<OrOp>(Value* op1, Value* op2, const Locator* loc);
+
+template NorOp*
+AST::new_BinaryOp<NorOp>(
+    const Type* Ty, Value* op1, Value* op2, const Locator* loc);
 template NorOp*
 AST::new_BinaryOp<NorOp>(Value* op1, Value* op2, const Locator* loc);
+
+template XorOp*
+AST::new_BinaryOp<XorOp>(
+    const Type* Ty, Value* op1, Value* op2, const Locator* loc);
 template XorOp*
 AST::new_BinaryOp<XorOp>(Value* op1, Value* op2, const Locator* loc);
+
+template LessThanOp*
+AST::new_BinaryOp<LessThanOp>(
+    const Type* Ty, Value* op1, Value* op2, const Locator* loc);
 template LessThanOp*
 AST::new_BinaryOp<LessThanOp>(Value* op1, Value* op2, const Locator* loc);
+
+template GreaterThanOp* 
+AST::new_BinaryOp<GreaterThanOp>(
+    const Type* Ty, Value* op1, Value* op2,const Locator* loc);
 template GreaterThanOp* 
 AST::new_BinaryOp<GreaterThanOp>(Value* op1, Value* op2,const Locator* loc);
+
+template LessEqualOp* 
+AST::new_BinaryOp<LessEqualOp>(
+    const Type* Ty, Value* op1, Value* op2, const Locator* loc);
 template LessEqualOp* 
 AST::new_BinaryOp<LessEqualOp>(Value* op1, Value* op2, const Locator* loc);
+
+template GreaterEqualOp* 
+AST::new_BinaryOp<GreaterEqualOp>(
+    const Type* Ty, Value* op1,Value* op2, const Locator* loc);
 template GreaterEqualOp* 
 AST::new_BinaryOp<GreaterEqualOp>(Value* op1,Value* op2, const Locator* loc);
+
+template EqualityOp*
+AST::new_BinaryOp<EqualityOp>(
+    const Type* Ty, Value* op1, Value* op2, const Locator* loc);
 template EqualityOp*
 AST::new_BinaryOp<EqualityOp>(Value* op1, Value* op2, const Locator* loc);
+
+template InequalityOp*
+AST::new_BinaryOp<InequalityOp>(
+    const Type* Ty, Value* op1,Value* op2,const Locator* loc);
 template InequalityOp*
 AST::new_BinaryOp<InequalityOp>(Value* op1,Value* op2,const Locator* loc);
 
 // Control Flow Operators
 template NoOperator* 
+AST::new_NilaryOp<NoOperator>(const Type* Ty, const Locator*loc);
+template NoOperator* 
 AST::new_NilaryOp<NoOperator>(const Locator*loc);
+
 template SelectOp*
-AST::new_TernaryOp<SelectOp>(Value*op1,Value*op2,Value*op3,const Locator* loc);
+AST::new_TernaryOp<SelectOp>(
+    const Type* Ty, Value*op1,Value*op2,Value*op3,const Locator* loc);
+template<> SelectOp*
+AST::new_TernaryOp<SelectOp>(Value*op1,Value*op2,Value*op3,const Locator* loc)
+{
+  return new_TernaryOp<SelectOp>(op2->getType(),op1,op2,op3,loc);
+}
+
 template LoopOp*
-AST::new_TernaryOp<LoopOp>(Value*op1,Value*op2,Value*op3,const Locator* loc);
+AST::new_TernaryOp<LoopOp>(const Type* Ty, Value*op1,Value*op2,Value*op3,const Locator* loc);
+
+template<> LoopOp*
+AST::new_TernaryOp<LoopOp>(Value*op1,Value*op2,Value*op3,const Locator* loc)
+{
+  const Type* Ty = op2->getType();
+  if (llvm::isa<Block>(Ty))
+    Ty = llvm::cast<Block>(op2)->getResultType();
+  return new_TernaryOp<LoopOp>(Ty,op1,op2,op3,loc);
+}
+
 template SwitchOp*
-AST::new_MultiOp<SwitchOp>(const Locator* loc);
+AST::new_MultiOp<SwitchOp>(
+    const Type* Ty, const std::vector<Value*>& ops, const Locator* loc);
+template<> SwitchOp*
+AST::new_MultiOp<SwitchOp>(const std::vector<Value*>& ops, const Locator* loc)
+{
+  hlvmAssert(ops.size() >= 2 && "Too few operands for SwitchOp");
+  const Type* Ty = ops[1]->getType();
+  if (llvm::isa<Block>(Ty))
+    Ty = llvm::cast<Block>(ops[1])->getResultType();
+  return new_MultiOp<SwitchOp>(Ty, ops, loc);
+}
+
+template BreakOp* 
+AST::new_NilaryOp<BreakOp>(const Type*Ty, const Locator*loc);
 template BreakOp* 
 AST::new_NilaryOp<BreakOp>(const Locator*loc);
+
+template ContinueOp* 
+AST::new_NilaryOp<ContinueOp>(const Type* Ty, const Locator*loc);
 template ContinueOp* 
 AST::new_NilaryOp<ContinueOp>(const Locator*loc);
+
+template ReturnOp* 
+AST::new_UnaryOp<ReturnOp>(const Type*Ty, Value*op1,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);
-template LoadOp*   
-AST::new_UnaryOp<LoadOp>(Value*op1,const Locator*loc);
-template AutoVarOp*
-AST::new_UnaryOp<AutoVarOp>(Value*op1,const Locator* loc);
-template ReferenceOp* 
-AST::new_NilaryOp<ReferenceOp>(const Locator*loc);
-// Input/Output Operators
-template OpenOp* 
-AST::new_UnaryOp<OpenOp>(Value*op1,const Locator*loc);
-template WriteOp* 
-AST::new_BinaryOp<WriteOp>(Value*op1,Value*op2,const Locator*loc);
-template CloseOp* 
-AST::new_UnaryOp<CloseOp>(Value*op1,const Locator*loc);
-
-Documentation* 
-AST::new_Documentation(const Locator* loc)
+AST::new_BinaryOp<StoreOp>(const Type*, Value*op1,Value*op2,const Locator*loc);
+template<> StoreOp*  
+AST::new_BinaryOp<StoreOp>(Value*op1,Value*op2,const Locator*loc)
 {
-  Documentation* result = new Documentation();
-  result->setLocator(loc);
-  return result;
+  return new_BinaryOp<StoreOp>(getPrimitiveType(VoidTypeID),op1,op2,loc);
 }
 
-Argument* 
-AST::new_Argument(const std::string& id, Type* ty , const Locator* loc)
-{
-  Argument* result = new Argument();
-  result->setLocator(loc);
-  result->setName(id);
-  result->setElementType(ty);
-  return result;
+template LoadOp*   
+AST::new_UnaryOp<LoadOp>(const Type* Ty, Value*op1,const Locator*loc);
+template<> LoadOp*   
+AST::new_UnaryOp<LoadOp>(Value*op1,const Locator*loc)
+{
+  hlvmAssert(llvm::isa<PointerType>(op1->getType()) && 
+      "LoadOp Requires PointerType operand");
+  const Type* Ty = llvm::cast<PointerType>(op1->getType())->getElementType();
+  return new_UnaryOp<LoadOp>(Ty, op1, loc);
 }
 
-BufferType* 
-AST::new_BufferType( const std::string& id, const Locator* loc)
+// Input/Output Operators
+template OpenOp* 
+AST::new_UnaryOp<OpenOp>(const Type* Ty, Value*op1,const Locator*loc);
+template<> OpenOp* 
+AST::new_UnaryOp<OpenOp>(Value*op1,const Locator*loc)
 {
-  BufferType* result = new BufferType();
-  result->setName(id);
-  result->setLocator(loc);
-  return result;
+  return new_UnaryOp<OpenOp>(getPrimitiveType(StreamTypeID),op1,loc);
 }
 
-StreamType* 
-AST::new_StreamType( const std::string& id, const Locator* loc)
+template WriteOp* 
+AST::new_BinaryOp<WriteOp>(
+  const Type* Ty, Value*op1,Value*op2, const Locator*loc);
+template<> WriteOp* 
+AST::new_BinaryOp<WriteOp>(Value*op1,Value*op2,const Locator*loc)
 {
-  StreamType* result = new StreamType();
-  result->setName(id);
-  result->setLocator(loc);
-  return result;
+  return new_BinaryOp<WriteOp>(getPrimitiveType(UInt64TypeID),op1,op2,loc);
 }
 
-TextType*
-AST::new_TextType(const std::string& id, const Locator* loc)
+template CloseOp* 
+AST::new_UnaryOp<CloseOp>(const Type* Ty, Value*op1,const Locator*loc);
+template<> CloseOp* 
+AST::new_UnaryOp<CloseOp>(Value*op1,const Locator*loc)
 {
-  TextType* result = new TextType();
-  result->setName(id);
-  result->setLocator(loc);
-  return result;
+  return new_UnaryOp<CloseOp>(getPrimitiveType(VoidTypeID),op1,loc);
 }
 
 Type* 
@@ -870,16 +1155,19 @@
     case TextTypeID:
       if (!ast->TextTypeSingleton) {
         ast->TextTypeSingleton = new TextType();
+        ast->TextTypeSingleton->setName("text");
       }
       return ast->TextTypeSingleton;
     case StreamTypeID:
       if (!ast->StreamTypeSingleton) {
         ast->StreamTypeSingleton = new StreamType();
+        ast->StreamTypeSingleton->setName("stream");
       }
       return ast->StreamTypeSingleton;
     case BufferTypeID:
       if (!ast->BufferTypeSingleton) {
         ast->BufferTypeSingleton = new BufferType();
+        ast->BufferTypeSingleton->setName("buffer");
       }
       return ast->BufferTypeSingleton;
     default:

Modified: hlvm/trunk/hlvm/AST/AST.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/AST.h?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.h (original)
+++ hlvm/trunk/hlvm/AST/AST.h Sat Jul  7 19:01:35 2007
@@ -58,12 +58,8 @@
 class ConstantText;
 class ConstantZero;
 class Pool;
-class ReturnOp;
-class StoreOp;
-class LoadOp;
-class OpenOp;
-class CloseOp;
-class WriteOp;
+class AutoVarOp;
+class ReferenceOp;
 
 /// This class is used to hold or contain an Abstract Syntax Tree. It forms the
 /// root node of a multi-way tree of other nodes. As such, its parent node is
@@ -112,12 +108,20 @@
   /// @name Lookup
   /// @{
   public:
+    /// Get one of the primitive types directly by its identifier
+    Type* getPrimitiveType(NodeIDs kind);
+
+    /// Resolve a type name into a Type and allow for forward referencing.
     Type* resolveType(const std::string& name);
 
+    /// Get a standard pointer type to the element type Ty.
+    PointerType* getPointerTo(const Type* Ty);
+
   /// @}
   /// @name Iterators
   /// @{
   public:
+    /// Bundle Iteration
     iterator           begin()       { return bundles.begin(); }
     const_iterator     begin() const { return bundles.begin(); }
     iterator           end  ()       { return bundles.end(); }
@@ -133,9 +137,6 @@
   /// @name Factories
   /// @{
   public:
-    /// Get one of the primitive types directly by its identifier
-    Type* getPrimitiveType(NodeIDs kind);
-
     /// Create a new Locator object. Locators indicate where in the source
     /// a particular AST node is located. Locators can be very general (just
     /// the URI) or very specific (the exact range of bytes in the file). The
@@ -458,6 +459,21 @@
       const Locator* loc = 0 ///< 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.
+    AutoVarOp* new_AutoVarOp(
+      const std::string& name, ///< Name of the autovar in its scope
+      const Type* Ty,          ///< Type of the autovar
+      Constant* op1,           ///< Initializer for the autovar
+      const Locator* loc       ///< The source locator
+    );
+
+    ReferenceOp* new_ReferenceOp(
+      const Value* V,       ///< The value being referred to
+      const Locator*loc = 0 ///< The source locator
+    );
+
     /// Provide a template function for creating a nilary operator
     template<class OpClass>
     OpClass* new_NilaryOp(
@@ -488,46 +504,56 @@
       const Locator* loc = 0 ///< The source locator
     );
 
+    /// Provide a template function for creating a multi-operand operator
     template<class OpClass>
     OpClass* new_MultiOp(
-      const Locator* loc = 0 ///< The source locator
+      const std::vector<Value*>& o, ///< The list of operands
+      const Locator* loc = 0
     );
-
-    /// 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(
-      Value* val,            ///< The value to return
-      const Locator* loc = 0 ///< The source locator
-    );
-    /// Create a new StoreOp node.
-    StoreOp* new_StoreOp(
-      Value* var,            ///< The variable whose value is assigned
-      Value* val,            ///< The value to assign to the variable
+  protected:
+    /// Provide a template function for creating a nilary operator
+    template<class OpClass>
+    OpClass* new_NilaryOp(
+      const Type* Ty,        ///< Result type of the operator
       const Locator* loc = 0 ///< The source locator
     );
-    /// Create a new LoadOp node.
-    LoadOp* new_LoadOp(
-      Value* var,            ///< The variable from which the value is loaded
+
+    /// Provide a template function for creating a unary operator
+    template<class OpClass>
+    OpClass* new_UnaryOp(
+      const Type* Ty,        ///< Result type of the operator
+      Value* oprnd1,         ///< The first operand
       const Locator* loc = 0 ///< The source locator
     );
-    /// Create a new OpenOp node.
-    OpenOp* new_OpenOp(
-      Value* uri,            ///< The URI saying what to open and how
+
+    /// Provide a template function for creating a binary operator
+    template<class OpClass>
+    OpClass* new_BinaryOp(
+      const Type* Ty,        ///< Result type of the operator
+      Value* oprnd1,         ///< The first operand
+      Value* oprnd2,         ///< The second operand
       const Locator* loc = 0 ///< The source locator
     );
-    /// Create a new WriteOp node.
-    WriteOp* new_WriteOp(
-      Value* strm,           ///< The stream to write
-      Value* buffer,         ///< The buffer that should be written
-      Value* len,            ///< The length of the buffer
+
+    /// Provide a template function for creating a ternary operator
+    template<class OpClass>
+    OpClass* new_TernaryOp(
+      const Type* Ty,        ///< Result type of the operator
+      Value* oprnd1,         ///< The first operand
+      Value* oprnd2,         ///< The second operand
+      Value* oprnd3,         ///< The third operand
       const Locator* loc = 0 ///< The source locator
     );
-    /// Create a new CloseOp node.
-    CloseOp* new_CloseOp(
-      const Value* strm,     ///< The stream to close
-      const Locator* loc = 0 ///< The source locator
+
+    /// Provide a template function for creating a multi-operand operator
+    template<class OpClass>
+    OpClass* new_MultiOp(
+      const Type* Ty,         ///< Result type of the operator
+      const std::vector<Value*>& o, ///< The list of operands
+      const Locator* loc = 0
     );
 
+
   /// @}
   /// @name Data
   /// @{

Modified: hlvm/trunk/hlvm/AST/Block.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Block.h?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Block.h (original)
+++ hlvm/trunk/hlvm/AST/Block.h Sat Jul  7 19:01:35 2007
@@ -59,6 +59,7 @@
   public:
     const std::string& getLabel() const { return label; }
     AutoVarOp*   getAutoVar(const std::string& name) const; 
+    const Type* getResultType() { return this->back()->getType(); }
     static inline bool classof(const Block*) { return true; }
     static inline bool classof(const Node* N) { return N->is(BlockID); }
 

Modified: hlvm/trunk/hlvm/AST/ContainerType.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/ContainerType.cpp?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.cpp (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.cpp Sat Jul  7 19:01:35 2007
@@ -51,7 +51,7 @@
 {
   hlvmAssert(isa<Type>(n) && "Can't insert those here");
   if (type)
-    type->setParent(0);
+    const_cast<Type*>(type)->setParent(0);
   type = cast<Type>(n);
 }
 

Modified: hlvm/trunk/hlvm/AST/ContainerType.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/ContainerType.h?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.h (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.h Sat Jul  7 19:01:35 2007
@@ -53,7 +53,7 @@
   /// @name Accessors
   /// @{
   public:
-    Type* getElementType() const { return type; }
+    const Type* getElementType() const { return type; }
     virtual const char* getPrimitiveName() const; // asserting override
     /// Methods to support type inquiry via isa, cast, dyn_cast
     static inline bool classof(const UniformContainerType*) { return true; }
@@ -65,7 +65,7 @@
   /// @name Mutators
   /// @{
   public:
-    void setElementType(Type* t) { type = t; }
+    void setElementType(const Type* t) { type = t; }
 
   protected:
     virtual void insertChild(Node* n);
@@ -75,7 +75,7 @@
   /// @name Data
   /// @{
   protected:
-    Type* type; ///< The contained types
+    const Type* type; ///< The contained types
   /// @}
 };
 

Modified: hlvm/trunk/hlvm/AST/LinkageItem.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/LinkageItem.h?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/LinkageItem.h (original)
+++ hlvm/trunk/hlvm/AST/LinkageItem.h Sat Jul  7 19:01:35 2007
@@ -74,8 +74,9 @@
   /// @name Accessors
   /// @{
   public:
-    inline const std::string& getName() { return name; }
-    inline LinkageKinds getLinkageKind() { return LinkageKinds(flags & 0x0007); }
+    inline const std::string& getName() const { return name; }
+    inline LinkageKinds getLinkageKind() const { 
+      return LinkageKinds(flags & 0x0007); }
     static inline bool classof(const LinkageItem*) { return true; }
     static inline bool classof(const Node* N) { return N->isLinkageItem(); }
 

Modified: hlvm/trunk/hlvm/AST/Locator.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Locator.cpp?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Locator.cpp (original)
+++ hlvm/trunk/hlvm/AST/Locator.cpp Sat Jul  7 19:01:35 2007
@@ -51,16 +51,16 @@
 }
 
 void 
-URILocator::getReference(std::string& ref) const
+URILocator::getLocation(std::string& ref) const
 {
   hlvmAssert(uri != 0);
   ref = uri->as_string();
 }
 
 void 
-LineLocator::getReference(std::string& ref) const
+LineLocator::getLocation(std::string& ref) const
 {
-  URILocator::getReference(ref);
+  URILocator::getLocation(ref);
   ref += ":" + llvm::utostr(line);
 }
 
@@ -75,9 +75,9 @@
   return false;
 }
 void
-LineColumnLocator::getReference(std::string& ref) const
+LineColumnLocator::getLocation(std::string& ref) const
 {
-  LineLocator::getReference(ref);
+  LineLocator::getLocation(ref);
   ref += ":" + llvm::utostr(col);
 }
 
@@ -93,9 +93,9 @@
 }
 
 void
-RangeLocator::getReference(std::string& ref) const
+RangeLocator::getLocation(std::string& ref) const
 {
-  URILocator::getReference(ref);
+  URILocator::getLocation(ref);
   ref += "(" + llvm::utostr(line) + ":" + llvm::utostr(col) + "," 
              + llvm::utostr(line2) + ":" + llvm::utostr(col2) + ")"; 
 }

Modified: hlvm/trunk/hlvm/AST/Locator.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Locator.h?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Locator.h (original)
+++ hlvm/trunk/hlvm/AST/Locator.h Sat Jul  7 19:01:35 2007
@@ -56,7 +56,7 @@
   /// @name Accessors
   /// @{
   public:
-    virtual void getReference(std::string& ref) const = 0;
+    virtual void getLocation(std::string& ref) const = 0;
     virtual bool equals(const Locator& that) const = 0;
     bool operator==(const Locator& that) { return this->equals(that); }
     unsigned short id() const { return SubclassID; }
@@ -83,7 +83,7 @@
   /// @name Accessors
   /// @{
   public:
-    virtual void getReference(std::string& ref) const;
+    virtual void getLocation(std::string& ref) const;
     virtual bool equals(const Locator& that) const;
 
   /// @}
@@ -112,7 +112,7 @@
   /// @name Accessors
   /// @{
   public:
-    virtual void getReference(std::string& ref) const;
+    virtual void getLocation(std::string& ref) const;
     virtual bool equals(const Locator& that) const;
 
   /// @}
@@ -139,7 +139,7 @@
   /// @name Accessors
   /// @{
   public:
-    virtual void getReference(std::string& ref) const;
+    virtual void getLocation(std::string& ref) const;
     virtual bool equals(const Locator& that) const;
 
   /// @}
@@ -169,7 +169,7 @@
   /// @name Accessors
   /// @{
   public:
-    virtual void getReference(std::string& ref) const;
+    virtual void getLocation(std::string& ref) const;
     virtual bool equals(const Locator& that) const;
 
   /// @}

Modified: hlvm/trunk/hlvm/AST/MemoryOps.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/MemoryOps.h?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/MemoryOps.h (original)
+++ hlvm/trunk/hlvm/AST/MemoryOps.h Sat Jul  7 19:01:35 2007
@@ -193,7 +193,7 @@
   /// @name Accessors
   /// @{
   public:
-    const std::string& getName() { return name; }
+    const std::string& getName() const { return name; }
     Constant* getInitializer() { return static_cast<Constant*>(getOperand());}
     static inline bool classof(const AutoVarOp*) { return true; }
     static inline bool classof(const Node* N) { return N->is(AutoVarOpID); }
@@ -237,7 +237,7 @@
   /// @name Accessors
   /// @{
   public:
-    Value* getReferent() const { return referent; }
+    const Value* getReferent() const { return referent; }
     static inline bool classof(const ReferenceOp*) { return true; }
     static inline bool classof(const Node* N) { return N->is(ReferenceOpID); }
 
@@ -245,22 +245,22 @@
   /// @name Mutators
   /// @{
   public:
-    void setReferent(Value* ref) { referent = ref; }
+    void setReferent(const Value* ref) { referent = ref; }
 
   /// @}
   /// @name Data
   /// @{
   protected:
-    Value* referent;
+    const Value* referent;
   /// @}
   friend class AST;
 };
 
 /// This class provides an Abstract Syntax Tree node that represents an operator
 /// for indexing into a ContainerType.  The Index operator can have many
-//operands but in all cases requires at least two.  The first operand must
-//resolve to the address of a memory location, such as returned by the
-//ReferenceOp. The second and subsequent operands must all be of integer type.
+/// operands but in all cases requires at least two.  The first operand must
+/// resolve to the address of a memory location, such as returned by the
+/// ReferenceOp. The second and subsequent operands must all be of integer type.
 /// They specify which elements of the memory object should be indexed. This
 /// operator is the means by which the elements of memory objects of type 
 /// PointerType, ArrayType, VectorType, StructureType, and ContinuationType can

Modified: hlvm/trunk/hlvm/AST/Operator.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Operator.cpp?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Operator.cpp (original)
+++ hlvm/trunk/hlvm/AST/Operator.cpp Sat Jul  7 19:01:35 2007
@@ -51,7 +51,7 @@
 }
 
 size_t  
-NilaryOperator::numOperands() const
+NilaryOperator::getNumOperands() const
 {
   return 0;
 }
@@ -86,7 +86,7 @@
 }
 
 size_t  
-UnaryOperator::numOperands() const
+UnaryOperator::getNumOperands() const
 {
   return op1 != 0;
 }
@@ -131,7 +131,7 @@
 }
 
 size_t  
-BinaryOperator::numOperands() const
+BinaryOperator::getNumOperands() const
 {
   return (ops[0] ? 1 : 0) + (ops[1] ? 1 : 0);
 }
@@ -180,7 +180,7 @@
 }
 
 size_t  
-TernaryOperator::numOperands() const
+TernaryOperator::getNumOperands() const
 {
   return (ops[0] ? 1 : 0) + (ops[1] ? 1 : 0) + (ops[2] ? 1 : 0);
 }
@@ -233,7 +233,7 @@
 }
 
 size_t  
-MultiOperator::numOperands() const
+MultiOperator::getNumOperands() const
 {
   return ops.size();
 }

Modified: hlvm/trunk/hlvm/AST/Operator.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Operator.h?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Operator.h (original)
+++ hlvm/trunk/hlvm/AST/Operator.h Sat Jul  7 19:01:35 2007
@@ -42,7 +42,8 @@
 /// some action. Operators form the content of a Block.  As this is the base
 /// class of all operators, the Operator class only provides the functionality
 /// that is common to all operators: getting the number of operands
-/// (numOperands), getting the Value of an operand (getOperand), and  setting 
+/// (getNumOperands), getting the Value of an operand (getOperand), and  
+/// setting 
 /// the Value of an operand (setOperand). Since Operand is a Value, this implies
 /// two things: (1) Operators can be the operand of other operators and (2) eery
 /// Operator has a type.
@@ -62,7 +63,7 @@
   /// @{
   public:
     /// Get a specific operand of this operator.
-    virtual size_t  numOperands() const = 0;
+    virtual size_t  getNumOperands() const = 0;
     virtual Value* getOperand(unsigned opnum) const = 0;
 
     /// Determine if this is a classof some other type.
@@ -94,7 +95,7 @@
   /// @name Accessors
   /// @{
   public:
-    virtual size_t  numOperands() const;
+    virtual size_t  getNumOperands() const;
     virtual Value* getOperand(unsigned opnum) const;
     static inline bool classof(const NilaryOperator*) { return true; }
     static inline bool classof(const Node* N) { return N->isNilaryOperator(); }
@@ -128,7 +129,7 @@
   /// @{
   public:
     Value* getOperand() const { return op1; }
-    virtual size_t  numOperands() const;
+    virtual size_t  getNumOperands() const;
     virtual Value* getOperand(unsigned opnum) const;
     static inline bool classof(const UnaryOperator*) { return true; }
     static inline bool classof(const Node* N) { return N->isUnaryOperator(); }
@@ -168,7 +169,7 @@
   /// @name Accessors
   /// @{
   public:
-    virtual size_t  numOperands() const;
+    virtual size_t  getNumOperands() const;
     virtual Value* getOperand(unsigned opnum) const;
     static inline bool classof(const BinaryOperator*) { return true; }
     static inline bool classof(const Node* N) { return N->isBinaryOperator(); }
@@ -207,7 +208,7 @@
   /// @name Accessors
   /// @{
   public:
-    virtual size_t  numOperands() const;
+    virtual size_t  getNumOperands() const;
     virtual Value* getOperand(unsigned opnum) const;
     static inline bool classof(const TernaryOperator*) { return true; }
     static inline bool classof(const Node* N) { return N->isTernaryOperator(); }
@@ -257,7 +258,7 @@
   /// @name Accessors
   /// @{
   public:
-    virtual size_t  numOperands() const;
+    virtual size_t  getNumOperands() const;
     virtual Value* getOperand(unsigned opnum) const;
     static inline bool classof(const MultiOperator*) { return true; }
     static inline bool classof(const Node* N) { return N->isMultiOperator(); }
@@ -283,6 +284,9 @@
   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());
+    }
   protected:
     virtual void insertChild(Node* child);
     virtual void removeChild(Node* child);

Modified: hlvm/trunk/hlvm/Base/Memory.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Base/Memory.cpp?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Base/Memory.cpp (original)
+++ hlvm/trunk/hlvm/Base/Memory.cpp Sat Jul  7 19:01:35 2007
@@ -30,7 +30,6 @@
 #include <hlvm/Base/Memory.h>
 #include <hlvm/Base/Assert.h>
 #include <hlvm/Base/Config.h>
-#include <llvm/System/Signals.h>
 #include <apr-1/apr_general.h>
 #include <memory>
 #include <new>
@@ -112,11 +111,6 @@
       if (APR_SUCCESS != apr_initialize())
         hlvmAssert(!"Can't initialize APR");
 
-#ifdef XPS_DEBUG
-      // Make sure we print stack trace if we get bad signals
-      llvm::sys::PrintStackTraceOnErrorSignal();
-#endif
-
     }
     catch ( ... )
     {

Modified: hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp (original)
+++ hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp Sat Jul  7 19:01:35 2007
@@ -58,6 +58,15 @@
 #include <llvm/Assembly/PrintModulePass.h>
 #include <llvm/Analysis/Verifier.h>
 
+namespace llvm {
+  void dump(llvm::Value* V) {
+    V->dump();
+  }
+  void dumpType(llvm::Type* T) {
+    T->dump();
+  }
+}
+
 namespace 
 {
 using namespace hlvm;
@@ -124,7 +133,10 @@
   llvm::Value* getVariable(const hlvm::Variable* V);
   inline llvm::GlobalValue::LinkageTypes getLinkageTypes(LinkageKinds lk);
   inline std::string getLinkageName(LinkageItem* li);
-  inline llvm::Value* toBoolean(llvm::Value*);
+  inline llvm::Value* getBoolean(llvm::Value* op);
+  inline llvm::Value* getInteger(llvm::Value* op);
+  inline llvm::Value* toBoolean(llvm::Value* op);
+  inline llvm::Value* ptr2Value(llvm::Value* op);
 
   /// Accessors for HLVM Runtime Library things
   inline llvm::Type*         get_hlvm_size();
@@ -435,7 +447,7 @@
       break;
     case PointerTypeID: 
     {
-      hlvm::Type* hElemType = 
+      const hlvm::Type* hElemType = 
         llvm::cast<hlvm::PointerType>(ty)->getElementType();
       const llvm::Type* lElemType = getType(hElemType);
       result = llvm::PointerType::get(lElemType);
@@ -580,6 +592,20 @@
   hlvmAssert(!"Don't know how to convert V into bool");
 }
 
+llvm::Value* 
+LLVMGeneratorPass::ptr2Value(llvm::Value* V)
+{
+  if (!llvm::isa<llvm::PointerType>(V->getType()))
+    return V;
+
+ // llvm::GetElementPtrInst* GEP = new llvm::GetElementPtrIns(V,
+  //    llvm::ConstantInt::get(llvm::Type::UIntTy,0),
+   //   llvm::ConstantInt::get(llvm::Type::UIntTy,0),
+    //  "ptr2Value", lblk);
+  llvm::LoadInst* Load = new llvm::LoadInst(V,"ptr2Value",lblk);
+  return Load;
+}
+
 std::string
 LLVMGeneratorPass::getLinkageName(LinkageItem* lk)
 {
@@ -789,6 +815,9 @@
 {
   hlvmAssert(lops.size() >= 1 && "Too few operands for NegateOp");
   llvm::Value* operand = lops.back(); lops.pop_back();
+  hlvmAssert((operand->getType()->isInteger() || 
+              operand->getType()->isFloatingPoint()) && 
+              "Can't negate non-numeric");
   llvm::BinaryOperator* neg = 
     llvm::BinaryOperator::createNeg(operand,"neg",lblk);
   lops.push_back(neg);
@@ -799,6 +828,7 @@
 {
   hlvmAssert(lops.size() >= 1 && "Too few operands for ComplementOp");
   llvm::Value* operand = lops.back(); lops.pop_back();
+  operand = ptr2Value(operand);
   const llvm::Type* lType = operand->getType();
   hlvmAssert(lType->isInteger() && "Can't complement non-integral type");
   llvm::ConstantIntegral* allOnes = 
@@ -868,6 +898,8 @@
   hlvmAssert(lops.size() >= 2 && "Too few operands for AddOp");
   llvm::Value* op2 = lops.back(); lops.pop_back();
   llvm::Value* op1 = lops.back(); lops.pop_back();
+  op1 = ptr2Value(op1);
+  op2 = ptr2Value(op2);
   llvm::BinaryOperator* add = llvm::BinaryOperator::create(
     llvm::Instruction::Add, op1, op2, "add", lblk);
   lops.push_back(add);
@@ -879,6 +911,8 @@
   hlvmAssert(lops.size() >= 2 && "Too few operands for SubtractOp");
   llvm::Value* op2 = lops.back(); lops.pop_back();
   llvm::Value* op1 = lops.back(); lops.pop_back();
+  op1 = ptr2Value(op1);
+  op2 = ptr2Value(op2);
   llvm::BinaryOperator* sub = llvm::BinaryOperator::create(
     llvm::Instruction::Sub, op1, op2, "add", lblk);
   lops.push_back(sub);
@@ -890,6 +924,8 @@
   hlvmAssert(lops.size() >= 2 && "Too few operands for MultiplyOp");
   llvm::Value* op2 = lops.back(); lops.pop_back();
   llvm::Value* op1 = lops.back(); lops.pop_back();
+  op1 = ptr2Value(op1);
+  op2 = ptr2Value(op2);
   llvm::BinaryOperator* mul = llvm::BinaryOperator::create(
     llvm::Instruction::Mul, op1, op2, "mul", lblk);
   lops.push_back(mul);
@@ -901,6 +937,8 @@
   hlvmAssert(lops.size() >= 2 && "Too few operands for DivideOp");
   llvm::Value* op2 = lops.back(); lops.pop_back();
   llvm::Value* op1 = lops.back(); lops.pop_back();
+  op1 = ptr2Value(op1);
+  op2 = ptr2Value(op2);
   llvm::BinaryOperator* div = llvm::BinaryOperator::create(
     llvm::Instruction::Div, op1, op2, "div", lblk);
   lops.push_back(div);
@@ -912,6 +950,8 @@
   hlvmAssert(lops.size() >= 2 && "Too few operands for ModuloOp");
   llvm::Value* op2 = lops.back(); lops.pop_back();
   llvm::Value* op1 = lops.back(); lops.pop_back();
+  op1 = ptr2Value(op1);
+  op2 = ptr2Value(op2);
   llvm::BinaryOperator* rem = llvm::BinaryOperator::create(
     llvm::Instruction::Rem, op1, op2, "mod", lblk);
   lops.push_back(rem);
@@ -923,6 +963,8 @@
   hlvmAssert(lops.size() >= 2 && "Too few operands for BAndOp");
   llvm::Value* op2 = lops.back(); lops.pop_back();
   llvm::Value* op1 = lops.back(); lops.pop_back();
+  op1 = ptr2Value(op1);
+  op2 = ptr2Value(op2);
   llvm::BinaryOperator* band = llvm::BinaryOperator::create(
     llvm::Instruction::And, op1, op2, "band", lblk);
   lops.push_back(band);
@@ -934,6 +976,8 @@
   hlvmAssert(lops.size() >= 2 && "Too few operands for BOrOp");
   llvm::Value* op2 = lops.back(); lops.pop_back();
   llvm::Value* op1 = lops.back(); lops.pop_back();
+  op1 = ptr2Value(op1);
+  op2 = ptr2Value(op2);
   llvm::BinaryOperator* bor = llvm::BinaryOperator::create(
     llvm::Instruction::Or, op1, op2, "bor", lblk);
   lops.push_back(bor);
@@ -945,6 +989,8 @@
   hlvmAssert(lops.size() >= 2 && "Too few operands for BXorOp");
   llvm::Value* op2 = lops.back(); lops.pop_back();
   llvm::Value* op1 = lops.back(); lops.pop_back();
+  op1 = ptr2Value(op1);
+  op2 = ptr2Value(op2);
   llvm::BinaryOperator* Xor = llvm::BinaryOperator::create(
     llvm::Instruction::Xor, op1, op2, "bor", lblk);
   lops.push_back(Xor);
@@ -956,6 +1002,8 @@
   hlvmAssert(lops.size() >= 2 && "Too few operands for BNorOp");
   llvm::Value* op2 = lops.back(); lops.pop_back();
   llvm::Value* op1 = lops.back(); lops.pop_back();
+  op1 = ptr2Value(op1);
+  op2 = ptr2Value(op2);
   llvm::BinaryOperator* bor = llvm::BinaryOperator::create(
     llvm::Instruction::Or, op1, op2, "bor", lblk);
   llvm::BinaryOperator* nor = llvm::BinaryOperator::createNot(bor,"bor",lblk);
@@ -972,6 +1020,7 @@
 {
   hlvmAssert(lops.size() >= 1 && "Too few operands for BNorOp");
   llvm::Value* op1 = lops.back(); lops.pop_back();
+  op1 = ptr2Value(op1);
   llvm::Value* b1 = toBoolean(op1);
   llvm::BinaryOperator* Not = llvm::BinaryOperator::createNot(b1,"not",lblk);
   lops.push_back(Not);
@@ -983,6 +1032,8 @@
   hlvmAssert(lops.size() >= 2 && "Too few operands for BNorOp");
   llvm::Value* op2 = lops.back(); lops.pop_back();
   llvm::Value* op1 = lops.back(); lops.pop_back();
+  op1 = ptr2Value(op1);
+  op2 = ptr2Value(op2);
   llvm::Value* b1 = toBoolean(op1);
   llvm::Value* b2 = toBoolean(op2);
   llvm::BinaryOperator* And = llvm::BinaryOperator::create(
@@ -996,6 +1047,8 @@
   hlvmAssert(lops.size() >= 2 && "Too few operands for BNorOp");
   llvm::Value* op2 = lops.back(); lops.pop_back();
   llvm::Value* op1 = lops.back(); lops.pop_back();
+  op1 = ptr2Value(op1);
+  op2 = ptr2Value(op2);
   llvm::Value* b1 = toBoolean(op1);
   llvm::Value* b2 = toBoolean(op2);
   llvm::BinaryOperator* Or = llvm::BinaryOperator::create(
@@ -1009,6 +1062,8 @@
   hlvmAssert(lops.size() >= 2 && "Too few operands for NorOp");
   llvm::Value* op2 = lops.back(); lops.pop_back();
   llvm::Value* op1 = lops.back(); lops.pop_back();
+  op1 = ptr2Value(op1);
+  op2 = ptr2Value(op2);
   llvm::Value* b1 = toBoolean(op1);
   llvm::Value* b2 = toBoolean(op2);
   llvm::BinaryOperator* Or = llvm::BinaryOperator::create(
@@ -1023,6 +1078,8 @@
   hlvmAssert(lops.size() >= 2 && "Too few operands for XorOp");
   llvm::Value* op2 = lops.back(); lops.pop_back();
   llvm::Value* op1 = lops.back(); lops.pop_back();
+  op1 = ptr2Value(op1);
+  op2 = ptr2Value(op2);
   llvm::Value* b1 = toBoolean(op1);
   llvm::Value* b2 = toBoolean(op2);
   llvm::BinaryOperator* Xor = llvm::BinaryOperator::create(
@@ -1036,6 +1093,8 @@
   hlvmAssert(lops.size() >= 2 && "Too few operands for EqualityOp");
   llvm::Value* op2 = lops.back(); lops.pop_back();
   llvm::Value* op1 = lops.back(); lops.pop_back();
+  op1 = ptr2Value(op1);
+  op2 = ptr2Value(op2);
   llvm::SetCondInst* SCI = 
     new llvm::SetCondInst(llvm::Instruction::SetEQ, op1,op2,"eq",lblk);
   lops.push_back(SCI);
@@ -1047,6 +1106,8 @@
   hlvmAssert(lops.size() >= 2 && "Too few operands for InequalityOp");
   llvm::Value* op2 = lops.back(); lops.pop_back();
   llvm::Value* op1 = lops.back(); lops.pop_back();
+  op1 = ptr2Value(op1);
+  op2 = ptr2Value(op2);
   llvm::SetCondInst* SCI = 
     new llvm::SetCondInst(llvm::Instruction::SetNE, op1,op2,"ne",lblk);
   lops.push_back(SCI);
@@ -1154,7 +1215,7 @@
 template<> void
 LLVMGeneratorPass::gen<ReferenceOp>(ReferenceOp* r)
 {
-  hlvm::Value* referent = r->getReferent();
+  hlvm::Value* referent = const_cast<hlvm::Value*>(r->getReferent());
   llvm::Value* v = 0;
   if (llvm::isa<Variable>(referent)) {
     VariableDictionary::iterator I = gvars.find(llvm::cast<Variable>(referent));

Modified: hlvm/trunk/hlvm/Pass/Pass.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Pass/Pass.cpp?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Pass/Pass.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Pass.cpp Sat Jul  7 19:01:35 2007
@@ -121,7 +121,7 @@
 PassManagerImpl::runOn(Operator* op)
 {
   runPreOrder(op);
-  size_t limit = op->numOperands();
+  size_t limit = op->getNumOperands();
   for (size_t i = 0; i < limit; ++i) {
     runOn(op->getOperand(i));
   }

Modified: hlvm/trunk/hlvm/Pass/Pass.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Pass/Pass.h?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Pass/Pass.h (original)
+++ hlvm/trunk/hlvm/Pass/Pass.h Sat Jul  7 19:01:35 2007
@@ -72,7 +72,7 @@
   /// @name Constructors
   /// @{
   protected:
-    Pass(int i, TraversalKinds m) : interest_(i), mode_(m) {}
+    Pass(int i, TraversalKinds m) : interest_(i), mode_(m), passed_(true) {}
   public:
     virtual ~Pass();
 
@@ -104,6 +104,7 @@
   public:
     int mode()     const { return mode_; }
     int interest() const { return interest_; }
+    int passed()   const { return passed_; }
 
   /// @}
   /// @name Data
@@ -111,6 +112,8 @@
   private:
     int interest_;
     TraversalKinds mode_;
+  protected:
+    bool passed_;
   /// @}
 };
 
@@ -125,5 +128,6 @@
     virtual void runOn(AST* tree) = 0;
 };
 
+bool validate(AST* tree);
 } // hlvm
 #endif

Modified: hlvm/trunk/hlvm/Pass/Validate.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Pass/Validate.cpp?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Pass/Validate.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Validate.cpp Sat Jul  7 19:01:35 2007
@@ -54,22 +54,64 @@
     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);
 
     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)
+{
+  const Type* Ty = n->getType();
+  if (Ty) {
+    if (isa<PointerType>(Ty)) {
+      error(n,"Expecting a non-pointer value");
+      return false;
+    }
+  }
+  return true;
+}
+
 void 
 ValidateImpl::error(Node* n, const char* msg)
 {
-  std::cerr << "Node(" << n << "): " << msg << "\n";
+  if (n) {
+    const Locator* loc = n->getLocator();
+    if (loc) {
+      std::string msg;
+      loc->getLocation(msg);
+      std::cerr << msg << " ";
+    } else
+      std::cerr << "Unknown Location: ";
+    std::cerr << "Node(" << n << "): ";
+  }
+  std::cerr << msg << "\n";
+  passed_ = false;
 }
 
 inline void
 ValidateImpl::validateName(Node*n, const std::string& name)
 {
   if (name.empty()) {
-    error(0,"Empty Name");
+    error(n,"Empty Name");
   }
 }
 
@@ -245,11 +287,28 @@
 template<> inline void
 ValidateImpl::validate(LoadOp* n)
 {
+  if (checkNumOperands(n,1)) {
+    Value* oprnd = n->getOperand(0);
+    if (!isa<PointerType>(oprnd->getType()))
+      error(n,"LoadOp expects a pointer type operand");
+    else if (n->getType() != 
+             cast<PointerType>(oprnd->getType())->getElementType())
+      error(n,"LoadOp type and operand type do not agree");
+  }
 }
 
 template<> inline void
 ValidateImpl::validate(StoreOp* n)
 {
+  if (checkNumOperands(n,2)) {
+    Value* op1 = n->getOperand(0);
+    Value* op2 = n->getOperand(1);
+    if (!isa<PointerType>(op1->getType()))
+      error(n,"StoreOp expects first operand to be pointer type");
+    else if (cast<PointerType>(op1->getType())->getElementType() != 
+             op2->getType())
+      error(n,"StoreOp operands do not agree in type");
+  }
 }
 
 template<> inline void
@@ -265,232 +324,324 @@
 template<> inline void
 ValidateImpl::validate(ComplementOp* n)
 {
+  if (checkNumOperands(n,1))
+    checkNonPointer(n->getOperand(0));
 }
 
 template<> inline void
 ValidateImpl::validate(PreIncrOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(PostIncrOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(PreDecrOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(PostDecrOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(AddOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(SubtractOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(MultiplyOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(DivideOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(ModuloOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(BAndOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(BOrOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(BXorOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(BNorOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(NotOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(AndOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(OrOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(NorOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(XorOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(LessThanOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(GreaterThanOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(LessEqualOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(GreaterEqualOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(EqualityOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(InequalityOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(IsPInfOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(IsNInfOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(IsNanOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(TruncOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(RoundOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(FloorOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(CeilingOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(LogEOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(Log2Op* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(Log10Op* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(SquareRootOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(CubeRootOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(FactorialOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(PowerOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(RootOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(GCDOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(LCMOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 
 template<> inline void
 ValidateImpl::validate(OpenOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(CloseOp* n)
 {
+  if (checkNumOperands(n,1))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(ReadOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
 ValidateImpl::validate(WriteOp* n)
 {
+  if (checkNumOperands(n,2))
+    ;
 }
 
 template<> inline void
@@ -673,3 +824,16 @@
 {
   return new ValidateImpl();
 }
+
+bool
+hlvm::validate(AST* tree)
+{
+  PassManager* PM = PassManager::create();
+  Pass* pass = Pass::new_ValidatePass(); 
+  PM->addPass( pass );
+  PM->runOn(tree);
+  delete PM;
+  bool result = pass->passed();
+  delete pass;
+  return result;
+}

Modified: hlvm/trunk/hlvm/Reader/HLVM.rng
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/HLVM.rng?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Reader/HLVM.rng (original)
+++ hlvm/trunk/hlvm/Reader/HLVM.rng Sat Jul  7 19:01:35 2007
@@ -678,7 +678,6 @@
     <choice>
       <ref name="Operators.pat"/>
       <ref name="Constant.pat"/>
-      <ref name="Location.pat"/>
     </choice>
   </define>
 

Modified: hlvm/trunk/hlvm/Reader/XMLReader.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XMLReader.cpp?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Reader/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XMLReader.cpp Sat Jul  7 19:01:35 2007
@@ -104,6 +104,9 @@
     return loc = new LineLocator(uri,cur->line);
   }
 
+  inline Type* getType(const std::string& name );
+
+
   inline void handleParseError(xmlErrorPtr error);
   inline void handleValidationError(xmlErrorPtr error);
 
@@ -128,6 +131,8 @@
   Operator*      parseOperator      (xmlNodePtr& cur, int token);
   Value*         parseValue         (xmlNodePtr& cur);
   Value*         parseValue         (xmlNodePtr& cur, int token);
+  StoreOp*       parseStoreOp       (xmlNodePtr& cur);
+  LoadOp*        parseLoadOp        (xmlNodePtr& cur);
 
   template<class OpClass>
   OpClass*       parse(xmlNodePtr& cur);
@@ -354,6 +359,17 @@
   type = getAttribute(cur,"type");
 }
 
+Type* 
+XMLReaderImpl::getType(const std::string& name )
+{
+  Type* Ty = recognize_builtin_type(ast,name);
+  if (!Ty) {
+    Ty = ast->resolveType(name);
+  }
+  hlvmAssert(Ty != 0 && "Couldn't get Type!");
+  return Ty;
+}
+
 inline ConstantInteger*
 XMLReaderImpl::parseBinary(xmlNodePtr& cur)
 {
@@ -582,7 +598,7 @@
   std::string name = getAttribute(cur,"id");
   std::string type = getAttribute(cur,"renames");
   AliasType* alias = 
-    ast->new_AliasType(name,ast->resolveType(type),getLocator(cur));
+    ast->new_AliasType(name,getType(type),getLocator(cur));
   checkDoc(cur,alias);
   return alias;
 }
@@ -612,7 +628,7 @@
   std::string name = getAttribute(cur,"id");
   std::string type = getAttribute(cur,"to");
   PointerType* result = 
-    ast->new_PointerType(name,ast->resolveType(type),loc);
+    ast->new_PointerType(name,getType(type),loc);
   checkDoc(cur,result);
   return result;
 }
@@ -626,7 +642,7 @@
   std::string type = getAttribute(cur,"of");
   const char* len = getAttribute(cur,"length");
   ArrayType* result = ast->new_ArrayType(
-    name, ast->resolveType(type), recognize_nonNegativeInteger(len),loc);
+    name, getType(type), recognize_nonNegativeInteger(len),loc);
   checkDoc(cur,result);
   return result;
 }
@@ -641,7 +657,7 @@
   const char* len  = getAttribute(cur,"length");
   VectorType* result =
     ast->new_VectorType(
-      name,ast->resolveType(type), recognize_nonNegativeInteger(len),loc);
+      name,getType(type), recognize_nonNegativeInteger(len),loc);
   checkDoc(cur,result);
   return result;
 }
@@ -659,7 +675,7 @@
                "Structure only has fields");
     std::string name = getAttribute(child,"id");
     std::string type = getAttribute(child,"type");
-    AliasType* alias = ast->new_AliasType(name,ast->resolveType(type),loc);
+    AliasType* alias = ast->new_AliasType(name,getType(type),loc);
     alias->setParent(struc);
     checkDoc(child,alias);
     child = child->next;
@@ -676,7 +692,7 @@
   std::string result = getAttribute(cur,"result");
   const char* varargs = getAttribute(cur,"varargs",false);
   SignatureType* sig = 
-    ast->new_SignatureType(name,ast->resolveType(result),loc);
+    ast->new_SignatureType(name,getType(result),loc);
   if (varargs)
     sig->setIsVarArgs(recognize_boolean(varargs));
   xmlNodePtr child = checkDoc(cur,sig); 
@@ -684,7 +700,7 @@
     hlvmAssert(getToken(child->name) == TKN_arg && "Signature only has args");
     std::string name = getAttribute(child,"id");
     std::string type = getAttribute(child,"type");
-    AliasType* alias = ast->new_AliasType(name,ast->resolveType(type),loc);
+    AliasType* alias = ast->new_AliasType(name,getType(type),loc);
     alias->setParent(sig);
     checkDoc(child,alias);
     child = child->next;
@@ -712,9 +728,7 @@
   getNameType(cur, name, type);
   const char* cnst = getAttribute(cur, "const", false);
   const char* lnkg = getAttribute(cur, "linkage", false);
-  const Type* Ty = recognize_builtin_type(ast,type);
-  if (!Ty)
-    Ty = ast->resolveType(type);
+  const Type* Ty = getType(type);
   Variable* var = ast->new_Variable(name,Ty,loc);
   if (cnst)
     var->setIsConstant(recognize_boolean(cnst));
@@ -734,9 +748,7 @@
   std::string name, type;
   getNameType(cur, name, type);
   Locator* loc = getLocator(cur);
-  const Type* Ty = recognize_builtin_type(ast,type);
-  if (Ty == 0)
-    Ty = ast->resolveType(type);
+  const Type* Ty = getType(type);
   xmlNodePtr child = cur->children;
   Constant* C = 0;
   if (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
@@ -744,10 +756,7 @@
   } else {
     C = ast->new_ConstantZero(Ty,loc);
   }
-  AutoVarOp* result = ast->AST::new_UnaryOp<AutoVarOp>(C,loc);
-  result->setName(name);
-  result->setType(Ty);
-  return result;
+  return ast->AST::new_AutoVarOp(name,Ty,C,loc);
 }
 
 template<> ReferenceOp*
@@ -756,15 +765,15 @@
   std::string id = getAttribute(cur,"id");
   Locator* loc = getLocator(cur);
 
-  ReferenceOp* result = ast->AST::new_NilaryOp<ReferenceOp>(loc);
-
   // Find the referrent variable in a block
   Block* blk = block;
+  Value* referent = 0;
   while (blk != 0) {
-    if (AutoVarOp* av = blk->getAutoVar(id)) {
-      result->setReferent(av);
-      return result;
-    }
+    if (AutoVarOp* av = blk->getAutoVar(id))
+      if (av->getName() == id) {
+        referent = av;
+        break;
+      }
     if (llvm::isa<Block>(blk->getParent()))
       blk = llvm::cast<Block>(blk->getParent());
     else
@@ -772,10 +781,31 @@
   }
 
   // Didn't find an autovar, try a global variable
-  Variable* var = bundle->var_find(id);
-  hlvmAssert(var && "Variable not found");
-  result->setReferent(var);
-  return result;
+  if (!referent) {
+    referent = bundle->var_find(id);
+    hlvmAssert(referent && "Variable not found");
+  }
+
+  return ast->AST::new_ReferenceOp(referent, loc);
+}
+
+StoreOp*
+XMLReaderImpl::parseStoreOp(xmlNodePtr& cur)
+{
+  xmlNodePtr child = cur->children;
+  Value* oprnd1 = getValue(child);
+  Value* oprnd2 = getValue(child);
+  Locator* loc = getLocator(cur);
+  return ast->AST::new_BinaryOp<StoreOp>(oprnd1,oprnd2,loc);
+}
+
+LoadOp*
+XMLReaderImpl::parseLoadOp(xmlNodePtr& cur)
+{
+  xmlNodePtr child = cur->children;
+  Value* oprnd1 = getValue(child);
+  Locator* loc = getLocator(cur);
+  return ast->AST::new_UnaryOp<LoadOp>(oprnd1,loc);
 }
 
 template<class OpClass>
@@ -825,14 +855,14 @@
 XMLReaderImpl::parseMultiOp(xmlNodePtr& cur)
 {
   Locator* loc = getLocator(cur);
-  OpClass* result = ast->AST::new_MultiOp<OpClass>(loc);
   xmlNodePtr child = cur->children;
   Value* operand = getValue(child);
+  MultiOperator::OprndList ol;
   while (operand != 0) {
-    operand->setParent(result);
+    ol.push_back(operand);
     operand = getValue(child);
   }
-  return result;
+  return ast->AST::new_MultiOp<OpClass>(ol,loc);
 }
 
 template<> Block*
@@ -1097,8 +1127,8 @@
     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;
-    case TKN_load:         op = parseUnaryOp<LoadOp>(cur); break;
+    case TKN_store:        op = parseStoreOp(cur); break;
+    case TKN_load:         op = parseLoadOp(cur); break;
     case TKN_open:         op = parseUnaryOp<OpenOp>(cur); break;
     case TKN_write:        op = parseBinaryOp<WriteOp>(cur); break;
     case TKN_close:        op = parseUnaryOp<CloseOp>(cur); break;

Modified: hlvm/trunk/hlvm/Writer/XMLWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Writer/XMLWriter.cpp?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Writer/XMLWriter.cpp (original)
+++ hlvm/trunk/hlvm/Writer/XMLWriter.cpp Sat Jul  7 19:01:35 2007
@@ -707,7 +707,7 @@
 XMLWriterImpl::WriterPass::put(ReferenceOp* r)
 {
   startElement("ref");
-  Value* ref = r->getReferent();
+  const Value* ref = r->getReferent();
   const std::string& name = 
      (isa<Variable>(ref) ? cast<Variable>(ref)->getName() :
       (isa<AutoVarOp>(ref) ? cast<AutoVarOp>(ref)->getName() : "oops" ));

Modified: hlvm/trunk/test/xml2xml/arithmetic.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/arithmetic.hlx?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/test/xml2xml/arithmetic.hlx (original)
+++ hlvm/trunk/test/xml2xml/arithmetic.hlx Sat Jul  7 19:01:35 2007
@@ -10,58 +10,102 @@
           <zero/>
         </autovar>
         <preinc>
-          <ref id="v1"/>
+          <load>
+            <ref id="v1"/>
+          </load>
         </preinc>
         <postinc>
-          <ref id="v1"/>
+          <load>
+            <ref id="v1"/>
+          </load>
         </postinc>
         <postdec>
-          <ref id="v2"/>
+          <load>
+            <ref id="v2"/>
+          </load>
         </postdec>
         <predec>
-          <ref id="v2"/>
+          <load>
+            <ref id="v2"/>
+          </load>
         </predec>
         <neg>
-          <ref id="v1"/>
+          <load>
+            <ref id="v1"/>
+          </load>
         </neg>
         <cmpl>
-          <ref id="v2"/>
+          <load>
+            <ref id="v2"/>
+          </load>
         </cmpl>
         <add>
-          <ref id="v1"/>
+          <load>
+            <ref id="v1"/>
+          </load>
           <dec>1</dec>
         </add>
         <sub>
-          <ref id="v1"/>
+          <load>
+            <ref id="v1"/>
+          </load>
           <dec>1</dec>
         </sub>
         <mul>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </mul>
         <div>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </div>
         <mod>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </mod>
         <band>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </band>
         <bor>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </bor>
         <bxor>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </bxor>
         <bnor>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </bnor>
       </block>
     </program>

Modified: hlvm/trunk/test/xml2xml/booleanops.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/booleanops.hlx?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/test/xml2xml/booleanops.hlx (original)
+++ hlvm/trunk/test/xml2xml/booleanops.hlx Sat Jul  7 19:01:35 2007
@@ -10,47 +10,89 @@
           <false/>
         </autovar>
         <not>
-          <ref id="v1"/>
+          <load>
+            <ref id="v1"/>
+          </load>
         </not>
         <and>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </and>
         <or>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </or>
         <nor>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </nor>
         <xor>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </xor>
         <eq>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </eq>
         <ne>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </ne>
         <gt>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </gt>
         <lt>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </lt>
         <ge>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </ge>
         <le>
-          <ref id="v1"/>
-          <ref id="v2"/>
+          <load>
+            <ref id="v1"/>
+          </load>
+          <load>
+            <ref id="v2"/>
+          </load>
         </le>
       </block>
     </program>

Modified: hlvm/trunk/test/xml2xml/helloworld.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/helloworld.hlx?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/test/xml2xml/helloworld.hlx (original)
+++ hlvm/trunk/test/xml2xml/helloworld.hlx Sat Jul  7 19:01:35 2007
@@ -3,7 +3,7 @@
   <bundle id="helloworld">
     <program id="helloworld">
       <block>
-        <autovar id="stdout" type="hlvm_stream">
+        <autovar id="stdout" type="stream">
           <zero/>
         </autovar>
         <store>

Modified: hlvm/trunk/tools/hlvm-compiler/hlvm-compiler.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/tools/hlvm-compiler/hlvm-compiler.cpp?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/tools/hlvm-compiler/hlvm-compiler.cpp (original)
+++ hlvm/trunk/tools/hlvm-compiler/hlvm-compiler.cpp Sat Jul  7 19:01:35 2007
@@ -47,7 +47,7 @@
 OutputFilename("o", cl::desc("Override output filename"),
                cl::value_desc("filename"));
 
-static cl::opt<bool> Validate("validate", 
+static cl::opt<bool> Validate("validate", cl::init(true),
   cl::desc("Validate input before generating code"));
 
 enum GenerationOptions {

Modified: hlvm/trunk/tools/hlvm-xml2xml/hlvm-xml2xml.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/tools/hlvm-xml2xml/hlvm-xml2xml.cpp?rev=38247&r1=38246&r2=38247&view=diff

==============================================================================
--- hlvm/trunk/tools/hlvm-xml2xml/hlvm-xml2xml.cpp (original)
+++ hlvm/trunk/tools/hlvm-xml2xml/hlvm-xml2xml.cpp Sat Jul  7 19:01:35 2007
@@ -94,12 +94,8 @@
     rdr->read();
     AST* node = rdr->get();
     if (node) {
-      PassManager* PM = PassManager::create();
-      Pass* pass = Pass::new_ValidatePass(); 
-      PM->addPass( pass );
-      PM->runOn(node);
-      delete PM;
-      delete pass;
+      if (!validate(node))
+        return 1;
       wrtr->write(node);
     }
     delete rdr;





More information about the llvm-commits mailing list