[llvm-commits] [hlvm] r38291 - in /hlvm/trunk: hlvm/AST/AST.cpp hlvm/AST/AST.h hlvm/AST/ControlFlow.cpp hlvm/AST/ControlFlow.h hlvm/AST/Linkables.cpp hlvm/AST/Linkables.h hlvm/CodeGen/LLVMGenerator.cpp hlvm/Pass/Validate.cpp hlvm/Reader/XMLReader.cpp test/return0/boolean.hlx

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


Author: reid
Date: Sat Jul  7 19:02:01 2007
New Revision: 38291

URL: http://llvm.org/viewvc/llvm-project?rev=38291&view=rev
Log:
Fix the selectop and the boolean.hlx return0 test case so that
this test case now passes. Also, start to implement some of
the call operator.

Modified:
    hlvm/trunk/hlvm/AST/AST.cpp
    hlvm/trunk/hlvm/AST/AST.h
    hlvm/trunk/hlvm/AST/ControlFlow.cpp
    hlvm/trunk/hlvm/AST/ControlFlow.h
    hlvm/trunk/hlvm/AST/Linkables.cpp
    hlvm/trunk/hlvm/AST/Linkables.h
    hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
    hlvm/trunk/hlvm/Pass/Validate.cpp
    hlvm/trunk/hlvm/Reader/XMLReader.cpp
    hlvm/trunk/test/return0/boolean.hlx

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

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul  7 19:02:01 2007
@@ -591,11 +591,13 @@
 }
 
 Function*
-AST::new_Function(const std::string& id, const Locator* loc)
+AST::new_Function(
+  const std::string& id, const SignatureType* ty, const Locator* loc)
 {
   Function* result = new Function();
   result->setLocator(loc);
   result->setName(id);
+  result->setType(ty);
   return result;
 }
 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.h (original)
+++ hlvm/trunk/hlvm/AST/AST.h Sat Jul  7 19:02:01 2007
@@ -179,6 +179,7 @@
     /// Create a new Function node. 
     Function* new_Function(
       const std::string& id, ///< The name of the function
+      const SignatureType* type,   ///< The type of the function
       const Locator* loc = 0 ///< The source locator
     );
     /// Create a new Argument node. Arguments are used as the formal argument

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

==============================================================================
--- hlvm/trunk/hlvm/AST/ControlFlow.cpp (original)
+++ hlvm/trunk/hlvm/AST/ControlFlow.cpp Sat Jul  7 19:02:01 2007
@@ -56,4 +56,12 @@
   return const_cast<Function*>(cast<Function>(referent));
 }
 
+const Type* 
+CallOp::getType() const 
+{
+  Function* F = getCalledFunction();
+  hlvmAssert(F && "Call With No Function?");
+  return F->getSignature()->getResultType();
+}
+
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/ControlFlow.h (original)
+++ hlvm/trunk/hlvm/AST/ControlFlow.h Sat Jul  7 19:02:01 2007
@@ -254,6 +254,9 @@
   /// @name Accessors
   /// @{
   public:
+    /// Returns the type of the value of the call. This is the same as the
+    /// result type of the function's signature.
+    const Type* getType() const; 
     Function* getCalledFunction() const;
     static inline bool classof(const CallOp*) { return true; }
     static inline bool classof(const Node* N) { return N->is(CallOpID); }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Linkables.cpp (original)
+++ hlvm/trunk/hlvm/AST/Linkables.cpp Sat Jul  7 19:02:01 2007
@@ -42,8 +42,8 @@
 Program::~Program() { }
 
 const SignatureType* 
-Function::getSignature() const
-{ 
+Function::getSignature() const 
+{
   return cast<SignatureType>(type); 
 }
 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Linkables.h (original)
+++ hlvm/trunk/hlvm/AST/Linkables.h Sat Jul  7 19:02:01 2007
@@ -164,8 +164,10 @@
   /// @name Accessors
   /// @{
   public:
+    bool hasBlock() const { return block != 0; }
     Block* getBlock() const { return block; }
     const SignatureType* getSignature() const;
+
     static inline bool classof(const Function*) { return true; }
     static inline bool classof(const Node* N) { return N->isFunction(); }
 

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

==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp (original)
+++ hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp Sat Jul  7 19:02:01 2007
@@ -1209,9 +1209,9 @@
              llvm::isa<llvm::BasicBlock>(op3));
   if (llvm::isa<llvm::BasicBlock>(op2)) {
     // both are blocks, emit a BranchInstr
-    new llvm::BranchInst(
-        llvm::cast<llvm::BasicBlock>(op2),
-        llvm::cast<llvm::BasicBlock>(op3),op1,lblk);
+    lops.push_back(new llvm::BranchInst(
+      llvm::cast<llvm::BasicBlock>(op2),
+      llvm::cast<llvm::BasicBlock>(op3),op1,lblk));
     return;
   } 
 
