byucc.jhdl.base
Class CompiledCodeGenerator

java.lang.Object
  extended bybyucc.jhdl.base.CompiledCodeGenerator
All Implemented Interfaces:
PreDefinedSchematic

public abstract class CompiledCodeGenerator
extends java.lang.Object
implements PreDefinedSchematic

This class is a generic interface for compiled code simulators. The default JHDL MCSimulator is used to do all of the scheduling of circuit elements. At the level where the various PropagateableLists are fired during simulation, this interface allows that part of the inner loop to be offloaded into a compiled code backend. The class was written with the principal intent to allow my bytecode compiled code version to be leveraged to support native assembly code. Admittedly, I know relatively little about assembly programming, and simply make a naive attempt to make a generic interface that abstracts much of the complexities of dealing with JHDL simulation. The basic idea is the concept of a location. The abstract methods implemented by a particular back end operate on locations (in assembly I thought of either addresses or registers, for the byte codes it would be stack location (almost always the top). The initializeCode() method is used to set up the global data structures needed for the operation of the simulation. The array of value propagaters is used extensively to create the code. The extending classes must know how to retrieve information from a ValuePropagater and store information to it. The implementation is left up to the user. Another important concept is the label. It is assumed that the code is generated as the abstract methods are called. The setLabelLocation() method is called where the jump label needs to be. So, a gotoLabel() will occur before the label location is set (we don't know where it is yet!)

Author:
Brett H Williams $Id: CompiledCodeGenerator.java,v 3.4 2001/12/06 21:40:02 aslade Exp $

Field Summary
protected static boolean DEBUG
           
protected static long multiputs
           
protected  byucc.jhdl.base.ValuePropagater[] vp_array
           
 
Fields inherited from interface byucc.jhdl.apps.Viewers.Schematic.PreDefinedSchematic
PreDefinedSchematic_ADD, PreDefinedSchematic_ADDSUB, PreDefinedSchematic_AND, PreDefinedSchematic_BUF, PreDefinedSchematic_CONST, PreDefinedSchematic_GEN, PreDefinedSchematic_GND, PreDefinedSchematic_INC, PreDefinedSchematic_INV, PreDefinedSchematic_MUX, PreDefinedSchematic_NAND, PreDefinedSchematic_NOR, PreDefinedSchematic_OR, PreDefinedSchematic_PULLDOWN, PreDefinedSchematic_PULLUP, PreDefinedSchematic_REG, PreDefinedSchematic_SHL, PreDefinedSchematic_SHR, PreDefinedSchematic_TBUF, PreDefinedSchematic_VCC, PreDefinedSchematic_XNOR, PreDefinedSchematic_XOR
 
Constructor Summary
CompiledCodeGenerator(byucc.jhdl.base.ClockableList cl)
          Generates code for a clockable list.
CompiledCodeGenerator(byucc.jhdl.base.PropagateableList pl)
          Generates code for a PropagateableList.
 
Method Summary
abstract  int andIntegers(int location1, int location2)
          Perform a bitwise AND on two locations.
abstract  int andIntegerWithConstant(int location, int constant)
          Perform a bitwise AND on a constant and a value
abstract  void finalizeCode()
          Do things like compilation, writing to file, anything necessary to prepare the code for running.
protected  void generateCodeForClockable(Clockable c)
           
protected  void generateCodeForPropagateable(byucc.jhdl.base.Propagateable p)
           
protected  int getVPWireValue(int index)
           
abstract  void gotoLabel(java.lang.String label)
          Jump! Now!
abstract  void gotoLabelIfLtZero(int location, java.lang.String label)
          If the value in location is less than zero, then branch to the label.
abstract  void handleUnrecognizedPropagateable(byucc.jhdl.base.Propagateable p, int index)
          Handle a Propagateable that the CompiledCodeGenerator can't.
protected  void initGlobalVPArray(byucc.jhdl.base.ClockableList cl)
           
protected  void initGlobalVPArray(byucc.jhdl.base.PropagateableList pl)
           
abstract  void initializeCode()
          Performs necessary code initialization.
abstract  int loadConstant(int constant)
          Load a constant into a location.
abstract  int loadVPDataField(int index)
          Loads the data field of a ValuePropagater.
abstract  int notInteger(int location)
          Perform a bitwise NOT on a value
abstract  int orIntegers(int location1, int location2)
          Perform a bitwise OR on two locations.
abstract  int orIntegerWithConstant(int location, int constant)
          Perform a bitwise OR on a constant and a value
abstract  void printDebugInfo()
          Embed code to print debug information.
abstract  void printLocationContents(int location)
          Embed code to print the contents of a location.
abstract  void printMessage(java.lang.String msg)
          Embed code to print a message.
protected  void putVPWireValue(int location, int index)
           
abstract  void setLabelLocation(java.lang.String label)
          Mark the current point in the generated code with this label.
abstract  int shiftLeft(int location, int shift_amt)
          Shifts a value left by shift_amt places.
abstract  int shiftRightLogical(int location, int shift_amt)
          Shifts a value right by shift_amt places.
abstract  void simulate()
          Execute the generated Code.
abstract  void storeVPDataField(int location, int index)
          Stores a value into the data field of a ValuePropagater.
 int type()
          This method returns one of the predefined schematic constants to identify the type of this cell.
abstract  int xorIntegers(int location1, int location2)
          Perform a bitwise XOR on two locations.
abstract  int xorIntegerWithConstant(int location, int constant)
          Perform a bitwise XOR on a constant and a value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

protected static boolean DEBUG

multiputs

protected static long multiputs

vp_array

protected byucc.jhdl.base.ValuePropagater[] vp_array
Constructor Detail

CompiledCodeGenerator

public CompiledCodeGenerator(byucc.jhdl.base.PropagateableList pl)
Generates code for a PropagateableList.

Parameters:
pl - Contains cells and wires to simulate.

CompiledCodeGenerator

public CompiledCodeGenerator(byucc.jhdl.base.ClockableList cl)
Generates code for a clockable list.

Parameters:
cl - Contains synchronous elements to simulate.
Method Detail

initializeCode

public abstract void initializeCode()
Performs necessary code initialization. This method is intended to make the global data structure of ValuePropagaters that will be used throughout simulation. It also will create any other things (i.e., JNI files or whatever) that will be needed for the back end to begin code generation.


finalizeCode

public abstract void finalizeCode()
Do things like compilation, writing to file, anything necessary to prepare the code for running.


loadVPDataField

public abstract int loadVPDataField(int index)
Loads the data field of a ValuePropagater.

Parameters:
index - Index of the ValuePropagater to load
Returns:
location of the loaded field

storeVPDataField

public abstract void storeVPDataField(int location,
                                      int index)
Stores a value into the data field of a ValuePropagater.

Parameters:
location - the location of the value to store
index - Index of the ValuePropagater to store into

andIntegerWithConstant

public abstract int andIntegerWithConstant(int location,
                                           int constant)
Perform a bitwise AND on a constant and a value

Parameters:
location - location of the non-constant value
constant - the constant to AND with
Returns:
the location of the result

andIntegers

public abstract int andIntegers(int location1,
                                int location2)
Perform a bitwise AND on two locations.

Parameters:
location1 - first location
location2 - second location
Returns:
the location of the result.

orIntegerWithConstant

public abstract int orIntegerWithConstant(int location,
                                          int constant)
Perform a bitwise OR on a constant and a value

Parameters:
location - location of the non-constant value
constant - the constant to AND with
Returns:
the location of the result

orIntegers

public abstract int orIntegers(int location1,
                               int location2)
Perform a bitwise OR on two locations.

Parameters:
location1 - first location
location2 - second location
Returns:
the location of the result.

xorIntegerWithConstant

public abstract int xorIntegerWithConstant(int location,
                                           int constant)
Perform a bitwise XOR on a constant and a value

Parameters:
location - location of the non-constant value
constant - the constant to AND with
Returns:
the location of the result

xorIntegers

public abstract int xorIntegers(int location1,
                                int location2)
Perform a bitwise XOR on two locations.

Parameters:
location1 - first location
location2 - second location
Returns:
the location of the result.

notInteger

public abstract int notInteger(int location)
Perform a bitwise NOT on a value

Parameters:
location - location of the non-constant value
Returns:
the location of the result

shiftLeft

public abstract int shiftLeft(int location,
                              int shift_amt)
Shifts a value left by shift_amt places. This could be handled at a higher level but this could lead to problems with different integer width machines. It's easy to do for the back end writer anyway.

Parameters:
location - the location of the value to shift
shift_amt - how many places to shift
Returns:
the location of the result

loadConstant

public abstract int loadConstant(int constant)
Load a constant into a location.

Parameters:
constant - constant to load
Returns:
location of the result

shiftRightLogical

public abstract int shiftRightLogical(int location,
                                      int shift_amt)
Shifts a value right by shift_amt places. Note that the shift must be a logical shift and not arithmetic, or the propagate method for which it was used will not work

Parameters:
location - the location of the value to shift
shift_amt - how many places to shift
Returns:
the location of the result

printMessage

public abstract void printMessage(java.lang.String msg)
Embed code to print a message. Prints debug messages when DEBUG is true.

Parameters:
msg -

printDebugInfo

public abstract void printDebugInfo()
Embed code to print debug information. This could be used to dump register contents or address locations, for example.


printLocationContents

public abstract void printLocationContents(int location)
Embed code to print the contents of a location.

Parameters:
location -

gotoLabelIfLtZero

public abstract void gotoLabelIfLtZero(int location,
                                       java.lang.String label)
If the value in location is less than zero, then branch to the label.

Parameters:
location - location of the int to compare to zero
label - branch label to jump to

gotoLabel

public abstract void gotoLabel(java.lang.String label)
Jump! Now!

Parameters:
label - branch label to jump to

setLabelLocation

public abstract void setLabelLocation(java.lang.String label)
Mark the current point in the generated code with this label.

Parameters:
label - the branch label

handleUnrecognizedPropagateable

public abstract void handleUnrecognizedPropagateable(byucc.jhdl.base.Propagateable p,
                                                     int index)
Handle a Propagateable that the CompiledCodeGenerator can't. Currently, this means anything that is not a normal boolean gate. In the ByteCodeGenerator, this is handled by simply calling the behavior method of the propagateable. You could also throw an exception or handle it in the extending class's code.

Parameters:
p - the unrecognized Propagateable
index - the wire index of the first input to the cell (indexes into the global ValuePropagater array)

simulate

public abstract void simulate()
Execute the generated Code.


getVPWireValue

protected int getVPWireValue(int index)

putVPWireValue

protected void putVPWireValue(int location,
                              int index)

initGlobalVPArray

protected void initGlobalVPArray(byucc.jhdl.base.PropagateableList pl)

initGlobalVPArray

protected void initGlobalVPArray(byucc.jhdl.base.ClockableList cl)

generateCodeForPropagateable

protected void generateCodeForPropagateable(byucc.jhdl.base.Propagateable p)

generateCodeForClockable

protected void generateCodeForClockable(Clockable c)

type

public int type()
Description copied from interface: PreDefinedSchematic
This method returns one of the predefined schematic constants to identify the type of this cell.

Specified by:
type in interface PreDefinedSchematic
Returns:
A predefined schematic constant


Copyright ? 2006 Brigham Young University, Configurable Computing Laboratory. All Rights Reserved.