Ticket #254: tt254-64bit-pbc.patch

File tt254-64bit-pbc.patch, 49.9 KB (added by rurban, 13 years ago)
  • include/parrot/packfile.h

    old new  
    11/* 
    2  * Copyright (C) 2001-2007, Parrot Foundation 
     2 * Copyright (C) 2001-2009, Parrot Foundation 
    33 */ 
    44 
    55/* packfile.h 
     
    3030#define FLOATTYPE_12_NAME     "x86 little endian 12 byte long double" 
    3131#define FLOATTYPE_16          2 
    3232#define FLOATTYPE_16_NAME     "IEEE-754 16 byte long double" 
     33/* Supported until here. */ 
    3334#define FLOATTYPE_MAX         2 
    34 /* Unsupported NaN difference, but patches welcome */ 
     35/* Non IEEE-754 versions, yet unsupported. */ 
     36/* NaN difference, but patches welcome */ 
    3537#define FLOATTYPE_16MIPS      3 
    3638#define FLOATTYPE_16MIPS_NAME "MIPS 16 byte long double" 
    3739/* See http://www.ncsa.uiuc.edu/UserInfo/Resources/Hardware/IBMp690/IBM/usr/share/man/info/en_US/a_doc_lib/aixprggd/genprogc/128bit_long_double_floating-point_datatype.htm */ 
    3840#define FLOATTYPE_16AIX       4 
    39 #define FLOATTYPE_16AIX_NAME "AIX 16 byte long double" 
    40 /* Not yet set into silicon AFAIK */ 
    41 #define FLOATTYPE_32          5 
    42 #define FLOATTYPE_32_NAME     "256-bit extended double" 
     41#define FLOATTYPE_16AIX_NAME  "AIX 16 byte long double" 
     42/* IEEE-754 old and tiny, yet unsupported */ 
     43#define FLOATTYPE_4           5 
     44#define FLOATTYPE_4_NAME      "4-byte float" 
    4345 
    44 #define TRACE_PACKFILE 0 
     46#define TRACE_PACKFILE 2 
    4547 
    4648#if TRACE_PACKFILE 
    4749/* Here we pass multipe args to a macro so the args may not be bracketed here! */ 
    48 #  define TRACE_PRINTF(args)       if (pf->options) Parrot_trace_eprintf args 
     50#  define TRACE_PRINTF(args)       if (pf->options & 2) Parrot_trace_eprintf args 
     51#  define TRACE_PRINTF_ALIGN(args) if (pf->options & 4) Parrot_trace_eprintf args 
    4952#  if TRACE_PACKFILE == 2 
    50 #    define TRACE_PRINTF_VAL(args) if (pf->options & 2) Parrot_trace_eprintf args 
     53#    define TRACE_PRINTF_VAL(args) if (pf->options & 8) Parrot_trace_eprintf args 
    5154#    define TRACE_PRINTF_2(args)   Parrot_trace_eprintf args 
    5255#  else 
    5356#    define TRACE_PRINTF_VAL(args) 
     
    5659#else 
    5760#  define TRACE_PRINTF(args) 
    5861#  define TRACE_PRINTF_VAL(args) 
     62#  define TRACE_PRINTF_ALIGN(args) 
    5963#  define TRACE_PRINTF_2(args) 
    6064#endif 
    6165 
     66#if TRACE_PACKFILE && (PARROT_PTR_ALIGNMENT > 1) 
     67/* TT #364 Check if cursor is ptr_alignment aligned */ 
     68#  define CHECK_PTR_ALIGNMENT(ptr, where) \ 
     69    if (PTR2INTVAL(ptr) & (PARROT_PTR_ALIGNMENT - 1)) { \ 
     70        TRACE_PRINTF_2(("Warning: Misaligned cursor ptr %x at %s\n", (ptr), (where))); \ 
     71    } 
     72#else 
     73#  define CHECK_PTR_ALIGNMENT(ptr, where) \ 
     74    PARROT_ASSERT((PTR2INTVAL(ptr) & (PARROT_PTR_ALIGNMENT - 1)) == 0) 
     75#endif 
     76 
    6277/* 
    6378** Structure Definitions: 
    6479*/ 
  • src/pbc_dump.c

    old new  
    99=head1 SYNOPSIS 
    1010 
    1111 pbc_dump [-tdh] [--terse|--disassemble|--header-only] file.pbc 
     12 pbc_dump --debug|-D <2-14> file.pbc 
    1213 
    1314 pbc_dump -o converted.pbc file.pbc 
    1415 
     
    3233 
    3334Terse output. 
    3435 
    35 =item C<-e> C--debug> 
     36=item C<-D> C<--debug> value 
    3637 
    3738Display detailed packfile reader debugging information if 
    38 F<include/parrot/packfile.h> enables TRACE_PACKFILE 
     39F<include/parrot/packfile.h> enables TRACE_PACKFILE. 
     40 
     41  2  print general debug info 
     42  4  print alignment info 
     43  8  print values 
    3944 
    4045=item C<-o converted.pbc> 
    4146 
     
    156161    Parrot_io_printf(interp, "\tparrot-version %d.%d.%d, bytecode-version %d.%d\n", 
    157162                     pf->header->major, pf->header->minor, pf->header->patch, 
    158163                     pf->header->bc_major, pf->header->bc_minor); 
    159     Parrot_io_printf(interp, "\tUUID type = %d, UUID size = %d\n", 
     164    Parrot_io_printf(interp, "\tUUID: type = %d, size = %d", 
    160165                     pf->header->uuid_type, pf->header->uuid_size); 
     166    if (pf->header->uuid_data) 
     167        Parrot_io_printf(interp, ", '%s'\n", pf->header->uuid_data); 
     168    else 
     169        Parrot_io_printf(interp, "\n"); 
    161170    Parrot_io_printf(interp, "\t%s endianize, %s opcode, %s numval transform\n", 
    162171            pf->need_endianize ? "**need**" : "no", 
    163172            pf->need_wordsize ? "**need**" : "no", 
     
    186195    printf("\t-h ... dump header only\n"); 
    187196    printf("\t-t ... terse output\n"); 
    188197#if TRACE_PACKFILE 
    189     printf("\t--debug debug output\n"); 
     198    printf("\t-D<2-14> --debug debug output\n"); 
     199    printf("\t   2 general info\n"); 
     200    printf("\t   4 alignment\n"); 
     201    printf("\t   8 values\n"); 
    190202#endif 
    191203    printf("\n\t-o converted.pbc repacks a PBC file into " 
    192204           "the platform's native\n"); 
     
    200212    { '?', '?', OPTION_optional_FLAG, { "--help" } }, 
    201213    { 't', 't', OPTION_optional_FLAG, { "--terse" } }, 
    202214    { 'd', 'd', OPTION_optional_FLAG, { "--disassemble" } }, 
    203     { 'e', 'e', OPTION_optional_FLAG, { "--debug" } }, 
     215    { 'D', 'D', OPTION_required_FLAG, { "--debug" } }, 
    204216    { 'o', 'o', OPTION_required_FLAG, { "--output" } } 
    205217}; 
    206218 
     
    224236    int disas = 0; 
    225237    int convert = 0; 
    226238    int header = 0; 
    227     int debug = 0; 
     239    int debug = 1; /* parrot_utils continue on version/UUID mismatches */ 
    228240    const char *file = NULL; 
    229241    struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; 
    230242    int status; 
     
    247259            case 'd': 
    248260                disas = 1; 
    249261                break; 
    250             case 'e': 
    251                 debug = 1; 
     262            case 'D': 
     263                debug += (atoi(opt.opt_arg) | 1) - 1; 
    252264                break; 
    253265            case 'o': 
    254266                file = opt.opt_arg; 
  • src/packfile.c

    old new  
    147147PARROT_CANNOT_RETURN_NULL 
    148148static const opcode_t * directory_unpack(PARROT_INTERP, 
    149149    ARGMOD(PackFile_Segment *segp), 
    150     ARGIN(const opcode_t *cursor)) 
     150    ARGMOD(opcode_t *cursor)) 
    151151        __attribute__nonnull__(1) 
    152152        __attribute__nonnull__(2) 
    153153        __attribute__nonnull__(3) 
    154         FUNC_MODIFIES(*segp); 
     154        FUNC_MODIFIES(*segp) 
     155        FUNC_MODIFIES(*cursor); 
    155156 
    156157PARROT_WARN_UNUSED_RESULT 
    157158PARROT_CAN_RETURN_NULL 
     
    452453    extern int Parrot_exec_run; 
    453454#endif 
    454455 
    455 /* TODO: This is broken on 64/32 transformations. See TT #254 */ 
    456 #define ROUND_16(val) (((val) & 0xf) ? 16 - ((val) & 0xf) : 0) 
    457 #define ALIGN_16(st, cursor) \ 
    458     (cursor) += ROUND_16((const char *)(cursor) - (const char *)(st))/sizeof (opcode_t) 
     456/* pad to 16 in bytes */ 
     457#define PAD_16_B(size)        ((size) % 16 ? 16 - (size) % 16 : 0) 
     458/* offset from pf->src not in ptr diff, but in byte */ 
     459#define OFFS(cursor) ((const char *)(cursor) - (const char *)(pf->src)) 
     460 
    459461 
    460462#if TRACE_PACKFILE 
    461463void 
     
    933935    self->src  = packed; 
    934936    self->size = packed_size; 
    935937 
    936     /* Extract the header. */ 
     938    /* Extract the header, up to excluding uuid_data */ 
    937939    memcpy(header, packed, PACKFILE_HEADER_BYTES); 
    938940 
    939941    /* Ensure the magic is correct. */ 
     
    953955        Parrot_io_eprintf(NULL, "PackFile_unpack: This Parrot cannot read " 
    954956            "bytecode files with version %d.%d.\n", 
    955957            header->bc_major, header->bc_minor); 
    956         return 0; 
     958        if (!(pf->options & 1)) 
     959            return 0; 
    957960    } 
    958961 
    959962    /* Check wordsize, byte order and floating point number type are valid. */ 
     
    976979    } 
    977980 
    978981    /* Describe what was read for debugging. */ 
    979     TRACE_PRINTF(("PackFile_unpack: Wordsize %d.\n", header->wordsize)); 
     982    TRACE_PRINTF(("PackFile_unpack: Wordsize  %d.\n", header->wordsize)); 
    980983    TRACE_PRINTF(("PackFile_unpack: Floattype %d (%s).\n", 
    981984                  header->floattype, 
    982985                  header->floattype == FLOATTYPE_8 
     
    986989                          : FLOATTYPE_12_NAME)); 
    987990    TRACE_PRINTF(("PackFile_unpack: Byteorder %d (%sendian).\n", 
    988991                  header->byteorder, header->byteorder ? "big " : "little-")); 
     992    TRACE_PRINTF(("PackFile_unpack: parrot version %d.%d.%d", 
     993                  header->major, header->minor, header->patch)); 
     994    TRACE_PRINTF((", bc_version %d.%d\n", 
     995                  header->bc_major, header->bc_minor)); 
     996    TRACE_PRINTF(("PackFile_unpack: uuid: type=%d, size=%d\n", 
     997                  header->uuid_type, header->uuid_size)); 
    989998 
    990999    /* Check the UUID type is valid and, if needed, read a UUID. */ 
    9911000    if (header->uuid_type == 0) { 
    9921001        /* No UUID; fine, nothing more to do. */ 
    9931002    } 
    994     else if (header->uuid_type == 1) { 
     1003    else if (header->uuid_type == 1 && header->uuid_size) { 
    9951004        /* Read in the UUID. We'll put it in a NULL-terminated string, just in 
    996          * case pepole use it that way. */ 
     1005         * case people use it that way. */ 
    9971006        header->uuid_data = (unsigned char *) 
    9981007            mem_sys_allocate(header->uuid_size + 1); 
    9991008 
    1000         memcpy(header->uuid_data, packed + PACKFILE_HEADER_BYTES, 
    1001             header->uuid_size); 
     1009        memcpy(header->uuid_data, packed + 
     1010               (PACKFILE_HEADER_BYTES/sizeof (opcode_t *)), 
     1011               header->uuid_size); 
    10021012 
    10031013        /* NULL terminate */ 
    10041014        header->uuid_data[header->uuid_size] = 0; 
     1015 
     1016        TRACE_PRINTF_VAL(("PackFile_unpack: uuid_data='%s'\n", header->uuid_data)); 
     1017        /* TODO TT #359. compare computed UUID and fail */ 
    10051018    } 
    1006     else 
     1019    else { 
    10071020        /* Don't know this UUID type. */ 
    10081021        Parrot_io_eprintf(NULL, "PackFile_unpack: Invalid UUID type %d\n", 
    10091022                    header->uuid_type); 
     1023        if (!(pf->options & 1)) 
     1024            return 0; 
     1025    } 
    10101026 
    10111027    /* Set cursor to position after what we've read, allowing for padding to a 
    10121028     * 16 byte boundary. */ 
    10131029    header_read_length  = PACKFILE_HEADER_BYTES + header->uuid_size; 
    1014     header_read_length += header_read_length % 16 ? 
    1015         16 - header_read_length % 16 : 0; 
     1030    header_read_length += PAD_16_B(header_read_length); 
    10161031    cursor              = packed + (header_read_length / sizeof (opcode_t)); 
     1032    TRACE_PRINTF(("PackFile_unpack: pad=%d\n", 
     1033                  cursor - packed)); 
    10171034 
    10181035    /* Set what transforms we need to do when reading the rest of the file. */ 
    10191036    PackFile_assign_transforms(self); 
     
    12441261    header->floattype = FLOATTYPE_16; 
    12451262#    else 
    12461263    exit_fatal(1, "PackFile_set_header: Unsupported floattype NUMVAL_SIZE=%d," 
    1247                " PARROT_BIGENDIAN=%d\n", NUMVAL_SIZE, 
    1248                PARROT_BIGENDIAN ? "big-endian" : "little-endian"); 
     1264               " PARROT_BIGENDIAN=%s\n", 
     1265               NUMVAL_SIZE, PARROT_BIGENDIAN ? "big-endian" : "little-endian"); 
    12491266#    endif 
    12501267#  endif 
    12511268#endif 
     
    14401457    } 
    14411458    else { 
    14421459        int i; 
     1460        /* XXX What are we doing here? */ 
     1461        TRACE_PRINTF(("default_unpack: pre-fetch %d ops into data\n", 
     1462                      self->size)); 
    14431463        for (i = 0; i < (int)self->size; i++) { 
    14441464            self->data[i] = PF_fetch_opcode(self->pf, &cursor); 
    1445             TRACE_PRINTF(("default_unpack: transformed op[#%d]/%d %u\n", 
     1465            TRACE_PRINTF(("default_unpack: transformed op[#%d]/%d %lu\n", 
    14461466                          i, self->size, self->data[i])); 
    14471467        } 
    14481468    } 
     
    17071727 
    17081728=item C<void PackFile_Segment_destroy> 
    17091729 
    1710 Destroys the given PackFile_Segment. 
     1730Call the segment registered destroy_func and then destroy the segment self. 
    17111731 
    17121732=cut 
    17131733 
     
    17901810 
    17911811    if (align && (cursor - self->pf->src) % align) 
    17921812        cursor += align - (cursor - self->pf->src) % align; 
     1813    CHECK_PTR_ALIGNMENT(cursor, "PackFile_Segment_pack"); 
    17931814 
    17941815    return cursor; 
    17951816} 
     
    18181839        ARGIN(const opcode_t *cursor)) 
    18191840{ 
    18201841    ASSERT_ARGS(PackFile_Segment_unpack) 
     1842    int offs; 
    18211843    PackFile_Segment_unpack_func_t f = self->pf->PackFuncs[self->type].unpack; 
    1822 #if TRACE_PACKFILE 
    18231844    PackFile * const pf  = self->pf; 
    1824 #endif 
    18251845 
    18261846    cursor = default_unpack(self, cursor); 
    18271847 
     
    18331853 
    18341854        cursor = (f)(interp, self, cursor); 
    18351855        TRACE_PRINTF_VAL(("  PackFile_Segment_unpack: offset=0x%x\n", 
    1836                           pf->src - cursor)); 
     1856                          OFFS(cursor))); 
    18371857 
    18381858        if (!cursor) 
    18391859            return NULL; 
    18401860    } 
    18411861 
    1842     TRACE_PRINTF_VAL(("pre-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
    1843                       pf->src - cursor, pf->src, cursor)); 
    1844  
    1845     /* FIXME on 64bit reading 32bit */ 
    1846     ALIGN_16(self->pf->src, cursor); 
    1847     TRACE_PRINTF_VAL(("ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
    1848                       pf->src - cursor, pf->src, cursor)); 
     1862    offs = OFFS(cursor); 
     1863    TRACE_PRINTF_ALIGN(("-S ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
     1864                        offs, pf->src, cursor)); 
     1865    offs += PAD_16_B(offs); 
     1866    cursor = (const char *)(pf->src) + offs; 
     1867    TRACE_PRINTF_ALIGN(("+S ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
     1868                        offs, pf->src, cursor)); 
     1869    CHECK_PTR_ALIGNMENT(cursor, "PackFile_Segment_unpack"); 
    18491870    return cursor; 
    18501871} 
    18511872 
     
    19501971PARROT_WARN_UNUSED_RESULT 
    19511972PARROT_CANNOT_RETURN_NULL 
    19521973static const opcode_t * 
    1953 directory_unpack(PARROT_INTERP, ARGMOD(PackFile_Segment *segp), ARGIN(const opcode_t *cursor)) 
     1974directory_unpack(PARROT_INTERP, ARGMOD(PackFile_Segment *segp), ARGMOD(opcode_t *cursor)) 
    19541975{ 
    19551976    ASSERT_ARGS(directory_unpack) 
    19561977    PackFile_Directory * const dir = (PackFile_Directory *) segp; 
    19571978    PackFile           * const pf  = dir->base.pf; 
    19581979    const opcode_t            *pos; 
    19591980    size_t                     i; 
     1981    int                        offs; 
    19601982 
    19611983    dir->num_segments = PF_fetch_opcode(pf, &cursor); 
    19621984    TRACE_PRINTF(("directory_unpack: %ld num_segments\n", dir->num_segments)); 
     
    20022024                return 0; 
    20032025            } 
    20042026            TRACE_PRINTF_VAL(("Segment offset: new pos 0x%x " 
    2005                 "(src=0x%x cursor=0x%x).\n", pos - pf->src, pf->src, cursor)); 
     2027                              "(src=0x%x cursor=0x%x).\n", 
     2028                              OFFS(pos), pf->src, cursor)); 
    20062029        } 
    20072030        else 
    20082031            pos = pf->src + seg->file_offset; 
     
    20292052        seg->dir         = dir; 
    20302053    } 
    20312054 
    2032     TRACE_PRINTF_VAL(("pre-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
    2033                       pf->src - cursor, pf->src, cursor)); 
    2034  
    2035     /* FIXME on 64bit reading 32bit */ 
    2036     ALIGN_16(pf->src, cursor); 
    2037     TRACE_PRINTF_VAL(("ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
    2038                       pf->src - cursor, pf->src, cursor)); 
     2055    offs = OFFS(cursor); 
     2056    TRACE_PRINTF_ALIGN(("-D ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
     2057                        offs, pf->src, cursor)); 
     2058    offs += PAD_16_B(offs); 
     2059    cursor = (const char *)(pf->src) + offs; 
     2060    TRACE_PRINTF_ALIGN(("+D ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
     2061                        offs, pf->src, cursor)); 
     2062    CHECK_PTR_ALIGNMENT(cursor, "directory_unpack"); 
    20392063 
    20402064    /* and now unpack contents of dir */ 
    20412065    for (i = 0; cursor && i < dir->num_segments; i++) { 
     
    20572081            return 0; 
    20582082        } 
    20592083        else { 
    2060             TRACE_PRINTF_VAL(("PackFile_Segment_unpack ok. pos=0x%x\n", pos)); 
     2084            TRACE_PRINTF_VAL(("directory_unpack ok. pos=0x%x\n", OFFS(pos))); 
    20612085        } 
    20622086 
    2063         /* BUG: on 64bit reading 32bit lurking here! */ 
    20642087        if (pf->need_wordsize) { 
    20652088#if OPCODE_T_SIZE == 8 
    20662089            if (pf->header->wordsize == 4) 
     
    20732096        else 
    20742097            delta = pos - cursor; 
    20752098 
    2076         TRACE_PRINTF_VAL(("  delta=%d pos=0x%x cursor=0x%x\n", 
     2099        TRACE_PRINTF_VAL(("  delta=%d, pos=0x%x cursor=0x%x\n", 
    20772100                          delta, pos, cursor)); 
    20782101 
    20792102        if ((size_t)delta != tmp || dir->segments[i]->op_count != tmp) 
    2080             fprintf(stderr, "PackFile_unpack segment '%s' directory length %d " 
    2081                     "length in file %d needed %d for unpack\n", 
     2103            fprintf(stderr, "PackFile_unpack segment '%s' directory length %d. " 
     2104                    "length in file %d, needed %d for unpack\n", 
    20822105                    dir->segments[i]->name, 
    20832106                    (int)dir->segments[i]->op_count, (int)tmp, 
    20842107                    (int)delta); 
    20852108        cursor = pos; 
    20862109    } 
     2110    CHECK_PTR_ALIGNMENT(cursor, "directory_unpack after padding"); 
    20872111 
    20882112    return cursor; 
    20892113} 
     
    22482272 
    22492273    if (align && (cursor - self->pf->src) % align) 
    22502274        cursor += align - (cursor - self->pf->src) % align; 
     2275    CHECK_PTR_ALIGNMENT(cursor, "directory_pack after padding"); 
    22512276 
    22522277    /* now pack all segments into new format */ 
    22532278    for (i = 0; i < dir->num_segments; i++) { 
     
    32323257    opcode_t i; 
    32333258 
    32343259    *cursor++ = ft->fixup_count; 
     3260    CHECK_PTR_ALIGNMENT(cursor, "fixup_pack fixup_count"); 
    32353261 
    32363262    for (i = 0; i < ft->fixup_count; i++) { 
    32373263        *cursor++ = (opcode_t) ft->fixups[i]->type; 
     
    33493375                return NULL; 
    33503376        } 
    33513377    } 
     3378    CHECK_PTR_ALIGNMENT(cursor, "fixup_unpack"); 
    33523379 
    33533380    return cursor; 
    33543381} 
     
    37913818 
    37923819    TRACE_PRINTF(("PackFile_Constant_unpack(): Type is %ld ('%c')...\n", 
    37933820                  type, (char)type)); 
     3821    CHECK_PTR_ALIGNMENT(cursor, "PackFile_Constant_unpack"); 
    37943822 
    37953823    switch (type) { 
    37963824        case PFC_NUMBER: 
     
    38493877    /* thawing the PMC needs the real packfile in place */ 
    38503878    PackFile_ByteCode * const cs_save = interp->code; 
    38513879    interp->code                      = pf->cur_cs; 
     3880    CHECK_PTR_ALIGNMENT(cursor, "PackFile_Constant_unpack_pmc"); 
    38523881    image                             = PF_fetch_string(interp, pf, &cursor); 
    38533882 
    38543883    /* 
    38553884     * TODO use thaw_constants 
    38563885     * current issue: a constant Sub with attached properties 
    38573886     *                doesn't GC mark the properties 
    3858      * for a constant PMC *all* contents have to be in the constant pools 
     3887     * for a constant PMC *all* contents have to be in the constant pools. 
    38593888     */ 
    38603889    pmc         = Parrot_thaw(interp, image); 
    3861  
    38623890    /* place item in const_table */ 
    38633891    self->type  = PFC_PMC; 
    38643892    self->u.key = pmc; 
     
    40784106 
    40794107    /* Write key count and any keys. */ 
    40804108    *cursor++ = self->num_keys; 
     4109    CHECK_PTR_ALIGNMENT(cursor, "PackFile_Annotations_pack"); 
    40814110 
    40824111    for (i = 0; i < self->num_keys; i++) { 
    40834112        *cursor++ = self->keys[i]->name; 
    40844113        *cursor++ = self->keys[i]->type; 
    40854114    } 
     4115    CHECK_PTR_ALIGNMENT(cursor, "PackFile_Annotations_pack keys"); 
    40864116 
    40874117    /* Write group count and any groups. */ 
    40884118    *cursor++ = self->num_groups; 
     
    41324162    /* Unpack keys. */ 
    41334163    self->num_keys = PF_fetch_opcode(seg->pf, &cursor); 
    41344164 
     4165    CHECK_PTR_ALIGNMENT(cursor, "PackFile_Annotations_unpack"); 
    41354166    TRACE_PRINTF(("PackFile_Annotations_unpack: Unpacking %ld keys\n", 
    41364167                  self->num_keys)); 
    41374168 
  • src/embed.c

    old new  
    381381 
    382382Read in a bytecode, unpack it into a C<PackFile> structure, and do fixups. 
    383383 
     384C<options> are passed to the packfile reader. 
     385 
     386  0   strict,  fails on version or UUID mismatch (parrot). 
     387  1   relaxed, warns on version or UUID mismatch (parrot_utils). 
     388  2++ --debug cmdline options, only when packfile.h has TRACE_PACKFILE set. 
     389     2 TRACE_PRINTF 
     390     4 TRACE_PRINTF_ALIGN 
     391     8 TRACE_PRINTF_VAL 
     392 
    384393=cut 
    385394 
    386395*/ 
     
    388397PARROT_EXPORT 
    389398PARROT_CAN_RETURN_NULL 
    390399PackFile * 
    391 Parrot_pbc_read(PARROT_INTERP, ARGIN_NULLOK(const char *fullname), const int debug) 
     400Parrot_pbc_read(PARROT_INTERP, ARGIN_NULLOK(const char *fullname), const int options) 
    392401{ 
    393402    FILE     *io        = NULL; 
    394403    INTVAL    is_mapped = 0; 
     
    531540 
    532541    pf = PackFile_new(interp, is_mapped); 
    533542 
    534     /* Make the cmdline option available to the unpackers */ 
    535     pf->options = debug; 
     543    /* 0   to fail on version or UUID mismatch (parrot) 
     544     * 1   to pass on version or UUID mismatch (parrot_utils) 
     545     * 2++ --debug cmdline options: 
     546     *   2 TRACE_PRINTF 
     547     *   4 TRACE_PRINTF_ALIGN 
     548     *   8 TRACE_PRINTF_VAL */ 
     549    pf->options = options; 
    536550 
    537551    if (!PackFile_unpack(interp, pf, (opcode_t *)program_code, 
    538552            (size_t)program_size)) { 
     
    11541168 
    11551169PARROT_EXPORT 
    11561170void 
    1157 Parrot_disassemble(PARROT_INTERP, const char *outfile, Parrot_disassemble_options options) 
     1171Parrot_disassemble(PARROT_INTERP, ARGIN_NULLOK(const char *outfile), 
     1172                   Parrot_disassemble_options options) 
    11581173{ 
    11591174    PDB_line_t *line; 
    11601175    PDB_t      *pdb             = mem_allocate_zeroed_typed(PDB_t); 
     
    12931308     */ 
    12941309    if (! interp->initial_pf) { 
    12951310        PackFile *pf = PackFile_new_dummy(interp, "compile_string"); 
     1311        interp->initial_pf = pf; 
    12961312        /* Assumption: there is no valid reason to fail to create it. 
    1297          * If the assumption changes, replace the assertio with a 
     1313         * If the assumption changes, replace the assertion with a 
    12981314         * runtime check 
    12991315         */ 
    13001316        PARROT_ASSERT(interp->initial_pf); 
  • src/packfile/pf_items.c

    old new  
    161161static opcode_t fetch_op_mixed_le(ARGIN(const unsigned char *b)) 
    162162        __attribute__nonnull__(1); 
    163163 
    164 PARROT_WARN_UNUSED_RESULT 
    165 static opcode_t fetch_op_test(ARGIN(const unsigned char *b)) 
    166         __attribute__nonnull__(1); 
    167  
    168164#define ASSERT_ARGS_cvt_num12_num16 __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 
    169165       PARROT_ASSERT_ARG(dest) \ 
    170166    || PARROT_ASSERT_ARG(src) 
     
    219215       PARROT_ASSERT_ARG(b) 
    220216#define ASSERT_ARGS_fetch_op_mixed_le __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 
    221217       PARROT_ASSERT_ARG(b) 
    222 #define ASSERT_ARGS_fetch_op_test __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 
    223        PARROT_ASSERT_ARG(b) 
    224218/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */ 
    225219/* HEADERIZER END: static */ 
    226220 
     
    235229#define ROUND_UP(val, size) (((val) + ((size) - 1))/(size)) 
    236230 
    237231/* 
     232 * offset not in ptr diff, but in byte 
     233 */ 
     234#define OFFS(cursor) ((const char *)(cursor) - (const char *)(pf->src)) 
     235 
     236/* 
    238237 * low level FLOATVAL fetch and convert functions 
    239238 * 
    240239 * Floattype 0 = IEEE-754 8 byte double 
     
    274273       exp  11 bits 62-52 
    275274       man  52 bits 51-0 
    276275 
    277          +------+------+------+------+------+------+-...--+------+ 
    278          |byte 0|byte 1|byte 2|byte 3|byte 4|byte 5| ...  |byte12| 
    279          S|    E       |                F                        | 
    280          +------+------+------+------+------+------+-...--+------+ 
    281          1|<----15---->|<-------------80 bits------------------->| 
    282          <-----------------------96 bits-------------------------> 
    283               12-byte LONG DOUBLE FLOATING-POINT (i386 special) 
    284  
    285          +------+------+------+------+------+------+------+------+ 
    286          |byte 0|byte 1|byte 2|byte 3|byte 4|byte 5|byte 6|byte 7| 
    287          S|    E   |                    F                        | 
    288          +------+------+------+------+------+------+------+------+ 
    289          1|<--11-->|<-----------------52 bits------------------->| 
    290          <-----------------------64 bits-------------------------> 
    291                  8-byte DOUBLE FLOATING-POINT 
     276    +-------+-------+-------+-------+-------+-------+--...--+-------+ 
     277    |src[11]|src[10]|src[9] |src[8] |src[7] |src[6] | ...   |src[0] | 
     278    S|     E        |                    F                          | 
     279    +-------+-------+-------+-------+-------+-------+--...--+-------+ 
     280    1|<-----15----->|<----------------80 bits---------------------->| 
     281    <----------------------------96 bits----------------------------> 
     282 
     283    +-------+-------+-------+-------+-------+-------+-------+-------+ 
     284    |dest[7]|dest[6]|dest[5]|dest[4]|dest[3]|dest[2]|dest[1]|dest[0]| 
     285    S|    E    |                           F                        | 
     286    +-------+-------+-------+-------+-------+-------+-------+-------+ 
     287    1|<---11-->|<---------------------52 bits---------------------->| 
     288    <----------------------------64 bits----------------------------> 
     289                       8-byte DOUBLE FLOATING-POINT 
    292290    */ 
     291 
    293292    memset(dest, 0, 8); 
    294293    /* exponents 15 -> 11 bits */ 
    295294    s = src[9] & 0x80; /* sign */ 
     
    359358       exp  15 bits 94-80 
    360359       man  80 bits 79-0 
    361360 
    362          +------+------+------+------+------+------+-...--+------+ 
    363          |byte 0|byte 1|byte 2|byte 3|byte 4|byte 5| ...  |byte15| 
    364          S|    E       |                  F                      | 
    365          +------+------+------+------+------+------+-...--+------+ 
    366          1|<----15---->|<-------------112 bits------------------>| 
    367          <-----------------------128 bits------------------------> 
     361    +-------+-------+-------+-------+-------+-------+--...--+-------+ 
     362    |src[15]|src[14]|src[13]|src[12]|src[11]|src[10]| ...   |src[0] | 
     363    S|     E        |                    F                          | 
     364    +-------+-------+-------+-------+-------+-------+--...--+-------+ 
     365    1|<-----15----->|<----------------112 bits--------------------->| 
     366    <---------------------------128 bits----------------------------> 
    368367            16-byte LONG DOUBLE FLOATING-POINT (IA64 or BE 64-bit) 
    369368 
    370          +------+------+------+------+------+------+-...--+------+ 
    371          |byte 0|byte 1|byte 2|byte 3|byte 4|byte 5| ...  |byte11| 
    372          S|    E       |                F                        | 
    373          +------+------+------+------+------+------+-...--+------+ 
    374          1|<----15---->|<-------------80 bits------------------->| 
    375          <-----------------------96 bits-------------------------> 
     369    +-------+-------+-------+-------+-------+-------+--...--+-------+ 
     370    |dest[11]dest[10]dest[9]|dest[8]|dest[7]|dest[6]| ...   |dest[0]| 
     371    S|     E        |                    F                          | 
     372    +-------+-------+-------+-------+-------+-------+--...--+-------+ 
     373    1|<-----15----->|<----------------80 bits---------------------->| 
     374    <----------------------------96 bits----------------------------> 
    376375              12-byte LONG DOUBLE FLOATING-POINT (i386 special) 
    377376 
    378377    */ 
     
    395394 
    396395Converts i386 LE 12-byte long double to IEEE 754 LE 16-byte long double. 
    397396 
    398 TODO: Inaccurate implementation 12->8->16. Need to follow cvt_num12_num8 
    399 See http://babbage.cs.qc.cuny.edu/IEEE-754/References.xhtml 
     397TODO: Inaccurate implementation 12->8->16. Need to disect. 
    400398 
    401399=cut 
    402400 
    403401*/ 
    404402 
     403#if (NUMVAL_SIZE == 16) 
    405404static void 
    406405cvt_num12_num16(ARGOUT(unsigned char *dest), ARGIN(const unsigned char *src)) 
    407406{ 
     
    410409    cvt_num12_num8(b, src); 
    411410    cvt_num8_num16(dest, b); 
    412411} 
    413  
     412#endif 
    414413/* 
    415414 
    416415=item C<static void cvt_num16_num8> 
    417416 
    418417Converts IEEE 754 16-byte long double to IEEE 754 8 byte double. 
    419418 
    420 Fails on longdoublesize=12 with fatal exception. 
    421 Untested on longdoublesize=16. 
     419Tested ok. 
    422420 
    423421=cut 
    424422 
     
    429427{ 
    430428    ASSERT_ARGS(cvt_num16_num8) 
    431429 
    432 #if NUMVAL_SIZE == 16 
     430    if ((sizeof (long double) == 16) && (sizeof (double) == 8)) { 
    433431 
    434     /* The compiler can do this for us */ 
    435     long double ld; 
    436     double d; 
    437     memcpy(&d, src, 8); 
    438     ld = (long double)d; /* TODO: test compiler cast */ 
    439     TRACE_PRINTF_2(("  cvt_num16_num8: ld=%lf, d=%f\n", ld, d)); 
    440     memcpy(dest, &ld, 16); 
     432        long double ld; 
     433        double d; 
    441434 
    442 #else 
     435        memcpy(&ld, src, 16); 
     436        d = (double)ld; /* compiler cast */ 
     437        memcpy(dest, &d, 8); 
    443438 
    444     int expo, i, s; 
    445 #  ifdef __LCC__ 
    446     int expo2; 
    447 #  endif 
     439    } 
     440    else { 
     441 
     442        int expo, i, s; 
     443#ifdef __LCC__ 
     444        int expo2; 
     445#endif 
    448446 
    449     /* TODO: Have only 12-byte long double, need to disect it */ 
    450     exit_fatal(1, "TODO cvt_num16_num8\n"); 
     447    /* Have only 12-byte long double, or no long double at all. Need to disect it */ 
    451448 
    452449    /* 
    453450       16-byte double (128 bits): 
     
    459456       exp  11 bits 62-52 
    460457       man  52 bits 51-0 
    461458 
    462          +------+------+------+------+------+------+-...--+------+ 
    463          |byte 0|byte 1|byte 2|byte 3|byte 4|byte 5| ...  |byte15| 
    464          S|    E       |                  F                      | 
    465          +------+------+------+------+------+------+-...--+------+ 
    466          1|<----15---->|<-------------112 bits------------------>| 
    467          <-----------------------128 bits------------------------> 
     459    +-------+-------+-------+-------+-------+-------+--...--+-------+ 
     460    |src[15]|src[14]|src[13]|src[12]|src[11]|src[10]| ...   |src[0] | 
     461    S|     E        |                    F                          | 
     462    +-------+-------+-------+-------+-------+-------+--...--+-------+ 
     463    1|<-----15----->|<----------------112 bits--------------------->| 
     464    <---------------------------128 bits----------------------------> 
    468465            16-byte LONG DOUBLE FLOATING-POINT (IA64 or BE 64-bit) 
    469466 
    470          +------+------+------+------+------+------+------+------+ 
    471          |byte 0|byte 1|byte 2|byte 3|byte 4|byte 5|byte 6|byte 7| 
    472          S|    E   |                    F                        | 
    473          +------+------+------+------+------+------+------+------+ 
    474          1|<--11-->|<-----------------52 bits------------------->| 
    475          <-----------------------64 bits-------------------------> 
    476                  8-byte DOUBLE FLOATING-POINT 
     467    +-------+-------+-------+-------+-------+-------+-------+-------+ 
     468    |dest[7]|dest[6]|dest[5]|dest[4]|dest[3]|dest[2]|dest[1]|dest[0]| 
     469    S|    E    |                           F                        | 
     470    +-------+-------+-------+-------+-------+-------+-------+-------+ 
     471    1|<---11-->|<---------------------52 bits---------------------->| 
     472    <----------------------------64 bits----------------------------> 
     473                       8-byte DOUBLE FLOATING-POINT 
     474 
    477475   */ 
    478476 
    479     memset(dest, 0, 16); 
    480     s = src[15] & 0x80; /* 10000000 */ 
    481     /* 15->8 exponents bits */ 
    482     expo = ((src[15] & 0x7f)<< 8 | src[14]); 
    483     if (expo == 0) { 
    484 nul: 
     477        memset(dest, 0, 8); 
     478        s = src[15] & 0x80; /* 10000000 */ 
     479        /* 15->11 exponents bits */ 
     480        expo = ((src[15] & 0x7f)<< 8 | src[14]); 
     481        if (expo == 0) { 
     482          nul: 
     483            if (s) 
     484                dest[7] |= 0x80; 
     485            return; 
     486        } 
     487#ifdef __LCC__ 
     488        /* LCC blows up mysteriously until a temporary variable is 
     489         * added. */ 
     490        expo2 = expo - 16383; 
     491        expo  = expo2; 
     492#else 
     493        expo -= 16383;       /* - same bias as with 12-byte */ 
     494#endif 
     495        expo += 1023;       /* + bias 8byte */ 
     496        if (expo <= 0)       /* underflow */ 
     497            goto nul; 
     498        if (expo > 0x7ff) {  /* inf/nan */ 
     499            dest[7] = 0x7f; 
     500            dest[6] = src[7] == 0xc0 ? 0xf8 : 0xf0 ; 
     501            goto nul; 
     502        } 
     503        expo <<= 4; 
     504        dest[6] = (expo & 0xff); 
     505        dest[7] = (expo & 0x7f00) >> 8; 
    485506        if (s) 
    486507            dest[7] |= 0x80; 
    487         return; 
    488     } 
    489 #  ifdef __LCC__ 
    490     /* LCC blows up mysteriously until a temporary variable is 
    491      * added. */ 
    492     expo2 = expo - 16383; 
    493     expo  = expo2; 
    494 #  else 
    495     expo -= 16383;       /* - same bias as with 12-byte */ 
    496 #  endif 
    497     expo += 1023;       /* + bias 8byte */ 
    498     if (expo <= 0)       /* underflow */ 
    499         goto nul; 
    500     if (expo > 0x7ff) {  /* inf/nan */ 
    501         dest[7] = 0x7f; 
    502         dest[6] = src[7] == 0xc0 ? 0xf8 : 0xf0 ; 
    503         goto nul; 
    504     } 
    505     expo <<= 4; 
    506     dest[6] = (expo & 0xff); 
    507     dest[7] = (expo & 0x7f00) >> 8; 
    508     if (s) 
    509         dest[7] |= 0x80; 
    510     /* long double frac 63 bits => 52 bits 
    511        src[7] &= 0x7f; reset integer bit */ 
    512     for (i = 0; i < 6; i++) { 
    513         dest[i+1] |= (i==5 ? src[7]&0x7f : src[i+2]) >> 3; 
    514         dest[i] |= (src[i+2] & 0x1f) << 5; 
     508        /* long double frac 112 bits => 52 bits 
     509           src[13] &= 0x7f; reset integer bit */ 
     510        for (i = 0; i < 6; i++) { 
     511            dest[i+1] |= (i==5 ? src[13]&0x7f : src[i+7]) >> 3; 
     512            dest[i] |= (src[i+7] & 0x1f) << 5; 
     513        } 
     514        dest[0] |= src[1] >> 3; 
    515515    } 
    516     dest[0] |= src[1] >> 3; 
    517  
    518 #endif 
    519516} 
    520517 
    521518/* 
     
    530527 
    531528*/ 
    532529 
     530#if (NUMVAL_SIZE == 16) 
    533531static void 
    534532cvt_num8_num16(ARGOUT(unsigned char *dest), ARGIN(const unsigned char *src)) 
    535533{ 
     
    542540    TRACE_PRINTF_2(("  cvt_num8_num16: d=%f, ld=%lf\n", d, ld)); 
    543541    memcpy(dest, &ld, 16); 
    544542} 
     543#endif 
    545544 
    546545/* 
    547546 
     
    576575 
    577576Converts a big-endian IEEE 754 8-byte double to i386 LE 12-byte long double. 
    578577 
    579 Untested. 
     578Tested ok. 
    580579 
    581580=cut 
    582581 
     
    588587{ 
    589588    ASSERT_ARGS(cvt_num8_num12_be) 
    590589    unsigned char b[8]; 
    591     fetch_buf_be_8(b, src);  /* TODO test endianize */ 
    592     TRACE_PRINTF_2(("  cvt_num8_num12_be: 0x%8x\n", b)); 
     590    fetch_buf_be_8(b, src); 
     591    /*TRACE_PRINTF_2(("  cvt_num8_num12_be: 0x%8x\n", b));*/ 
    593592    cvt_num8_num12(dest, b); 
    594593} 
    595594#endif 
     
    752751 
    753752*/ 
    754753 
     754#if (NUMVAL_SIZE == 16) && !PARROT_BIGENDIAN 
    755755static void 
    756756cvt_num8_num16_be(ARGOUT(unsigned char *dest), ARGIN(const unsigned char *src)) 
    757757{ 
     
    760760    fetch_buf_be_8(b, src); 
    761761    cvt_num8_num16(dest, b); 
    762762} 
     763#endif 
    763764 
    764 /* 
    765  
    766 =item C<static opcode_t fetch_op_test> 
    767  
    768 Fetches an C<opcode_t> operation in little-endian format. 
    769  
    770 =cut 
    771  
    772 */ 
    773  
    774 PARROT_WARN_UNUSED_RESULT 
    775 static opcode_t 
    776 fetch_op_test(ARGIN(const unsigned char *b)) 
    777 { 
    778     ASSERT_ARGS(fetch_op_test) 
    779     union { 
    780         unsigned char buf[4]; 
    781         opcode_t o; 
    782     } u; 
    783     fetch_buf_le_4(u.buf, b); 
    784     return u.o; 
    785 } 
     765#if 0 
    786766 
    787767/* 
    788768 
     
    803783fetch_op_mixed_le(ARGIN(const unsigned char *b)) 
    804784{ 
    805785    ASSERT_ARGS(fetch_op_mixed_le) 
    806 #if OPCODE_T_SIZE == 4 
     786#  if OPCODE_T_SIZE == 4 
    807787    union { 
    808788        unsigned char buf[8]; 
    809789        opcode_t o[2]; 
     
    811791    /* wordsize = 8 then */ 
    812792    fetch_buf_le_8(u.buf, b); 
    813793    return u.o[0]; /* or u.o[1] */ 
    814 #else 
     794#  else 
    815795    union { 
    816796        unsigned char buf[4]; 
    817797        opcode_t o; 
     
    821801    u.o = 0; 
    822802    fetch_buf_le_4(u.buf, b); 
    823803    return u.o; 
    824 #endif 
     804#  endif 
    825805} 
    826806 
    827807/* 
     
    840820fetch_op_mixed_be(ARGIN(const unsigned char *b)) 
    841821{ 
    842822    ASSERT_ARGS(fetch_op_mixed_be) 
    843 #if OPCODE_T_SIZE == 4 
     823#  if OPCODE_T_SIZE == 4 
    844824    union { 
    845825        unsigned char buf[8]; 
    846826        opcode_t o[2]; 
     
    848828    /* wordsize = 8 then */ 
    849829    fetch_buf_be_8(u.buf, b); 
    850830    return u.o[1]; /* or u.o[0] */ 
    851 #else 
     831#  else 
    852832    union { 
    853833        unsigned char buf[4]; 
    854834        opcode_t o; 
     
    857837    u.o = 0; 
    858838    fetch_buf_be_4(u.buf, b); 
    859839    return u.o; 
    860 #endif 
     840#  endif 
    861841} 
    862842 
     843#endif 
     844 
    863845/* 
    864846 
    865847=item C<static opcode_t fetch_op_be_4> 
     
    998980 
    999981Fetches an C<opcode_t> from the stream, converting byteorder if needed. 
    1000982 
     983When used for freeze/thaw the C<pf> argument might be NULL. 
     984 
    1001985=cut 
    1002986 
    1003987*/ 
     
    1009993{ 
    1010994    ASSERT_ARGS(PF_fetch_opcode) 
    1011995    opcode_t o; 
     996 
     997    CHECK_PTR_ALIGNMENT(*stream, "PF_fetch_opcode"); 
     998    PARROT_ASSERT((PTR2INTVAL(*stream) & (PARROT_PTR_ALIGNMENT - 1)) == 0); 
    1012999    if (!pf || !pf->fetch_op) 
    10131000        return *(*stream)++; 
    10141001    o = (pf->fetch_op)(*((const unsigned char **)stream)); 
     1002    TRACE_PRINTF_VAL(("  PF_fetch_opcode: 0x%lx (%ld), at 0x%x\n", 
     1003                      o, o, OFFS(*stream))); 
    10151004    *((const unsigned char **) (stream)) += pf->header->wordsize; 
    1016     TRACE_PRINTF_VAL(("  PF_fetch_opcode: 0x%lx (%ld)\n", o, o)); 
     1005    CHECK_PTR_ALIGNMENT(*stream, "PF_fetch_opcode after padding"); 
    10171006    return o; 
    10181007} 
    10191008 
     
    10651054XXX assumes C<sizeof (INTVAL) == sizeof (opcode_t)> - we don't have 
    10661055C<INTVAL> size in the PackFile header. 
    10671056 
     1057When used for freeze/thaw the C<pf> argument might be NULL. 
     1058 
    10681059=cut 
    10691060 
    10701061*/ 
     
    10751066{ 
    10761067    ASSERT_ARGS(PF_fetch_integer) 
    10771068    INTVAL i; 
     1069    CHECK_PTR_ALIGNMENT(*stream, "PF_fetch_integer"); 
    10781070    if (!pf || pf->fetch_iv == NULL) 
    10791071        return *(*stream)++; 
    10801072    i = (pf->fetch_iv)(*((const unsigned char **)stream)); 
    1081  
     1073    TRACE_PRINTF_VAL(("  PF_fetch_integer: 0x%x (%d) at 0x%x\n", i, i, 
     1074                      OFFS(*stream))); 
    10821075    /* XXX assume sizeof (opcode_t) == sizeof (INTVAL) on the 
    1083      * machine producing this PBC 
     1076     * machine producing this PBC. 
     1077     * 
     1078     * TT #364 on Sparc 64bit: On pbc wordsize=4 but native ptrsize=8 and ptr_alignment=8 
     1079     * the advance by 4 will signal BUS (invalid address alignment) in PF_fetch_integer 
     1080     * http://nopaste.snit.ch/15684. It even fails natively by some PMC thaw misalignment 
     1081     * at the innocent *(*stream)++ above. 
    10841082     */ 
    10851083    *((const unsigned char **) (stream)) += pf->header->wordsize; 
     1084    CHECK_PTR_ALIGNMENT(*stream, "PF_fetch_integer after padding"); 
    10861085    return i; 
    10871086} 
    10881087 
     
    11451144     * to use memcpy() for native byteorder.  */ 
    11461145    FLOATVAL f; 
    11471146    double d; 
     1147 
     1148    CHECK_PTR_ALIGNMENT(*stream, "PF_fetch_number"); 
    11481149    if (!pf || !pf->fetch_nv) { 
    11491150        TRACE_PRINTF(("PF_fetch_number: Native [%d bytes]\n", 
    11501151                      sizeof (FLOATVAL))); 
    11511152        memcpy(&f, (const char *)*stream, sizeof (FLOATVAL)); 
    1152         TRACE_PRINTF_VAL(("PF_fetch_number: %f\n", f)); 
     1153        TRACE_PRINTF_VAL(("PF_fetch_number: %f at 0x%x\n", f, OFFS(*stream))); 
    11531154        (*stream) += (sizeof (FLOATVAL) + sizeof (opcode_t) - 1)/ 
    11541155            sizeof (opcode_t); 
     1156        CHECK_PTR_ALIGNMENT(*stream, "PF_fetch_number after padding"); 
    11551157        return f; 
    11561158    } 
    11571159    f = (FLOATVAL) 0; 
    1158     TRACE_PRINTF(("PF_fetch_number: Converting...\n")); 
     1160    TRACE_PRINTF(("PF_fetch_number at 0x%x: Converting...\n", OFFS(*stream))); 
    11591161    /* 12->8 has a messy cast. */ 
    11601162    if (NUMVAL_SIZE == 8 && pf->header->floattype == FLOATTYPE_12) { 
    11611163        (pf->fetch_nv)((unsigned char *)&d, (const unsigned char *) *stream); 
     
    11751177    else if (pf->header->floattype == FLOATTYPE_16) { 
    11761178        *((const unsigned char **) (stream)) += 16; 
    11771179    } 
     1180    else if (pf->header->floattype == FLOATTYPE_16MIPS) { 
     1181        *((const unsigned char **) (stream)) += 16; 
     1182    } 
     1183    else if (pf->header->floattype == FLOATTYPE_16AIX) { 
     1184        *((const unsigned char **) (stream)) += 16; 
     1185    } 
     1186    else if (pf->header->floattype == FLOATTYPE_4) { 
     1187        *((const unsigned char **) (stream)) += 4; 
     1188    } 
     1189    CHECK_PTR_ALIGNMENT(*stream, "PF_fetch_number after (no padding)"); 
    11781190    return f; 
    11791191} 
    11801192 
     
    12331245    opcode_t size 
    12341246    * data 
    12351247 
     1248When used for freeze/thaw the C<pf> argument might be NULL. 
     1249 
    12361250=cut 
    12371251 
    12381252*/ 
     
    12501264    const int wordsize = pf ? pf->header->wordsize : sizeof (opcode_t); 
    12511265    const char *charset_name; 
    12521266 
     1267    CHECK_PTR_ALIGNMENT(*cursor, "PF_fetch_string"); 
    12531268    flags = PF_fetch_opcode(pf, cursor); 
    12541269    /* don't let PBC mess our internals - only constant or not */ 
    12551270    flags &= (PObj_constant_FLAG | PObj_private7_FLAG); 
     
    12571272 
    12581273    /* These may need to be separate */ 
    12591274    size = (size_t)PF_fetch_opcode(pf, cursor); 
    1260     TRACE_PRINTF(("PF_fetch_string(): flags are 0x%04x...\n", flags)); 
    1261     TRACE_PRINTF(("PF_fetch_string(): charset_nr is %ld...\n", 
    1262                   charset_nr)); 
    1263     TRACE_PRINTF(("PF_fetch_string(): size is %ld...\n", size)); 
    1264  
     1275#if TRACE_PACKFILE 
     1276    if (pf && pf->options & 2) { 
     1277        TRACE_PRINTF(("PF_fetch_string(): flags=0x%04x, ", flags)); 
     1278        TRACE_PRINTF(("charset_nr=%ld, ", charset_nr)); 
     1279        TRACE_PRINTF(("size=%ld.\n", size)); 
     1280    } 
     1281#endif 
    12651282    charset_name = Parrot_charset_c_name(interp, charset_nr); 
    12661283    s = string_make(interp, (const char *)*cursor, size, charset_name, flags); 
    12671284 
    12681285#if TRACE_PACKFILE == 2 
    1269     if (pf->options & 3) { 
     1286    if (pf->options & 8) { 
    12701287        /* print only printable characters */ 
    1271         Parrot_io_eprintf(NULL, "PF_fetch_string(): string is '%s'\n", s->strstart); 
     1288        Parrot_io_eprintf(NULL, "PF_fetch_string(): string is '%s' at 0x%x\n", 
     1289                          s->strstart, OFFS(*cursor)); 
    12721290    } 
    12731291#endif 
    12741292 
    12751293/*    s = string_make(interp, *cursor, size, 
    12761294            encoding_lookup_index(encoding), 
    12771295                               flags); */ 
    1278  
     1296    TRACE_PRINTF_ALIGN(("-s ROUND_UP_B: cursor=0x%x, size=%d, wordsize=%d\n", 
     1297                        (const char *)*cursor + size, size, wordsize)); 
    12791298    size = ROUND_UP_B(size, wordsize); 
    12801299    TRACE_PRINTF(("PF_fetch_string(): round size up to %ld.\n", size)); 
    12811300    *((const unsigned char **) (cursor)) += size; 
     1301    TRACE_PRINTF_ALIGN(("+s ROUND_UP_B: cursor=0x%x, size=%d\n", *cursor, size)); 
     1302    CHECK_PTR_ALIGNMENT(*cursor, "PF_fetch_string after padding"); 
    12821303    return s; 
    12831304} 
    12841305 
     
    13861407    ASSERT_ARGS(PF_fetch_cstring) 
    13871408    const size_t str_len = strlen((const char *)(*cursor)) + 1; 
    13881409    char * const p = (char *)mem_sys_allocate(str_len); 
    1389  
    13901410    const int wordsize = pf->header->wordsize; 
    13911411 
     1412    CHECK_PTR_ALIGNMENT(*cursor, "PF_fetch_cstring"); 
     1413 
     1414#if TRACE_PACKFILE 
     1415    if (pf && pf->options & 2) { 
     1416        TRACE_PRINTF(("PF_fetch_cstring(): size is %ld...\n", str_len)); 
     1417    } 
     1418#endif 
     1419 
    13921420    strcpy(p, (const char*) (*cursor)); 
     1421#if TRACE_PACKFILE == 2 
     1422    if (pf && pf->options & 8) { 
     1423        TRACE_PRINTF(("PF_fetch_cstring(): string is '%s' at 0x%x\n", 
     1424                      p, OFFS(*cursor))); 
     1425    } 
     1426#endif 
     1427    TRACE_PRINTF_ALIGN(("-s ROUND_UP_B: cursor=0x%x, size=%d, wordsize=%d (cstring)\n", 
     1428                        *cursor, str_len, wordsize)); 
     1429    /* TT #254 need 32/64bit ptr advance correction */ 
     1430    /*(*cursor) += (ROUND_UP_B(str_len, wordsize) + sizeof (opcode_t) - 1)/sizeof (opcode_t);*/ 
    13931431    *((const unsigned char **) (cursor)) += ROUND_UP_B(str_len, wordsize); 
     1432    TRACE_PRINTF_ALIGN(("+s ROUND_UP_B: cursor=0x%x\n", 
     1433                        *cursor)); 
     1434    CHECK_PTR_ALIGNMENT(*cursor, "PF_fetch_cstring after padding"); 
    13941435 
    13951436    return p; 
    13961437} 
     
    14661507            pf->fetch_op = fetch_op_le_8; 
    14671508        pf->fetch_iv = pf->fetch_op; 
    14681509 
     1510        pf->fetch_iv = pf->fetch_op; 
    14691511        switch (pf->header->floattype) { 
    14701512#  if NUMVAL_SIZE == 8 
    14711513        case FLOATTYPE_8: 
  • src/pbc_disassemble.c

    old new  
    8585    Parrot_Interp interp; 
    8686    const char *outfile = NULL; 
    8787    int option = 0; 
    88     int debug = 0; 
     88    int debug = 1; 
    8989    struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; 
    9090    int status; 
    9191 
     
    108108                outfile = opt.opt_arg; 
    109109                break; 
    110110            case 'd': 
    111                 debug = 1; 
     111                debug += 6; 
    112112                break; 
    113113            case '?': 
    114114            default: 
  • src/pbc_info.c

    old new  
    7070 
    7171    interp = Parrot_new(NULL); 
    7272 
    73     pf = Parrot_pbc_read(interp, argv[1], 0); 
     73    pf = Parrot_pbc_read(interp, argv[1], 1); 
    7474 
    7575    /* 
    7676     * add some more segments 
  • t/codingstd/c_macro_args.t

    old new  
    4646        $buf =~ s{ (?: 
    4747                       (?: ' (?: \\\\ | \\' | [^'] )* ' )  # remove ' string 
    4848                     | (?: " (?: \\\\ | \\" | [^"] )* " )  # remove " string 
    49                      | /\*[^@] .*? \*/                         # remove C comment 
     49                     | /\*[^@] .*? \*/                     # remove C comment 
    5050                   ) 
    5151                }{}gsx; 
    5252 
     
    8787                    next if $macro =~ m/(TEST|SET|CLEAR)$/; 
    8888 
    8989                    # skip those two varargs macros, already called as TRACE_PRINTF((args)) 
    90                     next if $macro =~ m/^TRACE_PRINTF(_VAL)?$/; 
     90                    next if $macro =~ m/^TRACE_PRINTF(_VAL|_ALIGN)?$/; 
    9191 
    9292                    # Any remaining usage must be improper 
    9393                    if ($definition =~ m/\b\Q$arg\E\b/) { 
  • docs/pdds/pdd13_bytecode.pod

    old new  
    5151implemented. This section details these changes and some of the reasoning 
    5252behind them. 
    5353 
     54=head4 8-byte ptr_alignment 
     55 
     56We should be aware that some systems such as a Sparc/PPC 64-bit use strict 
     578-byte ptr_alignment per default, and all C<(opcode_t*)cursor++> or 
     58C<(opcode_t*)cursor +=> advances must ensure that the cursor ptr is 8-byte 
     59aligned.  We enforce 16-byte alignment at the start and end of all segments 
     60and ptrsize alignment for all strings, but not in-between, esp. with 4-byte 
     61integers and 4-byte opcode_t pointers. 
     62 
     63Which means that for a 32-bit (4-byte) pbc on a 8-byte ptr_alignment machine 
     64the pmc designer should take care that integers and opcode_t pointers appear 
     65pairwise in the frozen format, so that the 16-byte padding at the end of a 
     66segment already happens on an already 8-byte aligned pointer (<C<xxx0> or 
     67C<xxx8>), and not on a 4-byte ptr (C<xxx4> or C<xxxc>) alignment. Operations 
     68on aligned pointers are much faster than on un-aligned pointers. 
    5469 
    5570=head4 Packfile Header 
    5671 
     
    146161  |        |        | Must be one of:                                        | 
    147162  |        |        |    0x00 - IEEE 754 8 byte double                       | 
    148163  |        |        |    0x01 - i386 little endian 12 byte long double       | 
     164  |        |        |    0x02 - IEEE 754 16 byte long double                 | 
    149165  +--------+--------+--------------------------------------------------------+ 
    150166  | 11     | 1      | Major version number of the version of Parrot that     | 
    151167  |        |        | wrote this bytecode file. For example, if Parrot 0.9.5 | 
     
    170186  | 16     | 1      | The type of the UUID associated with this packfile.    | 
    171187  |        |        | Must be one of:                                        | 
    172188  |        |        |    0x00 - No UUID                                      | 
    173   |        |        |    0x01 - MD5                                          | 
     189  |        |        |    0x01 - MD5 + base64                                 | 
    174190  +--------+--------+--------------------------------------------------------+ 
    175191  | 17     | 1      | Length of the UUID associated with this packfile. May  | 
    176192  |        |        | be zero if the type of the UUID is 0x00. Maximum       | 
     
    185201  +--------+--------+--------------------------------------------------------+ 
    186202  | 18 + u | n      | Zero-padding to make the total header length a         | 
    187203  |        |        | multiple of 16 bytes in length.                        | 
    188   |        |        |    n = u % 16 == 0 ? 0 : 16 - (u % 16)                 | 
     204  |        |        |    n = u % 16 ? 16 - (u % 16) : 0                      | 
    189205  +--------+--------+--------------------------------------------------------+ 
    190206 
    191207Everything beyond the header is an opcode, with word length and byte ordering 
  • parrot-svn

    old new  
    25972597t/native_pbc/integer_3.pbc                                  [test] 
    25982598t/native_pbc/integer_4.pbc                                  [test] 
    25992599t/native_pbc/integer_5.pbc                                  [test] 
     2600t/native_pbc/integer_6.pbc                                  [test] 
    26002601t/native_pbc/number.t                                       [test] 
    26012602t/native_pbc/number_1.pbc                                   [test] 
    26022603t/native_pbc/number_2.pbc                                   [test] 
    26032604t/native_pbc/number_3.pbc                                   [test] 
    26042605t/native_pbc/number_4.pbc                                   [test] 
    26052606t/native_pbc/number_5.pbc                                   [test] 
     2607t/native_pbc/number_6.pbc                                   [test] 
    26062608t/native_pbc/string.t                                       [test] 
    26072609t/native_pbc/string_1.pbc                                   [test] 
    26082610t/native_pbc/string_2.pbc                                   [test] 
  • src/pmc_freeze.c

    old new  
    558558{ 
    559559    ASSERT_ARGS(push_ascii_string) 
    560560    const UINTVAL length = Parrot_str_byte_length(interp, s); 
    561     char * const buffer = (char *)malloc(4*length); /* XXX Why 4?  What does that mean? */ 
     561    char * const buffer = (char *)malloc(OPCODE_T_SIZE*length); 
    562562    char *cursor = buffer; 
    563563    UINTVAL idx = 0; 
    564564 
     
    10801080         16 - PACKFILE_HEADER_BYTES % 16 : 0); 
    10811081 
    10821082    info->image_io = mem_allocate_typed(IMAGE_IO); 
    1083     info->image_io->image = s = info->image; 
     1083    info->image_io->image = info->image; 
    10841084#if FREEZE_ASCII 
    10851085    info->image_io->vtable = &ascii_funcs; 
    10861086#else 
    10871087    info->image_io->vtable = &opcode_funcs; 
    10881088#endif 
    10891089    pf = info->image_io->pf = PackFile_new(interp, 0); 
     1090#if TRACE_PACKFILE 
     1091    pf->options = 0; /* 15 to debug freeze */ 
     1092#endif 
    10901093    if (info->what == VISIT_FREEZE_NORMAL || 
    10911094        info->what == VISIT_FREEZE_AT_DESTRUCT) { 
    10921095 
     
    12161219    ASSERT_ARGS(thaw_pmc) 
    12171220    PMC *n; 
    12181221    IMAGE_IO * const io = info->image_io; 
     1222#if TRACE_PACKFILE 
     1223    PackFile *pf = info->image_io->pf; 
     1224#endif 
    12191225    int seen = 0; 
    12201226 
    12211227    info->extra_flags = EXTRA_IS_NULL; 
    12221228    n = VTABLE_shift_pmc(interp, io); 
     1229    TRACE_PRINTF(("thaw_pmc: pmc=0x%x\n", n)); 
    12231230    if (((UINTVAL) n & 3) == 3) { 
    12241231        /* pmc has extra data */ 
    12251232        info->extra_flags = VTABLE_shift_integer(interp, io); 
     1233        TRACE_PRINTF(("thaw_pmc: pmc extra_flags=0x%x\n", info->extra_flags)); 
    12261234    } 
    12271235    else if ((UINTVAL) n & 1) {     /* seen PMCs have bit 0 set */ 
    12281236        seen = 1; 
     
    12321240    } 
    12331241    else {                          /* type follows */ 
    12341242        *type = VTABLE_shift_integer(interp, io); 
     1243        TRACE_PRINTF(("thaw_pmc: pmc type=%d\n", *type)); 
    12351244        info->last_type = *type; 
    12361245        if (*type <= 0) 
    12371246            Parrot_ex_throw_from_c_args(interp, NULL, 1,