001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021package org.biojava.utils.bytecode;
022
023/**
024 * Interface for an object which can produce Java bytecode.
025 *
026 * @author Thomas Down
027 * @author Matthew Pocock
028 */
029
030public interface CodeGenerator {
031    /**
032     * Write the byte or bytes for this CodeGenerator to a CodeContext.
033     *
034     * @param ctx  a CodeContext to write to
035     * @throws CodeException if there was some failure in writing to the context
036     */
037    public void writeCode(CodeContext ctx) throws CodeException;
038    
039    /**
040     * Return the total depth of the stack required by this CodeGenerator.
041     *
042     * <p>For single byte-code instructions, this will be the same as
043     * stackDelta() if stackDelta() is positive, zero otherwise. For a
044     * compound instruction, this will be the maximum stack depth required to
045     * execute all sub-instructions.</p>
046     *
047     * @return the stack depth needed
048     */
049    public int stackDepth();
050    
051    /**
052     * Return the change in the stack dept this generator will cause.
053     *
054     * <p>In the case of an instruction that adds items to the stack, stackDelta
055     * will be positive. For instructions that removes items from the stack,
056     * this will be negative.</p>
057     *
058     * @return the change between stack depth before and after execution of this
059     *   code
060     */
061    public int stackDelta();
062}
063