Package bytecode

Class CodeFile


  • public class CodeFile
    extends java.lang.Object
    An instance of this class is to contain a representation of the code of a complete program. Typically, per compilation, there is only one instance of that class, i.e., the typical usage is that of a singleton class.
    • Constructor Summary

      Constructors 
      Constructor Description
      CodeFile()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addProcedure​(java.lang.String name)
      Prepare for a procedure declaration and definition.
      int addStringConstant​(java.lang.String value)
      Add a string constant.
      void addStruct​(java.lang.String name)
      Prepare the definition of a named record type (struct type).
      void addVariable​(java.lang.String name)
      Prepare a global variable "declaration", i.e.
      int fieldNumber​(java.lang.String structName, java.lang.String varName)
      Look up the index of a record type.
      byte[] getBytecode()
      Returning the resulting bytecode as the overall result of the byte code generation.
      int globalVariableNumber​(java.lang.String name)
      Determine the index (an integer) of a global variable declared earlier
      int procedureNumber​(java.lang.String name)
      Look up the index of a procedure.
      void setMain​(java.lang.String name)
      Determine the "main" procedure
      int structNumber​(java.lang.String name)
      Look up the index of a record type.
      void updateProcedure​(CodeProcedure codeProcedure)
      Finalize the definition of a procedure (whose name has to be added before.
      void updateStruct​(CodeStruct codeStruct)
      Finalize the definition of a named record type (struct type), by providing the "code" object for the record type.
      void updateVariable​(java.lang.String name, bytecode.type.CodeType type)
      Declare the type for a global variable (which must have been added before), Add a global variable "declaration".
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CodeFile

        public CodeFile()
    • Method Detail

      • addVariable

        public void addVariable​(java.lang.String name)
        Prepare a global variable "declaration", i.e. initialize it in adding the name of the variable. Internally, the variable is known via its index, which is not returned by the method.
        Parameters:
        name - of the variable. The variable name must be unique.
      • updateVariable

        public void updateVariable​(java.lang.String name,
                                   bytecode.type.CodeType type)
        Declare the type for a global variable (which must have been added before), Add a global variable "declaration". Internally, the variable is managed via its index, which is not returned by the method.
        Parameters:
        name - of the variable.
        type - of the variable.
      • addProcedure

        public void addProcedure​(java.lang.String name)
        Prepare for a procedure declaration and definition. Internally, the procedure is is managed via its index, which, however, is not returned by the method.
        Parameters:
        name - of the variable.
      • updateProcedure

        public void updateProcedure​(CodeProcedure codeProcedure)
        Finalize the definition of a procedure (whose name has to be added before.
        Parameters:
        codeProcedure - : the "code" of the procedure, which includes parameters and their types.
      • addStruct

        public void addStruct​(java.lang.String name)
        Prepare the definition of a named record type (struct type). Internally, the (name of) the record type is is managed via its index, which, however, is not returned by the method.
        Parameters:
        name - of the record type
      • updateStruct

        public void updateStruct​(CodeStruct codeStruct)
        Finalize the definition of a named record type (struct type), by providing the "code" object for the record type.
        Parameters:
        codeStruct - of the record type
      • addStringConstant

        public int addStringConstant​(java.lang.String value)
        Add a string constant. Unlike some other add-methods, the index of the added string constant is returned to the caller.
        Parameters:
        value - is the string constant
        Returns:
        the index under which the the constant is stored
      • globalVariableNumber

        public int globalVariableNumber​(java.lang.String name)
        Determine the index (an integer) of a global variable declared earlier
        Parameters:
        name - of the variable
        Returns:
        the so-called index of a global variable.
      • procedureNumber

        public int procedureNumber​(java.lang.String name)
        Look up the index of a procedure.
        Parameters:
        name - of the procedure
        Returns:
        the index of the procedure.
      • structNumber

        public int structNumber​(java.lang.String name)
        Look up the index of a record type.
        Parameters:
        name - of the record type
        Returns:
        the index of the record type.
      • fieldNumber

        public int fieldNumber​(java.lang.String structName,
                               java.lang.String varName)
        Look up the index of a record type.
        Parameters:
        structName - name of the record type
        varName - name of the field
        Returns:
        the index of a field inside a record type.
      • setMain

        public void setMain​(java.lang.String name)
        Determine the "main" procedure
        Parameters:
        name - of the main procedure
      • getBytecode

        public byte[] getBytecode()
        Returning the resulting bytecode as the overall result of the byte code generation.
        Returns:
        the byte code as array of bytes.