let command line define flags optionally
[repair.git] / Repair / RepairCompiler / MCC / CRuntime / tmap.c
index 25c326d9068fcbfce731172d1d9170aff7a6e5ba..bf03f04bada39ac855dcc5750b59d1d9e0b60708 100755 (executable)
@@ -4,8 +4,10 @@
 #include "stack.h"
 #include <stdlib.h>
 
+#ifndef COMMANDLINEFLAGS
 #define CHECKTYPE
 #define CHECKMEMORY
+#endif
 
 struct typemap * allocatetypemap() {
   struct typemap *thisvar=(struct typemap *) malloc(sizeof(struct typemap));
@@ -80,6 +82,26 @@ bool typemapassertvalidmemory(struct typemap * thisvar, void* low, int s) {
   return typemapassertvalidmemoryB(thisvar, low,((char *)low)+toadd);
 }
 
+bool typemapassertexactmemory(struct typemap * thisvar, void* low, int s) {
+  int toadd=sizeBytes(s);
+#ifdef CHECKMEMORY
+  {
+    void * high=((char *)low)+toadd;
+    struct pair allocp=rbfind(low,high,thisvar->alloctree);
+    if (allocp.low == NULL) {
+      return false;
+    } else if ((allocp.low != low) || (allocp.high != high)) {
+    /* make sure this block exactly lines up */
+      return false;
+    } else {
+      return true;
+    }
+  }
+#else
+  return true;
+#endif
+}
+
 bool typemapassertvalidmemoryB(struct typemap * thisvar, void* low, void* high) {
 #ifdef CHECKMEMORY
   return typemapcheckmemory(thisvar, low, high);
@@ -161,6 +183,17 @@ bool typemapcheckmemory(struct typemap *thisvar, void* low, void* high) {
   }
 }
 
+void * typemapgetendofblock(struct typemap *thisvar, void* low) {
+  struct pair allocp=rbfind(low,((char*)low)+1,thisvar->alloctree);
+  if (allocp.low == NULL) {
+    return NULL;
+  } else if ((allocp.low > low)||(allocp.high <= allocp.low)) { /* make sure this block is used */
+    return NULL;
+  } else {
+    return (void *)allocp.high;
+  }
+}
+
 
 bool typemapchecktype(struct typemap *thisvar, bool doaction,void *ptr, int structure) {
   int ssize=sizeBytes(structure);