llvm.org GIT mirror llvm / 9a88638
Add -o support for TableGen I figure that misha has done a lot of things on my todo list, the least I can do is reciprocate a bit. :) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6571 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 16 years ago
2 changed file(s) with 50 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
0 #include "Record.h"
11 #include "Support/CommandLine.h"
2 #include "Support/Signals.h"
23 #include "CodeEmitterGen.h"
34 #include
5 #include
46
57 enum ActionType {
68 PrintRecords,
2426
2527 cl::opt
2628 Class("class", cl::desc("Print Enum list for this class"));
29
30 cl::opt
31 OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"),
32 cl::init("-"));
2733 }
2834
2935
373379 cl::ParseCommandLineOptions(argc, argv);
374380 ParseFile();
375381
382 std::ostream *Out = &std::cout;
383 if (OutputFilename != "-") {
384 Out = new std::ofstream(OutputFilename.c_str());
385
386 if (!Out->good()) {
387 std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
388 return 1;
389 }
390
391 // Make sure the file gets removed if *gasp* tablegen crashes...
392 RemoveFileOnSignal(OutputFilename);
393 }
394
376395 switch (Action) {
377396 case Parse: ParseMachineCode(); break;
378397 case GenEmitter:
379 CodeEmitterGen(Records).createEmitter(std::cout);
398 CodeEmitterGen(Records).createEmitter(*Out);
380399 break;
381400 case PrintRecords:
382 std::cout << Records; // No argument, dump all contents
401 *Out << Records; // No argument, dump all contents
383402 break;
384403 case PrintEnums:
385404 Record *R = Records.getClass(Class);
392411 for (std::map::const_iterator I = Defs.begin(),
393412 E = Defs.end(); I != E; ++I) {
394413 if (I->second->isSubClassOf(R)) {
395 std::cout << I->first << ", ";
414 *Out << I->first << ", ";
396415 }
397416 }
398 std::cout << "\n";
417 *Out << "\n";
399418 break;
400419 }
420
421 if (Out != &std::cout) delete Out;
401422 return 0;
402423 }
0 #include "Record.h"
11 #include "Support/CommandLine.h"
2 #include "Support/Signals.h"
23 #include "CodeEmitterGen.h"
34 #include
5 #include
46
57 enum ActionType {
68 PrintRecords,
2426
2527 cl::opt
2628 Class("class", cl::desc("Print Enum list for this class"));
29
30 cl::opt
31 OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"),
32 cl::init("-"));
2733 }
2834
2935
373379 cl::ParseCommandLineOptions(argc, argv);
374380 ParseFile();
375381
382 std::ostream *Out = &std::cout;
383 if (OutputFilename != "-") {
384 Out = new std::ofstream(OutputFilename.c_str());
385
386 if (!Out->good()) {
387 std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
388 return 1;
389 }
390
391 // Make sure the file gets removed if *gasp* tablegen crashes...
392 RemoveFileOnSignal(OutputFilename);
393 }
394
376395 switch (Action) {
377396 case Parse: ParseMachineCode(); break;
378397 case GenEmitter:
379 CodeEmitterGen(Records).createEmitter(std::cout);
398 CodeEmitterGen(Records).createEmitter(*Out);
380399 break;
381400 case PrintRecords:
382 std::cout << Records; // No argument, dump all contents
401 *Out << Records; // No argument, dump all contents
383402 break;
384403 case PrintEnums:
385404 Record *R = Records.getClass(Class);
392411 for (std::map::const_iterator I = Defs.begin(),
393412 E = Defs.end(); I != E; ++I) {
394413 if (I->second->isSubClassOf(R)) {
395 std::cout << I->first << ", ";
414 *Out << I->first << ", ";
396415 }
397416 }
398 std::cout << "\n";
417 *Out << "\n";
399418 break;
400419 }
420
421 if (Out != &std::cout) delete Out;
401422 return 0;
402423 }