Compilers
Studying compilers on basis of C and Java compiler. Stack, JIT compilers, pragmas, interpreted VS compiled languages.
14 flashcards · Computer Science · by lakesare
What's a JIT compiler?
Just-in-time compiler compiles a program during its execution rather than prior to execution. JIT compiler continuously analyses the code being executed and identifies parts of the code where the speedup gained from compilation would outweigh the overhead of compiling that code.
What's IR (Intermediate Representation)?
There are different CPU architectures, and we'd need to translate our high-level language into machine code for all of these types. To make code that will run on all CPU architectures, some compilers compile from language to IR first (frontend), and then from IR to machine code (backend).
Name 2 examples of IR (Intermediate Representation).
C: Though not explicitly designed as an intermediate language, C's nature as an abstraction of assembly made it a popular IR Java Bytecode Links: list of IR languages
What's a directive / directive pragma?
Language construct that specifies how a compiler should process its source. Directives are not part of the grammar of a programming language, and may vary from compiler to compiler.
Name 2 examples of directives/pragmas.
Js: "use strict" C: #define, #include
Why does directive also get called 'pragma' sometimes?
'pragma' means 'action' in Greek. Used to direct the actions of the compiler in particular ways. Links: stack overflow answer
What exactly is pushed onto the stack?
A frame. When a function begins its execution, a new frame is pushed onto the stack. That frame is used to store local variables, parameters and a return address (of the calling function). If function a calls function b, then a new frame for function b is pushed onto the stack above the frame for function a. When function b completes, its frame is popped off, and execution continues from the return address stored in it. Source: good article on stack
We have a function a which calls function b. How does the stack look while function b is executed?
function b function a _________
C compiler (GCC) is a de-facto standard for learning compilers. Name 4 stages GCC goes through in order to compile hello.c. #include <stdio.h> int main() { printf("hello, world\n") }
preprocessor: takes directives (pragmas, e.g. #include), and inserts them directly into the text. compiler: translates c code into assembly. assembler: assembler (compiler for assembler) translates assembly into a machine code. linker: printf function is located in a separate printf.o file (available to C by default), and linker inserts printf.o into our hello.o. The hello.o file is a binary file whose bytes encode machine language instructions rather than characters. If we were to view hello.o…
What's object code? After what compilation stage do we have a relocatable object file?
Object code is a machine binary code hello.o, produced after preprocessor => compiler => assembler stage.
What's relocation?
When linker replaces symbolic references or names of libraries with actual usable addresses in memory. Usually relocatable object files contain not only some binary sections (containing machine code and/or data) but also some relocation sections containing a sequence of relocation directives. It is typically done by the linker during compilation (at compile time), although it can be done at runtime by a relocating loader.
Why is a file resulting from Assembler called relocatable object file hello.o?
relocatable: because this file contains relocation directives, and can be relocated by linker. object: as opposed to 'source' code, as if that was our objective.
Name 2 portions of memory.
Stack (same as call stack) Heap (free-floating region of memory and is larger) Each thread gets a stack, while there's typically only one heap for the application (although it isn't uncommon to have multiple heaps for different types of allocation). One important detail is that the stack for storing objects is the same as the run-time call stack. The run-time stack, consisting of stack frames, is responsible for program execution and function calls. A stack frame contains all the data for one f…
Heap as data structure VS heap as a memory management area?
Heap as a tree data structure: Heap as a memory management area: