trick/trick_source/sim_services/include/mm_macros.hh
Alex Lin 14a75508a3 Cleaning up once include variables and copyright cleanup.
Changed all header file once include variables to follow the same naming
convention and not start with any underscores.  Also deleted old
incorrect copyright notices.  Also removed $Id: tags from all files.

Fixes #14.  Fixes #22.
2015-03-23 16:03:14 -05:00

48 lines
2.1 KiB
C++

#ifndef MM_MACORS_HH
#define MM_MACORS_HH
#include <stdlib.h>
#include <new>
#include "sim_services/MemoryManager/include/memorymanager_c_intf.h"
#include "sim_services/MemoryManager/include/MemoryManager.hh"
#ifdef SWIG
#define TRICK_MM_FRIENDS(class_name_with_underscores)
#define TRICK_MM_INTERFACE(class_name, class_name_with_underscores)
#else
#define TRICK_MM_FRIENDS(class_name_with_underscores) \
friend class InputProcessor; \
friend void init_attr ## class_name_with_underscores();
// The delete operators test to see if the pointer exists in the memory manager before calling
// TMM_delete_var_a. This was done to avoid this recursive call sequence
// TMM_delete_var_a -> io_src_delete_class -> io_src_delete_<class_name> -> delete -> TMM_delete_var_a
#define TRICK_MM_INTERFACE(class_name, class_name_with_underscores) \
friend class InputProcessor; \
friend void init_attr ## class_name_with_underscores(); \
public: \
static void* operator new (size_t size, const char * alloc_name = "" ) { \
void * new_ptr = calloc( 1, size ) ; \
TMM_declare_ext_var(new_ptr, TRICK_STRUCTURED,#class_name, 0, alloc_name, 0, NULL) ; \
return new_ptr ; \
} ; \
static void* operator new[] (size_t size, const char * alloc_name = "" ) { \
void * new_ptr = calloc( 1, size ) ; \
TMM_declare_ext_var(new_ptr, TRICK_STRUCTURED,#class_name, 0, alloc_name , 0, NULL) ; \
return new_ptr ; \
} ; \
static void* operator new (size_t size __attribute__((unused)), class_name * addr, const char * alloc_name = "") { \
TMM_declare_ext_var(addr, TRICK_STRUCTURED,#class_name, 0, alloc_name, 0, NULL) ; \
return addr ; \
} ; \
static void operator delete (void *p) { \
if ( get_alloc_info_at(p) ) { trick_MM->delete_var(p, false) ; free(p) ; } \
} ; \
static void operator delete[] (void *p) { \
if ( get_alloc_info_at(p) ) { trick_MM->delete_var(p, false) ; free(p) ; } \
} ;
#endif
#endif