Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could I use LLVM for parsing Fortran?

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?)?

like image 541
Li Dong Avatar asked Apr 20 '13 09:04

Li Dong


People also ask

Does LLVM compile to machine code?

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.

What is flang compiler?

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.


2 Answers

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.
like image 75
Eli Bendersky Avatar answered Sep 21 '22 04:09

Eli Bendersky


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.

like image 29
joey Avatar answered Sep 19 '22 04:09

joey