Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73573 - trunk/libs/spirit/example/qi/compiler_tutorial/conjure3
From: joel_at_[hidden]
Date: 2011-08-06 10:55:22


Author: djowel
Date: 2011-08-06 10:55:21 EDT (Sat, 06 Aug 2011)
New Revision: 73573
URL: http://svn.boost.org/trac/boost/changeset/73573

Log:
refactoring the compiler
Text files modified:
   trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.cpp | 13 +++++--------
   trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.hpp | 6 +++++-
   2 files changed, 10 insertions(+), 9 deletions(-)

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.cpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.cpp 2011-08-06 10:55:21 EDT (Sat, 06 Aug 2011)
@@ -578,7 +578,7 @@
             value return_val = (*this)(*x.expr);
             if (!return_val)
                 return false;
- builder.CreateStore(return_val, return_alloca);
+ return_alloca.assign(return_val);
         }
 
         builder.CreateBr(return_block);
@@ -651,12 +651,10 @@
         BOOST_FOREACH(ast::identifier const& arg, x.args)
         {
             // Create an alloca for this variable.
- llvm::AllocaInst* alloca =
- create_entry_block_alloca(
- function, arg.name.c_str(), context());
+ lvalue alloca(builder, arg.name.c_str());
 
             // Store the initial value into the alloca.
- builder.CreateStore(iter, alloca);
+ alloca.assign(value(iter));
 
             // Add arguments to variable symbol table.
             named_values[arg.name] = alloca;
@@ -666,8 +664,7 @@
         if (!void_return)
         {
             // Create an alloca for the return value
- return_alloca =
- create_entry_block_alloca(function, "return.val", context());
+ return_alloca = lvalue(builder, "return.val");
         }
     }
 
@@ -714,7 +711,7 @@
             if (void_return)
                 builder.CreateRetVoid();
             else
- builder.CreateRet(builder.CreateLoad(return_alloca, "return.val"));
+ builder.CreateRet(return_alloca);
 
             //~ vm.module()->dump();
 

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.hpp 2011-08-06 10:55:21 EDT (Sat, 06 Aug 2011)
@@ -68,6 +68,10 @@
 
     struct lvalue : value
     {
+ lvalue()
+ : value(0, true, 0)
+ {}
+
         lvalue(
             llvm::AllocaInst* var,
             llvm::IRBuilder<>& builder)
@@ -150,7 +154,7 @@
         std::string current_function_name;
         std::map<std::string, llvm::AllocaInst*> named_values;
         llvm::BasicBlock* return_block;
- llvm::AllocaInst* return_alloca;
+ lvalue return_alloca;
 
         vmachine& vm;
         llvm::FunctionPassManager fpm;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk