SlideShare a Scribd company logo
The Compilation Process
From Source to Silicon
How do we go from this?
TO THIS???
Compilation + Linking = Building
The Pipeline
Source program
preprocessing ¯
Source program
compiling ¯
Assembly program
assembling ¯
Machine instructions
linking ¯
Executable code
Lots of stuff
happens here
Loader, processes, OS,
Stacks and Heaps,
Runtimes, exceptions,
CRASH!
Programming..
Xcode, Eclipse,
Sublime Text etc..
Compiling C with GCC
The GNU Compiler Collection originally written as the compiler for the GNU OS. The GNU system was developed to be 100% free
software, free in the sense that it “respects the user’s freedom”. - Richard Stallman
Although originally a compiler for only C, Frontends were developed for a number of languages like C, C++, Obj-C, Fortran, Java, Ada,
Go, etc..
Many processor architectures can be targeted by GCC’s backend. In fact, it supports more build targets than LLVM.
"Once GNU is written, everyone will be able to obtain good
system software free, just like air."
RAW C FILE contains…
Defines, includes (elements preceded by a
pound character), comments, and others will
be processed by the preprocessor.
Preprocessor directives can be used to
achieve a many where the common
principle is first stage text substituton and
manipulation.
After this step, the compilation stages that
follow except pure and valid C code.
“Afunc” function declaration
will be “included” in main.c,
allowing reference to it in main
()’s body.
aFunc’s definition is defined in
aFunc.c. (also compiled
alongside main.c)
“gcc -E main.c -o main.i”
GCC’s Preprocessor replaces Include with our
function declaration, removes comments and
performs other text processing tasks. The scope of
what the preprocessor can do expands to many
topics such as enabling debug printing to
determining the target OS to allow conditional code
sections.
E.G.
#if TARGET_OS_IPHONE
@import UIKit;
#else
@import AppKit;
#endif
~#MACROS_also_Useful ( )
Tokens and Lexical Analysis
Code Generation (in a gigantic nutshell)
After the lexer turns individual lexemes into tokens, the parser performs its language specific
transformation into Abstract Syntax Trees (AST) which are then semantically analyzed and possibly
optimized depending on what flags are set. The parsing stage verifies these syntax trees to check if the
sequence of lexical elements if correct with respect to the grammar of the language. Next, the compiler
either interprets the AST on the fly such as in the case of an interpreted language (Python, Javascript), or
a machine platform is targeted for native code generation.
Typically, interpreted languages allow more platform indifference as an interpreter program which IS
compiled into the machine’s native machine code convert say an “+” operator into the native machines
“Add(i,j)” machine instruction. This results in a potentially very high overhead and therefore a truly
compiled language is typically much faster. In addition, because a fully compiled language sees more of
the program at once, it has the ability to apply more powerful and deep optimizations on the initial code
before compiling down to assembly. With the addition of the notions of bytecode and Virtual machines,
the distinction between interpretation and compilation gets even more complicated...
“gcc -S main.i -o main.s”
“gcc -c main.s -o main.o”
This Object File contains machine code produced by the GCC assembler from the ‘.s’
assembly file. Multiple .o files can be linked by the linker along with static and shared
libraries to produce the final executable image.
“gcc main.o aFunc.o”
Alongside these slides, “aFunc.c” has also been processed in an analogous manner resulting in
aFunc.o. This file, “a.out”, is the executable produced by GCC’s linker program linking these
two object files together into one unit.
Shared Vs. Static Libraries
Comparing Static and Shared Libraries
If every C program required the C standard library in the form of a static library
than the executables would consume a lot of unnecessary disk space , if every
executable has a copy of printf and fopen for example.. If a library is statically
linked, the code representing the library is compiled into the executable via a
library mechanism. (.a on mac, .lib on windows)
Shared libraries modularize these reusable components and allow multiple
program binaries to link against them at runtime. Shared libraries not only
decrease the size of the dependent program on disk, but allow these programs
which link against them to benefit from improvements made to the shared library.
Modern Compilers and You
LLVM
Some interesting facts about Clang
- Clang is designed as an API from its inception, allowing it to be reused by source analysis tools, refactoring, IDEs (etc)
as well as for code generation. GCC is built as a monolithic static compiler, which makes it extremely difficult to use
as an API and integrate into other tools. Further, its historic design and current policy makes it difficult to decouple
the front-end from the rest of the compiler.
- Clang does not implicitly simplify code as it parses it like GCC does. Doing so causes many problems for
source analysis tools: as one simple example, if you write "x-x" in your source code, the GCC AST will
contain "0", with no mention of 'x'. This is extremely bad for a refactoring tool that wants to rename 'x'.
The compilation process

More Related Content

What's hot

loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
Temesgen Molla
 
Enums in c
Enums in cEnums in c
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
Neeru Mittal
 
C basics
C   basicsC   basics
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
programming9
 
System Programming Overview
System Programming OverviewSystem Programming Overview
System Programming Overview
Dattatray Gandhmal
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
Neeru Mittal
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
Rai University
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
Venkata.Manish Reddy
 
The Phases of a Compiler
The Phases of a CompilerThe Phases of a Compiler
The Phases of a Compiler
Radhika Talaviya
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
Akhil Kaushik
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
MOHIT TOMAR
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
Tanzeela_Hussain
 
Types of Compilers
Types of CompilersTypes of Compilers
Types of Compilers
Hemant Chetwani
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
MOHAMAD NOH AHMAD
 
Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)
guest251d9a
 
File Management in C
File Management in CFile Management in C
File Management in C
Paurav Shah
 

What's hot (20)

loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Enums in c
Enums in cEnums in c
Enums in c
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
 
C basics
C   basicsC   basics
C basics
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
System Programming Overview
System Programming OverviewSystem Programming Overview
System Programming Overview
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
The Phases of a Compiler
The Phases of a CompilerThe Phases of a Compiler
The Phases of a Compiler
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Types of Compilers
Types of CompilersTypes of Compilers
Types of Compilers
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)
 
File Management in C
File Management in CFile Management in C
File Management in C
 

Similar to The compilation process

Language translators
Language translatorsLanguage translators
Language translatorsAditya Sharat
 
Localization (l10n) - The Process
Localization (l10n) - The ProcessLocalization (l10n) - The Process
Localization (l10n) - The Process
Sundeep Anand
 
Source vs object code
Source vs object codeSource vs object code
Source vs object code
Sana Ullah
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
Keroles karam khalil
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
Keroles karam khalil
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
guestd9065
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3
aminmesbahi
 
Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdf
AkarTaher
 
Insight into progam execution ppt
Insight into progam execution pptInsight into progam execution ppt
Insight into progam execution ppt
Keerty Smile
 
2 Programming Language.pdf
2 Programming Language.pdf2 Programming Language.pdf
2 Programming Language.pdf
KINGZzofYouTube
 
COM1407: Introduction to C Programming
COM1407: Introduction to C Programming COM1407: Introduction to C Programming
COM1407: Introduction to C Programming
Hemantha Kulathilake
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
Ramesh Prasad
 
Autotools pratical training
Autotools pratical trainingAutotools pratical training
Autotools pratical training
Thierry Gayet
 
Inside .net framework
Inside .net frameworkInside .net framework
Inside .net frameworkFaisal Aziz
 
A Slice Of Rust - A quick look at the Rust programming language
A Slice Of Rust - A quick look at the Rust programming languageA Slice Of Rust - A quick look at the Rust programming language
A Slice Of Rust - A quick look at the Rust programming language
LloydMoore
 
Dot net
Dot netDot net
Dot net
public
 
Transpilers(Source-to-Source Compilers)
Transpilers(Source-to-Source Compilers)Transpilers(Source-to-Source Compilers)
Transpilers(Source-to-Source Compilers)
Shivang Bajaniya
 

Similar to The compilation process (20)

Language translators
Language translatorsLanguage translators
Language translators
 
Chapter1
Chapter1Chapter1
Chapter1
 
Localization (l10n) - The Process
Localization (l10n) - The ProcessLocalization (l10n) - The Process
Localization (l10n) - The Process
 
Introduction to .net
Introduction to .netIntroduction to .net
Introduction to .net
 
Source vs object code
Source vs object codeSource vs object code
Source vs object code
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3
 
Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdf
 
Insight into progam execution ppt
Insight into progam execution pptInsight into progam execution ppt
Insight into progam execution ppt
 
2 Programming Language.pdf
2 Programming Language.pdf2 Programming Language.pdf
2 Programming Language.pdf
 
COM1407: Introduction to C Programming
COM1407: Introduction to C Programming COM1407: Introduction to C Programming
COM1407: Introduction to C Programming
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
 
Autotools pratical training
Autotools pratical trainingAutotools pratical training
Autotools pratical training
 
Linkers
LinkersLinkers
Linkers
 
Inside .net framework
Inside .net frameworkInside .net framework
Inside .net framework
 
A Slice Of Rust - A quick look at the Rust programming language
A Slice Of Rust - A quick look at the Rust programming languageA Slice Of Rust - A quick look at the Rust programming language
A Slice Of Rust - A quick look at the Rust programming language
 
Dot net
Dot netDot net
Dot net
 
Transpilers(Source-to-Source Compilers)
Transpilers(Source-to-Source Compilers)Transpilers(Source-to-Source Compilers)
Transpilers(Source-to-Source Compilers)
 

