252-210: Compiler Design Fall 2015 Thomas R. Gross - - PowerPoint PPT Presentation

252 210 compiler design fall 2015
SMART_READER_LITE
LIVE PREVIEW

252-210: Compiler Design Fall 2015 Thomas R. Gross - - PowerPoint PPT Presentation

252-210: Compiler Design Fall 2015 Thomas R. Gross Computer Science Department ETH Zurich, Switzerland Rule 1 Peace in the lecture hall


slide-1
SLIDE 1

252-­‑210: ¡Compiler ¡Design ¡ Fall ¡2015 ¡

Thomas ¡R. ¡Gross ¡ Computer ¡Science ¡Department ¡ ETH ¡Zurich, ¡Switzerland ¡

slide-2
SLIDE 2
slide-3
SLIDE 3

Rule ¡1 ¡ ¡ ¡

  • Peace ¡in ¡the ¡lecture ¡hall ¡ ¡ ¡

4 ¡

slide-4
SLIDE 4
slide-5
SLIDE 5

Course ¡structure ¡

  • You ¡will ¡not ¡learn ¡this ¡material ¡from ¡lectures ¡alone ¡
  • Homework ¡essenDal ¡

10 ¡

slide-6
SLIDE 6

Homework ¡

  • Core ¡element ¡of ¡the ¡course ¡
  • You ¡will ¡build ¡a ¡compiler ¡
  • More ¡on ¡this ¡topic ¡(organizaDon, ¡constraints, ¡etc) ¡tomorrow ¡

11 ¡

slide-7
SLIDE 7
slide-8
SLIDE 8

