1 /*
 2  *  Copyright (c) 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.  Oracle designates this
 8  *  particular file as subject to the "Classpath" exception as provided
 9  *  by Oracle in the LICENSE file that accompanied this code.
10  *
11  *  This code is distributed in the hope that it will be useful, but WITHOUT
12  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  *  version 2 for more details (a copy is included in the LICENSE file that
15  *  accompanied this code).
16  *
17  *  You should have received a copy of the GNU General Public License version
18  *  2 along with this work; if not, write to the Free Software Foundation,
19  *  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  *   Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  *  or visit www.oracle.com if you need additional information or have any
23  *  questions.
24  *
25  */
26 package jdk.internal.clang;
27 
28 import java.util.HashMap;
29 import java.util.Map;
30 import java.util.NoSuchElementException;
31 import static jdk.internal.clang.libclang.Index_h.*;
32 
33 public enum CallingConvention {
34 
35     Default(CXCallingConv_Default()),
36     C(CXCallingConv_C()),
37     X86StdCall(CXCallingConv_X86StdCall()),
38     X86FastCall(CXCallingConv_X86FastCall()),
39     X86ThisCall(CXCallingConv_X86ThisCall()),
40     X86Pascal(CXCallingConv_X86Pascal()),
41     AAPCS(CXCallingConv_AAPCS()),
42     AAPCS_VFP(CXCallingConv_AAPCS_VFP()),
43     PnaclCall(CXCallingConv_X86RegCall()),
44     IntelOclBicc(CXCallingConv_IntelOclBicc()),
45     X86_64Win64(CXCallingConv_X86_64Win64()),
46     X86_64SysV(CXCallingConv_X86_64SysV()),
47     Invalid(CXCallingConv_Invalid()),
48     Unexposed(CXCallingConv_Unexposed());
49 
50     private final int value;
51 
52     CallingConvention(int value) {
53         this.value = value;
54     }
55 
56     public int value() {
57         return value;
58     }
59 
60     private final static Map<Integer, CallingConvention> lookup;
61 
62     static {
63         lookup = new HashMap<>();
64         for (CallingConvention e: CallingConvention.values()) {
65             lookup.put(e.value(), e);
66         }
67     }
68 
69     public final static CallingConvention valueOf(int value) {
70         CallingConvention x = lookup.get(value);
71         if (null == x) {
72             throw new NoSuchElementException();
73         }
74         return x;
75     }
76 }