com.joanju.cg.compileunit
Class InstructionSet

java.lang.Object
  extended by com.joanju.cg.compileunit.InstructionSet

public class InstructionSet
extends java.lang.Object

Target for Compiler Bytecode instructions. Provides services for add/move/remove of Bytecode instructions for a single compile unit. It maintains internal Maps of the bytecode instructions for fast lookup and sorted iteration by address.


Field Summary
 Checkvals checkvalCache
           
static int LAZY_LOAD_FROM_DB
           
 PProcedureCache ppcache
          We keep a persistent procedure cache around for as long as we're working on this one instruction set.
 
Constructor Summary
InstructionSet(int cuid)
           
InstructionSet(int cuid, int flags)
          Valid bit field flags are: LAZY_LOAD_FROM_DB.
 
Method Summary
 void addRecalc(java.util.Collection<java.lang.Integer> addresses)
          Add a set of instruction addresses to schedule for localRecalc.
 void addRecalc(int addr)
          Add a single instruction address to schedule for localRecalc.
 void addRecalcCalls()
          Add recalcs for all Call instructions.
 void addRecalcCallSupers()
          Add recalcs for all Callsuper instructions.
 void calcLocalValues()
          Calculate the local values for all instructions in this set.
 int fillFromDB()
          Construct the instruction set from the database.
 int fillFromDBWithData()
          Construct the instruction set from the database with data.
 void finalizeAndStoreCheckedRecords()
          This is called from Checkvals.
 void finalizeAndStoreNewBuild(int[] fileIDIndex)
           
 Bytecode get(int address)
           
 java.util.TreeMap<java.lang.Integer,Bytecode> getCopy()
           
 ProcedureInstr getProcedureInstrFor(int address)
          For an input instruction address, get the ProcedureInstr for the procedure it belongs to.
 java.util.ArrayList<Bytecode> getSortedList()
           
 Bytecode getThisProcedureExprInstr()
          For THIS-PROCEDURE as an r-value, just need an instruction which returns this CUID.
 boolean isProcNameExpression()
          Used by BuiltinfuncInstr.
 int lookupLocalProcedureAddress(int nameID)
           
 java.util.HashSet<int[]> lookupSupersLocally(int procnameID)
          Lookup a set of local supers {cuid, procaddress} for a procedure name.
 void move(Bytecode bc, int newAddress)
           
 int nextSequentialHeaderInstructionAddress()
           
 void put(Bytecode bc)
           
 void rebuildSuperProceduresLookupTable()
           
 void recalc()
           
 Bytecode remove(int address)
           
 ScriptValsInstr scriptValsInstr(java.util.Collection<java.lang.String> strings)
          Add a ScriptValsInstr to the header, returns the new instruction record.
 void setProcNameExpression(boolean on)
          Set by the code generator.
 Bytecode stringLiteralInstruction(java.lang.String s)
          Get or create a LiteralstrInstr for the input string.
 void writeFixedHeaderInstructions()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LAZY_LOAD_FROM_DB

public static final int LAZY_LOAD_FROM_DB
See Also:
Constant Field Values

checkvalCache

public Checkvals checkvalCache

ppcache

public PProcedureCache ppcache
We keep a persistent procedure cache around for as long as we're working on this one instruction set. We certainly can't keep it around any longer than that - records written to the database would invalidate the cache.

Constructor Detail

InstructionSet

public InstructionSet(int cuid)

InstructionSet

public InstructionSet(int cuid,
                      int flags)
Valid bit field flags are: LAZY_LOAD_FROM_DB.

See Also:
LAZY_LOAD_FROM_DB
Method Detail

addRecalc

public void addRecalc(int addr)
Add a single instruction address to schedule for localRecalc.


addRecalc

public void addRecalc(java.util.Collection<java.lang.Integer> addresses)
Add a set of instruction addresses to schedule for localRecalc.


addRecalcCalls

public void addRecalcCalls()
                    throws java.sql.SQLException
Add recalcs for all Call instructions.

Throws:
java.sql.SQLException

addRecalcCallSupers

public void addRecalcCallSupers()
                         throws java.sql.SQLException
Add recalcs for all Callsuper instructions.

Throws:
java.sql.SQLException

calcLocalValues

public void calcLocalValues()
                     throws java.sql.SQLException,
                            java.io.IOException
Calculate the local values for all instructions in this set. Takes care of anything that's been added to the recalcLocal set due to circular references.

Throws:
java.sql.SQLException
java.io.IOException

fillFromDB

