A Look at the MIRV Compiler System EECS 483 Supplementary Information for Project 2 October 9, 2006.

Slides:



Advertisements
Similar presentations
Computer Programming Lecture 14 C/C++ Pointers
Advertisements

Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Intermediate Code Generation
Programming and Data Structure
Programming Languages and Paradigms The C Programming Language.
C Programming Day 1 based upon Practical C Programming by Steve Oualline CS550 Operating Systems.
Kernighan/Ritchie: Kelley/Pohl:
Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
ECE 103 Engineering Programming Chapter 11 One Minute Synopsis Herbert G. Mayer, PSU CS Status 7/1/2014.
Declarations and Expressions C and Data Structures Baojian Hua
Primitive Variable types Basic types –char (single character or ASCII integer value) –int (integer) –short (not longer than int) –long (longer than int)
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Guide To UNIX Using Linux Third Edition
Data Types.
FunctionsFunctions Systems Programming Concepts. Functions   Simple Function Example   Function Prototype and Declaration   Math Library Functions.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Computer Science 210 Computer Organization Introduction to C.
1 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University.
High-Level Programming Languages: C++
CIS Computer Programming Logic
18-2 Understand “Scope” of an Identifier Know the Storage Classes of variables and functions Related Chapter: ABC 5.10, 5.11.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
C Tokens Identifiers Keywords Constants Operators Special symbols.
CPS120: Introduction to Computer Science
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
COMPUTER PROGRAMMING. variable What is variable? a portion of memory to store a determined value. Each variable needs an identifier that distinguishes.
Pointers: Basics. 2 What is a pointer? First of all, it is a variable, just like other variables you studied  So it has type, storage etc. Difference:
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics.
Chapters 1-5 Review C++ Class. Chapter 1 – the big picture Objects Class Inheritance Reusability Polymorphism and Overloading.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
Slides created by: Professor Ian G. Harris Hello World #include main() { printf(“Hello, world.\n”); }  #include is a compiler directive to include (concatenate)
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee C Language Part 1.
CPS120: Introduction to Computer Science Variables and Constants.
EEL 3801 C++ as an Enhancement of C. EEL 3801 – Lotzi Bölöni Comments  Can be done with // at the start of the commented line.  The end-of-line terminates.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
C programming---Pointers The first step: visualizing what pointers represent at the machine level. In most modern computers, main memory is divided into.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
C is a high level language (HLL)
FUNCTIONS (CONT). Midterm questions (21-30) 21. The underscore can be used anywhere in an identifier. 22. The keyword void is a data type in C. 23. Floating.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Pointers: Basics. 2 Address vs. Value Each memory cell has an address associated with it
Basic Concepts:- Invalid use of Address Operator &75 &(‘a’) &(a+b)
Module 6 – Decision Control Statements Objectives  Understands Increment/Decrement operators, Conditional and special operators in C  Understands significance.
Computer Science 210 Computer Organization
COM S 326X Deep C Programming for the 21st Century Prof. Rozier
C Short Overview Lembit Jürimägi.
C Basics.
Introduction to C Programming
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
An Introduction to Java – Part I, language basics
Variables in C Topics Naming Variables Declaring Variables
Program Breakdown, Variables, Types, Control Flow, and Input/Output
C Programming Getting started Variables Basic C operators Conditionals
2. Second Step for Learning C++ Programming • Data Type • Char • Float
C++ Programming Basics
Module 2 Variables, Data Types and Arithmetic
Programming Languages and Paradigms
C Language B. DHIVYA 17PCA140 II MCA.
INTRODUCTION TO C.
Presentation transcript:

A Look at the MIRV Compiler System EECS 483 Supplementary Information for Project 2 October 9, 2006

Overview MIRV compiler –Frontend Convert C to MIRV IR (Project 2) –Backend Convert MIRV IR to assembly code (Project 3) Simplescalar simulator –Sim-fast functional simulator –Sim-outorder behavioral simulator

MIRV Overview High Level Intermediate Representation Textual Format A “sanitizied C” –Type declarations, constant declarations, etc. Prefix Form AST c = a+b  = c + a b Developed by Dave Green and Matt Postiff

Fundamental Concepts Symbol –Abstract representation of a program object Constant (Data value) Variable (Storage location) Function (Program text) Type (Object characteristic – a “meta object”) Unid: UNique ID –Every symbol has one –Present a flat namespace –[a-zA-Z][\.a-zA-Z_0-9]*

General Program Structure (before use) (of things declared) (flat namespace, no declarations in loops, if-else, etc)

Packages and Modules Package version unid __mirv_pack version { name “__mirv_pack” } Module unid __mirv_pack.ml { }

Symbols All Symbols Are Declared –tsdecl: “type simple” decl (int, float, pointer, array) –tcdel: “type complex” decl (struct, union) –tfdecl: “type function” decl (function signature) –vdecl: variable decl –cdecl: constant decl –fdecl: function decl Must declare a symbol before using it!

Type Declaration Integer Type –tsdecl unid integer – : (signed | unsigned) Pointer Type –tsdecl unid pointer unid Array Type –tsdecl unid array unid { } Function Type –tfdecl unid { }

Simple Type Example C int *ptr[10]; MIRV –Type names can be anything, but need to be unique and consistent tsdecl unid sint32_t integer signed 32 tsdecl unid sint32_t_p_t pointer unid sint32_t tsdecl unid sint32_t_p_t_10_t array unid sint32_t_p_t { 10 }

