|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r73622 - trunk/libs/spirit/example/qi/compiler_tutorial/conjure3
From: joel_at_[hidden]
Date: 2011-08-09 11:07:53
Author: djowel
Date: 2011-08-09 11:07:52 EDT (Tue, 09 Aug 2011)
New Revision: 73622
URL: http://svn.boost.org/trac/boost/changeset/73622
Log:
refactoring: moving low-level llvm stuff into separate classes
Text files modified:
trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.cpp | 22 ++++++++++++----------
trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.hpp | 19 +++++++++++++------
2 files changed, 25 insertions(+), 16 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-09 11:07:52 EDT (Tue, 09 Aug 2011)
@@ -49,6 +49,11 @@
return v != 0;
}
+ value::operator bool() const
+ {
+ return v != 0;
+ }
+
void value::name(char const* id)
{
v->setName(id);
@@ -379,17 +384,14 @@
return value(alloca, true, &llvm_builder);
}
- namespace
+ struct value::to_llvm_value
{
- struct llvm_value
+ typedef llvm::Value* result_type;
+ llvm::Value* operator()(value const& x) const
{
- typedef llvm::Value* result_type;
- llvm::Value* operator()(value const& x) const
- {
- return x;
- }
- };
- }
+ return x;
+ }
+ };
template <typename C>
llvm::Value* llvm_compiler::call_impl(
@@ -422,7 +424,7 @@
{
llvm::Value* call = call_impl(
callee,
- args | boost::adaptors::transformed(llvm_value()));
+ args | boost::adaptors::transformed(value::to_llvm_value()));
if (call == 0)
return val();
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-09 11:07:52 EDT (Tue, 09 Aug 2011)
@@ -36,17 +36,17 @@
struct llvm_compiler;
///////////////////////////////////////////////////////////////////////////
- // The Value (light abstraction of an LLVM::Value
+ // The Value (light abstraction of an LLVM::Value)
///////////////////////////////////////////////////////////////////////////
struct value
{
value();
value(value const& rhs);
- operator llvm::Value*() const;
value& operator=(value const& rhs);
bool is_lvalue() const;
bool is_valid() const;
+ operator bool() const;
value& assign(value const& rhs);
@@ -76,6 +76,8 @@
protected:
+ struct to_llvm_value;
+ friend struct to_llvm_value;
friend struct llvm_compiler;
value(
@@ -88,12 +90,16 @@
private:
+ operator llvm::Value*() const;
+
llvm::Value* v;
bool is_lvalue_;
llvm::IRBuilder<>* builder;
};
///////////////////////////////////////////////////////////////////////////
+ // The Basic Block (light abstraction of an LLVM::BasicBlock)
+ ///////////////////////////////////////////////////////////////////////////
struct function;
struct basic_block
@@ -118,6 +124,8 @@
};
///////////////////////////////////////////////////////////////////////////
+ // The Function (light abstraction of an LLVM::Function)
+ ///////////////////////////////////////////////////////////////////////////
struct llvm_compiler;
struct function
@@ -218,9 +226,6 @@
llvm::IRBuilder<>& builder()
{ return llvm_builder; }
- vmachine& vm; // $$$ protected for now $$$
- llvm::FunctionPassManager fpm; // $$$ protected for now $$$
-
private:
friend struct function::to_value;
@@ -234,10 +239,12 @@
void init_fpm();
llvm::IRBuilder<> llvm_builder;
+ vmachine& vm;
+ llvm::FunctionPassManager fpm;
};
///////////////////////////////////////////////////////////////////////////
- // The Compiler
+ // The main compiler. Generates code from our AST.
///////////////////////////////////////////////////////////////////////////
struct compiler : llvm_compiler
{
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