001/*
002 * Copyright (c) 2012-2017 Institut National des Sciences Appliquées de Lyon (INSA-Lyon)
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 */
009
010package org.eclipse.golo.compiler;
011
012import java.util.Arrays;
013
014/**
015 * A code generation result.
016 * <p>
017 * Compiling a single Golo source file may result in several JVM classes to be produced.
018 * A <code>CodeGenerationResult</code> represents one such output.
019 */
020public final class CodeGenerationResult {
021
022  private final byte[] bytecode;
023  private final PackageAndClass packageAndClass;
024
025  /**
026   * Constructor for a code generation result.
027   *
028   * @param bytecode        the JVM bytecode as an array.
029   * @param packageAndClass the package and class descriptor for the bytecode.
030   */
031  public CodeGenerationResult(byte[] bytecode, PackageAndClass packageAndClass) {
032    if (bytecode == null) {
033      this.bytecode = new byte[0];
034    } else {
035      this.bytecode = Arrays.copyOf(bytecode, bytecode.length);
036    }
037    this.packageAndClass = packageAndClass;
038  }
039
040  /**
041   * @return the bytecode array.
042   */
043  public byte[] getBytecode() {
044    return Arrays.copyOf(this.bytecode, this.bytecode.length);
045  }
046
047  /**
048   * @return the package and class descriptor.
049   */
050  public PackageAndClass getPackageAndClass() {
051    return packageAndClass;
052  }
053}