From 3f99e854a54fb62414a2cfcb44a1b7233c71ccac Mon Sep 17 00:00:00 2001
From: whh8b <whh8b@git.zephyr-software.com>
Date: Fri, 21 Aug 2015 03:17:39 +0000
Subject: [PATCH] Update ZiprSDK API so plugins can plop insns

---
 .gitattributes        |  1 +
 include/zipr.h        | 69 +++++++++++++++++++++++++++++++++++++++++++
 include/zipr_plugin.h | 22 ++++++++++++--
 include/zipr_sdk.h    |  1 +
 4 files changed, 91 insertions(+), 2 deletions(-)
 create mode 100644 include/zipr.h

diff --git a/.gitattributes b/.gitattributes
index bfd0c26..14ce7d7 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -3,6 +3,7 @@
 /SDK_VERSION -text
 include/memory_space.h -text
 include/range.h -text
+include/zipr.h -text
 include/zipr_options.h -text
 include/zipr_plugin.h -text
 include/zipr_sdk.h -text
diff --git a/include/zipr.h b/include/zipr.h
new file mode 100644
index 0000000..c8a7e86
--- /dev/null
+++ b/include/zipr.h
@@ -0,0 +1,69 @@
+/***************************************************************************
+ * Copyright (c)  2014  Zephyr Software LLC. All rights reserved.
+ *
+ * This software is furnished under a license and/or other restrictive
+ * terms and may be used and copied only in accordance with such terms
+ * and the inclusion of the above copyright notice. This software or
+ * any other copies thereof may not be provided or otherwise made
+ * available to any other person without the express written consent
+ * of an authorized representative of Zephyr Software LCC. Title to,
+ * ownership of, and all rights in the software is retained by
+ * Zephyr Software LCC.
+ *
+ * Zephyr Software LLC. Proprietary Information
+ *
+ * Unless otherwise specified, the information contained in this
+ * directory, following this legend, and/or referenced herein is
+ * Zephyr Software LLC. (Zephyr) Proprietary Information. 
+ *
+ * CONTACT
+ *
+ * For technical assistance, contact Zephyr Software LCC. at:
+ *      
+ *
+ * Zephyr Software, LLC
+ * 2040 Tremont Rd
+ * Charlottesville, VA 22911
+ *
+ * E-mail: jwd@zephyr-software.com
+ **************************************************************************/
+
+#ifndef zipr_h
+#define zipr_h
+
+class Zipr_t
+{
+	public:
+		Zipr_t() {}; 
+
+	protected:
+		/*
+		 * Private, but listing them here so that SDK users
+		 * can get a sense of the overall flow of the rewriter.
+		 */
+		virtual void FindFreeRanges(const std::string &name) = 0;
+		virtual void AddPinnedInstructions() = 0;
+		virtual void ReservePinnedInstructions() = 0;
+		virtual void PreReserve2ByteJumpTargets() = 0;
+		virtual void ExpandPinnedInstructions() = 0;
+		virtual void Fix2BytePinnedInstructions() = 0;
+		virtual void OptimizePinnedInstructions() = 0;
+		virtual void OptimizePinnedFallthroughs() = 0;
+		virtual void AskPluginsAboutPlopping() = 0;
+		virtual void PlopTheUnpinnedInstructions() = 0;
+		virtual void UpdateCallbacks() = 0;
+		virtual void PrintStats() = 0;
+		virtual void RecordPinnedInsnAddrs() = 0;
+	
+	public:
+		/*
+		 * These are public functions that the SDK user
+		 * way want to use.
+		 */
+		virtual int DetermineWorstCaseInsnSize(libIRDB::Instruction_t*) = 0;
+		virtual Zipr_SDK::RangeAddress_t PlopInstruction(libIRDB::Instruction_t* insn, Zipr_SDK::RangeAddress_t addr) = 0;
+		virtual Zipr_SDK::RangeAddress_t PlopWithTarget(libIRDB::Instruction_t* insn, Zipr_SDK::RangeAddress_t at) = 0;
+		virtual Zipr_SDK::RangeAddress_t PlopWithCallback(libIRDB::Instruction_t* insn, Zipr_SDK::RangeAddress_t at) = 0;
+};
+
+#endif
diff --git a/include/zipr_plugin.h b/include/zipr_plugin.h
index 534c7ab..1cc84b0 100644
--- a/include/zipr_plugin.h
+++ b/include/zipr_plugin.h
@@ -1,8 +1,6 @@
 
-
 namespace Zipr_SDK
 {
-
 typedef std::map<libIRDB::Instruction_t*,Zipr_SDK::RangeAddress_t> InstructionLocationMap_t;
 
 class ZiprPluginInterface_t
@@ -15,6 +13,26 @@ class ZiprPluginInterface_t
 		virtual void CallbackLinkingBegin()=0;
 		virtual void CallbackLinkingEnd()=0;
 
+		virtual bool WillPluginPlop(libIRDB::Instruction_t*)
+		{
+			return false;
+		}
+		virtual int WorstCaseInsnSize(libIRDB::Instruction_t*, Zipr_t *)
+		{
+			return 0;
+		}
+		virtual RangeAddress_t PlopInstruction(libIRDB::Instruction_t*,
+			RangeAddress_t,
+			RangeAddress_t &,
+			Zipr_t *)
+		{
+			return 0;
+		}
+
+		virtual std::string ToString()
+		{
+			return "NamelessPlugin";
+		}
 };
 
 }
diff --git a/include/zipr_sdk.h b/include/zipr_sdk.h
index 13944cf..e9ca4ca 100644
--- a/include/zipr_sdk.h
+++ b/include/zipr_sdk.h
@@ -48,6 +48,7 @@
 
 // SDK internals
 #include <range.h>
+#include <zipr.h>
 #include <memory_space.h>
 #include <zipr_options.h>
 #include <zipr_plugin.h>
-- 
GitLab