Getting started with LLVM using Swift. Alex Denisov,

Size: px
Start display at page:

Download "Getting started with LLVM using Swift. Alex Denisov,"

Transcription

1 Getting started with LLVM using Swift Alex Denisov,

2 whoami ios Apps Developer Compiler Hobbyist Internet User:

3 Outline What is LLVM Compilation Process Practical Applications LLVM C API QA

4 LLVM

5 Frontend Backend 5

6 Lexer Parser Frontend Code Generation Semantic Analysis Backend 6

7 Lexer Parser Frontend Code Generation Semantic Analysis Optimization Assembler Backend Linker 7

8 Frontend Optimization Assembler Backend Linker 8

9 Frontend Backend ARM x86 MIPS 9

10 Compilation Process

11 int main(){ } return 0; cf fa ed fe f f 5f a f f 5f a b0 5f 5f c0 5f 5f d0 98 0f e0 98 0f f f 5f 75 6e e 64 5f 69 6e 66 6f f 5f a0 0f a0 0f f 5f f d f 5f e8 0f e8 0f a f 5f 4c 49 4e 4b b c d0 d

12 const float factor = 42.f; int calc(float x) { } return factor * x; 12

13 Lexer 13

14 const float factor = 42.f; int calc(float x) { return factor * x; } 14

15 (KW const ) const float factor = 42.f; int calc(float x) { return factor * x; } 15

16 (KW const ) (TYPE float ) const float factor = 42.f; int calc(float x) { return factor * x; } 16

17 (KW const ) (TYPE float ) (ID factor ) (EQ = ) (NUM 42.f ) (SEMI ; ) const float factor = 42.f; int calc(float x) { return factor * x; } 17

18 (KW const ) (TYPE float ) (ID factor ) (EQ = ) (NUM 42.f ) (SEMI ; ) (TYPE int ) (ID calc ) (L_PAREN ( ) (TYPE float ) (ID x ) (R_PAREN ) ) (L_BRACE { ) (KW return ) (ID factor ) (STAR * ) (ID x ) (SEMI ; ) (R_BRACE } ) (EOF ) const float factor = 42.f; int calc(float x) { return factor * x; } 18

19 Parser 19

20 return factor * x 20

21 return factor * x (KW return ) (ID factor ) (STAR * ) (ID x ) 21

22 return factor * x (KW return ) (ID factor ) (STAR * ) (ID x ) (KW return ) (STAR * ) (ID factor ) (ID x ) 22

23 return factor * x (KW return ) (ID factor ) (STAR * ) (ID x ) ReturnStmt return BinaryOperator * ReferenceDecl factor 23 ReferenceDecl x

24 AST FunctionDecl calc : int VariableDecl factor : float ParameterDecl x : float ReturnStmt return FloatLiteral 42.f BinaryOperator * ReferenceDecl x 24 ReferenceDecl factor

25 Semantic Analysis 25

26 AST FunctionDecl calc : int VariableDecl factor : float ParameterDecl x : float ReturnStmt return FloatLiteral 42.f BinaryOperator * ReferenceDecl x 26 ReferenceDecl factor

27 AST FunctionDecl calc : int VariableDecl factor : float ParameterDecl x : float ReturnStmt return : int FloatLiteral 42.f : float BinaryOperator * : float ReferenceDecl x : float 27 ReferenceDecl factor : float

28 AST FunctionDecl calc : int VariableDecl factor : float ParameterDecl x : float ReturnStmt return : int FloatLiteral 42.f : float??? BinaryOperator * : float ReferenceDecl x : float 28 ReferenceDecl factor : float

29 AST FunctionDecl calc : int VariableDecl factor : float ParameterDecl x : float ReturnStmt return : int FloatLiteral 42.f : float ImplicitCast ftoi : int BinaryOperator * : float ReferenceDecl x : float 29 ReferenceDecl factor : float

30 Code Generation 30

31 @factor = constant float 42.0 define calc(float %x) { entry: movf %x, %r1 %r2 %r3 = fmul %r1, %r2 movf %r3, %r0 ret } 31

32 Optimization 32

33 @factor = constant float 42.0 define calc(float %x) { entry: movf %x, %r1 %r2 %r3 = fmul %r1, %r2 movf %r3, %r0 ret } 33

34 @factor = constant float 42.0 define calc(float %x) { entry: %r0 = %x ret } 34

35 Assembler 35

36 _calc: push {r7, lr} mov r7, sp mov r1, # orr r1, r1, # bl mulsf3 bl fixsfsi pop {r7, lr} mov pc, lr.section TEXT, 2 _factor:.long float 42 36

37 Linker 37

38 const float factor = 42.f; int calc(float x) { } return factor * x; $ clang -c calc.c -o calc.o 38

39 extern int calc(float); int main() { printf( %d\n, calc(2.f)); return 0; } $ clang -c main.c -o main.o 39

