Exemplo n.º 1
0
// Extract data from a <bank> element.
int EpiphanyXML::ExtractBank(XMLElement* element, mem_def_t* bank)
{
	return ((ExtractAttr(element, &bank->name, "name")  == 0) &&
	        (ExtractAttr(element, &bank->base, "start") == 0) &&
	        (ExtractAttr(element, &bank->size, "size")  == 0)
	       ) ? 0 : -1;
}
Exemplo n.º 2
0
// Extract the column and row attributes from an ioreg element.
int EpiphanyXML::ExtractIOReg(XMLElement* element, unsigned* row, unsigned* col)
{
	// ioregs is a child of chip and should have a col and row attribute
	int nkids;
	int i;
	XMLElement* child;
	char buf[128];

	nkids = element->GetChildrenNum();
	for (i=0; i<nkids; i++)
	{
		if ((child = element->GetChildren()[i]))
		{
			child->GetElementName(buf);
			if ((strcmp(buf, "ioregs") == 0) &&
			    (ExtractAttr(child, row, "row") == 0) &&
			    (ExtractAttr(child, col, "col") == 0))
			{
				// found the ioregs element and liked it.
				return 0;
			}
		}
	}
	*row = NO_IOREG;
	*col = NO_IOREG;
	return -1;
}
Exemplo n.º 3
0
// Extract data from a <chip> element.
int EpiphanyXML::ExtractChip(XMLElement* element, chip_def_t* chip)
{
	ExtractAttr(element, &chip->version, "version");
	ExtractIOReg(element, &chip->ioreg_row, &chip->ioreg_col);
	return (ExtractCoords(element, &chip->yid, &chip->xid)      ||
	        ExtractAttr(element, &chip->num_rows, "rows")       ||
	        ExtractAttr(element, &chip->num_cols, "cols")       ||
	        ExtractAttr(element, &chip->host_base, "host_base") ||
	        ExtractAttr(element, &chip->core_memory_size, "core_memory_size")
	       ) ? -1 : 0;
}
static void ExtractAttr(Node *nd)
{
   int i ;

   if (nd == 0)
      return ;

   if (nd->type != ParentNode) {
      char *scan = nd->text ;
      while(*scan != ':') ++scan ;
      *scan++ = '\0' ;

      switch(nd->type) {
         case ViewNode:
            nd->len = atoi(scan) ;
            if (nd->len == 0)
               nd->len = nd->parent->len ;
            break ;

         case RelationNode:
            // get the length
            nd->size = atoi(scan) ;
            nd->len = nd->parent->len ;
            while(*scan != ':') ++scan ;
            ++scan ;
            nd->otherView = scan ;
            break ;

         case FieldNode:
            nd->datatype = *scan ;
            scan += 2 ;
            nd->min = atof(scan) ;
            while(*scan != ':') ++scan ;
            ++scan ;
            nd->max = atof(scan) ;
            nd->len = nd->parent->len ;
            break ;

         default: ;
      }


      ExtractAttr(nd->next) ;
   }

   for (i=0; i<nd->numChild; ++i)
      ExtractAttr(nd->child[i]) ;
}
int main(int argc, char **argv) {
    if (!ReadParameter(argc, argv)) {
        std::cout << "Bad Parameters.\n";
        return 1;
    }
    SetConfig();
    if (compress) {
        // Compress
        db_compress::Compressor compressor(outputFileName, schema, config);
        int iter_cnt = 0;
        while (1) {
            std::cout << "Iteration " << ++iter_cnt << " Starts\n";
            std::ifstream inFile(inputFileName);
            std::string str;
            int tuple_cnt = 0;
            while (std::getline(inFile,str)) {
                std::stringstream sstream(str);
                std::string item;
                db_compress::Tuple tuple(schema.attr_type.size());
                
                db_compress::IntegerAttrValue attr(++tuple_cnt);
                tuple.attr[0] = &attr; 

                size_t count = 0;
                std::vector< std::unique_ptr<ColorAttr> > vec;
                while (std::getline(sstream, item, ' ')) {
                    if (++ count > 1)
                        AppendAttr(std::stod(item), &tuple, count - 1);
                }
                // The first item is tuple id
                if (count != schema.attr_type.size()) {
                    std::cerr << "File Format Error!\n";
                }
                compressor.ReadTuple(tuple);
                if (!compressor.RequireFullPass() && 
                    tuple_cnt >= NonFullPassStopPoint) {
                    break;
                }
            }
            compressor.EndOfData();
            if (!compressor.RequireMoreIterations()) 
                break;
        }
    } else {
        // Decompress
        db_compress::Decompressor decompressor(inputFileName, schema);
        std::ofstream outFile(outputFileName);
        decompressor.Init();
        while (decompressor.HasNext()) {
            db_compress::Tuple tuple(33);
            decompressor.ReadNextTuple(&tuple);
            for (size_t i = 0; i < schema.attr_type.size(); ++i) {
                double attr = ExtractAttr(&tuple, i);
                outFile << attr << (i == schema.attr_type.size() - 1 ? '\n' : ' ');
            } 
        }
    }
    return 0;
}
Exemplo n.º 6
0
int EpiphanyXML::Parse()
{
	int nkids = 0;
	int i;
	XMLElement* root;
	XMLElement* child;
	//XMLElement* gchild;
	char buf[256];

	root = m_xml->GetRootElement();
	root->GetElementName(buf);
	if (strcmp(buf, "platform") ||
	    ExtractAttr(root, &m_platform->version, "version") ||
	    ExtractAttr(root, &m_platform->name, "name") ||
	    ExtractAttr(root, &m_platform->lib, "lib") ||
	    ExtractAttr(root, &m_platform->libinitargs, "libinitargs"))
	{
		return -1;
	}

	if (m_platform->version != 1)
	{
		return -2;
	}

	// process platform children
	nkids = root->GetChildrenNum();
	for (i=0; i < nkids; i++)
	{
		child = root->GetChildren()[i];
		child->GetElementName(buf);
		if (strcmp(buf, "chips") == 0)
		{
			ExtractChips(child);
		}
		else if (strcmp(buf, "external_memory") == 0)
		{
			ExtractExternalMemory(child);
		}
	}

	return 0;
}
int main(int argc, char **argv) {
    if (argc == 1)
        PrintHelpInfo();
    else {
        if (!ReadParameter(argc, argv)) {
            std::cerr << "Bad Parameters.\n";
            return 1;
        }
        ReadConfig(configFileName);
        if (compress) {
            // Compress
            db_compress::Compressor compressor(outputFileName, schema, config);
            int iter_cnt = 0;
            while (1) {
                std::cout << "Iteration " << ++iter_cnt << " Starts\n";
                std::ifstream inFile(inputFileName);
                std::string str;
                int tuple_cnt = 0;
                while (std::getline(inFile,str)) {
                    std::stringstream sstream(str);
                    std::string item;
                    db_compress::Tuple tuple(schema.attr_type.size());

                    size_t count = 0;
                    while (std::getline(sstream, item, ',')) {
                        AppendAttr(&tuple, item, attr_type[count], count);
                        ++ count;
                    }
                    // The last item might be empty string
                    if (str[str.length() - 1] == ',') {
                        AppendAttr(&tuple, "", attr_type[count], count);
                        ++ count;
                    }
                    if (count != attr_type.size()) {
                        std::cerr << "File Format Error!\n";
                    }
                    compressor.ReadTuple(tuple);
                    if (!compressor.RequireFullPass() && 
                        ++ tuple_cnt >= NonFullPassStopPoint) {
                        break;
                    }
                }
                compressor.EndOfData();
                if (!compressor.RequireMoreIterations()) 
                    break;
            }
        } else {
            // Decompress
            db_compress::Decompressor decompressor(inputFileName, schema);
            std::ofstream outFile(outputFileName);
            decompressor.Init();
            while (decompressor.HasNext()) {
                db_compress::Tuple tuple(attr_type.size());
                decompressor.ReadNextTuple(&tuple);
                for (size_t i = 0; i < attr_type.size(); ++i) {
                    std::string str = ExtractAttr(tuple, attr_type[i], i);
                    outFile << str << (i == attr_type.size() - 1 ? '\n' : ',');
                } 
            }
        }
    }
    return 0;
}