Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/debugtools/DDR_Autoblob/src/com/ibm/j9ddr/autoblob/GenerateInputCFile.java
6007 views
1
/*******************************************************************************
2
* Copyright (c) 2010, 2014 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* 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-exception
21
*******************************************************************************/
22
package com.ibm.j9ddr.autoblob;
23
24
import java.io.File;
25
import java.io.FileWriter;
26
import java.io.IOException;
27
import java.io.PrintWriter;
28
29
import com.ibm.j9ddr.autoblob.config.Configuration;
30
31
/**
32
* Generates the C file containing the header includes
33
* to be pre-processed.
34
*
35
* Usage:
36
*
37
* java com.ibm.j9ddr.autoblob.GenerateInputCFile <config file> <output file>
38
*
39
* @author andhall
40
*
41
*/
42
public class GenerateInputCFile
43
{
44
45
private static final int EXPECTED_NUMBER_OF_ARGUMENTS = 2;
46
47
/**
48
* @param args
49
* @throws IOException
50
*/
51
public static void main(String[] args) throws IOException
52
{
53
printHeader();
54
55
if (args.length != EXPECTED_NUMBER_OF_ARGUMENTS) {
56
System.err.println("Unexpected number of arguments. Expected " + EXPECTED_NUMBER_OF_ARGUMENTS + ", actually got " + args.length);
57
usage();
58
System.exit(1);
59
}
60
61
File configFile = new File(args[0]);
62
63
if (! configFile.exists()) {
64
System.err.println("Specified config file: " + configFile.getAbsolutePath() + " does not exist");
65
System.exit(1);
66
}
67
68
Configuration config = Configuration.loadConfiguration(configFile, null);
69
70
File outputFile = new File(args[1]);
71
72
writeCFile(outputFile, config);
73
}
74
75
private static void writeCFile(File outputFile, Configuration config) throws IOException
76
{
77
PrintWriter writer = new PrintWriter(new FileWriter(outputFile));
78
79
try {
80
System.out.println("Writing C file: " + outputFile.getAbsolutePath());
81
writeCFile(writer, config);
82
if (writer.checkError()) {
83
System.out.println("Error during write");
84
} else {
85
System.out.println("C file written");
86
}
87
} finally {
88
writer.close();
89
}
90
91
}
92
93
private static void writeCFile(PrintWriter writer, Configuration config)
94
{
95
writer.println("/* GENERATED BY J9DDR AUTOBLOB GenerateInputCFile. DO NOT EDIT */");
96
writer.println();
97
writer.println();
98
config.writeCIncludes(writer);
99
}
100
101
private static void printHeader()
102
{
103
System.out.println("J9DDR Autoblob GenerateInputCFile");
104
}
105
106
private static void usage()
107
{
108
System.err.println();
109
System.err.println("java com.ibm.j9ddr.autoblob.GenerateInputCFile <config file> <output file>");
110
}
111
112
}
113
114