40 $ nm main.o U _calc T _main U _printf 40

41 $ nm main.o U _calc T _main U _printf $ ld -lc calc.o main.o -o main $ nm main f30 T _calc fc8 S _factor f60 T _main U _printf 41

42 Lexer Parser Frontend Code Generation Semantic Analysis Optimization Assembler Backend Linker 42

43 Applications

44 Application #1 UI Development

45

46

47 Application #2 Mocks

48

49

50

51 Application #3 Mutation Testing

52

53

54

55

56

57 Applications Haml/Slim compiler Swift + Mocks Mutation Testing You name it!

58 LLVM Template

59 $ make setup $ make build $ open LLVMTemplate.xcodeproj

60

61

62

63

64 What s next?

65 Design decisions that shaped LLVM Implementing a Language with LLVM Various articles about LLVM Kaleidoscope in Swift LLVM + Swift Xcode Template

66 Thank You! Alex Denisov,

Compilation process. How a program is born

Compilation process. How a program is born Compilation process How a program is born CocoaHeads Berlin, 2015 > whoami Twitter: @1101_debian Github: @AlexDenisov Freenode: AlexDenisov Outline Compilation process LLVM/Clang Q & A Compilation Process

More information

Magic Behind Xcode. Compilation

Magic Behind Xcode. Compilation Magic Behind Xcode Compilation Mobile Warsaw, 2015 > whoami Twitter: @1101_debian Github: @AlexDenisov Freenode: AlexDenisov Blog: http://lowlevelbits.org Outline Compilation process LLVM/Clang Q & A Compilation

More information

Introduction to Compiler Design

Introduction to Compiler Design Introduction to Compiler Design Lecture 1 Chapters 1 and 2 Robb T. Koether Hampden-Sydney College Wed, Jan 14, 2015 Robb T. Koether (Hampden-Sydney College) Introduction to Compiler Design Wed, Jan 14,

More information

Lecture Code Generation for WLM

Lecture Code Generation for WLM Lecture 17+18 Code Generation for WLM CS 241: Foundations of Sequential Programs Winter 2018 Troy Vasiga et al University of Waterloo 1 Code Generation (A9/A10) Input: Output: Number of different outputs:

More information

Getting started. Roel Jordans

Getting started. Roel Jordans Getting started Roel Jordans Goal Translate a program from a high level language into something the processor can execute efficiently So before we start we need to know how this processor executes a program

More information

CMSC 350: COMPILER DESIGN

CMSC 350: COMPILER DESIGN Lecture 11 CMSC 350: COMPILER DESIGN see HW3 LLVMLITE SPECIFICATION Eisenberg CMSC 350: Compilers 2 Discussion: Defining a Language Premise: programming languages are purely formal objects We (as language

More information

Topic 3: Syntax Analysis I

Topic 3: Syntax Analysis I Topic 3: Syntax Analysis I Compiler Design Prof. Hanjun Kim CoreLab (Compiler Research Lab) POSTECH 1 Back-End Front-End The Front End Source Program Lexical Analysis Syntax Analysis Semantic Analysis

More information

Lecture 3 Overview of the LLVM Compiler

Lecture 3 Overview of the LLVM Compiler Lecture 3 Overview of the LLVM Compiler Jonathan Burket Special thanks to Deby Katz, Gennady Pekhimenko, Olatunji Ruwase, Chris Lattner, Vikram Adve, and David Koes for their slides The LLVM Compiler Infrastructure

More information

LLVM MC in Practice. Jim Grosbach and Owen Anderson

LLVM MC in Practice. Jim Grosbach and Owen Anderson LLVM MC in Practice Jim Grosbach and Owen Anderson What is MC? LLVM Machine Code Details of encodings and object file output Why MC? Disassembler JIT Assembler Debugger LLVM Machine Code Disassembler Assembler

More information

An Evil Copy: How the Loader Betrays You

An Evil Copy: How the Loader Betrays You An Evil Copy: How the Loader Betrays You Xinyang Ge 1,3, Mathias Payer 2 and Trent Jaeger 3 Microsoft Research 1 Purdue University 2 Penn State University 3 Page 1 Problem: A Motivating Example // main.c

More information

Syntax-Directed Translation. Lecture 14

Syntax-Directed Translation. Lecture 14 Syntax-Directed Translation Lecture 14 (adapted from slides by R. Bodik) 9/27/2006 Prof. Hilfinger, Lecture 14 1 Motivation: parser as a translator syntax-directed translation stream of tokens parser ASTs,

More information

Adventures in Fuzzing Instruction Selection. 1 EuroLLVM 2017 Justin Bogner

Adventures in Fuzzing Instruction Selection. 1 EuroLLVM 2017 Justin Bogner Adventures in Fuzzing Instruction Selection 1 EuroLLVM 2017 Justin Bogner Overview Hardening instruction selection using fuzzers Motivated by Global ISel Leveraging libfuzzer to find backend bugs Techniques

More information

Semantic Analysis Attribute Grammars

Semantic Analysis Attribute Grammars Semantic Analysis Attribute Grammars Martin Sulzmann Martin Sulzmann Semantic Analysis Attribute Grammars 1 / 18 Syntax versus Semantics Syntax Analysis When is a program syntactically valid? Formalism:

More information

Introduc)on. Tristan Naumann. Sahar Hasan. Steve Hehl. Brian Lu

