How to write a GCC plugin with MELT?

Size: px
Start display at page:

Download "How to write a GCC plugin with MELT?"

Transcription

1 Polytech Tours July 12, 2011, RMLL 2011 These slides are under a Creative Commons Attribution-ShareAlike 3.0 Unported License 1/35

2 About me [] I am finishing my studies at Polytech Tours (France) (both as engineer and researcher student). I have been fortunate to work on (and ) during a school project. I am still working on this as a Google Summer Of Code Project. I am still learning and don t know everything :) Special thanks I specially thanks Alexandre Lissy (my supervisor), Basile Starynkevitch ( creator), and the Google GSOC program. 2/35

3 Plan 1 About me About this talk Foreword about 2 Presentation Internal structure of Plugins 3 Presentation Why a DSL? Using 4 Type of tests Using Modularity 3/35

4 About this talk Questions to the audience: Do you use? Do you use static analysis tools? Or is there never bugs in your code? :) We are going to discuss: Overview of. Good (and bad) reasons to code a plugin. Using to develop more efficiently extensions. Detail about. 4/35

5 Foreword about means mole in Esperanto! The idea of the name is that it digs blindly into (without knowing much where it goes :) ) and calls still found useful informations you need. In fact: a customizable extension (written in ) to run simple analysis in your C/C++ programs. Use case: You want to check that a call to malloc function is followed by a call to free in the same function. You want to check that a call to fopen is immediately followed by a test on his returned pointer. Checking that there is (or not) code after an execx* (execl, execlp, execle, execv, execvp, execvpe) (to check for error for example). 5/35

6 presentation : GNU Compiler Collection: a set of compilers for many architectures and several languages: C, C++, Ada, Fortran, Objective C, Java, Go. The Free Software compiler. Started many years ago (1987: 1.0). Distributed by the FSF (GPL V3). Widely used (Linux, Firefox, Mandriva... ). Current release is (June 2011). 450 regular contributors. Huge and complex. Incomplete documentation. Possibility to write plugins since 4.5 (April 2010). 6/35

7 presentation is still evolving: New processors support + improvements. New languages (Go has been added in 4.6) + conformity to newer language standards New optimizations (LTO with WHOPR 1 ) So, size is increasing (stat for 4.6 with ohcount): Files: Code: lines Comment: 23,6% 1 Link Time Optimization on Whole Program 7/35

8 Internal structure of 8/35

9 Internal structure of 3 parts into Front-end: parse your source code to GENERIC representation. Middle-end: make many optimizations and code analysis ( using GIMPLE representation). Back-End: convert to a processor specific assembly code (using RTL language). The Middle-end is the bigger part of : it factorizes the optimization for the different languages. This is also the main part on which (Middle End Lisp Translator) works. 9/35

10 Middle-end representation Intermediate languages at Middle end level are AST (Abstract Syntax Tree): A node represents an operator, a leaf represents an operand). An operator can be a type declaration, a condition, a function call... Example of AST for the following code: if (a < b){a = 5; } return a; 10/35

11 Middle-end representation There are two main internal representations at Middle-end level: GENERIC/TREE: AST with 180 different possible tree operators. The list of operators can be found in gcc/tree.def. GIMPLE: AST with 36 different possible GIMPLE operators 2. The list of operators can be found in gcc/gimple.def. Example of GENERIC/TREE opcodes 1 / Relational operators. 2 EQ EXPR and NE EXPR are allowed for any types. 3 The others are allowed only for integer (or pointer or enumeral) or real types. 4 In all cases the operands will have the same type, 5 and the value is always the type used by the language for booleans. / 6 DEFTREECODE (LT EXPR, lt expr, tcc comparison, 2) 7 DEFTREECODE (LE EXPR, le expr, tcc comparison, 2) 8 DEFTREECODE (GT EXPR, gt expr, tcc comparison, 2) 9 DEFTREECODE (GE EXPR, ge expr, tcc comparison, 2) 10 DEFTREECODE (EQ EXPR, eq expr, tcc comparison, 2) 11 DEFTREECODE (NE EXPR, ne expr, tcc comparison, 2) 2 Almost half of the Gimple operators are OpenMP specific. 11/35

12 The pass mechanism In the Front-end, Middle-end, Back-end, each operation or transformation of the code is performed by one or several passes. Example of passes: Dead Code Elimination. Mudflap: add Exception, on risky operations, such as dereferencing pointers, dangerous use of standard String functions... There are more than 250 passes in. They are dynamically inserted and the issue is to find where to insert your own pass (-fdump-tree-all, -fdump-rtl-all and -fdump-ipa-all dump every pass into files and are quite useful). 12/35

13 The pass mechanism 13/35

14 The Control Flow Graph (CFG) A directed graph showing the control flow behaviour of a single function: composed of Basic blocks (set of sequential instructions). a single entry and exit block per function. Simple passes are running on each function (and use the CFG). 14/35

