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