// MEMBER FUNCTION
void Trick::MemoryManager::clear_var( void* address) {

    ATTRIBUTES* reference_attr;
    ALLOC_INFO* alloc_info;

    pthread_mutex_lock(&mm_mutex);
    alloc_info = get_alloc_info_at( address);
    if (alloc_info != NULL) {
        reference_attr = make_reference_attr( alloc_info);
        if (alloc_info->type == TRICK_STRUCTURED ) {
            if (alloc_info->num_index != 0) {
                clear_arrayed_class( (char*)(alloc_info->start), reference_attr, 0, 0) ;
            } else {
                clear_class( (char*)(alloc_info->start), alloc_info->attr) ;
            }
        } else {
            clear_rvalue( alloc_info->start, reference_attr, 0, 0 );
        }
        free_reference_attr( reference_attr);
    } else {
        std::stringstream message;
        message << "Cannot clear the variable at address " << address
                << "because memory manager knows nothing about it." ;
        emitError(message.str());
    }
    pthread_mutex_unlock(&mm_mutex);
}
Esempio n. 2
0
// MEMBER FUNCTION
void Trick::MemoryManager::restore_stls( ALLOC_INFO* alloc_info ) {

    ATTRIBUTES* reference_attr;

    if (debug_level > 1) {
          std::cout << "DEBUG: Entered function:" <<  __FUNCTION__ << std::endl;
    }

    if (alloc_info == NULL) {
        std::cout << "ERROR: Trick::MemoryManager::restore_stls called with alloc_info == NULL." << std::endl;
        std::cout.flush();
        return;
    }

    // If there is no name associated with this alloc_info, we won't be able to find any stls associated with it.
    if (alloc_info->name == NULL) {
        return;
    }

    if (debug_level) {
        std::cout << __FUNCTION__ <<  ": Begin scan of allocation @" << (void*)alloc_info->start << " for dependencies." << std::endl;
    }

    reference_attr = make_reference_attr( alloc_info );

    // Get the dependencies of the allocation
    if (alloc_info->type == TRICK_STRUCTURED) {
        if (reference_attr->num_index > 0) {
            restore_stls_in_arrayed_class(alloc_info->name, (char*)(alloc_info->start), reference_attr, 0, 0) ;
        } else {
            restore_stls_in_class(alloc_info->name, (char*)(alloc_info->start), alloc_info->attr) ;
        }
    } else {
        restore_stls_in_intrinsic(alloc_info->name, alloc_info->start, reference_attr, 0, 0 );
    }

    if (debug_level) {
        std::cout <<  __FUNCTION__ << ": End scan of allocation @" << (void*)alloc_info->start << "." << std::endl;
    }

    free_reference_attr( reference_attr );

}