1 /*
 2  * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 5  * This code is free software; you can redistribute it and/or modify it
 6  * under the terms of the GNU General Public License version 2 only, as
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 package org.openjdk.asmtools.jdis;
24 
25 import java.util.EnumSet;
26 
27 /**
28  * The singleton class to share global options among jdis classes.
29  */
30 public class Options {
31 
32     public static final int BODY_INDENT = 2;
33 
34     /* Options Fields */
35     private static Options ref;
36 
37      public enum PR {
38 
39         CP, // print Constant Pool
40         LNT, // print Line Number table
41         PC, // print Program Counter - for all instr
42         LABS, // print Labels (as identifiers)
43         CPX, // print CP index along with arguments
44         SRC, // print Source Line as comment
45         HEX, // print numbers as hexadecimals
46         VAR, // print local variables declarations
47         DEBUG;  // Debug flag
48     };
49 
50     static private final EnumSet<PR> JASM = EnumSet.<PR>of(PR.LABS); // default options
51     static private final EnumSet<PR> CODE = EnumSet.<PR>of(
52             PR.CP,
53             PR.LNT,
54             PR.PC,
55             PR.CPX,
56             PR.VAR
57     );
58 
59     static private EnumSet<PR> printOptions = JASM;
60     /*-------------------------------------------------------- */
61 
62     private Options() {
63     }
64 
65     public static Options OptionObject() {
66         if (ref == null) {
67             ref = new Options();
68         }
69         return ref;
70     }
71 
72     public void set(PR val) {
73         printOptions.add(val);
74     }
75 
76     public void setCodeOptions() {
77         printOptions.addAll(CODE);
78     }
79 
80     public boolean contains(PR val) {
81         return printOptions.contains(val);
82     }
83 
84     public boolean debug() {
85         return printOptions.contains(PR.DEBUG);
86     }
87 
88     @Override
89     public String toString() {
90         return printOptions.toString();
91     }
92 
93 }