DOC PREVIEW
UW-Madison CS 536 - Compilers Enable Programming Languages

This preview shows page 1-2-3-4-5-6 out of 18 pages.

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

Unformatted text preview:

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 interpreted.23CS 536 Spring 2008©Formats of TranslatedProgramsCompilers differ in the formatof the target code theygenerate. Target formats maybe categorized as assemblylanguage, relocatable binary,or memory-image.• Assembly Language (Symbolic)FormatA text file containing assemblersource code is produced. Anumber of code generationdecisions (jump targets, longvs. short address forms, and soon) can be left for theassembler. This approach isgood for instructional projects.24CS 536 Spring 2008©Generating assembler codesupports cross-compilation(running a compiler on onecomputer, while its target is asecond computer). Generatingassembly language alsosimplifies debugging andunderstanding a compiler(since you can see thegenerated code).C rather than a specificassembly language cangenerated, using C as a“universal assembly language.”25CS 536 Spring 2008©C is far more machine-independent than anyparticular assembly language.However, some aspects of aprogram (such as the run-timerepresentations of program anddata) are inaccessible using Ccode, but readily accessible inassembly language.26CS 536 Spring 2008©• Relocatable Binary FormatTarget code may be generatedin a binary format withexternal references and localinstruction and data addressesare not yet bound. Instead,addresses are assigned relativeto the beginning of the moduleor relative to symbolicallynamed locations. A linkage stepadds support libraries andother separately compiledroutines and produces anabsolute binary programformat that is executable.27CS 536 Spring 2008©• Memory-Image (Absolute Binary)FormCompiled code may be loadedinto memory and immediatelyexecuted. This is faster thangoing through the intermediatestep of link/editing. The abilityto access library andprecompiled routines may belimited. The program must berecompiled for each execution.Memory-image compilers areuseful for student anddebugging use, where frequentchanges are the rule andcompilation costs far exceedexecution costs.28CS 536 Spring 2008©Java is designed to use andshare classes defined andimplemented at a variety oforganizations. Rather than usea fixed copy of a class (whichmay be outdated), the JVMsupports dynamic linking ofexternally defined classes.When first


View Full Document

UW-Madison CS 536 - Compilers Enable Programming Languages

Download Compilers Enable Programming Languages
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 Compilers Enable Programming Languages 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 Compilers Enable Programming Languages 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?