Information about the Scale compiler for use in CSE 231, Spring 2002

We had planned to set up CVS for you using your groups so that you could collaborate easier, but this isn't happening fast enough and I know some of you have already started work, so I thought I'd send instructions out and if you want to use CVS to organize your project, you can still do so, but you won't have to.

NOTE: I understand that these notes might not be 100% complete, so please feel free to ask questions of me to clarify details or debug problems. I will help as much as I can. Send the questions to for fast responses.

Here is a file full of tcsh environment variable definitions that you need to compile Scale. The comments at the top have some extra info - you need to change one of the variables to point to your directory structure in your home directory. (You also need to make changes to all of them if you don't run tcsh.)

So, if you haven't tried to get scale to work yet, here is what you need to do:

Next, if you're looking at the javadoc and wondering "where do i start?", here's a tip: the class that is called at the top level to do compilation (if you peek into the runscale script at ${SCALEHOME}/../../runscale) is scale.test.Scale .

So, to make any changes in how Scale actually compiles anything, you'll need your own version of that. I suggested subclassing it at one point, but I ended up just copying the file and renaming the class to Scale_Mike - this worked for me so far, but no guarantees.

You'll want to look at the source for scale.test.Scale - it's in ${SCALEHOME}/scale/test/ (and wherever you copied it to - hopefully to ${SCALE}/rel1.51/scale/test/

You will probably need to add a command line switch to tell Scale to do your optimization. Here's a starter on how that will get you into the code and start showing how Scale is organized:

Command line switches are represented by instances of the class CmdParam. They're defined in if you want to know how they work - look at the javadoc for what they do.
They're all declared at the top of
for instance, the FOO optimization is either on or off, so it's a switch. try:

protected CmdParam FOO = new CmdParam("FOO", true, null, "do the foo optimization");

there are other examples in the source, and you can always look at the javadocs to see what else you can do with CmdParams.
You also need to add your parameter to the params[] array - search for protected CmdParam params[] = and add it there.

you also need to add a variable that tells whether or not your switch was specified on the command line - Scale already has some, for instance doSSA and doLICM are two of them. If you're implementing the FOO optimization, you would add this line somewhere near those declarations:

protected boolean doFOO = false; // comment your code!

then how do you set this?
inside parseCmdLine, you'll need to add some code to check your parameter.
for a switch it's easy: FOO.specified() returns true if FOO was specified on the command line, so we just add this line:

doFOO = FOO.specified();

you can see the other code in parseCmdLine for examples of more complicated options.

Second, if you're now wondering, "ok, but how do I start writing an optimization?"
the optimizing transformations are in ${SCALEHOME}/scale/score/trans/
Look there for code examples.

and "how do i call my optimization from my newly subclassed or renamed version of scale.test.Scale with the new magic command line option?"

Okay, look in, and see that compile() calls either separateCompilation(..) or multiCompilation(..), which both call optimizeCallNode(), which calls optimizeScribble(), which has a bunch of if statements that look like this:

FOO foo = new FOO(scribble); // FOO is a class that inherits from scale.score.trans.Optimization.
... etcetera.
so add one for your optimization, and look at examples like scale.score.trans.GlobalVarReplacement for further info on how to actually write an optimization.