コード例 #1
0
ファイル: bmf_famstats.cpp プロジェクト: ARUP-NGS/BMFtools
int famstats_sum_main(int argc, char *argv[]) {
    if(argc < 2)
        return sum_usage(argv);
    if(strcmp(argv[1], "--help") == 0) {
        return sum_usage(argv, EXIT_SUCCESS);
    }
    int c;
    FILE *ofp(stdout);
    while((c = getopt(argc, argv, "o:h?")) > -1) {
        switch(c) {
        case 'o': ofp = fopen(optarg, "w"); break;
        case 'h': case '?': return sum_usage(argv, EXIT_SUCCESS);
        }
    }
    fputs("Filename: count\n", ofp);
    for(int i(1); i < argc; ++i) {
        dlib::check_bam_tag_exit(argv[i], "FM");
        dlib::BamHandle in(argv[i]);
        bam1_t *b(bam_init1());
        size_t count(0);
        while(sam_read1(in.fp, in.header, b) >= 0)
            if((b->core.flag & (BAM_FSECONDARY | BAM_FSUPPLEMENTARY | BAM_FREAD2)) == 0) 
                count += bam_itag(b,"FM");
        fprintf(ofp, "%s: %lu\n", argv[i], count);
        bam_destroy1(b);
    }
    fclose(ofp);
    return EXIT_SUCCESS;
}
コード例 #2
0
void ExtractScummMac::execute() {
	Common::Filename inPath(_inputPaths[0].path);
	Common::Filename outPath(_outputPath);

	if (outPath.empty())
		outPath.setFullPath("./");

	Common::File ifp(inPath, "rb");

	// Get the length of the data file to use for consistency checks
	uint32 dataFileLength = ifp.size();

	// Read offset and length to the file records
	uint32 fileRecordOffset = ifp.readUint32BE();
	uint32 fileRecordLength = ifp.readUint32BE();

	// Do a quick check to make sure the offset and length are good
	if (fileRecordOffset + fileRecordLength > dataFileLength)
		error("File records out of bounds");

	// Do a little consistancy check on fileRecordLength
	if (fileRecordLength % 0x28)
		error("File record length not multiple of 40");

	// Extract the files
	for (uint32 i = 0; i < fileRecordLength; i += 0x28) {
		// read a file record
		ifp.seek(fileRecordOffset + i, SEEK_SET);

		uint32 fileOffset = ifp.readUint32BE();
		uint32 fileLength = ifp.readUint32BE();

		char fileName[0x21];
		ifp.read_throwsOnError(fileName, 0x20);
		fileName[0x20] = 0;

		if (!fileName[0])
			error("File has no name");

		print("Extracting %s...", fileName);

		// Consistency check. make sure the file data is in the file
		if (fileOffset + fileLength > dataFileLength)
			error("File out of bounds");

		// Write a file
		ifp.seek(fileOffset, SEEK_SET);

		outPath.setFullName(fileName);
		Common::File ofp(outPath, "wb");

		byte *buf = new byte[fileLength];
		ifp.read_throwsOnError(buf, fileLength);
		ofp.write(buf, fileLength);
		delete[] buf;
	}
}
コード例 #3
0
ファイル: V3StatsReport.cpp プロジェクト: jeras/verilator
void V3Stats::statsReport() {
    UINFO(2,__FUNCTION__<<": "<<endl);

    // Open stats file
    string filename = v3Global.opt.makeDir()+"/"+v3Global.opt.prefix()+"__stats.txt";
    std::ofstream* ofp (V3File::new_ofstream(filename));
    if (ofp->fail()) v3fatal("Can't write "<<filename);

    StatsReport reporter (ofp);

    // Cleanup
    ofp->close(); delete ofp; VL_DANGLING(ofp);
}
コード例 #4
0
ファイル: V3EmitCInlines.cpp プロジェクト: torc-isi/torc
void EmitCInlines::emitInt() {
    string filename = v3Global.opt.makeDir()+"/"+topClassName()+"__Inlines.h";
    newCFile(filename, false/*slow*/, false/*source*/);
    V3OutCFile hf (filename);
    m_ofp = &hf;

    ofp()->putsHeader();
    puts("#ifndef _"+topClassName()+"__Inlines_H_\n");
    puts("#define _"+topClassName()+"__Inlines_H_\n");
    puts("\n");

    puts("#include \"verilated.h\"\n");

    puts("\n//======================\n\n");

    for (unsigned words=0; words<m_wordWidths.size(); words++) {
	if (m_wordWidths.at(words)) {
	    puts("#ifndef VL_HAVE_CONST_W_"+cvtToStr(words)+"X\n");
	    puts("# define VL_HAVE_CONST_W_"+cvtToStr(words)+"X\n");
	    puts("static inline WDataOutP VL_CONST_W_"+cvtToStr(words)+"X(int obits, WDataOutP o\n");
	    puts("\t");
	    for (int i=words-1; i>=0; --i) {
		puts(",IData d"+cvtToStr(i));
		if (i && (i % 8 == 0)) puts("\n\t");
	    }
	    puts(") {\n");
	    puts("   ");
	    for (int i=words-1; i>=0; --i) {
		puts(" o["+cvtToStr(i)+"]=d"+cvtToStr(i)+";");
		if (i && (i % 8 == 0)) puts("\n   ");
	    }
	    puts("\n");
	    puts("    for(int i="+cvtToStr(words)+";i<VL_WORDS_I(obits);i++) o[i] = (IData)0x0;\n");
	    puts("    return o;\n");
	    puts("}\n");
	    puts("#endif\n");
	    puts("\n");
	}
    }

    puts("//======================\n\n");
    puts("#endif  /*guard*/\n");
}
コード例 #5
0
ファイル: V3EmitCInlines.cpp プロジェクト: jeras/verilator
void EmitCInlines::emitInt() {
    string filename = v3Global.opt.makeDir()+"/"+topClassName()+"__Inlines.h";
    newCFile(filename, false/*slow*/, false/*source*/);
    V3OutCFile hf (filename);
    m_ofp = &hf;

    ofp()->putsHeader();
    puts("#ifndef _"+topClassName()+"__Inlines_H_\n");
    puts("#define _"+topClassName()+"__Inlines_H_\n");
    puts("\n");

    puts("#include \"verilated.h\"\n");

    puts("\n//======================\n\n");

    // Placeholder - v3Global.needHInlines(true) currently not used

    puts("//======================\n\n");
    puts("#endif // guard\n");
}
コード例 #6
0
void ExtractScummMac::execute() {
	unsigned long file_record_off, file_record_len;
	unsigned long file_off, file_len;
	unsigned long data_file_len;
	char file_name[0x20];
	char *buf;
	unsigned long i;
	int j;

	Common::Filename inpath(_inputPaths[0].path);
	Common::Filename outpath(_outputPath);

	if (outpath.empty())
		outpath.setFullPath("./");

	Common::File ifp(inpath, "rb");

	/* Get the length of the data file to use for consistency checks */
	data_file_len = ifp.size();

	/* Read offset and length to the file records */
	file_record_off = ifp.readUint32BE();
	file_record_len = ifp.readUint32BE();

	/* Do a quick check to make sure the offset and length are good */
	if (file_record_off + file_record_len > data_file_len) {
		error("\'%s\'. file records out of bounds.", inpath.getFullPath().c_str());
	}

	/* Do a little consistancy check on file_record_length */
	if (file_record_len % 0x28) {
		error("\'%s\'. file record length not multiple of 40.", inpath.getFullPath().c_str());
	}

	/* Extract the files */
	for (i = 0; i < file_record_len; i += 0x28) {
		/* read a file record */
		ifp.seek(file_record_off + i, SEEK_SET);

		file_off = ifp.readUint32BE();
		file_len = ifp.readUint32BE();
		ifp.read_throwsOnError(file_name, 0x20);

		if (!file_name[0])
			error("\'%s\'. file has no name.", inpath.getFullPath().c_str());

		print("extracting \'%s\'", file_name);

		/* For convenience compatibility with scummvm (and case sensitive
		 * file systems) change the file name to lowercase.
		 *
		 * if i ever add the ability to pass flags on the command
		 * line, i will make this optional, but i really don't
		 * see the point to bothering
		 */
		for (j = 0; j < 0x20; j++) {
			if (!file_name[j]) {
				break;
			}

#ifdef CHANGECASE
			file_name[j] = tolower(file_name[j]);
#endif
		}

		if (j == 0x20) {
			file_name[0x1f] = 0;
			warning("\'%s\'. file name not null terminated.", file_name);
			print("data file \'%s\' may be not a file extract_scumm_mac can extract.", inpath.getFullPath().c_str());
		}

		print(", saving as \'%s\'", file_name);

		/* Consistency check. make sure the file data is in the file */
		if (file_off + file_len > data_file_len) {
			error("\'%s\'. file out of bounds.", inpath.getFullPath().c_str());
		}

		/* Write a file */
		ifp.seek(file_off, SEEK_SET);

		outpath.setFullName(file_name);
		Common::File ofp(outpath, "wb");

		if (!(buf = (char *)malloc(file_len))) {
			error("Could not allocate %ld bytes of memory.", file_len);
		}

		ifp.read_throwsOnError(buf, file_len);
		ofp.write(buf, file_len);
		free(buf);
	}
}
コード例 #7
0
void EmitCSyms::emitSymImp() {
    UINFO(6,__FUNCTION__<<": "<<endl);
    string filename = v3Global.opt.makeDir()+"/"+symClassName()+".cpp";
    AstCFile* cfilep = newCFile(filename, true/*slow*/, true/*source*/);
    cfilep->support(true);
    V3OutCFile cf (filename);
    m_ofp = &cf;
    ofp()->putsHeader();
    puts("// DESCR" "IPTION: Verilator output: Symbol table implementation internals\n");
    puts("\n");

    // Includes
    puts("#include \""+symClassName()+".h\"\n");
    for (AstNodeModule* nodep = v3Global.rootp()->modulesp(); nodep; nodep=nodep->nextp()->castNodeModule()) {
	puts("#include \""+modClassName(nodep)+".h\"\n");
    }

    //puts("\n// GLOBALS\n");

    puts("\n// FUNCTIONS\n");
    puts(symClassName()+"::"+symClassName()+"("+topClassName()+"* topp, const char* namep)\n");
    puts("\t// Setup locals\n");
    puts("\t: __Vm_namep(namep)\n");	// No leak, as we get destroyed when the top is destroyed
    puts("\t, __Vm_activity(false)\n");
    puts("\t, __Vm_didInit(false)\n");
    puts("\t// Setup submodule names\n");
    char comma=',';
    for (vector<ScopeModPair>::iterator it = m_scopes.begin(); it != m_scopes.end(); ++it) {
	AstScope* scopep = it->first;  AstNodeModule* modp = it->second;
	if (modp->isTop()) {
	} else {
	    ofp()->printf("\t%c %-30s ", comma, scopep->nameDotless().c_str());
	    puts("(Verilated::catName(topp->name(),");
	    // The "." is added by catName
	    putsQuoted(scopep->prettyName());
	    puts("))\n");
	    comma=',';
	}
    }
    puts("{\n");

    puts("// Pointer to top level\n");
    puts("TOPp = topp;\n");
    puts("// Setup each module's pointers to their submodules\n");
    for (vector<ScopeModPair>::iterator it = m_scopes.begin(); it != m_scopes.end(); ++it) {
	AstScope* scopep = it->first;  AstNodeModule* modp = it->second;
	if (!modp->isTop()) {
	    string arrow = scopep->name();
	    string::size_type pos;
	    while ((pos=arrow.find(".")) != string::npos) {
		arrow.replace(pos, 1, "->");
	    }
	    if (arrow.substr(0,5) == "TOP->") arrow.replace(0,5,"TOPp->");
	    ofp()->printf("%-30s ", arrow.c_str());
	    puts(" = &");
	    puts(scopep->nameDotless()+";\n");
	}
    }

    puts("// Setup each module's pointer back to symbol table (for public functions)\n");
    puts("TOPp->__Vconfigure(this, true);\n");
    for (vector<ScopeModPair>::iterator it = m_scopes.begin(); it != m_scopes.end(); ++it) {
	AstScope* scopep = it->first;  AstNodeModule* modp = it->second;
	if (!modp->isTop()) {
	    // first is used by AstCoverDecl's call to __vlCoverInsert
	    bool first = !modp->user1();
	    modp->user1(true);
	    puts(scopep->nameDotless()+".__Vconfigure(this, "
		 +(first?"true":"false")
		 +");\n");
	}
    }

    puts("// Setup scope names\n");
    for (ScopeNames::iterator it = m_scopeNames.begin(); it != m_scopeNames.end(); ++it) {
	puts("__Vscope_"+it->second.m_symName+".configure(this,name(),");
	putsQuoted(it->second.m_prettyName);
	puts(");\n");
    }

    if (v3Global.dpi()) {
	puts("// Setup export functions\n");
	puts("for (int __Vfinal=0; __Vfinal<2; __Vfinal++) {\n");
	for (ScopeFuncs::iterator it = m_scopeFuncs.begin(); it != m_scopeFuncs.end(); ++it) {
	    AstScopeName* scopep = it->second.m_scopep;
	    AstCFunc* funcp = it->second.m_funcp;
	    AstNodeModule* modp = it->second.m_modp;
	    if (funcp->dpiExport()) {
		puts("__Vscope_"+scopep->scopeSymName()+".exportInsert(__Vfinal,");
		putsQuoted(funcp->cname());
		puts(", (void*)(&");
		puts(modClassName(modp));
		puts("::");
		puts(funcp->name());
		puts("));\n");
	    }
	}
	// It would be less code if each module inserted its own variables.
	// Someday.  For now public isn't common.
	for (ScopeVars::iterator it = m_scopeVars.begin(); it != m_scopeVars.end(); ++it) {
	    AstNodeModule* modp = it->second.m_modp;
	    AstScope* scopep = it->second.m_scopep;
	    AstVar* varp = it->second.m_varp;
	    //
	    int pdim=0;
	    int udim=0;
	    string bounds;
	    if (AstBasicDType* basicp = varp->basicp()) {
		// Range is always first, it's not in "C" order
		if (basicp->isRanged()) {
		    bounds += " ,"; bounds += cvtToStr(basicp->msb());
		    bounds += ","; bounds += cvtToStr(basicp->lsb());
		    pdim++;
		}
		for (AstNodeDType* dtypep=varp->dtypep(); dtypep; ) {
		    dtypep = dtypep->skipRefp();  // Skip AstRefDType/AstTypedef, or return same node
		    if (AstNodeArrayDType* adtypep = dtypep->castNodeArrayDType()) {
			bounds += " ,"; bounds += cvtToStr(adtypep->msb());
			bounds += ","; bounds += cvtToStr(adtypep->lsb());
			if (dtypep->castPackArrayDType()) pdim++; else udim++;
			dtypep = adtypep->subDTypep();
		    }
		    else break; // AstBasicDType - nothing below, 1
		}
	    }
	    //
	    if (pdim>1 || udim>1) {
		puts("//UNSUP ");  // VerilatedImp can't deal with >2d or packed arrays
	    }
	    puts("__Vscope_"+it->second.m_scopeName+".varInsert(__Vfinal,");
	    putsQuoted(it->second.m_varBasePretty);
	    puts(", &(");
	    if (modp->isTop()) {
		puts(scopep->nameDotless());
		puts("p->");
	    } else {
		puts(scopep->nameDotless());
		puts(".");
	    }
	    puts(varp->name());
	    puts("), ");
	    puts(varp->vlEnumType());  // VLVT_UINT32 etc
	    puts(",");
	    puts(varp->vlEnumDir());  // VLVD_IN etc
	    if (varp->isSigUserRWPublic()) puts("|VLVF_PUB_RW");
	    else if (varp->isSigUserRdPublic()) puts("|VLVF_PUB_RD");
	    puts(",");
	    puts(cvtToStr(pdim+udim));
	    puts(bounds);
	    puts(");\n");
	}
	puts("}\n");
    }

    puts("}\n");

    if (v3Global.opt.savable() ) {
	puts("\n");
	for (int de=0; de<2; ++de) {
	    string classname = de ? "VerilatedDeserialize" : "VerilatedSerialize";
	    string funcname = de ? "__Vdeserialize" : "__Vserialize";
	    string op = de ? ">>" : "<<";
	    puts("void "+symClassName()+"::"+funcname+"("+classname+"& os) {\n");
	    puts(   "// LOCAL STATE\n");
	    // __Vm_namep presumably already correct
	    puts(   "os"+op+"__Vm_activity;\n");
	    puts(   "os"+op+"__Vm_didInit;\n");
	    puts(   "// SUBCELL STATE\n");
	    for (vector<ScopeModPair>::iterator it = m_scopes.begin(); it != m_scopes.end(); ++it) {
		AstScope* scopep = it->first;  AstNodeModule* modp = it->second;
		if (!modp->isTop()) {
		    puts(   scopep->nameDotless()+"."+funcname+"(os);\n");
		}
	    }
	    puts("}\n");
	}
    }
}
コード例 #8
0
void EmitCSyms::emitSymHdr() {
    UINFO(6,__FUNCTION__<<": "<<endl);
    string filename = v3Global.opt.makeDir()+"/"+symClassName()+".h";
    newCFile(filename, true/*slow*/, false/*source*/);
    V3OutCFile hf (filename);
    m_ofp = &hf;

    ofp()->putsHeader();
    puts("// DESCR" "IPTION: Verilator output: Symbol table internal header\n");
    puts("//\n");
    puts("// Internal details; most calling programs do not need this header\n");
    puts("\n");

    puts("#ifndef _"+symClassName()+"_H_\n");
    puts("#define _"+symClassName()+"_H_\n");
    puts("\n");

    if (optSystemPerl()) puts("#include \"systemperl.h\"\n");
    else if (optSystemC()) puts("#include \"systemc.h\"\n");

    if (optSystemPerl() || optSystemC()) {
	puts("#include \"verilated_sc.h\"\n");
    }
    if (v3Global.needHeavy()) {
	puts("#include \"verilated_heavy.h\"\n");
    } else {
	puts("#include \"verilated.h\"\n");
    }

    // for
    puts("\n// INCLUDE MODULE CLASSES\n");
    for (AstNodeModule* nodep = v3Global.rootp()->modulesp(); nodep; nodep=nodep->nextp()->castNodeModule()) {
	puts("#include \""+modClassName(nodep)+".h\"\n");
    }

    if (v3Global.dpi()) {
	puts ("\n// DPI TYPES for DPI Export callbacks (Internal use)\n");
	map<string,int> types;  // Remove duplicates and sort
	for (ScopeFuncs::iterator it = m_scopeFuncs.begin(); it != m_scopeFuncs.end(); ++it) {
	    AstCFunc* funcp = it->second.m_funcp;
	    if (funcp->dpiExport()) {
		string cbtype = v3Global.opt.prefix()+"__Vcb_"+funcp->cname()+"_t";
		types["typedef void (*"+cbtype+") ("+cFuncArgs(funcp)+");\n"] = 1;
	    }
	}
	for (map<string,int>::iterator it = types.begin(); it != types.end(); ++it) {
	    puts(it->first);
	}
    }

    puts("\n// SYMS CLASS\n");
    puts((string)"class "+symClassName()+" : public VerilatedSyms {\n");
    ofp()->putsPrivate(false);  // public:

    puts("\n// LOCAL STATE\n");
    ofp()->putAlign(V3OutFile::AL_AUTO, sizeof(vluint64_t));
    puts("const char* __Vm_namep;\n");	// Must be before subcells, as constructor order needed before _vlCoverInsert.
    ofp()->putAlign(V3OutFile::AL_AUTO, sizeof(bool));
    puts("bool\t__Vm_activity;\t\t///< Used by trace routines to determine change occurred\n");
    ofp()->putAlign(V3OutFile::AL_AUTO, sizeof(bool));
    puts("bool\t__Vm_didInit;\n");

    ofp()->putAlign(V3OutFile::AL_AUTO, sizeof(vluint64_t));
    puts("\n// SUBCELL STATE\n");
    for (vector<ScopeModPair>::iterator it = m_scopes.begin(); it != m_scopes.end(); ++it) {
	AstScope* scopep = it->first;  AstNodeModule* modp = it->second;
	if (modp->isTop()) {
	    ofp()->printf("%-30s ", (modClassName(modp)+"*").c_str());
	    puts(scopep->nameDotless()+"p;\n");
	}
	else {
	    ofp()->printf("%-30s ", (modClassName(modp)+"").c_str());
	    puts(scopep->nameDotless()+";\n");
	}
    }

    puts("\n// COVERAGE\n");
    if (m_coverBins) {
	ofp()->putAlign(V3OutFile::AL_AUTO, sizeof(uint32_t));
	puts("uint32_t\t__Vcoverage["); puts(cvtToStr(m_coverBins)); puts("];\n");
    }

    puts("\n// SCOPE NAMES\n");
    for (ScopeNames::iterator it = m_scopeNames.begin(); it != m_scopeNames.end(); ++it) {
	puts("VerilatedScope __Vscope_"+it->second.m_symName+";\n");
    }

    puts("\n// CREATORS\n");
    puts(symClassName()+"("+topClassName()+"* topp, const char* namep);\n");
    puts((string)"~"+symClassName()+"() {};\n");

    puts("\n// METHODS\n");
    puts("inline const char* name() { return __Vm_namep; }\n");
    puts("inline bool getClearActivity() { bool r=__Vm_activity; __Vm_activity=false; return r;}\n");
    if (v3Global.opt.savable() ) {
	puts("void __Vserialize(VerilatedSerialize& os);\n");
	puts("void __Vdeserialize(VerilatedDeserialize& os);\n");
    }
    puts("\n");
    puts("} VL_ATTR_ALIGNED(64);\n");
    puts("\n");
    puts("#endif  /*guard*/\n");
}