Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 103 Engineering Programming Chapter 7 Compiling C Programs Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material.

Similar presentations


Presentation on theme: "ECE 103 Engineering Programming Chapter 7 Compiling C Programs Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material."— Presentation transcript:

1 ECE 103 Engineering Programming Chapter 7 Compiling C Programs Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed by Professor Phillip Wong @ PSU ECE

2 Syllabus What’s This Blue Code? C Programming Cycle Code File Types Compilation Utilities Compilation Flow Compiler Internals Compilers versus Interpreters

3 2 What’s This Blue Code? // Newton's iteration formula: square root r from value v, // with initial guess r0 = v, and subsequent values: // r( n+1 ) = ( r( n ) + v / ( r( n ) ) ) / 2 double root( double v ) { // root double new_r = v; double old_r; do { old_r = new_r; new_r = ( old_r + v / old_r ) / 2.0; } while( fabs( old_r - new_r ) > DELTA ); return new_r; } //end root

4 3 C Programming Cycle Test & Debug Compile & Link Edit Code

5 4 Code File Types Source files contain the C program code. .c extension (file is in text format) Header files can contain prototypes, macros, data type declarations, or code. .h extension (file is in text format) Object files contain intermediate compiled code. .o -or-.obj extension Executable files contain runnable binary code. .out -or-.exe -or- no extension

6 5 Compilation Utilities preprocessor → handles preprocessor directives and expands macro definitions compiler → takes preprocessed source code files and translates them to intermediate code assembler → takes intermediate code files and translates them to binary object code linker → resolves references among the object files and the libraries. It puts all the parts together to create the final executable file

7 6 Compilation Flow prog_1.c prog_2.c prog_3.c etc. Source files prog_1.o prog_2.o prog_3.o etc. Object files prog Executable file stdio stdlib math etc. Library files Compiler PreprocessorLinker prog_1.h prog_2.h prog_3.h etc. User Header files stdio.h stdlib.h math.h etc. Library Header files Assembler

8 7 Compiler Internals Front end  Tokenizes source code using lexical analysis  Parses tokens to check syntax & semantics  Generates intermediate representation IR F Middle end (Yes, counter-intuitive )  Applies optimization techniques to IR F  Generates intermediate representation IR M Back end  Maps IR M to target platform & generates actual code

9 8 Compiler versus Interpreter Compiler:  Code translation occurs at compile-time  Program execution speed is maximized Interpreter:  Translation time and run-time are the same  Thus source translation occurs during run-time  And t ranslation re-occurs each time a program line is executed  Program execution speed may be much slower


Download ppt "ECE 103 Engineering Programming Chapter 7 Compiling C Programs Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material."

Similar presentations


Ads by Google