15 Middle-end dump C file SSA(Static Single Assignment) representation 1 #include <stdio.h> 2 3 int main(){ 4 FILE file; 5 file= fopen( /root/test fopen cfile.c, 6 r+ ); 7 if(file){ 8 return 0; 9 } 10 else{ 11 return 1; 12 } 13 } 1 main (){ 2 struct FILE file; 3 int D.2531; 4 const char restrict D.2528; 5 const char restrict D.2527; 6 <bb 2>: 7 D = (const char restrict) & r+ [0]; 8 D = (const char restrict) & /root/ test fopen cfile.c [0]; 9 file 4 = fopen (D , D ); 10 if (file 4!= 0B) 11 goto <bb 3>; 12 else 13 goto <bb 4>; 14 <bb 3>: 15 D = 0; 16 goto <bb 5> (<L2>); 17 <bb 4>: 18 D = 1; 19 # D = PHI <D (3), D (4)> 20 <L2>: return D ; 21 } 15/35

16 Plugins How does it work 3? Every plugin should export a plugin init function. Severals callbacks are defined in gcc/gcc-plugin.c Plugins register handlers to theses callbacks with register callback function. Plugins can add their own new passes. To run with a plugin: gcc-4.6 -fplugin=pluginname foo.c However For the moment, there is no stable API! This is strongly discussed within the community /35