Introduc)on. Tristan Naumann. Sahar Hasan. Steve Hehl. Brian Lu Introduc)on Tristan Naumann Sahar Hasan Steve Hehl Brian Lu Introduc)on Friendly Interac)ve Recursion Educator (FIRE) Recursion is one of the most difficult topics for novice programmers to understand

More information

MP 3 A Lexer for MiniJava

MP 3 A Lexer for MiniJava MP 3 A Lexer for MiniJava CS 421 Spring 2012 Revision 1.0 Assigned Wednesday, February 1, 2012 Due Tuesday, February 7, at 09:30 Extension 48 hours (penalty 20% of total points possible) Total points 43

More information

A clarification on terminology: Recognizer: accepts or rejects strings in a language. Parser: recognizes and generates parse trees (imminent topic)

A clarification on terminology: Recognizer: accepts or rejects strings in a language. Parser: recognizes and generates parse trees (imminent topic) A clarification on terminology: Recognizer: accepts or rejects strings in a language Parser: recognizes and generates parse trees (imminent topic) Assignment 3: building a recognizer for the Lake expression

More information

Compiler Design IIIT Kalyani, West Bengal 1. Introduction. Goutam Biswas. Lect 1

Compiler Design IIIT Kalyani, West Bengal 1. Introduction. Goutam Biswas. Lect 1 Compiler Design IIIT Kalyani, West Bengal 1 Introduction Compiler Design IIIT Kalyani, West Bengal 2 Programming a Computer High level language program Assembly language program Machine language program

More information

Lecture 2 Overview of the LLVM Compiler

Lecture 2 Overview of the LLVM Compiler Lecture 2 Overview of the LLVM Compiler Abhilasha Jain Thanks to: VikramAdve, Jonathan Burket, DebyKatz, David Koes, Chris Lattner, Gennady Pekhimenko, and Olatunji Ruwase, for their slides The LLVM Compiler

More information

gpio timer uart printf malloc keyboard fb gl console shell

gpio timer uart printf malloc keyboard fb gl console shell Where are We Going? Processor and memory architecture Peripherals: GPIO, timers, UART Assembly language and machine code From C to assembly language Function calls and stack frames Serial communication

More information

Lecture 9 CIS 341: COMPILERS

Lecture 9 CIS 341: COMPILERS Lecture 9 CIS 341: COMPILERS Announcements HW3: LLVM lite Available on the course web pages. Due: Monday, Feb. 26th at 11:59:59pm Only one group member needs to submit Three submissions per group START

More information

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100 GATE- 2016-17 Postal Correspondence 1 Compiler Design Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts,

More information

Lexical Analysis. Textbook:Modern Compiler Design Chapter 2.1.

Lexical Analysis. Textbook:Modern Compiler Design Chapter 2.1. Lexical Analysis Textbook:Modern Compiler Design Chapter 2.1 http://www.cs.tau.ac.il/~msagiv/courses/wcc11-12.html 1 A motivating example Create a program that counts the number of lines in a given input

More information

CSE 582 Autumn 2002 Exam Sample Solution

CSE 582 Autumn 2002 Exam Sample Solution Question 1. (10 points) Regular expressions. Describe the set of strings that are generated by the each of the following regular expressions. a) (a (bc)* d)+ One or more of the string a or the string d

More information

Lexical Analysis. Textbook:Modern Compiler Design Chapter 2.1

Lexical Analysis. Textbook:Modern Compiler Design Chapter 2.1 Lexical Analysis Textbook:Modern Compiler Design Chapter 2.1 A motivating example Create a program that counts the number of lines in a given input text file Solution (Flex) int num_lines = 0; %% \n ++num_lines;.

More information

Compiling Techniques

Compiling Techniques Lecture 2: The view from 35000 feet 19 September 2017 Table of contents 1 2 Passes Representations 3 Instruction Selection Register Allocation Instruction Scheduling 4 of a compiler Source Compiler Machine

More information

McSema: Static Translation of X86 Instructions to LLVM

McSema: Static Translation of X86 Instructions to LLVM McSema: Static Translation of X86 Instructions to LLVM ARTEM DINABURG, ARTEM@TRAILOFBITS.COM ANDREW RUEF, ANDREW@TRAILOFBITS.COM About Us Artem Security Researcher blog.dinaburg.org Andrew PhD Student,

