Initial revision

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@19 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 27 years ago
parent c885953efd
commit 6ef8416dd6
  1. 99
      jode/jode/flow/SequentialBlock.java
  2. 156
      jode/jode/flow/VariableSet.java
  3. 38
      jode/jode/flow/jode.ppl

@ -0,0 +1,99 @@
/* SequentialBlock (c) 1998 Jochen Hoenicke
*
* You may distribute under the terms of the GNU General Public License.
*
* IN NO EVENT SHALL JOCHEN HOENICKE BE LIABLE TO ANY PARTY FOR DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
* THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JOCHEN HOENICKE
* HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* JOCHEN HOENICKE SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
* BASIS, AND JOCHEN HOENICKE HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
* SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* $Id$
*/
package jode.flow;
/**
* A sequential block combines exactly two structured blocks to a new
* one. The first sub block mustn't be another sequential block,
* instead the second sub block should be used for this. This
* condition is temporarily violated, while the t1 transformation is
* done.
*/
public class SequentialBlock {
StructuredBlock[] subBlocks;
public SequentialBlock() {
subBlocks = new StructuredBlock[2];
}
public setFirst(StructuredBlock sb) {
subBlocks[0] = sb;
sb.outer = this;
}
public setSecond(StructuredBlock sb) {
subBlocks[1] = sb;
sb.outer = this;
}
/**
* Returns the block where the control will normally flow to, when
* the given sub block is finished (<em>not</em> ignoring the jump
* after this block). (This is overwritten by SequentialBlock and
* SwitchBlock). If this isn't called with a direct sub block,
* the behaviour is undefined, so take care.
* @return null, if the control flows to another FlowBlock. */
StructuredBlock getNextBlock(StructuredBlock subBlock) {
if (subBlock == subBlocks[0])
return subBlocks[1];
return getNextBlock();
}
FlowBlock getNextFlowBlock(StructuredBlock subBlock) {
if (subBlock == subBlocks[0])
return null;
return getNextFlowBlock();
}
/**
* Replaces the given sub block with a new block.
* @param oldBlock the old sub block.
* @param newBlock the new sub block.
* @return false, if oldBlock wasn't a direct sub block.
*/
boolean replaceSubBlock(StructuredBlock oldBlock,
StructuredBlock newBlock) {
for (int i=0; i<2; i++) {
if (subBlocks[i] == oldBlock) {
subBlocks[i] = newBlock;
return true;
}
}
return false;
}
/**
* Returns all sub block of this structured block.
*/
StructuredBlock[] getSubBlocks() {
return subBlocks;
}
/**
* Determines if there is a sub block, that flows through to the end
* of this block. If this returns true, you know that jump is null.
* @return true, if the jump may be safely changed.
*/
public boolean jumpMayBeChanged() {
return (subBlocks[1].jump != null || subBlocks[1].jumpMayBeChanged());
}
}

