001: /*=============================================================================
002: * Copyright Texas Instruments 2000. All Rights Reserved.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * $ProjectHeader: OSCRIPT 0.155 Fri, 20 Dec 2002 18:34:22 -0800 rclark $
019: */
020:
021: package oscript.compiler;
022:
023: import java.util.*;
024:
025: // The Bytecode Engineerign Library
026: import org.apache.bcel.generic.*;
027:
028: /**
029: * These is a rather cheezy implementation... be careful because this
030: * doesn't overload all the apend methods. It is, at least, a way to
031: * break some extra crap out of the visitor.
032: *
033: * @author Rob Clark (rob@ti.com)
034: * <!--$Format: " * @version $Revision$"$-->
035: * @version 1.5
036: */
037: public class CompilerInstructionList extends InstructionList {
038: private InstructionHandle lastHandle;
039: private LinkedList biList;
040:
041: private InstructionHandle lastTarget = null;
042:
043: /*=======================================================================*/
044: /**
045: *
046: *
047: */
048: public CompilerInstructionList() {
049: super ();
050: }
051:
052: public InstructionHandle append(Instruction i) {
053: lastHandle = super .append(i);
054:
055: if (biList != null) {
056: for (Iterator itr = biList.iterator(); itr.hasNext();) {
057: ((BranchInstruction) (itr.next()))
058: .setTarget(lastHandle);
059: lastTarget = lastHandle;
060: biList = null;
061: }
062: }
063:
064: return lastHandle;
065: }
066:
067: public InstructionHandle append(CompoundInstruction i) {
068: lastHandle = super .append(i);
069:
070: if (biList != null) {
071: for (Iterator itr = biList.iterator(); itr.hasNext();) {
072: ((BranchInstruction) (itr.next()))
073: .setTarget(lastHandle);
074: lastTarget = lastHandle;
075: biList = null;
076: }
077: }
078:
079: return lastHandle;
080: }
081:
082: public BranchHandle append(BranchInstruction i) {
083: lastHandle = super .append(i);
084:
085: if (biList != null) {
086: for (Iterator itr = biList.iterator(); itr.hasNext();) {
087: ((BranchInstruction) (itr.next()))
088: .setTarget(lastHandle);
089: lastTarget = lastHandle;
090: biList = null;
091: }
092: }
093:
094: return (BranchHandle) lastHandle;
095: }
096:
097: public InstructionHandle getLastInstructionHandle() {
098: return lastHandle;
099: }
100:
101: public void setNextAsTarget(BranchInstruction bi) {
102: if (biList == null) {
103: biList = new LinkedList();
104: }
105:
106: biList.add(bi);
107: }
108:
109: public InstructionHandle getLastBranchTarget() {
110: return lastTarget;
111: }
112: }
113:
114: /*
115: * Local Variables:
116: * tab-width: 2
117: * indent-tabs-mode: nil
118: * mode: java
119: * c-indentation-style: java
120: * c-basic-offset: 2
121: * eval: (c-set-offset 'substatement-open '0)
122: * eval: (c-set-offset 'case-label '+)
123: * eval: (c-set-offset 'inclass '+)
124: * eval: (c-set-offset 'inline-open '0)
125: * End:
126: */
|