Exemplo n.º 1
0
void
codegen_init_data()
{
  codegen_write_comment("declarations");

  if (state.section.udata) {
    if (state.section.udata_addr_valid) {
      fprintf(state.output.f, "%s udata %#x\n", 
              state.section.udata,
              state.section.udata_addr);
    } else {
      fprintf(state.output.f, "%s udata\n", state.section.udata);
    }
  } else {
    if (state.section.udata_addr_valid) {
      fprintf(state.output.f, ".udata_%s udata %#x\n",
              FILE_NAME(state.module),
              state.section.udata_addr);
    } else {
      fprintf(state.output.f, ".udata_%s udata\n", FILE_NAME(state.module));
    }  
  }

  codegen_write_label(LOCAL_DATA_LABEL);
  
}
Exemplo n.º 2
0
void
codegen_init_asm()
{
  char buffer[BUFSIZ];

  /* open output filename */
  strncpy(state.asmfilename, state.basefilename, sizeof(state.asmfilename));
  strncat(state.asmfilename, ".asm", sizeof(state.asmfilename));
  state.output.f = fopen(state.asmfilename, "w");
  if (state.output.f == NULL) {
    perror(state.asmfilename);
    exit(1);
  }

  label_number = 0;
  max_temp_number = 0;
  codegen_working_bytes = 1;
  codegen_size = size_uint8;
  codegen_bytes = prim_size(codegen_size);

  gp_date_string(buffer, sizeof(buffer));

  fprintf(state.output.f, "; %s\n", state.asmfilename);
  fprintf(state.output.f, "; generated by %s on %s\n\n",
          GPAL_VERSION_STRING,
          buffer);

  fprintf(state.output.f, "#file \"%s\"\n\n", state.srcfilename);

  if (state.processor_chosen) {
    fprintf(state.output.f, "  processor %s\n", 
            state.processor_info->names[1]);
    fprintf(state.output.f, "  include \"%s.inc\"\n\n",
            state.processor_info->names[1]);
  } else {
    gp_error("processor not selected");
  } 

  if (state.section.code) {
    if (state.section.code_addr_valid) {
      fprintf(state.output.f, "%s code %#x\n", 
              state.section.code,
              state.section.code_addr);
    } else {
      fprintf(state.output.f, "%s code\n", state.section.code);
    }
  } else {
    if (state.section.code_addr_valid) {
      fprintf(state.output.f, ".code_%s code %#x\n", 
              FILE_NAME(state.module),
              state.section.code_addr);
    } else {
      fprintf(state.output.f, ".code_%s code\n", FILE_NAME(state.module));
    }
  }

  return;
}
/*
*	\brief	Release all memory and destroy all memory nuggets
*/
void CNotAmnesia::Shutdown()
{
	MemoryNugget *freeNugget = m_freeNugget;
	while (freeNugget != nullptr)
	{
		MemoryNugget *const prevNugget = freeNugget->prevNugget;
		A_DELETE(freeNugget);
		freeNugget = prevNugget;
	}
	m_freeNugget = nullptr;

#ifndef OPTIMIZED
	int noofLeakedNuggets = 0;
#endif

	MemoryNugget *nugget = m_lastNugget;
	while (nugget != nullptr)
	{
#ifndef OPTIMIZED
		noofLeakedNuggets++;
		std::stringstream buf;
		buf << "Memory leak detected in " << FILE_NAME(nugget->file.c_str()) << " (" << nugget->line << ")";
		m_statusTextList.push_back(buf.str().c_str());
#endif
		nugget = nugget->prevNugget;
	}

#ifndef OPTIMIZED
	if (noofLeakedNuggets != 0)
	{
		m_statusTextList.push_front("Memory Leaks Detected");
		if (noofLeakedNuggets != 2)
			m_statusTextList.push_front("More than 2 leaks, this should not happed");
	}
#endif

	nugget = m_lastNugget;
	while (nugget != nullptr)
	{
		MemoryNugget *const prevNugget = nugget->prevNugget;
		A_DELETE(nugget);
		nugget = prevNugget;
	}
	m_lastNugget = nullptr;

	A_DELETE(m_startPtr);
	m_startPtr = nullptr;

	m_totalSize = 0;
	m_amountAllocated = 0;

	#ifndef OPTIMIZED
		m_noofNuggets = 0;
		m_noofFreeNuggets = 0;
	#endif
}
Exemplo n.º 4
0
void
codegen_temp_data()
{
  int i;

  /* extended math used so a working register is required */
  if (codegen_working_bytes != 1) {  
    codegen_write_label(WORKING_LABEL);
  }

  for (i = 0; i < max_temp_number; i++) 
    fprintf(state.output.f, "_%s_temp_%d res 1\n", FILE_NAME(state.module), i);

}
Exemplo n.º 5
0
char *
codegen_get_temp(enum size_tag size)
{
  char temp_name[BUFSIZ];
 
  snprintf(temp_name,
           sizeof(temp_name),
           "_%s_temp_%d",
           FILE_NAME(state.module),
           temp_number);

  temp_number += prim_size(size);

  return strdup(temp_name);
}
Exemplo n.º 6
0
void GEN_CSV_WRITER::openCSVFile(){
  QO() = false;
  if(0 == m_pstCSVFile){
    m_pstCSVFile = fopen(FILE_NAME().getValue(), "w+");
    if(0 != m_pstCSVFile){
      STATUS() = "OK";
      QO() = true;
    }
    else{
      STATUS() = strerror(errno);
    }
  }
  else{
    STATUS() = "File already open";
  }
}
Exemplo n.º 7
0
int
main(int argc, char **argv) {
  // Try block to detect exceptions raised by any of the calls inside it
  try {
    // Turn off the auto-printing when failure occurs so that we can
    // handle the errors appropriately
    H5std_string FILE_NAME(argv[1]);
    Exception::dontPrint();

    // Open the file and the dataset in the file.
    H5File file(FILE_NAME, H5F_ACC_RDONLY);

    DataSet dataset;
    H5std_string dataset_name;
    auto objCount(H5Fget_obj_count(file.getId(), H5F_OBJ_ALL));
    for (size_t i = 0; i != objCount; ++i)
      if (H5G_DATASET == file.getObjTypeByIdx(i)) {
	dataset_name = file.getObjnameByIdx(i);
	dataset = file.openDataSet(dataset_name);
      }

    auto datatype(dataset.getDataType());
    auto dataspace(dataset.getSpace());

    hsize_t dims_in[2];
    auto ndims(dataspace.getSimpleExtentDims(dims_in, NULL));

    hsize_t dims_out[2] = { DIM0, DIM1 };	// dataset dimensions

    double *buf = new double[dims_in[0] * dims_in[1]];

    // Read data.
    dataset.read(buf, PredType::NATIVE_DOUBLE);//, memspace, dataspace);

    H5std_string outFileName("out.h5");

    // Create a new file using the default property lists. 
    H5File outfile(outFileName, H5F_ACC_TRUNC);

    // Create the data space for the dataset.
    DataSpace *output_dataspace = new DataSpace(ndims, dims_out);

    hsize_t chunk_dims[2] = { 20, 20 };	// chunk dimensions
    // Modify dataset creation property to enable chunking
    DSetCreatPropList *plist = new DSetCreatPropList;
    plist->setChunk(2, chunk_dims);

    // Set ZLIB (DEFLATE) Compression using level 9.
    plist->setDeflate(9);

    // Create the attributes.
    const size_t numAttrs = file.getNumAttrs();
    for (size_t i = 0; i != numAttrs; ++i) {
      auto attr(file.openAttribute(i));
      auto output_attr(outfile.createAttribute(attr.getName(), 
					       attr.getDataType(), 
					       attr.getSpace()));

      switch (attr.getTypeClass()) {
      case H5T_FLOAT: {
	double buf;
    	attr.read(attr.getDataType(), &buf);
    	output_attr.write(attr.getDataType(), &buf);
      }
	break;
      case H5T_STRING: {
	char *buf = new char[(unsigned long)attr.getStorageSize()];
    	attr.read(attr.getDataType(), buf);
    	output_attr.write(attr.getDataType(), buf);
	delete buf;
      }
	break;
      default:
	break;
      }
    }

    // Create the dataset.      
    DataSet *output_dataset = new DataSet(outfile.createDataSet(dataset_name, datatype, *output_dataspace, *plist));

    // Write data to dataset.
    output_dataset->write(buf, datatype);

    // Close objects and file.  Either approach will close the HDF5 item.
    delete output_dataspace;
    delete output_dataset;
    delete plist;
    file.close();
  }  // end of try block

  // catch failure caused by the H5File operations
  catch(FileIException &error) {
    error.printError();
    return -1;
  }

  // catch failure caused by the DataSet operations
  catch(DataSetIException &error) {
    error.printError();
    return -1;
  }

  // catch failure caused by the DataSpace operations
  catch(DataSpaceIException &error) {
    error.printError();
    return -1;
  }

  // catch failure caused by the Attribute operations
  catch (AttributeIException &error) {
    error.printError();
    return -1;
  }

  catch (std::exception &error) {
    std::cerr << error.what() << std::endl;
    return -1;
  }

  return 0;  // successfully terminated
}