Пример #1
0
void Model::draw(int ranges) const
{
	if (!vbuffer)
		read_file();

	glBindBuffer(GL_ARRAY_BUFFER, vbuffer);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibuffer);

	const junk::element& vertex = data_set->get_element("vertex");

	bool vertex_array = false;
	bool normal_array = false;
	bool color_array = false;

	BOOST_FOREACH(const junk::attribute& attr, vertex.attributes)
	{
		if (attr.name == "position")
		{
			vertex_array = true;
			glEnableClientState(GL_VERTEX_ARRAY);
			glVertexPointer(attr.size, gl_type(attr.type), size_in_bytes(vertex), (const GLvoid*) attr.offset);
		}
		else if (attr.name == "normal")
		{
			normal_array = true;
			glEnableClientState(GL_NORMAL_ARRAY);
			glNormalPointer(gl_type(attr.type), size_in_bytes(vertex), (const GLvoid*) attr.offset);
		}
		else if (attr.name == "color")
		{
			color_array = true;
			glEnableClientState(GL_COLOR_ARRAY);
			glColorPointer(attr.size, gl_type(attr.type), size_in_bytes(vertex), (const GLvoid*) attr.offset);
		}
	}

	std::size_t faces = data_set->get_size("face");

	for (int i = 0; i < ranges; ++i)
	{
		int frag = faces / ranges;
		int size = ((i + 1) * (frag + 1) * 3) - (i * frag * 3);
		GLvoid* index = (char*) NULL + (i * frag * 3 * sizeof(unsigned int));

		set_color(float(i) / float(ranges));
		glDrawElements(GL_TRIANGLES, size, GL_UNSIGNED_INT, index);
	}

	if (vertex_array)
		glDisableClientState(GL_VERTEX_ARRAY);

	if (normal_array)
		glDisableClientState(GL_NORMAL_ARRAY);

	if (color_array)
		glDisableClientState(GL_COLOR_ARRAY);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
}
Пример #2
0
void ImplicitExceptionTable::copy_to( nmethod* nm ) {
  assert(size_in_bytes() <= nm->nul_chk_table_size(), "size of space allocated in nmethod incorrect");
  if (len() != 0) {
    implicit_null_entry* nmdata = (implicit_null_entry*)nm->nul_chk_table_begin();
    // store the length in the first uint
    nmdata[0] = _len;
    nmdata++;
    // copy the table after the length
    memmove( nmdata, _data, 2 * len() * sizeof(implicit_null_entry));
  } else {
    // zero length table takes zero bytes
    assert(size_in_bytes() == 0, "bad size");
    assert(nm->nul_chk_table_size() == 0, "bad size");
  }
}
Пример #3
0
/// grow_pod - This is an implementation of the grow() method which only works
/// on POD-like datatypes and is out of line to reduce code duplication.
    void SmallVectorBase::grow_pod(size_t MinSizeInBytes, size_t TSize)
    {
        size_t CurSizeBytes = size_in_bytes();
        size_t NewCapacityInBytes = 2 * capacity_in_bytes() + TSize; // Always grow.
        if (NewCapacityInBytes < MinSizeInBytes)
            NewCapacityInBytes = MinSizeInBytes;

        void *NewElts;
        if (this->isSmall())
        {
            NewElts = malloc(NewCapacityInBytes);

            // Copy the elements over.  No need to run dtors on PODs.
            memcpy(NewElts, this->BeginX, CurSizeBytes);
        }
        else
        {
            // If this wasn't grown from the inline copy, grow the allocated space.
            NewElts = realloc(this->BeginX, NewCapacityInBytes);
        }

        this->EndX = (char*)NewElts+CurSizeBytes;
        this->BeginX = NewElts;
        this->CapacityX = (char*)this->BeginX + NewCapacityInBytes;
    }
