示例#1
0
void Code::disassemble(ostream& out, FunctionFilter* filter) {
    for (uint32_t i = 0; i < _functions.size(); i++) {
        TranslatedFunction* function = _functions[i];
        bool match = filter ? filter->matches(function) : true;
        if (match) {
            out << "function [" << function->id() << "] "
                << typeToName(function->returnType())
                << " " << function->name() << "(";
            for (uint32_t i = 0; i < function->parametersNumber(); i++) {
                out << typeToName(function->parameterType(i));
                if (i + 1 < function->parametersNumber()) {
                    out << ", ";
                }
            }
            out << ")" << endl;
            function->disassemble(out);
        }
    }
}
示例#2
0
void ByteCodeVisitor::initVars(Scope *scope) {
    if (!scope) return;
    Scope::VarIterator varIt(scope);
    while (varIt.hasNext()) {
        AstVar *var = varIt.next();
        if (!var->info()) {
            var->setInfo(new AstVarInfo(currentBytecodeFunction->id(), currentBytecodeFunction->localsNumber()));
            currentBytecodeFunction->setLocalsNumber(currentBytecodeFunction->localsNumber() + 1);
            if (currentBytecodeFunction->localsNumber() >= UINT16_MAX) {
                error("vars overflow in function <%s,id>", currentBytecodeFunction->name().c_str(), currentBytecodeFunction->id());
            }
        } else {
            AstVarInfo *varInfo = (AstVarInfo *) var->info();
            TranslatedFunction *function = interpreterCode->functionById(varInfo->contextId);
            error("variable already declared var <%s,%d,%d> for function %s",
                    var->name().c_str(), varInfo->contextId, varInfo->id, function->name().c_str());
        }
    }

}