示例#1
0
  public void compile(Clazz clazz) throws IOException {
    reset();

    File llFile = config.getLlFile(clazz);
    File bcFile = config.getBcFile(clazz);
    File sFile = config.getSFile(clazz);
    File oFile = config.getOFile(clazz);
    llFile.getParentFile().mkdirs();
    bcFile.getParentFile().mkdirs();
    sFile.getParentFile().mkdirs();
    oFile.getParentFile().mkdirs();

    OutputStream out = null;
    try {
      config.getLogger().debug("Compiling %s", clazz);
      out = new FileOutputStream(llFile);
      compile(clazz, out);
    } catch (Throwable t) {
      FileUtils.deleteQuietly(llFile);
      if (t instanceof IOException) {
        throw (IOException) t;
      }
      if (t instanceof RuntimeException) {
        throw (RuntimeException) t;
      }
      throw new RuntimeException(t);
    } finally {
      IOUtils.closeQuietly(out);
    }

    config.getLogger().debug("Optimizing %s", clazz);
    CompilerUtil.opt(config, llFile, bcFile, "-mem2reg", "-always-inline");

    config.getLogger().debug("Generating %s assembly for %s", config.getArch(), clazz);
    CompilerUtil.llc(config, bcFile, sFile);

    patchAsmWithFunctionSizes(clazz, sFile);

    config.getLogger().debug("Assembling %s", clazz);
    CompilerUtil.assemble(config, sFile, oFile);
  }