1f8f4a0b31
* Makefile.in (ggc-callbacks.o): Remove target. (flow.o): Depend on GGC_H. * alias.c (init_alias_analysis): Remove ggc_p conditionals. (end_alias_analysis): Likewise. * basic-block.h (init_flow): New function. (allocate_reg_life_data): Declare. * bb-reorder.c (function_obstack): Replace with ... (flow_obstack): ... new variable. (fixup_reorder_chain): Use it. * c-decl.c (ggc_p): Remove. (caller-save.c): Don't call oballoc/obfree. * combine.c (struct undobuf): Remove storage. (try_combine): Don't call oballoc. (undo_all): Don't call obfree. * cse.c (insert): Use xmalloc, not oballoc. (cse_main): Adjust accordingly. * dwarf2out.c (save_rtx): Remove obstack code. (dwarf2out_init): Remove ggc_p conditionals. * emit-rtl.c (rtl_obstack): Remove. (gen_rtx_CONST_INT): Remove ggc_p conditionals. (make_insn_raw): Likewise. (emit_insn_before): Likewise. (emit_insn_after): Likewise. (emit_insn): Likewise. (gen_sequence): Likewise. (copy_insn_1): Remove handling of `b' RTL components. (init_emit_once): Remove ggc_p conditionals. * except.c (create_rethrow_ref): Don't fool with obstacks. (add_partial_entry): Likewise. (call_get_eh_context): Likewise. (begin_protect_partials): Likewise. (protect_with_terminate): Likewise. * explow.c (plus_constant_wide): Likewise. * expr.c (init_expr_once): Likewise. (emit_block_move): Likewise. (clear_storage): Likewise. (expand_expr): Likewise. * flow.c (function_obstack): Remove. (flow_obstack): New variable. (flow_firstobj): Likewise. (create_base_block): Use the flow_obstack. (split_block): Likewise. (split_edge): Likewise. (calculate_global_regs_live): Likewise. (allocate_bb_life_data): Make it static. Likewiwse. (init_flow): New function. (size_int_type_wide): Remove ggc_p conditionals. * function.c (push_function_context_to): Don't call save_tree_status. (pop_function_context_from): Or restore_tree_status. (assign_stack_local_1): Don't call push_obstacks. (find_fixup_replacement): Use xmalloc. (fixup_var_refs_insns): Free the storage. (insns_for_mem_walk): Don't mess with obstacks. (instantiate_decls): Likewise. (trampoline_address): Likewise. (expand_function_end): Likewise. * function.h (sturct function): Remove obstack-related variables. (save_tree_status): Don't declare. (restore_tree_status): Likewise. * gcse.c (compute_can_copy): Don't call oballoc/obfree. * genattrtab.c (operate_exp): Remove ggc_p conditionals. (simplify_cond): Likewise. (simplify_test_exp): Don't mess with obstacks. (optimize_attrs): Likewise. * gengenrtl.c (gendef): Don't include ggc_p conditionals. * ggc-callbacks.c (ggc_p): Remove. * ggc-none.c (ggc_p): Remove. * ggc.h (ggc_p): Don't declare. * integrate.c (save_for_inline): Don't mess with obstacks. (integrate_decl_tree): Likewise. (output_inline_function): Likewise. * lists.c (init_EXPR_INSN_LIST_cache): Likewise. * loop.c (temp_obstack): Remove. (rtl_obstack): Likewise. (init_loop): Don't mess with obstacks. (reg_address_cost): Free BIVs and GIVs. (check_insns_for_bivs): Use xmalloc, not oballoc. (find_mem_givs): Likewise. (record_biv): Likewise. (general_induction_var): Likewise. (product_cheap_p): Likewse. * optabs.c (init_one_libfunc): Remove ggc_p conditional. * print-tree.c (debug_tree): Don't use oballoc/obfree. (print_node): Likewise. * profile.c (output_func_start_profiler): Remove call to temporary_allocation. * reload1.c (eliminate_regs_in_insn): Don't mess with obstacks. * resource.c (mark_target_live_regs): Use xmalloc. (free_resource_info): Free the memory. * rtl.c (rtl_obstack): Remove. (rtvec_alloc): Don't mess with obstacks. (rtx_alloc): Likewise. (rtx_free): Remove. (copy_rtx): Don't handle `b' cases. (read_rtx): Use a local rtl_obstack. * rtl.h (oballoc): Remove. (obfree): Likewise. (pop_obstacks): Likewise. (push_obstacks): Likewise. (allocate_bb_life_data): Likewise. (allocate_reg_life_data): Likewise. (rtx_free): Likewise. * sdbout.c (sdbout_queue_anonymous_type): Use tree_cons, not saveable_tree_cons. * simplify-rtx.c (cselib_init): Don't mess with obstacks. * stmt.c (mark_block_nesting): Mark the label_chain. (epxand_label): Use ggc_alloc, not oballoc. (clear_last_expr): Don't mess with obstacks. (expand_decl_cleanup): Likewise. (expand_dcc_cleanup): Likewise. (expand_dhc_cleanup): Likewise. (expand_anon_union_decl): Likewise. (add_case_node): Use xmalloc, not oballoc. (free_case_nodes): New function. (expand_end_case): Call it. * stor-layout.c (layout_type): Don't mess with obstacks. (layout_type): Likewise. * toplev.c (wrapup_global_declarations): Likewise. (compile_file): Remove ggc_p conditionals. (rest_of_compilation): Call init_flow. Remove ggc_p conditionals. (decode_f_option): Remove ggc_p conditionals. * tree.c (function_maybepermanent_obstack): Remove. (maybepermanent_obstack): Likewise. (function_obstack): Likewise. (tmeporary_obstack): Likewise. (momentary_obstack): Likewise. (temp_decl_obstack): Likewise. (saveable_obstack): Likewise. (rtl_obstack): Likewise. (current_obstack): Likewise. (expression_obstack): Likewise. (struct obstack_stack): Likewise. (obstack_stack): Likewise. (obstack_stack_obstack): Likewise. (maybepermanent_firstobj): Likewise. (temporary_firstobj): Likewise. (momentary_firstobj): Likewise. (temp_decl_firstobj): Likewise. (momentary_function_firstobj): Likewise. (all_types_permanent): Likewise. (struct momentary_level): Likewise. (momentary_stack): Likewise. (init_obstacks): Remove initialization of removed obstacks. (save_tree_status): Remove. (restore_tree_status): Likewise. (temporary_allocation): Liekwise. (end_temporary_allocation): Liekwise. (resume_temporary_allocation): Likewise. (saveable_allocation): Likewise. (push_obstacks): Likewise. (push_obstacks_nochange): Likewise. (pop_obstacks): Likewise. (allocation_temporary_p): Likewise. (permanent_allocation): Likewise. (preserve_data): Likewise. (preserve_initializer): Likewise. (rtl_in_current_obstack): Likewise. (rtl_in_saveable_obstack): Likewise. (oballoc): Likewise. (obfree): Likewise. (savealloc): Likewise. (expralloc): Likewise. (print_obstack_name): Likewise. (debug_obstack): Likewise. (object_permanent_p): Likewise. (push_momentary): Likewise. (perserve_momentary): Likewise. (clear_momentary): Likewise. (pop_momentary): Likewise. (pop_momentary_nofree): Likewise. (suspend_momentary): Likewise. (resume_momentary): Likewise. (make_node): Don't set TREE_PERMANENT. (copy_node): Remove ggc_p conditionals. Don't set TYPE_OBSTACK. Don't set TREE_PERMANENT. (get_identifier): Remove ggc_p conditionals. (build_string): Likewise. (make_tree_vec): Likewise. (build_decl_list): Remove. (build_expr_list): Likewise. (tree_cons): Remove ggc_p conditionals. (decl_tree_cons): Remove. (expr_tree_cons): Likewise. (perm_tree_cons): Likewise. (temp_tree_cons): Likewise. (saveable_tree_cons): Likewise. (build1): Remove ggc_p conditionals. (build_parse_node): Likewise. (build_type_attribute_variant): Don't mess with obstacks. (build_type_copy): Likewise. (type_hash_canon): Likewise. (build_pointer_type): Likewise. (build_reference_type): Likewise. (build_index_type): Likewise. (build_range_type): Likewise. (dump_tree_statistics): Don't print obstack information. * tree.h (struct tree_common): Remove permanent_flag. (TREE_PERMANENT): Remove. (TREE_SET_PERMANENT): Likewise. (TYPE_OBSTACK): Likewise. (struct tree_type): Remove obstack. (oballoc): Remove. (savealloc): Likewise. (build_decl_list): Likewise. (build_expr_list): Likewise. (perm_tree_cons): Likewise. (temp_tree_cons): Likewise. (saveable_tree_cons): Likewise. (decl_tree_cons): Likewise. (expr_tree_cons): Likewise. (suspend_momentary): Likewise. (allocation_temporary_p): Likewise. (resume_momentary): Likewise. (push_obstacks_nochange): Likewise. (permanent_allocation): Likewise. (push_momentary): Likewise. (clear_momentary): Likewise. (pop_momentary): Likewise. (end_temporary_allocation): Likewise. (pop_obstacks): Likewise. (push_obstacks): Likewise. (pop_momentary_nofree): LIkewise. (preserve_momentary): Likewise. (saveable_allocation): Likewise. (temporary_allocation): Likewise. (resume_temporary_allocation): Likewise. (perserve_initializer): Likewise. (debug_obstack): Likewise. (rtl_in_current_obstack): Likewise. (rtl_in_saveable_obstack): Likewise. (obfree): Likewise. * varasm.c (current_obstack): Remove. (saveable_obstack): Remove. (rtl_obstack): Remove. (immed_double_const): Don't mess with obstacks. (immed_real_cons): Likewise. (output_constant_def): Likewise. (init_varasm_status): Use xcalloc. (mark_pool_constant): Mark the pool constant itself. (free_varasm_status): Free memory. (decode_rtx_const): Call bzero directly, rather than expanding it inline. (record_rtx_const): Don't mess with obstacks. (force_const_mem): Likewise. * config/arm/arm.c (arm_encode_call_attribute): Remove ggc_p conditionals. (aof_pic_entry): Likewise. * config/ia64/ia64.c (ia64_encode_section_info): Likewise. * config/m32r/m32r.c (m32r_encode_section_info): Likewise. * config/pa/pa.c (saveable_obstack): Remove. (rtl_obstack): Likewise. (current_obstack): Likewise. (output_call): Don't mess with obstacks. (hppa_encode_label): Remove ggc_p conditionals. * config/romp/romp.c (get_symref): Don't mess with obstacks. * config/rs6000/rs6000.c (output_toc): Remove ggc_p conditional. (rs6000_encode_section_info): Likewise. * config/sh/sh.c (get_fpscr_rtx): Likewise. From-SVN: r36856
488 lines
13 KiB
C
488 lines
13 KiB
C
/* Handle the constant pool of the Java(TM) Virtual Machine.
|
|
Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
|
|
|
|
This file is part of GNU CC.
|
|
|
|
GNU CC is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
any later version.
|
|
|
|
GNU CC is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
You should have received a copy of the GNU General Public License
|
|
along with GNU CC; see the file COPYING. If not, write to
|
|
the Free Software Foundation, 59 Temple Place - Suite 330,
|
|
Boston, MA 02111-1307, USA.
|
|
|
|
Java and all Java-based marks are trademarks or registered trademarks
|
|
of Sun Microsystems, Inc. in the United States and other countries.
|
|
The Free Software Foundation is independent of Sun Microsystems, Inc. */
|
|
|
|
#include "config.h"
|
|
#include "system.h"
|
|
#include "jcf.h"
|
|
#include "tree.h"
|
|
#include "java-tree.h"
|
|
#include "toplev.h"
|
|
#include "ggc.h"
|
|
|
|
extern struct obstack permanent_obstack;
|
|
|
|
static void set_constant_entry PARAMS ((CPool *, int, int, jword));
|
|
static int find_class_or_string_constant PARAMS ((CPool *, int, tree));
|
|
static int find_name_and_type_constant PARAMS ((CPool *, tree, tree));
|
|
static tree get_tag_node PARAMS ((int));
|
|
static tree build_constant_data_ref PARAMS ((void));
|
|
|
|
/* Set the INDEX'th constant in CPOOL to have the given TAG and VALUE. */
|
|
|
|
static void
|
|
set_constant_entry (cpool, index, tag, value)
|
|
CPool *cpool;
|
|
int index;
|
|
int tag;
|
|
jword value;
|
|
{
|
|
if (cpool->data == NULL)
|
|
{
|
|
cpool->capacity = 100;
|
|
cpool->tags = (uint8*) xmalloc (sizeof(uint8) * cpool->capacity);
|
|
cpool->data = (jword*) xmalloc (sizeof(jword) * cpool->capacity);
|
|
cpool->count = 1;
|
|
}
|
|
if (index >= cpool->capacity)
|
|
{
|
|
cpool->capacity *= 2;
|
|
if (index >= cpool->capacity)
|
|
cpool->capacity = index + 10;
|
|
cpool->tags = (uint8*) xrealloc (cpool->tags,
|
|
sizeof(uint8) * cpool->capacity);
|
|
cpool->data = (jword*) xrealloc (cpool->data,
|
|
sizeof(jword) * cpool->capacity);
|
|
}
|
|
if (index >= cpool->count)
|
|
cpool->count = index + 1;
|
|
cpool->tags[index] = tag;
|
|
cpool->data[index] = value;
|
|
}
|
|
|
|
/* Find (or create) a constant pool entry matching TAG and VALUE. */
|
|
|
|
int
|
|
find_constant1 (cpool, tag, value)
|
|
CPool *cpool;
|
|
int tag;
|
|
jword value;
|
|
{
|
|
int i;
|
|
for (i = cpool->count; --i > 0; )
|
|
{
|
|
if (cpool->tags[i] == tag && cpool->data[i] == value)
|
|
return i;
|
|
}
|
|
i = cpool->count == 0 ? 1 : cpool->count;
|
|
set_constant_entry (cpool, i, tag, value);
|
|
return i;
|
|
}
|
|
|
|
/* Find a double-word constant pool entry matching TAG and WORD1/WORD2. */
|
|
|
|
int
|
|
find_constant2 (cpool, tag, word1, word2)
|
|
CPool *cpool;
|
|
int tag;
|
|
jword word1, word2;
|
|
{
|
|
int i;
|
|
for (i = cpool->count - 1; --i > 0; )
|
|
{
|
|
if (cpool->tags[i] == tag
|
|
&& cpool->data[i] == word1
|
|
&& cpool->data[i+1] == word2)
|
|
return i;
|
|
}
|
|
i = cpool->count == 0 ? 1 : cpool->count;
|
|
set_constant_entry (cpool, i, tag, word1);
|
|
set_constant_entry (cpool, i+1, 0, word2);
|
|
return i;
|
|
}
|
|
|
|
int
|
|
find_utf8_constant (cpool, name)
|
|
CPool *cpool;
|
|
tree name;
|
|
{
|
|
if (name == NULL_TREE)
|
|
return 0;
|
|
return find_constant1 (cpool, CONSTANT_Utf8, (jword) name);
|
|
}
|
|
|
|
static int
|
|
find_class_or_string_constant (cpool, tag, name)
|
|
CPool *cpool;
|
|
int tag;
|
|
tree name;
|
|
{
|
|
int j = find_utf8_constant (cpool, name);
|
|
int i;
|
|
for (i = cpool->count; --i > 0; )
|
|
{
|
|
if (cpool->tags[i] == tag && cpool->data[i] == (jword) j)
|
|
return i;
|
|
}
|
|
i = cpool->count;
|
|
set_constant_entry (cpool, i, tag, (jword) j);
|
|
return i;
|
|
}
|
|
|
|
int
|
|
find_class_constant (cpool, type)
|
|
CPool *cpool;
|
|
tree type;
|
|
{
|
|
return find_class_or_string_constant (cpool, CONSTANT_Class,
|
|
build_internal_class_name (type));
|
|
}
|
|
|
|
/* Allocate a CONSTANT_string entry given a STRING_CST. */
|
|
|
|
int
|
|
find_string_constant (cpool, string)
|
|
CPool *cpool;
|
|
tree string;
|
|
{
|
|
string = get_identifier (TREE_STRING_POINTER (string));
|
|
return find_class_or_string_constant (cpool, CONSTANT_String, string);
|
|
|
|
}
|
|
|
|
/* Find (or create) a CONSTANT_NameAndType matching NAME and TYPE.
|
|
Return its index in the constant pool CPOOL. */
|
|
|
|
static int
|
|
find_name_and_type_constant (cpool, name, type)
|
|
CPool *cpool;
|
|
tree name;
|
|
tree type;
|
|
{
|
|
int name_index = find_utf8_constant (cpool, name);
|
|
int type_index = find_utf8_constant (cpool, build_java_signature (type));
|
|
return find_constant1 (cpool, CONSTANT_NameAndType,
|
|
(name_index << 16) | type_index);
|
|
}
|
|
|
|
/* Find (or create) a CONSTANT_Fieldref for DECL (a FIELD_DECL or VAR_DECL).
|
|
Return its index in the constant pool CPOOL. */
|
|
|
|
int
|
|
find_fieldref_index (cpool, decl)
|
|
CPool *cpool;
|
|
tree decl;
|
|
{
|
|
int class_index = find_class_constant (cpool, DECL_CONTEXT (decl));
|
|
int name_type_index
|
|
= find_name_and_type_constant (cpool, DECL_NAME (decl), TREE_TYPE (decl));
|
|
return find_constant1 (cpool, CONSTANT_Fieldref,
|
|
(class_index << 16) | name_type_index);
|
|
}
|
|
|
|
/* Find (or create) a CONSTANT_Methodref for DECL (a FUNCTION_DECL).
|
|
Return its index in the constant pool CPOOL. */
|
|
|
|
int
|
|
find_methodref_index (cpool, decl)
|
|
CPool *cpool;
|
|
tree decl;
|
|
{
|
|
tree mclass = DECL_CONTEXT (decl);
|
|
int class_index = find_class_constant (cpool, mclass);
|
|
tree name = DECL_CONSTRUCTOR_P (decl) ? init_identifier_node
|
|
: DECL_NAME (decl);
|
|
int name_type_index;
|
|
if (TREE_CODE (name) == EXPR_WITH_FILE_LOCATION)
|
|
name = EXPR_WFL_NODE (name);
|
|
name_type_index =
|
|
find_name_and_type_constant (cpool, name, TREE_TYPE (decl));
|
|
return find_constant1 (cpool,
|
|
CLASS_INTERFACE (TYPE_NAME (mclass))
|
|
? CONSTANT_InterfaceMethodref
|
|
: CONSTANT_Methodref,
|
|
(class_index << 16) | name_type_index);
|
|
}
|
|
|
|
#define PUT1(X) (*ptr++ = (X))
|
|
#define PUT2(X) (PUT1((X) >> 8), PUT1(X))
|
|
#define PUT4(X) (PUT2((X) >> 16), PUT2(X))
|
|
#define PUTN(P, N) (bcopy(P, ptr, N), ptr += (N))
|
|
|
|
/* Give the number of bytes needed in a .class file for the CPOOL
|
|
constant pool. Includes the 2-byte constant_pool_count. */
|
|
|
|
int
|
|
count_constant_pool_bytes (cpool)
|
|
CPool *cpool;
|
|
{
|
|
int size = 2;
|
|
int i = 1;
|
|
for ( ; i < cpool->count; i++)
|
|
{
|
|
size++;
|
|
switch (cpool->tags[i])
|
|
{
|
|
case CONSTANT_NameAndType:
|
|
case CONSTANT_Fieldref:
|
|
case CONSTANT_Methodref:
|
|
case CONSTANT_InterfaceMethodref:
|
|
case CONSTANT_Float:
|
|
case CONSTANT_Integer:
|
|
size += 4;
|
|
break;
|
|
case CONSTANT_Class:
|
|
case CONSTANT_String:
|
|
size += 2;
|
|
break;
|
|
case CONSTANT_Long:
|
|
case CONSTANT_Double:
|
|
size += 8;
|
|
i++;
|
|
break;
|
|
case CONSTANT_Utf8:
|
|
{
|
|
tree t = (tree) cpool->data[i];
|
|
int len = IDENTIFIER_LENGTH (t);
|
|
size += len + 2;
|
|
}
|
|
break;
|
|
default:
|
|
/* Second word of CONSTANT_Long and CONSTANT_Double. */
|
|
size--;
|
|
}
|
|
}
|
|
return size;
|
|
}
|
|
|
|
/* Write the constant pool CPOOL into BUFFER.
|
|
The length of BUFFER is LENGTH, which must match the needed length. */
|
|
|
|
void
|
|
write_constant_pool (cpool, buffer, length)
|
|
CPool *cpool;
|
|
unsigned char* buffer;
|
|
int length;
|
|
{
|
|
unsigned char* ptr = buffer;
|
|
int i = 1;
|
|
jword *datap = &cpool->data[1];
|
|
PUT2 (cpool->count);
|
|
for ( ; i < cpool->count; i++, datap++)
|
|
{
|
|
int tag = cpool->tags[i];
|
|
PUT1 (tag);
|
|
switch (tag)
|
|
{
|
|
case CONSTANT_NameAndType:
|
|
case CONSTANT_Fieldref:
|
|
case CONSTANT_Methodref:
|
|
case CONSTANT_InterfaceMethodref:
|
|
case CONSTANT_Float:
|
|
case CONSTANT_Integer:
|
|
PUT4 (*datap);
|
|
break;
|
|
case CONSTANT_Class:
|
|
case CONSTANT_String:
|
|
PUT2 (*datap);
|
|
break;
|
|
break;
|
|
case CONSTANT_Long:
|
|
case CONSTANT_Double:
|
|
PUT4(*datap);
|
|
i++;
|
|
datap++;
|
|
PUT4 (*datap);
|
|
break;
|
|
case CONSTANT_Utf8:
|
|
{
|
|
tree t = (tree) *datap;
|
|
int len = IDENTIFIER_LENGTH (t);
|
|
PUT2 (len);
|
|
PUTN (IDENTIFIER_POINTER (t), len);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if (ptr != buffer + length)
|
|
fatal("internal error - incorrect constant pool");
|
|
}
|
|
|
|
CPool *outgoing_cpool;
|
|
|
|
static tree
|
|
get_tag_node (tag)
|
|
int tag;
|
|
{
|
|
/* A Cache for build_int_2 (CONSTANT_XXX, 0). */
|
|
static tree tag_nodes[13];
|
|
static int initialized_p;
|
|
|
|
/* Register the TAG_NODES with the garbage collector. */
|
|
if (!initialized_p)
|
|
{
|
|
ggc_add_tree_root (tag_nodes, 13);
|
|
initialized_p = 1;
|
|
}
|
|
|
|
if (tag_nodes[tag] == NULL_TREE)
|
|
tag_nodes[tag] = build_int_2 (tag, 0);
|
|
return tag_nodes[tag];
|
|
}
|
|
|
|
/* Look for a constant pool entry that matches TAG and NAME.
|
|
Creates a new entry if not found.
|
|
TAG is one of CONSTANT_Utf8, CONSTANT_String or CONSTANT_Class.
|
|
NAME is an IDENTIFIER_NODE naming the Utf8 constant, string, or class.
|
|
Returns the index of the entry. */
|
|
|
|
int
|
|
alloc_name_constant (tag, name)
|
|
int tag;
|
|
tree name;
|
|
{
|
|
return find_constant1 (outgoing_cpool, tag, (jword) name);
|
|
}
|
|
|
|
/* Build an identifier for the internal name of reference type TYPE. */
|
|
|
|
tree
|
|
build_internal_class_name (type)
|
|
tree type;
|
|
{
|
|
tree name;
|
|
if (TYPE_ARRAY_P (type))
|
|
name = build_java_signature (type);
|
|
else
|
|
{
|
|
name = TYPE_NAME (type);
|
|
if (TREE_CODE (name) != IDENTIFIER_NODE)
|
|
name = DECL_NAME (name);
|
|
name = identifier_subst (name, "", '.', '/', "");
|
|
}
|
|
return name;
|
|
}
|
|
|
|
/* Look for a CONSTANT_Class entry for CLAS, creating a new one if needed. */
|
|
|
|
int
|
|
alloc_class_constant (clas)
|
|
tree clas;
|
|
{
|
|
tree class_name = build_internal_class_name (clas);
|
|
|
|
return alloc_name_constant (CONSTANT_Class,
|
|
(unmangle_classname
|
|
(IDENTIFIER_POINTER(class_name),
|
|
IDENTIFIER_LENGTH(class_name))));
|
|
}
|
|
|
|
/* Return a reference to the data array of the current constant pool. */
|
|
|
|
static tree
|
|
build_constant_data_ref ()
|
|
{
|
|
if (TYPE_CPOOL_DATA_REF (current_class))
|
|
current_constant_pool_data_ref = TYPE_CPOOL_DATA_REF (current_class);
|
|
|
|
else if (current_constant_pool_data_ref == NULL_TREE)
|
|
{
|
|
tree decl;
|
|
tree decl_name = mangled_classname ("_CD_", current_class);
|
|
decl = build_decl (VAR_DECL, decl_name,
|
|
build_array_type (ptr_type_node,
|
|
one_elt_array_domain_type));
|
|
TREE_STATIC (decl) = 1;
|
|
make_decl_rtl (decl, NULL, 1);
|
|
TYPE_CPOOL_DATA_REF (current_class) = current_constant_pool_data_ref
|
|
= build1 (ADDR_EXPR, ptr_type_node, decl);
|
|
}
|
|
return current_constant_pool_data_ref;
|
|
}
|
|
|
|
/* Get the pointer value at the INDEX'th element of the constant pool. */
|
|
|
|
tree
|
|
build_ref_from_constant_pool (index)
|
|
int index;
|
|
{
|
|
tree t = build_constant_data_ref ();
|
|
index *= int_size_in_bytes (ptr_type_node);
|
|
t = fold (build (PLUS_EXPR, ptr_type_node,
|
|
t, build_int_2 (index, 0)));
|
|
return build1 (INDIRECT_REF, ptr_type_node, t);
|
|
}
|
|
|
|
/* Build an initializer for the constants field of the current constal pool.
|
|
Should only be called at top-level, since it may emit declarations. */
|
|
|
|
tree
|
|
build_constants_constructor ()
|
|
{
|
|
tree tags_value, data_value;
|
|
tree cons;
|
|
tree tags_list = NULL_TREE;
|
|
tree data_list = NULL_TREE;
|
|
int i;
|
|
for (i = outgoing_cpool->count; --i > 0; )
|
|
{
|
|
tags_list
|
|
= tree_cons (NULL_TREE, get_tag_node (outgoing_cpool->tags[i]),
|
|
tags_list);
|
|
data_list
|
|
= tree_cons (NULL_TREE, build_utf8_ref ((tree)outgoing_cpool->data[i]),
|
|
data_list);
|
|
}
|
|
if (outgoing_cpool->count > 0)
|
|
{
|
|
tree index_type;
|
|
tree data_decl, tags_decl, tags_type;
|
|
tree max_index = build_int_2 (outgoing_cpool->count - 1, 0);
|
|
TREE_TYPE (max_index) = sizetype;
|
|
index_type = build_index_type (max_index);
|
|
|
|
/* Add dummy 0'th element of constant pool. */
|
|
tags_list = tree_cons (NULL_TREE, get_tag_node (0), tags_list);
|
|
data_list = tree_cons (NULL_TREE, null_pointer_node, data_list);
|
|
|
|
data_decl = TREE_OPERAND (build_constant_data_ref (), 0);
|
|
TREE_TYPE (data_decl) = build_array_type (ptr_type_node, index_type),
|
|
DECL_INITIAL (data_decl) = build (CONSTRUCTOR, TREE_TYPE (data_decl),
|
|
NULL_TREE, data_list);
|
|
DECL_SIZE (data_decl) = TYPE_SIZE (TREE_TYPE (data_decl));
|
|
DECL_SIZE_UNIT (data_decl) = TYPE_SIZE_UNIT (TREE_TYPE (data_decl));
|
|
rest_of_decl_compilation (data_decl, (char *) 0, 1, 0);
|
|
data_value = build_address_of (data_decl);
|
|
|
|
tags_type = build_array_type (unsigned_byte_type_node, index_type);
|
|
tags_decl = build_decl (VAR_DECL, mangled_classname ("_CT_",
|
|
current_class),
|
|
tags_type);
|
|
TREE_STATIC (tags_decl) = 1;
|
|
DECL_INITIAL (tags_decl) = build (CONSTRUCTOR, tags_type,
|
|
NULL_TREE, tags_list);
|
|
rest_of_decl_compilation (tags_decl, (char*) 0, 1, 0);
|
|
tags_value = build_address_of (tags_decl);
|
|
}
|
|
else
|
|
{
|
|
data_value = null_pointer_node;
|
|
tags_value = null_pointer_node;
|
|
}
|
|
START_RECORD_CONSTRUCTOR (cons, constants_type_node);
|
|
PUSH_FIELD_VALUE (cons, "size", build_int_2 (outgoing_cpool->count, 0));
|
|
PUSH_FIELD_VALUE (cons, "tags", tags_value);
|
|
PUSH_FIELD_VALUE (cons, "data", data_value);
|
|
FINISH_RECORD_CONSTRUCTOR (cons);
|
|
return cons;
|
|
}
|