📄 serial.cc
字号:
#include <string.h>#include "assert.hh"#include "checkpoint.hh"#include "cpu.hh"#include "error.hh"#include "serial.hh"#include "sulima.hh"// The SerialType list.BasicSerialType *BasicSerialType::first = 0;// The Serializable object list. In the interest of speed, this is// kept as a circular linked-list guarded by a sintinel object.Serializable Serializable::sentinel_object(0);// The object ID generator.SerialID Serializable::id_generator = 0;// Fake "create" on objects that do not define a SimArgs constructor.Serializable *BasicSerialType::create(const SimArgs &args) const{ return 0;}// checkpoint() is pointless for the base object, but it has to be defined so// that the sentinel object is not abstract.voidSerializable::checkpoint(Checkpoint &, bool) const{ assert(UNREACHABLE);}// Serialized base constructor.Serializable::Serializable(Checkpoint &cp) : id(extract<SerialID>(cp)){ // Make sure that any existing objects won't interfere with us. if (id_generator) throw Error("A checkpoint may be restored only onto a clean system."); next_object = &sentinel_object; prev_object = sentinel_object.prev_object; next_object->prev_object = prev_object; prev_object->next_object = next_object;}// Search the SerialType list for a module with Type name (name).BasicSerialType &find_type(const char *name){ for (SerialTypeIterator i; i; ++i) if (!strcmp(i->name(), name)) return *i; throw Error("Unknown module type \"%#s\".", name);}// List all known module types for which a description string is available.SimArglist_known_modules(const SimArgs &args){ if (args.length() == 1) { if (!strcmp(args[0], "available")) { for (SerialTypeIterator i; i; ++i) { if (i->descr()[0]) { sulima->msg("%-15s %s", i->name(), i->descr()); } } return ""; } else if (!strcmp(args[0], "installed")) { for (ObjectIterator i; i; ++i) { Module *mod = dynamic_cast<Module *>(&*i); if (mod) { sulima->msg("%-20s %s", mod->name(), dynamic_cast<CPU *>(mod) ? "(CPU)" : ""); } } return ""; } } throw Error(args.length() ? "Invalid arguments to \"sim::list\"." : "Missing argument to \"sim::list\".");}// An extractor for SerialType objects.Checkpoint &operator>>(Checkpoint &cp, BasicSerialType *&type){ const char *name = extract_word(cp); try { type = &find_type(name); } catch (...) { delete name; throw; } delete name; return cp;}// Find an object with the given ID, 0 if none.Serializable *find_object(SerialID id){ for (ObjectIterator i; i; ++i) if (i->id == id) return &*i; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -