00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 #ifdef _KEEP_RCS_ID
00073 static char *rcs_id = "$Source: kgccfe/SCCS/s.wfe_dst.cxx $ $Revision: 1.49 $";
00074 #endif
00075
00076 #if ! defined(BUILD_OS_DARWIN)
00077 #include <values.h>
00078 #endif
00079
00080 #include "defs.h"
00081 #include "glob.h"
00082 #include "config.h"
00083 #include "dwarf_DST_producer.h"
00084 #include "dwarf_DST_dump.h"
00085 #include "file_util.h"
00086 #include "srcpos.h"
00087 #include "symtab.h"
00088 extern "C" {
00089 #include "gnu_config.h"
00090 }
00091 #ifdef KEY
00092
00093 #include "gnu/hwint.h"
00094 #endif
00095 extern "C" {
00096 #include "gnu/flags.h"
00097 #include "gnu/system.h"
00098 #include "gnu/tree.h"
00099
00100 }
00101
00102 #include "wfe_misc.h"
00103 #include "wfe_dst.h"
00104 #include "wfe_expr.h"
00105 #include "tree_symtab.h"
00106
00107 #include <sys/types.h>
00108 #include <sys/stat.h>
00109 #include <sys/param.h>
00110 #include <unistd.h>
00111 #include <string>
00112 #include <vector>
00113 #include <map>
00114 #ifdef KEY
00115 #include "stamp.h"
00116 #endif
00117 extern const char *dump_base_name ;
00118
00119 extern FILE *tree_dump_file;
00120
00121 static BOOL dst_initialized = FALSE;
00122
00123 #ifdef __MINGW32__
00124 static char cwd_buffer[MAXPATHLEN];
00125 #else
00126 #define MAX_CWD_CHARS (256 - (MAXHOSTNAMELEN+1))
00127 static char cwd_buffer[MAX_CWD_CHARS+MAXHOSTNAMELEN+1];
00128 #endif
00129 static char *current_working_dir = &cwd_buffer[0];
00130 static char *current_host_dir = &cwd_buffer[0];
00131
00132
00133
00134
00135
00136 static DST_INFO_IDX comp_unit_idx = DST_INVALID_INIT;
00137
00138 static void DST_enter_file (const char *, UINT);
00139
00140 static UINT last_dir_num = 0;
00141 static UINT current_dir = 1;
00142 static UINT last_file_num = 0;
00143 UINT current_file = 1;
00144
00145 static DST_INFO_IDX DST_Create_var(ST *var_st, tree decl);
00146 static DST_INFO_IDX DST_Create_Parmvar(ST *var_st, tree decl);
00147 static DST_INFO_IDX DST_Create_type(ST *typ_decl, tree decl);
00148 static int same_dst_idx(struct mongoose_gcc_DST_IDX s1,
00149 struct mongoose_gcc_DST_IDX s2);
00150
00151
00152
00153 static std::vector< std::pair< char *, UINT > > dir_dst_list;
00154 typedef std::map< std::string, DST_INFO_IDX > DST_Type_Map;
00155 static DST_Type_Map basetypes;
00156
00157
00158
00159
00160 #ifndef KEY
00161 static inline void
00162 #else
00163
00164 void
00165 #endif // !KEY
00166 cp_to_tree_from_dst(
00167 struct mongoose_gcc_DST_IDX * dest,
00168 DST_INFO_IDX *src)
00169 {
00170 dest->block = src->block_idx;
00171 dest->offset = src->byte_idx;
00172 }
00173
00174 #ifndef KEY
00175 static inline void
00176 #else
00177
00178 void
00179 #endif // !KEY
00180 cp_to_dst_from_tree(
00181 DST_INFO_IDX *dest,
00182 struct mongoose_gcc_DST_IDX * src)
00183 {
00184 dest->block_idx = src->block;
00185 dest->byte_idx = src->offset;
00186 }
00187
00188 #ifdef KEY
00189
00190
00191 static inline BOOL is_typedef (tree type_tree)
00192 {
00193 tree tname = TYPE_NAME (type_tree);
00194 return (tname && TREE_CODE (tname) == TYPE_DECL &&
00195 DECL_ORIGINAL_TYPE (tname));
00196 }
00197 #endif
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 static DST_INFO_IDX
00222 DST_get_context(tree intree)
00223 {
00224 tree ltree = intree;
00225 struct mongoose_gcc_DST_IDX l_tree_idx;
00226 DST_INFO_IDX l_dst_idx;
00227
00228 while (ltree) {
00229 switch(TREE_CODE(ltree)) {
00230 case BLOCK:
00231
00232
00233 DevWarn("Unhandled BLOCK scope of decl/var");
00234
00235 return comp_unit_idx;
00236 case FUNCTION_DECL:
00237
00238 l_tree_idx = DECL_DST_IDX(ltree);
00239 cp_to_dst_from_tree(&l_dst_idx,&l_tree_idx);
00240 #ifdef KEY
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 if (DST_IS_NULL(l_dst_idx))
00254 l_dst_idx.byte_idx = l_dst_idx.block_idx = 0;
00255 #endif
00256 return l_dst_idx;
00257
00258 case RECORD_TYPE:
00259 DevWarn("Unhandled RECORD_TYPE scope of decl/var/type");
00260 ltree = TYPE_CONTEXT(ltree);
00261 continue;
00262
00263 case UNION_TYPE:
00264 DevWarn("Unhandled UNION_TYPE scope of decl/var/type");
00265 ltree = TYPE_CONTEXT(ltree);
00266 continue;
00267
00268 case QUAL_UNION_TYPE:
00269 DevWarn("Unhandled QUAL_UNION_TYPE scope of decl/var/type");
00270 ltree = TYPE_CONTEXT(ltree);
00271 continue;
00272
00273 case FUNCTION_TYPE:
00274 DevWarn("Unhandled FUNCTION_TYPE scope of decl/var/type");
00275 return comp_unit_idx;
00276
00277 default:
00278 DevWarn("Unhandled scope of tree code %d",
00279 TREE_CODE(ltree));
00280
00281
00282 if(TREE_CODE_CLASS(TREE_CODE(ltree)) == 'd') {
00283 ltree = DECL_CONTEXT(ltree);
00284
00285 continue;
00286 } else if (TREE_CODE_CLASS(TREE_CODE(ltree)) == 't') {
00287 ltree = TYPE_CONTEXT(ltree);
00288
00289 continue;
00290 }
00291
00292
00293
00294 return comp_unit_idx;
00295 }
00296
00297 }
00298
00299 return comp_unit_idx;
00300 }
00301
00302
00303
00304
00305 static UINT
00306 Get_Dir_Dst_Info (char *name)
00307 {
00308 #ifdef TARG_SL
00309 if (name == NULL) return 0;
00310 #endif
00311 std::vector< std::pair < char*, UINT > >::iterator found;
00312
00313 for (found = dir_dst_list.begin();
00314 found != dir_dst_list.end();
00315 ++found)
00316 {
00317 if (strcmp ((*found).first, name) == 0) {
00318 return (*found).second;
00319 }
00320 }
00321
00322 #ifdef KEY
00323
00324
00325 char *new_name = (char *)malloc((strlen(name)+1)*sizeof(char));
00326 strcpy(new_name, name);
00327 name = new_name;
00328 #endif
00329 dir_dst_list.push_back (std::make_pair (name, ++last_dir_num));
00330 DST_mk_include_dir (name);
00331 return last_dir_num;
00332 }
00333
00334 static std::vector< std::pair< const char *, UINT > > file_dst_list;
00335
00336
00337
00338 static UINT
00339 Get_File_Dst_Info (const char *name, UINT dir)
00340 {
00341 #ifdef KEY
00342 if (name[0] == '\0')
00343 return last_file_num;
00344 #endif
00345 std::vector< std::pair < const char*, UINT > >::iterator found;
00346
00347 for (found = file_dst_list.begin();
00348 found != file_dst_list.end();
00349 ++found)
00350 {
00351 if (strcmp ((*found).first, name) == 0) {
00352 return (*found).second;
00353 }
00354 }
00355
00356 #ifdef KEY
00357
00358
00359 char *new_name = (char *)malloc((strlen(name)+1)*sizeof(char));
00360 strcpy(new_name, name);
00361 name = new_name;
00362 #endif
00363 file_dst_list.push_back (std::make_pair (name, ++last_file_num));
00364 DST_enter_file (name, dir);
00365 return last_file_num;
00366 }
00367
00368
00369
00370 static const char *
00371 drop_path (const char *s)
00372 {
00373 const char *tail;
00374 tail = strrchr (s, '/');
00375 if (tail == NULL) {
00376 return s;
00377 } else {
00378 tail++;
00379 return tail;
00380 }
00381 }
00382
00383 static void
00384 DST_enter_file (const char *file_name, UINT dir)
00385 {
00386 UINT64 file_size = 0;
00387 UINT64 fmod_time = 0;
00388 struct stat fstat;
00389 if (stat(file_name, &fstat) == 0) {
00390
00391 file_size = (UINT64)fstat.st_size;
00392 fmod_time = (UINT64)fstat.st_mtime;
00393 }
00394 DST_mk_file_name(
00395 (char *) file_name,
00396 dir,
00397 file_size,
00398 fmod_time);
00399 }
00400
00401
00402
00403
00404
00405
00406
00407 static char *
00408 DST_get_command_line_options(INT32 num_copts,
00409 char *copts[])
00410 {
00411 INT32 i,
00412 strlength = 0;
00413 INT32 num_opts = 0;
00414 char **selected_opt;
00415 INT32 *opt_size;
00416 char *rtrn, *cp;
00417 char ch;
00418 INT32 record_option;
00419
00420 selected_opt = (char **)malloc(sizeof(char*) * num_copts);
00421 opt_size = (INT32 *)malloc(sizeof(INT32) * num_copts);
00422
00423 for (i = 1; i <= num_copts; i++)
00424 {
00425 if (copts[i] != NULL && copts[i][0] == '-')
00426 {
00427 ch = copts[i][1];
00428 if (Debug_Level <= 0)
00429
00430 record_option = (ch == 'g' ||
00431 ch == 'O');
00432 else
00433
00434 record_option = (ch == 'D' ||
00435 ch == 'g' ||
00436 ch == 'I' ||
00437 ch == 'O' ||
00438 ch == 'U');
00439 if (record_option)
00440 {
00441 opt_size[num_opts] = strlen(copts[i]) + 1;
00442 selected_opt[num_opts] = copts[i];
00443 strlength += opt_size[num_opts];
00444 num_opts += 1;
00445 }
00446 }
00447 }
00448
00449 if (strlength == 0)
00450 {
00451 rtrn = (char *)calloc(1, 1);
00452 }
00453 else
00454 {
00455 rtrn = (char *)malloc(strlength);
00456 cp = rtrn;
00457
00458
00459 for (i = 0; i < num_opts; i++)
00460 if (opt_size[i] > 0)
00461 {
00462 cp = strcpy(cp, selected_opt[i]) + opt_size[i];
00463 cp[-1] = ' ';
00464 }
00465 cp[-1] = '\0';
00466 }
00467
00468 free(selected_opt);
00469 free(opt_size);
00470 return rtrn;
00471 }
00472
00473 static char *
00474 Get_Name (tree node)
00475 {
00476 static char buf[64];
00477
00478
00479 if (node == NULL) {
00480 buf[0] = 0;
00481 return buf;
00482 }
00483 char *name = buf;
00484 buf[0] = 0;
00485
00486 #define DANAME(d) ((TREE_CODE_CLASS(TREE_CODE(d)) =='d')? \
00487 ((DECL_NAME(d))?IDENTIFIER_POINTER(DECL_NAME(d)):"?"):\
00488 "?2")
00489
00490
00491 int tc_class = (int)TREE_CODE_CLASS(TREE_CODE(node));
00492
00493 if (tc_class == 'd')
00494 {
00495 if (DECL_NAME (node)) {
00496 name = IDENTIFIER_POINTER (DECL_NAME (node));
00497 }
00498 }
00499 else if (tc_class == 't')
00500 {
00501 if (TYPE_NAME (node))
00502 {
00503 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
00504 name = IDENTIFIER_POINTER (TYPE_NAME (node));
00505 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
00506 && DECL_NAME (TYPE_NAME (node)))
00507 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
00508
00509 }
00510 } else {
00511 }
00512 return name;
00513 }
00514
00515 static void
00516 DST_enter_struct_union_members(tree parent_tree,
00517 DST_INFO_IDX parent_idx )
00518 {
00519 DST_INFO_IDX dst_idx;
00520 TY_IDX parent_ty_idx = Get_TY(parent_tree);
00521
00522
00523
00524
00525
00526
00527 tree field = TREE_PURPOSE(parent_tree);
00528
00529
00530
00531
00532 for( ; field ; field = TREE_CHAIN(field) )
00533 {
00534 if(TREE_CODE(field) != FIELD_DECL) {
00535 continue;
00536 }
00537
00538 char isbit = 0;
00539 if ( ! DECL_BIT_FIELD(field)
00540 #ifdef KEY
00541 && DECL_SIZE(field)
00542 #endif
00543 && Get_Integer_Value(DECL_SIZE(field)) > 0
00544 && Get_Integer_Value(DECL_SIZE(field))
00545 != (TY_size(Get_TY(TREE_TYPE(field)))
00546 * BITSPERBYTE) )
00547 {
00548
00549
00550
00551
00552
00553
00554
00555
00557
00558
00559 isbit = 1;
00560 }
00561 if (DECL_BIT_FIELD(field)) {
00562 isbit = 1;
00563 }
00564 DST_INFO_IDX field_idx;
00565 char *field_name = (Get_Name((field)));
00566
00567 tree ftype = TREE_TYPE(field);
00568
00569
00570 TY_IDX base = Get_TY(ftype);
00571
00572 struct mongoose_gcc_DST_IDX g_idx;
00573 g_idx = Create_DST_type_For_Tree(ftype,base,parent_ty_idx);
00574 DST_INFO_IDX fidx;
00575
00576 USRCPOS src;
00577
00578
00579
00580
00581 USRCPOS_clear(src);
00582
00583 cp_to_dst_from_tree(&fidx,&g_idx);
00584
00585 INT bitoff = Get_Integer_Value(DECL_FIELD_BIT_OFFSET(field));
00586 #ifndef KEY
00587 INT fld_offset_bytes =
00588 (bitoff / BITSPERBYTE);
00589 #else
00590
00591 INT fld_offset_bytes = Get_Integer_Value(DECL_FIELD_OFFSET(field)) +
00592 (bitoff / BITSPERBYTE);
00593 #endif
00594 tree type_size = TYPE_SIZE(ftype);
00595 UINT align = TYPE_ALIGN(ftype)/BITSPERBYTE;
00596 INT tsize;
00597 if (type_size == NULL) {
00598
00599 #ifndef KEY
00600 Fail_FmtAssertion("DST_enter_struct_union_members: type_size NULL ");
00601 #endif
00602 tsize = 0;
00603 }
00604 else {
00605 if (TREE_CODE(type_size) != INTEGER_CST) {
00606 if (TREE_CODE(type_size) == ARRAY_TYPE)
00607 Fail_FmtAssertion ("Encountered VLA at line %d", lineno);
00608 else
00609 Fail_FmtAssertion ("VLA at line %d not currently implemented",
00610 lineno);
00611 tsize = 0;
00612 }
00613 else
00614 tsize = Get_Integer_Value(type_size) / BITSPERBYTE;
00615 }
00616
00617 if(isbit == 0) {
00618
00619 field_idx = DST_mk_member(
00620 src,
00621 field_name,
00622 fidx,
00623 fld_offset_bytes,
00624 0,
00625 0,
00626 0,
00627 FALSE,
00628 FALSE,
00629 FALSE,
00630 FALSE);
00631
00632 } else {
00633 if(tsize == 0) {
00634 Fail_FmtAssertion("bit field type size 0!");
00635 continue;
00636 }
00637 UINT container_off = fld_offset_bytes - (fld_offset_bytes%align);
00638
00639
00640
00641
00642
00643 #ifndef KEY
00644 UINT into_cont_off = bitoff - (container_off*BITSPERBYTE);
00645 #else
00646 UINT into_cont_off = bitoff - ((container_off%16)*BITSPERBYTE);
00647
00648
00649
00650
00651 if (!BYTES_BIG_ENDIAN) {
00652 into_cont_off = tsize*BITSPERBYTE - into_cont_off;
00653 into_cont_off -= Get_Integer_Value(DECL_SIZE(field));
00654 }
00655 #endif
00656
00657 field_idx = DST_mk_member(
00658 src,
00659 field_name,
00660 fidx ,
00661 #ifdef KEY
00662 container_off,
00663 #else
00664 fld_offset_bytes,
00665 #endif
00666 tsize,
00667 into_cont_off,
00668
00669
00670 Get_Integer_Value(DECL_SIZE(field)),
00671 TRUE,
00672 FALSE,
00673 FALSE,
00674 FALSE);
00675 }
00676 DST_append_child(parent_idx,field_idx);
00677
00678
00679
00680
00681 }
00682
00683 return ;
00684 }
00685
00686
00687
00688 static DST_INFO_IDX
00689 DST_enter_struct_union(tree type_tree, TY_IDX ttidx , TY_IDX idx,
00690 INT tsize)
00691 {
00692 DST_INFO_IDX dst_idx ;
00693 struct mongoose_gcc_DST_IDX tdst
00694 = TYPE_DST_IDX(type_tree);
00695 cp_to_dst_from_tree(&dst_idx,&tdst);
00696
00697 DST_INFO_IDX current_scope_idx =
00698 DST_get_context(TYPE_CONTEXT(type_tree));
00699
00700 if(DST_IS_NULL(dst_idx)) {
00701
00702
00703
00704
00705
00706
00707
00708 USRCPOS src;
00709
00710
00711
00712
00713 USRCPOS_clear(src);
00714
00715 char *name = Get_Name(type_tree);
00716
00717 if(TREE_CODE(type_tree) == RECORD_TYPE) {
00718 dst_idx = DST_mk_structure_type(src,
00719 name ,
00720 tsize,
00721 DST_INVALID_IDX,
00722 TREE_PURPOSE(type_tree)== 0
00723 );
00724 } else if (TREE_CODE(type_tree) == UNION_TYPE) {
00725 dst_idx = DST_mk_union_type(src,
00726 name ,
00727 tsize,
00728 DST_INVALID_IDX,
00729 TREE_PURPOSE(type_tree)== 0
00730 );
00731 } else {
00732 DevWarn("DST_enter_struct_union type tree wrong code! %d",
00733 (int)TREE_CODE(type_tree));
00734 return dst_idx;
00735 }
00736 DST_append_child(current_scope_idx,dst_idx);
00737
00738
00739
00740 struct mongoose_gcc_DST_IDX mdst;
00741 cp_to_tree_from_dst(&mdst,&dst_idx);
00742 TYPE_DST_IDX(type_tree) = mdst;
00743
00744
00745 DST_enter_struct_union_members(type_tree,dst_idx);
00746
00747 }
00748
00749 return dst_idx;
00750 }
00751
00752
00753
00754
00755 static DST_INFO_IDX
00756 DST_enter_enum(tree type_tree, TY_IDX ttidx , TY_IDX idx,
00757 INT tsize)
00758 {
00759 DST_INFO_IDX dst_idx;
00760 struct mongoose_gcc_DST_IDX tdst
00761 = TYPE_DST_IDX(type_tree);
00762 cp_to_dst_from_tree(&dst_idx,&tdst);
00763
00764 if(TREE_CODE_CLASS(TREE_CODE(type_tree)) != 't') {
00765 DevWarn("DST_enter_enum input not 't' but %c",
00766 TREE_CODE_CLASS(TREE_CODE(type_tree)));
00767 }
00768 DST_INFO_IDX current_scope_idx =
00769 DST_get_context(TYPE_CONTEXT(type_tree));
00770
00771
00772 if(DST_IS_NULL(dst_idx)) {
00773 DST_INFO_IDX t_dst_idx;
00774 USRCPOS src;
00775
00776
00777
00778
00779 USRCPOS_clear(src);
00780 char *name1 = Get_Name(type_tree);
00781 tree enum_entry = TYPE_VALUES(type_tree);
00782 DST_size_t e_tsize = tsize;
00783 t_dst_idx = DST_mk_enumeration_type( src,
00784 name1,
00785 e_tsize,
00786 DST_INVALID_IDX,
00787 (enum_entry==NULL_TREE));
00788
00789 DST_append_child(current_scope_idx,t_dst_idx);
00790
00791 struct mongoose_gcc_DST_IDX mdst;
00792 cp_to_tree_from_dst(&mdst,&t_dst_idx);
00793 TYPE_DST_IDX(type_tree) = mdst;
00794
00795
00796 DST_CONST_VALUE enumerator;
00797 if(tsize == 8) {
00798 DST_CONST_VALUE_form(enumerator) = DST_FORM_DATA8;
00799 } else if (tsize == 4) {
00800 DST_CONST_VALUE_form(enumerator) = DST_FORM_DATA4;
00801 } else {
00802
00803 DST_CONST_VALUE_form(enumerator) = DST_FORM_DATA4;
00804 DevWarn("Unexpected type size %d in enumerator",
00805 (int)tsize);
00806 }
00807
00808 for( ; enum_entry; enum_entry = TREE_CHAIN(enum_entry) ) {
00809 USRCPOS src;
00810
00811
00812
00813
00814 USRCPOS_clear(src);
00815 char *name2 = IDENTIFIER_POINTER(TREE_PURPOSE(enum_entry));
00816
00817 if (tsize == 8) {
00818 DST_CONST_VALUE_form_data8(enumerator) =
00819 Get_Integer_Value(TREE_VALUE(enum_entry));
00820 } else {
00821 DST_CONST_VALUE_form_data4(enumerator) =
00822 Get_Integer_Value(TREE_VALUE(enum_entry));
00823 }
00824
00825 DST_INFO_IDX ed = DST_mk_enumerator(src,
00826 name2,
00827 enumerator);
00828 DST_append_child(t_dst_idx,ed);
00829
00830 }
00831
00832
00833 #ifdef KEY
00834
00835
00836 dst_idx = t_dst_idx;
00837 #endif
00838 }
00839 return dst_idx;
00840 }
00841
00842
00843
00844 #ifdef KEY
00845 typedef struct type_trans {
00846 DST_size_t size;
00847 char *name;
00848 DST_ATE_encoding encoding;
00849 } type_trans;
00850
00851 static DST_INFO_IDX base_types[MTYPE_LAST+5] =
00852 {
00853 DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,
00854 DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,
00855 DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,
00856 DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,
00857 DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,
00858 DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,
00859 DST_INVALID_INIT
00860 } ;
00861
00862 static type_trans ate_types[] = {
00863 #ifdef TARG_IA64
00864 1, "BAD", 0,
00865 1, "LOGICAL_1", DW_ATE_boolean,
00866 #else
00867 4, "BAD", 0,
00868 4, "UNK", 0,
00869 #endif
00870 1, "INTEGER_1", DW_ATE_signed,
00871 2, "INTEGER_2", DW_ATE_signed,
00872 4, "INTEGER_4", DW_ATE_signed,
00873 8, "INTEGER_8", DW_ATE_signed,
00874 1, "INTEGER*1", DW_ATE_unsigned,
00875 2, "INTEGER*2", DW_ATE_unsigned,
00876 4, "INTEGER*4", DW_ATE_unsigned,
00877 8, "INTEGER*8", DW_ATE_unsigned,
00878 4, "REAL_4", DW_ATE_float,
00879 8, "REAL_8", DW_ATE_float,
00880 #ifdef TARG_IA64
00881 16,"REAL_10", DW_ATE_float,
00882 #else
00883 10, "UNK", DW_ATE_float,
00884 #endif
00885 16,"REAL_16", DW_ATE_float,
00886 1 ,"CHAR" , DW_ATE_signed_char,
00887 16,"REAL_16", DW_ATE_float,
00888 1, "UNK", DW_ATE_unsigned_char,
00889 8, "COMPLEX_4", DW_ATE_complex_float,
00890 16,"COMPLEX_8", DW_ATE_complex_float,
00891 32,"COMPLEX_16",DW_ATE_complex_float,
00892 1, "VOID", 0,
00893 #ifdef TARG_IA64
00894 1, "UNK", 0,
00895 4, "ADDRESS_4", DW_ATE_unsigned,
00896 8, "ADDRESS_8", DW_ATE_unsigned,
00897 32,"COMPLEX_16",DW_ATE_complex_float,
00898 #else
00899 1, "LOGICAL_1", DW_ATE_boolean,
00900 2, "LOGICAL_2", DW_ATE_boolean,
00901 4, "LOGICAL_4", DW_ATE_boolean,
00902 8, "LOGICAL_8", DW_ATE_boolean,
00903 #endif
00904 } ;
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916 static DST_INFO_IDX
00917 DST_create_basetype (TY_IDX ty)
00918 {
00919 TYPE_ID bt ;
00920 DST_INFO_IDX i ;
00921
00922 bt = TY_mtype(ty);
00923
00924 if (bt == MTYPE_V) return(DST_INVALID_IDX);
00925
00926 if (TY_is_logical(Ty_Table[ty]))
00927 bt = bt -MTYPE_I1 + MTYPE_V + 1 ;
00928
00929 if (!DST_IS_NULL(base_types[bt]))
00930 return base_types[bt];
00931
00932 i = DST_mk_basetype(ate_types[bt].name,
00933 ate_types[bt].encoding,
00934 ate_types[bt].size);
00935
00936 base_types[bt] = i;
00937 DST_append_child(comp_unit_idx,i);
00938 return i;
00939 }
00940
00941
00942
00943 static DST_INFO_IDX
00944 DST_enter_subrange_type (ARB_HANDLE ar)
00945 {
00946 DST_INFO_IDX i ;
00947 DST_cval_ref lb,ub;
00948 DST_flag const_lb,const_ub ;
00949 BOOL extent = FALSE ;
00950 USRCPOS src;
00951 USRCPOS_clear(src);
00952 DST_INFO_IDX type;
00953
00954 const_lb = ARB_const_lbnd(ar) ;
00955 const_ub = ARB_const_ubnd(ar) ;
00956
00957
00958 if (const_lb)
00959 lb.cval = ARB_lbnd_val(ar) ;
00960 else {
00961 ST* var_st = &St_Table[ARB_lbnd_var(ar)];
00962 type = DST_create_basetype(ST_type(var_st));
00963 lb.ref = DST_mk_variable(
00964 src,
00965 ST_name(var_st),
00966 type,
00967 0,
00968 ST_st_idx(var_st),
00969 DST_INVALID_IDX,
00970 FALSE,
00971 ST_sclass(var_st) == SCLASS_AUTO,
00972 FALSE,
00973 FALSE );
00974 #ifdef KEY
00975
00976 if (ST_name(var_st) != NULL && *ST_name(var_st) != '\0')
00977 #endif
00978 DST_append_child(comp_unit_idx,lb.ref);
00979 }
00980
00981 if (const_ub) {
00982 ub.cval = ARB_ubnd_val(ar) ;
00983
00984
00985 if (ub.cval == 0xffffffff) {
00986 const_ub = 0 ;
00987 }
00988
00989 } else if (ARB_ubnd_var(ar)) {
00990 ST* var_st = &St_Table[ARB_ubnd_var(ar)];
00991 type = DST_create_basetype(ST_type(var_st));
00992 ub.ref = DST_mk_variable(
00993 src,
00994 ST_name(var_st),
00995 type,
00996 0,
00997 ST_st_idx(var_st),
00998 DST_INVALID_IDX,
00999 FALSE,
01000 ST_sclass(var_st) == SCLASS_AUTO,
01001 FALSE,
01002 FALSE );
01003 #ifdef KEY
01004
01005 if (ST_name(var_st) != NULL && *ST_name(var_st) != '\0')
01006 #endif
01007 DST_append_child(comp_unit_idx,ub.ref);
01008 }
01009
01010 i = DST_mk_subrange_type(const_lb,
01011 lb,
01012 const_ub,
01013 ub);
01014
01015 if (extent)
01016 DST_SET_count(DST_INFO_flag(DST_INFO_IDX_TO_PTR(i))) ;
01017
01018 return i;
01019 }
01020
01021 #endif
01022
01023
01024
01025 static DST_INFO_IDX
01026 DST_enter_array_type(tree type_tree, TY_IDX ttidx , TY_IDX idx,INT tsize)
01027 {
01028 DST_INFO_IDX dst_idx;
01029 struct mongoose_gcc_DST_IDX tdst
01030 = TYPE_DST_IDX(type_tree);
01031 cp_to_dst_from_tree(&dst_idx,&tdst);
01032
01033 if(TREE_CODE_CLASS(TREE_CODE(type_tree)) != 't') {
01034 DevWarn("DST_enter_array_type input not 't' but %c",
01035 TREE_CODE_CLASS(TREE_CODE(type_tree)));
01036 }
01037
01038 if(DST_IS_NULL(dst_idx)) {
01039
01040 USRCPOS src;
01041
01042
01043
01044
01045 USRCPOS_clear(src);
01046
01047
01048
01049 tree elt_tree = TREE_TYPE(type_tree);
01050 TY_IDX itx = TYPE_TY_IDX(elt_tree);
01051 struct mongoose_gcc_DST_IDX amdst
01052 = TYPE_DST_IDX(type_tree);
01053 cp_to_dst_from_tree(&dst_idx,&amdst);
01054
01055
01056 struct mongoose_gcc_DST_IDX inner =
01057 Create_DST_type_For_Tree (elt_tree,itx, idx);
01058
01059 DST_INFO_IDX inner_dst;
01060 cp_to_dst_from_tree(&inner_dst,&inner);
01061
01062 #ifndef KEY
01063 dst_idx = DST_mk_array_type( src,
01064 0,
01065
01066 inner_dst,
01067 tsize,
01068 DST_INVALID_IDX,
01069 (tsize == 0));
01070 #else
01071
01072
01073
01074 dst_idx = DST_mk_array_type( src,
01075 0,
01076
01077 inner_dst,
01078 0,
01079 DST_INVALID_IDX,
01080 TRUE);
01081 TY& tt = Ty_Table[ttidx];
01082 ARB_HANDLE arb = TY_arb(ttidx);
01083 DST_INFO_IDX d;
01084 if ( TY_kind (tt) != KIND_INVALID ) {
01085 for (INT index = TY_AR_ndims(ttidx) - 1; index >= 0; index--) {
01086
01087 if (!ARB_const_ubnd(arb[index])) {
01088
01089
01090
01091
01092 if (!ARB_ubnd_var(arb[index]))
01093 break;
01094 ST* var_st = &St_Table[ARB_ubnd_var(arb[index])];
01095 if (ST_sclass(var_st) == SCLASS_AUTO)
01096 break;
01097 }
01098
01099 d = DST_enter_subrange_type(arb[index]);
01100 DST_append_child(dst_idx,d);
01101 }
01102 }
01103 #endif
01104 DST_append_child(comp_unit_idx,dst_idx);
01105
01106 struct mongoose_gcc_DST_IDX mdst;
01107 cp_to_tree_from_dst(&mdst,&dst_idx);
01108 TYPE_DST_IDX(type_tree) = mdst;
01109 }
01110 return dst_idx;
01111 }
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129 extern struct mongoose_gcc_DST_IDX
01130 Create_DST_type_For_Tree (tree type_tree, TY_IDX ttidx , TY_IDX idx, bool ignoreconst, bool ignorevolatile)
01131 {
01132
01133 struct mongoose_gcc_DST_IDX actual_retval;
01134
01135
01136 if(TREE_CODE_CLASS(TREE_CODE(type_tree)) != 't') {
01137 DevWarn("Create_DST_type_For_Tree input not 't' but %c",
01138 TREE_CODE_CLASS(TREE_CODE(type_tree)));
01139 }
01140
01141 DST_INFO_IDX dst_idx = DST_INVALID_INIT;
01142
01143 DST_INFO_IDX current_scope_idx = comp_unit_idx;
01144 if(TYPE_CONTEXT(type_tree)) {
01145 current_scope_idx = DST_get_context(TYPE_CONTEXT(type_tree));
01146 }
01147
01148
01149 if (TYPE_NAME(type_tree)) {
01150
01151 if( idx == 0 &&
01152 (TREE_CODE(type_tree) == RECORD_TYPE ||
01153 TREE_CODE(type_tree) == UNION_TYPE) &&
01154 TREE_CODE(TYPE_NAME(type_tree)) == TYPE_DECL &&
01155 TYPE_MAIN_VARIANT(type_tree) != type_tree) {
01156 idx = Get_TY (TYPE_MAIN_VARIANT(type_tree));
01157
01158 #ifndef KEY
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174 cp_to_tree_from_dst(&actual_retval,&dst_idx);
01175 return actual_retval;
01176 #endif
01177 } else {
01178
01179 }
01180 }
01181
01182 char *name1 = Get_Name(type_tree);
01183
01184 TYPE_ID mtype;
01185 INT tsize;
01186 BOOL variable_size = FALSE;
01187 tree type_size = TYPE_SIZE(type_tree);
01188 UINT align = TYPE_ALIGN(type_tree) / BITSPERBYTE;
01189 if (type_size == NULL) {
01190
01191
01192 FmtAssert(TREE_CODE(type_tree) == ARRAY_TYPE
01193 || TREE_CODE(type_tree) == UNION_TYPE
01194 || TREE_CODE(type_tree) == RECORD_TYPE
01195 || TREE_CODE(type_tree) == ENUMERAL_TYPE
01196 || TREE_CODE(type_tree) == VOID_TYPE
01197 || TREE_CODE(type_tree) == LANG_TYPE,
01198 ("Create_DST_type_For_Tree: type_size NULL for non ARRAY/RECORD"));
01199 tsize = 0;
01200 }
01201 else {
01202 if (TREE_CODE(type_size) != INTEGER_CST) {
01203 if (TREE_CODE(type_tree) == ARRAY_TYPE)
01204 DevWarn ("Encountered VLA at line %d", lineno);
01205 else
01206 Fail_FmtAssertion ("VLA at line %d not currently implemented", lineno);
01207 variable_size = TRUE;
01208 tsize = 0;
01209 }
01210 else
01211 tsize = Get_Integer_Value(type_size) / BITSPERBYTE;
01212 }
01213 if (!ignoreconst && TYPE_READONLY (type_tree)) {
01214 struct mongoose_gcc_DST_IDX tdst = TYPE_DST_IDX(type_tree);
01215 cp_to_dst_from_tree(&dst_idx,&tdst);
01216 if(DST_IS_NULL(dst_idx)) {
01217 TY_IDX itx = TYPE_TY_IDX(type_tree);
01218 struct mongoose_gcc_DST_IDX unqualtype = Create_DST_type_For_Tree (type_tree, itx, idx, true, false) ;
01219 DST_INFO_IDX unqual_dst;
01220
01221 cp_to_dst_from_tree(&unqual_dst,&unqualtype);
01222
01223 dst_idx = DST_mk_const_type (unqual_dst) ;
01224
01225 DST_append_child(current_scope_idx,dst_idx);
01226
01227 struct mongoose_gcc_DST_IDX qual_dst_idx;
01228 cp_to_tree_from_dst(&qual_dst_idx,&dst_idx);
01229 TYPE_DST_IDX(type_tree) = qual_dst_idx;
01230 }
01231 cp_to_tree_from_dst(&actual_retval,&dst_idx);
01232 return actual_retval;
01233 }
01234 if (!ignorevolatile && TYPE_VOLATILE (type_tree)) {
01235 struct mongoose_gcc_DST_IDX tdst = TYPE_DST_IDX(type_tree);
01236 cp_to_dst_from_tree(&dst_idx,&tdst);
01237 if(DST_IS_NULL(dst_idx)) {
01238 TY_IDX itx = TYPE_TY_IDX(type_tree);
01239 struct mongoose_gcc_DST_IDX unqualtype = Create_DST_type_For_Tree (type_tree, itx, idx, true, true) ;
01240 DST_INFO_IDX unqual_dst;
01241
01242 cp_to_dst_from_tree(&unqual_dst,&unqualtype);
01243
01244 dst_idx = DST_mk_volatile_type (unqual_dst) ;
01245
01246 DST_append_child(current_scope_idx,dst_idx);
01247
01248 struct mongoose_gcc_DST_IDX qual_dst_idx;
01249 cp_to_tree_from_dst(&qual_dst_idx,&dst_idx);
01250 TYPE_DST_IDX(type_tree) = qual_dst_idx;
01251 }
01252 cp_to_tree_from_dst(&actual_retval,&dst_idx);
01253 return actual_retval;
01254 }
01255 int encoding = 0;
01256 switch (TREE_CODE(type_tree)) {
01257 case VOID_TYPE:
01258
01259
01260 break;
01261 case BOOLEAN_TYPE:
01262 {
01263 encoding = DW_ATE_boolean;
01264 goto common_basetypes;
01265 }
01266 case INTEGER_TYPE:
01267 {
01268
01269 #ifdef KEY
01270
01271
01272
01273
01274
01275 if (tsize == 1 &&
01276 (strcmp(name1, "char") == 0 ||
01277 strcmp(name1, "unsigned char") == 0)) {
01278 if (TREE_UNSIGNED(type_tree)) {
01279 encoding = DW_ATE_unsigned_char;
01280 } else {
01281 encoding = DW_ATE_signed_char;
01282 }
01283 goto common_basetypes;
01284 }
01285 #endif
01286 if (TREE_UNSIGNED(type_tree)) {
01287 encoding = DW_ATE_unsigned;
01288 } else {
01289 encoding = DW_ATE_signed;
01290 }
01291 goto common_basetypes;
01292 }
01293 case CHAR_TYPE:
01294 {
01295
01296 if (TREE_UNSIGNED(type_tree)) {
01297 encoding = DW_ATE_unsigned_char;
01298 } else {
01299 encoding = DW_ATE_signed_char;
01300 }
01301 goto common_basetypes;
01302 }
01303 case ENUMERAL_TYPE:
01304 {
01305 #ifdef KEY
01306
01307 if (is_typedef (type_tree))
01308 dst_idx = DST_Create_type ((ST*)NULL, TYPE_NAME (type_tree));
01309 else
01310 #endif
01311 dst_idx = DST_enter_enum(type_tree,ttidx,idx,
01312 tsize);
01313
01314 }
01315 break;
01316 case REAL_TYPE:
01317 {
01318
01319 encoding = DW_ATE_float;
01320 goto common_basetypes;
01321 }
01322 case COMPLEX_TYPE:
01323
01324 encoding = DW_ATE_complex_float;
01325
01326 common_basetypes:
01327 {
01328 FmtAssert(name1 != 0,
01329 ("name of base type empty, cannot make DST entry!"));
01330
01331 std::string names(name1);
01332 DST_Type_Map::iterator p =
01333 basetypes.find(names);
01334 if(p != basetypes.end()) {
01335 DST_INFO_IDX t = (*p).second;
01336 cp_to_tree_from_dst(&actual_retval,&t);
01337 return actual_retval;
01338 } else {
01339 #ifdef KEY
01340
01341 if (is_typedef (type_tree))
01342 dst_idx = DST_Create_type ((ST*)NULL,
01343 TYPE_NAME (type_tree));
01344 else
01345 #endif
01346 {
01347 dst_idx = DST_mk_basetype(
01348 name1,encoding,tsize);
01349 basetypes[names] = dst_idx;
01350 DST_append_child(comp_unit_idx,dst_idx);
01351 }
01352 }
01353
01354 }
01355
01356 break;
01357 case REFERENCE_TYPE:
01358 {
01359 struct mongoose_gcc_DST_IDX tdst
01360 = TYPE_DST_IDX(type_tree);
01361 cp_to_dst_from_tree(&dst_idx,&tdst);
01362 if(DST_IS_NULL(dst_idx)) {
01363
01364 tree ttree = TREE_TYPE(type_tree);
01365 TY_IDX itx = TYPE_TY_IDX(ttree);
01366 struct mongoose_gcc_DST_IDX inner =
01367 Create_DST_type_For_Tree (ttree,itx, idx);
01368
01369 DST_INFO_IDX inner_dst;
01370
01371 cp_to_dst_from_tree(&inner_dst,&inner);
01372
01373 dst_idx = DST_mk_reference_type(
01374 inner_dst,
01375 #ifdef TARG_NVISA
01376 DW_ADDR_global_space,
01377 #else
01378 DW_ADDR_none,
01379 #endif
01380 tsize);
01381
01382 DST_append_child(current_scope_idx,dst_idx);
01383
01384 struct mongoose_gcc_DST_IDX ptr_dst_idx;
01385 cp_to_tree_from_dst(&ptr_dst_idx,&dst_idx);
01386 TYPE_DST_IDX(type_tree) = ptr_dst_idx;
01387 }
01388 }
01389 break;
01390 case POINTER_TYPE:
01391 #ifdef KEY
01392
01393 if (is_typedef (type_tree))
01394 dst_idx = DST_Create_type ((ST*)NULL, TYPE_NAME (type_tree));
01395 else
01396 #endif
01397 {
01398 struct mongoose_gcc_DST_IDX tdst
01399 = TYPE_DST_IDX(type_tree);
01400 cp_to_dst_from_tree(&dst_idx,&tdst);
01401 if(DST_IS_NULL(dst_idx)) {
01402
01403 tree ttree = TREE_TYPE(type_tree);
01404 TY_IDX itx = TYPE_TY_IDX(ttree);
01405 struct mongoose_gcc_DST_IDX inner =
01406 Create_DST_type_For_Tree (ttree,itx, idx);
01407
01408
01409
01410 DST_INFO_IDX inner_dst;
01411
01412 cp_to_dst_from_tree(&inner_dst,&inner);
01413 dst_idx = DST_mk_pointer_type(
01414 inner_dst,
01415 #ifdef TARG_NVISA
01416
01417
01418 DW_ADDR_global_space,
01419 #else
01420 DW_ADDR_none,
01421 #endif
01422 tsize);
01423
01424 DST_append_child(current_scope_idx,dst_idx);
01425
01426 struct mongoose_gcc_DST_IDX ptr_dst_idx;
01427 cp_to_tree_from_dst(&ptr_dst_idx,&dst_idx);
01428 TYPE_DST_IDX(type_tree) = ptr_dst_idx;
01429 }
01430 }
01431 break;
01432
01433 case ARRAY_TYPE:
01434
01435 {
01436 dst_idx = DST_enter_array_type(type_tree,
01437 ttidx, idx, tsize);
01438 }
01439 break;
01440 case RECORD_TYPE:
01441 case UNION_TYPE:
01442 {
01443 #ifdef KEY
01444
01445 if (is_typedef (type_tree))
01446 dst_idx = DST_Create_type ((ST*)NULL, TYPE_NAME (type_tree));
01447 else
01448 #endif
01449 dst_idx = DST_enter_struct_union(type_tree,ttidx,idx,
01450 tsize);
01451 }
01452 break;
01453 case METHOD_TYPE:
01454 {
01455
01456 }
01457 break;
01458 case FUNCTION_TYPE:
01459 {
01460 #if 0
01461 tree arg;
01462 INT32 num_args;
01463 TY &ty = New_TY (idx);
01464 TY_Init (ty, 0, KIND_FUNCTION, MTYPE_UNKNOWN, NULL);
01465 Set_TY_align (idx, 1);
01466 TY_IDX ret_ty_idx;
01467 TY_IDX arg_ty_idx;
01468 TYLIST tylist_idx;
01469
01470
01471
01472
01473
01474 ret_ty_idx = Get_TY(TREE_TYPE(type_tree));
01475 for (arg = TYPE_ARG_TYPES(type_tree);
01476 arg;
01477 arg = TREE_CHAIN(arg))
01478 arg_ty_idx = Get_TY(TREE_VALUE(arg));
01479
01480
01481
01482 if (!WFE_Keep_Zero_Length_Structs &&
01483 TY_mtype (ret_ty_idx) == MTYPE_M &&
01484 TY_size (ret_ty_idx) == 0) {
01485
01486 DevWarn ("function returning zero length struct at line %d", lineno);
01487 ret_ty_idx = Be_Type_Tbl (MTYPE_V);
01488 }
01489
01490 Set_TYLIST_type (New_TYLIST (tylist_idx), ret_ty_idx);
01491 Set_TY_tylist (ty, tylist_idx);
01492 for (num_args = 0, arg = TYPE_ARG_TYPES(type_tree);
01493 arg;
01494 num_args++, arg = TREE_CHAIN(arg))
01495 {
01496 arg_ty_idx = Get_TY(TREE_VALUE(arg));
01497 if (!WFE_Keep_Zero_Length_Structs &&
01498 TY_mtype (arg_ty_idx) == MTYPE_M &&
01499 TY_size (arg_ty_idx) == 0) {
01500
01501 DevWarn ("zero length struct encountered in function prototype at line %d", lineno);
01502 }
01503 else
01504 Set_TYLIST_type (New_TYLIST (tylist_idx), arg_ty_idx);
01505 }
01506 if (num_args)
01507 {
01508 Set_TY_has_prototype(idx);
01509 if (arg_ty_idx != Be_Type_Tbl(MTYPE_V))
01510 {
01511 Set_TYLIST_type (New_TYLIST (tylist_idx), 0);
01512 Set_TY_is_varargs(idx);
01513 }
01514 else
01515 Set_TYLIST_type (Tylist_Table [tylist_idx], 0);
01516 }
01517 else
01518 Set_TYLIST_type (New_TYLIST (tylist_idx), 0);
01519 #endif
01520 }
01521 break;
01522 #ifdef TARG_X8664
01523 case VECTOR_TYPE:
01524 {
01525
01526
01527 type_tree = TREE_TYPE (TYPE_FIELDS
01528 (TYPE_DEBUG_REPRESENTATION_TYPE (type_tree)));
01529 ttidx = Get_TY (type_tree);
01530 dst_idx = DST_enter_array_type(type_tree, ttidx, idx, tsize);
01531 DST_SET_GNU_vector(DST_INFO_flag(DST_INFO_IDX_TO_PTR(dst_idx)));
01532 }
01533 break;
01534 #endif // TARG_X8664
01535 default:
01536 FmtAssert(FALSE, ("Create_DST_type_For_Tree: unexpected tree_type"));
01537 }
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547 cp_to_tree_from_dst(&actual_retval,&dst_idx);
01548 return actual_retval;
01549 }
01550
01551
01552 static int
01553 same_dst_idx(struct mongoose_gcc_DST_IDX s1, struct mongoose_gcc_DST_IDX s2)
01554 {
01555 if( (s1.block == s2.block) &&
01556 (s1.offset == s2.offset) ) {
01557 return 1;
01558 }
01559 return 0;
01560 }
01561
01562 #ifdef KEY
01563
01564 extern bool
01565 have_dst_idx (tree decl)
01566 {
01567 struct mongoose_gcc_DST_IDX var_idx;
01568 DST_INFO_IDX dst_idx = DST_INVALID_INIT;
01569
01570 cp_to_tree_from_dst(&var_idx,&dst_idx);
01571
01572 return (!same_dst_idx (DECL_DST_IDX(decl), var_idx));
01573 }
01574 #endif // KEY
01575
01576 extern struct mongoose_gcc_DST_IDX
01577 Create_DST_decl_For_Tree(
01578 tree decl, ST* var_st)
01579 {
01580
01581 struct mongoose_gcc_DST_IDX var_idx;
01582 DST_INFO_IDX dst_idx = DST_INVALID_INIT;
01583 cp_to_tree_from_dst(&var_idx,&dst_idx);
01584
01585
01586 struct mongoose_gcc_DST_IDX cur_idx;
01587
01588
01589 cur_idx = DECL_DST_IDX(decl);
01590 if(!same_dst_idx(cur_idx,var_idx)) {
01591 return cur_idx;
01592 }
01593
01594
01595
01596
01597
01598 if (DECL_IGNORED_P(decl)) {
01599 return var_idx;
01600 }
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613 if (TREE_CODE(decl) == VAR_DECL &&
01614 DECL_EXTERNAL(decl) && !DECL_COMMON(decl)) {
01615 return var_idx;
01616 }
01617 #ifndef KEY
01618
01619
01620
01621
01622
01623
01624 if (TREE_CODE(decl) == VAR_DECL && (!TREE_STATIC(decl)
01625 && !DECL_COMMON(decl))) {
01626 return var_idx ;
01627 }
01628 #endif
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638 int tcode = TREE_CODE(decl);
01639 switch(tcode) {
01640 case VAR_DECL: {
01641
01642 dst_idx = DST_Create_var(var_st,decl);
01643 }
01644 break;
01645 case TYPE_DECL: {
01646
01647 dst_idx = DST_Create_type(var_st,decl);
01648 }
01649 break;
01650 case PARM_DECL: {
01651
01652 dst_idx = DST_Create_Parmvar(var_st,decl);
01653 }
01654 break;
01655 #ifdef KEY
01656 case FUNCTION_DECL: {
01657 dst_idx = DST_Create_Subprogram(var_st,decl);
01658 }
01659 break;
01660 #endif // KEY
01661 default: {
01662 }
01663 break;
01664 }
01665 cp_to_tree_from_dst(&var_idx,&dst_idx);
01666 return var_idx;
01667 }
01668
01669
01670
01671 static DST_INFO_IDX
01672 DST_Create_type(ST *typ_decl, tree decl)
01673 {
01674 USRCPOS src;
01675
01676
01677
01678
01679
01680
01681 USRCPOS_clear(src);
01682 DST_INFO_IDX dst_idx;
01683
01684
01685
01686 char *name1 = 0;
01687 if(DECL_ORIGINAL_TYPE(decl)== 0) {
01688
01689 name1 = Get_Name(TREE_TYPE(decl));
01690 } else {
01691
01692 #ifdef KEY
01693
01694
01695 name1 = Get_Name(TREE_TYPE(decl));
01696 #else
01697 name1 = Get_Name(DECL_ORIGINAL_TYPE(decl));
01698 #endif
01699 }
01700
01701
01702
01703
01704 std::string names(name1);
01705 DST_Type_Map::iterator p =
01706 basetypes.find(names);
01707 if(p != basetypes.end()) {
01708
01709 DST_INFO_IDX t = (*p).second;
01710
01711 return t;
01712 }
01713
01714 DST_INFO_IDX current_scope_idx =
01715 DST_get_context(DECL_CONTEXT(decl));
01716
01717
01718
01719 #ifdef KEY
01720
01721 tree undt = DECL_ORIGINAL_TYPE(decl);
01722 #else
01723 tree undt = DECL_RESULT(decl);
01724 #endif
01725 struct mongoose_gcc_DST_IDX dst;
01726 TY_IDX base;
01727
01728 if(!undt) {
01729 DevWarn ("DST no result type for typedef decl: impossible");
01730 return DST_INVALID_IDX;
01731 }
01732
01733
01734 base = Get_TY(undt);
01735 dst = Create_DST_type_For_Tree(undt,base, 0);
01736
01737 DST_INFO_IDX sub_idx;
01738 cp_to_dst_from_tree(&sub_idx,&dst);
01739
01740 dst_idx = DST_mk_typedef( src,
01741 name1,
01742 sub_idx,
01743 DST_INVALID_IDX);
01744 DST_append_child(current_scope_idx,dst_idx);
01745
01746 basetypes[names] = dst_idx;
01747 struct mongoose_gcc_DST_IDX mdst;
01748 cp_to_tree_from_dst(&mdst,&dst_idx);
01749 TYPE_DST_IDX(undt) = mdst;
01750
01751 return dst_idx;
01752 }
01753
01754 static DST_INFO_IDX
01755 DST_Create_Parmvar(ST *var_st, tree param)
01756 {
01757 USRCPOS src;
01758
01759
01760
01761
01762
01763 USRCPOS_clear(src);
01764
01765 DST_INFO_IDX dtype;
01766
01767 DST_INFO_IDX type_idx;
01768
01769 ST * st = Get_ST(param);
01770
01771
01772 tree type = TREE_TYPE(param);
01773
01774 TY_IDX ty_idx = Get_TY(type);
01775
01776
01777 struct mongoose_gcc_DST_IDX type_gcc_dst =
01778 DECL_DST_IDX(param);
01779 cp_to_dst_from_tree(&dtype,&type_gcc_dst);
01780 return dtype;
01781 }
01782
01783 static DST_INFO_IDX
01784 DST_Create_var(ST *var_st, tree decl)
01785 {
01786 USRCPOS src;
01787
01788
01789
01790
01791
01792 int is_external = TREE_PUBLIC(decl);
01793
01794 USRCPOS_clear(src);
01795 DST_INFO_IDX dst;
01796 DST_INFO_IDX type;
01797
01798
01799 struct mongoose_gcc_DST_IDX type_gcc_dst =
01800 TYPE_DST_IDX(TREE_TYPE(decl));
01801 cp_to_dst_from_tree(&type,&type_gcc_dst);
01802 #ifdef KEY
01803 DST_INFO_IDX current_scope_idx =
01804 DST_get_context(DECL_CONTEXT(decl));
01805
01806 if (TYPE_READONLY(TREE_TYPE(decl))) {
01807 type = DST_mk_const_type (type) ;
01808 DST_append_child(current_scope_idx, type);
01809 }
01810
01811 if (TYPE_VOLATILE(TREE_TYPE(decl))) {
01812 type = DST_mk_volatile_type (type) ;
01813 DST_append_child(current_scope_idx, type);
01814 }
01815 #endif
01816 dst = DST_mk_variable(
01817 src,
01818 ST_name(var_st),
01819 type,
01820 0,
01821 ST_st_idx(var_st),
01822 DST_INVALID_IDX,
01823 FALSE,
01824 #ifndef KEY
01825 FALSE,
01826 #else
01827
01828 ST_sclass(var_st) == SCLASS_AUTO,
01829 #endif
01830 is_external,
01831 FALSE );
01832
01833
01834
01835 #ifndef KEY // moved above
01836 DST_INFO_IDX current_scope_idx =
01837 DST_get_context(DECL_CONTEXT(decl));
01838 #endif
01839
01840 #ifdef KEY
01841
01842 if (ST_name(var_st) != NULL && *ST_name(var_st) != '\0')
01843 #endif
01844 DST_append_child (current_scope_idx, dst);
01845 return dst;
01846
01847 }
01848
01849
01850
01851
01852
01853 static void
01854 DST_enter_param_vars(tree fndecl,tree parameter_list)
01855 {
01856 USRCPOS src;
01857 USRCPOS_srcpos(src) = Get_Srcpos();
01858
01859 struct mongoose_gcc_DST_IDX tree_parent_idx =
01860 DECL_DST_IDX(fndecl);
01861 DST_INFO_IDX parent;
01862 cp_to_dst_from_tree(&parent,&tree_parent_idx);
01863
01864
01865 tree pdecl = parameter_list;
01866
01867 for( ; pdecl; pdecl = TREE_CHAIN(pdecl)) {
01868 if(TREE_CODE_CLASS(TREE_CODE(pdecl)) != 'd') {
01869 DevWarn("parameter node not decl! tree node code %d ",
01870 TREE_CODE(pdecl));
01871 } else {
01872 DST_INFO_IDX param_idx;
01873 DST_INFO_IDX type_idx;
01874 BOOL is_artificial = FALSE;
01875
01876 ST * st = Get_ST(pdecl);
01877
01878
01879
01880 tree type = TREE_TYPE(pdecl);
01881 TY_IDX ty_idx = Get_TY(type);
01882
01883
01884 struct mongoose_gcc_DST_IDX ty_tree_idx
01885 = TYPE_DST_IDX(type);
01886
01887 cp_to_dst_from_tree(&type_idx,&ty_tree_idx);
01888
01889 char *name = Get_Name(pdecl);
01890
01891 param_idx = DST_mk_formal_parameter(
01892 src,
01893 name,
01894 type_idx,
01895 ST_st_idx(st),
01896 DST_INVALID_IDX,
01897 DST_INVALID_IDX,
01898 FALSE,
01899 FALSE,
01900 is_artificial,
01901 FALSE );
01902
01903 struct mongoose_gcc_DST_IDX decl_gcc_dst;
01904 cp_to_tree_from_dst(&decl_gcc_dst,¶m_idx);
01905
01906 DECL_DST_IDX(pdecl) = decl_gcc_dst;
01907
01908 DST_append_child(parent,param_idx);
01909 }
01910 }
01911 }
01912
01913
01914
01915
01916 DST_INFO_IDX
01917 DST_Create_Subprogram (ST *func_st,tree fndecl)
01918 {
01919 USRCPOS src;
01920 USRCPOS_srcpos(src) = Get_Srcpos();
01921 DST_INFO_IDX dst;
01922 DST_INFO_IDX ret_dst = DST_INVALID_IDX;
01923
01924 DST_INFO_IDX current_scope_idx = fndecl ?
01925 (DST_get_context(DECL_CONTEXT(fndecl))):
01926 comp_unit_idx;
01927
01928
01929
01930
01931 BOOL isprototyped = FALSE;
01932
01933
01934 if(Debug_Level >= 2 && fndecl) {
01935
01936 #ifndef KEY
01937 tree resdecl = DECL_RESULT(fndecl);
01938 tree restype = 0;
01939 if( resdecl) {
01940 restype = TREE_TYPE(resdecl);
01941 }
01942 #else
01943
01944
01945 tree restype = 0;
01946 if (TREE_TYPE(fndecl))
01947 restype = TREE_TYPE(TREE_TYPE(fndecl));
01948 #endif
01949 if(restype) {
01950 struct mongoose_gcc_DST_IDX ret_g_idx;
01951 TY_IDX itx = Get_TY(restype);
01952
01953
01954
01955 ret_g_idx = TYPE_DST_IDX(restype);
01956
01957 cp_to_dst_from_tree(&ret_dst,&ret_g_idx);
01958 }
01959
01960 tree type = TREE_TYPE(fndecl);
01961 if(type) {
01962 tree arg_types = TYPE_ARG_TYPES(type);
01963 if(arg_types) {
01964 isprototyped = TRUE;
01965 }
01966 }
01967 }
01968
01969
01970 dst = DST_mk_subprogram(
01971 src,
01972 ST_name(func_st),
01973 ret_dst,
01974 DST_INVALID_IDX,
01975 ST_st_idx(func_st),
01976 DW_INL_not_inlined,
01977 DW_VIRTUALITY_none,
01978 0,
01979 FALSE,
01980 isprototyped,
01981 #ifdef KEY
01982 FALSE,
01983 #endif
01984 ! ST_is_export_local(func_st) );
01985
01986 #if !defined(TARG_NVISA)
01987
01988 DST_RESET_assoc_fe (DST_INFO_flag(DST_INFO_IDX_TO_PTR(dst)));
01989 #endif
01990 DST_append_child (current_scope_idx, dst);
01991
01992
01993 struct mongoose_gcc_DST_IDX fn_dst_idx;
01994 cp_to_tree_from_dst(&fn_dst_idx,&dst);
01995
01996 if(fndecl) {
01997 DECL_DST_IDX(fndecl) = fn_dst_idx;
01998 }
01999
02000
02001
02002
02003 #ifndef KEY
02004 if(isprototyped) {
02005 #else
02006
02007
02008
02009
02010 if (fndecl && DECL_ARGUMENTS(fndecl)) {
02011 #endif
02012 tree parms = DECL_ARGUMENTS(fndecl);
02013 if(!parms) {
02014 DevWarn("impossible arg decls -- is empty?");
02015 } else {
02016 DST_enter_param_vars(fndecl, parms);
02017 }
02018
02019 }
02020
02021 return dst;
02022 }
02023
02024 DST_INFO_IDX
02025 DST_Get_Comp_Unit (void)
02026 {
02027 return comp_unit_idx;
02028 }
02029
02030
02031
02032
02033 void
02034 DST_build(int num_copts,
02035 char *copts[])
02036 {
02037 char *src_path, *comp_info;
02038
02039 dst_initialized = TRUE;
02040
02041
02042 DST_Init (NULL, 0);
02043
02044
02045
02046
02047
02048
02049
02050 if (Orig_Src_File_Name != NULL)
02051 {
02052 src_path = Orig_Src_File_Name;
02053 }
02054
02055
02056
02057
02058
02059
02060
02061
02062 if (Debug_Level > 0)
02063 {
02064 int host_name_length = 0;
02065
02066 current_host_dir = &cwd_buffer[0];
02067 #ifndef __MINGW32__
02068 if (gethostname(current_host_dir, MAXHOSTNAMELEN) == 0)
02069 {
02070
02071 host_name_length = strlen(current_host_dir);
02072 current_host_dir[host_name_length] = '.';
02073 if (getdomainname(¤t_host_dir[host_name_length+1],
02074 MAXHOSTNAMELEN-host_name_length) == 0)
02075 {
02076
02077 host_name_length += strlen(¤t_host_dir[host_name_length]);
02078 }
02079 }
02080 current_host_dir[host_name_length++] = ':';
02081 #endif
02082 current_working_dir = &cwd_buffer[host_name_length];
02083 }
02084 else
02085 {
02086 current_host_dir = NULL;
02087 current_working_dir = &cwd_buffer[0];
02088 }
02089 strcpy(current_working_dir, Get_Current_Working_Directory());
02090 #ifdef KEY
02091
02092 current_host_dir = current_working_dir;
02093 #endif
02094 if (current_working_dir == NULL) {
02095 perror("getcwd");
02096 exit(2);
02097 }
02098
02099
02100 #ifndef KEY
02101 comp_info = DST_get_command_line_options(num_copts, copts);
02102 #else
02103
02104 comp_info = (char *)malloc(sizeof(char)*100);
02105 #ifdef PSC_TO_OPEN64
02106 strcpy(comp_info, "opencc ");
02107 #endif
02108 if (INCLUDE_STAMP)
02109 strcat(comp_info, INCLUDE_STAMP);
02110 #endif
02111
02112 {
02113 comp_unit_idx = DST_mk_compile_unit((char*)dump_base_name,
02114 current_host_dir,
02115 comp_info,
02116 DW_LANG_C89,
02117 DW_ID_case_sensitive);
02118 }
02119
02120 free(comp_info);
02121
02122 #ifndef KEY
02123
02124
02125
02126 WFE_Set_Line_And_File (0, Orig_Src_File_Name);
02127 #endif
02128 }
02129
02130 void
02131 WFE_Set_Line_And_File (UINT line, const char *file)
02132 {
02133 if (!dst_initialized) return;
02134
02135
02136 char *dir;
02137 const char *file_name = drop_path(file);;
02138 char buf[256];
02139 if (file_name == file) {
02140
02141 #ifdef TARG_SL
02142
02143
02144
02145
02146 dir = NULL;
02147 }
02148 #else
02149 #ifdef TARG_NVISA
02150 dir = ".";
02151 #else
02152 dir = current_working_dir;
02153 #endif
02154 }
02155 else if (strncmp(file, "./", 2) == 0) {
02156
02157 #ifdef TARG_NVISA
02158 dir = ".";
02159 #else
02160 dir = current_working_dir;
02161 #endif
02162 }
02163 #endif //TARG_SL
02164 else {
02165
02166 strcpy (buf, file);
02167 dir = (char *) drop_path(buf);
02168 --dir;
02169 *dir = '\0';
02170 dir = buf;
02171 }
02172
02173 current_dir = Get_Dir_Dst_Info (dir);
02174 current_file = Get_File_Dst_Info (file_name, current_dir);
02175 }
02176
02177 #ifdef KEY
02178 void WFE_Macro_Define (UINT line, const char *buffer)
02179 {
02180 DST_mk_macr(line, (char *)buffer, 1 );
02181 return;
02182 }
02183
02184 void WFE_Macro_Undef (UINT line, const char *buffer)
02185 {
02186 DST_mk_macr(line, (char *)buffer, 2 );
02187 return;
02188 }
02189
02190 void WFE_Macro_Start_File (UINT line, UINT file)
02191 {
02192 DST_mk_macr_start_file(line, file);
02193 }
02194
02195 void WFE_Macro_End_File (void)
02196 {
02197 DST_mk_macr_end_file();
02198 }
02199 #endif