CS 142 (b) * Compiler Construction Project

advertisement
CS 142 (b) – Compiler
Construction Project
Harry Xu
Assistant Professor of Computer
Science
Compiler is becoming more and more important
…
General Information
• Heavyweight project class
• Drop the class immediately
– If you don’t like programming
– If you have more than one project classes
• Require compiler background knowledge and
C/C++ programming experience
• TA
– Gulfem Savrun Yeniceri
– Email: gsavruny@uci.edu, office: CS 444
Project—Implement a Mini-JVM
• Implement the functionality of the “java”
command for a subset of the Java language
• How a Java program is executed by a JVM
– Interpreter
– Optimizing compiler
– Feedback-directed optimization system
√
√
X
• Implement a static compiler as apposed to a
dynamic compiler as used in modern JVMs
Project Phases
Phase 1: Parsing .class files
Representations of fields,
classes, and methods
Phase 2: Building an
Interpreter
Phase 3: Building SSA
SSA representation
Phase 4: Building
dataflow optimizers
Optimized code
Phase 5: Generating
executable code
Schedule
• Phase 1: Parsing the .class file
– Week 1, 1 lecture
• Phase 2: Building an interpreter
– Week 2 and 3, 1 lecture
• Phase 3: Building SSA
– Week 4 and 5, 1 lecture
• Phase 4: Developing optimizations
– Week 6 and 7, 2 lectures
• Phase 5: Generating executable code
– Week 8 and 9, 1 lecture
• Demos in Week 10
• Lab sessions TBD
Expected Outcome
• After this quarter, you will have hands-on
experience with
– What is inside a JVM
– How to implement a real-world compiler
– How interpreter works
– Dataflow analysis and optimizations
– X86 assembler
Grading Policy
• I will provide a public set of test cases
• If your project does phase 1, 2, and 3, you will
be guaranteed to have a ‘B’
• If your project does all the five phases and
passes all my test cases, you will get an ‘A’
• If your project does an additional dataflow
optimization, you will get an ‘A+’
Overview of the .class File
ClassFile {
u4 magic;
u2 minor_version;
u2 major_version;
u2 constant_pool_count;
cp_info constant_pool[constant_pool_count-1];
u2 access_flags;
u2 this_class;
u2 super_class;
u2 interfaces_count;
u2 interfaces[interfaces_count];
u2 fields_count;
field_info fields[fields_count];
u2 methods_count;
method_info methods[methods_count];
u2 attributes_count;
attribute_info attributes[attributes_count];
// (0xCAFEBABE)
}
http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html
Your Representation
class Class{
Method[] methods; //instance and static
Field[] fields; //instance and static
Attribute[] attributes;
Class[] superclasses;
…
}
Class Method{
Qualifier[] qualifiers;
Instruction[] instructions;
}
Instruction{
int opCode;
Operand[] operands;
}
No Need to Consider
•
•
•
•
Inner classes
Exception handling
Garbage collection
Anything related to runtime system
Last but the Least
• Various tutorials and resources are available at
the course website
• You cannot rely solely on lectures; do your
homework to learn whatever necessary for
the project
Download