asm.java
来自「用Java实现的编译器。把源代码编译成SPARC汇编程序」· Java 代码 · 共 156 行
JAVA
156 行
// $Id: ASM.java,v 1.4 1999/11/15 07:48:05 deberg Exp $package java6035.tools.ASM;import java.util.*;import java6035.tools.IR.Walkable;/** * ASM represents a list of assembly entries, such as instructions, labels, * comments, etc. */public class ASM implements Walkable{ Vector asm; public ASM() { asm = new Vector(); } /** * Returns an enumeration of ASM entries */ public Enumeration nodes() { return asm.elements(); } /** * Returns the size of the list. */ public int size() { return asm.size(); } /** * Removes a node at index i. */ public void removeEntryAt(int i) { asm.removeElementAt(i); } /** * Removes a node. */ public void removeEntry(ASMEntry n) { asm.removeElement(n); } /** * Returns a node at index i. */ public ASMEntry getEntryAt(int i) { return (ASMEntry) asm.elementAt(i); } /** * Replace the node at index i with a new one. */ public void setEntryAt(ASMEntry a, int i) { if (a == null) throw new ASMException("ASM: setEntryAt: node null"); asm.setElementAt(a,i); } /** * Insert given node into this block at index i. */ public void insertEntryAt(ASMEntry a, int i) { if (a == null) throw new ASMException("ASM: insertEntryAt: node null"); asm.insertElementAt(a,i); } /** * Add given node to this block. */ public void appendEntry(ASMEntry a) { if (a == null) throw new ASMException("ASM: appendEntry: node null"); asm.addElement(a); } // add comment to last instruction public void commentLast(String s) { ASMEntry e = (ASMEntry)asm.elementAt(asm.size()-1); if (e instanceof SPARCInstruction) { ((SPARCInstruction)e).setComment(s); } } /** * Add the set of nodes in the given vector. */ public void appendEntries(Vector alist) { if (alist == null) throw new ASMException("ASM: appendEntries: list null"); for (int i=0; i<alist.size(); i++) { Object o = alist.elementAt(i); if (o != null && o instanceof ASMEntry) this.appendEntry((ASMEntry)o); else throw new ASMException ("ASM: appendEntries: node null or not a ASMEntry"); } } /** * Walkable interface: get name of the node. */ public String getNodeName() { return "asm_list"; } /** * Walkable interface: return number of neighbors. */ public int getNeighborCount() { return size(); } /** * Walkable interface: return the requested neighbor: 0, label; 1 - n, * elements of the body (index 0 - n-1). */ public Object getNeighbor(int index) { return getEntryAt(index-1); } public String PPrint(int indent, boolean recursive) { return ""; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?