Example #1
0
DebugInfos* getDebInfo(const char* package)
{
    SymbolID_t pkgid = gSymbolTable.symbolID(package);
    DebugInfos** pdsi = m_debInfos.find(pkgid);
    if (pdsi != NULL)
        return *pdsi;
    hyu32 len = HMD_STRLEN(package);
    TArray<char>* fname = new TArray<char>(len + HMD_STRLEN(DEBUGINFO_EXT) + 1);
    memcpy(fname->addSpaces(len), package, len);
    len = HMD_STRLEN(DEBUGINFO_EXT);
    memcpy(fname->addSpaces(len), DEBUGINFO_EXT, len);
    fname->add('\0');

    return new DebugInfos(fname->top());
}
Example #2
0
 // ロードパスを追加する
 void    addLoadPath(const char* path)
 {
     //printf("addLoadPath(%s)\n", path);
     hyu32 n = loadPathArr.size();
     if (n == 0) {
         loadPathArr.add(NULL);
         n = 1;
     }
     hyu32 len = HMD_STRLEN(path);
     char* apath = gMemPool->allocT<char>(len+1);
     HMD_STRNCPY(apath, path, len+1);
     loadPathArr[n-1] = apath;  // end mark に上書き
     loadPathArr.add(NULL);     // 新しい end mark
     HMD_LOADPATH = loadPathArr.top();
     // n=0;for(const char** p = HMD_LOADPATH; *p != NULL; ++p)HMD_PRINTF("path %d:'%s'\n",n++,*p);
 }
