Hi, I'm new in LLVM project , I have to write a compiler frond-end (based on LLVM) in C++ to support my programming language .Am I have to implement support for each architecture or LLVM has libraries that can do this for me ? (btw I don't want to support architecture that LLVM don't) . does LLVM has helper functions to create objects in heap ? if not is it good idea to use C++11 smart pointer to do memory management operations (at least in the first versions of my language ) ? Sorry,if some questions are silly , but I'm still beginner in compiler's world . Thanks.
On Wed, Feb 18, 2015 at 8:34 AM, Ahmed Taj elsir <meedo456123 at gmail.com> wrote:> Hi, > > I'm new in LLVM project , I have to write a compiler frond-end (based > on LLVM) in C++ to support my programming language .Am I have to > implement support for each architecture or LLVM has libraries that > can do this for me ? (btw I don't want to support architecture that > LLVM don't) . >Most of the architecture-specific code is in LLVM, away from anything you'll have to worry about. Some stuff ends up leaking up into your front-end, but not much if you're starting with a simple language and don't need to interoperate with existing C libraries, for example. (if your language needs to be able to call into existing C (or, worse, C++) libraries then you'll need to worry about the ABI, and that's a fair amount of work/code/knowledge that needs to reside in your frontend)> does LLVM has helper functions to create objects in heap ?In your target program? No, there's not much/any help there - you just call malloc/free (or op new/delete) in your LLVM IR like you would in a simple C program.> if not is it good idea to use C++11 smart pointer to do memory management > operations (at least in the first versions of my language ) ? >Inside your target program? You won't, presumably, have access to the C++ standard library in your language so you won't be able to use its convenient smart pointers. You can make your own in your new programming language, depending on what language features you have to work with. The LLVM Kaleidoscope tutorials might give you some idea of how to get started writing a compiler using LLVM. - David> > Sorry,if some questions are silly , but I'm still beginner in compiler's > world . > > Thanks. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150218/a0e1bf25/attachment.html>
On Wed, Feb 18, 2015 at 9:15 AM, Ahmed Taj elsir <meedo456123 at gmail.com> wrote:> Thanks you for help , David. > > Can you briefly explain this: > " Most of the architecture-specific code is in LLVM, away from > anything you'll have to worry about.Most of this is in LLVM's backends - that's where things like CPU instruction set, register files, etc, etc, are - so your frontend doesn't need to know about much of that.> Some stuff ends up leaking up > into your front-end " >The stuff that you end up having to worry about in the frontend mostly relates to the ABI things I mentioned earlier - knowing that on certain platforms you need to put the function parameters in a certain order/structure so you can interoperate with existing C code, etc. If you don't need that interoperability, you don't have to worry about that.> > Thanks again. > > On 2/18/15, David Blaikie <dblaikie at gmail.com> wrote: > > On Wed, Feb 18, 2015 at 8:34 AM, Ahmed Taj elsir <meedo456123 at gmail.com> > > wrote: > > > >> Hi, > >> > >> I'm new in LLVM project , I have to write a compiler frond-end (based > >> on LLVM) in C++ to support my programming language .Am I have to > >> implement support for each architecture or LLVM has libraries that > >> can do this for me ? (btw I don't want to support architecture that > >> LLVM don't) . > >> > > > > Most of the architecture-specific code is in LLVM, away from anything > > you'll have to worry about. Some stuff ends up leaking up into your > > front-end, but not much if you're starting with a simple language and > don't > > need to interoperate with existing C libraries, for example. (if your > > language needs to be able to call into existing C (or, worse, C++) > > libraries then you'll need to worry about the ABI, and that's a fair > amount > > of work/code/knowledge that needs to reside in your frontend) > > > > > >> does LLVM has helper functions to create objects in heap ? > > > > > > In your target program? No, there's not much/any help there - you just > call > > malloc/free (or op new/delete) in your LLVM IR like you would in a > simple C > > program. > > > > > >> if not is it good idea to use C++11 smart pointer to do memory > management > >> operations (at least in the first versions of my language ) ? > >> > > > > Inside your target program? You won't, presumably, have access to the C++ > > standard library in your language so you won't be able to use its > > convenient smart pointers. You can make your own in your new programming > > language, depending on what language features you have to work with. > > > > The LLVM Kaleidoscope tutorials might give you some idea of how to get > > started writing a compiler using LLVM. > > > > - David > > > > > >> > >> Sorry,if some questions are silly , but I'm still beginner in compiler's > >> world . > >> > >> Thanks. > >> _______________________________________________ > >> LLVM Developers mailing list > >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >> > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150218/39bf4b11/attachment.html>
Ahmed, You do not have to write code for each target architecture. Rather, when you invoke LLVM to generate your code, you specify the requested target. The best way to proceed here is to look at the sources for llc and opt. There is no well-defined API for ahead-of-time code generation, so you'll need to use llc/opt as examples. Be aware that the API will change from release to release. In particular, the change from 3.5.1 to 3.6.0 is significant. For my project I call out to my own runtime to perform tasks such as memory allocation. You can't really use C++ smart pointers in your generated code. What you are generating most closely resembles assembly language - you have nothing high-level. Here, I would recommend that you define the interface between your generated code and runtime library in terms of plain C functions using the standard C calling convention. You would then implement your own garbage collector in your runtime. If you don't want to do that, then consider using the Boehm-Demers-Weiser conservative collector. It requires no special support from LLVM. On Wed, Feb 18, 2015 at 11:34 AM, Ahmed Taj elsir <meedo456123 at gmail.com> wrote:> Hi, > > I'm new in LLVM project , I have to write a compiler frond-end (based > on LLVM) in C++ to support my programming language .Am I have to > implement support for each architecture or LLVM has libraries that > can do this for me ? (btw I don't want to support architecture that > LLVM don't) . > > does LLVM has helper functions to create objects in heap ? if not is > it good idea to use C++11 smart pointer to do memory management > operations (at least in the first versions of my language ) ? > > Sorry,if some questions are silly , but I'm still beginner in compiler's > world . > > Thanks. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150218/d7cd55a9/attachment.html>
I'm also a beginner, so asking on this beginner thread -- is there anything in addition to the C ABI that one needs to worry about? I imagine a C ABI gives lots of free libraries to integrate into your language, etc. Also the C ABI change on platforms? I thought C Calling convention was the same on all platforms. On Wed, Feb 18, 2015 at 9:23 AM, David Blaikie <dblaikie at gmail.com> wrote:> > > On Wed, Feb 18, 2015 at 9:15 AM, Ahmed Taj elsir <meedo456123 at gmail.com> > wrote: > >> Thanks you for help , David. >> >> Can you briefly explain this: >> " Most of the architecture-specific code is in LLVM, away from >> anything you'll have to worry about. > > > Most of this is in LLVM's backends - that's where things like CPU > instruction set, register files, etc, etc, are - so your frontend doesn't > need to know about much of that. > > >> Some stuff ends up leaking up >> into your front-end " >> > > The stuff that you end up having to worry about in the frontend mostly > relates to the ABI things I mentioned earlier - knowing that on certain > platforms you need to put the function parameters in a certain > order/structure so you can interoperate with existing C code, etc. > > If you don't need that interoperability, you don't have to worry about > that. > > >> >> Thanks again. >> >> >> On 2/18/15, David Blaikie <dblaikie at gmail.com> wrote: >> > On Wed, Feb 18, 2015 at 8:34 AM, Ahmed Taj elsir <meedo456123 at gmail.com >> > >> > wrote: >> > >> >> Hi, >> >> >> >> I'm new in LLVM project , I have to write a compiler frond-end (based >> >> on LLVM) in C++ to support my programming language .Am I have to >> >> implement support for each architecture or LLVM has libraries that >> >> can do this for me ? (btw I don't want to support architecture that >> >> LLVM don't) . >> >> >> > >> > Most of the architecture-specific code is in LLVM, away from anything >> > you'll have to worry about. Some stuff ends up leaking up into your >> > front-end, but not much if you're starting with a simple language and >> don't >> > need to interoperate with existing C libraries, for example. (if your >> > language needs to be able to call into existing C (or, worse, C++) >> > libraries then you'll need to worry about the ABI, and that's a fair >> amount >> > of work/code/knowledge that needs to reside in your frontend) >> > >> > >> >> does LLVM has helper functions to create objects in heap ? >> > >> > >> > In your target program? No, there's not much/any help there - you just >> call >> > malloc/free (or op new/delete) in your LLVM IR like you would in a >> simple C >> > program. >> > >> > >> >> if not is it good idea to use C++11 smart pointer to do memory >> management >> >> operations (at least in the first versions of my language ) ? >> >> >> > >> > Inside your target program? You won't, presumably, have access to the >> C++ >> > standard library in your language so you won't be able to use its >> > convenient smart pointers. You can make your own in your new programming >> > language, depending on what language features you have to work with. >> > >> > The LLVM Kaleidoscope tutorials might give you some idea of how to get >> > started writing a compiler using LLVM. >> > >> > - David >> > >> > >> >> >> >> Sorry,if some questions are silly , but I'm still beginner in >> compiler's >> >> world . >> >> >> >> Thanks. >> >> _______________________________________________ >> >> LLVM Developers mailing list >> >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> >> > >> > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150218/425df2d7/attachment.html>