krys at polarlights.net
2011-Mar-08 20:47 UTC
[LLVMdev] Using LLVM to convert a language to another language
Hi, Sorry for my newbies questions... but here it is... My goal is to have a "shading language", it is very similar to the "C" language but with special tokens. I have a parser and a lexer done with Lex/bison, once I have lexed/parsed my "shading language" I must create 3 new "source code" in OpenCL. It mean that by example for the following : shader matte(float Kd, color c) { Ci = diffuse(Kd * c); } I have to create 3 methods in OpenCL, by example 1 - matte_sampling 2 - matte_pdf 3 - matte_f Each of theses method is in OpenCL (It is like C too). So, I would like to use LLVM to create an optimized version of my shader code. But once I have the LLVM byte code... how can I parse it "easily" to create my shader code ? NB: also, you can tell me if it is really a good idea ! Thanks
Villmow, Micah
2011-Mar-08 22:53 UTC
[LLVMdev] Using LLVM to convert a language to another language
Probably the easiest way is to take the C backend and modify it to handle the special OpenCL constructs that you generate.> -----Original Message----- > From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] > On Behalf Of krys at polarlights.net > Sent: Tuesday, March 08, 2011 12:48 PM > To: llvmdev at cs.uiuc.edu > Subject: [LLVMdev] Using LLVM to convert a language to another language > > Hi, > > Sorry for my newbies questions... but here it is... > > My goal is to have a "shading language", it is very similar to the "C" > language but with special tokens. > > I have a parser and a lexer done with Lex/bison, once I have > lexed/parsed my "shading language" I must create 3 new "source code" in > OpenCL. > > It mean that by example for the following : > > shader matte(float Kd, color c) > { > Ci = diffuse(Kd * c); > } > > I have to create 3 methods in OpenCL, by example > > 1 - matte_sampling > 2 - matte_pdf > 3 - matte_f > > Each of theses method is in OpenCL (It is like C too). > > So, I would like to use LLVM to create an optimized version of my > shader code. But once I have the LLVM byte code... how can I parse it > "easily" to create my shader code ? > > NB: also, you can tell me if it is really a good idea ! > > Thanks > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Jim Grosbach
2011-Mar-09 16:55 UTC
[LLVMdev] Using LLVM to convert a language to another language
On Mar 8, 2011, at 12:47 PM, krys at polarlights.net wrote:> Hi, > > Sorry for my newbies questions... but here it is... > > My goal is to have a "shading language", it is very similar to the "C" language but with special tokens. > > I have a parser and a lexer done with Lex/bison, once I have lexed/parsed my "shading language" I must create 3 new "source code" in OpenCL. > > It mean that by example for the following : > > shader matte(float Kd, color c) > { > Ci = diffuse(Kd * c); > } > > I have to create 3 methods in OpenCL, by example > > 1 - matte_sampling > 2 - matte_pdf > 3 - matte_f > > Each of theses method is in OpenCL (It is like C too). > > So, I would like to use LLVM to create an optimized version of my shader code. But once I have the LLVM byte code... how can I parse it "easily" to create my shader code ?At a high level, this sounds like like a task better suited for Clang. I'd suggest asking on cfe-dev about source-to-source rewriting. -Jim> > NB: also, you can tell me if it is really a good idea ! > > Thanks > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev