2
Copyright (c) 1994 - 2010, Lawrence Livermore National Security, LLC.
6
This file is part of Silo. For details, see silo.llnl.gov.
8
Redistribution and use in source and binary forms, with or without
9
modification, are permitted provided that the following conditions
12
* Redistributions of source code must retain the above copyright
13
notice, this list of conditions and the disclaimer below.
14
* Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the disclaimer (as noted
16
below) in the documentation and/or other materials provided with
18
* Neither the name of the LLNS/LLNL nor the names of its
19
contributors may be used to endorse or promote products derived
20
from this software without specific prior written permission.
22
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE
26
LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR
27
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
This work was produced at Lawrence Livermore National Laboratory under
36
Contract No. DE-AC52-07NA27344 with the DOE.
38
Neither the United States Government nor Lawrence Livermore National
39
Security, LLC nor any of their employees, makes any warranty, express
40
or implied, or assumes any liability or responsibility for the
41
accuracy, completeness, or usefulness of any information, apparatus,
42
product, or process disclosed, or represents that its use would not
43
infringe privately-owned rights.
45
Any reference herein to any specific commercial products, process, or
46
services by trade name, trademark, manufacturer or otherwise does not
47
necessarily constitute or imply its endorsement, recommendation, or
48
favoring by the United States Government or Lawrence Livermore
49
National Security, LLC. The views and opinions of authors expressed
50
herein do not necessarily state or reflect those of the United States
51
Government or Lawrence Livermore National Security, LLC, and shall not
52
be used for advertising or product endorsement purposes.
55
* PDB.H - header file supporting PDBLIB routines
58
* Software Release #92-0043
65
#include <setjmp.h> /* For the setjmp/long structure jmp_buf. */
67
#include "score.h" /* For type definitions */
69
/* The MAXLINE macro is defined in score.h and taken from stdio.h's */
70
/* FILENAME_MAX. HP's is only 14, so correct that here. */
81
#define PDB_SYSTEM_VERSION 14
82
#define PDB_WRITE /*Include code to write to pdb files*/
89
* Structure Chart Address
90
* Symbol Table Address
98
#define NORMAL_ORDER 1
99
#define REVERSE_ORDER 2 /* this must not be -1 which turns out to be EOF */
101
#define IEEE_32_64 1 /* IEEE standard 32 bit float : 64 bit double */
102
#define INTEL_X86 2 /* Intel 80x86 class machines */
103
#define CRAY_64 3 /* CRAY class machines */
104
#define VAX_11 4 /* VAX class machines */
105
#define IEEE_32_96 6 /* IEEE standard 32 bit float : 96 bit double */
106
#define NSTD 6 /* Number of standards currently in the system
107
should be same as last standard */
118
#define ROW_MAJOR_ORDER 101
119
#define COLUMN_MAJOR_ORDER 102
121
#define PF_ALPHABETIC 1
122
#define PF_DISK_ORDER 2
128
/*--------------------------------------------------------------------------*/
130
/*--------------------------------------------------------------------------*/
132
#define PN_sizeof(type, tab) _lite_PD_lookup_size(type, tab)
134
#define PD_get_mode(file) ((file)->mode)
135
#define PD_set_mode(file, v) (file)->mode = (v)
136
#define PD_get_offset(file) ((file)->default_offset)
137
#define PD_set_offset(file, v) (file)->default_offset = (v)
139
/* #define PD_file_maximum_size(file) file->maximum_size */
140
/* replaced by PD_get_max_file_size and PD_set_max_file_size below */
142
#define PD_get_max_file_size(file) ((file)->maximum_size)
143
#define PD_set_max_file_size(file, v) (file)->maximum_size = (v)
146
#define PD_entry_type(ep) ((ep)->type)
147
#define PD_entry_dimensions(ep) ((ep)->dimensions)
148
#define PD_entry_address(ep) ((ep)->blocks[0].diskaddr)
149
#define PD_entry_number(ep) ((ep)->number)
150
#define PD_entry_indirects(ep) ((ep)->indirects)
151
#define PD_entry_blocks(ep) ((ep)->blocks)
152
#define PD_block_address(ep, n) ((ep)->blocks[n].diskaddr)
153
#define PD_block_number(ep, n) ((ep)->blocks[n].number)
154
#define PD_n_blocks(ep) (lite_SC_arrlen((ep)->blocks)/sizeof(symblock))
156
#define PD_get_major_order(file) ((file)->major_order)
157
#define PD_set_major_order(file, type) (file)->major_order = (type)
159
#define PD_has_directories(file) \
160
(lite_SC_def_lookup("Directory", file->chart) != NULL)
162
#define PD_inquire_type(file, name) \
163
(defstr *) lite_SC_def_lookup(name, file->chart)
165
#define PD_inquire_host_type(file, name) \
166
(defstr *) lite_SC_def_lookup(name, file->host_chart)
168
#define PD_inquire_table_type(table, name) \
169
(defstr *) lite_SC_def_lookup(name, table)
171
#define PD_hyper_refp(name, commnd) \
172
{char c, s[MAXLINE]; \
174
c = s[strlen(s) - 1]; \
175
if ((c == ')') || (c == ']')) \
178
#define PD_hyper_ref(s, name) \
181
c = s[strlen(s) - 1]; \
182
if ((c == ')') || (c == ']')) \
183
{s[strlen(s) - 1] = '\0'; \
184
lite_SC_lasttok(s, "[]()");};}
186
#define PD_INQUIRE_ATTRIBUTE(x) \
187
((attribute *) lite_SC_def_lookup((x), file->attrtab))
189
#define PD_INQUIRE_ATTRIBUTE_VALUE(x) \
190
((attribute_value *) lite_SC_def_lookup((x), file->attrtab))
192
#define PD_CAST_TYPE(t, d, vg, vl, err_fnc, err_msg, err_arg) \
193
{if (d->cast_offs < 0L) \
196
{t = DEREF(vl + d->cast_offs); \
198
{if (DEREF(vg) != NULL) \
199
{err_fnc(err_msg, err_arg);} \
203
/*--------------------------------------------------------------------------*/
204
/* TYPEDEFS AND STRUCTS */
205
/*--------------------------------------------------------------------------*/
207
struct s_data_alignment {
213
int longlong_alignment;
215
int double_alignment;
216
int struct_alignment;
219
typedef struct s_data_alignment data_alignment;
222
struct s_data_standard {
240
typedef struct s_data_standard data_standard;
246
char *type; /* used by files masqerading as PDB */
251
long maximum_size; /* for file family bookkeeping */
252
char *previous_file; /* for file family bookkeeping */
256
data_standard *host_std;
257
data_alignment *align;
258
data_alignment *host_align;
259
char *current_prefix;
261
int virtual_internal;
270
typedef struct s_PDBfile PDBfile;
274
* Dimension descriptor - describe an array dimension range
275
* NOTE: changes here must be reflected in sxhook.c
281
struct s_dimdes *next;
284
typedef struct s_dimdes dimdes;
288
* Member descriptor - describe a member efficiently
289
* NOTE: changes here must be reflected in sxhook.c
301
struct s_memdes *next;
304
typedef struct s_memdes memdes;
307
* Symbol table entry block - manage discontiguous data items
308
* NOTE: changes here must be reflected in sxhook.c
315
typedef struct s_symblock symblock;
319
* Symbol table entry indirects
320
* NOTE: changes here must be reflected in sxhook.c
328
typedef struct s_symindir symindir;
332
* Symbol table entry - the def member of a hashel
333
* NOTE: changes here must be reflected in sxhook.c
343
typedef struct s_syment syment;
347
* Structure chart entry - the def member of a hashel
348
* NOTE: changes here must be reflected in sxhook.c
354
int alignment; /* type begins on byte boundary divisible by alignment */
355
int n_indirects; /* number of indirections */
357
int onescmp; /* TRUE iff ones complement arithmetic - old machines */
358
int unsgned; /* TRUE iff the integral type is unsigned */
365
typedef struct s_defstr defstr;
367
typedef memdes *(*PFPmemdes)() ;
368
typedef memdes *(*ReaderFuncType)(memdes *);
369
typedef memdes *(*WriterFuncType)(PDBfile *,char *,defstr *);
372
* Indirect reference tag.
375
long nitems; /* number of items pointed to */
376
char *type; /* type of item pointed to */
377
long addr; /* address of the itag owning data */
378
int flag; /* TRUE if this itag owns the data */
381
typedef struct s_PD_itag PD_itag;
385
* Hyper-index support structure
394
typedef struct s_dimind dimind;
405
typedef struct s_attribute attribute;
408
struct s_attribute_value {
411
struct s_attribute_value *next;
414
typedef struct s_attribute_value attribute_value;
418
* PD_IMAGE is a faithful shadow of the PG_image which is not defined yet
419
* any changes to PG_image must be reflected here
431
unsigned char *buffer;
439
typedef struct s_PD_image PD_image;
441
/*--------------------------------------------------------------------------*/
442
/* PDBLIB VARIABLES */
443
/*--------------------------------------------------------------------------*/
445
extern jmp_buf _lite_PD_close_err ;
446
extern jmp_buf _lite_PD_print_err ;
447
extern jmp_buf _lite_PD_read_err ;
448
extern jmp_buf _lite_PD_trace_err ;
449
extern char lite_PD_err[] ;
450
extern int lite_PD_buffer_size ;
451
extern int lite_FORMAT_FIELDS ;
452
extern data_standard lite_IEEEA_STD ;
453
extern data_standard lite_IEEEB_STD ;
454
extern data_standard lite_INTELA_STD ;
455
extern data_standard lite_CRAY_STD ;
456
extern data_standard lite_VAX_STD ;
457
extern data_standard lite_DEF_STD ;
458
extern data_standard *lite_INT_STANDARD ;
459
extern data_alignment lite_M68000_ALIGNMENT ;
460
extern data_alignment lite_INTELA_ALIGNMENT ;
461
extern data_alignment lite_UNICOS_ALIGNMENT ;
462
extern data_alignment lite_SPARC_ALIGNMENT ;
463
extern data_alignment lite_RS6000_ALIGNMENT ;
464
extern data_alignment lite_MIPS_ALIGNMENT ;
465
extern data_alignment lite_DEF_ALIGNMENT ;
466
extern data_alignment *lite_INT_ALIGNMENT ;
467
extern ReaderFuncType lite_pdb_rd_hook;
468
extern WriterFuncType lite_pdb_wr_hook;
471
/*--------------------------------------------------------------------------*/
472
/* PDBLIB FUNCTIONS */
473
/*--------------------------------------------------------------------------*/
475
SILO_API extern int lite_PD_cd (PDBfile*,char*);
476
SILO_API extern int lite_PD_close (PDBfile*);
477
SILO_API extern int lite_PD_convert (char**,char**,char*,char*,long,
478
data_standard*,data_standard*,
479
data_standard*,long*,long*,HASHTAB*,
481
SILO_API extern dimdes *lite_PD_copy_dims (dimdes*);
482
SILO_API extern memdes *lite_PD_copy_members (memdes*);
483
SILO_API extern syment *lite_PD_copy_syment (syment*);
484
SILO_API extern defstr *lite_PD_defncv (PDBfile*,char*,long,int);
485
SILO_API extern char * lite_PD_dereference (char*);
486
SILO_API extern void lite_PD_error (char*,int);
487
SILO_API extern byte * lite_PD_get_attribute (PDBfile*,char*,char*);
488
SILO_API extern long lite_PD_hyper_number (PDBfile*,char*,syment*);
489
SILO_API extern syment *lite_PD_inquire_entry (PDBfile*,char*,int,char*);
490
SILO_API extern char ** lite_PD_ls (PDBfile*,char*,char*,int*);
491
SILO_API extern PDBfile *lite_PD_open (char*,char*);
492
SILO_API extern char * lite_PD_pwd (PDBfile*);
493
SILO_API extern int lite_PD_read (PDBfile*,char*,byte*);
494
SILO_API extern int lite_PD_read_alt (PDBfile*,char*,byte*,long*);
495
SILO_API extern int lite_PD_read_as (PDBfile*,char*,char*,byte*);
496
SILO_API extern int lite_PD_read_as_alt (PDBfile*,char*,char*,byte*,long*);
497
SILO_API extern defstr *lite_PD_typedef (PDBfile*,char*,char*);
498
extern int _lite_PD_align (long,char*,HASHTAB*,int*);
499
extern void _lite_PD_check_casts (HASHTAB*,char**,long);
500
extern void _lite_PD_clr_table (HASHTAB*,FreeFuncType);
501
extern long _lite_PD_comp_num (dimdes*);
502
extern int _lite_PD_compare_std (data_standard*,data_standard*,
503
data_alignment*,data_alignment*);
504
extern int _lite_PD_convert (char**,char**,long,int,defstr*,
505
defstr*,data_standard*,long*,long*);
506
extern void _lite_PD_convert_ascii (char*,char*,long,int,int);
507
extern data_alignment * _lite_PD_copy_alignment (data_alignment*);
508
extern data_standard * _lite_PD_copy_standard (data_standard*);
509
extern void _lite_PD_d_install (char*,defstr*,HASHTAB*);
510
extern defstr * _lite_PD_defstr_inst (char*,memdes*,int,int*,long*,
513
data_alignment*,int);
514
extern void _lite_PD_e_install (char*,syment*,HASHTAB*);
515
extern syment * _lite_PD_effective_ep (PDBfile*,char*,int,char*);
516
extern dimdes * _lite_PD_ex_dims (char*,int,int);
517
extern long _lite_PD_extract_field (char*,int,int,int,int*);
518
extern void _lite_PD_fconvert (char**,char**,long,int,long*,int*,
519
long*,int*,int,int,int);
520
extern char * _lite_PD_fixname (PDBfile*,char*);
521
extern long _lite_PD_hyper_number (PDBfile*,char*,long,dimdes*,
523
extern int _lite_PD_hyper_read (PDBfile*,char*,char*,syment*,
525
extern void _lite_PD_iconvert (char**,char**,long,long,int,long,
527
extern int _lite_PD_indexed_read_as (PDBfile*,char*,char*,byte*,
529
extern int _lite_PD_indirection (char*);
530
extern void _lite_PD_init_chrt (PDBfile*);
531
extern void _lite_PD_init_dimind (dimind*,long,long,char*);
532
extern long _lite_PD_lookup_size (char*,HASHTAB*);
533
extern defstr * _lite_PD_lookup_type (char*,HASHTAB*);
534
extern char * _lite_PD_member_base_type (char*);
535
extern long _lite_PD_member_items (char*);
536
extern long _lite_PD_member_location (char*,HASHTAB*,defstr*,
538
extern char * _lite_PD_member_name (char*);
539
extern char * _lite_PD_member_type (char*);
540
extern data_alignment * _lite_PD_mk_alignment (char*);
541
extern defstr * _lite_PD_mk_defstr (char*,memdes*,long,int,int,int,
543
extern memdes * _lite_PD_mk_descriptor (char*,int);
544
extern dimdes * _lite_PD_mk_dimensions (long,long);
545
extern PDBfile * _lite_PD_mk_pdb (char*);
546
extern data_standard * _lite_PD_mk_standard (void);
547
extern syment * _lite_PD_mk_syment (char*,long,long,symindir*,dimdes*);
548
extern int _lite_PD_null_pointer (char*,int);
549
extern int _lite_PD_pio_close (FILE*);
550
extern int _lite_PD_pio_printf (FILE*,char*,...);
551
extern int _lite_PD_pio_seek (FILE*,long,int);
552
extern int _lite_PD_prim_typep (char*,HASHTAB*,int);
553
extern int _lite_PD_rd_chrt (PDBfile*);
554
extern int _lite_PD_rd_extras (PDBfile*);
555
extern int _lite_PD_rd_format (PDBfile*);
556
extern int _lite_PD_rd_itag (PDBfile*,PD_itag*);
557
extern void _lite_PD_rd_prim_extras (PDBfile*,int,int,char*);
558
extern long _lite_PD_rd_syment (PDBfile*,syment*,char*,byte*);
559
extern int _lite_PD_rd_symt (PDBfile*);
560
extern char * _lite_PD_rfgets (char*,int,FILE*);
561
extern void _lite_PD_rl_alignment (data_alignment*);
562
extern void _lite_PD_rl_defstr (defstr*);
563
extern void _lite_PD_rl_descriptor (memdes*);
564
extern void _lite_PD_rl_dimensions (dimdes*);
565
extern void _lite_PD_rl_pdb (PDBfile*);
566
extern void _lite_PD_rl_standard (data_standard*);
567
extern void _lite_PD_rl_syment (syment*);
568
extern void _lite_PD_rl_syment_d (syment*);
569
extern void _lite_PD_setup_chart (HASHTAB*,data_standard*,
570
data_standard*,data_alignment*,
571
data_alignment*,int);
572
extern long _lite_PD_skip_over (PDBfile*,long,int);
573
extern long _lite_PD_str_size (memdes*,HASHTAB*);
574
extern int _lite_PD_unp_bits (char*,char*,int,int,int,int,long,
577
/* added 26Feb08 as per request from Burl Hall */
578
SILO_API extern int lite_PD_entry_number(syment*);
579
SILO_API extern long lite_PD_get_file_length(PDBfile *file);
581
extern char *lite_PD_SYMENT_S;
582
extern char *lite_PD_DEFSTR_S;
585
SILO_API extern int lite_PD_mkdir (PDBfile*,char*);
586
SILO_API extern int lite_PD_write (PDBfile*,char*,char*,byte*);
587
SILO_API extern int lite_PD_write_as (PDBfile*,char*,char*,char*,byte*);
588
SILO_API extern int lite_PD_write_alt (PDBfile*,char*,char*,byte*,int,
590
SILO_API extern int lite_PD_write_as_alt (PDBfile*,char*,char*,char*,byte*,
592
SILO_API extern PDBfile *lite_PD_create (char*);
593
extern int _lite_PD_adj_dimensions (PDBfile*,char*,syment*);
594
extern int _lite_PD_add_block (PDBfile*,syment*,dimdes*);
595
extern int _lite_PD_hyper_write (PDBfile*,char*,syment*,byte*,
597
extern void _lite_PD_convert_attrtab (PDBfile*);
598
extern int _lite_PD_wr_format (PDBfile*);
599
SILO_API extern defstr *lite_PD_defstr (PDBfile*,char*,...);
600
SILO_API extern int lite_PD_cast (PDBfile*,char*,char*,char*);
601
extern int _lite_PD_extend_file (PDBfile*,long);
602
extern long _lite_PD_wr_syment (PDBfile*,char*,long,char*,char*);
603
extern long _lite_PD_number_refd (byte*,char*,HASHTAB*);
604
extern int _lite_PD_wr_itag (PDBfile*,long,char*,long,int);
605
extern void _lite_PD_eod (PDBfile*);
606
SILO_API extern int lite_PD_target (data_standard*,data_alignment*);
607
SILO_API extern int lite_PD_flush (PDBfile*);
608
extern long _lite_PD_wr_chrt (PDBfile*);
609
extern long _lite_PD_wr_symt (PDBfile*);
610
extern int _lite_PD_wr_extras (PDBfile*);
611
extern int _lite_PD_rev_chrt (PDBfile*);
612
extern void _lite_PD_wr_prim_extras (FILE*,HASHTAB*,int,int);
613
SILO_API extern syment *lite_PD_defent_alt (PDBfile*,char*,char*,int,long*);
614
extern syment *_lite_PD_defent (PDBfile*,char*,char*,long,dimdes*);
616
/* added 26Feb08 as per request from Burl Hall */
617
SILO_API extern int lite_PD_append_alt(PDBfile*,char*,void*,int,long*);
618
SILO_API extern void lite_PD_set_major_order(PDBfile*,int);
619
#endif /* PDB_WRITE */