DOC PREVIEW
UW-Madison CS 536 - Lecture 02

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

10CS 536 Spring 2008©CompilersCompilers are fundamental tomodern computing.They act as translators,transforming human-orientedprogramming languages intocomputer-oriented machinelanguages.To most users, a compiler canbe viewed as a “black box” thatperforms the transformationshown below.ProgrammingLanguageMachineLanguageCompiler11CS 536 Spring 2008©A compiler allowsprogrammers to ignore themachine-dependent details ofprogramming.Compilers allow programs andprogramming skills to bemachine-independent.Compilers also aid in detectingprogramming errors (which areall too common).Compiler techniques also helpto improve computer security.For example, the Java BytecodeVerifier helps to guarantee thatJava security rules are satisfied.12CS 536 Spring 2008©Compilers currently help inprotection of intellectualproperty (using obfuscation)and provenance (throughwatermarking).13CS 536 Spring 2008©History of CompilersThe term compiler was coinedin the early 1950s by GraceMurray Hopper. Translation wasviewed as the “compilation” ofa sequence of machine-language subprograms selectedfrom a library.One of the first real compilerswas the FORTRAN compiler ofthe late 1950s. It allowed aprogrammer to use a problem-oriented source language.14CS 536 Spring 2008©Ambitious “optimizations” wereused to produce efficientmachine code, which was vitalfor early computers with quitelimited capabilities.Efficient use of machineresources is still an essentialrequirement for moderncompilers.15CS 536 Spring 2008©Compilers EnableProgramming LanguagesProgramming languages areused for much more than“ordinary” computation.• TeX and LaTeX use compilers totranslate text and formattingcommands into intricatetypesetting commands.• Postscript, generated by text-formatters like LaTeX, Word, andFrameMaker, is really aprogramming language. It istranslated and executed by laserprinters and document previewersto produce a readable form of adocument. A standardizeddocument representation languageallows documents to be freelyinterchanged, independent of how16CS 536 Spring 2008©they were created and how theywill be viewed.• Mathmatica is an interactive systemthat intermixes programming withmathematics; it is possible to solveintricate problems in both symbolicand numeric form. This systemrelies heavily on compilertechniques to handle thespecification, internalrepresentation, and solution ofproblems.• Verilog and VHDL support thecreation of VLSI circuits. A siliconcompiler specifies the layout andcomposition of a VLSI circuit mask,using standard cell designs. Just asan ordinary compiler understandsand enforces programminglanguage rules, a silicon compilerunderstands and enforces thedesign rules that dictate thefeasibility of a given circuit.17CS 536 Spring 2008©• Interactive tools often need aprogramming language to supportautomatic analysis andmodification of an artifact.How do you automatically filter orchange a MS Word document? Youneed a text-based specification thatcan be processed, like a program,to check validity or produce anupdated version.18CS 536 Spring 2008©When do We Run a Compiler?• Prior to executionThis is standard. We compile aprogram once, then use it repeatedly.• At the start of each executionWe can incorporate values known atthe start of the run to improveperformance.A program may be partially complied,then completed with values set atexecution-time.• During executionUnused code need not be compiled.Active or “hot” portions of a programmay be specially optimized.• After executionWe can profile a program, looking forheavily used routines, which can bespecially optimized for later runs.19CS 536 Spring 2008©What do Compilers Produce?Pure Machine CodeCompilers may generate codefor a particular machine, notassuming any operating systemor library routines. This is “purecode” because it includesnothing beyond the instructionset. This form is rare; it issometimes used with systemimplementation languages, thatdefine operating systems orembedded applications (like aprogrammable controller). Purecode can execute on barehardware without dependenceon any other software.20CS 536 Spring 2008©Augmented Machine CodeCommonly, compilers generatecode for a machine architectureaugmented with operatingsystem routines and run-timelanguage support routines.To use such a program, aparticular operating systemmust be used and a collectionof run-time support routines(I/O, storage allocation,mathematical functions, etc.)must be available. Thecombination of machineinstruction and OS and run-timeroutines define a virtualmachine—a computer thatexists only as a hardware/software combination.21CS 536 Spring 2008©Virtual Machine CodeGenerated code can consistentirely of virtual instructions(no native code at all). Thisallows code to run on a varietyof computers.Java, with its JVM (Java VirtualMachine) is a great example ofthis approach.If the virtual machine is keptsimple and clean, its interpretercan be easy to write. Machineinterpretation slows executionby a factor of 3:1 to perhaps10:1 over compiled code.A “Just in Time” (JIT) compilercan translate “hot” portions ofvirtual code into native code tospeed execution.22CS 536 Spring 2008©Advantages of VirtualInstructionsVirtual instructions serve avariety of purposes.• They simplify a compiler byproviding suitable primitives (suchas method calls, stringmanipulation, and so on).• They aid compiler transportability.• They may decrease in the size ofgenerated code since instructionsare designed to match a particularprogramming language (forexample, JVM code for Java).Almost all compilers, to agreater or lesser extent,generate code for a virtualmachine, some of whoseoperations must be


View Full Document

UW-Madison CS 536 - Lecture 02

Download Lecture 02
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 02 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 02 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?