Example #1
0
static bool openCmdFile(        // OPEN A COMMAND FILE
    char const *filename,       // - file name
    size_t size )               // - size of name
{
    char fnm[ _MAX_PATH ];      // - buffer for name

    stvcpy( fnm, filename, size );
    StripQuotes( fnm );
    return IoSuppOpenSrc( fnm, FT_CMD );
}
Example #2
0
char *vctsave(                  // ALLOCATE AND SAVE VECTOR AS STRING
    const char *vector,         // - source vector
    size_t vsize )              // - size of source vector
{
    char * new_str;             // - target string

    new_str = (char *) CMemAlloc( vsize + 1 );
    stvcpy( new_str, vector, vsize );
    return( new_str );
}
Example #3
0
static void addString           // STORE A STRING
    ( OPT_STRING **h            // - addr[ storage ]
    , char const *s             // - string
    , size_t len )              // - length
{
    OPT_STRING *value;

    value = _MemoryAllocate( sizeof( *value ) + len );
    stvcpy( value->data, s, len );
    value->next = *h;
    *h = value;
}
Example #4
0
static char *get_env(           // GET ENVIRONMENT VAR
    const char *var,            // - variable name
    size_t len )                // - length of name
{
    char buf[128];              // - used to make a string
    char *env;                  // - environment name

    if( len >= sizeof( buf ) ) {
        env = NULL;
    } else {
        stvcpy( buf, var, len );
        env = CppGetEnv( buf );
    }
    return env;
}
Example #5
0
static PC_SEGMENT *segmentDefine(// SEGMENT: DEFINE IF REQUIRED
    const char *seg_name,       // - segment name
    const char *class_name,     // - segment class name
    fe_seg_id seg_id,           // - segment id (if not SEG_NULL)
    unsigned attrs,             // - segment attributes
    unsigned control )          // - segmentAlloc control mask
{
    PC_SEGMENT *curr;           // - current segment
    struct seg_look lk;         // - look-up structure
#if _INTEL_CPU
    const char* pc_reg;         // - scans register bound to segment
    char pc_reg_name[8];        // - name of pc register

    for( pc_reg = seg_name; ; ++pc_reg ) {
        if( *pc_reg == '\0' ) {
            pc_reg_name[0] = '\0';
            break;
        }
        if( *pc_reg == ':' ) {
            stvcpy( pc_reg_name, seg_name, pc_reg - seg_name );
            seg_name = pc_reg + 1;
            break;
        }
    }
#endif
    lk.seg_id = seg_id;
    lk.use_seg_id = TRUE;
    lk.attrs = attrs;
    lk.use_attrs = TRUE;
    lk.use_align = FALSE;
    lk.use_sym_size_align = FALSE;
    lk.seg_name = seg_name;
    lk.class_name = class_name;
    lk.use_name = TRUE;
    lk.use_only_strings = FALSE;
    curr = RingLookup( seg_list, &same_segment, &lk );
    if( curr == NULL ) {
        curr = segmentAlloc( lk.seg_name, lk.class_name, lk.seg_id, lk.attrs, control );
#if _INTEL_CPU
        if( pc_reg_name[0] != '\0' ) {
            curr->binding = PragRegName( pc_reg_name );
        }
#endif
    }
    return curr;
}
Example #6
0
static void scanInputFile(       // PROCESS NAME OF INPUT FILE
    void )
{
    char filename[ _MAX_PATH ]; // - scanned file name
    size_t len;                 // - length of file name
    char const *fnm;            // - file name in command line

    len = CmdScanFilename( &fnm );
    ++CompInfo.compfile_max;
    if( CompInfo.compfile_max == CompInfo.compfile_cur ) {
        if( WholeFName == NULL ) {
            stvcpy( filename, fnm, len );
            StripQuotes( filename );
            WholeFName = FNameAdd( filename );
        } else {
            CErr1( ERR_CAN_ONLY_COMPILE_ONE_FILE );
        }
    }
}
Example #7
0
void HFileAppend(               // APPEND HFILE TO LIST
    const char *filename,       // - file name
    size_t len )                // - size of name
{
    int old_len;                // - length of old H list
    char *p;                    // - points into H list
    char *old_list;             // - old H list

    if( hfile_list != NULL ) {
        old_list = hfile_list;
        old_len = strlen( old_list );
        p = (char *) CMemAlloc( len + old_len + 2 );
        hfile_list = p;
        p = stpcpy( p, old_list );
        p = IoSuppAddIncPathSep( p );
        CMemFree( old_list );
    } else {
        p = (char *) CMemAlloc( len + 1 );
        hfile_list = p;
    }
    p = stvcpy( p, filename, len );
}
Example #8
0
static void dumpPTreeNode(      // DUMP A PARSE TREE NODE
    PTREE node )                // - node in parse tree
{
    static char buffer[128];    // - debugging buffer
    char *node_name;            // - name of node
    VSTK_CTL ctl;               // - VSTK control information (nodes)
    VSTK_CTL dup;               // - VSTK control information (duplicates)
    int dup_out;                // - last duplicate printed

    VstkOpen( &ctl, sizeof( PTREE ), 32 );
    VstkOpen( &dup, sizeof( PTREE ), 8 );
    dup_out = -1;
    for( ; ; ) {
        switch( node->op ) {
          case PT_ERROR :
            printf( "PT_ERROR"      F_BADDR
                    " ***** ERROR TREE *****" F_EOL
                  , node
                  );
            break;
          case PT_INT_CONSTANT :
            node_name = "PT_INT_CONSTANT";
            printf( F_NAME          F_BADDR
                    " flags"        F_HEX_4
                    " type"         F_PTR
                  , node_name
                  , node
                  , node->flags
                  , node->type
                  );
            if( NULL == Integral64Type( node->type ) ) {
                printf( " integer"      F_HEX_4
                      , node->u.int_constant
                      );
            } else {
                printf( " integer-64" F_S64
                      , VAL64( node->u.int64_constant )
                      );
            }
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            break;
          case PT_FLOATING_CONSTANT : {
            char buffer[256];

            BFCnvFS( node->u.floating_constant, buffer, 256 );
            printf( "PT_FLOATING_CONSTANT" F_BADDR
                    " flags"        F_HEX_4
                    " float"        F_CPP_FLOAT
                  , node
                  , node->flags
                  , buffer
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
          }
            break;
          case PT_STRING_CONSTANT :
            stvcpy( buffer, node->u.string->string, node->u.string->len );
            printf( "PT_STRING_CONSTANT" F_BADDR
                    " flags"        F_HEX_4
                    " string"       F_STRING
                  , node
                  , node->flags
                  , buffer
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            break;
          case PT_ID :
            printf( "PT_ID"         F_BADDR
                    " flags"        F_HEX_4
                    " cgop"         F_STRING F_NL
                    " id"           F_PTR
                    "="             F_STRING
                    " id_cgop"      F_STRING
                    " u.id.scope"   F_PTR
                  , node
                  , node->flags
                  , DbgOperator( node->cgop )
                  , node->u.id.name
                  , NameStr( node->u.id.name )
                  , DbgOperator( node->id_cgop )
                  , node->u.id.scope
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            break;
          case PT_TYPE :
            printf( "PT_TYPE"       F_BADDR
                    " cgop"         F_STRING
                    " flags"        F_HEX_4
                    " next"         F_PTR
                    " scope"        F_PTR
                  , node
                  , DbgOperator( node->cgop )
                  , node->flags
                  , node->u.type.next
                  , node->u.type.scope
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            break;
          case PT_SYMBOL :
            if( node->cgop == CO_NAME_THIS ) {
                printf( "PT_SYMBOL"     F_BADDR
                        " flags"        F_HEX_4
                        " this "
                      , node
                      , node->flags
                      );
                dumpNodeType( node );
                dumpLocation( &node->locn );
                dumpPtreeFlags( node );
            } else if( node->cgop == CO_NAME_CDTOR_EXTRA ) {
                printf( "PT_SYMBOL"     F_BADDR
                        " flags"        F_HEX_4
                        " cdtor_extra_parm "
                      , node
                      , node->flags
                      );
                dumpNodeType( node );
                dumpLocation( &node->locn );
                dumpPtreeFlags( node );
            } else {
                printf( "PT_SYMBOL"     F_BADDR
                        " flags"        F_HEX_4
                        " cgop"         F_STRING F_NL
                        " symbol"       F_PTR
                        " result"       F_PTR
                      , node
                      , node->flags
                      , DbgOperator( node->cgop )
                      , node->u.symcg.symbol
                      , node->u.symcg.result
                      );
                dumpNodeType( node );
                dumpLocation( &node->locn );
                dumpPtreeFlags( node );
                DumpSymbol( node->u.symcg.symbol );
            }
            break;
          case PT_UNARY :
            printf( "PT_UNARY"      F_BADDR
                    F_POINTS        F_ADDR
                    " flags"        F_HEX_4
                    " cgop"         F_STRING
                  , node
                  , node->u.subtree[0]
                  , node->flags
                  , DbgOperator( node->cgop )
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            PUSH_NODE( ctl, node->u.subtree[0] );
            break;
          case PT_BINARY :
            printf( "PT_BINARY"     F_BADDR
                    F_POINTS        F_ADDR
                    ","             F_ADDR
                    " flags"        F_HEX_4
                    " cgop"         F_STRING
                  , node
                  , node->u.subtree[0]
                  , node->u.subtree[1]
                  , node->flags
                  , DbgOperator( node->cgop )
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            PUSH_NODE( ctl, node->u.subtree[1] );
            PUSH_NODE( ctl, node->u.subtree[0] );
            break;
          case PT_DUP_EXPR :
          { PTREE *duped;       // - duplicated expression
            printf( "PT_DUP_EXPR"   F_BADDR
                    F_POINTS        F_ADDR
                    " flags"        F_HEX_4
                    " node"         F_ADDR
                  , node
                  , node->u.dup.subtree[0]
                  , node->flags
                  , node->u.dup.node
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            if( node->u.subtree[0] != NULL ) {
                for( duped = VstkTop( &dup )
                   ;
                   ; duped = VstkNext( &dup, duped ) ) {
                    if( duped == NULL ) {
                        PUSH_NODE( dup, node->u.subtree[0] );
                    } else if( *duped == node->u.subtree[0] ) {
                        break;
                    }
                }
            }
          } break;
          case PT_IC :
            printf( "PT_IC"         F_BADDR
                    " "             F_NAME
                    " value"        F_ADDR
                  , node
                  , DbgIcOpcode( node->u.ic.opcode )
                  , node->u.ic.value.pvalue
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            break;
          default :
            printf( "***INVALID***" F_BADDR
                    " flags"        F_HEX_4
                    " op"           F_HEX_1
                  , node
                  , node->flags
                  , node->op
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            break;
        }
        {
            PTREE *next;            // - addr[next node]
            next = VstkPop( &ctl );
            if( next != NULL ) {
                node = *next;
            } else {
                ++dup_out;
                if( dup_out > VstkDimension( &dup ) ) break;
                next = VstkIndex( &dup, dup_out );
                printf( "--------------- duplicate ------------\n" );
                node = *next;
            }
        }
    }
    VstkClose( &ctl );
    VstkClose( &dup );
}
Example #9
0
static PC_SEGMENT *segmentAlloc(    // SEGMENT: ALLOCATE NEW SEGMENT
    const char *seg_name,           // - segment name
    const char *class_name,         // - segment class name
    fe_seg_id seg_id,               // - segment id (if not SEG_NULL)
    unsigned attrs,                 // - segment attributes
    unsigned control )              // - control mask
{
    PC_SEGMENT *curr;               // - segment pointer
    size_t size;                    // - size of segment name

#if _INTEL_CPU && COMP_CFG_COFF == 0
//alpha permits segments defined anywhere and we need it for comdat data
//ditto for COFF
    DbgVerify( ! flags.in_back_end || ( attrs & PRIVATE ) || ( control & SA_DEFINE_ANYTIME )
               , "segmentAlloc -- defining in back end" );
#endif
    size = strlen( seg_name );
    curr = RingAlloc( &seg_list, sizeof( PC_SEGMENT ) + size );
    curr->sibling = curr;
    stvcpy( curr->name, seg_name, size );
    curr->offset = 0;
    curr->dgroup = (( control & SA_IN_DGROUP ) != 0 );
    curr->lab_gened = FALSE;
    if( class_name != NULL ) {
        curr->class_name = strpermsave( class_name );
    } else {
        curr->class_name = NULL;
    }
    curr->used = FALSE;
    curr->module_prefix = (( control & SA_MODULE_PREFIX ) != 0 );
    curr->fixed_alignment = FALSE;
    curr->cg_defed = FALSE;
    curr->has_data = FALSE;
    curr->only_strings = FALSE;
    curr->label = NULL;
    curr->attrs = attrs;
#if _INTEL_CPU
    HW_CAsgn( curr->binding, HW_EMPTY );
#endif
    if( seg_id == SEG_NULL ) {
        seg_id = ++seg_max;
        checkSegmentOverflow();
    } else {
        if( seg_id > seg_max ) {
            seg_max = seg_id;
            checkSegmentOverflow();
        }
    }
    curr->seg_id = seg_id;
    switch( seg_id ) {
    case SEG_PROF_BEG:
    case SEG_PROF_REF:
    case SEG_PROF_END:
        // we don't want padding introduced
        curr->align = TARGET_LONG;
        // we don't want alignment changed either
        curr->fixed_alignment = TRUE;
        break;
    case SEG_INIT_BEG:
    case SEG_INIT_REF:
    case SEG_INIT_END:
    case SEG_FINI_BEG:
    case SEG_FINI_REF:
    case SEG_FINI_END:
        // we don't want padding introduced
#if _INTEL_CPU
        curr->align = TARGET_SHORT;
#elif _CPU == _AXP
        curr->align = TARGET_POINTER;
#else
#error no alignment set
#endif
        // we don't want alignment changed either
        curr->fixed_alignment = TRUE;
        break;
    default:
        curr->align = TARGET_CHAR;
        if( flags.in_back_end ) {
            segmentCgDefine( curr );
        }
        break;
    }
    return( curr );
}