From 92bdc21ddb9bb871600e6047fa24056476606d8c Mon Sep 17 00:00:00 2001 From: Alexandre Bique Date: Thu, 5 Mar 2009 20:34:48 +0000 Subject: [PATCH] factorised loop code --- src/ast/generator-data.cc | 24 +++++++------- src/ast/llvm-generator-visitor.cc | 37 +++++++-------------- src/ast/llvm-generator-visitor.hh | 1 + src/ast/simplify-visitor.cc | 57 +++++++++++++-------------------- src/lang/mugiwara/bison-parser/parser.y | 8 ++--- 5 files changed, 51 insertions(+), 76 deletions(-) diff --git a/src/ast/generator-data.cc b/src/ast/generator-data.cc index 7f76811..e440d90 100644 --- a/src/ast/generator-data.cc +++ b/src/ast/generator-data.cc @@ -253,28 +253,28 @@ const ag::Node ag::nodes[] = { } }, - {"If", "Node", "If statement", { + {"ConditionalBranch", "Node", "Factorisation code for loops", { {"Exp *", "cond"}, - {"Node *", "ifTrue"}, - {"Node *", "ifFalse"}, + {"Label *", "trueLabel"}, + {"Label *", "falseLabel"}, + }, + }, + + {"If", "ConditionalBranch", "If statement", { + {"Node *", "trueBlock"}, + {"Node *", "falseBlock"}, {"Label *", "endLabel"} }, }, - {"While", "Node", "While statement", { - {"Exp *", "cond"}, + {"While", "ConditionalBranch", "While statement", { {"Node *", "block"}, - {"Label *", "beginLabel"}, - {"Label *", "middleLabel"}, - {"Label *", "endLabel"} + {"Label *", "beginLabel"} }, }, - {"DoWhile", "Node", "Do while statement", { - {"Exp *", "cond"}, + {"DoWhile", "ConditionalBranch", "Do while statement", { {"Node *", "block"}, - {"Label *", "beginLabel"}, - {"Label *", "endLabel"} }, }, diff --git a/src/ast/llvm-generator-visitor.cc b/src/ast/llvm-generator-visitor.cc index 4c73864..787c7a1 100644 --- a/src/ast/llvm-generator-visitor.cc +++ b/src/ast/llvm-generator-visitor.cc @@ -263,37 +263,24 @@ namespace ast out_ << " br label %" << node.label << std::endl; } - void - LLVMGeneratorVisitor::visit(const If & node) - { - assert(node.ifTrue->nodeType == Label::nodeTypeId()); - assert(node.ifFalse->nodeType == Label::nodeTypeId()); - - Label * trueLabel = reinterpret_cast