I’m a computer science student. Currently we are learning the Ada programming language. The compilation is very straightforward for now: gnatmake source.adb so I don’t have any idea of what gnatmake actually does or is (script? binary? something else?). Anyway, I was wondering in what language the compiler itself (also the parser, if written in a different language) was coded?
I’m a computer science student. Currently we are learning the Ada programming language. The
Share
Your typical compiler comes with two basic tools: The compiler and the linker.
The comiler translates the language source code (text) into machine language object files (binaries). It will perhaps include some object relocation information, to help the linker.
The linker takes multiple machine language object files and links them all together into one machine executable.
You typically have to tell the compiler where to find all the extra files it needs to perform a compilation, and then you have to tell the linker the name of every file needed to link together your executable, including and system libraries you might use. This can get pretty dang complicated, which is where build tools like
makecome in.Ada is defined in such a way that there should always be some kind of librarian to keep track of this information for you. Thus to perform a complete build of your system, all you should have to do is ask the librarian to build your executable for you.
The way
Gnathandles this librarian functionality is that it assumes (unless told otherwise) that there’s a one-to-one correspondence between Ada unit (package) names and source and object file names. Thus if it needs the specification forXto complete a compile, it knows to go toX.adsto find the specification file. When its time to link, it knows it will find its object file inX.o. This means that if it needs a routine from packageXto successfully link, it knows exactly how to do that for you, where a dumb linker would just fail and tell you the semi-encrypted name of the “symbol” it can’t find.So instead of typing out individual compile commands for every unit in your program like you’d have to do with C or C++, you can just use
gnatmaketo compile every unit the given executable name would need, and then link them together for you. One step, easy peasy.As for your last question, the Gnat Ada compiler is written almost entirely in Ada. It is fairly typical for compilers to be written in their own language, and compiled using themselves. This is called self-hosting.
However, it is tied into GCC, so the parts that are common with GCC (the part that translates from tree format to target object code and the linker I believe) are written in C.