Пример #4
0
static tree
do_allocate_exception (tree type)
{
  tree fn;

  fn = get_identifier ("__cxa_allocate_exception");
  if (!get_global_value_if_present (fn, &fn))
    {
      /* Declare void *__cxa_allocate_exception(size_t) throw().  */
      fn = declare_library_fn (fn, ptr_type_node, size_type_node,
			        ECF_NOTHROW | ECF_MALLOC);

      if (flag_tm)
	{
	  tree fn2 = get_identifier ("_ITM_cxa_allocate_exception");
	  if (!get_global_value_if_present (fn2, &fn2))
	    fn2 = declare_library_fn (fn2, ptr_type_node,
				      size_type_node, 
				      ECF_NOTHROW | ECF_MALLOC | ECF_TM_PURE);
	  record_tm_replacement (fn, fn2);
	}
    }

  return cp_build_function_call_nary (fn, tf_warning_or_error,
				      size_in_bytes (type), NULL_TREE);
}
Пример #5
0
// generate buffer for instance data
GLuint gen_instance_buf(const std::vector<glm::vec2>& v) {
    GLuint inst_vbo;
    glGenBuffers(1, &inst_vbo);
    glBindBuffer(GL_ARRAY_BUFFER, inst_vbo);
    glBufferData(GL_ARRAY_BUFFER, size_in_bytes(v), v.data(), GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    return inst_vbo;
}
Пример #6
0
inline void HandleMark::pop_and_restore() {
  HandleArea* area = _area;   // help compilers with poor alias analysis
  // Delete later chunks
  if( _chunk->next() ) {
    // reset arena size before delete chunks. Otherwise, the total
    // arena size could exceed total chunk size
    assert(area->size_in_bytes() > size_in_bytes(), "Sanity check");
    area->set_size_in_bytes(size_in_bytes());
    _chunk->next_chop();
  } else {
    assert(area->size_in_bytes() == size_in_bytes(), "Sanity check");
  }
  // Roll back arena to saved top markers
  area->_chunk = _chunk;
  area->_hwm = _hwm;
  area->_max = _max;
  debug_only(area->_handle_mark_nesting--);
}
Пример #7
0
void ExceptionHandlerTable::print() const {
  tty->print_cr("ExceptionHandlerTable (size = %d bytes)", size_in_bytes());
  int i = 0;
  while (i < _length) {
    HandlerTableEntry* t = _table + i;
    print_subtable(t);
    // advance to next subtable
    i += t->len() + 1; // +1 for header
  }
}
Пример #8
0
Arena *Arena::move_contents(Arena *copy) {
  copy->destruct_contents();
  copy->_chunk = _chunk;
  copy->_hwm   = _hwm;
  copy->_max   = _max;
  copy->_first = _first;
  copy->set_size_in_bytes(size_in_bytes());
  // Destroy original arena
  reset();
  return copy;            // Return Arena with contents
}
Пример #9
0
// returns the size of a  point/face/...
std::size_t size_in_bytes(const element& e)
{
	std::size_t size = 0;

	BOOST_FOREACH(const attribute& attr, e.attributes)
	{
		size += size_in_bytes(attr);
	}

	return size;
}
Пример #10
0
ImplicitExceptionTable::ImplicitExceptionTable(const nmethod* nm) {
  if (nm->nul_chk_table_size() == 0) {
    _len = 0;
    _data = NULL;
  } else {
    // the first word is the length if non-zero, so read it out and
    // skip to the next word to get the table.
    _data  = (implicit_null_entry*)nm->nul_chk_table_begin();
    _len = _data[0];
    _data++;
  }
  _size = len();
  assert(size_in_bytes() <= nm->nul_chk_table_size(), "size of space allocated in nmethod incorrect");
}
Пример #11
0
static tree
do_allocate_exception (tree type)
{
  if (!allocate_exception_fn)
    /* Declare void *__cxa_allocate_exception(size_t) throw().  */
    allocate_exception_fn
      = declare_library_fn ("__cxa_allocate_exception",
			    ptr_type_node, size_type_node,
			    ECF_NOTHROW | ECF_MALLOC, ECF_TM_PURE);

  return cp_build_function_call_nary (allocate_exception_fn,
				      tf_warning_or_error,
				      size_in_bytes (type), NULL_TREE);
}
Пример #12
0
//------------------------------grow-------------------------------------------
// Grow a new Chunk
void* Arena::grow( size_t x ) {
    // Get minimal required size.  Either real big, or even bigger for giant objs
    size_t len = max(x, Chunk::size);

    register Chunk *k = _chunk;   // Get filled-up chunk address
    _chunk = new (len) Chunk(len);

    if( k ) k->_next = _chunk;    // Append new chunk to end of linked list
    else _first = _chunk;
    _hwm  = _chunk->bottom();     // Save the cached hwm, max
    _max =  _chunk->top();
    set_size_in_bytes(size_in_bytes() + len);
    void* result = _hwm;
    _hwm += x;
    return result;
}
Пример #13
0
static tree
do_allocate_exception (tree type)
{
  tree fn;

  fn = get_identifier ("__cxa_allocate_exception");
  if (!get_global_value_if_present (fn, &fn))
    {
      /* Declare void *__cxa_allocate_exception(size_t).  */
      tree tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
      fn = push_library_fn (fn, build_function_type (ptr_type_node, tmp));
    }
  
  return build_function_call (fn, tree_cons (NULL_TREE, size_in_bytes (type),
					     NULL_TREE));
}
static tree
do_allocate_exception (tree type)
{
  tree fn;

  fn = get_identifier ("__cxa_allocate_exception");
  if (!get_global_value_if_present (fn, &fn))
    {
      /* Declare void *__cxa_allocate_exception(size_t) throw().  */
      fn = declare_nothrow_library_fn (fn, ptr_type_node, size_type_node);
    }

  return cp_build_function_call (fn, 
				 tree_cons (NULL_TREE, size_in_bytes (type),
					    NULL_TREE),
				 tf_warning_or_error);
}
Пример #15
0
/*
 * Generate objects like Vertex Array Objects, Vertex Buffer Object using
 * pointer to std::vector (trying to achieve more general solution)
 */
void gen_objects_base(GLuint &vao, GLuint &vbo, const std::vector<GLfloat> &v,
        const GLuint stride, const GLuint offset) {
    glGenVertexArrays(1, &vao);
    glGenBuffers(1, &vbo);

    glBindVertexArray(vao);

    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, size_in_bytes(v), v.data(), GL_STATIC_DRAW);

    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, stride * sizeof(GLfloat),
            0);

    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,
            stride * sizeof(GLfloat), (GLvoid*)(offset * sizeof(GLfloat)));
}
Пример #16
0
// Grow a new Chunk
void* Arena::grow( size_t x ) {
  // Get minimal required size.  Either real big, or even bigger for giant objs
  size_t len = MAX2(x, (size_t) Chunk::size);

  Chunk *k = _chunk;            // Get filled-up chunk address
  _chunk = new (len) Chunk(len);

  if (_chunk == NULL)
      vm_exit_out_of_memory(len * Chunk::aligned_overhead_size(), "Arena::grow");

  if (k) k->set_next(_chunk);   // Append new chunk to end of linked list
  else _first = _chunk;
  _hwm  = _chunk->bottom();     // Save the cached hwm, max
  _max =  _chunk->top();
  set_size_in_bytes(size_in_bytes() + len);
  void* result = _hwm;
  _hwm += x;
  return result;
}
Пример #17
0
void
mudflap_enqueue_constant (tree obj)
{
  tree object_size, varname;

  if (mf_marked_p (obj))
    return;

  if (TREE_CODE (obj) == STRING_CST)
    object_size = build_int_cst (NULL_TREE, TREE_STRING_LENGTH (obj));
  else
    object_size = size_in_bytes (TREE_TYPE (obj));

  if (TREE_CODE (obj) == STRING_CST)
    varname = mf_build_string ("string literal");
  else
    varname = mf_build_string ("constant");

  mudflap_register_call (obj, object_size, varname);
}
Пример #18
0
static tree
init_module_descriptor (tree type, long vers)
{
  tree expr, ltyp;
  location_t loc;
  vec<constructor_elt, va_gc> *v = NULL;

  /* No really useful place to point to.  */
  loc = UNKNOWN_LOCATION;

  /* version = { 1, ... } */

  expr = build_int_cst (long_integer_type_node, vers);
  CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr);

  /* size = { ..., sizeof (struct _objc_module), ... } */

  expr = convert (long_integer_type_node,
		  size_in_bytes (objc_module_template));
  CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr);

  /* Don't provide any file name for security reasons. */
  /* name = { ..., "", ... } */

  expr = add_objc_string (get_identifier (""), class_names);
  CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr);

  /* symtab = { ..., _OBJC_SYMBOLS, ... } */

  ltyp = build_pointer_type (xref_tag (RECORD_TYPE,
				       get_identifier (UTAG_SYMTAB)));
  if (UOBJC_SYMBOLS_decl)
    expr = convert (ltyp, build_unary_op (loc,
			   ADDR_EXPR, UOBJC_SYMBOLS_decl, 0));
  else
    expr = convert (ltyp, null_pointer_node);
  CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr);

  return objc_build_constructor (type, v);
}
Пример #19
0
// set transformation matrices as an instance vertex attribute
void bind_mat4(Model& m, const std::vector<glm::mat4>& v) {
    for (GLuint i {0}; i < m.num_meshes(); ++i) {
        glBindVertexArray(m.mesh_vao(i));

        GLuint buf;
        glGenBuffers(1, &buf);

        glBindBuffer(GL_ARRAY_BUFFER, buf);
        glBufferData(GL_ARRAY_BUFFER, size_in_bytes(v), v.data(),
                GL_STATIC_DRAW);

        const auto mat4_size = sizeof(glm::mat4);
        const auto vec4_size = sizeof(glm::vec4);

        glEnableVertexAttribArray(3);
        glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, mat4_size,
                (GLvoid*)(0));

        glEnableVertexAttribArray(4);
        glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, mat4_size,
                (GLvoid*)(vec4_size));

        glEnableVertexAttribArray(5);
        glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, mat4_size,
                (GLvoid*)(vec4_size << 1));

        glEnableVertexAttribArray(6);
        glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, mat4_size,
                (GLvoid*)(3 * vec4_size));

        glVertexAttribDivisor(3, 1);
        glVertexAttribDivisor(4, 1);
        glVertexAttribDivisor(5, 1);
        glVertexAttribDivisor(6, 1);

        glBindVertexArray(0);
    }
}
Пример #20
0
int main(int argc, char *argv[]) {
	ParamProgram *par = new ParamProgram();
	char fileName[300];

	if(argc != 2){
		cout << "ERRORR !! " << endl;
		cout << "buildDL_LZ's usage requires the Properties File as parameter !! " << endl;
		cout << "Example for the file 'config.txt' in the same directory: ./buildDL_LZ config.txt" << endl;
		exit(1);
	}
	par->configFile = string(argv[1]);
	cout << "Congif file: " << par->configFile << endl;
	ConfigFile cf(par->configFile);

	TRACE = cf.Value("GLOBALS","TRACE");
	TEST = cf.Value("GLOBALS","TEST");
	N_REP = cf.Value("GLOBALS","N_REP");

	strcpy(par->inputFile, ((string)(cf.Value("DL","inputFile"))).c_str());
	par->filesInList = cf.Value("DL","filesInList");
	par->boundSymbol = cf.Value("DL","boundSymbol");
	par->cutDoc = cf.Value("DL","cutDoc");
	par->lowercase = cf.Value("DL","lowercase");
	par->levRMQ_range = cf.Value("DL","levRMQ");
	strcpy(par->dirStore, ((string)(cf.Value("DL","dirStore"))).c_str());

	cout << "buildDL_LZ config parameters..." << endl;
	cout << "Input File            : " << par->inputFile << endl;
	cout << "File in list          : " << par->filesInList << endl;
	cout << "Boundary Symbol(code) : " << (int)par->boundSymbol << endl;
	cout << "Cut Doc. Symbol(code) : " << (int)par->cutDoc << endl;
	cout << "Lowercase             : " << par->lowercase << endl;
	cout << "Range levels with RMQ : " << par->levRMQ_range << endl;
	cout << "Store Folder          : " << par->dirStore << endl;

	LZDocList64::TRACE = TRACE;
	LZDocList64::TEST = TEST;
	par->index = new LZDocList64(par->levRMQ_range, par->inputFile, par->filesInList, par->cutDoc, par->lowercase, par->dirStore, par->boundSymbol, false);
	par->n = par->index->n;
	par->EndDocs = par->index->EndDocs;
	cout << "____________________________________________________" << endl;
	cout << "***  Index size " << par->index->sizeDS << " bytes = " << (float)par->index->sizeDS*8.0/(float)par->n << " bpc" << endl;
	cout << "***  SizeUpRange = " << par->index->sizeUpRange << " bytes = " << (float)par->index->sizeUpRange*8.0/(float)par->n << " bpc" << endl;
	cout << "====================================================" << endl;

	par->index->saveDS(true);

	{
		// create the FMI to execute test...
		cout << "____________________________________________________" << endl;
		cout << " Make the FMI ..." << endl;
		strcpy(fileName, "");
		strcpy(fileName, par->inputFile);
		cout << " Reading... " << fileName << endl;
		strcat(fileName, "_copy.txt");
		construct(par->index->fmi, fileName, 1); // generate index
		cout << " **  FMI size " << size_in_bytes(par->index->fmi) << " bytes = " << (float)size_in_bytes(par->index->fmi)/(float)par->n << "|T|" << endl;
		cout << " **  FMI length " << par->index->fmi.size() << endl;
		if (par->index->fmi.size() != par->n){
			cout << "ERROR. FMI length != n = " << par->n << endl;
			exit(1);
		}
		strcpy(fileName, "");
		strcpy(fileName, par->dirStore);
		strcat(fileName, "fmi.test");
		store_to_file(par->index->fmi, fileName);
	}

	if (TEST){
		strcpy(fileName, "");
		strcpy(fileName, par->dirStore);
		strcat(fileName, "EndDocs.test");
		ofstream os2 (fileName, ios::binary);
		os2.write((const char*)par->EndDocs, par->index->nDocs*sizeof(ulong));					// save LbRev[]
		if(TRACE) cout << " .- EndDocs[] " << par->index->nDocs*sizeof(ulong) << " Bytes" << endl;
		os2.close();

		par->index->sep_rrr = rrr_vector<127>(par->index->sepPhrase_b);
		par->index->sep_rank = rrr_vector<127>::rank_1_type(&par->index->sep_rrr);
		std::cout << " sep_rrr uses " << size_in_bytes(par->index->sep_rrr) << " Bytes" << endl;

		strcpy(fileName, "");
		strcpy(fileName, par->dirStore);
		strcat(fileName, "sep_rrr.test");
		store_to_file(par->index->sep_rrr, fileName);

		strcpy(fileName, "");
		strcpy(fileName, par->dirStore);
		strcat(fileName, "sep_rank.test");
		store_to_file(par->index->sep_rank, fileName);

		strcpy(fileName, "");
		strcpy(fileName, par->dirStore);
		strcat(fileName, "EndDocs.test");
		ofstream os3 (fileName, ios::binary);
		os3.write((const char*)par->EndDocs, par->index->nDocs*sizeof(ulong));					// save LbRev[]
		if(TRACE) cout << " .- EndDocs[] " << par->index->nDocs*sizeof(ulong) << " Bytes" << endl;
		os3.close();

		// load Sequence...
		strcpy(fileName, "");
		strcpy(fileName, par->dirStore);
		strcat(fileName, "sequence.test");
		ifstream is(fileName, ios::binary);
		par->seq = new uchar[par->n];
		is.read((char*)par->seq, par->n*sizeof(uchar));
		is.close();

		cout << "Running test searchPattern.." << endl;
		testSearchPatt_DL_CSA_LZ(par);
		cout << "Test searchPattern OK !!" << endl;
	}

	par->index->~LZDocList64();

	cout << "$$$$$$$$$$$$$$$$$$$$$" << endl;
	return 0;
}
Пример #21
0
 size_t total_size(VM* state) const {
   return size_in_bytes(state);
 }
