Skip to content

Commit

Permalink
[Driver] added option to dump CFG
Browse files Browse the repository at this point in the history
  • Loading branch information
isuckatcs committed Jun 29, 2024
1 parent e35c49d commit 8f0daaf
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <sstream>
#include <string>

#include "cfg.h"
#include "codegen.h"
#include "lexer.h"
#include "parser.h"
Expand All @@ -20,7 +21,8 @@ void displayHelp() {
<< " -o <file> write executable to <file>\n"
<< " -ast-dump print the abstract syntax tree\n"
<< " -res-dump print the resolved syntax tree\n"
<< " -llvm-dump print the llvm module\n";
<< " -llvm-dump print the llvm module\n"
<< " -cfg-dump print the control flow graph\n";
}

[[noreturn]] void error(std::string_view msg) {
Expand All @@ -35,6 +37,7 @@ struct CompilerOptions {
bool astDump = false;
bool resDump = false;
bool llvmDump = false;
bool cfgDump = false;
};

CompilerOptions parseArguments(int argc, const char **argv) {
Expand All @@ -60,6 +63,8 @@ CompilerOptions parseArguments(int argc, const char **argv) {
options.resDump = true;
else if (arg == "-llvm-dump")
options.llvmDump = true;
else if (arg == "-cfg-dump")
options.cfgDump = true;
else
error("unexpected option '" + std::string{arg} + '\'');
}
Expand Down Expand Up @@ -109,6 +114,16 @@ int main(int argc, const char **argv) {
if (resolvedFunctions.empty())
return 1;

// FIXME: Is this the proper place to do this?
if (options.cfgDump) {
for (auto &&fn : resolvedFunctions) {
CFGBuilder b;
b.build(*fn).dump();
}

return 0;
}

if (options.resDump) {
for (auto &&fn : resolvedFunctions)
fn->dump();
Expand Down

0 comments on commit 8f0daaf

Please sign in to comment.