today ’ s topic

14
Today Today s Topic s Topic Breakdown of CC script Breakdown of CC script

Upload: lorenzo-romero

Post on 04-Jan-2016

22 views

Category:

Documents


4 download

DESCRIPTION

Today ’ s Topic. Breakdown of CC script. Today ’ s Objectives. Within context of “ compiling ” C program Define actions of linker, compiler, assembler, OS, macro preprocessor, loader Draw block diagram showing order of linker, compiler, assembler, OS, macro preprocessor, loader - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Today ’ s Topic

TodayToday’’s Topics Topic

Breakdown of CC scriptBreakdown of CC script

Page 2: Today ’ s Topic

TodayToday’’s Objectivess Objectives

Within context of Within context of ““compilingcompiling”” C program C program Define actions of linker, compiler, assembler, Define actions of linker, compiler, assembler, OS, macro preprocessor, loaderOS, macro preprocessor, loader

Draw block diagram showing order of linker, Draw block diagram showing order of linker, compiler, assembler, OS, macro preprocessor, compiler, assembler, OS, macro preprocessor, loaderloader

Explain why runtime stack needed for CExplain why runtime stack needed for C Draw logical division of memory into Draw logical division of memory into stack, heapstack, heap

Compare and contrast stack and heapCompare and contrast stack and heap For C program, indicate which variables For C program, indicate which variables are stored in heap; in stack; in neitherare stored in heap; in stack; in neither

Page 3: Today ’ s Topic

Breaking Down CCBreaking Down CC

source

Preprocessed

SourceASM

O

B

J

E

C

T

.s

.o

Preprocessor

Compiler

Assembler

LinkerLoader

Executablea.out

Executable

Program

In Memory

Page 4: Today ’ s Topic

Breaking Down CCBreaking Down CC

source

Preprocessed

SourceASM

O

B

J

E

C

T

.s

.o

Preprocessor

Compiler

Assembler

LinkerLoader

Executablea.out

Executable

Program

In Memory

Page 5: Today ’ s Topic

C Preprocessor (cpp)C Preprocessor (cpp)

Pass over sourcePass over source Insert included filesInsert included files Perform macro substitutionsPerform macro substitutions

Define macrosDefine macros #define NUM 100#define NUM 100 #define xx(v,name,op,metrics) \ #define xx(v,name,op,metrics) \ v=xxinit(op,name,IR->metrics)v=xxinit(op,name,IR->metrics)

gcc –E example.c sends preprocessor gcc –E example.c sends preprocessor output to stdoutoutput to stdout

Page 6: Today ’ s Topic

Breaking Down CCBreaking Down CC

source

Preprocessed

SourceASM

O

B

J

E

C

T

.s

.o

Preprocessor

Compiler

Assembler

LinkerLoader

Executablea.out

Executable

Program

In Memory

Page 7: Today ’ s Topic

CompilerCompiler

gcc actually name of a scriptgcc actually name of a script Compiler translates one language to Compiler translates one language to another (or the same???)another (or the same???)

gcc compiler translates C to gcc compiler translates C to assemblerassembler

gcc –S example.c gcc –S example.c ““savessaves”” example.s example.s Compiler consists ofCompiler consists of

ParserParser Code generationCode generation MysticismMysticism

Page 8: Today ’ s Topic

Breaking Down CCBreaking Down CC

source

Preprocessed

SourceASM

O

B

J

E

C

T

.s

.o

Preprocessor

Compiler

Assembler

LinkerLoader

Executablea.out

Executable

Program

In Memory

Page 9: Today ’ s Topic

AssemblerAssembler

Another translator ??? (Another translator ??? (asas example.s)example.s)

Assembler to (binary) objectAssembler to (binary) object Why not compile straight to Why not compile straight to binary?binary?

gcc –c example.c to gcc –c example.c to ““savesave”” object object NM to look at object (nm NM to look at object (nm example.o)example.o)

Page 10: Today ’ s Topic

Breaking Down CCBreaking Down CC

source

Preprocessed

SourceASM

O

B

J

E

C

T

.s

.o

Preprocessor

Compiler

Assembler

LinkerLoader

Executablea.out

Executable

Program

In Memory

Page 11: Today ’ s Topic

LinkerLinker

Combine objects, both user .o Combine objects, both user .o files and libraries, make an files and libraries, make an executableexecutable

gcc *.o –lm yields a.outgcc *.o –lm yields a.out gcc –o myExec *.o –lm gcc –o myExec *.o –lm Use nm to look at objectUse nm to look at object

Page 12: Today ’ s Topic

Breaking Down CCBreaking Down CC

source

Preprocessed

SourceASM

O

B

J

E

C

T

.s

.o

Preprocessor

Compiler

Assembler

LinkerLoader

Executablea.out

Executable

Program

In Memory

Page 13: Today ’ s Topic

LoaderLoader

Gets an address to place Gets an address to place programprogram

Changes necessary addresses (if Changes necessary addresses (if any)any)

Places code into memory Places code into memory

Page 14: Today ’ s Topic

Operating SystemOperating System

Oversees whole processOversees whole process ““RecognizesRecognizes”” gcc example.c command gcc example.c command Parses flags and argumentsParses flags and arguments Invokes gcc scriptInvokes gcc script Performs memory mangagement Performs memory mangagement (malloc)(malloc)

Chooses Chooses ““addressaddress”” to place program to place program