@@ -1219,7 +1219,7 @@
   // operators translate to a first class type. Since the select operator
   // requires first class types, its okay to just use it here.
   hlvmAssert(op2->getType()->isFirstClassType());
-  new llvm::SelectInst(op1,op2,op3,"select",lblk);
+  lops.push_back(new llvm::SelectInst(op1,op2,op3,"select",lblk));
 }
 
 template<> void
@@ -1259,8 +1259,10 @@
   if (retTy != lfunc->getReturnType()) {
     retVal = new llvm::CastInst(retVal,lfunc->getReturnType(),"",lblk);
   }
+  // RetInst is never the operand of another instruction because it is
+  // a terminator and cannot return a value. Consequently, we don't push it
+  // on the lops stack.
   new llvm::ReturnInst(retVal,lblk);
-  // RetInst is never the operand of another instruction (Terminator)
 }
 
 template<> void

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

==============================================================================
--- hlvm/trunk/hlvm/Pass/Validate.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Validate.cpp Sat Jul  7 19:02:01 2007
@@ -221,7 +221,7 @@
   bool result = true;
   if (!checkType(n,id))
     result = false;
-  else if (n->size() == 0) {
+  else if (n->size() == 0 && !llvm::isa<SignatureType>(n)) {
     error(n,"DisparateContainerType without elements");
     result = false;
   } else

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

==============================================================================
--- hlvm/trunk/hlvm/Reader/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XMLReader.cpp Sat Jul  7 19:02:01 2007
@@ -876,11 +876,34 @@
   Locator* loc = getLocator(cur);
   std::string name, type;
   getNameType(cur, name, type);
-  func = ast->new_Function(name,loc);
-  const char* lnkg = getAttribute(cur, "linkage", false);
-  if (lnkg)
-    func->setLinkageKind(recognize_LinkageKinds(lnkg));
+  Linkable* lkbl = bundle->find_linkable(name);
+  if (lkbl) {
+    if (llvm::isa<Function>(lkbl)) {
+      func = llvm::cast<Function>(lkbl);
+      if (func->hasBlock()) {
+        error(loc,std::string("Function '") + name + "' was already defined.");
+        return func;
+      }
+    } else {
+      error(loc,std::string("Name '") + name + "' was already used.");
+      return 0;
+    }
+  } else {
+    const Type* Ty = getType(type);
+    if (llvm::isa<SignatureType>(Ty)) {
+      func = ast->new_Function(name,llvm::cast<SignatureType>(Ty),loc);
+      const char* lnkg = getAttribute(cur, "linkage", false);
+      if (lnkg)
+        func->setLinkageKind(recognize_LinkageKinds(lnkg));
+    } else {
+      error(loc,"Invalid type for a function, must be signature");
+    }
+  }
   checkDoc(cur,func);
+  xmlNodePtr child = cur->children;
+  if (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
+    parse<Block>(child);
+  }
   return func;
 }
 
@@ -892,6 +915,7 @@
   std::string name(getAttribute(cur, "id"));
   Program* program = ast->new_Program(name,loc);
   func = program;
+  checkDoc(cur,func);
   xmlNodePtr child = cur->children;
   if (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
     parse<Block>(child);

Modified: hlvm/trunk/test/return0/boolean.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/return0/boolean.hlx?rev=38291&r1=38290&r2=38291&view=diff

==============================================================================
--- hlvm/trunk/test/return0/boolean.hlx (original)
+++ hlvm/trunk/test/return0/boolean.hlx Sat Jul  7 19:02:01 2007
@@ -5,35 +5,28 @@
     <constant id="false" type="bool"><false/></constant>
     <constant id="one" type="s32"><dec>1</dec></constant>
     <constant id="zero" type="s32"><dec>0</dec></constant>
-    <signature id="compute_type" result="bool"/>
     <program id="boolean">
       <block>
-        <select>
-          <call><ref id="compute"/></call>
-          <ref id="one"/>
-          <ref id="zero"/>
-        </select>
-      </block>
-    </program>
-
-    <function id="compute" type="compute_type">
-      <block>
         <ret>
-          <and>
-            <nor>
-              <or>
-                <xor>
-                  <ref id="true"/>
+          <select>
+            <and>
+              <nor>
+                <or>
+                  <xor>
+                    <ref id="true"/>
+                    <ref id="false"/>
+                  </xor>
                   <ref id="false"/>
-                </xor>
-                <ref id="false"/>
-              </or>
-              <ref id="true"/>
-            </nor>
-            <ref id="false"/>
-          </and>
+                </or>
+                <ref id="true"/>
+              </nor>
+              <ref id="false"/>
+            </and>
+            <ref id="one"/>
+            <ref id="zero"/>
+          </select>
         </ret>
       </block>
-    </function>
+    </program>
   </bundle>
 </hlvm>





More information about the llvm-commits mailing list