Blocks

11 views
Skip to first unread message

Douglas Camata

unread,
Feb 22, 2012, 5:08:19 PM2/22/12
to ruby-llvm
Hello folks, I'm combining llvm-gcc and treetop to a compiler's paper
at college and I have a few simple questions.

I have a function, defined like this:

@function = @module.functions.add("main", [LLVM::Int], LLVM::Int)

How do I define and store a block in some object without using the
"do" way? I'll need this to send the block to many different classes
of my project, so they can add statements to the same block.

Just to help you understand what I want, in some old API it was like
this:

@entry_block = @function.create_block.builder

Jeremy Voorhis

unread,
Feb 22, 2012, 5:50:09 PM2/22/12
to ruby...@googlegroups.com
Hi Douglas,

You can see an example of this at [1].

For convenience, I host a (hopefully) up to date copy of the api docs [2], but there are cases where you may prefer to consult the source. The api in question is defined at [3].

Finally, the old api you refer to is actually Tom Bagby's llvmruby. As you can see [4], this project has not been updated in roughly 3 years and only supports LLVM 2.4. I created ruby-llvm as a separate project because llvmruby had become inactive. Although they had done a fine job, I strongly prefer to use Ruby's foreign function interface instead of C for creating bindings for such a large and moving target as LLVM.

Hope that helps,

Jeremy

Douglas Camata

unread,
Feb 22, 2012, 8:44:01 PM2/22/12
to ruby...@googlegroups.com
Another noob question, I'm trying to alloc and store a value in a double, doing like this:

  double = builder.alloca(LLVM::Double.type)
  builder.store(1.0, double)

This gives me the following exception:

  ArgumentError: :pointer argument is not a valid pointer
  from /Users/douglascamata/.rvm/gems/ruby-1.9.3-p0@compiler/gems/ruby-llvm-3.0.0.beta/lib/llvm/core/builder.rb:397:in `LLVMBuildStore'

Please, a light.

Thanks
--
Douglas Camata
Graduando em Ciência da Computação (UENF)

Skype: douglas_camata
-----------------------------------
Linux User #509211

Douglas Camata

unread,
Feb 22, 2012, 8:46:42 PM2/22/12
to ruby...@googlegroups.com
Just to complement: already trying changing LLVM:Double.type just to LLVM::Double and it didn't work too.

Ary Borenszweig

unread,
Feb 22, 2012, 8:50:46 PM2/22/12
to ruby...@googlegroups.com

I'm not on the computer right night, but I think that instead of 1.0 it should be something like LLVM::Double.new(1.0) or something similar (check which class is an llvm double... you need to pass an instance of an llvm value, not a ruby value). By the way,  stumbled upon this error many times. I think a ruby double should be accepted.

On Feb 22, 2012 10:46 PM, "Douglas Camata" <d.ca...@gmail.com> wrote:

Just to complement: already trying changing LLVM:Double.type just to LLVM::Double and it didn't work too.



On Wed, Feb 22, 2012 at 11:44 PM, Douglas Camata <d.ca...@gmail.com> wrote:
>

> Another noob ques...

Ary Borenszweig

unread,
Feb 22, 2012, 8:52:48 PM2/22/12
to ruby...@googlegroups.com

Ummm... I think LLVM::Int64.new or similar... maybe just LLVM::Int64(1.0)

On Feb 22, 2012 10:50 PM, "Ary Borenszweig" <a...@esperanto.org.ar> wrote:

I'm not on the computer right night, but I think that instead of 1.0 it should be something like LLVM::Double.new(1.0) or something similar (check which class is an llvm double... you need to pass an instance of an llvm value, not a ruby value). By the way,  stumbled upon this error many times. I think a ruby double should be accepted.


>
> On Feb 22, 2012 10:46 PM, "Douglas Camata" <d.ca...@gmail.com> wrote:
>

> Just to complement: ...

Douglas Camata

unread,
Feb 22, 2012, 8:54:43 PM2/22/12
to ruby...@googlegroups.com
LLVM::Double(1.0) worked. Thank you for the extremely fast help.

Douglas Camata

unread,
Feb 22, 2012, 9:07:08 PM2/22/12
to ruby...@googlegroups.com
I'm really sorry, but how I put a terminator to a basic block?

Ary Borenszweig

unread,
Feb 22, 2012, 9:10:44 PM2/22/12
to ruby...@googlegroups.com
The terminators are described here:


In ruby-llvm they are LLVM::Bulder#ret, LLVM::Builder#ret_void (thought passing nil to ret is the same, it seems), and others :-)
--
Ary Borenszweing         Manas Technology Solutions
[ar.phone]                      5258.5240       #ARY(279)
[us.phone]                      312.612.1050    #ARY(279)
[email]                         aboren...@manas.com.ar
[web]                           www.manas.com.ar
[blog]                           weblogs.manas.com.ar/ary

Douglas Camata

unread,
Feb 22, 2012, 9:12:36 PM2/22/12
to ruby...@googlegroups.com
Can I add you in google talk or something like that to get help faster? hahahahaha

Ary Borenszweig

unread,
Feb 22, 2012, 9:15:38 PM2/22/12
to ruby...@googlegroups.com
:-D

Sure, this is the email I use for gtalk.
Reply all
Reply to author
Forward
0 new messages