mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-06 06:33:24 +00:00
Clean up dis so that it does not print out code in various traversal orders.
Now it only output llvm or C code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2564 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d086fb20eb
commit
aa3904faff
@ -7,22 +7,13 @@
|
|||||||
// to the x.ll file.
|
// to the x.ll file.
|
||||||
// Options:
|
// Options:
|
||||||
// --help - Output information about command line switches
|
// --help - Output information about command line switches
|
||||||
// -dfo - Print basic blocks in depth first order
|
// -c - Print C code instead of LLVM assembly
|
||||||
// -rdfo - Print basic blocks in reverse depth first order
|
|
||||||
// -po - Print basic blocks in post order
|
|
||||||
// -rpo - Print basic blocks in reverse post order
|
|
||||||
//
|
|
||||||
// -c - Print C code
|
|
||||||
//
|
|
||||||
// TODO: add -vcg which prints VCG compatible output.
|
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Bytecode/Reader.h"
|
#include "llvm/Bytecode/Reader.h"
|
||||||
#include "llvm/Support/CFG.h"
|
#include "llvm/Support/CFG.h"
|
||||||
#include "Support/DepthFirstIterator.h"
|
|
||||||
#include "Support/PostOrderIterator.h"
|
|
||||||
#include "Support/CommandLine.h"
|
#include "Support/CommandLine.h"
|
||||||
#include "Support/Signals.h"
|
#include "Support/Signals.h"
|
||||||
#include "llvm/Assembly/CWriter.h"
|
#include "llvm/Assembly/CWriter.h"
|
||||||
@ -32,26 +23,16 @@ using std::cerr;
|
|||||||
|
|
||||||
// OutputMode - The different orderings to print basic blocks in...
|
// OutputMode - The different orderings to print basic blocks in...
|
||||||
enum OutputMode {
|
enum OutputMode {
|
||||||
Default = 0, // Function Order (list order)
|
llvm = 0, // Generate LLVM assembly (the default)
|
||||||
dfo, // Depth First ordering
|
c, // Generate C code
|
||||||
rdfo, // Reverse Depth First ordering
|
|
||||||
po, // Post Order
|
|
||||||
rpo, // Reverse Post Order
|
|
||||||
|
|
||||||
c, // Generate C code
|
|
||||||
};
|
};
|
||||||
|
|
||||||
cl::String InputFilename ("", "Load <arg> file, print as assembly", 0, "-");
|
cl::String InputFilename ("", "Load <arg> file, print as assembly", 0, "-");
|
||||||
cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "");
|
cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "");
|
||||||
cl::Flag Force ("f", "Overwrite output files", cl::NoFlags, false);
|
cl::Flag Force ("f", "Overwrite output files", cl::NoFlags, false);
|
||||||
cl::EnumFlags<enum OutputMode> WriteMode(cl::NoFlags,
|
cl::EnumFlags<enum OutputMode> WriteMode(cl::NoFlags,
|
||||||
clEnumVal(Default, "Write basic blocks in bytecode order"),
|
clEnumVal(llvm, "Output LLVM assembly"),
|
||||||
clEnumVal(dfo , "Write basic blocks in depth first order"),
|
clEnumVal(c , "Output C code for program"),
|
||||||
clEnumVal(rdfo , "Write basic blocks in reverse DFO"),
|
|
||||||
clEnumVal(po , "Write basic blocks in postorder"),
|
|
||||||
clEnumVal(rpo , "Write basic blocks in reverse postorder"),
|
|
||||||
|
|
||||||
clEnumVal(c , "Write corresponding C code"),
|
|
||||||
0);
|
0);
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
@ -85,9 +66,9 @@ int main(int argc, char **argv) {
|
|||||||
OutputFilename = IFN; // Append a .ll to it
|
OutputFilename = IFN; // Append a .ll to it
|
||||||
}
|
}
|
||||||
if (WriteMode == c)
|
if (WriteMode == c)
|
||||||
OutputFilename += ".c";
|
OutputFilename += ".c";
|
||||||
else
|
else
|
||||||
OutputFilename += ".ll";
|
OutputFilename += ".ll";
|
||||||
|
|
||||||
if (!Force && std::ifstream(OutputFilename.c_str())) {
|
if (!Force && std::ifstream(OutputFilename.c_str())) {
|
||||||
// If force is not specified, make sure not to overwrite a file!
|
// If force is not specified, make sure not to overwrite a file!
|
||||||
@ -109,47 +90,15 @@ int main(int argc, char **argv) {
|
|||||||
Out = &std::cout;
|
Out = &std::cout;
|
||||||
}
|
}
|
||||||
|
|
||||||
// All that dis does is write the assembly or C out to a file... which is
|
// All that dis does is write the assembly or C out to a file...
|
||||||
// exactly what the writer or cwriter library is supposed to do...
|
//
|
||||||
if (WriteMode == Default) {
|
switch (WriteMode) {
|
||||||
(*Out) << M; // Print out in list order
|
case llvm:
|
||||||
} else if (WriteMode == c) {
|
(*Out) << M; // Output LLVM assembly
|
||||||
WriteToC(M, *Out);
|
break;
|
||||||
} else {
|
case c:
|
||||||
// TODO: This does not print anything other than the basic blocks in the
|
WriteToC(M, *Out); // Convert LLVM to C
|
||||||
// functions... more should definately be printed. It should be valid
|
break;
|
||||||
// output consumable by the assembler.
|
|
||||||
//
|
|
||||||
for (Module::iterator I = M->begin(), End = M->end(); I != End; ++I) {
|
|
||||||
Function *F = *I;
|
|
||||||
(*Out) << "-------------- Method: " << F->getName() << " -------------\n";
|
|
||||||
|
|
||||||
switch (WriteMode) {
|
|
||||||
case dfo: // Depth First ordering
|
|
||||||
copy(df_begin(F), df_end(F),
|
|
||||||
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
|
|
||||||
break;
|
|
||||||
case rdfo: // Reverse Depth First ordering
|
|
||||||
copy(df_begin(F, true), df_end(F),
|
|
||||||
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
|
|
||||||
break;
|
|
||||||
case po: // Post Order
|
|
||||||
copy(po_begin(F), po_end(F),
|
|
||||||
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
|
|
||||||
break;
|
|
||||||
case rpo: { // Reverse Post Order
|
|
||||||
#if 0 // FIXME, GCC 3.0.4 bug
|
|
||||||
ReversePostOrderTraversal<Function*> RPOT(F);
|
|
||||||
copy(RPOT.begin(), RPOT.end(),
|
|
||||||
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
abort();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
delete M;
|
delete M;
|
||||||
|
|
||||||
|
@ -7,22 +7,13 @@
|
|||||||
// to the x.ll file.
|
// to the x.ll file.
|
||||||
// Options:
|
// Options:
|
||||||
// --help - Output information about command line switches
|
// --help - Output information about command line switches
|
||||||
// -dfo - Print basic blocks in depth first order
|
// -c - Print C code instead of LLVM assembly
|
||||||
// -rdfo - Print basic blocks in reverse depth first order
|
|
||||||
// -po - Print basic blocks in post order
|
|
||||||
// -rpo - Print basic blocks in reverse post order
|
|
||||||
//
|
|
||||||
// -c - Print C code
|
|
||||||
//
|
|
||||||
// TODO: add -vcg which prints VCG compatible output.
|
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Bytecode/Reader.h"
|
#include "llvm/Bytecode/Reader.h"
|
||||||
#include "llvm/Support/CFG.h"
|
#include "llvm/Support/CFG.h"
|
||||||
#include "Support/DepthFirstIterator.h"
|
|
||||||
#include "Support/PostOrderIterator.h"
|
|
||||||
#include "Support/CommandLine.h"
|
#include "Support/CommandLine.h"
|
||||||
#include "Support/Signals.h"
|
#include "Support/Signals.h"
|
||||||
#include "llvm/Assembly/CWriter.h"
|
#include "llvm/Assembly/CWriter.h"
|
||||||
@ -32,26 +23,16 @@ using std::cerr;
|
|||||||
|
|
||||||
// OutputMode - The different orderings to print basic blocks in...
|
// OutputMode - The different orderings to print basic blocks in...
|
||||||
enum OutputMode {
|
enum OutputMode {
|
||||||
Default = 0, // Function Order (list order)
|
llvm = 0, // Generate LLVM assembly (the default)
|
||||||
dfo, // Depth First ordering
|
c, // Generate C code
|
||||||
rdfo, // Reverse Depth First ordering
|
|
||||||
po, // Post Order
|
|
||||||
rpo, // Reverse Post Order
|
|
||||||
|
|
||||||
c, // Generate C code
|
|
||||||
};
|
};
|
||||||
|
|
||||||
cl::String InputFilename ("", "Load <arg> file, print as assembly", 0, "-");
|
cl::String InputFilename ("", "Load <arg> file, print as assembly", 0, "-");
|
||||||
cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "");
|
cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "");
|
||||||
cl::Flag Force ("f", "Overwrite output files", cl::NoFlags, false);
|
cl::Flag Force ("f", "Overwrite output files", cl::NoFlags, false);
|
||||||
cl::EnumFlags<enum OutputMode> WriteMode(cl::NoFlags,
|
cl::EnumFlags<enum OutputMode> WriteMode(cl::NoFlags,
|
||||||
clEnumVal(Default, "Write basic blocks in bytecode order"),
|
clEnumVal(llvm, "Output LLVM assembly"),
|
||||||
clEnumVal(dfo , "Write basic blocks in depth first order"),
|
clEnumVal(c , "Output C code for program"),
|
||||||
clEnumVal(rdfo , "Write basic blocks in reverse DFO"),
|
|
||||||
clEnumVal(po , "Write basic blocks in postorder"),
|
|
||||||
clEnumVal(rpo , "Write basic blocks in reverse postorder"),
|
|
||||||
|
|
||||||
clEnumVal(c , "Write corresponding C code"),
|
|
||||||
0);
|
0);
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
@ -85,9 +66,9 @@ int main(int argc, char **argv) {
|
|||||||
OutputFilename = IFN; // Append a .ll to it
|
OutputFilename = IFN; // Append a .ll to it
|
||||||
}
|
}
|
||||||
if (WriteMode == c)
|
if (WriteMode == c)
|
||||||
OutputFilename += ".c";
|
OutputFilename += ".c";
|
||||||
else
|
else
|
||||||
OutputFilename += ".ll";
|
OutputFilename += ".ll";
|
||||||
|
|
||||||
if (!Force && std::ifstream(OutputFilename.c_str())) {
|
if (!Force && std::ifstream(OutputFilename.c_str())) {
|
||||||
// If force is not specified, make sure not to overwrite a file!
|
// If force is not specified, make sure not to overwrite a file!
|
||||||
@ -109,47 +90,15 @@ int main(int argc, char **argv) {
|
|||||||
Out = &std::cout;
|
Out = &std::cout;
|
||||||
}
|
}
|
||||||
|
|
||||||
// All that dis does is write the assembly or C out to a file... which is
|
// All that dis does is write the assembly or C out to a file...
|
||||||
// exactly what the writer or cwriter library is supposed to do...
|
//
|
||||||
if (WriteMode == Default) {
|
switch (WriteMode) {
|
||||||
(*Out) << M; // Print out in list order
|
case llvm:
|
||||||
} else if (WriteMode == c) {
|
(*Out) << M; // Output LLVM assembly
|
||||||
WriteToC(M, *Out);
|
break;
|
||||||
} else {
|
case c:
|
||||||
// TODO: This does not print anything other than the basic blocks in the
|
WriteToC(M, *Out); // Convert LLVM to C
|
||||||
// functions... more should definately be printed. It should be valid
|
break;
|
||||||
// output consumable by the assembler.
|
|
||||||
//
|
|
||||||
for (Module::iterator I = M->begin(), End = M->end(); I != End; ++I) {
|
|
||||||
Function *F = *I;
|
|
||||||
(*Out) << "-------------- Method: " << F->getName() << " -------------\n";
|
|
||||||
|
|
||||||
switch (WriteMode) {
|
|
||||||
case dfo: // Depth First ordering
|
|
||||||
copy(df_begin(F), df_end(F),
|
|
||||||
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
|
|
||||||
break;
|
|
||||||
case rdfo: // Reverse Depth First ordering
|
|
||||||
copy(df_begin(F, true), df_end(F),
|
|
||||||
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
|
|
||||||
break;
|
|
||||||
case po: // Post Order
|
|
||||||
copy(po_begin(F), po_end(F),
|
|
||||||
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
|
|
||||||
break;
|
|
||||||
case rpo: { // Reverse Post Order
|
|
||||||
#if 0 // FIXME, GCC 3.0.4 bug
|
|
||||||
ReversePostOrderTraversal<Function*> RPOT(F);
|
|
||||||
copy(RPOT.begin(), RPOT.end(),
|
|
||||||
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
abort();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
delete M;
|
delete M;
|
||||||
|
|
||||||
|
@ -7,22 +7,13 @@
|
|||||||
// to the x.ll file.
|
// to the x.ll file.
|
||||||
// Options:
|
// Options:
|
||||||
// --help - Output information about command line switches
|
// --help - Output information about command line switches
|
||||||
// -dfo - Print basic blocks in depth first order
|
// -c - Print C code instead of LLVM assembly
|
||||||
// -rdfo - Print basic blocks in reverse depth first order
|
|
||||||
// -po - Print basic blocks in post order
|
|
||||||
// -rpo - Print basic blocks in reverse post order
|
|
||||||
//
|
|
||||||
// -c - Print C code
|
|
||||||
//
|
|
||||||
// TODO: add -vcg which prints VCG compatible output.
|
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Bytecode/Reader.h"
|
#include "llvm/Bytecode/Reader.h"
|
||||||
#include "llvm/Support/CFG.h"
|
#include "llvm/Support/CFG.h"
|
||||||
#include "Support/DepthFirstIterator.h"
|
|
||||||
#include "Support/PostOrderIterator.h"
|
|
||||||
#include "Support/CommandLine.h"
|
#include "Support/CommandLine.h"
|
||||||
#include "Support/Signals.h"
|
#include "Support/Signals.h"
|
||||||
#include "llvm/Assembly/CWriter.h"
|
#include "llvm/Assembly/CWriter.h"
|
||||||
@ -32,26 +23,16 @@ using std::cerr;
|
|||||||
|
|
||||||
// OutputMode - The different orderings to print basic blocks in...
|
// OutputMode - The different orderings to print basic blocks in...
|
||||||
enum OutputMode {
|
enum OutputMode {
|
||||||
Default = 0, // Function Order (list order)
|
llvm = 0, // Generate LLVM assembly (the default)
|
||||||
dfo, // Depth First ordering
|
c, // Generate C code
|
||||||
rdfo, // Reverse Depth First ordering
|
|
||||||
po, // Post Order
|
|
||||||
rpo, // Reverse Post Order
|
|
||||||
|
|
||||||
c, // Generate C code
|
|
||||||
};
|
};
|
||||||
|
|
||||||
cl::String InputFilename ("", "Load <arg> file, print as assembly", 0, "-");
|
cl::String InputFilename ("", "Load <arg> file, print as assembly", 0, "-");
|
||||||
cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "");
|
cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "");
|
||||||
cl::Flag Force ("f", "Overwrite output files", cl::NoFlags, false);
|
cl::Flag Force ("f", "Overwrite output files", cl::NoFlags, false);
|
||||||
cl::EnumFlags<enum OutputMode> WriteMode(cl::NoFlags,
|
cl::EnumFlags<enum OutputMode> WriteMode(cl::NoFlags,
|
||||||
clEnumVal(Default, "Write basic blocks in bytecode order"),
|
clEnumVal(llvm, "Output LLVM assembly"),
|
||||||
clEnumVal(dfo , "Write basic blocks in depth first order"),
|
clEnumVal(c , "Output C code for program"),
|
||||||
clEnumVal(rdfo , "Write basic blocks in reverse DFO"),
|
|
||||||
clEnumVal(po , "Write basic blocks in postorder"),
|
|
||||||
clEnumVal(rpo , "Write basic blocks in reverse postorder"),
|
|
||||||
|
|
||||||
clEnumVal(c , "Write corresponding C code"),
|
|
||||||
0);
|
0);
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
@ -85,9 +66,9 @@ int main(int argc, char **argv) {
|
|||||||
OutputFilename = IFN; // Append a .ll to it
|
OutputFilename = IFN; // Append a .ll to it
|
||||||
}
|
}
|
||||||
if (WriteMode == c)
|
if (WriteMode == c)
|
||||||
OutputFilename += ".c";
|
OutputFilename += ".c";
|
||||||
else
|
else
|
||||||
OutputFilename += ".ll";
|
OutputFilename += ".ll";
|
||||||
|
|
||||||
if (!Force && std::ifstream(OutputFilename.c_str())) {
|
if (!Force && std::ifstream(OutputFilename.c_str())) {
|
||||||
// If force is not specified, make sure not to overwrite a file!
|
// If force is not specified, make sure not to overwrite a file!
|
||||||
@ -109,47 +90,15 @@ int main(int argc, char **argv) {
|
|||||||
Out = &std::cout;
|
Out = &std::cout;
|
||||||
}
|
}
|
||||||
|
|
||||||
// All that dis does is write the assembly or C out to a file... which is
|
// All that dis does is write the assembly or C out to a file...
|
||||||
// exactly what the writer or cwriter library is supposed to do...
|
//
|
||||||
if (WriteMode == Default) {
|
switch (WriteMode) {
|
||||||
(*Out) << M; // Print out in list order
|
case llvm:
|
||||||
} else if (WriteMode == c) {
|
(*Out) << M; // Output LLVM assembly
|
||||||
WriteToC(M, *Out);
|
break;
|
||||||
} else {
|
case c:
|
||||||
// TODO: This does not print anything other than the basic blocks in the
|
WriteToC(M, *Out); // Convert LLVM to C
|
||||||
// functions... more should definately be printed. It should be valid
|
break;
|
||||||
// output consumable by the assembler.
|
|
||||||
//
|
|
||||||
for (Module::iterator I = M->begin(), End = M->end(); I != End; ++I) {
|
|
||||||
Function *F = *I;
|
|
||||||
(*Out) << "-------------- Method: " << F->getName() << " -------------\n";
|
|
||||||
|
|
||||||
switch (WriteMode) {
|
|
||||||
case dfo: // Depth First ordering
|
|
||||||
copy(df_begin(F), df_end(F),
|
|
||||||
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
|
|
||||||
break;
|
|
||||||
case rdfo: // Reverse Depth First ordering
|
|
||||||
copy(df_begin(F, true), df_end(F),
|
|
||||||
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
|
|
||||||
break;
|
|
||||||
case po: // Post Order
|
|
||||||
copy(po_begin(F), po_end(F),
|
|
||||||
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
|
|
||||||
break;
|
|
||||||
case rpo: { // Reverse Post Order
|
|
||||||
#if 0 // FIXME, GCC 3.0.4 bug
|
|
||||||
ReversePostOrderTraversal<Function*> RPOT(F);
|
|
||||||
copy(RPOT.begin(), RPOT.end(),
|
|
||||||
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
abort();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
delete M;
|
delete M;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user