CS520
Fall 2013
Lab 4
Due Wednesday, October 2


Printing opcodes by name

In this program, you will be further improving the program you wrote in lab 5. Instead of printing the opcode's number, now you will be printing the opcode's name instead.

Some students have already gone well past this point in their program. For those students, this lab would represent a step backwards, and I realize you may not want to do that. If you feel you already have a good grasp on how to do this lab because you are pretty much done the program, and would rather not bother with this lab, if you do not submit anything at all for this lab I will take the grade you receive on P3 and use it in place of this lab.

Output

Your program should function as follows:
cmw@paris:~/cs520/p3/lab6$ ./dis_class ../classfile/tests/Pathetic.class 
Method Name: <init>
	0 aload_0
	1 invokespecial
	2 nop
	3 aconst_null
	4 return
Method Name: main
	0 return
cmw@paris:~/cs520/p3/lab6$ ./dis_class ../classfile/tests/Multinewarray.class 
Method Name: <init>
	0 aload_0
	1 invokespecial
	2 nop
	3 aconst_null
	4 return
Method Name: main
	0 iconst_2
	1 iconst_5
	2 multianewarray
	3 nop
	4 iconst_m1
	5 iconst_m1
	6 astore_1
	7 return
There is to be 1 command line argument, which should be a java class file. You may assume the input argument, if present, is a valid java class file. Your lab 5 code should be able to print out the opcode's numbers one at a time, but now you will instead be printing out the opcode's name.

The format is as follows. Each method should be printed in two parts. The first part should contain the words, "Method Name:" followed by a space, followed by the method's name as looked up in the constant table. The next part is the individual opcode names. Each opcode (or argument that is interpreted as an opcode) should appear on its own line. Each opcode should be preceded by a tab, followed by the index of the opcode, followed by a space, followed by the opcode's name.

Reference Solution

Once again, I am providing a sample binary for you to compare against. I expect your program and this binary to produce identical outputs.

It can be copied from ~cs520/lab6_ref which is world readable.

Note that the reference solution may not handle non existent opcodes correctly.

Testing

In order to do testing, you will need to create some java class files. I assume everyone in this class is familiar enough with java to be able to compile and build java programs. For example, here is a simple test.
-bash-4.2$ ./dis_class ../classfile/tests/Pathetic.class > Pathetic.mine
-bash-4.2$ ~cs520/lab6_ref ../classfile/tests/Pathetic.class > Pathetic.ref
-bash-4.2$ diff Pathetic.mine Pathetic.ref 
The > redirects the standard out stream from the program to a file, in the first case the file is named Pathetic.mine and the second is called Pathetic.ref. Next, the diff program compares the two outputs and notes what the differences, if any, are.

Testing files like that one at a time is labor intensive and annoying if there are a lot of files you want to test. It may be worth investing in learning how to make bash scripts (if you're old school) or python scripts (if you're new school) to automate this testing. For example, the grading scripts are all python scripts that automatically run the programs and look at the outputs, which is very effective for identifying stuff that passes perfectly.

Note that I expect all students to have done at least one diff test on a basic test file, and if your program has an error that makes it clear you did not do a diff test, you will lose points.


High level instructions

  1. If you have only completed the lab, but not the program, you should probably just continue working in the same place where your lab is. Depending on how far along you are, you may find it beneficial to fork your code for this lab.
  2. Write the necessary code. Note that some of your files will be exceedingly large. Please do not make disassemble.c a large file, please add the long stuff into a DIFFERENT file. I don't want to have to search for where your code is in the event that I have to inspect it to give partial credit.
  3. When you are done, submit your source file. In order to submit your file, you will need to be SSH'd in to agate.
    ~cs520/bin/DoSubmission.py lab6 file1.c file2.c file3.c file1.h \
      file2.h file3.h makefile
    Note that for this program, just like the assignment, you are free to structure your code however you wish, with a few restrictions. I copy all the files you submit into a directory, and then run make in that directory. That should build your program, meaning you must submit the makefile, as well as all of the different code files required to build your program.

Submitting

Please submit whatever you have at the end of lab, even if it is incomplete. You have the rest of today to finish this assignment.

Grading

Your program will be graded primarily by testing it for correct functionality. In addition, remember, you may lose points if your program is not properly structured or adequately documented. Coding guidelines are given on the course overview webpage.

Next Steps

The last step to getting this program fully working is handling the arguments that some of the opcodes have. I would recommend by figuring out how to handle the opcodes that have 1 argument, and then handle the special opcodes listed specifically in the assignment one at a time each in its own special case.