本文整理汇总了C++中Encoder::encodeChunk方法的典型用法代码示例。如果您正苦于以下问题:C++ Encoder::encodeChunk方法的具体用法?C++ Encoder::encodeChunk怎么用?C++ Encoder::encodeChunk使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Encoder
的用法示例。
在下文中一共展示了Encoder::encodeChunk方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: asm_main
int asm_main(int argc, char **argv) {
string archString("8w32/32/8"), outFileName("a.out.HOF"),
inFileName(argv[argc-1]);
bool showHelp;
/* Get command line arguments. */
CommandLineArgFlag fh("-h", "--help", "", showHelp);
CommandLineArgSetter<string>fo("-o", "--output", "", outFileName);
CommandLineArgSetter<string>fa("-a", "--arch", "", archString);
CommandLineArg::readArgs(argc-1, argv);
if (showHelp || argc == 0) {
cout << Help::asmHelp;
exit(0);
}
ArchDef arch(archString);
D(0, "Created ArchDef for " << string(arch));
/* Create an appropriate encoder. */
Encoder *enc;
switch (arch.getEncChar()) {
case 'b': enc = new ByteEncoder(arch); break;
case 'w': enc = new WordEncoder(arch); break;
defaulet:
cout << "Unknown encoding type, \"" << arch.getEncChar() << "\"\n";
exit(1);
}
/* Open files. */
if (outFileName == "") {
cout << "HARP Assembler: No output filename given.\n";
exit(1);
}
ifstream asmFile(inFileName.c_str());
ofstream outFile(outFileName.c_str());
if (!asmFile) {
cout << "Could not open \"" << inFileName << "\" for reading.\n";
exit(1);
}
if (!outFile) {
cout << "Could not open \"" << outFileName << "\" for writing.\n";
exit(1);
}
/* Read an Obj from the assembly file. */
D(0, "Passing AsmReader ArchDef: " << string(arch));
AsmReader ar(arch);
Obj *o = ar.read(asmFile);
/* Encode the text chunks read from the assembly file. */
for (Size j = 0; j < o->chunks.size(); j++) {
Chunk *&c = o->chunks[j];
TextChunk *tc;
DataChunk *dc;
if ((tc = dynamic_cast<TextChunk*>(c)) != NULL) {
/* Encode it. */
dc = new DataChunk(tc->name);
enc->encodeChunk(*dc, *tc);
/* Delete the text chunk. */
delete tc;
/* Do the switch. */
c = dc;
}
}
asmFile.close();
delete enc;
/* Write a HOF binary. */
D(0, "Creating a HOFWriter, passing it ArchDef: " << string(arch));
HOFWriter hw(arch);
hw.write(outFile, *o);
outFile.close();
delete o;
return 0;
}