What instruction are you trying to call? On Sun, May 17, 2015 at 11:21 AM, andrew cooke <[email protected]> wrote:
> > ah, thanks - that issue is a huge help. > > On Sunday, 17 May 2015 11:38:20 UTC-3, Isaiah wrote: >> >> i am going to look at the implementing code and work out what is >>> generated, i think, and then ask llvmdev for help. >> >> >> You should start with lli and make sure that you are writing the IR >> correctly; if it works in lli, then the issue is with Julia (as is most >> likely -- llvmcall is kind of brittle). >> >> >>> here's something i don't understand about the context in which the llvm >>> ir is inserted. "declare" instructions don't seem to be accepted, for >>> example. >> >> >> See >> https://github.com/JuliaLang/julia/pull/8740 >> >> >> On Sun, May 17, 2015 at 10:17 AM, andrew cooke <[email protected]> wrote: >> >>> thanks, but the reason i need lvmcall is because i want to call a >>> specific intel instruction (which llvm actually supports - i've found the >>> patch for it). but before i do that i am trying to just get "something" to >>> work, and printf seemed like a good intermediate goal. >>> >>> i am going to look at the implementing code and work out what is >>> generated, i think, and then ask llvmdev for help. there's something i >>> don't understand about the context in which the llvm ir is inserted. >>> "declare" instructions don't seem to be accepted, for example. once i can >>> pin that down i think i can ask a sensible question on llvmdev... >>> >>> cheers, >>> andrew >>> >>> >>> On Saturday, 16 May 2015 22:01:25 UTC-3, Yichao Yu wrote: >>> >>>> On Sat, May 16, 2015 at 5:01 PM, andrew cooke <[email protected]> >>>> wrote: >>>> > >>>> > Does anyone have a working example that calls printf via llvmcall? >>>> > >>>> > I realise I'm uncomfortably inbetween llvmdev and julia-users, but >>>> I'm >>>> > asking here first because I suspect my limitations are still more >>>> > julia-related. >>>> > >>>> > In particular, >>>> > >>>> > julia> g() = Base.llvmcall(""" >>>> > call i32 (i8*, ...)* @printf(i8* c"hello world\00") >>>> > ret""", >>>> > Void, Tuple{}) >>>> > g (generic function with 2 methods) >>>> > >>>> > julia> g() >>>> > ERROR: error compiling g: Failed to parse LLVM Assembly: >>>> > julia: llvmcall:3:35: error: expected string >>>> > call i32 (i8*, ...)* @printf(i8* c"hello world >>>> > ^ >>>> > >>>> > seems like it's *almost* there...? >>>> > >>>> > Thanks, >>>> > Andrew >>>> > >>>> > (I suspect I also need something other than @printf, like >>>> > IntrinsicsX86.printf or something, but I can't find where I saw an >>>> example >>>> > like that... Related, declare doesn't seem to be accepted, or >>>> assignment to >>>> > global vsariables. But I am completely new to all this...) >>>> > >>>> >>>> I was also interested in knowning how to use `llvmcall` in general but >>>> at least for this limited case, (and I guess you probably know >>>> already) it is easier to user `ccall` >>>> >>>> ```julia >>>> julia> ccall(:printf, Int, (Ptr{Cchar},), "hellow world\n") >>>> hellow world >>>> 13 >>>> ``` >>>> >>> >>
