-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_blackbox.cpp
executable file
·74 lines (57 loc) · 2.17 KB
/
main_blackbox.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "slang/ast/Compilation.h"
#include "slang/driver/Driver.h"
#include "slang/util/VersionInfo.h"
#include <iostream>
#include "documenter_visitor.h"
using namespace slang;
using namespace slang::driver;
int main(int argc, char** argv) {
Driver driver;
driver.addStandardArgs();
std::optional<bool> showHelp;
std::optional<bool> showVersion;
std::optional<bool> pretty;
std::optional<bool> onlyModules;
driver.cmdLine.add("-h,--help", showHelp, "Display available options");
driver.cmdLine.add("--version", showVersion, "Display version information and exit");
driver.cmdLine.add("--pretty", pretty, "Prettify the output");
driver.cmdLine.add("--only-modules", onlyModules, "Only output module names");
if (!driver.parseCommandLine(argc, argv))
return 1;
if (showHelp == true) {
printf("%s\n", driver.cmdLine.getHelpText("slang SystemVerilog compiler").c_str());
return 0;
}
if (showVersion == true) {
printf("slang version %d.%d.%d+%s\n", VersionInfo::getMajor(),
VersionInfo::getMinor(), VersionInfo::getPatch(),
std::string(VersionInfo::getHash()).c_str());
return 0;
}
if (!driver.processOptions())
return 2;
bool ok = driver.parseAllSources();
auto compilation = driver.createCompilation();
ok &= driver.reportCompilation(*compilation, /* quiet */ true);
auto syntax_trees = compilation->getSyntaxTrees();
DocumenterVisitor visitor(bool(onlyModules), &(driver.sourceManager));
json output;
output["modules"] = json::array();
if(! onlyModules)
output["content"] = json::array();
for (auto st : syntax_trees)
{
//std::cout << "Found syntax tree" << std::endl;
visitor.set_source_manager(&(st->sourceManager()));
st->root().visit(visitor);
output["modules"].push_back(visitor.module);
if(! onlyModules)
output["content"].push_back(visitor.data);
}
//std::cout << "JSON Output is :" << std::endl;
if(pretty)
std::cout << output.dump(4) << std::endl;
else
std::cout << output.dump() << std::endl;
return ok ? 0 : 3;
}