Example #3
0
int main(int argc, const char* argv[])
{
    hyu32 memSize = DEFAULT_MEMSIZE;
    const char* param;
    const char* symbolFile = NULL;
    const char* incPath[32];
    int numIncPath = 0;
    void* hayatMemory = NULL;

    numLoadPath = 0;
    HMD_LOADPATH = NULL;
    bPrintSource = false;

    for (int i = 1; i < argc; i++) {
        if (argv[i][0] == '-') {
            switch (argv[i][1]) {
            case 'I':
                // includeパス
                if (numIncPath >= 32) {
                    usage();
                    HMD_PRINTF("too many include path (must <=32)\n");
                    return 1;
                }
                param = getParam(i, argc, argv, "-I");
                if (param == NULL) {
                    usage();
                    HMD_PRINTF("parameter for -I is not specified\n");
                    return 1;
                }
                incPath[numIncPath++] = param;
                break;

            case 'M':
                param = getParam(i, argc, argv, "-M");
                if (param == NULL) {
                    usage();
                    HMD_PRINTF("parameter for -M is not specified\n");
                    return 1;
                } else {
                    memSize = 0;
                    while('0' <= *param && *param <= '9') {
                        memSize *= 10;
                        memSize += (*param++ - '0');
                    }
                    if (*param == 'k' || *param == 'K') {
                        memSize *= 1024;
                    } else if (*param == 'm' || *param == 'M') {
                        memSize *= 1024 * 1024;
                    } else if (*param != '\0') {
                        printf("bad parameter for -M\n");
                        memSize = DEFAULT_MEMSIZE;
                    }
                }
                break;

            case 'f':
                param = getParam(i, argc, argv, "-f");
                if (param == NULL) {
                    HMD_PRINTF("symbol file is not specified\n");
                    return 1;
                }
                symbolFile = param;
                break;
                    
            case 's':
                bPrintSource = true;
                break;

            case 'h':
                usage(true);
                return 1;

            default:
                usage(true);
                HMD_PRINTF("unknown option %s\n", argv[i]);
                return 1;
            }
        } else {
            usage(true);
            HMD_PRINTF("unknown option %s\n", argv[i]);
            return 1;
        }
    }

    hayatMemory = HMD_ALLOC(memSize);
    MemPool::initGMemPool(hayatMemory, memSize);


    for (int i = 0; i < numIncPath; ++i) {
        addLoadPath(incPath[i], "out");
    }
    addLoadPath(".", "out");

    if (symbolFile != NULL) {
        if (! gSymbolTable.readFile(symbolFile)) {
            HMD_PRINTF("symbol file '%s' load failed\n", symbolFile);
            HMD_FREE(hayatMemory);
            return 1;
        }
    } else {
        hyu8* fileBuf;
        hyu32 len = hmd_loadFile_inPath("symbols.sym", &fileBuf);
        if (len != 0)
            gSymbolTable.readTable(fileBuf);
        else
            HMD_PRINTF("could not load symbols.sym\n");
    }

    
    // main loop

    static const size_t BUF_SIZE = 1024;
    char buf[BUF_SIZE];
    while (fgets(buf, BUF_SIZE, stdin) != NULL) {
        TArray<char>* s = replaceSymbol(buf);
        printResolvedLine(s->top());
        s->finalize();
    }



    // normal exit
    gSymbolTable.finalize();
    HMD_FREE(hayatMemory);
    return 0;
}
Example #4
0
void DClass::dump(TArray<SymbolID_t>& parents)
{
    hyu8 sbuf[256];

    if (bPrimitive)
        HMD_PRINTF("flag: primitive\n");
    if (numDefaultVal > 0)
        HMD_PRINTF("number of default values: %d\n", numDefaultVal);
    if (numSuper > 0) {
        HMD_PRINTF("%d super classes: ", numSuper);
        for (int i = 0; i < numSuper; ++i) {
            SymbolID_t supsym = (SymbolID_t)Endian::unpack<hyu32>((const hyu8*)&superTable[i]);
            gSymbolTable.id2str_n(sbuf, 256, supsym);
            HMD_PRINTF((char*)sbuf);
            if (i < numSuper - 1)
                HMD_PRINTF(", ");
        }
        HMD_PRINTF("\n");
    }

    bool bPrintUsingPath = false;
    hyu16 usingInfoSize = Endian::unpack<hyu16>((const hyu8*)usingPaths);
    const hyu8* ptr = ((const hyu8*)usingPaths) + 4;
    for (;;) {
        SymbolID_t sym = Endian::unpackP<SymbolID_t>(&ptr);
        if (sym == SYMBOL_ID_ERROR)
            break;
        if (!bPrintUsingPath) {
            bPrintUsingPath = true;
            HMD_PRINTF("using paths:\n");
        }
        if (sym != (SymbolID_t)0) { // 0 == HSym_nil
            gSymbolTable.id2str_n(sbuf, 256, sym);
            HMD_PRINTF((char*)sbuf);
        }
        for (;;) {
            sym = Endian::unpackP<SymbolID_t>(&ptr);
            if (sym == SYMBOL_ID_ERROR)
                break;
            gSymbolTable.id2str_n(sbuf, 256, sym);
            HMD_PRINTF("::%s", sbuf);
        }
    }
    HMD_DEBUG_ASSERT(ptr <= ((const hyu8*)usingPaths) + usingInfoSize);

    if (numClassVar > 0) {
        HMD_PRINTF("class variables: ");
        printSymbols(classVarSymArr.top(), numClassVar, "@@");
    }
    if (numMembVar > 0) {
        HMD_PRINTF("member variables: ");
        printSymbols(membVarSymArr.top(), numMembVar, "@");
    }
    if (numConstVar > 0) {
        HMD_PRINTF("constants: ");
        printSymbols(constVarSymArr.top(), numConstVar, "");
    }
        
    int numBlk = numMethods + numClosures;
    TArray<const hyu8*> adrs(numBlk + 2);
    adrs.add(codes);
    for (int i = 0; i < numBlk; ++i)
        adrs.add(codes + methodTable[i]);
    if (numInnerClasses > 0)
        adrs.add(codes + innerClassTable[0]);
    else
        adrs.add(bottomAddr);
    
    for (int i = 0; i <= numBlk; ++i) {
        if (i == 0)
            HMD_PRINTF("***** classInitializer *MAIN *****\n");
        else if (i <= numMethods) {
            gSymbolTable.id2str_n(sbuf, 256, methodSymTable[i-1]);
            HMD_PRINTF("***** method %s *****\n", sbuf);
        }
        else
            HMD_PRINTF("***** closure #%d *****\n", i - numMethods - 1);
        dumpMethod(adrs[i], adrs[i+1]);
    }


    for (int i = 0; i < numInnerClasses; ++i) {
        TArray<SymbolID_t> abs(parents.size() + 1);
        abs.add(parents);
        abs.add(innerClasses[i]->classSymbol);

        SymbolID_t sym;
        HMD_PRINTF("======== class ");
        for (hyu32 j = 0; j < abs.size(); ++j) {
            sym = abs[j];
            gSymbolTable.id2str_n(sbuf, 256, sym);
            HMD_PRINTF("::%s", sbuf);
        }
        HMD_PRINTF(" ========\n");
        innerClasses[i]->dump(abs);
    }
}