Recently uploaded

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 

Recently uploaded (20)

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 

The compilation process

  • 1. The Compilation Process From Source to Silicon
  • 2. How do we go from this?
  • 6. Source program preprocessing ¯ Source program compiling ¯ Assembly program assembling ¯ Machine instructions linking ¯ Executable code Lots of stuff happens here Loader, processes, OS, Stacks and Heaps, Runtimes, exceptions, CRASH! Programming.. Xcode, Eclipse, Sublime Text etc..
  • 7. Compiling C with GCC The GNU Compiler Collection originally written as the compiler for the GNU OS. The GNU system was developed to be 100% free software, free in the sense that it “respects the user’s freedom”. - Richard Stallman Although originally a compiler for only C, Frontends were developed for a number of languages like C, C++, Obj-C, Fortran, Java, Ada, Go, etc.. Many processor architectures can be targeted by GCC’s backend. In fact, it supports more build targets than LLVM. "Once GNU is written, everyone will be able to obtain good system software free, just like air."
  • 8. RAW C FILE contains… Defines, includes (elements preceded by a pound character), comments, and others will be processed by the preprocessor. Preprocessor directives can be used to achieve a many where the common principle is first stage text substituton and manipulation. After this step, the compilation stages that follow except pure and valid C code.
  • 9. “Afunc” function declaration will be “included” in main.c, allowing reference to it in main ()’s body. aFunc’s definition is defined in aFunc.c. (also compiled alongside main.c)
  • 10. “gcc -E main.c -o main.i” GCC’s Preprocessor replaces Include with our function declaration, removes comments and performs other text processing tasks. The scope of what the preprocessor can do expands to many topics such as enabling debug printing to determining the target OS to allow conditional code sections. E.G. #if TARGET_OS_IPHONE @import UIKit; #else @import AppKit; #endif ~#MACROS_also_Useful ( )
  • 11.
  • 12. Tokens and Lexical Analysis
  • 13. Code Generation (in a gigantic nutshell) After the lexer turns individual lexemes into tokens, the parser performs its language specific transformation into Abstract Syntax Trees (AST) which are then semantically analyzed and possibly optimized depending on what flags are set. The parsing stage verifies these syntax trees to check if the sequence of lexical elements if correct with respect to the grammar of the language. Next, the compiler either interprets the AST on the fly such as in the case of an interpreted language (Python, Javascript), or a machine platform is targeted for native code generation. Typically, interpreted languages allow more platform indifference as an interpreter program which IS compiled into the machine’s native machine code convert say an “+” operator into the native machines “Add(i,j)” machine instruction. This results in a potentially very high overhead and therefore a truly compiled language is typically much faster. In addition, because a fully compiled language sees more of the program at once, it has the ability to apply more powerful and deep optimizations on the initial code before compiling down to assembly. With the addition of the notions of bytecode and Virtual machines, the distinction between interpretation and compilation gets even more complicated...
  • 14. “gcc -S main.i -o main.s”
  • 15.
  • 16. “gcc -c main.s -o main.o” This Object File contains machine code produced by the GCC assembler from the ‘.s’ assembly file. Multiple .o files can be linked by the linker along with static and shared libraries to produce the final executable image.
  • 17. “gcc main.o aFunc.o” Alongside these slides, “aFunc.c” has also been processed in an analogous manner resulting in aFunc.o. This file, “a.out”, is the executable produced by GCC’s linker program linking these two object files together into one unit.
  • 18. Shared Vs. Static Libraries
  • 19. Comparing Static and Shared Libraries If every C program required the C standard library in the form of a static library than the executables would consume a lot of unnecessary disk space , if every executable has a copy of printf and fopen for example.. If a library is statically linked, the code representing the library is compiled into the executable via a library mechanism. (.a on mac, .lib on windows) Shared libraries modularize these reusable components and allow multiple program binaries to link against them at runtime. Shared libraries not only decrease the size of the dependent program on disk, but allow these programs which link against them to benefit from improvements made to the shared library.
  • 21. LLVM
  • 22. Some interesting facts about Clang - Clang is designed as an API from its inception, allowing it to be reused by source analysis tools, refactoring, IDEs (etc) as well as for code generation. GCC is built as a monolithic static compiler, which makes it extremely difficult to use as an API and integrate into other tools. Further, its historic design and current policy makes it difficult to decouple the front-end from the rest of the compiler. - Clang does not implicitly simplify code as it parses it like GCC does. Doing so causes many problems for source analysis tools: as one simple example, if you write "x-x" in your source code, the GCC AST will contain "0", with no mention of 'x'. This is extremely bad for a refactoring tool that wants to rename 'x'.