Path: blob/master/debugtools/DDR_Autoblob/src/com/ibm/j9ddr/autoblob/GenerateInputCFile.java
6007 views
/*******************************************************************************1* Copyright (c) 2010, 2014 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/21package com.ibm.j9ddr.autoblob;2223import java.io.File;24import java.io.FileWriter;25import java.io.IOException;26import java.io.PrintWriter;2728import com.ibm.j9ddr.autoblob.config.Configuration;2930/**31* Generates the C file containing the header includes32* to be pre-processed.33*34* Usage:35*36* java com.ibm.j9ddr.autoblob.GenerateInputCFile <config file> <output file>37*38* @author andhall39*40*/41public class GenerateInputCFile42{4344private static final int EXPECTED_NUMBER_OF_ARGUMENTS = 2;4546/**47* @param args48* @throws IOException49*/50public static void main(String[] args) throws IOException51{52printHeader();5354if (args.length != EXPECTED_NUMBER_OF_ARGUMENTS) {55System.err.println("Unexpected number of arguments. Expected " + EXPECTED_NUMBER_OF_ARGUMENTS + ", actually got " + args.length);56usage();57System.exit(1);58}5960File configFile = new File(args[0]);6162if (! configFile.exists()) {63System.err.println("Specified config file: " + configFile.getAbsolutePath() + " does not exist");64System.exit(1);65}6667Configuration config = Configuration.loadConfiguration(configFile, null);6869File outputFile = new File(args[1]);7071writeCFile(outputFile, config);72}7374private static void writeCFile(File outputFile, Configuration config) throws IOException75{76PrintWriter writer = new PrintWriter(new FileWriter(outputFile));7778try {79System.out.println("Writing C file: " + outputFile.getAbsolutePath());80writeCFile(writer, config);81if (writer.checkError()) {82System.out.println("Error during write");83} else {84System.out.println("C file written");85}86} finally {87writer.close();88}8990}9192private static void writeCFile(PrintWriter writer, Configuration config)93{94writer.println("/* GENERATED BY J9DDR AUTOBLOB GenerateInputCFile. DO NOT EDIT */");95writer.println();96writer.println();97config.writeCIncludes(writer);98}99100private static void printHeader()101{102System.out.println("J9DDR Autoblob GenerateInputCFile");103}104105private static void usage()106{107System.err.println();108System.err.println("java com.ibm.j9ddr.autoblob.GenerateInputCFile <config file> <output file>");109}110111}112113114