2015-05-05 Yvan Roux <yvan.roux@linaro.org>
[official-gcc.git] / gcc / java / verify.h
bloba5d3342453dfd324e73ee4a907295a1167b375ce
1 /* Declarations to interface gcj with bytecode verifier.
2 Copyright (C) 2003-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>.
20 Java and all Java-based marks are trademarks or registered trademarks
21 of Sun Microsystems, Inc. in the United States and other countries.
22 The Free Software Foundation is independent of Sun Microsystems, Inc. */
24 /* Written by Tom Tromey <tromey@redhat.com>. */
26 #ifndef GCC_VERIFY_H
27 #define GCC_VERIFY_H
29 #include "jcf.h"
30 #include "tree.h"
31 #include "java-tree.h"
33 typedef JCF vfy_constants;
35 /* For our purposes a string is the same as an identifier. */
36 typedef tree vfy_string;
38 /* The TYPE_DECL for a class or primitive type. */
39 typedef tree vfy_jclass;
41 /* An unsigned jshort. */
42 typedef uint16 vfy_uint_16;
44 typedef struct
46 int handler, start, end, type;
47 } vfy_exception;
49 typedef struct
51 tree method;
52 vfy_string signature;
53 vfy_string name;
54 const unsigned char *bytes;
55 vfy_exception *exceptions;
57 /* These fields are referred to directly by the verifier. */
58 vfy_jclass defining_class;
59 int max_stack;
60 int max_locals;
61 int code_length;
62 int exc_count;
63 } vfy_method;
65 /* Entry point to the verifier. */
66 int verify_jvm_instructions_new (JCF *jcf, const unsigned char *byte_ops,
67 long length);
69 void *vfy_alloc (size_t bytes);
70 void vfy_free (void *mem);
71 bool vfy_strings_equal (vfy_string one, vfy_string two);
72 const char *vfy_string_bytes (vfy_string str);
73 int vfy_string_length (vfy_string str);
74 vfy_string vfy_get_string (const char *chars, int length);
75 vfy_string vfy_init_name (void);
76 vfy_string vfy_clinit_name (void);
77 int vfy_count_arguments (vfy_string signature);
78 vfy_string vfy_get_signature (vfy_method *method);
79 vfy_string vfy_get_method_name (vfy_method *method);
80 bool vfy_is_static (vfy_method *method);
81 const unsigned char *vfy_get_bytecode (vfy_method *method);
82 vfy_exception *vfy_get_exceptions (vfy_method *method);
83 void vfy_get_exception (vfy_exception *, int index, int *handler,
84 int *start, int *end, int *handler_type);
85 int vfy_tag (vfy_constants *pool, int index);
86 void vfy_load_indexes (vfy_constants *pool, int index,
87 vfy_uint_16 *index0, vfy_uint_16 *index1);
88 vfy_constants *vfy_get_constants (vfy_jclass klass);
89 int vfy_get_constants_size (vfy_jclass klass);
90 vfy_string vfy_get_pool_string (vfy_constants *pool, int index);
91 vfy_jclass vfy_get_pool_class (vfy_constants *pool, int index);
92 vfy_string vfy_get_class_name (vfy_jclass klass);
93 bool vfy_is_assignable_from (vfy_jclass target, vfy_jclass source);
94 char vfy_get_primitive_char (vfy_jclass klass);
95 int vfy_get_interface_count (vfy_jclass klass);
96 vfy_jclass vfy_get_interface (vfy_jclass klass, int index);
97 bool vfy_is_array (vfy_jclass klass);
98 bool vfy_is_interface (vfy_jclass klass);
99 bool vfy_is_primitive (vfy_jclass klass);
100 vfy_jclass vfy_get_superclass (vfy_jclass klass);
101 vfy_jclass vfy_get_array_class (vfy_jclass klass);
102 vfy_jclass vfy_get_component_type (vfy_jclass klass);
103 bool vfy_is_abstract (vfy_jclass klass);
104 vfy_jclass vfy_find_class (vfy_jclass klass, vfy_string name);
105 vfy_jclass vfy_object_type (void);
106 vfy_jclass vfy_class_type (void);
107 vfy_jclass vfy_string_type (void);
108 vfy_jclass vfy_throwable_type (void);
109 vfy_jclass vfy_unsuitable_type (void);
110 vfy_jclass vfy_return_address_type (void);
111 vfy_jclass vfy_null_type (void);
112 int vfy_fail (const char *message, int pc, vfy_jclass ignore1,
113 vfy_method *method);
114 vfy_jclass vfy_get_primitive_type (int type);
115 void vfy_note_stack_depth (vfy_method *method, int pc, int depth);
116 void vfy_note_stack_type (vfy_method *method, int pc, int slot,
117 vfy_jclass type);
118 void vfy_note_local_type (vfy_method *method, int pc, int slot,
119 vfy_jclass type);
120 void vfy_note_instruction_seen (int pc);
121 bool vfy_class_has_field (vfy_jclass klass, vfy_string name,
122 vfy_string signature);
124 #define GLOM(name, stuff) name ## stuff
125 #define VFY_PRIMITIVE_CLASS(name) \
126 vfy_get_primitive_type ((int) (GLOM (name, _type)))
128 typedef enum
130 #define JAVAOP(name, num, ignore1, ignore2, ignore3) \
131 GLOM (op_, name) = num,
132 #include "javaop.def"
133 java_opcode_end
134 } java_opcode;
137 #define JV_CONSTANT_Class CONSTANT_Class
138 #define JV_CONSTANT_ResolvedClass CONSTANT_ResolvedClass
139 #define JV_CONSTANT_String CONSTANT_String
140 #define JV_CONSTANT_ResolvedString CONSTANT_ResolvedString
141 #define JV_CONSTANT_Integer CONSTANT_Integer
142 #define JV_CONSTANT_Float CONSTANT_Float
143 #define JV_CONSTANT_Long CONSTANT_Long
144 #define JV_CONSTANT_Double CONSTANT_Double
145 #define JV_CONSTANT_Fieldref CONSTANT_Fieldref
146 #define JV_CONSTANT_InterfaceMethodref CONSTANT_InterfaceMethodref
147 #define JV_CONSTANT_Methodref CONSTANT_Methodref
149 int verify_method (vfy_method *meth);
151 #endif /* ! GCC_VERIFY_H */