Constant String Type C (type declaration for “%d\n”) printf(“%d\n”, x); MIRV tsdecl unid sint8_t_4_t array unid sint8_t { 4 } –‘\n’ is a single char –Leave room for the ‘\0’!

Function Type Example C int foo(int); MIRV tfdecl unid sint32_t_sint32_t_t { retValType sint32_t argType sint32_t }

Function Type Example C int bar(void); MIRV tfdecl unid sint32_t_sint0_t_t { retValType sint32_t } NOTE: No argType! (inconsistency)

Vararg Function Type C extern int printf(char *a, …); MIRV tfdecl unid sint32_t_sint8_t_p_t_va_t { retValType sint32_t argType sint8_t_p_t varArgList }

Symbol Linkage Specify Symbol Visibility –Global -> export (visible to anyone) –Extern -> import (visible from anyone) –Static -> internal (visible only within file) –Local -> internal (visible only within function) Affect Variables and Functions –Functions and global variables must retain their original C names for the linker to work properly!

Declarations Example C int global = 10; int main(void); extern int printf(char *, …); MIRV vdecl export unid global unid sing32_t {} cdecl unid c10_c unid sint32_t 10 fdecl export unid main unid sint32_t_sint0_t_t fdecl import unid printf unid sint32_t_va_t

Declaring Constant String C (declaration for “%d\n”) printf(“%d\n”, x); MIRV cdecl unid const_8 unid sint8_t_4_t "%d\n\0"

Variable Declaration Unique names for all local variables –C void foo() { int a; int b; } void main() { int a; } –MIRV fdef unid fib { vdecl internal unid a_1 unid sint32_t {} vdecl internal unid b_2 unid sint32_t {} } fdef unid main { vdecl internal unid a_3 unid sint32_t {} } Rename all local variables –Keep a global counter in Bison NOTE: all global variables and functions need to retain their original name!

Function Argument Declaration C int foo (int a, int b) { … } MIRV fdef unid foo { retDecl unid foo.__retval unid sint32_t argDecl unid a_1 unid sint32_t argDecl unid b_2 unid sint32_t … }

Attributes Not used in this class, but MIRV backend needs them Defined before every type, function and constant declaration. ( technically not necessary, but …) –i.e. attribute { name “my_global” } vdecl unid my_global unid sint32_t {}

Attributes Variables need more (these are safe defaults) attribute { name “my_local” register false addrof true temp false } Return ( retdecl ) attribute is a bit different, please refer to the sample MIRV output

Definitions Specify the “Value” of a Symbol –Types: none –Constants: none (in declaration) –Functions: body (the “guts” of the program) –Variables: assignment (in function definition)

Definition Example C void foo(void) { int local; } MIRV fdef unid main { vdecl internal unid foo.local_1 unid sint32_t return }

Expressions Reference values: –By symbol name: (vref, cref, aref) –Through indirection: (deref, airef) Specify computation: –Arithmetic (+, -, /, *) –Comparison ( =, >) –Boolean evaluation (cand, cor, not) –Casting/Addressing (cast, addrOf) Prefix Form (“Easy” to Translate)

Referencing Data C int scalar; int *pointer; scalar pointer *pointer 10 MIRV vref unid scalar vref unid pointer deref vref unid pointer cref unid c10_c

Array References C int array[10]; int *p; array[2]; p[i]; MIRV aref unid array { cref unid c8_c } airef unid p { #Remember, we address bytes! * vref unid i cref unid c4_c }

Statements Specify Machine State Changes –Data value update (assignment) –Control sequencing (program counter update) Block ({}, a list of sequential statements) Conditionals (if, ifElse) Loops (while) Function calls (fcall) Function returns (return) NOTE: Function calls are not expressions as in C— –Need to create temporary variables to handle them Also “prefix” form

Statement Grammar assign { } if ifElse while –NOTE: for “For” loop, initialization before while statement, update in fcall unid { } return

Assignments C int foo(int a, char b) { return (a+b); } MIRV fdef unid foo { assign vref unid foo.__retval + vref unid foo.a_1 cast unid sint32_t vref unid foo.b_2 return }

Conditionals C if (x<10) x = x + 1; else x = 0; MIRV ifElse < vref unid x cref unid c10_c { assign vref unid x + vref unid x cref unid c1_c }{ assign vref unid x cref unid c0_c }

Loops C for (x=0; x } MIRV assign vref unid x cref unid c0_c while < vref unid c cref unid c10_c { assign vref unid x + vref unid x cref unid c1_c }

Function Calls C void foo(void) { bar(); a = foo() + 1; } MIRV fcall unid bar {} assign vref unid foo.__tmp_2 fcall unid foo {} assign vref unid a + vref unid foo.__tmp_2 cref unid c1_c }

Vararg Function Calls C char c; printf(“%c”, c); MIRV fcall unid printf { cast unid sint8_t_p_t addrOf unid sint8_t_3_t_p_t cref unid string_l cast unid sint32_t vref unid c } NOTE: remember the promotions!

Gotchas: “Array” Assignment C int array[10]; int *p; p = array; MIRV assign vref unid p cast unid sint32_t_p_t addrOf unid sint32_t_10_t_p_t vref unid array –Arrays are “first-class” objects!

Gotchas: Pointer Arithmetic C int *p; p = p + i; MIRV assign vref unid p + vref unid p * vref unid i cref unid c4_c –This is like &p[i], so we must scale the address

Questions Please post questions on the newsgroup so other people can benefit from them too Get started on the project now!