Lexical Analysis in GCC for C language - gcc

I am looking for the lexical analyzer code in GCC for C language but unable to find. I found lex.c but the comment inside the file says it works for C++.
Please provide any link(If available) which can help.

The parser is reading a stream of tokens from the preprocessor, in directory libcpp/
Read the documentation and slides available on the GCC resource center (IIT Bombay, India)
If you wish to extend GCC, consider using MELT
BTW, use a more recent version of GCC, e.g. 4.9

Related

how to integrate fairplay license sdk by using golang?

I have downloaded FairPlay Streaming Server SDK, but it is written by C++, and I use golang as programming language, how can I integrate it?
Thanks for your help.
You would need to write a wrapper in C, from which you can call your C++ SDK.
(example here)
Then using cgo, you can compile, linking to your SDK library.
See a concrete example in "Linking Dynamic C++ Libraries with Go" from Brand Aaron Taylor
Specifying the location of this file requires custom flags for the compiler command.
With a bit of searching I was able to find the -L flag, which, similarly to the -I flag, specifies a search directory for the compilation process as a whole.
By specifying both Drafter’s build directory and dynamic library itself, we had a compiling C program!
gcc ctest.o -L./drafter/build/out/Release/ -ldrafter -o ctest

Can I use GCC compiler AND Clangd Language Server?

I am working on a project that uses a GCC library (SFML), which is not available for clang, as far as I know. I am using COC with vim for code completions, but for C++ it needs clangd. Is there a way to use GCC as my compiler, but still use the clangd language server?
I have also heard that there may be a way to make clang recognize GCC libraries/headers, but I've never been able to make it work right. If somebody could point me in the right direction there that would be helpfull too. But I'm used to GCC (I've been using it since I started programming C++), so being able to use clangd and GCC would be preferable.
Yes it is. I do it with ccls (which is clang based as well).
Given my installation of clang is not the standard one (I compile it, tune it to use libc++ by default, and I install it somewhere in my personal space) I have to inject paths to header files known by clang but unknown by other clang based tools.
I obtain them with
clang++ -E -xc++ - -Wp,-v < /dev/null
Regarding the other options related to the current project, I make sure to have a compile_commands.json compilation database (generated by CMake, or bear if I have no other choice), and ccls can work from there. I expect clangd to be quite similar in these aspects.
Ops, answered the wrong question.
But for those who use ccls:
create a .ccls file in your project directory and append --gcc-toolchain=/usr to it.
use this tool to generate a compile_commands.json file
see https://github.com/MaskRay/ccls/wiki/FAQ#compiling-with-gcc

What is OPENMP_DIRECTIVE_EXT and how to declare a new one?

The freecompilercamp.org has a very good tutorial about defining OpenMP Directives.
However, apart from this I was unable to find any good resource on how to add new directives,
clauses etc for OpenMP in llvm.
Moreover, I am interested in knowing more about what OPENMP_DIRECTIVE_EXT is and how to declare a new one? Any guide about this or how the User defined Reduction is implemented would be helpful. Even a link to the patchset or pull request that added this functionality would be helpful.
Thank you!
Citing the openMP spec -
Compilers can therefore ignore OpenMP directives and conditionally compiled code if support of the OpenMP API is not provided or enabled. A compliant implementation must provide an option or interface that ensures that underlying support of all OpenMP directives and OpenMP conditional compilation mechanisms is enabled. In the remainder of this document, the phrase OpenMP compilation is used to mean a compilation with these OpenMP features enabled.
In other words, the directives are a programming tool to allow compilers to compile code under it if an existing implementation for such a directive exists and otherwise falls back to compiling the code as normal for a cpu. I also found this IBM page which explains the pragmas a bit further.
I didn't really find any other tutorial than the one you mention. You should probably look at the clang tutorials in that site. I think the OpenMP directives are implemented as a clang frontend parser. You need to parse the structured code inside the directive and add a new AST node. This will be compiled to LLVM IR and passed to LLVM where you can do more transformations to the IR.

How does one find what C++11 features have been implemented given a GLIBCXX version

Given a GLIBCXX version of the stdc++ library (example GLIBCXX_3.4.17) given this version, where would one find documentation which specifies what features have been implemented?
Further is there a way to which given the SO NAME version will provide the this same document.
I am working on an embedded system which has an existing version of libstdc++; unfortunately the supplied cross compiler (g++) is at a greater version than what the stdc++ library on the target supports. Upgrading the stdc++ library on the target is not an option. Before I write a lot of code, to only find that it does not run on the target; I would like to know beforehand what is and is not supported.
I have found the GNU Documentation to be useful; however, I am hoping there is a document in which one can get what has been implemented given the symbol version and/or the SO NAME and I just have somehow missed it.
Thanks for any help in advance
given this version, where would one find documentation which specifies what features have been implemented?
You can map a GLIBCXX_A.B.C symbol version to a GCC release by checking
https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html
N.B. that won't be precise, because e.g. GCC 5.1 and GCC 5.2 both use GLIBCXX_3.4.21 in the shared library. To tell them apart check the __GLIBCXX__ macro defined by the libstdc++ headers, also documented on that page.
The manuals for libstdc++ releases are at
gcc.gnu.org/onlinedocs/gcc-[X.Y.Z]/libstdc++/manual/
e.g.
https://gcc.gnu.org/onlinedocs/gcc-5.3.0/libstdc++/manual/
Within that manual is a status table showing the implementation status for each standard, the table for C++11 support in GCC 5.3.0 is at
https://gcc.gnu.org/onlinedocs/gcc-5.3.0/libstdc++/manual/manual/status.html#status.iso.2011
Before I write a lot of code, to only find that it does not run on the target; I would like to know beforehand what is and is not supported.
It's not enough to simply avoid using features that aren't supported by the library on the target system. If you link with the cross-compiler then it will depend on the libstdc++.so from that cross-compiler, and will fail to run on the target system if it only has an older libstdc++.so
Upgrading the stdc++ library on the target is not an option.
Then you either need to link statically (creating large executables) or downgrade your cross-compiler to match the target. Or at least force it to use the headers and dynamic library from the same version as found on the target (by overriding the header and library search paths to point to copies of the older files), although that might not work, as the newer g++ might not be able to compile the older headers if they contain some invalid C++ that the older g++ didn't diagnose.

Can the gcc preprocessor know if a plugin has been loaded

Assume I have a plugin and I load it using the gcc -fplugin=foo.so...
Is there any preprocessor symbol or macro that gets defined that I can use to conditionally compile out language features that plugin requires.
Of course I can provide that macro on the command line, e.g -Dplugin_foo_loaded.
But it would be better if such macros were generated by the act of loading the plugin.
What is the answer?
Currently (GCC 4.9) you cannot do that, since there is no plugin hooks related to the preprocessor.
I guess that the simplest way would be to pass a -DMYPLUGIN. Or define some builtin in your plugin.
PS. If you are looking for some tutorial material about GCC plugins consider also MELT and some documentation there (e.g. slides on GCC plugins thru the MELT example; Linux Foundation, march 2014)

Resources