[llvm-commits] [hlvm] r38296 - in /hlvm/trunk: hlvm/AST/Block.cpp hlvm/CodeGen/LLVMGenerator.cpp hlvm/Reader/XMLReader.cpp test/xml2xml/block.hlx
Reid Spencer
reid at x10sys.com
Sat Jul 7 17:02:04 PDT 2007
Author: reid
Date: Sat Jul 7 19:02:04 2007
New Revision: 38296
URL: http://llvm.org/viewvc/llvm-project?rev=38296&view=rev
Log:
Implement block nesting in operators.
Added:
hlvm/trunk/test/xml2xml/block.hlx
Modified:
hlvm/trunk/hlvm/AST/Block.cpp
hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
hlvm/trunk/hlvm/Reader/XMLReader.cpp
Modified: hlvm/trunk/hlvm/AST/Block.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Block.cpp?rev=38296&r1=38295&r2=38296&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Block.cpp (original)
+++ hlvm/trunk/hlvm/AST/Block.cpp Sat Jul 7 19:02:04 2007
@@ -30,6 +30,7 @@
#include <hlvm/AST/Block.h>
#include <hlvm/AST/MemoryOps.h>
#include <hlvm/Base/Assert.h>
+#include <hlvm/AST/Linkables.h>
#include <llvm/Support/Casting.h>
namespace hlvm {
@@ -74,7 +75,7 @@
Block::getParentBlock() const
{
Node* p = getParent();
- while (p) {
+ while (p && !llvm::isa<Function>(p)) {
if (llvm::isa<Block>(p))
return llvm::cast<Block>(p);
p = p->getParent();
Modified: hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp?rev=38296&r1=38295&r2=38296&view=diff
==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp (original)
+++ hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp Sat Jul 7 19:02:04 2007
@@ -76,6 +76,7 @@
{
typedef std::vector<llvm::Module*> ModuleList;
typedef std::vector<llvm::Value*> OperandList;
+ typedef std::vector<llvm::BasicBlock*> BlockStack;
typedef std::map<const hlvm::Variable*,llvm::Value*> VariableDictionary;
typedef std::map<const hlvm::AutoVarOp*,llvm::Value*> AutoVarDictionary;
typedef std::map<const hlvm::ConstantValue*,llvm::Constant*>
@@ -85,8 +86,8 @@
llvm::Module* lmod; ///< The current module we're generation
llvm::Function* lfunc; ///< The current LLVM function we're generating
llvm::BasicBlock* lblk; ///< The current LLVM block we're generating
- llvm::BasicBlock::InstListType linst;
OperandList lops; ///< The current list of instruction operands
+ BlockStack blocks; ///< The stack of blocks we're constructing
VariableDictionary gvars; ///< Dictionary of HLVM -> LLVM gvars
AutoVarDictionary lvars; ///< Dictionary of HLVM -> LLVM auto vars
llvm::TypeSymbolTable ltypes; ///< The cached LLVM types we've generated
@@ -119,7 +120,7 @@
public:
LLVMGeneratorPass(const AST* tree)
: Pass(0,Pass::PreAndPostOrderTraversal),
- modules(), lmod(0), lfunc(0), lblk(0), linst(), lops(),
+ modules(), lmod(0), lfunc(0), lblk(0), lops(), blocks(),
gvars(), lvars(), ltypes(), consts(),
ast(tree), bundle(0), function(0), block(0),
hlvm_text(0), hlvm_text_create(0), hlvm_text_delete(0),
@@ -1436,6 +1437,8 @@
lfunc = getFunction(llvm::cast<Function>(n));
// Clear the LLVM vars
lvars.clear();
+ blocks.clear();
+ lops.clear();
break;
}
case ProgramID:
@@ -1449,6 +1452,8 @@
);
// Clear LLVM vars
lvars.clear();
+ blocks.clear();
+ lops.clear();
// Save the program so it can be generated into the list of program
// entry points.
progs.push_back(lfunc);
@@ -1457,6 +1462,7 @@
case BlockID:
{
lblk = new llvm::BasicBlock(llvm::cast<Block>(n)->getLabel(),lfunc,0);
+ blocks.push_back(lblk);
break;
}
default:
@@ -1552,7 +1558,11 @@
lfunc = 0;
break;
case BlockID:
- lblk = 0;
+ blocks.pop_back();
+ if (blocks.empty())
+ lblk = 0;
+ else
+ lblk = blocks.back();
break;
// everything else is an error
Modified: hlvm/trunk/hlvm/Reader/XMLReader.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XMLReader.cpp?rev=38296&r1=38295&r2=38296&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Reader/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XMLReader.cpp Sat Jul 7 19:02:04 2007
@@ -67,12 +67,14 @@
Locator* loc;
URI* uri;
Block* block;
+ std::vector<Block*> blocks;
Function* func;
Bundle* bundle;
bool isError;
public:
XMLReaderImpl(const std::string& p)
- : path(p), ast(0), loc(0), uri(0), block(0), func(0), bundle(0), isError(0)
+ : path(p), ast(0), loc(0), uri(0), block(0), blocks(), func(0), bundle(0),
+ isError(0)
{
ast = AST::create();
ast->setSystemID(p);
@@ -856,8 +858,10 @@
const char* label = getAttribute(cur, "label",false);
xmlNodePtr child = cur->children;
MultiOperator::OprndList ops;
- block = ast->new_Block(loc);
- block->setParent(func);
+ if (block)
+ blocks.push_back(block);
+ Block* result = ast->new_Block(loc);
+ block = result;
if (label)
block->setLabel(label);
while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE)
@@ -866,7 +870,13 @@
block->addOperand(op);
child = child->next;
}
- return block;
+ if (blocks.empty())
+ block = 0;
+ else {
+ block = blocks.back();
+ blocks.pop_back();
+ }
+ return result;
}
template<> Function*
@@ -902,7 +912,8 @@
checkDoc(cur,func);
xmlNodePtr child = cur->children;
if (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
- parse<Block>(child);
+ Block* b = parse<Block>(child);
+ b->setParent(func);
}
return func;
}
@@ -918,7 +929,8 @@
checkDoc(cur,func);
xmlNodePtr child = cur->children;
if (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
- parse<Block>(child);
+ Block* b = parse<Block>(child);
+ b->setParent(func);
} else {
hlvmDeadCode("Program Without Block!");
}
Added: hlvm/trunk/test/xml2xml/block.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/block.hlx?rev=38296&view=auto
==============================================================================
--- hlvm/trunk/test/xml2xml/block.hlx (added)
+++ hlvm/trunk/test/xml2xml/block.hlx Sat Jul 7 19:02:04 2007
@@ -0,0 +1,34 @@
+<?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/block.hlx">
+ <bundle id="block">
+ <constant id="0" type="s32">
+ <dec>0</dec>
+ </constant>
+ <constant id="21" type="s32">
+ <dec>21</dec>
+ </constant>
+ <constant id="42" type="s32">
+ <dec>42</dec>
+ </constant>
+ <program id="block">
+ <block>
+ <ret>
+ <select>
+ <block>
+ <ne>
+ <ref id="0"/>
+ <ref id="21"/>
+ </ne>
+ </block>
+ <block>
+ <ref id="42"/>
+ </block>
+ <block>
+ <ref id="21"/>
+ </block>
+ </select>
+ </ret>
+ </block>
+ </program>
+ </bundle>
+</hlvm>
More information about the llvm-commits
mailing list