Example #1
0
  private void codeClassObjTable() {
    str.println("\n# Class Object Table");
    str.print(CgenSupport.CLASSOBJTAB + CgenSupport.LABEL);
    for (Object obj : nds) {
      AbstractSymbol className = ((CgenNode) obj).getName();

      // code prototype object reference
      str.print(CgenSupport.WORD);
      CgenSupport.emitProtObjRef(className, str);
      str.println();

      // code initializer reference
      str.print(CgenSupport.WORD);
      CgenSupport.emitInitRef(className, str);
      str.println();
    }
  }
Example #2
0
  private void codeObjInits() {
    str.println("\n# Object Initializers");
    for (Object obj : nds) {
      CgenNode nd = (CgenNode) obj;

      // code object initailzers (constructor method)
      CgenSupport.emitInitRef(nd.getName(), str);
      str.print(CgenSupport.LABEL);
      nd.codeObjInit(str);
    }
  }
Example #3
0
  private void codeDispTables() {
    str.println("\n# Dispatch Tables");
    for (Object obj : nds) {
      CgenNode nd = (CgenNode) obj;

      // code class method reference
      CgenSupport.emitDispTableRef(nd.getName(), str);
      str.print(CgenSupport.LABEL);
      nd.codeDispTab(str);
    }
  }
Example #4
0
  private void codeProtObjs() {
    str.println("\n# Prototype Objects");
    for (Object obj : nds) {
      CgenNode nd = (CgenNode) obj;

      // code class attributes
      str.println(CgenSupport.WORD + "-1"); // GC tag
      CgenSupport.emitProtObjRef(nd.getName(), str);
      str.print(CgenSupport.LABEL);
      nd.codeProtObj(str);
    }
  }
Example #5
0
  /** Emits code to start the .text segment and to declare the global names. */
  private void codeGlobalText() {
    str.println("\n# Global Text");

    str.println(CgenSupport.GLOBAL + CgenSupport.HEAP_START);
    str.print(CgenSupport.HEAP_START + CgenSupport.LABEL);
    str.println(CgenSupport.WORD + 0);
    str.println("\t.text");
    str.print(CgenSupport.GLOBAL);
    CgenSupport.emitInitRef(TreeConstants.Main, str);
    str.println("");
    str.print(CgenSupport.GLOBAL);
    CgenSupport.emitInitRef(TreeConstants.Int, str);
    str.println("");
    str.print(CgenSupport.GLOBAL);
    CgenSupport.emitInitRef(TreeConstants.Str, str);
    str.println("");
    str.print(CgenSupport.GLOBAL);
    CgenSupport.emitInitRef(TreeConstants.Bool, str);
    str.println("");
    str.print(CgenSupport.GLOBAL);
    CgenSupport.emitMethodRef(TreeConstants.Main, TreeConstants.main_meth, str);
    str.println("");
  }
Example #6
0
  /** Emits code to start the .data segment and to declare the global names. */
  private void codeGlobalData() {
    // The following global names must be defined first.

    // set FP offset to be below SP by 1
    fpOffset = 0;

    str.println("\n# Global Data");

    str.print("\t.data\n" + CgenSupport.ALIGN);
    str.println(CgenSupport.GLOBAL + CgenSupport.CLASSNAMETAB);
    str.print(CgenSupport.GLOBAL);
    CgenSupport.emitProtObjRef(TreeConstants.Main, str);
    str.println("");
    str.print(CgenSupport.GLOBAL);
    CgenSupport.emitProtObjRef(TreeConstants.Int, str);
    str.println("");
    str.print(CgenSupport.GLOBAL);
    CgenSupport.emitProtObjRef(TreeConstants.Str, str);
    str.println("");
    str.print(CgenSupport.GLOBAL);
    BoolConst.falsebool.codeRef(str);
    str.println("");
    str.print(CgenSupport.GLOBAL);
    BoolConst.truebool.codeRef(str);
    str.println("");
    str.println(CgenSupport.GLOBAL + CgenSupport.INTTAG);
    str.println(CgenSupport.GLOBAL + CgenSupport.BOOLTAG);
    str.println(CgenSupport.GLOBAL + CgenSupport.STRINGTAG);

    // We also need to know the tag of the Int, String, and Bool classes
    // during code generation.

    str.println(CgenSupport.INTTAG + CgenSupport.LABEL + CgenSupport.WORD + intclasstag);
    str.println(CgenSupport.BOOLTAG + CgenSupport.LABEL + CgenSupport.WORD + boolclasstag);
    str.println(CgenSupport.STRINGTAG + CgenSupport.LABEL + CgenSupport.WORD + stringclasstag);
  }