<<

A allows programmers to ignore the Compilers are fundamental to -dependent details of modern . programming. They act as translators, transforming human-oriented Compilers allow programs and programming languages into programming skills to be -oriented machine machine-independent. languages. To most users, a compiler can be viewed as a “black box” that Compilers also aid in detecting performs the transformation programming errors (which are shown below. all too common).

Compiler techniques also help to improve . Compiler Machine Language For example, the Verifier helps to guarantee that Java security rules are satisfied.

© © CS 536 Spring 2008 10 CS 536 Spring 2008 11

Compilers currently help in History of Compilers protection of intellectual property (using obfuscation) The term compiler was coined and provenance (through in the early 1950s by Grace watermarking). Murray Hopper. Translation was viewed as the “compilation” of a sequence of machine- language subprograms selected from a .

One of the first real compilers was the compiler of the late 1950s. It allowed a programmer to use a problem- oriented source language.

© © CS 536 Spring 2008 12 CS 536 Spring 2008 13 Ambitious “optimizations” were Compilers Enable used to produce efficient Programming Languages , which was vital for early with quite Programming languages are limited capabilities. used for much more than “ordinary” computation. Efficient use of machine • TeX and LaTeX use compilers to translate text and formatting resources is still an essential commands into intricate requirement for modern typesetting commands. compilers. • Postscript, generated by text- formatters like LaTeX, Word, and FrameMaker, is really a programming language. It is translated and executed by laser printers and document previewers to produce a readable form of a document. A standardized document representation language allows documents to be freely interchanged, independent of how

© © CS 536 Spring 2008 14 CS 536 Spring 2008 15

they were created and how they • Interactive tools often need a will be viewed. programming language to support • Mathmatica is an interactive system automatic and that intermixes programming with modification of an artifact. mathematics; it is possible to solve How do you automatically filter or intricate problems in both symbolic change a MS Word document? You and numeric form. This system need a text-based specification that relies heavily on compiler can be processed, like a program, techniques to handle the to check validity or produce an specification, internal updated version. representation, and solution of problems. • Verilog and VHDL support the creation of VLSI circuits. A silicon compiler specifies the layout and composition of a VLSI circuit mask, using standard cell designs. Just as an ordinary compiler understands and enforces programming language rules, a silicon compiler understands and enforces the design rules that dictate the feasibility of a given circuit.

© © CS 536 Spring 2008 16 CS 536 Spring 2008 17 When do We Run a Compiler? What do Compilers Produce?

• Prior to Pure Machine Code This is standard. We compile a program once, then use it repeatedly. Compilers may generate code for a particular machine, not • At the start of each execution assuming any We can incorporate values known at the start of the run to improve or library routines. This is “pure performance. code” because it includes A program may be partially complied, nothing beyond the instruction then completed with values set at set. This form is rare; it is execution-time. sometimes used with system • During execution implementation languages, that Unused code need not be compiled. define operating systems or Active or “hot” portions of a program embedded applications (like a may be specially optimized. programmable controller). Pure • After execution code can execute on bare We can profile a program, looking for hardware without dependence heavily used routines, which can be on any other . specially optimized for later runs.

© © CS 536 Spring 2008 18 CS 536 Spring 2008 19

Augmented Machine Code Code Commonly, compilers generate Generated code can consist code for a machine architecture entirely of virtual instructions augmented with operating (no native code at all). This system routines and run-time allows code to run on a variety language support routines. of computers. To use such a program, a Java, with its JVM (Java Virtual particular operating system Machine) is a great example of must be used and a collection this approach. of run-time support routines (I/O, storage allocation, If the virtual machine is kept mathematical functions, etc.) simple and clean, its must be available. The can be easy to write. Machine combination of machine interpretation slows execution instruction and OS and run-time by a factor of 3:1 to perhaps routines define a virtual 10:1 over compiled code. machine—a computer that A “Just in Time” (JIT) compiler exists only as a hardware/ can translate “hot” portions of software combination. virtual code into native code to speed execution.

© © CS 536 Spring 2008 20 CS 536 Spring 2008 21 Advantages of Virtual Instructions Virtual instructions serve a variety of purposes. • They simplify a compiler by providing suitable primitives (such as method calls, string manipulation, and so on). • They aid compiler transportability. • They may decrease in the size of generated code since instructions are designed to match a particular programming language (for example, JVM code for Java).

Almost all compilers, to a greater or lesser extent, generate code for a virtual machine, some of whose operations must be interpreted.

© CS 536 Spring 2008 22