1 Introduction
Le cours de programmation s'étend tout au long de la 1ère année à
Cachan. Vous aurez à y faire plusieurs projets. Le tout premier
d'entre eux commence le mardi 27 septembre 2005, et est à rendre le
vendredi 14 octobre 2005.
Il s'agit d'écrire un compilateur pour un sous-ensemble strict du
langage C, que nous appellerons C--. Le langage cible sera
l'assembleur x86. Votre compilateur sera écrit en
OCaml.
Voici un exemple de programme que votre compilateur devrait compiler:

Ce programme, qui sera un de nos exemples le premier jour de cours
(vendredi 30 septembre 2005) code la commande Unix cat.
Au passage, j'ai évidemment fait le projet avant vous. Voici ce que
mon compilateur produit:
.globl main
.type main,@function
main:
pushl %ebp
movl %esp, %ebp
subl $4, %esp
subl $4, %esp
movl $0x1, %eax
pushl %eax
movl (%esp), %eax
movl %eax, 0x-4(%ebp)
jmp .label_1
.label_1:
movl 0x-4(%ebp), %eax
pushl %eax
movl 0x8(%ebp), %eax
pushl %eax
popl %ebx
popl %eax
cmp %ebx, %eax
jl .label_2
movl $0x0, %eax
jmp .label_3
.label_2:
movl $0x1, %eax
.label_3:
pushl %eax
popl %eax
cmp $0x0, %eax
jne .label_4
jmp .label_5
.label_4:
subl $4, %esp
movl $.label_6, %eax
pushl %eax
movl 0xc(%ebp), %eax
pushl %eax
movl 0x-4(%ebp), %eax
pushl %eax
popl %ebx
popl %eax
movl (%eax, %ebx, 4), %ecx
pushl %ecx
call fopen
addl $0x8, %esp
movl (%esp), %eax
movl %eax, 0x-1-4(%ebp)
jmp .label_7
.label_7:
movl 0x-1-4(%ebp), %eax
pushl %eax
call fgetc
addl $0x4, %esp
movl (%esp), %eax
movl %eax, 0x-8(%ebp)
movl $0x1, %eax
pushl %eax
popl %eax
negl %eax
pushl %eax
popl %ebx
popl %eax
cmp %ebx, %eax
je .label_8
movl $0x0, %eax
jmp .label_9
.label_8:
movl $0x1, %eax
.label_9:
pushl %eax
popl %eax
cmp $0x0, %eax
jne .label_10
movl $0x1, %eax
pushl %eax
jmp .label_11
.label_10:
movl $0x0, %eax
pushl %eax
.label_11:
popl %eax
cmp $0x0, %eax
jne .label_12
jmp .label_13
.label_12:
push stdout
movl 0x-8(%ebp), %eax
pushl %eax
call fputc
addl $0x8, %esp
jmp .label_7
.label_13:
movl 0x-1-4(%ebp), %eax
pushl %eax
call fclose
addl $0x4, %esp
movl 0x-4(%ebp), %eax
pushl %eax
movl (%esp), %eax
addl $0x1, %eax
movl %eax, 0x-4(%ebp)
jmp .label_1
.label_5:
push stdout
call fflush
addl $0x4, %esp
movl $0x0, %eax
pushl %eax
call exit
addl $0x4, %esp
.label_6:
.string "r"
.align 4
Ceci peut vous sembler bien mystérieux. C'est normal! Ça le sera
moins après le premier cours.