1.0 ¡IntroducDon ¡

  • A ¡compiler ¡translates ¡a ¡program ¡wri[en ¡in ¡(programming) ¡

language ¡L1 ¡into ¡(programming) ¡language ¡L2. ¡

  • Compilers ¡are ¡programs ¡
  • Implemented ¡in ¡some ¡programming ¡language ¡P ¡
  • Compilers ¡transform ¡programs ¡
  • Many ¡other ¡programs ¡include ¡(small) ¡compilers ¡

16 ¡

slide-9
SLIDE 9

ObservaDons ¡

  • Languages ¡are ¡important ¡
  • Source ¡language ¡L1 ¡
  • Target ¡language ¡L2 ¡
  • Host ¡language ¡P ¡ ¡
  • Programs ¡can ¡be ¡“executed” ¡
  • Program ¡is ¡a ¡sequence ¡of ¡expressions ¡ ¡E1, ¡E2, ¡… ¡
  • A ¡processor ¡contains ¡state ¡
  • Each ¡expression ¡Ei ¡may ¡read ¡state, ¡modify ¡state, ¡and ¡determine ¡next ¡

expression ¡Ej ¡– ¡expression ¡execu+on ¡

  • A ¡special ¡expression ¡Estop ¡indicates ¡that ¡program ¡execu+on ¡stops ¡

17 ¡

slide-10
SLIDE 10

Program ¡execuDon ¡

  • ExecuDon ¡(“elaboraDon”) ¡of ¡expressions ¡ ¡E1, ¡E2, ¡… ¡by ¡some ¡

machine ¡M ¡

  • Machine ¡M ¡defined ¡by ¡soVware ¡– ¡“virtual ¡machine” ¡
  • M ¡executed ¡L1 ¡(or ¡L2) ¡
  • Machine ¡realized ¡by ¡hardware ¡– ¡physical ¡processor ¡
  • …. ¡
  • Expressions ¡ ¡E1, ¡E2, ¡… ¡also ¡referred ¡to ¡as ¡“statements” ¡or ¡

“operaDons” ¡

  • ElaboraDon ¡someDmes ¡referred ¡to ¡as ¡interpreta/on ¡
  • The ¡word ¡interpreta+on ¡some+mes ¡hints ¡at ¡“direct ¡execu+on” ¡ ¡

18 ¡

slide-11
SLIDE 11

Issues ¡ ¡

  • Choices ¡for ¡L1 ¡and ¡L2 ¡

19 ¡

slide-12
SLIDE 12
slide-13
SLIDE 13
slide-14
SLIDE 14

Issues ¡ ¡

  • Choices ¡for ¡L1 ¡and ¡L2 ¡
  • Program ¡wriZen ¡in ¡L1 ¡(PL1) ¡translated ¡into ¡program ¡wriZen ¡in ¡ ¡L2 ¡(PL2) ¡
  • ¡PL1 ¡ ¡PL2 ¡
  • Aspects ¡of ¡translaDon ¡of ¡programs ¡PL1 ¡ ¡PL2 ¡
  • When ¡does ¡it ¡mean ¡that ¡PL1 ¡is ¡a ¡“transla+on” ¡of ¡PL2 ¡
  • PL1 ¡should ¡produce ¡the ¡“same” ¡result ¡as ¡PL2 ¡

24 ¡

slide-15
SLIDE 15

SemanDcs ¡

  • Describes ¡the ¡“meaning” ¡of ¡programs ¡
  • Meaning ¡of ¡program ¡defined ¡by ¡meaning ¡of ¡statements ¡or ¡
  • peraDons ¡
  • Opera+onal ¡seman+cs ¡
  • Abstract ¡machine ¡ ¡A ¡
  • Sequences ¡of ¡ ¡steps ¡interpreted ¡ ¡(“elabora+on”) ¡– ¡effect ¡on ¡A ¡determines ¡meaning ¡
  • Denota+onal ¡seman+cs ¡
  • Mathema+cal ¡construct ¡describes ¡effect ¡– ¡can ¡be ¡manipulated ¡(composi+on, ¡

projec+on, ¡…) ¡

  • Axioma+c ¡seman+cs ¡
  • Asser+ons ¡on ¡program ¡state ¡and ¡rules ¡that ¡describe ¡the ¡effect ¡of ¡opera+ons ¡

25 ¡

slide-16
SLIDE 16

SemanDcs ¡

  • Translated ¡(target) ¡programs ¡PL2 ¡has ¡the ¡same ¡meaning ¡as ¡

the ¡(source) ¡program ¡PL1 ¡

  • At ¡least: ¡computes ¡the ¡same ¡result(s) ¡for ¡all ¡legal ¡inputs ¡
  • Same: ¡must ¡be ¡defined ¡... ¡ ¡
  • What ¡about ¡illegal ¡inputs? ¡
  • What ¡about ¡non-­‑funcDonal ¡properDes? ¡

27 ¡

slide-17
SLIDE 17
slide-18
SLIDE 18
slide-19
SLIDE 19

ComplicaDons ¡

  • L1 ¡and ¡L2 ¡have ¡different ¡resource ¡models ¡
  • L1: ¡ ¡no ¡limit ¡on ¡resources, ¡flexible ¡descripDon ¡
  • L2: ¡finite ¡resources, ¡inflexible ¡descripDon, ¡hardware-­‑based ¡

32 ¡

slide-20
SLIDE 20

ComplicaDons ¡

  • L1: ¡ ¡no ¡limit ¡on ¡resources ¡
  • ∞ ¡number ¡of ¡variables ¡
  • ∞ ¡lines ¡of ¡code ¡
  • ∞ ¡number ¡of ¡methods ¡
  • ∞ ¡data ¡space ¡
  • ∞ ¡nes+ng ¡
  • ∞ ¡characters ¡in ¡var ¡name ¡
  • L2: ¡finite ¡resources, ¡

inflexible ¡descripDon, ¡ hardware-­‑based ¡

  • Fixed ¡number ¡of ¡registers ¡
  • Limited ¡storage ¡
  • Finite ¡representa+on ¡
  • Machine ¡proper+es ¡maZer ¡
  • Caches ¡
  • TLBs ¡
  • NUMA ¡
  • … ¡

33 ¡

slide-21
SLIDE 21

Compiler ¡task: ¡Translate ¡PL1 ¡ ¡PL2 ¡

  • Management ¡of ¡resources ¡
  • PreservaDon ¡of ¡semanDcs ¡
  • Is ¡meaning ¡defined? ¡
  • For ¡all ¡possible ¡inputs? ¡
  • Check ¡constraints ¡on ¡PL1 ¡
  • Not ¡every ¡program ¡can ¡be ¡translated ¡
  • Not ¡every ¡aspect ¡can ¡be ¡checked ¡by ¡compiler ¡
  • Escape: ¡compiler ¡inserts ¡code ¡into ¡PL2 ¡to ¡check ¡proper+es ¡of ¡program ¡

during ¡execu+on ¡(“at ¡run+me”) ¡

34 ¡