Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/18583

Change subject: base: Add a type for keeping track of object file loaders.
......................................................................

base: Add a type for keeping track of object file loaders.

This avoids having a big pile of #if-s in sim/process.cc and allows
dynamically adding new types of object file loaders which might
recognize new arch/OS combinations.

Change-Id: Ie3b9c1aa2974d30a61afc4fcc529ffd6a74d43e0
---
M src/base/SConscript
A src/base/loader/loader.cc
A src/base/loader/loader.hh
3 files changed, 116 insertions(+), 0 deletions(-)



diff --git a/src/base/SConscript b/src/base/SConscript
index 29f87eb..114036f 100644
--- a/src/base/SConscript
+++ b/src/base/SConscript
@@ -77,6 +77,7 @@
 Source('loader/ecoff_object.cc')
 Source('loader/elf_object.cc')
 Source('loader/hex_file.cc')
+Source('loader/loader.cc')
 Source('loader/object_file.cc')
 Source('loader/raw_object.cc')
 Source('loader/symtab.cc')
diff --git a/src/base/loader/loader.cc b/src/base/loader/loader.cc
new file mode 100644
index 0000000..82c3377
--- /dev/null
+++ b/src/base/loader/loader.cc
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2019 Google, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Gabe Black
+ */
+
+#include "base/loader/loader.hh"
+
+#include <vector>
+
+namespace
+{
+
+typedef std::vector<ObjectFileLoader *> LoaderList;
+
+LoaderList &
+object_file_loaders()
+{
+    static LoaderList loaders;
+    return loaders;
+}
+
+} // anonymous namespace
+
+ObjectFileLoader::ObjectFileLoader()
+{
+    object_file_loaders().emplace_back(this);
+}
+
+Process *
+tryObjectFileLoaders(ProcessParams *params, ObjectFile *obj_file)
+{
+    for (auto &loader: object_file_loaders()) {
+        Process *p = loader->load(params, obj_file);
+        if (p)
+            return p;
+    }
+
+    return nullptr;
+}
diff --git a/src/base/loader/loader.hh b/src/base/loader/loader.hh
new file mode 100644
index 0000000..6725017
--- /dev/null
+++ b/src/base/loader/loader.hh
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2019 Google, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Gabe Black
+ */
+
+#ifndef __BASE_LOADER_LOADER_HH__
+#define __BASE_LOADER_LOADER_HH__
+
+class Process;
+class ProcessParams;
+class ObjectFile;
+
+class ObjectFileLoader
+{
+  public:
+    ObjectFileLoader();
+
+    ObjectFileLoader(const ObjectFileLoader &) = delete;
+    void operator=(const ObjectFileLoader &) = delete;
+
+    virtual ~ObjectFileLoader() {}
+
+    virtual Process *load(ProcessParams *params, ObjectFile *obj_file) = 0;
+};
+
+Process *tryObjectFileLoaders(ProcessParams *params, ObjectFile *obj_file);
+
+#endif // __BASE_LOADER_LOADER_HH__

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/18583
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Ie3b9c1aa2974d30a61afc4fcc529ffd6a74d43e0
Gerrit-Change-Number: 18583
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to