[cfe-dev] Support a new C-like language by libclang?

Sean Silva chisophugis at gmail.com
Wed Jan 7 22:09:18 PST 2015


On Wed, Jan 7, 2015 at 6:16 PM, Jovi Zhangwei <jovi.zhangwei at gmail.com>
wrote:

> Yes, I just need C, completely don‘t need any C++ and other extension,
> clang internal looks have more complexity than I need.
>
> Do you have any guide on how to write C frontend based on LLVM? any
> project can take reference other than clang?
>
FYI, clang started out as a C compiler before it grew C++ support. Check
back (way back) in the history.

-- Sean Silva


> I looked into tcc before, but it seems it's not fully C completely.
> actually I'm totally new to compiler, but I really want to build that
> tracing tool based on bpf.
>
> Thank you.
>
> Jovi
>  On Jan 7, 2015 5:58 PM, "Reid Kleckner" <rnk at google.com> wrote:
>
>> If you just want C and not C++ or other language extensions, then I think
>> writing your own C frontend IR is probably easier than reusing Clang's. All
>> the complexity in Clang comes from C++, really, and the frontend isn't
>> designed to be pluggable like the optimizer is.
>>
>> On Wed, Jan 7, 2015 at 5:36 PM, Jovi Zhangwei <jovi.zhangwei at gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> On Wed, Jan 7, 2015 at 4:55 PM, mats petersson <mats at planetcatfish.com>
>>> wrote:
>>> > And you want to DO what, exactly with it, after you have parsed it?
>>> >
>>> > And does your script use ALL of C's functionality?
>>> >
>>>
>>> Some functions will be compiled to bpf bytecode and inject into
>>> kernel(run in kernel), some functions
>>> in one script will be compiled to x86_64 instruction which run in
>>> userspace.
>>>
>>> (There have one project called ktap, www.ktap.org, mainly purpose for
>>> kernel dynamic tracing, probably you knows systemtap,
>>>  ktap is similar like systemtap. There will have a bpf backend for
>>> llvm, now I'm just think how to integrating ktap and bpf)
>>>
>>> Some basic requirement of this new frontend is:
>>> 1). support new keywords, like trace, trace_end, argstr.
>>> 2). support table syntax, also multiple key table. C language don't
>>> support table syntax at all.
>>> 3). data structure info retrieve from debuginfo(like vmlinux), not
>>> defined in script or header file.
>>>
>>> Do you think my design can achieve by change some part of clang(lex,
>>> etc) and reuse rest library of clang? or have better solution?
>>>
>>> Thank you.
>>>
>>> > --
>>> > Mats
>>> >
>>> > On 7 January 2015 at 23:58, Jovi Zhangwei <jovi.zhangwei at gmail.com>
>>> wrote:
>>> >> Hi,
>>> >>
>>> >> On Tue, Jan 6, 2015 at 4:16 PM, Nikola Smiljanic <popizdeh at gmail.com>
>>> wrote:
>>> >>> Yes, you'd have to modify clang to lex/parse/sema your
>>> >>> keywords/extensions/whatever.
>>> >>>
>>> >>
>>> >> Is there have a simple solution without change to much on clang?
>>> >>
>>> >> In my case, I want to parse script which have custom language based on
>>> >> C. The script just like below:
>>> >>
>>> >> trace syscalls:*
>>> >> {
>>> >>     print(argstr);
>>> >> }
>>> >>
>>> >> Actually there just have few new keywords(like trace, trace_end) in
>>> >> this new language, all others in C.
>>> >>
>>> >> Any guide on this?
>>> >>
>>> >> Thank you.
>>> >>
>>> >>> On Wed, Jan 7, 2015 at 10:15 AM, Jovi Zhangwei <
>>> jovi.zhangwei at gmail.com>
>>> >>> wrote:
>>> >>>>
>>> >>>> Hi,
>>> >>>>
>>> >>>> I'm new to clang world, here I have one question about libclang or
>>> >>>> libtooling, I would be very appreciate if anyone can help me.
>>> >>>>
>>> >>>> Currently I want to develop a new language, which is C like, just
>>> some new
>>> >>>> syntax sugars on top of C language, I can modify clang lexer code
>>> to make
>>> >>>> that, or I can use translator, but if this requirement can be done
>>> by
>>> >>>> libclang or libtooling, that's perfect simple for me.
>>> >>>>
>>> >>>> My direct impression is there have no way to change language syntax
>>> by
>>> >>>> libclang/libtooling, libclang/libtooling only can parse and
>>> analysis on C
>>> >>>> family language, no chance to support other language by library, is
>>> this
>>> >>>> correct?
>>> >>>>
>>> >>>> Thank you.
>>> >>>>
>>> >>>> Jovi
>>> >>>>
>>> >>>> _______________________________________________
>>> >>>> cfe-dev mailing list
>>> >>>> cfe-dev at cs.uiuc.edu
>>> >>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>> >>>>
>>> >>>
>>> >> _______________________________________________
>>> >> cfe-dev mailing list
>>> >> cfe-dev at cs.uiuc.edu
>>> >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>>
>>
>>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150107/618999fd/attachment.html>


More information about the cfe-dev mailing list