More information

Topic 5: Syntax Analysis III

Topic 5: Syntax Analysis III Topic 5: Syntax Analysis III Compiler Design Prof. Hanjun Kim CoreLab (Compiler Research Lab) POSTECH 1 Back-End Front-End The Front End Source Program Lexical Analysis Syntax Analysis Semantic Analysis

More information

MP 3 A Lexer for MiniJava

MP 3 A Lexer for MiniJava MP 3 A Lexer for MiniJava CS 421 Spring 2010 Revision 1.0 Assigned Tuesday, February 2, 2010 Due Monday, February 8, at 10:00pm Extension 48 hours (20% penalty) Total points 50 (+5 extra credit) 1 Change

More information

Compilation 2013 Parser Generators, Conflict Management, and ML-Yacc

Compilation 2013 Parser Generators, Conflict Management, and ML-Yacc Compilation 2013 Parser Generators, Conflict Management, and ML-Yacc Erik Ernst Aarhus University Parser generators, ML-Yacc LR parsers are tedious to write, but can be generated, e.g., by ML-Yacc Input:

More information

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters COP 3402 Systems Software Lecture 4: Compilers 1 Outline 1. Compiler and interpreters 2. Compilers 3. 4. PL/0 lexical tokens 2 Compilers / Programming languages are notations for describing computations

More information

Writing LLVM Backends Construindo Backends para o LLVM. Bruno Cardoso Lopes

Writing LLVM Backends Construindo Backends para o LLVM. Bruno Cardoso Lopes Writing LLVM Backends Construindo Backends para o LLVM Bruno Cardoso Lopes Agenda What s LLVM? Why LLVM? Who is using? Infrastructure. Internals. The Backend. Writing LLVM backends. Work. What's LLVM?

More information

LLVM C API. How to use it with Swift

LLVM C API. How to use it with Swift LLVM C API How to use it with Swift whoami ios Apps Developer Compiler Hobbyist Internet User: https://twitter.com/1101_debian https://github.com/alexdenisov http://lowlevelbits.org Outline Development

More information

CS241 Final Exam Review

CS241 Final Exam Review CS241 Final Exam Review Winter 2018 1 Notes and disclaimer These review materials only cover topics discussed after the midterm. For a review of pre-midterm content, see the midterm review materials. These

More information

An Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1

An Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1 An Overview to Compiler Design 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1 Outline An Overview of Compiler Structure Front End Middle End Back End 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 2 Reading

More information

ISA & CSE 141 Project. Vineet Kumar

ISA & CSE 141 Project. Vineet Kumar ISA & CSE 141 Project Vineet Kumar vkumar@cs From Code to Running Programs C program compiler Assembly Language assembler Object (Machine Code) Library (Machine Code) linker Executable (Machine Your Project!

More information

Figure 2.1: Role of Lexical Analyzer

Figure 2.1: Role of Lexical Analyzer Chapter 2 Lexical Analysis Lexical analysis or scanning is the process which reads the stream of characters making up the source program from left-to-right and groups them into tokens. The lexical analyzer

More information

LDC: The LLVM-based D Compiler

LDC: The LLVM-based D Compiler LDC: The LLVM-based D Compiler Using LLVM as backend for a D compiler Kai Nacke 02/02/14 LLVM devroom @ FOSDEM 14 Agenda Brief introduction to D Internals of the LDC compiler Used LLVM features Possible

More information

CM0506 Exploring the LPC4088 Instruction Set: 4b

CM0506 Exploring the LPC4088 Instruction Set: 4b CM0506 Exploring the LPC4088 Instruction Set: 4b Michael Brockway February 13, 2016 1 Introduction This lab activity continues exploring subroutine calling, this time looking at C or C++ code calling subroutines

More information

System calls and assembler

System calls and assembler System calls and assembler Michal Sojka sojkam1@fel.cvut.cz ČVUT, FEL License: CC-BY-SA 4.0 System calls (repetition from lectures) A way for normal applications to invoke operating system (OS) kernel's

More information

Stack Frames. September 2, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 September 2, / 15

Stack Frames. September 2, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 September 2, / 15 Stack Frames Geoffrey Brown Bryce Himebaugh Indiana University September 2, 2016 Geoffrey Brown, Bryce Himebaugh 2015 September 2, 2016 1 / 15 Outline Preserving Registers Saving and Restoring Registers

More information

LLVM and IR Construction

LLVM and IR Construction LLVM and IR Construction Fabian Ritter based on slides by Christoph Mallon and Johannes Doerfert http://compilers.cs.uni-saarland.de Compiler Design Lab Saarland University 1 Project Progress source code

More information

Building a Compiler with. JoeQ. Outline of this lecture. Building a compiler: what pieces we need? AKA, how to solve Homework 2

Building a Compiler with. JoeQ. Outline of this lecture. Building a compiler: what pieces we need? AKA, how to solve Homework 2 Building a Compiler with JoeQ AKA, how to solve Homework 2 Outline of this lecture Building a compiler: what pieces we need? An effective IR for Java joeq Homework hints How to Build a Compiler 1. Choose

More information

Introduction to LLVM. UG3 Compiling Techniques Autumn 2018

Introduction to LLVM. UG3 Compiling Techniques Autumn 2018 Introduction to LLVM UG3 Compiling Techniques Autumn 2018 Contact Information Instructor: Aaron Smith Email: aaron.l.smith@ed.ac.uk Office: IF 1.29 TA for LLVM: Andrej Ivanis Email: andrej.ivanis@ed.ac.uk

More information

Compilation

Compilation Compilation 0368-3133 Lecture 1: Introduction Noam Rinetzky 1 2 Admin Lecturer: Noam Rinetzky maon@tau.ac.il http://www.cs.tau.ac.il/~maon T.A.: Oren Ish Shalom Textbooks: Modern Compiler Design Compilers:

More information

What s New in the LLVM Compiler. Chris Lattner LLVM Chief Architect

What s New in the LLVM Compiler. Chris Lattner LLVM Chief Architect What s New in the LLVM Compiler Chris Lattner LLVM Chief Architect 2 Apple Compiler Evolution Renovating the Apple compiler landscape Phasing out GCC-based tools Driving innovation in LLVM-based technologies

More information

Lecture 3: Instruction Set Architecture

Lecture 3: Instruction Set Architecture Lecture 3: Instruction Set Architecture CSE 30: Computer Organization and Systems Programming Summer 2014 Diba Mirza Dept. of Computer Science and Engineering University of California, San Diego 1. Steps

More information

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) Introduction This semester, through a project split into 3 phases, we are going

