Representação do código objeto public class Instruction { public byte op; // op-code (0..15) public byte r; // register field (0..15) public byte n; //

Slides:



Advertisements
Similar presentations
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Advertisements

Goal: Write Programs in Assembly
Programming Languages and Paradigms
Intermediate Representation III. 2 PAs PA2 deadline is
Backpatching: The syntax directed definition we discussed before can be implemented in two or more passes (we have both synthesized attributes and inheritent.
1 Languages and Compilers (SProg og Oversættere) Code Generation.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Exercício de Interfaces O código terá erro de compilação ou executará normalmente?
Memory Management Case study (JVM & CLR) KIRAN KUMAR V KIRAN KUMAR V LENIN THUMMALAPALLI LENIN THUMMALAPALLI.
Análise Sintática – Parte 2 Árvores Sintáticas Abstratas (ASTs) Scanning.
COE Computer Organization & Assembly Language
Contextual Analysis (Chapter 5) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm Hutchinson.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch.5: Contextual Analysis Spring 2007 Marco.
Instructions Set Bo Cheng Instruction Set Design An Instruction Set provides a functional description of a processor. It is the visible.
1 Languages and Compilers (SProg og Oversættere) Lecture 11 Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch.8: Interpretation Spring 2008 Marco Valtorta.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch.7: Code Generation Spring 2008 Marco Valtorta.
1 Languages and Compilers (SProg og Oversættere) Lecture 6 Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch.5: Contextual Analysis Spring 2008 Marco.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
1 Sec (2.3) Program Execution. 2 In the CPU we have CU and ALU, in CU there are two special purpose registers: 1. Instruction Register 2. Program Counter.
Reverse-Engineering Instruction Encodings Wilson Hsieh, University of Utah Dawson Engler, Stanford University Godmar Back, University of Utah.
CS 300 – Lecture 6 Intro to Computer Architecture / Assembly Language Instructions.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
1 October 1, October 1, 2015October 1, 2015October 1, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa.
Interpretation (Chapter 8) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch.5: Contextual Analysis Spring 2013 Marco.
1 Languages and Compilers (SProg og Oversættere) Lecture 6 Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
Interfaces and Polymorphism CS 162 (Summer 2009).
 Fall Chart 2  Translators and Compilers  Textbook o Programming Language Processors in Java, Authors: David A. Watts & Deryck F. Brown, 2000,
JAVA for(int i = 0; i < 100; i++) { Statements } BASIC For i = 1 to 100; Statements Next i FORTRAN do counter = 1,100, 1 statements end do PASCAL for Counter.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm Hutchinson.
1 Interfaces and Abstract Classes The ability to define the behavior of an object without specifying that behavior is to be implemented Interface class.
1 Languages and Compilers (SProg og Oversættere) Lecture 9 (1) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm.
Module 13: Properties and Indexers. Overview Using Properties Using Indexers.
Code Generation (Chapter 7) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm Hutchinson.
First Foray into Programming (the hard way). A reminder from last lesson: A machine code instruction has two parts:  Op-code  Operand An instruction.
RealTimeSystems Lab Jong-Koo, Lim
R Byte Code Optimization Compiler (1) March
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016.
Web Design & Development Lecture 9
Course Overview PART I: overview material PART II: inside a compiler
Morgan Kaufmann Publishers
Refactoring Methods: Kevin Murphy.
University of Central Florida COP 3330 Object Oriented Programming
Instruction Formats Each instruction consists of two parts:
The fetch-execute cycle
Computer Architecture & Operations I
Computer Architecture
Computer Programming Machine and Assembly.
null, true, and false are also reserved.
Interface.
Introduction to Java Programming
The Boolean (logical) data type boolean
Interfaces.
Code Animation Examples
JavaScript Reserved Words
Classification of instructions
class PrintOnetoTen { public static void main(String args[]) {
Languages and Compilers (SProg og Oversættere)
Instruction encoding We’ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers.
Course Overview PART I: overview material PART II: inside a compiler
CSCE 531 Compiler Construction Ch.7: Code Generation
Languages and Compilers (SProg og Oversættere)
Languages and Compilers (SProg og Oversættere)
Sec (2.3) Program Execution.
Presentation transcript:

Representação do código objeto public class Instruction { public byte op; // op-code (0..15) public byte r; // register field (0..15) public byte n; // length field (..255) public short d; // operand field ( …

Representação do código objeto (2) public class Instruction { … public static final byte LOADop = 0, LOADAop = 1 LOADIop = 2, LOADLop = 3, STOREop = 4, STOREIop = 5, CALLop =6, CALLIop = 7, RETURNop = 8, PUSHop = 10, POPop = 11, JUMPop = 12, JUMPIop = 13, JUMPIFop = 14, HALTop = 15; …

Representação do código objeto (3) public class Instruction { … public static final byte CBr = 0, CTr = 1, PBr = 2, PTr = 3, SBr = 4, STr = 5, HBr = 6, HTr = 7, LBr = 8, L1r = 9, L2r = 10, L3r = 11, L4r = 12, L5r = 13, L6r = 14, CPr = 15; public Instruction (byte op, byte r, byte n, short d) {…}

Representação do programa objeto private Instruction[] code = new Instruction[1024]; private short nextInstrAddr = 0; private void emit (byte op, byte n, byte r, short d) { code[nextInstrAddr++] = new Instruction(op, n, r, d);

Geração de código – uso do padrão visitor public final class Encoder implements Visitor { … … public void encode (Program prog) { prog.visit(this, null); } }

Geração de código public Object visitProgram (Program prog, Object arg) { prog.C.visit(this, arg); emit(Instruction.HALTop,0,0,0); }

Geração de código (atribuição) public Object visitAssignCommand (AssignCommand com, Object arg) { com.E.visit(this, arg); encodeAssign(com.V); return null; }

Geração de código (call) public Object visitCallCommand (CallCommand com, Object arg) { com.E.visit(this, arg); short p = address of routine com.I; emit(Instruction.CALLop, Instruction.SBr, Instruction PBr, p); return null; }

Geração de código (sequencial) public Object visitSequentialCommand (SequentialCommand com, Object arg) { com.C1.visit(this, arg); com.C2.visit(this, arg); return null; }

Geração de código (Let) public Object visitLetCommand (LetCommand com, Object arg) { com.D.visit(this, arg); com.C.visit(this, arg); short s = espaço alocado por D; if (s > 0) emit (Instruction.POPop,0,0,s); return null; }

Geração de código (Inteiro) public Object visitIntegerExpression (IntegerExpression expr, Object arg) { short v = valuation(expr.IL.spelling); emit (Instruction.LOADLop,0,0,v); return null; }

Geração de código (Variável) public Object visitVNameExpression (VNameExpression expr, Object arg) { encodeFetch(expr.V); return null; }

Geração de código (Operação) public Object visitUnaryExpression (UnaryExpression expr, Object arg) { expr.E.visit(this, arg); short p = endereço da rotina expr.O; emit (Instruction.CALLop, Instruction.SBr, Instruction.PBr, p); return null; }

Backpatching public Object visitWhileCommand (whileCommand com, Object arg) { short j = nextInstrAddr; emit(Instruction.JUMPop,0, Instruction.CBr,0); short g = nextInstrAddr; com.C.visit(this,arg); short h = nextInstrAddr; patch(j,h); com.E.visit(this, arg); emit(Instruction.JUMPIFop,1,Instruction.CBr,g); return null; }

Declaração de Constantes e Variáveis Known Value x Unknown Value Known Address x Unknown Address Lifetime

Alocação estática public abstract class RuntimeEntity { public short size; …} public class KnownValue extends RuntimeEntity { public short value; …} public class UnknownValue extends RuntimeEntity { public short address; …}

Alocação estática (2) public class KnownAddress extends RuntimeEntity { public short address; …}