Author Topic: Clang integration?  (Read 35755 times)

Offline infinigon

  • Multiple posting newcomer
  • *
  • Posts: 10
Clang integration?
« on: October 24, 2010, 09:24:07 pm »
Are there any plans for integrating Code::Blocks with Clang? I've only looked over it briefly, but it looks to integrate much more tightly with IDE's, like aiding with static code analysis and transformation
http://clang.llvm.org/features.html#applications

Also, I don't know whether Clang's AST could benefit Code::Blocks' code-completion redesign?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Clang integration?
« Reply #1 on: October 25, 2010, 01:36:57 am »
Not sure How hard to integrate Clang to codeblocks.  :D
Quote
Currently, clang is divided into the following libraries and tool:

    * libsupport - Basic support library, from LLVM.
    * libsystem - System abstraction library, from LLVM.
    * libbasic - Diagnostics, SourceLocations, SourceBuffer abstraction, file system caching for input source files.
    * libast - Provides classes to represent the C AST, the C type system, builtin functions, and various helpers for analyzing and manipulating the AST (visitors, pretty printers, etc).
    * liblex - Lexing and preprocessing, identifier hash table, pragma handling, tokens, and macro expansion.
    * libparse - Parsing. This library invokes coarse-grained 'Actions' provided by the client (e.g. libsema builds ASTs) but knows nothing about ASTs or other client-specific data structures.
    * libsema - Semantic Analysis. This provides a set of parser actions to build a standardized AST for programs.
    * libcodegen - Lower the AST to LLVM IR for optimization & code generation.
    * librewrite - Editing of text buffers (important for code rewriting transformation, like refactoring).
    * libanalysis - Static analysis support.
    * libindex - Cross-translation-unit infrastructure and indexing support.
    * clang - A driver program, client of the libraries at various levels.

seems: librewrite can support code refactoring.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline infinigon

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Clang integration?
« Reply #2 on: October 29, 2010, 02:51:41 pm »
Eh, I just found this from about a year ago:
http://forums.codeblocks.org/index.php?topic=11268.0

Sorry about the redundancy (note to self: GIYF), but still, this would be useful to have, especially for the future as Clang becomes more mature and capable.

Offline reckless

  • Regular
  • ***
  • Posts: 353
Re: Clang integration?
« Reply #3 on: November 11, 2010, 03:40:46 am »
made a build of llvm/llvm-gcc svn and binutils.

includes native python and gdb.

ftp://90.184.233.166:21/LLVM.7z

can be used with msys also if you add the folder to fstab instead of the normal mingw.
like so C:/LLVM. /mingw

for msys autotool based builds you might have to tell the autotools what C and C++ compilers to use like this CC=llvm-gcc CXX=llvm-g++

mingw32-make is not included but the one from mingw site works just fine.

only handles c/c++ and fortran atm. ada cannot be built with gcc-4.5.1 i use to bootstrap as the version of gcc from llvm is a rather ancient one 4.2.1

« Last Edit: November 11, 2010, 03:49:02 am by reckless »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Clang integration?
« Reply #4 on: November 11, 2010, 03:48:54 am »
made a build of llvm/llvm-gcc svn and binutils.

includes native python and gdb.

ftp://90.184.233.166:21/LLVM.7z

can be used with msys also if you add the folder to fstab instead of the normal mingw.
like so C:/LLVM. /mingw

for msys autotool based builds you might have to tell the autotools what C and C++ compilers to use like this CC=llvm-gcc CXX=llvm-g++

mingw32-make is not included but the one from mingw site works just fine.

only handles c/c++ and fortran atm. ada cannot be built with gcc-4.5.1 i use to bootstrap as the version of gcc from llvm is a rather ancient one 4.2.1



So, this is a full package that can replace the mingw-gcc ??

Edit: it was 120M + .... to big...

BTW:
the link should be fixed to:

ftp://90.184.233.166:21/LLVM.7z
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline reckless

  • Regular
  • ***
  • Posts: 353
Re: Clang integration?
« Reply #5 on: November 11, 2010, 03:53:10 am »
yep noticed fixed the link ;)

if you only need c/c++ or fortran support it can replace the standard mingw.

there are a few quirks to get codeblocks running with it for one gcc and g++ are prefixed with llvm- so need to tell it that. the same goes for gfortran.

sorry about the size ill see if i can hammer it down some but this is mostly a test build.
« Last Edit: November 11, 2010, 04:10:28 am by reckless »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Clang integration?
« Reply #6 on: November 11, 2010, 07:46:34 am »
Did you enable optimization ?
Otherwise, you create a debug-build and that's mauch larger (and slower).

There is switch for the configure-script, I don't know exactly how it is named (not on my system), but I guess it was --enable-optimization.
Search for it with ./configure --help .

If you use makefiles directly, the switch is named ENABLE_OPTIMIZED=1 .

Offline reckless

  • Regular
  • ***
  • Posts: 353
Re: Clang integration?
« Reply #7 on: November 11, 2010, 09:46:38 am »
aye was set as debug compiling a release version now :) should be up in some hours unless i run into problems.

Offline joubertdj

  • Multiple posting newcomer
  • *
  • Posts: 120
Re: Clang integration?
« Reply #8 on: November 11, 2010, 10:11:35 am »
For those of you who don't know ... Clang has successfully compiled the Linux Kernel ... hmmm ...
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2010-October/011711.html ... whoop ...

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Clang integration?
« Reply #9 on: November 11, 2010, 12:22:24 pm »
For those of you who don't know ... Clang has successfully compiled the Linux Kernel ... hmmm ...
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2010-October/011711.html ... whoop ...
great compiler!!!

I have one glance on the source code of clang's lexer and parser. it was quite (too) complex. All the lexer/ parser was hand-written. and their hand-written lexer doesn't distinguish with any identifiers and keyword. instead, they use an identifier hash table, once the lexer get a general identifier, it will be looked up in the identifier table to see if it was a keyword or a macro definition or a new real identifier...

the code snippet of parsing a function declaration was more than 800 lines. :shock:

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline reckless

  • Regular
  • ***
  • Posts: 353
Re: Clang integration?
« Reply #10 on: November 11, 2010, 12:54:10 pm »
its good :) but a major pain in the beep beep! to compile.

the gcc to bootstrap it has neither thread nor exception support so im bootstrapping my version with gcc-4.5.1 and while it does seem to work for c/c++ and fortran ada barfs loudly because the ada compiler changed a lot from the 4.2 version (bad casing of NUL) error.

also bootstrapping the gcc 4.2 compiler seems to run out of stack space (pthread bug i suspect) so can only make a none bootstrapped gcc for the moment.

theres been some work to use gcc's plugin system with a plugin called dragonegg to use the llvm compiler with unmodified gcc 4.5. unfortunatly its linux/mac only atm so were stuck with the old gcc for the moment.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Clang integration?
« Reply #11 on: November 11, 2010, 12:59:48 pm »
Please keep in mind, that this is the C::B forum, not the clang/llvm forum.

Offline reckless

  • Regular
  • ***
  • Posts: 353
Re: Clang integration?
« Reply #12 on: November 11, 2010, 01:34:04 pm »
ofc. jens sorry about that.

still building so ill post when theres a new release for those who want to try it with cb.

Offline reckless

  • Regular
  • ***
  • Posts: 353
Re: Clang integration?
« Reply #13 on: November 12, 2010, 03:12:55 am »
ok new version up, same download link.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Clang integration?
« Reply #14 on: November 12, 2010, 03:17:02 am »
ok new version up, same download link.

strange, when I click on the ftp link, it opened a folder... (windows firefox)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.