[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Libjit-developers] What happens if I branch to a label that has not
From: |
Paul Brannan |
Subject: |
Re: [Libjit-developers] What happens if I branch to a label that has not been defined? |
Date: |
Fri, 14 Sep 2007 09:59:23 -0400 |
User-agent: |
Mutt/1.5.10i |
On Fri, Sep 14, 2007 at 09:37:30AM +0700, Aleksey Demakov wrote:
> If I got correctly what you want perhaps we need
> to add a function that explicitly converts a given
> instruction into a no-op.
Or provide an interface to detach_block and attach_block that provide
more options for moving code around within the function.
> Meanwhile it might work if you insert a label just
> after the branch and in case you need to remove
> the branch you generate an extra code that
> branches back to that label:
>
> br label_1
> label_2:
> ...
> return
> label_1:
> br label_2
>
> These extra branches should be removed by
> the branch optimization pass and will not get
> into the final code.
I'm not sure whether or not that would work for what I'm trying to do.
I'll have to give it some thought.
The reason I asked the question in the first place is that I have DSL on
the Ruby side of ruby-libjit that looks like this:
class Function
def if(cond, end_label = Label.new, &block)
false_label = Label.new
insn_branch_if_not(cond, false_label)
block.call
insn_branch(end_label)
insn_label(false_label)
return If.new(self, end_label)
end
class If
def initialize(function, end_label)
@function = function
@end_label = end_label
end
def else(&block)
block.call
return self
end
def end
@function.insn_label(@end_label)
end
end
end
So I can write:
Function.compile(context, signature) do |f|
f.if(f.get_param(0) == f.const(Type::INT, 1)) {
f.debug_print("arg0 == 1")
} .else {
f.debug_print("arg0 != 1")
} .end
f.insn_return
end
f.apply(1) #=> "arg0 == 1"
I was trying to eliminate the need to call #end to finish the
conditional.
Paul