Пример #22
0
 size_t body_in_bytes(VM* state) const {
   return size_in_bytes(state) - sizeof(ObjectHeader);
 }
Пример #23
0
void ExceptionHandlerTable::copy_to(nmethod* nm) {
  assert(size_in_bytes() == nm->handler_table_size(), "size of space allocated in nmethod incorrect");
  memmove(nm->handler_table_begin(), _table, size_in_bytes());
}
void StubCodeDesc::print() {
  tty->print(group());
  tty->print("::");
  tty->print(name());
  tty->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT "[ (%d bytes)", begin(), end(), size_in_bytes());
}
Пример #25
0
void StubCodeDesc::print_on(outputStream* st) const {
  st->print(group());
  st->print("::");
  st->print(name());
  st->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT "[ (%d bytes)", begin(), end(), size_in_bytes());
}
Пример #26
0
// returns the size of the whole data set
std::size_t file_size_in_bytes(const element& e)
{
	return e.size * size_in_bytes(e);
}
Пример #27
0
/* Emit any file-wide instrumentation.  */
void
mudflap_finish_file (void)
{
  tree ctor_statements = NULL_TREE;

  /* No need to continue when there were errors.  */
  if (errorcount != 0 || sorrycount != 0)
    return;

  /* Insert a call to __mf_init.  */
  {
    tree call2_stmt = build_function_call_expr (mf_init_fndecl, NULL_TREE);
    append_to_statement_list (call2_stmt, &ctor_statements);
  }
  
  /* If appropriate, call __mf_set_options to pass along read-ignore mode.  */
  if (flag_mudflap_ignore_reads)
    {
      tree arg = tree_cons (NULL_TREE, 
                            mf_build_string ("-ignore-reads"), NULL_TREE);
      tree call_stmt = build_function_call_expr (mf_set_options_fndecl, arg);
      append_to_statement_list (call_stmt, &ctor_statements);
    }

  /* Process all enqueued object decls.  */
  if (deferred_static_decls)
    {
      size_t i;
      tree obj;
      for (i = 0; VEC_iterate (tree, deferred_static_decls, i, obj); i++)
        {
          gcc_assert (DECL_P (obj));

          if (mf_marked_p (obj))
            continue;

          /* Omit registration for static unaddressed objects.  NB:
             Perform registration for non-static objects regardless of
             TREE_USED or TREE_ADDRESSABLE, because they may be used
             from other compilation units.  */
          if (! TREE_PUBLIC (obj) && ! TREE_ADDRESSABLE (obj))
            continue;

          if (! COMPLETE_TYPE_P (TREE_TYPE (obj)))
            {
              warning (0, "mudflap cannot track unknown size extern %qs",
                       IDENTIFIER_POINTER (DECL_NAME (obj)));
              continue;
            }
          
          mudflap_register_call (obj, 
                                 size_in_bytes (TREE_TYPE (obj)),
                                 mf_varname_tree (obj));
        }

      VEC_truncate (tree, deferred_static_decls, 0);
    }

  /* Append all the enqueued registration calls.  */
  if (enqueued_call_stmt_chain)
    {
      append_to_statement_list (enqueued_call_stmt_chain, &ctor_statements);
      enqueued_call_stmt_chain = NULL_TREE;
    }

  cgraph_build_static_cdtor ('I', ctor_statements, 
                             MAX_RESERVED_INIT_PRIORITY-1);
}
Пример #28
0
std::size_t size_in_bytes(const attribute& a)
{
	return a.size * size_in_bytes(a.type);
}