Search code examples
compiler-constructionllvmprogramming-languages

What is a language frontend?


I am confused about the definition of frontend and backend in the context of programming languages and compilers.

The LLVM compiler infrastructure project is a set of compiler and toolchain technologies, which can be used to develop a front end for any programming language and a back end for any instruction set architecture.

All I find when I search "programming language frontend" is HTML CSS JS, which I know isn't what it refers to in this context. Can anyone explain to me or direct me to right resources?


Solution

  • The front-end of a compiler is the part of the compiler that starts with the raw source code and ends up with some internal representation of what that program "means," stored in some format that allows the rest of the compiler to understand that structure and start generating code. It's where the scanning, parsing, and semantic analysis is (typically) done.

    The back-end of a compiler is the part of the compiler that takes that internal representation and uses it to generate code in some format (assembly, machine code, JVM bytecode, LLVM bitcode, etc.) It usually handles things like optimization, instruction selection, register allocation, etc.

    Some compilers have these two parts broken up into logically separate components. Sometimes they're intertwined. Part of what LLVM aims to do is make it so that you can build a front-end for a new language and then hook it into an existing backend, so you can design a new language and get all the nice optimization work that other folks have done, or build new backends for existing frontends in case you wanted to, say, analyze a program written in some existing language using a new analysis.