forked from chipsalliance/Surelog
-
Notifications
You must be signed in to change notification settings - Fork 3
/
hellodesign.cpp
121 lines (102 loc) · 3.93 KB
/
hellodesign.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
Copyright 2021 Alain Dargelas & Bsp13
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
* File: hellodesign.cpp
* Author: alain & bsp13
*
* Created on April 18, 2021, 08:07 PM
*/
// Example of usage:
// cd tests/UnitElabBlock
// hellodesign top.v -parse -mutestdout
#include <Surelog/API/Surelog.h>
#include <Surelog/CommandLine/CommandLineParser.h>
#include <Surelog/ErrorReporting/ErrorContainer.h>
#include <Surelog/SourceCompile/SymbolTable.h>
#include <functional>
#include <iostream>
// UHDM
#include <uhdm/ElaboratorListener.h>
#include <uhdm/VpiListener.h>
#include <uhdm/uhdm.h>
class DesignListener final : public UHDM::VpiListener {
void enterModule_inst(const UHDM::module_inst *object,
vpiHandle handle) final {
std::string_view instName = object->VpiName();
m_flatTraversal =
(instName.empty()) && ((object->VpiParent() == 0) ||
((object->VpiParent() != 0) &&
(object->VpiParent()->VpiType() != vpiModule)));
if (m_flatTraversal)
std::cout << "Entering Module Definition: " << object->VpiDefName() << " "
<< intptr_t(object) << " " << object->UhdmId() << std::endl;
else
std::cout << "Entering Module Instance: " << object->VpiFullName() << " "
<< intptr_t(object) << " " << object->UhdmId() << std::endl;
}
void enterCont_assign(const UHDM::cont_assign *object,
vpiHandle handle) final {
if (m_flatTraversal) {
std::cout << " Let's skip the cont assigns in the flat traversal and "
"only navigate the ones in the hierarchical tree!"
<< std::endl;
} else {
std::cout << " enterCont_assign " << intptr_t(object) << " "
<< object->UhdmId() << std::endl;
}
}
private:
bool m_flatTraversal = false;
};
static bool Build(const vpiHandle &design_handle) {
DesignListener listener;
listener.listenDesigns({design_handle});
std::cout << "End design traversal" << std::endl;
return true;
}
int main(int argc, const char **argv) {
if (argc < 2) return 0;
// Read command line, compile a design, use -parse argument
int32_t code = 0;
SURELOG::SymbolTable *const symbolTable = new SURELOG::SymbolTable();
SURELOG::ErrorContainer *const errors =
new SURELOG::ErrorContainer(symbolTable);
SURELOG::CommandLineParser *const clp =
new SURELOG::CommandLineParser(errors, symbolTable, false, false);
clp->noPython();
clp->setwritePpOutput(true);
clp->setParse(true);
clp->setCompile(true);
clp->setElaborate(true); // Request Surelog instance tree elaboration
clp->setElabUhdm(true); // Request UHDM Uniquification/Elaboration
bool success = clp->parseCommandLine(argc, argv);
errors->printMessages(clp->muteStdout());
vpiHandle vpi_design = nullptr;
SURELOG::scompiler *compiler = nullptr;
if (success && (!clp->help())) {
compiler = SURELOG::start_compiler(clp);
vpi_design = SURELOG::get_uhdm_design(compiler);
auto stats = errors->getErrorStats();
code = (!success) | stats.nbFatal | stats.nbSyntax | stats.nbError;
}
SURELOG::ErrorContainer::Stats stats = errors->getErrorStats();
errors->printStats(stats, false);
if (vpi_design == nullptr) return code;
if (!Build(vpi_design)) return -1;
// Do not delete these objects until you are done with UHDM
SURELOG::shutdown_compiler(compiler);
delete clp;
delete symbolTable;
delete errors;
return 0;
}