예제 #1
0
 public void usageHeader(PrintStream out) {
   out.println(
       "usage: "
           + extension.compilerName()
           + " [options] "
           + "<source-file>."
           + extension.fileExtensions()[0]
           + " ...");
   out.println("where [options] includes:");
   //      usageForFlag(out, "@<file>", "read options from <file>");
 }
예제 #2
0
  public static void main(String args[]) throws IllegalArgumentException, SemanticException {
    String extension = "jl";
    String className;
    if (args.length == 3 && args[0].equals("-ext")) extension = args[1];
    if ((extension == null && args.length != 1) || (extension != null && args.length != 3)) {
      System.err.println(
          "Usage: " + "polyglot.util.typedump.Main " + "[-ext <extension>] <classname>");
      System.exit(1);
    }

    if (extension == null) className = args[0];
    else className = args[2];

    ExtensionInfo extInfo = null;

    String extClassName = "polyglot.ext." + extension + ".ExtensionInfo";
    Class<?> extClass = null;

    try {
      extClass = Class.forName(extClassName);
    } catch (ClassNotFoundException e) {
      try {
        extClass = Class.forName(extension);
      } catch (ClassNotFoundException e2) {
        System.err.println(
            "Extension " + extension + " not found: could not find class " + extClassName + ".");
        System.err.println(e2.getMessage());
        System.exit(1);
      }
    }

    try {
      extInfo = (ExtensionInfo) extClass.newInstance();
    } catch (Exception e) {
      System.err.println(
          "Extension "
              + extension
              + " could not be loaded: "
              + "could not instantiate "
              + extClassName
              + ".");
      System.exit(1);
    }

    try {
      // now try to establish the type system correctly.
      Options options = extInfo.getOptions();

      Options.global = options;

      configureOptions(options);

      StdErrorQueue eq = new StdErrorQueue(System.err, 100, extInfo.compilerName());

      new Compiler(extInfo, eq);

      TypeSystem ts = extInfo.typeSystem();
      TypeDumper t = TypeDumper.load(className, ts, extInfo.version());

      CodeWriter cw = new OptimalCodeWriter(System.out, 100);

      t.dump(cw);
      cw.newline(0);

      try {
        cw.flush();
      } catch (java.io.IOException exn) {
        System.err.println(exn.getMessage());
      }
    } catch (ClassNotFoundException exn) {
      System.err.println("Could not load .class: " + className);
      System.err.println(exn.getMessage());
    } catch (NoSuchFieldException exn) {
      System.err.println("Could not reflect jlc fields");
      System.err.println(exn.getMessage());
    } catch (SecurityException exn) {
      System.err.println("Security policy error.");
      System.err.println(exn.getMessage());
    }
  }