public int fillFromDB()
               throws java.sql.SQLException
Construct the instruction set from the database. Don't use this if the instructions are intended to be written back to the database. (i.e. Use for queries only.)

Returns:
The number of Bytecode instructions for the cuid.
Throws:
java.sql.SQLException

fillFromDBWithData

public int fillFromDBWithData()
                       throws java.sql.SQLException,
                              java.io.IOException
Construct the instruction set from the database with data. Use this if the instructions are intended to be written back to the database.

Returns:
The number of Bytecode instructions for the cuid.
Throws:
java.sql.SQLException
java.io.IOException

finalizeAndStoreCheckedRecords

public void finalizeAndStoreCheckedRecords()
                                    throws java.sql.SQLException,
                                           java.io.IOException
This is called from Checkvals.

Throws:
java.sql.SQLException
java.io.IOException

finalizeAndStoreNewBuild

public void finalizeAndStoreNewBuild(int[] fileIDIndex)
                              throws java.sql.SQLException,
                                     java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

get

public Bytecode get(int address)
             throws java.sql.SQLException
Throws:
java.sql.SQLException

getProcedureInstrFor

public ProcedureInstr getProcedureInstrFor(int address)
                                    throws java.sql.SQLException
For an input instruction address, get the ProcedureInstr for the procedure it belongs to. It's important to note that if the address is in a trigger block, then the trigger's containing procedure will be returned. (i.e. One step beyond what Layout.procedureInstrAddrFor(address) does.)

Throws:
java.sql.SQLException

getThisProcedureExprInstr

public Bytecode getThisProcedureExprInstr()
For THIS-PROCEDURE as an r-value, just need an instruction which returns this CUID. (Remember that the CUID is the string ID for the compile unit's source file name.) This returns the appropriate instruction for that, creating it if necessary.


isProcNameExpression

public boolean isProcNameExpression()
Used by BuiltinfuncInstr. If the current expression is used as part of a procedure name, then it is safe for the func/operator to be recalculated. There is no concern of feedback loops.


getCopy

public java.util.TreeMap<java.lang.Integer,Bytecode> getCopy()

getSortedList

public java.util.ArrayList<Bytecode> getSortedList()

lookupSupersLocally

public java.util.HashSet<int[]> lookupSupersLocally(int procnameID)
                                             throws java.sql.SQLException,
                                                    java.io.IOException
Lookup a set of local supers {cuid, procaddress} for a procedure name.

Returns:
An empty set if none found. (Does not return null.)
Throws:
java.sql.SQLException
java.io.IOException

lookupLocalProcedureAddress

public int lookupLocalProcedureAddress(int nameID)
                                throws java.sql.SQLException,
                                       java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException
See Also:
CompileunitInstr.lookupActiveProcedureAddress(int)

move

public void move(Bytecode bc,
                 int newAddress)
          throws java.sql.SQLException
Throws:
java.sql.SQLException

put

public void put(Bytecode bc)

nextSequentialHeaderInstructionAddress

public int nextSequentialHeaderInstructionAddress()

rebuildSuperProceduresLookupTable

public void rebuildSuperProceduresLookupTable()
                                       throws java.sql.SQLException,
                                              java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

recalc

public void recalc()
            throws java.io.IOException,
                   java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

remove

public Bytecode remove(int address)
                throws java.sql.SQLException
Throws:
java.sql.SQLException

setProcNameExpression

public void setProcNameExpression(boolean on)
Set by the code generator. Increment a flag indicating that the current instructions are part of an expression which is a procedure name in a RUN or DYNAMIC-FUNCTION. These could be nested (stacked), like: DYNAMIC-FUNCTION(DYNAMIC-FUNCTION(expression ...) ...) so we have to keep a counter, rather than a simple boolean flag.


scriptValsInstr

public ScriptValsInstr scriptValsInstr(java.util.Collection<java.lang.String> strings)
                                throws java.sql.SQLException
Add a ScriptValsInstr to the header, returns the new instruction record. Not used within Callgraph - is only for use by end user scripts. The input string Collection may be null or empty.

Throws:
java.sql.SQLException
See Also:
ScriptValsInstr.ScriptValsInstr(int, int, Collection)

stringLiteralInstruction

public Bytecode stringLiteralInstruction(java.lang.String s)
                                  throws java.sql.SQLException
Get or create a LiteralstrInstr for the input string.

Throws:
java.sql.SQLException

writeFixedHeaderInstructions

public void writeFixedHeaderInstructions()


Copyright © 2008 Joanju Software. All Rights Reserved.