> Does the IL "switch" instruction do what you want?
>
> In any case, unlike asm, with IL any jump target must be defined at compile
> time - you can't arbitrarily jump to just any IL instruction based on a
> variable, otherwise there would be no guarantee of the stack. But you can
> create a pre-defined jump table using the "switch" instruction.
Hello Tim,
Thank you for your reply. I guess a pre-defined jump table would do it,
but that's a bit of a hack. For example, to implement this pseudo-asm :
print "start"
push 0
label1:
print "sub proc"
jump to next if top of stack == 0
ret
next:
print "after"
call label1
print "end"
ret
(which would print start,sub proc,after,sub proc,end), I would have, in
the code generation for the "ret" after the conditional jump, to store
"the line number" to jump to, and then to emit the switch itself.
That means storing at generation time n "after-call" labels (one for
each "call") and generating a n-possibilities switch for each ret-from-sub.
Optimization could help reducing this number, by analyzing the code paths.
It is possible, but I'm just wondering how big the overhead will be.
Thank you for your help :)
Nicolas.
Tim C - 25 Jan 2006 04:28 GMT
A couple things in asm won't translate to MSIL:
The IL "call" instruction can only target the beginning of a method
The IL "br__" instructions (jumping) can only jump inside the same method
Translating the asm to IL looks something like:
ldstr "start"
call print
ldc.i4.0
IL_label1:
ldstr "sub proc"
call print
dup
brfalse IL_next
ret
IL_next:
ldstr "after"
call print
; call IL_label1 ; <-- no such instruction; can't call to within method
ldstr "end"
call print
ret
Is there a way to design it such that you only call to methods and only jump
within a method?
-Tim
>> Does the IL "switch" instruction do what you want?
>>
[quoted text clipped - 34 lines]
>
> Nicolas.