Exemple #1
0
ObjFile::ObjFile(ObjFile &objfile){
    this->arr = objfile.getArray();
    this->size = this->arr.size();
    this->path = objfile.getPath();
    this->name = objfile.getName();
    this->md5 = objfile.getMd5();
    this->id = objfile.getId();
}
Exemple #2
0
void init()
{
	// Geometry shader examples
	// ------------------------

	// - geometry shader does nothing (just creates identical output triangle for each input triangle)
	//phongShader      = new Shader("../shaders/vshader_phong.glsl", "../shaders/fshader_phong.glsl", "../shaders/gshader_passthrough.glsl");

	// - geometry shader does position and lighting calculation (vertex shader just passes normal and position)
	//phongShader      = new Shader("../shaders/vshader_phong_passthrough.glsl", "../shaders/fshader_phong.glsl", "../shaders/gshader_lightingcalc.glsl");

	// - geometry shader can shrink each polygon about its center (use c/C keys) and/or explode along face normal (e/E keys)
	phongShader      = new Shader("../shaders/vshader_phong_passthrough_with_light.glsl", "../shaders/fshader_cel.glsl", "../shaders/gshader_explode.glsl");

	// - geometry shader tesselates each input triangle into three output triangles, potentially moved along original normal (t/T keys)
	//phongShader      = new Shader("../shaders/vshader_phong_passthrough.glsl", "../shaders/fshader_phong.glsl", "../shaders/gshader_spikes.glsl");

	//phongShader      = new Shader("../shaders/vshader_phong_passthrough.glsl", "../shaders/fshader_phong.glsl", "../shaders/gshader_outline.glsl");
	silhShader      = new Shader("../shaders/vshader_phong_passthrough.glsl", "../shaders/fshader_silh.glsl", "../shaders/gshader_silh.glsl");

	// for drawing axes
	vertexColorShader  = new Shader("../shaders/vshader.glsl", "../shaders/fshader.glsl");

	// Load model from obj file
	ObjFile* m = new ObjFile(objFileName);
	initialTransform = initialTransform * Translate(-m->GetCenter());

	std::string adjfilename = std::string(objFileName);
	size_t lastdot = adjfilename.find_last_of(".");
    if (lastdot != std::string::npos)
	{
		adjfilename = adjfilename.substr(0, lastdot);
	}
	object = new ObjectModel(m, true, adjfilename + ".adj");

	currentOrientation = Scale(m->GetScaleFactor()); // initial scale for model

	axesVao = new VertexArray();
	axesVao->AddAttribute("vPosition", axes, 6);
	axesVao->AddAttribute("vColor", colorsForAxes, 6);

	camera = new Camera (vec3(0.0, 0.0, 4.0),   // position
		vec3(0.0, 0.0, -1.0),  // forward
		vec3(0.0, 1.0, 0.0),   // up
		1.77f,                  // aspect
		30.0f,                 // fovy
		0.1f,                  // near
		1000.0f);              // far

	cameraControl = new CameraControl(camera);


	glEnable( GL_DEPTH_TEST );
	glClearColor( 0.2, 0.2, 0.2, 1.0 ); 

}
Exemple #3
0
void BuildBrowse(ObjFile &file, ObjFactory &factory, ObjLineNo *l)
{
    ObjBrowseInfo *b = factory.MakeBrowseInfo(ObjBrowseInfo::eFuncStart, ObjBrowseInfo::eExternal,
                                              l, "hi dave");
    file.Add(b);	
    l = factory.MakeLineNo(l->GetFile(), 27);
    b = factory.MakeBrowseInfo(ObjBrowseInfo::eVariable, ObjBrowseInfo::eStatic,
                                              l, "hi dave");
    file.Add(b);	
}
void LibFiles::Add(ObjFile &obj)
{
    for (int i=0; i < files.size(); i++)
        if (files[i]->name == obj.GetName())
        {
            std::cout << "Warning: module '" << files[i]->name << "' already exists in library, it won't be added" << std:: endl;
            return;
        }
    FileDescriptor *newFile = new FileDescriptor(obj.GetName());
    newFile->data = &obj;
    files.push_back(newFile);
}
static void finalizeShtGroup(OutputSection *OS,
                             InputSection *Section) {
  assert(Config->Relocatable);

  // sh_link field for SHT_GROUP sections should contain the section index of
  // the symbol table.
  OS->Link = In.SymTab->getParent()->SectionIndex;

  // sh_info then contain index of an entry in symbol table section which
  // provides signature of the section group.
  ObjFile<ELFT> *Obj = Section->getFile<ELFT>();
  ArrayRef<Symbol *> Symbols = Obj->getSymbols();
  OS->Info = In.SymTab->getSymbolIndex(Symbols[Section->Info]);
}
Exemple #6
0
int main()
{
    ObjIeeeIndexManager im;
    ObjFactory f(&im);
    
    ObjFile *fi = MakeData(f);
    fi->ResolveSymbols(&f);
    std::fstream a("hi.txt", std::fstream::trunc | std::fstream::out);
    
    ObjIeee i("hi");
    i.SetTranslatorName("Link32");
    i.SetDebugInfoFlag(true);
    ObjSection *sect = codeSection;
    ObjExpression *left = f.MakeExpression(sect);
    ObjExpression *right = f.MakeExpression(10);
    ObjExpression *sa = f.MakeExpression(ObjExpression::eAdd, left, right);
    i.SetStartAddress(sa);
    
    i.Write(a, fi, &f);
    a.close();
//	ObjFile *fi = i->Read(a, ObjIeee::eAll, f);

    ObjIeeeIndexManager im1;
    ObjFactory fact1(&im1);
    std::fstream b("hi.txt", std::fstream::in);
    ObjIeee i1("hi");
    ObjFile *fi1 = i.Read(b, ObjIeee::eAll, &fact1);
    a.close();
    
    std::fstream c("hi2.txt", std::fstream::trunc | std::fstream::out);
    ObjIeee i2("hi");
    i.SetTranslatorName("Link32");
    i.SetDebugInfoFlag(true);
    i.Write(c, fi1, &fact1);
    c.close();
    
}
Exemple #7
0
ObjFile *MakeData(ObjFactory &factory)
{
    ObjFile *rv = factory.MakeFile("test.dat");
    std::time_t x = std::time(0);
    rv->SetFileTime(*std::localtime(&x));
    ObjSourceFile *sf = factory.MakeSourceFile("test.dat");
    rv->Add(sf);
    ObjSourceFile *sf1 = factory.MakeSourceFile("q.dat");
    rv->Add(sf1);
    ObjSection *sect = factory.MakeSection("code");
    codeSection = sect;
    rv->Add(sect);
    ObjSymbol *s1 = factory.MakePublicSymbol("public");
    rv->Add(s1);
    ObjSymbol *s1a = factory.MakePublicSymbol("2public");
    s1a->SetBaseType(BuildType(*rv, factory));
    rv->Add(s1a);
    ObjSymbol *s2 = factory.MakeLocalSymbol("local");
    s2->SetBaseType(factory.MakeType(ObjType::eInt));
    rv->Add(s2);
    ObjSymbol *s3 = factory.MakeAutoSymbol("auto");
    s3->SetOffset(factory.MakeExpression(-8));
    rv->Add(s3);
    ObjSymbol *s4 = factory.MakeExternalSymbol("extern");
    rv->Add(s4);
    ObjMemory *mem = factory.MakeData((ObjByte *)"\x44\x22\x33\x11", 4);
    ObjLineNo *l = factory.MakeLineNo(sf, 3);
    mem->Add(factory.MakeDebugTag(l));
    sect->Add(mem);
    mem = factory.MakeData((ObjByte *)"\xaa\xbb\x33", 3);
    mem->Add(factory.MakeDebugTag(s1));
    sect->Add(mem);
    mem = factory.MakeData((ObjByte *)"\xf1\x9a\x33", 3);
    mem->Add(factory.MakeDebugTag(s2));
    l = factory.MakeLineNo(sf1, 4);
    mem->Add(factory.MakeDebugTag(l));
    sect->Add(mem);
    mem = factory.MakeData((ObjByte *)"\x32\x17\x33", 3);
    mem->Add(factory.MakeDebugTag(s3));
    sect->Add(mem);
    ObjExpression *left = factory.MakeExpression(s4);
    ObjExpression *right = factory.MakeExpression(7);
    mem = factory.MakeFixup(factory.MakeExpression(ObjExpression::eAdd, left, right), 4);
    sect->Add(mem);
    mem = factory.MakeData((ObjByte *)"\x55\x44\x33", 3);
    mem->Add(factory.MakeDebugTag(s4));
    mem->Add(factory.MakeDebugTag(s1a));
    sect->Add(mem);
    BuildBrowse(*rv, factory, l);
    
    ObjExportSymbol *es = factory.MakeExportSymbol("export");
    es->SetExternalName("myexport");
    es->SetByOrdinal(false);
    rv->Add(es);
    ObjExportSymbol *es1 = factory.MakeExportSymbol("export1");
    es1->SetOrdinal(500);
    es1->SetByOrdinal(true);
    rv->Add(es1);
    ObjImportSymbol *is = factory.MakeImportSymbol("import");
    is->SetExternalName("myimport");
    is->SetDllName("mydll");
    rv->Add(is);
    ObjImportSymbol *is1 = factory.MakeImportSymbol("import1");
    is1->SetByOrdinal(true);
    is1->SetOrdinal(512);
    is1->SetDllName("mydll");
    rv->Add(is1);
    return rv;
}
Exemple #8
0
ObjFile *CoffFile::ConvertToObject(std::string outputName, ObjFactory &factory)
{
    ObjFile *fil = new ObjFile(outputName);
    std::vector<ObjSection *> objectSections;
    std::map<int, ObjSymbol *> externalMapping;
    // Create the sections;
    for (int i=0; i < header.NumberOfSections; i++)
    {
        if (!(sections[i].Characteristics & (IMAGE_SCN_LNK_REMOVE | IMAGE_SCN_LNK_INFO)) && strnicmp(sections[i].Name, ".debug", 6))
        {
            std::string sectname = GetSectionName(i);
            ObjSection * sect = factory.MakeSection(sectname);
            CoffSectionAux *aux = (CoffSectionAux *)& sectionSymbols[i][1];
            sect->SetSize(new ObjExpression(aux->Length));
            sect->SetAlignment(IMAGE_SCN_ALIGN(sections[i].Characteristics));
            sect->SetQuals(GetSectionQualifiers(i));
            fil->Add(sect);
            objectSections.push_back(sect);
        }
        else
        {
            objectSections.push_back(NULL);
        }
    }
    // dump comdefs
    for (int i=1; i < header.NumberOfSymbols; i+= symbols[i].NumberOfAuxSymbols + 1)
    {
        if (symbols[i].SectionNumber > header.NumberOfSections && symbols[i].StorageClass == IMAGE_SYM_CLASS_EXTERNAL && symbols[i].Value)
        {
            char *sname = symbols[i].Name;
            std::string symbolName;
            if (*(unsigned *)sname == 0)
            {
                symbolName = strings + *(unsigned *)(sname + 4); 
            }            
            else
            {
                symbolName = symbols[i].Name;
                if (symbolName.size() > 8)
                    symbolName = symbolName.substr(0, 8);
            }
            symbolName = std::string("vsb") + symbolName;
            ObjSection * sect = factory.MakeSection(symbolName);
            sect->SetSize(new ObjExpression(symbols[i].Value));
            sect->SetAlignment(8);
            sect->SetQuals(ObjSection::ram | ObjSection::max | ObjSection::virt);
            fil->Add(sect);
            objectSections.push_back(sect);
        }
    }
    // create the symbols
    for (int i=0; i < header.NumberOfSymbols; i+= symbols[i].NumberOfAuxSymbols + 1)
    {
        if (symbols[i].StorageClass == IMAGE_SYM_CLASS_EXTERNAL && symbols[i].SectionNumber <= header.NumberOfSections)
        {
            if (symbols[i].SectionNumber <= 0 || (((CoffSectionAux *)&sectionSymbols[symbols[i].SectionNumber-1][1])->Selection <= 1))
            {
                char *sname = symbols[i].Name;
                std::string symbolName;
                if (*(unsigned *)sname == 0)
                {
                    symbolName = strings + *(unsigned *)(sname + 4); 
                    if (symbolName == "_WinMain@16")
                        symbolName = "WinMain";
                }            
                else
                {
                    symbolName = symbols[i].Name;
                    if (symbolName.size() > 8)
                        symbolName = symbolName.substr(0, 8);
                }
                if (symbols[i].SectionNumber == -1)
                {
                    ObjSymbol *symbol = factory.MakePublicSymbol(symbolName);
                    ObjExpression *exp = new ObjExpression(symbols[i].Value);
                    symbol->SetOffset(exp);       
                    fil->Add(symbol);
                }
                else if (symbols[i].SectionNumber)
                {
                    ObjSymbol *symbol = factory.MakePublicSymbol(symbolName);
                    ObjExpression *exp = new ObjExpression(ObjExpression::eAdd, new ObjExpression(objectSections[symbols[i].SectionNumber-1]), new ObjExpression(symbols[i].Value));
                    symbol->SetOffset(exp);       
                    fil->Add(symbol);
                }
                else
                {
                    ObjSymbol *symbol = factory.MakeExternalSymbol(symbolName);
                    externalMapping[i] = symbol;
                    fil->Add(symbol);
                }
            }
        }
    }
    // dump data to the sections
    for (int i=0; i < header.NumberOfSections; i++)
    {
        if (objectSections[i])
        {
            int len = sections[i].SizeOfRawData;
            if (len)
            {
                inputFile->seekg(sections[i].PointerToRawData + libOffset);
                int relocCount = sections[i].NumberOfRelocations;
                CoffReloc * relocPointer = relocs[i];
                if (relocCount == 0xffff && (sections[i].Characteristics & IMAGE_SCN_LNK_NRELOC_OVFL))
                {
                    relocCount = relocPointer[0].VirtualAddress;
                    relocPointer++;
                }
                unsigned offset = 0;
                inputFile->clear();
                while (offset < sections[i].SizeOfRawData)
                {
                    if (!relocCount)
                    {
                        ObjByte *data = new ObjByte[sections[i].SizeOfRawData-offset];
                        inputFile->read((char *)data, sections[i].SizeOfRawData-offset);
                        if (inputFile->fail())
                        {
                            return NULL;
                        }
                        ObjMemory *newMem = new ObjMemory(data, sections[i].SizeOfRawData-offset);
                        objectSections[i]->Add(newMem);
                        offset = sections[i].SizeOfRawData;
                    }
                    else
                    {
                        unsigned fixupOffset;
                        int n = relocPointer->VirtualAddress - offset;
                        if (n)
                        {
                            ObjByte *data = new ObjByte[n];
                            inputFile->read((char *)data, n);
                            if (inputFile->fail())
                            {
                                return NULL;
                            }
                            ObjMemory *newMem = new ObjMemory(data, n);
                            objectSections[i]->Add(newMem);
                        }
                        inputFile->read((char *)&fixupOffset, sizeof(unsigned));
                        if (inputFile->fail())
                        {
                            return NULL;
                        }
                        switch (relocPointer->Type)
                        {
                            ObjExpression *fixupExpr;
                            case IMAGE_REL_I386_DIR32:
                            case IMAGE_REL_I386_REL32:
                                if (symbols[relocPointer->SymbolTableIndex].StorageClass == IMAGE_SYM_CLASS_EXTERNAL)
                                {
                                    if  (symbols[relocPointer->SymbolTableIndex].SectionNumber == 0)
                                    {
                                        // external
                                        fixupExpr = new ObjExpression(externalMapping[relocPointer->SymbolTableIndex]);
                                    }
                                    else if  (symbols[relocPointer->SymbolTableIndex].SectionNumber > header.NumberOfSections)
                                    {
                                        fixupExpr = new ObjExpression(ObjExpression::eAdd, new ObjExpression(objectSections[symbols[relocPointer->SymbolTableIndex].SectionNumber-1]), new ObjExpression(0));
                                    }
                                    else
                                    {
                                        
                                        // public 
                                        fixupExpr = new ObjExpression(ObjExpression::eAdd, new ObjExpression(objectSections[symbols[relocPointer->SymbolTableIndex].SectionNumber-1]), new ObjExpression(symbols[relocPointer->SymbolTableIndex].Value));
                                    }    
                                    
                                }
                                else
                                {
                                    // local static
                                    fixupExpr = new ObjExpression(ObjExpression::eAdd, new ObjExpression(objectSections[symbols[relocPointer->SymbolTableIndex].SectionNumber-1]), new ObjExpression(symbols[relocPointer->SymbolTableIndex].Value));
                                }
                                if (relocPointer->Type == IMAGE_REL_I386_REL32)
                                {
                                    fixupExpr = new ObjExpression(ObjExpression::eAdd, fixupExpr, new ObjExpression(fixupOffset - 4));
                                    fixupExpr = new ObjExpression(ObjExpression::eSub, fixupExpr, new ObjExpression(ObjExpression::ePC) );
                                }
                                else if (fixupOffset)
                                {
                                    fixupExpr = new ObjExpression(ObjExpression::eAdd, fixupExpr, new ObjExpression(fixupOffset));
                                }
                                objectSections[i]->Add(new ObjMemory(fixupExpr, 4));
   
                                break;
                            default:
                                std::cout << "Invalid relocation" << std::endl;
                                return NULL;
                        }
                        
                        offset += n + 4;
                        relocPointer++;
                        relocCount--;
                    }
                }                
            }
        }
    }
    for (int i=1; i < header.NumberOfSymbols; i+= symbols[i].NumberOfAuxSymbols + 1)
    {
        if (symbols[i].SectionNumber > header.NumberOfSections && symbols[i].StorageClass == IMAGE_SYM_CLASS_EXTERNAL && symbols[i].Value)
        {
            int n = symbols[i].SectionNumber-1;
            ObjByte *data = new ObjByte[symbols[i].Value];
            memset(data,0, symbols[i].Value);
            ObjMemory *newMem = new ObjMemory(data, symbols[i].Value);
            objectSections[n]->Add(newMem);
        }
    }
    return fil;
}
static ArrayRef<uint8_t> getSectionContents(ObjFile<ELFT> &File,
                                            const typename ELFT::Shdr &Hdr) {
  if (Hdr.sh_type == SHT_NOBITS)
    return makeArrayRef<uint8_t>(nullptr, Hdr.sh_size);
  return check(File.getObj().getSectionContents(&Hdr));
}
Exemple #10
0
void StructuralReports::
saveMaterialBoundariesBeta_2(const GridDescription & grid,
    const VoxelizedPartition & vp)
{
	ObjFile objFile;
	int ii,jj,kk;
    
	ostringstream foutname;
	foutname << grid.name() << "_faces.obj";
	ofstream fout(foutname.str().c_str());
	
    const Map<Paint*, SetupUpdateEquationPtr> materials(vp.setupMaterials());
    map<Paint*, SetupUpdateEquationPtr>::const_iterator itr;
    
    const VoxelGrid & vg(vp.voxels());
	//const StructureGrid& grid = *mStructureGrid;
	
	// We'll write the materials one at a time.
	for (itr = materials.begin(); itr != materials.end(); itr++)
    if ( (*itr).first == (*itr).first->withoutModifications())
	{
		Paint* paint = (*itr).first;
		SetupUpdateEquationPtr mat = (*itr).second;
        string name = paint->fullName();
        Rect3i roi = grid.nonPMLHalfCells();
		Paint* lastMat;
        Paint* curMat;
		
		LOGF << "Considering material " << name << endl;
		
		//fout << name << endl;
		
		vector<OrientedRect3i> xFaces;
		vector<OrientedRect3i> yFaces;
		vector<OrientedRect3i> zFaces;
		
		// Do all the face determination stuff
		{
		// X-normal faces
		//	a.  Bottom layer
		ii = roi.p1[0];
		for (kk = roi.p1[2]; kk <= roi.p2[2]; kk++)
		for (jj = roi.p1[1]; jj <= roi.p2[1]; jj++)
		{
			curMat = vg(ii, jj, kk);
			if (curMat == paint)
			{
				xFaces.push_back( OrientedRect3i(
					Rect3i(ii,jj,kk,ii,jj+1,kk+1),
					Vector3i(-1, 0, 0)) );
			}
		} 
		//	b.  Top layer
		ii = roi.p2[0];
		for (kk = roi.p1[2]; kk <= roi.p2[2]; kk++)
		for (jj = roi.p1[1]; jj <= roi.p2[1]; jj++)
		{
			curMat = vg(ii, jj, kk);
			if (curMat == paint)
			{
				xFaces.push_back( OrientedRect3i(
					Rect3i(ii+1,jj,kk,ii+1,jj+1,kk+1),
					Vector3i(1,0,0) ));
			}
		}
		//	c.  Middle (careful about X direction for-loop limits)
		for (ii = roi.p1[0]+1; ii <= roi.p2[0]; ii++)
		for (kk = roi.p1[2]; kk <= roi.p2[2]; kk++)
		for (jj = roi.p1[1]; jj <= roi.p2[1]; jj++)
		{
			lastMat = vg(ii-1, jj, kk);
			curMat = vg(ii, jj, kk);
			
			if (lastMat == paint && curMat != paint)
			{
				xFaces.push_back( OrientedRect3i(
					Rect3i(ii,jj,kk,ii,jj+1,kk+1),
					Vector3i(1, 0, 0)) );
			}
			else if (lastMat != paint && curMat == paint)
			{
				xFaces.push_back( OrientedRect3i(
					Rect3i(ii,jj,kk,ii,jj+1,kk+1),
					Vector3i(-1,0,0) ));
			}
		}
		
		// Y-normal faces
		//	a.  Top layer
		jj = roi.p1[1];
		for (ii = roi.p1[0]; ii <= roi.p2[0]; ii++)
		for (kk = roi.p1[2]; kk <= roi.p2[2]; kk++)
		{
			curMat = vg(ii, jj, kk);
			if (curMat == paint)
			{
				yFaces.push_back( OrientedRect3i(
					Rect3i(ii,jj,kk,ii+1,jj,kk+1),
					Vector3i(0, -1, 0) ));
			}
		} 
		//	b.  Bottom layer
		jj = roi.p2[1];
		for (ii = roi.p1[0]; ii <= roi.p2[0]; ii++)
		for (kk = roi.p1[2]; kk <= roi.p2[2]; kk++)
		{
			curMat = vg(ii, jj, kk);
			if (curMat == paint)
			{
				yFaces.push_back( OrientedRect3i(
					Rect3i(ii,jj+1,kk,ii+1,jj+1,kk+1),
					Vector3i(0, 1, 0) ));
			}
		}
		//	c.  Middle (careful about X direction for-loop limits)
		for (jj = roi.p1[1]+1; jj <= roi.p2[1]; jj++)
		for (ii = roi.p1[0]; ii <= roi.p2[0]; ii++)
		for (kk = roi.p1[2]; kk <= roi.p2[2]; kk++)
		{
			lastMat = vg(ii, jj-1, kk);
			curMat = vg(ii, jj, kk);
			
			if (lastMat == paint && curMat != paint)
			{
				yFaces.push_back( OrientedRect3i(
					Rect3i(ii,jj,kk,ii+1,jj,kk+1),
					Vector3i(0, 1, 0) ));
			}
			else if (lastMat != paint && curMat == paint)
			{
				yFaces.push_back( OrientedRect3i(
					Rect3i(ii,jj,kk,ii+1,jj,kk+1),
					Vector3i(0, -1, 0) ));
			}
		}
		
		// Z-normal faces
		//	a.  Top layer
		kk = roi.p1[2];
		for (jj = roi.p1[1]; jj <= roi.p2[1]; jj++)
		for (ii = roi.p1[0]; ii <= roi.p2[0]; ii++)
		{
			curMat = vg(ii, jj, kk);
			if (curMat == paint)
			{
				zFaces.push_back( OrientedRect3i(
					Rect3i(ii,jj,kk,ii+1,jj+1,kk),
					Vector3i(0, 0, -1) ));
			}
		} 
		//	b.  Bottom layer
		kk = roi.p2[2];
		for (jj = roi.p1[1]; jj <= roi.p2[1]; jj++)
		for (ii = roi.p1[0]; ii <= roi.p2[0]; ii++)
		{
			curMat = vg(ii, jj, kk);
			if (curMat == paint)
			{
				zFaces.push_back( OrientedRect3i(
					Rect3i(ii,jj,kk+1,ii+1,jj+1,kk+1),
					Vector3i(0, 0, 1) ));
			}
		}
		//	c.  Middle (careful about X direction for-loop limits)
		for (kk = roi.p1[2]+1; kk <= roi.p2[2]; kk++)
		for (jj = roi.p1[1]; jj <= roi.p2[1]; jj++)
		for (ii = roi.p1[0]; ii <= roi.p2[0]; ii++)
		{
			lastMat = vg(ii, jj, kk-1);
			curMat = vg(ii, jj, kk);
			
			if (lastMat == paint && curMat != paint)
			{
				zFaces.push_back( OrientedRect3i(
					Rect3i(ii,jj,kk,ii+1,jj+1,kk),
					Vector3i(0, 0, 1) ));
			}
			else if (lastMat != paint && curMat == paint)
			{
				zFaces.push_back( OrientedRect3i(
					Rect3i(ii,jj,kk,ii+1,jj+1,kk),
					Vector3i(0, 0, -1) ));
			}
		}
		}
        
		// Now try to consolidate a little bit.		
		list<OrientedRect3i> xCompressed;
		list<OrientedRect3i> yCompressed;
		list<OrientedRect3i> zCompressed;
		
		consolidateRects(xFaces, xCompressed, 0);
		consolidateRects(yFaces, yCompressed, 1);
		consolidateRects(zFaces, zCompressed, 2);
		
		/*
		ostream_iterator<OrientedRect3i> fout_itr(fout, "\n");
		copy(xCompressed.begin(), xCompressed.end(), fout_itr);
		copy(yCompressed.begin(), yCompressed.end(), fout_itr);
		copy(zCompressed.begin(), zCompressed.end(), fout_itr);
		*/
        
		objFile.appendGroup(name, xCompressed);
		objFile.appendGroup(name, yCompressed);
		objFile.appendGroup(name, zCompressed);
	}
	
    objFile.write(fout, -grid.origin(), 0.5*grid.dxyz());
	//objFile.write(fout, 0.5);  // The scale factor 0.5 undoes half-cells.
	fout.close();
}
Exemple #11
0
void Writer::assignIndexes() {
  assert(InputFunctions.empty());
  uint32_t FunctionIndex = NumImportedFunctions;
  auto AddDefinedFunction = [&](InputFunction *Func) {
    if (!Func->Live)
      return;
    InputFunctions.emplace_back(Func);
    Func->setFunctionIndex(FunctionIndex++);
  };

  for (InputFunction *Func : Symtab->SyntheticFunctions)
    AddDefinedFunction(Func);

  for (ObjFile *File : Symtab->ObjectFiles) {
    LLVM_DEBUG(dbgs() << "Functions: " << File->getName() << "\n");
    for (InputFunction *Func : File->Functions)
      AddDefinedFunction(Func);
  }

  uint32_t TableIndex = TableBase;
  auto HandleRelocs = [&](InputChunk *Chunk) {
    if (!Chunk->Live)
      return;
    ObjFile *File = Chunk->File;
    ArrayRef<WasmSignature> Types = File->getWasmObj()->types();
    for (const WasmRelocation &Reloc : Chunk->getRelocations()) {
      if (Reloc.Type == R_WASM_TABLE_INDEX_I32 ||
          Reloc.Type == R_WASM_TABLE_INDEX_SLEB) {
        FunctionSymbol *Sym = File->getFunctionSymbol(Reloc.Index);
        if (Sym->hasTableIndex() || !Sym->hasFunctionIndex())
          continue;
        Sym->setTableIndex(TableIndex++);
        IndirectFunctions.emplace_back(Sym);
      } else if (Reloc.Type == R_WASM_TYPE_INDEX_LEB) {
        // Mark target type as live
        File->TypeMap[Reloc.Index] = registerType(Types[Reloc.Index]);
        File->TypeIsUsed[Reloc.Index] = true;
      }
    }
  };

  for (ObjFile *File : Symtab->ObjectFiles) {
    LLVM_DEBUG(dbgs() << "Handle relocs: " << File->getName() << "\n");
    for (InputChunk *Chunk : File->Functions)
      HandleRelocs(Chunk);
    for (InputChunk *Chunk : File->Segments)
      HandleRelocs(Chunk);
    for (auto &P : File->CustomSections)
      HandleRelocs(P);
  }

  assert(InputGlobals.empty());
  uint32_t GlobalIndex = NumImportedGlobals;
  auto AddDefinedGlobal = [&](InputGlobal *Global) {
    if (Global->Live) {
      LLVM_DEBUG(dbgs() << "AddDefinedGlobal: " << GlobalIndex << "\n");
      Global->setGlobalIndex(GlobalIndex++);
      InputGlobals.push_back(Global);
    }
  };

  for (InputGlobal *Global : Symtab->SyntheticGlobals)
    AddDefinedGlobal(Global);

  for (ObjFile *File : Symtab->ObjectFiles) {
    LLVM_DEBUG(dbgs() << "Globals: " << File->getName() << "\n");
    for (InputGlobal *Global : File->Globals)
      AddDefinedGlobal(Global);
  }

  assert(InputEvents.empty());
  uint32_t EventIndex = NumImportedEvents;
  auto AddDefinedEvent = [&](InputEvent *Event) {
    if (Event->Live) {
      LLVM_DEBUG(dbgs() << "AddDefinedEvent: " << EventIndex << "\n");
      Event->setEventIndex(EventIndex++);
      InputEvents.push_back(Event);
    }
  };

  for (ObjFile *File : Symtab->ObjectFiles) {
    LLVM_DEBUG(dbgs() << "Events: " << File->getName() << "\n");
    for (InputEvent *Event : File->Events)
      AddDefinedEvent(Event);
  }
}