OK, I thought what Tim wrote might be helpful for me so I took the expression generated by this and stuck it into a function which I then compiled to see the code_native (I want to see code_native/code_lowered of the final generated function - not the Julia code from a generated function which I did already know how to do, nor the native/llvm code of the *code generator* which is what code_native and code_llvm give in 0.4.3).
Anyway, my approach seemed to collide with another issue I had (https://groups.google.com/forum/#!topic/julia-users/4uDLFZUF_xM) where Expr(:meta,:inline) seems to behave different depending on if a function is generated (its OK) or not (must use @inline). So, to reiterate, is there a reliable way to get the native code of a generated function? Tim specifically - is there a mangled function name or something I might be able to hook code_native into? Thank you all for your help and patience. Andy On Wednesday, February 10, 2016 at 10:27:38 PM UTC+10, Tim Holy wrote: > > Slightly modifying an example from the docs: > > julia> function mysub2ind_gen(N) > ex = :(I[$N] - 1) > for i = N-1:-1:1 > ex = :(I[$i] - 1 + dims[$i]*$ex) > end > return :($ex + 1) > end > mysub2ind_gen (generic function with 1 method) > > julia> @generated function mysub2ind{N}(dims::NTuple{N}, I::Integer...) > length(I) == N || error("wrong number of indexes") > mysub2ind_gen(N) > end > mysub2ind (generic function with 1 method) > > julia> mysub2ind_gen(3) > :(((I[1] - 1) + dims[1] * ((I[2] - 1) + dims[2] * (I[3] - 1))) + 1) > > julia> mysub2ind((5,5,5), 1, 2, 3) > 56 > > julia> sub2ind((5,5,5), 1, 2, 3) > 56 > > > On Wednesday, February 10, 2016 03:31:15 AM Jeffrey Sarnoff wrote: > > Tim -- would you repeat that with some simple content illustrative of a > > useful use for generation --- thx > > > > On Wednesday, February 10, 2016 at 5:27:12 AM UTC-5, Tim Holy wrote: > > > On Tuesday, February 09, 2016 08:52:22 PM Andy Ferris wrote: > > > > What's the best way to find the code generated by a @generated > function? > > > > > > This isn't easy unless you (or the author) provides a function to do > so: > > > @generated function foo(x, y) > > > > > > foo_generator(x, y) > > > > > > end > > > > > > function foo_generator{Tx,Ty}(::Type{Tx}, ::Type{Ty}) > > > > > > # generate and return the expression for the function body > > > > > > end > > > > > > Then you can call `foo_generator(typeof(x), typeof(y))` to see the > > > returned > > > code. > > > > > > Best, > > > --Tim > >