DV1565 / DV1511:

Compiler and Interpreter Technology

Tuesday, January 17th, 2017

An overview of compilers and their construction.

Table of Contents
BackgroundCourse Structure
OverviewQuick tour of toolchain.

1. Background

2. Background: Inter-dependencies

3. Background: History

4. Background: Relation to other areas

5. Overview

6. Overview: Compilers and Interpreters

%3 input input target target input->target output output source source compiler compiler source->compiler compiler->target target->output %3 input input interpreter interpreter input->interpreter output output source source source->interpreter interpreter->output
%3 input input target target input->target interpreter interpreter input->interpreter output output source source compiler compiler source->compiler source->interpreter compiler->target target->output interpreter->output

7. Overview: Virtual Machines

8. Overview: Representations in Language Processors

9. Overview: Representations in Language Processors

10. Overview: Static and Dynamic Properties

11. Overview: Types

12. Overview: Scoping

13. Overview: Structure

14. Overview: Runtime

Break (15mins)





Intermission

15. Course Structure

16. Course Structure : Local Variations

17. Course Structure : Recent Updates

18. Course Structure : Part I Tasks

19. Expected Workload

20. Collaboration

21. Language

22. Quick tour of the toolchain.

#include<stdio.h> int main(int argc, char **argv) { printf("Hello world\n"); return 0; }

23. Quick tour of the toolchain.

.file "hello.c" .section .rodata .LC0: .string "Hello world" .text .globl main .type main, @function main: .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6
subq $16, %rsp movl %edi, -4(%rbp) movq %rsi, -16(%rbp) movl $.LC0, %edi call puts movl $0, %eax leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE0: .size main, .-main .ident "GCC: (Debian 4.9.2-10) 4.9.2" .section .note.GNU-stack,"",@progbits

24. Quick tour of the toolchain.

0000000: 7f45 4c46 0201 0100 0000 0000 0000 0000 .ELF............ 0000010: 0200 3e00 0100 0000 1004 4000 0000 0000 ..>.......@..... 0000020: 4000 0000 0000 0000 b812 0000 0000 0000 @............... 0000030: 0000 0000 4000 3800 0800 4000 1e00 1b00 ....@.8...@..... 0000040: 0600 0000 0500 0000 4000 0000 0000 0000 ........@....... 0000200: 2f6c 6962 3634 2f6c 642d 6c69 6e75 782d /lib64/ld-linux- 0000210: 7838 362d 3634 2e73 6f2e 3200 0400 0000 x86-64.so.2..... 0000220: 1000 0000 0100 0000 474e 5500 0000 0000 ........GNU..... 00002e0: 006c 6962 632e 736f 2e36 0070 7574 7300 .libc.so.6.puts. 00002f0: 5f5f 6c69 6263 5f73 7461 7274 5f6d 6169 __libc_start_mai 0000300: 6e00 5f5f 676d 6f6e 5f73 7461 7274 5f5f n.__gmon_start__ 0000310: 0047 4c49 4243 5f32 2e32 2e35 0000 0000 .GLIBC_2.2.5.... 0000580: 0148 39eb 75ea 4883 c408 5b5d 415c 415d .H9.u.H...[]A\A] 0000590: 415e 415f c366 662e 0f1f 8400 0000 0000 A^A_.ff......... 00005a0: f3c3 0000 4883 ec08 4883 c408 c300 0000 ....H...H....... 00005b0: 0100 0200 4865 6c6c 6f20 776f 726c 6400 ....Hello world.

24. Quick tour of the toolchain.

0000000000600920 B __bss_start 0000000000600920 b completed.6661 0000000000600910 D __data_start 0000000000600910 W data_start 0000000000400440 t deregister_tm_clones 00000000004004c0 t __do_global_dtors_aux 00000000006006f8 t __do_global_dtors_aux_fini_array_entry 0000000000600918 D __dso_handle 0000000000600708 d _DYNAMIC 0000000000600920 D _edata 0000000000600928 B _end 00000000004005a4 T _fini 00000000004004e0 t frame_dummy 00000000006006f0 t __frame_dummy_init_array_entry 00000000004006e8 r __FRAME_END__ 00000000006008e0 d _GLOBAL_OFFSET_TABLE_ w __gmon_start__ 00000000004003a8 T _init 00000000006006f8 t __init_array_end 00000000006006f0 t __init_array_start 00000000004005b0 R _IO_stdin_used w _ITM_deregisterTMCloneTable w _ITM_registerTMCloneTable 0000000000600700 d __JCR_END__ 0000000000600700 d __JCR_LIST__ w _Jv_RegisterClasses 00000000004005a0 T __libc_csu_fini 0000000000400530 T __libc_csu_init U __libc_start_main@@GLIBC_2.2.5 0000000000400506 T main U puts@@GLIBC_2.2.5 0000000000400480 t register_tm_clones 0000000000400410 T _start 0000000000600920 D __TMC_END__

25. Quick tour of the toolchain.

%3 tu TranslationUnitDecl fdecl FunctionDecl main 'int (int, char **)' tu->fdecl parmd1 argc 'int' fdecl->parmd1 parmd2 argv 'char **' fdecl->parmd2 comp CompoundStmt fdecl->comp call CallExpr 'int' comp->call ret ReturnStmt comp->ret cast1 ImplicitCastExpr 'int (*)(const char *, ...)' call->cast1 cast2 ImplicitCastExpr 'const char *' call->cast2 declref DeclRefExpr 'printf' 'int (const char *, ...)' cast1->declref cast3 ImplicitCastExpr 'char *' cast2->cast3 strlit StringLiteral 'char [13]' 'Hello world ' cast3->strlit intlit IntegerLiteral 0 ret->intlit
#include<stdio.h> int main(int argc, char **argv) { printf("Hello world\n"); return 0; }

26. Quick tour of the toolchain.

27. Roadmap / Structure of a compiler

%3 source source tokens tokens source->tokens scanning parse parse tree tokens->parse parsing ready ready to execute tokens->ready parse->ready IR IR parse->IR semantic analysis IR->IR optimise instructions instructions IR->instructions instruction selection