More information

Mutation Testing. How good your tests are

Mutation Testing. How good your tests are Mutation Testing How good your tests are 2017 whoami ios Developer by day compiler hacker by night https://twitter.com/1101_debian https://lowlevelbits.org https://systemundertest.org Mars Climate Orbiter

More information

REFLECTIONS ON TRUSTING BITCODE

REFLECTIONS ON TRUSTING BITCODE ITSECX - @FREDERICJACOBS REFLECTIONS ON TRUSTING BITCODE 2 INTRO ~ WHOIS FREDERIC icepa Signal Both Open-Source Software INTRO 3 Talk based on blog post HTTPS://MEDIUM.COM/@FREDERICJACOBS/WHY-I-M-NOT-ENABLING-BITCODE-F35CD8FBFCC5

More information

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016 CS 31: Intro to Systems ISAs and Assembly Kevin Webb Swarthmore College February 9, 2016 Reading Quiz Overview How to directly interact with hardware Instruction set architecture (ISA) Interface between

More information

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018 CS 31: Intro to Systems ISAs and Assembly Kevin Webb Swarthmore College September 25, 2018 Overview How to directly interact with hardware Instruction set architecture (ISA) Interface between programmer

More information

LLVM & LLVM Bitcode Introduction

LLVM & LLVM Bitcode Introduction LLVM & LLVM Bitcode Introduction What is LLVM? (1/2) LLVM (Low Level Virtual Machine) is a compiler infrastructure Written by C++ & STL History The LLVM project started in 2000 at the University of Illinois

More information

CS 33. Linkers. CS33 Intro to Computer Systems XXV 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

CS 33. Linkers. CS33 Intro to Computer Systems XXV 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. CS 33 Linkers CS33 Intro to Computer Systems XXV 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. gcc Steps 1) Compile to start here, supply.c file to stop here: gcc -S (produces.s file) if not

More information

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017 CS 31: Intro to Systems ISAs and Assembly Martin Gagné Swarthmore College February 7, 2017 ANNOUNCEMENT All labs will meet in SCI 252 (the robot lab) tomorrow. Overview How to directly interact with hardware

More information

Software II: Principles of Programming Languages

Software II: Principles of Programming Languages Software II: Principles of Programming Languages Lecture 4 Language Translation: Lexical and Syntactic Analysis Translation A translator transforms source code (a program written in one language) into

More information

Warm Up Problem. Write any equivalent MIPS program corresponding to the following code: int wain ( int a, int b){ int c = a + b; return c*a; }

Warm Up Problem. Write any equivalent MIPS program corresponding to the following code: int wain ( int a, int b){ int c = a + b; return c*a; } Warm Up Problem Write any equivalent MIPS program corresponding to the following code: int wain ( int a, int b){ int c = a + b; return c*a; } CS 241 Lecture 17 Type Checking Continued and Code Generation

More information

CS377P Programming for Performance Leveraging the Compiler for Performance

