Unformatted text preview:

Getting It Right Getting It Right COMS W4115 Subjects Your compiler is a large software system developed by four people Team oriented development Interface oriented design Version control systems assert Regression test suites Writing tests Code coverage Makefiles How do you get it right Prof Stephen A Edwards Spring 2003 Columbia University Department of Computer Science Team oriented Development Interface oriented Development Interface oriented design Basic challenge Remove as many inter person dependencies as possible Divide your compiler into a series of modules e g Write the interfaces first One group asked if the lexer parser person should finish before the tree walker person started Divide and conquer try to make it so that each person can work at his her own rate and not depend on others 1 Lexer Parser Document them well 2 Static semantics Write the public class definition the method declarations and the comments first 3 Code generation Later fill in code for each method private fields etc 4 Assembler Tricky each pass depends on the previous one Clearly define the interface between each module Solution careful design and modularity You ll want to write this in your project report anyway Use javadoc to extract documentation from your Java code and share with other group members Make the interfaces the contracts between the team members Version Control Systems The CVS Version Control System Four people working on a single program is not as easy as just one Basic model Need some way to make sure everybody s working on the same program Version control systems a good solution Grammar g v Repository Main java v Makefile v Grammar g Parser java Alice s Lexer java working Main java directory Main class Makefile Using the CVS Version Control System 1 Prepare a repository 2 Add an empty sudirectory to the repository 3 Create a working directory Grammar g Bob s Main java working Main class directory Makefile 4 Add files update directory commit changes One group member does 1 2 once Each group member does 3 once Each group member does 4 repeatedly Using CVS Assert Creating a working directory class Foo public static void main String args assert false Catch errors early and often Check function arguments are acceptable Check function return value is consistent javac source 1 4 foo java java ea Foo Exception in thread main java lang AssertionError at Foo main foo java 3 Check constructor has filled in every field Check object state is consistent Check loop invariants For the really ambitious write methods that check consistency of a whole data structure mkdir mydir cd mydir cvs checkout ourproj Editing adding and updating cd ourproj edit files compile etc cvs add Grammar g cvs commit Grammar g cvs update Assert Philosophy E g assert n null Regression test suites Regression tests Example tests How to avoid introducing new bugs when adding features Easiest is when program takes a text file as input and produces text as output module test emit1 type a type b input a input b integer output c integer Partial answer build something that tells you whether you ve broken the program Regression suite collection of tests exercises as much of your program as possible results are compared with golden references Fortunately compilers behave like this Regression test inputs short programs Regression test golden references assembly language emit a emit b emit c module output output output emit a emit b 10 emit c 5 0f end module end module Writing Tests Running Tests Shell Script Try to cover as much of your language as possible Easiest is to use a scripting language that Carefully runs two programs Try to write one test for each feature mentioned in the language reference manual Build sequences of tests that start with simple versions of a feature and build into the most complex Keep tests focused easier to track down fault if one fails invokes the test Compares output to reference file compares the outputs and Stores results when it differs logs results and any errors bin sh For CEC I wrote a shell script to do this test emit2 a b integer c float STRLXML strlxml XMLSTRL xmlstrl globallog teststrlxml log rm f globallog error 0 Shell Script Check basename echo 1 sed s s strl reffile echo 1 sed s strl out xmlfile basename xml outfile basename out difffile basename diff echo n Parsing basename echo Parsing basename 1 2 STRLXML 1 xmlfile 2 1 echo FAILED strlxml terminated error 1 return 1 XMLSTRL xmlfile outfile 2 1 echo FAILED xmlstrl terminated error 1 return 1 Shell Script diff b reffile outfile difffile 2 1 echo FAILED output mismatch error 1 return 1 rm xmlfile outfile difffile echo OK for file in tests test strl do Check file 2 globallog done Code coverage Basic idea your test suite should at least send the program counter over every part of your code To measure coverage need some sort of tool that can tell when each line of code is executed I found a couple of them gcov works with gcc to report for C C clover Commercial tool for Java but free for students and open source developers There are many more exit error Example of gcov Makefiles A Basic Makefile gcc fprofile arcs ftest coverage tmp c a out gcov tmp c 87 50 of 8 source lines executed in file tmp c Creating tmp c gcov How do you make it easy to compile your compiler cat Makefile Simp class Simp java javac Simp java make Simp class javac Simp java make Simp class make Simp class is up to date 1 1 11 10 1 1 1 main int i total total 0 for i 0 i 10 i total i if total 45 printf Failure n else printf Success n Need to run ANTLR to generate files then run javac on the results How do you make sure everything gets compiled when needed A More Complicated Makefile A More Complicated Makefile JAVASRC SimpParser java SimpWalker java SimpLexer java SimpParserTokenTypes java make Rules take the form java antlr Tool Simp g target source source ANTLR Parser Generator Version 2 7 1 1989 2000 jGuru com javac SimpParser java SimpWalker java SimpLexer java SimpParserTokenTypes java z commands rm SimpParser class tab make Variable definition and use javac SimpParser java SimpWalker java SimpLexer java SimpParserTokenTypes java variable value make clean rm f class SimpParserTokenTypes txt variable SimpParser java SimpWalker java SimpLexer java SimpParserTokenTypes java SimpParser class JAVASRC javac JAVASRC SimpParser java SimpLexer java Simp g java antlr Tool Simp g clean rm f class SimpParserTokenTypes txt SimpParser java SimpWalker java SimpLexer java


View Full Document

Columbia COMS W4115 - Getting It Right

Documents in this Course
YOLT

YOLT

13 pages

Lattakia

Lattakia

15 pages

EasyQL

EasyQL

14 pages

Photogram

Photogram

163 pages

Espresso

Espresso

27 pages

NumLang

NumLang

6 pages

EMPATH

EMPATH

14 pages

La Mesa

La Mesa

9 pages

JTemplate

JTemplate

238 pages

MATVEC

MATVEC

4 pages

TONEDEF

TONEDEF

14 pages

SASSi

SASSi

16 pages

JTemplate

JTemplate

39 pages

BATS

BATS

10 pages

Synapse

Synapse

11 pages

c.def

c.def

116 pages

TweaXML

TweaXML

108 pages

Load more
Loading Unlocking...
Login

Join to view Getting It Right and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Getting It Right and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?