I am a newbie to LLVM. My basic need is to parse the Fortran codes. By looking at LLVM website, it seems that LLVM can be used as a library for parsing codes. So could I use it to parse Fortran codes, and extract information about the codes (AST?)?
LLVM is a language-agnostic compiler toolchain that handles program optimization and code generation. It is based on its own internal representation, called LLVM IR, which is then transformed into machine code.
Flang is the Fortran front-end designed for integration with LLVM and suitable for interoperability with Clang/LLVM. Flang consists of two components flang1 and flang2.
LLVM is a compiler backend. The only thing it knows how to parse is LLVM IR - an intermediate language designed to be emitted from programing language frontends. The official frontend for LLVM is Clang, which can handle C, C++ and ObjC. If you're interested in other languages, there's also DragonEgg, which is a LLVM plugin for gcc. It uses gcc's front-end and LLVM as a backend, so it can parse anything gcc knows how to parse. I know that work is being done on making it generate correct code from Ada and Fortran. Here's an excerpt from its page:
Current Status
- Works best with gcc-4.6.
- Fortran works very well. Ada, C and C++ also work well. Ada works poorly with gcc-4.7.
- It can compile a reasonable amount of Obj-C, Obj-C++ and Go.
- It can compile simple Java programs, but they don't execute properly (this is a consequence of the java front-end not supporting GCC's LTO).
- Debug info is poor.
No, LLVM is not a library for parsing Fortran. LLVM is a library for implementing the backend of a compiler. You would need to write the Fortran frontend yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With