当前位置: 首页>>代码示例>>C++>>正文


C++ CPU::mapfunction方法代码示例

本文整理汇总了C++中CPU::mapfunction方法的典型用法代码示例。如果您正苦于以下问题:C++ CPU::mapfunction方法的具体用法?C++ CPU::mapfunction怎么用?C++ CPU::mapfunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CPU的用法示例。


在下文中一共展示了CPU::mapfunction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char* argv[]) {
    // setup command line arguments vector
    vector<string> args;
    string option;
    for (int i = 1; i < argc; ++i) {
        option = string(argv[i]);
        if (option == "--help") {
            SHOW_HELP = true;
            continue;
        } else if (option == "--version") {
            SHOW_VERSION = true;
            continue;
        } else if (option == "--verbose") {
            VERBOSE = true;
            continue;
        }
        args.push_back(argv[i]);
    }

    if (usage(argv[0], SHOW_HELP, SHOW_VERSION, VERBOSE)) { return 0; }

    if (args.size() == 0) {
        cout << "fatal: no input file" << endl;
        return 1;
    }

    string filename = "";
    filename = args[0];

    if (!filename.size()) {
        cout << "fatal: no file to run" << endl;
        return 1;
    }

    Loader loader(filename);
    loader.executable();

    uint16_t bytes = loader.getBytecodeSize();
    byte* bytecode = loader.getBytecode();

    CPU cpu;

    map<string, uint16_t> function_address_mapping = loader.getFunctionAddresses();
    uint16_t starting_instruction = function_address_mapping["__entry"];
    for (auto p : function_address_mapping) { cpu.mapfunction(p.first, p.second); }
    for (auto p : loader.getBlockAddresses()) { cpu.mapblock(p.first, p.second); }

    vector<string> cmdline_args;
    for (int i = 1; i < argc; ++i) {
        cmdline_args.push_back(argv[i]);
    }

    cpu.commandline_arguments = cmdline_args;

    cpu.load(bytecode).bytes(bytes).eoffset(starting_instruction).run();

    int ret_code = 0;
    string return_exception = "", return_message = "";
    tie(ret_code, return_exception, return_message) = cpu.exitcondition();

    if (ret_code != 0 and return_exception.size()) {
        cout << "exception after " << cpu.counter() << " ticks" << endl;
        cout << "uncaught object: " << return_exception << " = " << return_message << endl;
        cout << "\n";

        vector<Frame*> trace = cpu.trace();
        cout << "stack trace: from entry point, most recent call last...\n";
        for (unsigned i = 1; i < trace.size(); ++i) {
            cout << "  " << stringifyFunctionInvocation(trace[i]) << "\n";
        }
        cout << "\n";
        cout << "frame details:\n";

        Frame* last = trace.back();
        if (last->regset->size()) {
            unsigned non_empty = 0;
            for (unsigned r = 0; r < last->regset->size(); ++r) {
                if (last->regset->at(r) != 0) { ++non_empty; }
            }
            cout << "  non-empty registers: " << non_empty << '/' << last->regset->size();
            cout << (non_empty ? ":\n" : "\n");
            for (unsigned r = 0; r < last->regset->size(); ++r) {
                if (last->regset->at(r) == 0) { continue; }
                cout << "    registers[" << r << "]: ";
                cout << '<' << last->regset->get(r)->type() << "> " << last->regset->get(r)->str() << endl;
            }
        } else {
            cout << "  no registers were allocated for this frame" << endl;
        }

        if (last->args->size()) {
            cout << "  non-empty arguments (out of " << last->args->size() << "):" << endl;
            for (unsigned r = 0; r < last->args->size(); ++r) {
                if (last->args->at(r) == 0) { continue; }
                cout << "    arguments[" << r << "]: ";
                cout << '<' << last->args->get(r)->type() << "> " << last->args->get(r)->str() << endl;
            }
        } else {
            cout << "  no arguments were passed to this frame" << endl;
        }
//.........这里部分代码省略.........
开发者ID:saper,项目名称:wudoovm,代码行数:101,代码来源:cpu.cpp


注:本文中的CPU::mapfunction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。