17 What can you do with plugins? Example Technically: Add a new pass inside your plugin. In practice: Use the powerful infrastructure to add your own diagnostics or extensions. is a [meta-] plugin. Dehydra / Treehydra: A javascript tool for static C++ analysis (allows to parse the GIMPLE trees) a. gcc-vcg-plugin: Shows internal structure graphically. b... c a ( b c 17/35

18 What can you do with plugins? A plugin is not useful for programmers: They know well the different parts of (doesn t need the plugin abstraction). They want to write core features (always available, nothing specific, heavily integrated in the trunk). They follows the community guidelines (and want their work to be reviewed). Plugins are for people from other projects (You): Projects have their own coding rules and need to follow them (but don t have often automatic tools to check them). Coding rules are specific to each project, so could not be integrated into. It is easier to maintain a plugin than a fork. 18/35

19 Presentation of Goal: Help you to write more easily your own extensions? Started in Quite usable now (with bugs sometimes). Available as a branch 4 (for curious and hacker) or a plugin 5 (for quick and easy use). Motivated for simple static analysis work. A new DSL (Domain Specific Language) full of functionalities. Not really documented (but we work on it!). 4 svn://gcc.gnu.org/svn/gcc/branches/melt-branchgcc-melt 5 Version 0.8 has been released yesterday! Get it at 19/35

20 Why is a lispy langage? From Basile Starynkevitch slides: The internals API are not stable (from one release to the next), and will probably never be. The API is huge and ill-defined. the api contains a lot of more or less simple functions and also non-functions (e.g. macros and even non-expression iterative macros like FOREACH FUNCTION ARGS or FOR EACH BB FN etc.). Interfacing them with scripting-language specific glue functions would be error-prone and inefficient. Glue generators (à la SWIG) don t fit well. The Ggc ( garbage collector) is essential in ; mixing several GC-s(i.e. Ggc and Ocaml s GC) is perilous and brittle. 20/35

21 This explains why is not written in ocaml or python. A new Python binding 6 is appearing. This might be more limited than : Only a reduced set of structures might be available. It will have to deal with Garbage collector issues. has also some advanced features (pattern matching) that you won t have in Python /35

22 How works First you have to write a foo.melt file (which contains your module) 7. Convert your module into C and then into a.so 1 gcc fplugin=melt fplugin arg melt mode=translatetomodule \ 2 fplugin arg melt arg=foo.melt c empty.c Use your module while compiling a source 1 gcc fplugin=melt fplugin arg melt mode=foo \ 2 fplugin arg melt init=foo \ 3 fplugin arg melt module path=$build \ 4 fplugin arg melt source path=$build source.c 7 Every example is for plugin, you can find information about how to use branch on the website 22/35

23 Using is highly inspired by functional programming (Lisp, OCamls... ) A first Hello world example 1 (defun say hello () 2 (code chunk hellochunk #{printf( Saluton, mondo! )}#) 3 ) 4 (say hello) Ok... there is a lot of parenthesis (your text editor will handle them easily). Functions are defined with the defun keyword. A code chunk is a declaration of C code directly into (but we don t use it much usually). 23/35

24 Using Installing a new pass 1 (defun talpo docmd (cmd moduldata) 2 (let ((talpo (instance class gcc gimple pass 3 :named name melt talpo pass 4 :gccpass gate talpo gate 5 :gccpass exec talpo exec 6 :gccpass properties required () 7 ))) 8 (install melt gcc pass talpo after cfg 0) 9 (debug msg talpo talpo mode installed talpo ) 10 (return talpo) 11 )) Two important functions: gate : decides if the pass should be run. exec : do the real work of the pass New pass position relative to another pass ( cfg here). 24/35

25 values and stuff Important! This is specific to (and must be clearly understood!!!). Sometimes we use data coming from (processing GIMPLEs for example): In this case, you need to refer to the C type. We call this a stuff. But we much prefer to use dynamic values (because they are handled transparently by, especially by the garbage collector). We call this a value. 25/35

26 values and stuff Using a stuff 1 (let (( :cstring mystring a dummy C string )) 2 (code chunk test #{printf($mystring)}#) 3 ) let is the keyword to define a local variable. :cstring explicit the type of the variable mystring. Using a value 1 (let (( mystringval mytest )) 2 (errormsg strv Given argument is not a valid test. mystringval) 3 ) Usually, we try to work as much as possible with values! make <types>: box a stuff into a value <type> content: unbox a value as a stuff. 26/35

27 Iterative construct You can iterate over a list... But also over main types (very useful to parse CFG): each cgraph fun body each bb current fun each in gimpleseq eachgimple in basicblock... Iterating over gimpleseq 1 (eachgimple in basicblock 2 (bb) 3 (:gimple g) 4 (is gimple assignation g) 5 ) you can even define your own c-iterators! 27/35

28 Pattern matching on trees Regular expression on a text. pattern-matching on trees (especially representation). Many use cases: Finding every call of a function containing melt in his declaration name. Finding comparison to a NULL pointer. Detecting casts.... How to do? use the match operator. take a object as first parameter (a tree, a GIMPLE, a basic block...). add your different patterns and code to be run if the pattern is verified. You can also add your own pattern if you don t find what you need. 28/35

29 Pattern matching Pattern matching example 1 (defun detect fopen (grdata :gimple g) 2 (match g 3 ( 4?(gimple call 2?lhs 5?(and?callfndcl 6?(tree function decl 7?(cstring same fopen ) 8? )) 9?arg1 10?arg2 11 ) 12 (return (make tree discr tree lhs)) 13 ) 14 ( 15? ((return (make tree discr tree (null tree)))) 16 ) 17 ) 18 ) 29/35

30 8 started with the idea that a static analysis tool can use the powerful functionalities of and must be customized for a project: A test can be easily parameterized by people ignoring (much of) and. With you can check this: for each call to a foo function, result of the call is tested to be (not) NULL/negative/zero. each call to a foo function is immediately followed by a call to a bar function. each call to a foo function is followed by a call to a bar function in the same function body. This is quite simple and limited but can already be useful in many cases! /35

31 Easy to use There are different ways to pass argument to : Using pragma in code file 1 #pragma talpo testnull(fopen) 2 #pragma talpo test followed\by(chroot, chdir) Using direct argument 1 gcc... 2 fplugin arg melt option=talpo arg= (testnull fopen )\ 3 (test followed by chroot chown ) 4... Using a file to list argument? TODO! 31/35

32 Modularity You can implement a new way to read user input. You can implement a new test. 32/35

33 Try it argument 1 #include <stdio.h> 2 int main(void){ 3 FILE test; 4 test=fopen ( test, a ); 5 return 0; 6 } Result 1 gcc Wall fplugin=melt fplugin arg melt mode=talpo \ 2 fplugin arg melt module path= $(talpopath) \ 3 fplugin arg melt source path=. \ 4 fplugin arg melt extra=@$(talpopath)/talpo \ 5 fplugin arg melt option=talpo arg= (testnull fopen ) \ 6 O2 test.c o test.o 1 test simple check cfile.c:5:10: warning: Melt Warning[#221]: Function fopen not followed by a test on his returned pointer. 33/35

34 Try it argument 1 int main(void){ 2 int i=0; 3 FILE test; 4 FILE test2; 5 if( i ==1) 6 test=fopen( toto, a ); 7 else 8 test2=fopen( tata, a ); 9 if (test == NULL) 10 return 1; 11 return 0; 12 } Result 1 test simple check cfile.c:8:10: warning: Melt Warning[#216]: Function fopen not followed by a test on his returned pointer. 34/35

35 Conclusion Free software is about adapting software to your needs: Plugins are great way to personalize. 9 simplifies writing extensions (and is more fun than coding in C). is the result of previous points. I invite you to test. Questions: Was this interesting? Have you idea for a plugin? Have you idea of tests? Are you going to try //? 9 also has a mailing list : gcc-melt@googlegroup.com 35/35

36 Additional slides 36/35

37 Basic Block A basic block is a data representing a part of a function. It has only one input and one output. It is a set (gimple seq) of sequential instructions (without conditions or loops). instruction are GIMPLE This is very useful for analyse and optimisation: We can deduce in which Basic block a variable appears. Basic blocks are hierarchically organised (and we get properties from this). 37/35

38 Using You can declare classes (and instances of them): Class declaration 1 (defclass class talpo test model 2 :super class named 3 :fields ( 4 talpo test model handler ;;the handler is the function used when executing the pass 5 talpo test model help 6 talpo test model nbargs ;;number of arguments 7 )) single-inheritance hierarchy (using super) field name must be unique. no access properties (no protected/private fields) 38/35

39 Debugging in You will need to use debug: To understand structures. To understand results. To find bugs in your code (or in code). For now debug is limited to a file dumping many useful informations. You must pass the option -fplugin-arg-melt-debug when compiling. In your code you can use functions like: debug<type> (such as debugtree or debuggimple) when debugging stuff. debug msg when debugging a value 39/35

40 Debugging in Example of debugging 1 (debugtree test fopen gate cfun decl (cfun decl)) Result debugtree test fopen gate /function decl \ 2 <function decl 0x41a93580 hello 3... //ensemble d informations concernant la fonction \ 4 //hello (argument, retour...). 5 debugtree test fopen gate /function decl \ 7 <function decl 0x41a93600 main 8... //ensemble d informations concernant la fonction main. 40/35

41 primitives Example of primitive 1 (defprimitive get immediate dominator unsafe (:basic block bb) :basic block 2 :doc#{it doesn t check that dominance info are build, use 3 get immediate dominator instead.}# 4 #{($bb)? get immediate dominator (CDI DOMINATORS, $bb) : NULL}# 5 ) 41/35

MELT, a Translated Domain Specific Language Embedded in the GCC Compiler

MELT, a Translated Domain Specific Language Embedded in the GCC Compiler These slides are under a Creative Commons Attribution-ShareAlike 3.0 Unported License creativecommons.org/licenses/by-sa/3.0 and downloadable from gcc-melt.org Basile STARYNKEVITCH MELT, a translated DSL

More information

An Architectural Overview of GCC

An Architectural Overview of GCC An Architectural Overview of GCC Diego Novillo dnovillo@redhat.com Red Hat Canada Linux Symposium Ottawa, Canada, July 2006 Topics 1. Overview 2. Development model 3. Compiler infrastructure 4. Intermediate

More information

Using GCC as a Research Compiler

Using GCC as a Research Compiler Using GCC as a Research Compiler Diego Novillo dnovillo@redhat.com Computer Engineering Seminar Series North Carolina State University October 25, 2004 Introduction GCC is a popular compiler, freely available

More information

Kurt Schmidt. October 30, 2018

Kurt Schmidt. October 30, 2018 to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed

More information

Fall 2015 COMP Operating Systems. Lab #3

Fall 2015 COMP Operating Systems. Lab #3 Fall 2015 COMP 3511 Operating Systems Lab #3 Outline n Operating System Debugging, Generation and System Boot n Review Questions n Process Control n UNIX fork() and Examples on fork() n exec family: execute

More information

Compiler Theory. (GCC the GNU Compiler Collection) Sandro Spina 2009

Compiler Theory. (GCC the GNU Compiler Collection) Sandro Spina 2009 Compiler Theory (GCC the GNU Compiler Collection) Sandro Spina 2009 GCC Probably the most used compiler. Not only a native compiler but it can also cross-compile any program, producing executables for

More information

PRINCIPLES OF OPERATING SYSTEMS

PRINCIPLES OF OPERATING SYSTEMS PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)

More information

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level

More information

Introduce C# as Object Oriented programming language. Explain, tokens,

Introduce C# as Object Oriented programming language. Explain, tokens, Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation

More information

Slide Set 4. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 4. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 4 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary January 2018 ENCM 369 Winter 2018 Section

More information

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) CSE 413 Languages & Implementation Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) 1 Goals Representing programs as data Racket structs as a better way to represent

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and

More information

CS61C : Machine Structures

CS61C : Machine Structures Get your clickers ready...! inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 3 Introduction to the C Programming Language (pt 1) 2013-01-28! Hello to Nishant Varma watching from India!!!Senior

More information

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT C Review MaxMSP Developers Workshop Summer 2009 CNMAT C Syntax Program control (loops, branches): Function calls Math: +, -, *, /, ++, -- Variables, types, structures, assignment Pointers and memory (***

More information

Class Information ANNOUCEMENTS

Class Information ANNOUCEMENTS Class Information ANNOUCEMENTS Third homework due TODAY at 11:59pm. Extension? First project has been posted, due Monday October 23, 11:59pm. Midterm exam: Friday, October 27, in class. Don t forget to

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

Important From Last Time

Important From Last Time Important From Last Time Embedded C Ø Pros and cons Macros and how to avoid them Intrinsics Interrupt syntax Inline assembly Today Advanced C What C programs mean How to create C programs that mean nothing

More information

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures Dan Grossman Fall 2014 Hi! I m not Hal J I love this stuff and have taught

More information

Extending the GCC compiler with MELT

Extending the GCC compiler with MELT Extending the GCC compiler with MELT Basile Starynkevitch basile@starynkevitch.net or basile.starynkevitch@cea.fr may, 22 nd, 2013, EPITA LRDE seminar B.Starynkevitch extending GCC with MELT May 22, 2013

More information

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline CS 0 Lecture 8 Chapter 5 Louden Outline The symbol table Static scoping vs dynamic scoping Symbol table Dictionary associates names to attributes In general: hash tables, tree and lists (assignment ) can

More information

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations , 1 C#.Net VT 2009 Course Contents C# 6 hp approx. BizTalk 1,5 hp approx. No exam, but laborations Course contents Architecture Visual Studio Syntax Classes Forms Class Libraries Inheritance Other C# essentials

More information

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer. The Compiler So Far CSC 4181 Compiler Construction Scanner - Lexical analysis Detects inputs with illegal tokens e.g.: main 5 (); Parser - Syntactic analysis Detects inputs with ill-formed parse trees

More information

C - Basics, Bitwise Operator. Zhaoguo Wang

C - Basics, Bitwise Operator. Zhaoguo Wang C - Basics, Bitwise Operator Zhaoguo Wang Java is the best language!!! NO! C is the best!!!! Languages C Java Python 1972 1995 2000 (2.0) Procedure Object oriented Procedure & object oriented Compiled

More information

A Tour of the Cool Support Code

A Tour of the Cool Support Code A Tour of the Cool Support Code 1 Introduction The Cool compiler project provides a number of basic data types to make the task of writing a Cool compiler tractable in the timespan of the course. This

More information

Important From Last Time

Important From Last Time Important From Last Time Embedded C Pros and cons Macros and how to avoid them Intrinsics Interrupt syntax Inline assembly Today Advanced C What C programs mean How to create C programs that mean nothing

More information

A brief introduction to C programming for Java programmers

A brief introduction to C programming for Java programmers A brief introduction to C programming for Java programmers Sven Gestegård Robertz September 2017 There are many similarities between Java and C. The syntax in Java is basically

More information

Page 1. Today. Important From Last Time. Is the assembly code right? Is the assembly code right? Which compiler is right?

Page 1. Today. Important From Last Time. Is the assembly code right? Is the assembly code right? Which compiler is right? Important From Last Time Today Embedded C Pros and cons Macros and how to avoid them Intrinsics Interrupt syntax Inline assembly Advanced C What C programs mean How to create C programs that mean nothing

More information

Instantiation of Template class

Instantiation of Template class Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double

More information

Announcements. My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM.

Announcements. My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM. IR Generation Announcements My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM. This is a hard deadline and no late submissions will be

More information

The GNU Compiler Collection

The GNU Compiler Collection The GNU Compiler Collection Diego Novillo dnovillo@redhat.com Gelato Federation Meeting Porto Alegre, Rio Grande do Sul, Brazil October 3, 2005 Introduction GCC is a popular compiler, freely available

More information

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley. CS61C Machine Structures Lecture 3 Introduction to the C Programming Language 1/23/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L03 Introduction to C (1) Administrivia

More information

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018 CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018 Typical workflow concrete syntax (string) "(fn x => x + x) 4" Parsing Possible errors / warnings

More information

CS 314 Principles of Programming Languages. Lecture 9

CS 314 Principles of Programming Languages. Lecture 9 CS 314 Principles of Programming Languages Lecture 9 Zheng Zhang Department of Computer Science Rutgers University Wednesday 5 th October, 2016 Zheng Zhang 1 CS@Rutgers University Class Information Homework

More information

Introduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang

Introduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang Introduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang Topics History of Programming Languages Compilation Process Anatomy of C CMSC 104 Coding Standards Machine Code In the beginning,

More information

Running a C program Compilation Python and C Variables and types Data and addresses Functions Performance. John Edgar 2

Running a C program Compilation Python and C Variables and types Data and addresses Functions Performance. John Edgar 2 CMPT 125 Running a C program Compilation Python and C Variables and types Data and addresses Functions Performance John Edgar 2 Edit or write your program Using a text editor like gedit Save program with

More information

University of Arizona, Department of Computer Science. CSc 453 Assignment 5 Due 23:59, Dec points. Christian Collberg November 19, 2002

University of Arizona, Department of Computer Science. CSc 453 Assignment 5 Due 23:59, Dec points. Christian Collberg November 19, 2002 University of Arizona, Department of Computer Science CSc 453 Assignment 5 Due 23:59, Dec 4 100 points Christian Collberg November 19, 2002 1 Introduction Your task is to write a code generator for the

More information

CS691/SC791: Parallel & Distributed Computing

CS691/SC791: Parallel & Distributed Computing CS691/SC791: Parallel & Distributed Computing Introduction to OpenMP 1 Contents Introduction OpenMP Programming Model and Examples OpenMP programming examples Task parallelism. Explicit thread synchronization.

More information

C Language Summary. Chris J Michael 28 August CSC 4103 Operating Systems Fall 2008 Lecture 2 C Summary

C Language Summary. Chris J Michael 28 August CSC 4103 Operating Systems Fall 2008 Lecture 2 C Summary Chris J Michael cmicha1@lsu.edu 28 August 2008 C Language Summary Heavily Influenced by the GNU C Reference Manual: http://www.gnu.org/software/gnu-c-manual/ Introduction -C98, or the original ANSI C standard

More information

Day05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14

Day05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14 Day05 A Young W. Lim 2017-10-07 Sat Young W. Lim Day05 A 2017-10-07 Sat 1 / 14 Outline 1 Based on 2 Structured Programming (2) Conditions and Loops Conditional Statements Loop Statements Type Cast Young

More information

CSc 520 Principles of Programming Languages. 26 : Control Structures Introduction

CSc 520 Principles of Programming Languages. 26 : Control Structures Introduction CSc 520 Principles of Programming Languages 26 : Control Structures Introduction Christian Collberg Department of Computer Science University of Arizona collberg+520@gmail.com Copyright c 2008 Christian

More information

High Performance Computing in C and C++

High Performance Computing in C and C++ High Performance Computing in C and C++ Rita Borgo Computer Science Department, Swansea University Summary Introduction to C Writing a simple C program Compiling a simple C program Running a simple C program

More information

just a ((somewhat) safer) dialect.

just a ((somewhat) safer) dialect. Intro_to_C Page 1 Intro to C Tuesday, September 07, 2004 5:30 PM C was developed specifically for writing operating systems Low level of abstraction. "Just above machine language." Direct access to the

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2016 Lecture 3a Andrew Tolmach Portland State University 1994-2016 Formal Semantics Goal: rigorous and unambiguous definition in terms of a wellunderstood formalism (e.g.

More information

Writing Evaluators MIF08. Laure Gonnord

Writing Evaluators MIF08. Laure Gonnord Writing Evaluators MIF08 Laure Gonnord Laure.Gonnord@univ-lyon1.fr Evaluators, what for? Outline 1 Evaluators, what for? 2 Implementation Laure Gonnord (Lyon1/FST) Writing Evaluators 2 / 21 Evaluators,

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 4a Andrew Tolmach Portland State University 1994-2017 Semantics and Erroneous Programs Important part of language specification is distinguishing valid from

More information

Java: framework overview and in-the-small features

Java: framework overview and in-the-small features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: framework overview and in-the-small features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer

More information

What goes inside when you declare a variable?

What goes inside when you declare a variable? Stack, heap, value types, reference types, boxing, and unboxing Introduction This article will explain six important concepts: stack, heap, value types, reference types, boxing, and unboxing. This article

More information

Final CSE 131B Spring 2004

Final CSE 131B Spring 2004 Login name Signature Name Student ID Final CSE 131B Spring 2004 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (25 points) (24 points) (32 points) (24 points) (28 points) (26 points) (22 points)

More information

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

More information

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking CSE450 Translation of Programming Languages Lecture 11: Semantic Analysis: Types & Type Checking Structure Project 1 - of a Project 2 - Compiler Today! Project 3 - Source Language Lexical Analyzer Syntax

More information

Fibonacci in Lisp. Computer Programming: Skills & Concepts (CP1) Programming Languages. Varieties of Programing Language

Fibonacci in Lisp. Computer Programming: Skills & Concepts (CP1) Programming Languages. Varieties of Programing Language Fibonacci in Lisp Computer Programming: Skills & Concepts (CP1) Programming Languages (defun fibonacci (n) (if (or (= n 0) (= n 1)) 1 (+ (fibonacci (- n 1)) (fibonacci (- n 2))))) 22nd November 2010 defun-

More information

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga C-Programming CSC209: Software Tools and Systems Programming Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Adapted from Dan Zingaro s 2015 slides. Week 2.0 1 / 19 What

More information

Winter Compiler Construction Who. Mailing list and forum

Winter Compiler Construction Who. Mailing list and forum Winter 2006-2007 Compiler Construction 0368-3133 Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv University Who Roman Manevich Schreiber Open-space (basement) Tel: 640-5358 rumster@post.tau.ac.il

More information

Operating Systems 2INC0 C course Pointer Advanced. Dr. Ir. Ion Barosan

Operating Systems 2INC0 C course Pointer Advanced. Dr. Ir. Ion Barosan Operating Systems 2INC0 C course Pointer Advanced Dr. Ir. Ion Barosan (i.barosan@tue.nl) Containt Pointers Definition and Initilization Ponter Operators Pointer Arithmetic and Array Calling Functions by

More information

edunepal_info

edunepal_info facebook.com/edunepal.info @ edunepal_info C interview questions (1 125) C interview questions are given with the answers in this website. We have given C interview questions faced by freshers and experienced

More information

Recitation: Cache Lab & C

Recitation: Cache Lab & C 15-213 Recitation: Cache Lab & C Jack Biggs 16 Feb 2015 Agenda Buffer Lab! C Exercises! C Conventions! C Debugging! Version Control! Compilation! Buffer Lab... Is due soon. So maybe do it soon Agenda Buffer

More information

CS61C : Machine Structures

CS61C : Machine Structures Get your clickers ready...! inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 3 Introduction to the C Programming Language (pt 1)!!Senior Lecturer SOE Dan Garcia!!!www.cs.berkeley.edu/~ddgarcia

More information

Intermediate Representations

Intermediate Representations Compiler Design 1 Intermediate Representations Compiler Design 2 Front End & Back End The portion of the compiler that does scanning, parsing and static semantic analysis is called the front-end. The translation

More information

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011 More C++ David Chisnall March 17, 2011 Exceptions A more fashionable goto Provides a second way of sending an error condition up the stack until it can be handled Lets intervening stack frames ignore errors

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

Reversing. Time to get with the program

Reversing. Time to get with the program Reversing Time to get with the program This guide is a brief introduction to C, Assembly Language, and Python that will be helpful for solving Reversing challenges. Writing a C Program C is one of the

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

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

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine

More information

LECTURE 18. Control Flow

LECTURE 18. Control Flow LECTURE 18 Control Flow CONTROL FLOW Sequencing: the execution of statements and evaluation of expressions is usually in the order in which they appear in a program text. Selection (or alternation): a

More information

Memory Corruption 101 From Primitives to Exploit

Memory Corruption 101 From Primitives to Exploit Memory Corruption 101 From Primitives to Exploit Created by Nick Walker @ MWR Infosecurity / @tel0seh What is it? A result of Undefined Behaviour Undefined Behaviour A result of executing computer code

More information

CS 61c: Great Ideas in Computer Architecture

CS 61c: Great Ideas in Computer Architecture Introduction to C, Pointers June 24, 2014 Review of Last Lecture Six Great Ideas in Computer Architecture Number Representation Bits can represent anything! n bits can represent up to 2 n things Unsigned,

More information

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given MUHAMMAD FAISAL MIT 4 th Semester Al-Barq Campus (VGJW01) Gujranwala faisalgrw123@gmail.com MEGA File Solved MCQ s For Final TERM EXAMS CS508- Modern Programming Languages Question No: 1 ( Marks: 1 ) -

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2017 Lecture 3a Andrew Tolmach Portland State University 1994-2017 Binding, Scope, Storage Part of being a high-level language is letting the programmer name things: variables

More information

GDB Tutorial. Young W. Lim Fri. Young W. Lim GDB Tutorial Fri 1 / 24

GDB Tutorial. Young W. Lim Fri. Young W. Lim GDB Tutorial Fri 1 / 24 GDB Tutorial Young W. Lim 2016-02-19 Fri Young W. Lim GDB Tutorial 2016-02-19 Fri 1 / 24 Outline 1 Introduction Young W. Lim GDB Tutorial 2016-02-19 Fri 2 / 24 Based on Self-service Linux: Mastering the

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

Ruby: Introduction, Basics

Ruby: Introduction, Basics Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 3 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie

More information

Structure of Programming Languages Lecture 10

Structure of Programming Languages Lecture 10 Structure of Programming Languages Lecture 10 CS 6636 4536 Spring 2017 CS 6636 4536 Lecture 10: Classes... 1/23 Spring 2017 1 / 23 Outline 1 1. Types Type Coercion and Conversion Type Classes, Generics,

More information

Shell programming. Introduction to Operating Systems

Shell programming. Introduction to Operating Systems Shell programming Introduction to Operating Systems Environment variables Predened variables $* all parameters $# number of parameters $? result of last command $$ process identier $i parameter number

More information

Embedding Python in Your C Programs

Embedding Python in Your C Programs 1 of 7 6/18/2006 9:05 PM Embedding Python in Your C Programs William Nagel Abstract C, meet Python. Python, this is C. With surprisingly little effort, the Python interpreter can be integrated into your

More information

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming CMSC 330: Organization of Programming Languages OCaml Imperative Programming CMSC330 Spring 2018 1 So Far, Only Functional Programming We haven t given you any way so far to change something in memory

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

Plugin Mechanisms in GCC

Plugin Mechanisms in GCC Plugin Mechanisms in GCC (www.cse.iitb.ac.in/ uday) GCC Resource Center, Department of Computer Science and Engineering, Indian Institute of Technology, Bombay 13 June 2014 EAGCC-PLDI-14 Plugins: Outline

More information

Review of the C Programming Language

Review of the C Programming Language Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the

More information

Number review... Lecture 3 Introduction to the C Programming Language (pt 1) Has there been an update to ANSI C?

Number review... Lecture 3 Introduction to the C Programming Language (pt 1) Has there been an update to ANSI C? CS61C L03 Introduction to C (pt 1) (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 3 Introduction to the C Programming Language (pt 1) 2008-01-28 Lecturer SOE Dan Garcia Hello to Dev

More information

JAVA An overview for C++ programmers

JAVA An overview for C++ programmers JAVA An overview for C++ programmers Wagner Truppel wagner@cs.ucr.edu edu March 1st, 2004 The early history James Gosling, Sun Microsystems Not the usual start for a prog.. language Consumer electronics,

More information

So what does studying PL buy me?

So what does studying PL buy me? So what does studying PL buy me? Enables you to better choose the right language but isn t that decided by libraries, standards, and my boss? Yes. Chicken-and-egg. My goal: educate tomorrow s tech leaders

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2016 Lecture 4a Andrew Tolmach Portland State University 1994-2016 Pragmatics of Large Values Real machines are very efficient at handling word-size chunks of data (e.g.

More information

Slide Set 5. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 5. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 5 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October 2016 ENCM 339 Fall 2016 Slide Set 5 slide 2/32

More information

15-411: LLVM. Jan Hoffmann. Substantial portions courtesy of Deby Katz

15-411: LLVM. Jan Hoffmann. Substantial portions courtesy of Deby Katz 15-411: LLVM Jan Hoffmann Substantial portions courtesy of Deby Katz and Gennady Pekhimenko, Olatunji Ruwase,Chris Lattner, Vikram Adve, and David Koes Carnegie What is LLVM? A collection of modular and

More information

C++ for Java Programmers

C++ for Java Programmers Basics all Finished! Everything we have covered so far: Lecture 5 Operators Variables Arrays Null Terminated Strings Structs Functions 1 2 45 mins of pure fun Introduction Today: Pointers Pointers Even

More information

Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.)

Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.) Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.) David Haraburda January 30, 2013 1 Introduction Scala is a multi-paradigm language that runs on the JVM (is totally

More information

Continuations provide a novel way to suspend and reexecute

Continuations provide a novel way to suspend and reexecute Continuations provide a novel way to suspend and reexecute computations. 2. ML ( Meta Language ) Strong, compile-time type checking. Types are determined by inference rather than declaration. Naturally

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

CSE 431S Type Checking. Washington University Spring 2013

CSE 431S Type Checking. Washington University Spring 2013 CSE 431S Type Checking Washington University Spring 2013 Type Checking When are types checked? Statically at compile time Compiler does type checking during compilation Ideally eliminate runtime checks

More information

Functions & First Class Function Values

Functions & First Class Function Values Functions & First Class Function Values PLAI 1st ed Chapter 4, PLAI 2ed Chapter 5 The concept of a function is itself very close to substitution, and to our with form. Consider the following morph 1 {

More information

JTSK Programming in C II C-Lab II. Lecture 3 & 4

JTSK Programming in C II C-Lab II. Lecture 3 & 4 JTSK-320112 Programming in C II C-Lab II Lecture 3 & 4 Xu (Owen) He Spring 2018 Slides modified from Dr. Kinga Lipskoch Planned Syllabus The C Preprocessor Bit Operations Pointers and Arrays (Dynamically

More information

Show and Tell. 1. Plan 9 Things (brief) 2. An Extensible Compiler for Systems Programming. Russ Cox 1127 Show and Tell April 19, 2005

Show and Tell. 1. Plan 9 Things (brief) 2. An Extensible Compiler for Systems Programming. Russ Cox 1127 Show and Tell April 19, 2005 Show and Tell 1. Plan 9 Things (brief) 2. An Extensible Compiler for Systems Programming Russ Cox rsc@plan9 1127 Show and Tell April 19, 2005 who am i... Neighborhood kid 1995 summer hacking Excel (jlb)

More information

ELEC 377 C Programming Tutorial. ELEC Operating Systems

ELEC 377 C Programming Tutorial. ELEC Operating Systems ELE 377 Programming Tutorial Outline! Short Introduction! History & Memory Model of! ommon Errors I have seen over the years! Work through a linked list example on the board! - uses everything I talk about

More information

Intermediate Representations

Intermediate Representations Most of the material in this lecture comes from Chapter 5 of EaC2 Intermediate Representations Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP

More information

Lecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1

Lecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1 Lecture #16: Introduction to Runtime Organization Last modified: Fri Mar 19 00:17:19 2010 CS164: Lecture #16 1 Status Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces

More information

Lectures 5-6: Introduction to C

Lectures 5-6: Introduction to C Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most

More information

QUIZ. What is wrong with this code that uses default arguments?

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

GDB Tutorial. Young W. Lim Thr. Young W. Lim GDB Tutorial Thr 1 / 24

GDB Tutorial. Young W. Lim Thr. Young W. Lim GDB Tutorial Thr 1 / 24 GDB Tutorial Young W. Lim 2016-09-29 Thr Young W. Lim GDB Tutorial 2016-09-29 Thr 1 / 24 Outline 1 Introduction Young W. Lim GDB Tutorial 2016-09-29 Thr 2 / 24 Based on "Self-service Linux: Mastering the

More information