CS377P Programming for Performance Leveraging the Compiler for Performance CS377P Programming for Performance Leveraging the Compiler for Performance Sreepathi Pai UTCS October 5, 2015 Outline 1 Compiler Performance 2 Compiler Internals 3 Domain-specific Languages (DSLs) Outline

More information

Lecture 14 Sections Mon, Mar 2, 2009

Lecture 14 Sections Mon, Mar 2, 2009 Lecture 14 Sections 5.1-5.4 Hampden-Sydney College Mon, Mar 2, 2009 Outline 1 2 3 4 5 Parse A parse tree shows the grammatical structure of a statement. It includes all of the grammar symbols (terminals

More information

ARM Cortex-M4 Architecture and Instruction Set 4: The Stack and subroutines

ARM Cortex-M4 Architecture and Instruction Set 4: The Stack and subroutines ARM Cortex-M4 Architecture and Instruction Set 4: The Stack and subroutines M J Brockway February 13, 2016 The Cortex-M4 Stack SP The subroutine stack is full, descending It grows downwards from higher

More information

CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization

CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization Spring 2013 CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization Kitty Reeves TWRF 8:00-8:55am 1 Compiler Drivers = GCC When you invoke GCC, it normally does preprocessing,

More information

The Structure of a Syntax-Directed Compiler

The Structure of a Syntax-Directed Compiler Source Program (Character Stream) Scanner Tokens Parser Abstract Syntax Tree Type Checker (AST) Decorated AST Translator Intermediate Representation Symbol Tables Optimizer (IR) IR Code Generator Target

More information

COSE312: Compilers. Lecture 1 Overview of Compilers

COSE312: Compilers. Lecture 1 Overview of Compilers COSE312: Compilers Lecture 1 Overview of Compilers Hakjoo Oh 2017 Spring Hakjoo Oh COSE312 2017 Spring, Lecture 1 March 7, 2017 1 / 15 What is Compiler? Software systems that translate a program written

More information

A simple tutorial on generating PTX assembler out of Ada source code using LLVM NVPTX backend

A simple tutorial on generating PTX assembler out of Ada source code using LLVM NVPTX backend Institute of Computational Science A simple tutorial on generating PTX assembler out of Ada source code using LLVM NVPTX backend Dmitry Mikushin dmitrymikushin@usich September 14, 2012 Dmitry Mikushin

More information

Link Edits and Relocatable Code

Link Edits and Relocatable Code Link Edits and Relocatable Code Computer Systems Chapter 7.4-7.7 gcc g o ttt ttt.c ttt.c gcc ttt Pre-Processor Linker Compiler Assembler ttt.s ttt.o gcc g o ttt ttt.c main.c gcc cmd util.c Pre-Processor

More information

CUP. Lecture 18 CUP User s Manual (online) Robb T. Koether. Hampden-Sydney College. Fri, Feb 27, 2015

CUP. Lecture 18 CUP User s Manual (online) Robb T. Koether. Hampden-Sydney College. Fri, Feb 27, 2015 CUP Lecture 18 CUP User s Manual (online) Robb T. Koether Hampden-Sydney College Fri, Feb 27, 2015 Robb T. Koether (Hampden-Sydney College) CUP Fri, Feb 27, 2015 1 / 31 1 The CUP Parser Generator 2 The

More information

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006 C Compilation Model Comp-206 : Introduction to Software Systems Lecture 9 Alexandre Denault Computer Science McGill University Fall 2006 Midterm Date: Thursday, October 19th, 2006 Time: from 16h00 to 17h30

More information

CPS104 Recitation: Assembly Programming

CPS104 Recitation: Assembly Programming CPS104 Recitation: Assembly Programming Alexandru Duțu 1 Facts OS kernel and embedded software engineers use assembly for some parts of their code some OSes had their entire GUIs written in assembly in

More information

Link 7. Static Linking

Link 7. Static Linking Link 7. Static Linking Young W. Lim 2018-12-21 Fri Young W. Lim Link 7. Static Linking 2018-12-21 Fri 1 / 41 Outline 1 Linking - 7. Static Linking Based on Static Library Examples Linking with Static Libraries

More information

Part III : Parsing. From Regular to Context-Free Grammars. Deriving a Parser from a Context-Free Grammar. Scanners and Parsers.

Part III : Parsing. From Regular to Context-Free Grammars. Deriving a Parser from a Context-Free Grammar. Scanners and Parsers. Part III : Parsing From Regular to Context-Free Grammars Deriving a Parser from a Context-Free Grammar Scanners and Parsers A Parser for EBNF Left-Parsable Grammars Martin Odersky, LAMP/DI 1 From Regular

More information

symbolic name data type (perhaps with qualifier) allocated in data area, stack, or heap duration (lifetime or extent)

symbolic name data type (perhaps with qualifier) allocated in data area, stack, or heap duration (lifetime or extent) variables have multiple attributes variable symbolic name data type (perhaps with qualifier) allocated in data area, stack, or heap duration (lifetime or extent) storage class scope (visibility of the

More information

Review Questions. 1 The DRAM problem [5 points] Suggest a solution. 2 Big versus Little Endian Addressing [5 points]

Review Questions. 1 The DRAM problem [5 points] Suggest a solution. 2 Big versus Little Endian Addressing [5 points] Review Questions 1 The DRAM problem [5 points] Suggest a solution 2 Big versus Little Endian Addressing [5 points] Consider the 32-bit hexadecimal number 0x21d3ea7d. 1. What is the binary representation

More information

CSCI-243 Exam 2 Review February 22, 2015 Presented by the RIT Computer Science Community

CSCI-243 Exam 2 Review February 22, 2015 Presented by the RIT Computer Science Community CSCI-43 Exam Review February, 01 Presented by the RIT Computer Science Community http://csc.cs.rit.edu C Preprocessor 1. Consider the following program: 1 # include 3 # ifdef WINDOWS 4 # include

More information

Semantic actions for declarations and expressions

Semantic actions for declarations and expressions Semantic actions for declarations and expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate

More information

Intermediate Programming, Spring 2017*

Intermediate Programming, Spring 2017* 600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general

More information

Assembler Programming. Lecture 10

Assembler Programming. Lecture 10 Assembler Programming Lecture 10 Lecture 10 Mixed language programming. C and Basic to MASM Interface. Mixed language programming Combine Basic, C, Pascal with assembler. Call MASM routines from HLL program.

More information

Type Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules.

Type Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules. Outline Type Checking General properties of type systems Types in programming languages Notation for type rules Logical rules of inference Common type rules 2 Static Checking Refers to the compile-time

More information

Optimizing for Bugs Fixed

Optimizing for Bugs Fixed Optimizing for Bugs Fixed The Design Principles behind the Clang Static Analyzer Anna Zaks, Manager of Program Analysis Team @ Apple What is This Talk About? LLVM/clang project Overview of the Clang Static

More information

Porting & Optimising Code 32-bit to 64-bit

Porting & Optimising Code 32-bit to 64-bit Porting & Optimising Code 32-bit to 64-bit Matthew Gretton-Dann Technical Lead - Toolchain Working Group Linaro Connect, Dublin July 2013 A Presentation of Four Parts Register Files Structure Layout &

More information

ECE220: Computer Systems and Programming Spring 2018 Honors Section due: Saturday 14 April at 11:59:59 p.m. Code Generation for an LC-3 Compiler

ECE220: Computer Systems and Programming Spring 2018 Honors Section due: Saturday 14 April at 11:59:59 p.m. Code Generation for an LC-3 Compiler ECE220: Computer Systems and Programming Spring 2018 Honors Section Machine Problem 11 due: Saturday 14 April at 11:59:59 p.m. Code Generation for an LC-3 Compiler This assignment requires you to use recursion

More information

Semantic actions for declarations and expressions. Monday, September 28, 15

Semantic actions for declarations and expressions. Monday, September 28, 15 Semantic actions for declarations and expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate

More information

Outline. General properties of type systems. Types in programming languages. Notation for type rules. Common type rules. Logical rules of inference

Outline. General properties of type systems. Types in programming languages. Notation for type rules. Common type rules. Logical rules of inference Type Checking Outline General properties of type systems Types in programming languages Notation for type rules Logical rules of inference Common type rules 2 Static Checking Refers to the compile-time

More information

Summer 2003 Lecture 14 07/02/03

Summer 2003 Lecture 14 07/02/03 Summer 2003 Lecture 14 07/02/03 LAB 6 Lab 6 involves interfacing to the IBM PC parallel port Use the material on wwwbeyondlogicorg for reference This lab requires the use of a Digilab board Everyone should

More information

Building Compilers with Phoenix

Building Compilers with Phoenix Building Compilers with Phoenix Parser Generators: ANTLR History of ANTLR ANother Tool for Language Recognition Terence Parr's dissertation: Obtaining Practical Variants of LL(k) and LR(k) for k > 1 PCCTS:

More information

Free-RTOS Implementation

Free-RTOS Implementation Free-RTOS Implementation Deepak D Souza Department of Computer Science and Automation Indian Institute of Science, Bangalore. 23 August 2011 Outline 1 Architecture of Free-RTOS 2 Key data structures 3

More information

Point-Free Templates

Point-Free Templates Point-Free Templates European LLVM Developers Meeting 2018 Andrew Gozillon, Dr. Paul Keir School of Engineering and Computing University of the West of Scotland, Paisley Campus April 17th, 2018 Introduction

More information

CS377P Programming for Performance Single Thread Performance In-order Pipelines

CS377P Programming for Performance Single Thread Performance In-order Pipelines CS377P Programming for Performance Single Thread Performance In-order Pipelines Sreepathi Pai UTCS September 9, 2015 Outline 1 Introduction 2 Pipeline Preliminaries 3 The Inorder Pipeline and Performance

More information

Overview of Compiler. A. Introduction

Overview of Compiler. A. Introduction CMPSC 470 Lecture 01 Topics: Overview of compiler Compiling process Structure of compiler Programming language basics Overview of Compiler A. Introduction What is compiler? What is interpreter? A very

More information

TDDD55- Compilers and Interpreters Lesson 3

TDDD55- Compilers and Interpreters Lesson 3 TDDD55- Compilers and Interpreters Lesson 3 Zeinab Ganjei (zeinab.ganjei@liu.se) Department of Computer and Information Science Linköping University 1. Grammars and Top-Down Parsing Some grammar rules

More information

An experimental framework for Pragma handling in Clang

An experimental framework for Pragma handling in Clang Simone Pellegrini / EuroLLVM 2013 1/34 An experimental framework for Pragma handling in Clang Simone Pellegrini (spellegrini@dps.uibk.ac.at) University of Innsbruck Institut für Informatik Euro-LLVM Meeting,

More information

Compiler Drivers = GCC

Compiler Drivers = GCC Compiler Drivers = GCC When you invoke GCC, it normally does preprocessing, compilation, assembly and linking, as needed, on behalf of the user accepts options and file names as operands % gcc O1 -g -o

More information

LLVM, Clang and Embedded Linux Systems. Bruno Cardoso Lopes University of Campinas

LLVM, Clang and Embedded Linux Systems. Bruno Cardoso Lopes University of Campinas LLVM, Clang and Embedded Linux Systems Bruno Cardoso Lopes University of Campinas What s LLVM? What s LLVM Compiler infrastructure Frontend (clang) IR Optimizer Backends JIT Tools Assembler Disassembler

More information

The Structure of a Syntax-Directed Compiler

The Structure of a Syntax-Directed Compiler Source Program (Character Stream) Scanner Tokens Parser Abstract Syntax Tree Type Checker (AST) Decorated AST Translator Intermediate Representation Symbol Tables Optimizer (IR) IR Code Generator Target

More information

CSE302: Compiler Design

CSE302: Compiler Design CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University March 27, 2007 Outline Recap General/Canonical

More information

Today s Menu. >Use the Internal Register(s) >Use the Program Memory Space >Use the Stack >Use global memory

Today s Menu. >Use the Internal Register(s) >Use the Program Memory Space >Use the Stack >Use global memory Today s Menu Methods >Use the Internal Register(s) >Use the Program Memory Space >Use the Stack >Use global memory Look into my See examples on web-site: ParamPassing*asm and see Methods in Software and

More information

Code Genera*on for Control Flow Constructs

Code Genera*on for Control Flow Constructs Code Genera*on for Control Flow Constructs 1 Roadmap Last *me: Got the basics of MIPS CodeGen for some AST node types This *me: Do the rest of the AST nodes Introduce control flow graphs Scanner Parser

More information

Code Generation Introduction

Code Generation Introduction Code Generation Introduction i = 0 LF w h i l e i=0 while (i < 10) { a[i] = 7*i+3 i = i + 1 lexer i = 0 while ( i < 10 ) source code (e.g. Scala, Java,C) easy to write Compiler (scalac, gcc) parser type

More information

Group Project #2 Tips. Synopsis: This paper will illuminate key concepts needed to complete the Group #2 Project.

Group Project #2 Tips. Synopsis: This paper will illuminate key concepts needed to complete the Group #2 Project. Group Project #2 Tips Synopsis: This paper will illuminate key concepts needed to complete the Group #2 Project. Creating nodes dynamically Sometimes you may find it necessary to create your own root node

More information

CSE P 501 Exam 8/5/04 Sample Solution. 1. (10 points) Write a regular expression or regular expressions that generate the following sets of strings.

CSE P 501 Exam 8/5/04 Sample Solution. 1. (10 points) Write a regular expression or regular expressions that generate the following sets of strings. 1. (10 points) Write a regular ression or regular ressions that generate the following sets of strings. (a) (5 points) All strings containing a s, b s, and c s with at least one a and at least one b. [abc]*a[abc]*b[abc]*

More information

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

An Introduction to Assembly Programming with the ARM 32-bit Processor Family An Introduction to Assembly Programming with the ARM 32-bit Processor Family G. Agosta Politecnico di Milano December 3, 2011 Contents 1 Introduction 1 1.1 Prerequisites............................. 2

More information

Semantic actions for declarations and expressions

Semantic actions for declarations and expressions Semantic actions for declarations and expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate

More information