@ -0,0 +1,156 @@
/* VariableSet (c) 1998 Jochen Hoenicke
*
* You may distribute under the terms of the GNU General Public License.
*
* IN NO EVENT SHALL JOCHEN HOENICKE BE LIABLE TO ANY PARTY FOR DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
* THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JOCHEN HOENICKE
* HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* JOCHEN HOENICKE SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
* BASIS, AND JOCHEN HOENICKE HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
* SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* $Id$
*/
package jode.Flow;
/**
* This class represents a set of Variables, which are mainly used in
* the in/out sets of StructuredBlock. The type of the Variables is
* LocalInfo. <p>
*
* It defines some Helper-Function, like intersecting, merging, union
* and difference. <p>
*
* Note that a variable set can contain LocalInfos that use the same
* slot, but are different.
*/
public class VariableSet extends java.util.Vector {
/**
* Creates a new empty variable set
*/
public VariableSet() {
}
/**
* Adds a local variable to the variable set.
* @param li The local variable of type LocalInfo.
*/
public addElement(LocalInfo li) {
super.addElement((Object)li);
}
/**
* Merges the current VariableSet with another. For all slots occuring
* in both variable sets, all corresponding LocalInfos are merged.
* The variable sets are not changed (use union for this).
* @param vs the other variable set.
*/
public void merge(VariableSet vs) {
for (int i=0; i<elementCount; i++) {
LocalInfo li1 = ((LocalInfo) elementData[i]).getLocalInfo();
for (int j=0; j<vs.elementCount; j++) {
LocalInfo li2 = ((LocalInfo) vs.elementData[j]).getLocalInfo();
if (li1.getSlot() = li2.getSlot()) {
li1.combineWith(li2);
}
}
}
}
/**
* Intersects the current VariableSet with another and returns the
* intersection. The existing VariableSet are not changed.
* @param vs the other variable set.
*/
public VariableSet intersect(VariableSet vs) {
VariableSet intersection = new VariableSet();
for (int i=0; i<elementCount; i++) {
LocalInfo li1 = ((LocalInfo) elementData[i]).getLocalInfo();
for (int j=0; j<vs.elementCount; j++) {
LocalInfo li2 = ((LocalInfo) vs.elementData[j]).getLocalInfo();
if (li1.getSlot() = li2.getSlot()) {
if (!intersection.contains(li1))
intersection.addElement(li1);
if (!intersection.contains(li2))
intersection.addElement(li2);
}
}
}
return intersection;
}
/**
* Union the other variable set to the current.
*/
public void union(VariableSet vs) {
int oldSize = elementCount;
iloop:
for (int i=0; i< vs.elementCount; i++) {
LocalInfo li2 = ((LocalInfo) vs.elementData[i]).getLocalInfo();
/* check if this particular local info was already in the set */
for (int j=0; j< oldSize; j++) {
LocalInfo li1 = ((LocalInfo) elementData[j]).getLocalInfo();
if (li1 == li2)
/* Yes it was, take next variable */
continue iloop;
}
addElement(li2);
}
}
/**
* Add the other variable set to the current, except when the slot
* is already in the current set.
*/
public void union(VariableSet vs) {
int oldSize = elementCount;
iloop:
for (int i=0; i< vs.elementCount; i++) {
LocalInfo li2 = (LocalInfo) vs.elementData[i];
/* check if this slot was already overwritten by this block */
for (int j=0; j< oldSize; j++) {
LocalInfo li1 = (LocalInfo) elementData[j];
if (li1.getSlot() == li2.getSlot())
/* Yes it was, take next variable */
continue iloop;
}
addElement(li2.getLocalInfo());
}
}
/**
* Substract the other variable set from this one. This removes
* every variable from this set, that uses a slot in the other
* variable set.
* @param vs The other variable set.
*/
public void subtract(VariableSet vs) {
/* We count from top to bottom to have easier reorganization.
* Note, that the variables have not to be in any particular
* order. */
int newCount = elementCount
for (int i=newCount-1; i>=0; i--) {
LocalInfo li1 = (LocalInfo) elementData[i];
for (int j=0; j<vs.elementCount; j++) {
LocalInfo li2 = (LocalInfo) vs.elementData[j];
if (li1.getSlot() == li2.getSlot()) {
/* remove the element from this variable list. */
newCount--;
elementData[i] = elementData[newCount];
/* break the j-loop */
break;
}
}
}
/* Now set the new size */
setSize(newCount);
}
}

@ -0,0 +1,38 @@
#----- PSP time and defect log-file -----
# Project/Program:
# Author:
# Date of creation: 1998-09-16 18:01:38
#! begin=b; end=e; interrupt=i; defect=e
#! phase=ds
#! phase="design review"=dr
#! phase="code"=cd
#! phase=cr; phase=cp; phase=te; phase=pm
#! phase="test"=te
#--------------------------------------------------
1998-09-16 18:01:38 bcd
1998-09-16 18:11:37 be
1998-09-16 18:11:46 ee cd file ty EmptyBlock.java InstructionBlock.java
1998-09-16 18:44:48 ecd
1998-09-16 18:44:54 bdr
Need to rethink flowBlock union.
1998-09-16 19:49:35 edr
1998-09-17 14:14:57 bcd
1998-09-17 14:30:33 ecd
1998-09-17 14:30:38 bdr
What to do with in/out-Vectors?
1998-09-17 14:55:48 bi
auf Klo
Kaffe kochen
1998-09-17 15:01:09 ei
1998-09-17 15:33:08 edr
1998-09-17 15:33:14 bcd
1998-09-17 16:04:36 bi
zweiten Kaffe holen
1998-09-17 16:06:25 ei
1998-09-17 17:08:54 bi
auf klo
1998-09-17 17:11:45 ei
1998-09-17 17:49:35 ecd
Loading…
Cancel
Save