Example #1
0
int main(int argc, char *argv[]) {

	// Declare a pointer to the input file
	FILE *inFile;
	// Declare a pointer to the root file name
	char *rootName;
	// Declare pointers to the head and tail of the symbol table
	DEF_NODE *head, *tail;
	// Set head and tail to NULL
	head = tail = NULL;
	// Initialize the errorIndex to 0
	errorIndex = 0;
	// Find the root file name and set it
	rootName = (char *)findRootFileName(argv[IN_FILE]);

	// Try to open the input file for reading
	if((inFile = fopen(argv[IN_FILE], "r")) == NULL) {
		// Print error message if file could not be opened
		fprintf(stderr, "Could not open file: %s\n", argv[IN_FILE]);
		// Fatal error, exit program
		exit(1);
	}

	// Initialize all the opcodes
	initOpcodes();
	// Do the first pass and build the symbol table
	passOne(inFile, &head, &tail);
	// Rewind the input file so it is ready for the second pass
	rewind(inFile);
	// Do the second pass and check for errors
	passTwo(inFile, &head, &tail);

	// If there were errors in the input file...
	if(errorIndex > 0) {
		// Make an error file
		writeErrFile(inFile, rootName);
	}
	// There were no errors in the input file
	else {
		// Write the symbol table file
		printST(head, rootName);
		// Write the object code file
		writeObjFile(rootName);
	}

	// Try to close the input file
	if(fclose(inFile) == EOF) {
		// If file could not be closed, print error
		fprintf(stderr, "Could not close file: %s\n", argv[IN_FILE]);
		// Fatal error, exit program
		exit(1);
	}

	// Program finished without errors, return 0
	return 0;
}
Example #2
0
int main(void)
{
	FILE *progFile,*outputFile,*opcode,*ADFile;
	
	progFile = fopen("input.txt","r");
	opcode = fopen("opcode.txt","r");
	outputFile = fopen("obj.o", "w");
	ADFile = fopen("AssemblyDirectives.txt","r");
	
	fgets(assemblyDirectives,30,ADFile);

	
	//int hexTest = 0x16;
	//hexTest = hexTest << 16;
	//int hexLocTest = 0x1033;
	//unsigned int opcodeTest = hexTest | hexLocTest;
	//printf("Opcode Test:%x",opcodeTest);
	populateOpcode(opcode);

	
	lineByLine(progFile);
	
	rewind(progFile);
	symbolAddresses(progFile);
	

	printSymbolTable();

	rewind(progFile);
	setSymbolAddresses(progFile);
	



	lineOp[lineNum-1] = 0;//End of the file has a 0x00 opcode
	rewind(progFile);
	writeObjFile(progFile,outputFile);
	fclose(progFile);
	fclose(outputFile);
	fclose(opcode);
}
Example #3
0
void BVH::build(std::vector<Triangle *> triangles, std::vector<Instance *> *instances)
{
    std::cout << "Building BVH" << std::endl;
	m_buildData.reserve(triangles.size());
	m_triangles = triangles;
	for(int i=0;i<triangles.size();i++){
		m_buildData.push_back(BVHTriangleInfo(i,AABoundingBox(triangles[i]), 0, 1 ));
	}
    if(instances != 0){
        m_instances = *instances;
        for(int i=0;i<instances->size();i++){
            m_buildData.push_back(BVHTriangleInfo(i,(*instances)[i]->m_bounds, 1, (*instances)[i]->getNumTris()));
        }
    }
    int numTotalNodes = 0;
	BVHBuildNode *buildRoot = recursiveBuild(0,m_buildData.size(),&numTotalNodes);
    m_root = new BVHLinearNode[numTotalNodes];
    int offset = 0;
    flattenTree(buildRoot,&offset);
    recursiveDelete(buildRoot);
    m_buildData.clear();
    writeObjFile("/tmp/bvh.obj");
}
void initScene()
{
    // generate texture
    texture = std::unique_ptr<Texture>(new Texture());
    texture->genImageMask(16, 16, false);

    // setup scene
    viewTransform.SetPosition({ 0, 0, -3 });

    //addModelPlane(); // reference model to check that UV-coords are correct
    addModelCuboid();
    addModelEllipsoid();
    addModelCone();
    addModelCylinder();
    addModelPipe();
    addModelTorus();
    addModelSpiral();
    addModelTorusKnot();
    //addModelCurve();
    //addModelBezierPatch();
    //addModelTeapot();
    //...

    for (auto it = models.begin(); it != models.end();)
    {
        #ifdef ENABLE_PRESENTATION
        // setup model for presentation
        it->turn(0, Gs::Deg2Rad(20.0f));
        it->turn(Gs::Deg2Rad(40.0f), 0);
        #endif

        // check for unused vertices in all models
        auto n = countUnusedVertices(it->mesh);
        if (n > 0)
            std::cout << it->name << " has " << n << " unused vertices" << std::endl;
        else if (n < 0)
        {
            std::cout << it->name << " has " << (-n) << " invalid vertices -> model removed from list" << std::endl;
            it = models.erase(it);
            continue;
        }

        // compute tangent vectors
        const auto& verts = it->mesh.vertices;
        auto numVerts = verts.size();
        it->tangents[0].resize(numVerts);
        it->tangents[1].resize(numVerts);

        Gs::Vector3 tangent, bitangent, normal;

        for (const auto& indices : it->mesh.triangles)
        {
            Gm::Triangle3 coords(
                verts[indices.a].position,
                verts[indices.b].position,
                verts[indices.c].position
            );

            Gm::Triangle2 texCoords(
                verts[indices.a].texCoord,
                verts[indices.b].texCoord,
                verts[indices.c].texCoord
            );

            Gm::ComputeTangentSpace(coords, texCoords, tangent, bitangent, normal);

            (it->tangents[0])[indices.a] = tangent;
            (it->tangents[1])[indices.a] = bitangent;

            (it->tangents[0])[indices.b] = tangent;
            (it->tangents[1])[indices.b] = bitangent;

            (it->tangents[0])[indices.c] = tangent;
            (it->tangents[1])[indices.c] = bitangent;
        }

        #ifdef WRITE_MODELS_TO_FILE
        // write model to file
        it->writeObjFile("mesh/" + it->name + ".obj");
        #endif

        ++it;
    }

    // show first model
    std::cout << std::endl;
    showModel(models.size() - 1);
}