Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Fundamentals of Compiler Design I, Study notes of Compiler Design

A course overview for CSE 110A: Winter 2020 at UC Santa Cruz. It covers the definition of a compiler, its history, and what students will learn in the course. The course requires familiarity with functional programming, datatypes, polymorphism, recursion, and some C programming and assembly. examples of well-known compilers and their key requirements. It could be useful as study notes or a summary for a student preparing for an exam or assignment in a compiler design course.

Typology: Study notes

2019/2020

Uploaded on 05/11/2023

arien
arien 🇺🇸

4.8

(24)

310 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE 110A: Winter 2020!
!
Fundamentals of Compiler
Design I
Owen Arden
UC Santa Cruz
Introduction and Overview
Based on course materials developed by Ranjit Jhala
What!is!a Compiler?
A function that maps an!input!string to an!output!string.
compiler :: String -> String
Typically, the!input!and!output!strings are!“programs”
compiler :: SourceProgram -> TargetProgram
2
What!is!a Compiler?
For example, here are some well-known!compilers
gcc, clang :: C -> Binary -- a.out, .exe
ghc :: Haskell -> Binary
javac :: Java -> JvmByteCode -- .class
scalac :: Scala -> JvmByteCode
ocamlc :: Ocaml -> OcamlByteCode -- .cmo
ocamlopt :: Ocaml -> Binary
gwt :: Java -> JavaScript -- .js
v8 :: JavaScript -> Binary
nasm :: X86 -> Binary
pdftex :: LaTeX -> PDF
pandoc :: Markdown -> PDF | Html | Doc
Key Requirements on output program:
Has the!same meaning!(“semantics”) as input,
Is!executable!in relevant!context!(VM, microprocessor, web browser).
3
pf3
pf4
pf5

Partial preview of the text

Download Fundamentals of Compiler Design I and more Study notes Compiler Design in PDF only on Docsity!

CSE 110A: Winter 2020

Fundamentals of Compiler

Design I

Owen Arden UC Santa Cruz

Introduction and Overview

Based on course materials developed by Ranjit Jhala

What is a Compiler?

A function that maps an input string to an output string. compiler :: String -> String Typically, the input and output strings are “programs” compiler :: SourceProgram -> TargetProgram 2

What is a Compiler?

For example, here are some well-known compilers gcc, ghc clang :::: CHaskell ->-> BinaryBinary -- a.out, .exe javac :: Java -> JvmByteCode -- .class scalac ocamlc :::: ScalaOcaml ->-> JvmByteCodeOcamlByteCode -- .cmo ocamlopt :: Ocaml -> Binary gwt :: Java -> JavaScript -- .js v8 nasm :::: JavaScriptX86 ->-> BinaryBinary pdftex :: LaTeX -> PDF pandoc :: Markdown -> PDF | Html | Doc Key Requirements on output program:

  • Has the same meaning (“semantics”) as input,
  • Is executable in relevant context (VM, microprocessor, web browser).

A Bit of History

Compilers were invented to avoid writing machine code by hand 4 From Binary to FORTRAN

A Bit of History

Richard Hamming – The Art of Doing Science and Engineering, p25: 5 In the beginning we programmed in absolute binary… Finally, a Symbolic Assembly Program was devised – after more years than you are apt to believe during which most programmers continued their heroic absolute binary programming. At the time [the assembler] first appeared I would guess about 1% of the older programmers were interested in it – using [assembly] was “sissy stuff”, and a real programmer would not stoop to wasting machine capacity to do the assembly.

A Bit of History

John A.N. Lee, Dept of Computer Science, Virginia Polytechnical Institute One of von Neumann’s students at Princeton recalled that graduate students were being used to hand assemble programs into binary for their early machine. This student took time out to build an assembler, but when von Neumann found out about it he was very angry, saying that it was a waste of a valuable scientific computing instrument to use it to do clerical work.

How write a Compiler?

General recipe, applies to any large system

- gradually, one feature at a time! We will - Step 1 Start with a teeny tiny language, - Step 2 Build a full compiler for it, - Step 3 Add a few features, - Go to Step 2. (Yes, loops forever, but we will hit Ctrl-C in 10 weeks…) 10

How will we grade?

(30%) Assignments

  • 7 assignments, first one up today
  • All programming
  • Groups of up to 2 (except for HW#0) (30%) Midterm
  • In-class (2-sided “cheat sheet”) (35%) Final
  • 2-sided “cheat sheet” (5%) Quizzes (bring phone or laptop to class)
  • Attempting to answer > 75% questions
  • Starting from next week (5%) Piazza Extra Credit
  • To top-10 best participants 11

Course Outline

Write a compiler for NanoML —> X But Rome wasn’t built in a day … and neither is any serious software. So we will write many compilers:

  • Numbers and increment/decrement
  • Local Variables
  • Nested Binary Operations
  • Booleans, Branches and Dynamic Types
  • Functions
  • Tuples and Structures
  • Lambdas and closures
  • Types and Inference
  • Garbage Collection

What will you learn?

Core principles of compiler construction

  • Managing Stacks & Heap
  • (^) Type Checking
  • Intermediate forms
  • Optimization Several new languages
  • (^) Haskell to write the compiler
  • C to write the “run-time”
  • X86 compilation target More importantly how to write a large program
  • (^) How to use types for design
  • How to add new features / refactor
  • How to test & validate (^13)

What do you need to know?

This 110A uses many concepts from CSE 116

  • Familiarity with Functional Programming
  • Datatypes (e.g. Lists, Trees, ADTs)
  • Polymorphism
  • Recursion
  • HOFs (e.g. map, filter, fold) However: there will be lots of support for those picking up Haskell “as they go” Also depends on CSE 12
  • Experience with some C programming
  • Experience with some assembly (x86) 14

Questions?