20
20
#include " absl/status/status.h"
21
21
#include " absl/strings/str_cat.h"
22
22
#include " absl/strings/string_view.h"
23
+ #include " common/lexer/token_stream_adapter.h"
23
24
#include " common/util/file_util.h"
24
25
#include " common/util/init_command_line.h"
25
26
#include " common/util/subcommand.h"
26
- #include " verilog/transform/strip_comments.h"
27
- #include " verilog/parser/verilog_lexer.h"
28
- #include " verilog/preprocessor/verilog_preprocess.h"
29
- #include " common/lexer/token_stream_adapter.h"
27
+ #include " verilog/analysis/flow_tree.h"
30
28
#include " verilog/analysis/verilog_analyzer.h"
29
+ #include " verilog/parser/verilog_lexer.h"
31
30
#include " verilog/parser/verilog_token_enum.h"
32
- #include " verilog/analysis/flow_tree.h"
31
+ #include " verilog/preprocessor/verilog_preprocess.h"
32
+ #include " verilog/transform/strip_comments.h"
33
33
34
34
using verible::SubcommandArgsRange;
35
35
using verible::SubcommandEntry;
@@ -55,67 +55,68 @@ static absl::Status StripComments(const SubcommandArgsRange& args,
55
55
return absl::OkStatus ();
56
56
}
57
57
58
-
59
- static absl::Status MultipleCU (const SubcommandArgsRange& args,
60
- std::istream&, std::ostream& outs,
61
- std::ostream&) {
58
+ static absl::Status MultipleCU (const SubcommandArgsRange& args, std::istream&,
59
+ std::ostream& outs, std::ostream&) {
62
60
if (args.empty ()) {
63
- return absl::InvalidArgumentError (
64
- " Missing file argument." );
61
+ return absl::InvalidArgumentError (" Missing file argument." );
65
62
}
66
63
67
- for (auto source_file: args){
64
+ for (auto source_file : args) {
68
65
std::string source_contents;
69
66
if (auto status = verible::file::GetContents (source_file, &source_contents);
70
67
!status.ok ()) {
71
68
return status;
72
69
}
73
70
verilog::VerilogPreprocess::Config config;
74
- config.filter_branches = 1 ;
75
- // config.expand_macros=1;
71
+ config.filter_branches = 1 ;
72
+ // config.expand_macros=1;
76
73
verilog::VerilogPreprocess preprocessor (config);
77
74
verilog::VerilogLexer lexer (source_contents);
78
75
verible::TokenSequence lexed_sequence;
79
- for (lexer.DoNextToken (); !lexer.GetLastToken ().isEOF ();
80
- lexer.DoNextToken ()) {
81
- // For now we will store the syntax tree tokens only, ignoring all the white-space characters.
82
- // however that should be stored to output the source code just like it was, but with conditionals filtered.
83
- if (verilog::VerilogLexer::KeepSyntaxTreeTokens (lexer.GetLastToken ())) lexed_sequence.push_back (lexer.GetLastToken ());
76
+ for (lexer.DoNextToken (); !lexer.GetLastToken ().isEOF ();
77
+ lexer.DoNextToken ()) {
78
+ // For now we will store the syntax tree tokens only, ignoring all the
79
+ // white-space characters. however that should be stored to output the
80
+ // source code just like it was, but with conditionals filtered.
81
+ if (verilog::VerilogLexer::KeepSyntaxTreeTokens (lexer.GetLastToken ()))
82
+ lexed_sequence.push_back (lexer.GetLastToken ());
84
83
}
85
84
verible::TokenStreamView lexed_streamview;
86
85
// Initializing the lexed token stream view.
87
86
InitTokenStreamView (lexed_sequence, &lexed_streamview);
88
- verilog::VerilogPreprocessData preprocessed_data = preprocessor.ScanStream (lexed_streamview);
87
+ verilog::VerilogPreprocessData preprocessed_data =
88
+ preprocessor.ScanStream (lexed_streamview);
89
89
auto & preprocessed_stream = preprocessed_data.preprocessed_token_stream ;
90
- for (auto u:preprocessed_stream) outs<<*u<<' \n ' ; // output the preprocessed tokens.
91
- for (auto & u:preprocessed_data.errors ) outs<<u.error_message <<' \n ' ; // for debugging.
90
+ for (auto u : preprocessed_stream)
91
+ outs << *u << ' \n ' ; // output the preprocessed tokens.
92
+ for (auto & u : preprocessed_data.errors )
93
+ outs << u.error_message << ' \n ' ; // for debugging.
92
94
// parsing just as a trial
93
95
std::string post_preproc;
94
- for (auto u: preprocessed_stream) post_preproc+= std::string{u->text ()};
96
+ for (auto u : preprocessed_stream) post_preproc += std::string{u->text ()};
95
97
std::string source_view{post_preproc};
96
- verilog::VerilogAnalyzer analyzer (source_view," file1" ,config);
98
+ verilog::VerilogAnalyzer analyzer (source_view, " file1" , config);
97
99
auto analyze_status = analyzer.Analyze ();
98
100
const auto & mydata = analyzer.Data ().Contents ();
99
101
/* outs<<mydata; */
100
102
101
-
102
103
/* TODO(karimtera): regarding conditionals
103
- 1) Modify VerilogPreprocess config to have a configuration to generate SV source codes for all possible variants.
104
- 2) Then use parser, directly from VerilogAnalyzer or from VerilogParser to have less dependences.
105
- 3) Now, we should have multiple trees, we need to merge them as described by Tom in Verible's issue.
106
- 4) Finally, travese the tree and output the chosen path based on definitions.
104
+ 1) Modify VerilogPreprocess config to have a configuration to generate SV
105
+ source codes for all possible variants. 2) Then use parser, directly from
106
+ VerilogAnalyzer or from VerilogParser to have less dependences. 3) Now, we
107
+ should have multiple trees, we need to merge them as described by Tom in
108
+ Verible's issue. 4) Finally, travese the tree and output the chosen path
109
+ based on definitions.
107
110
*/
108
111
}
109
112
return absl::OkStatus ();
110
113
}
111
114
112
-
113
115
static absl::Status GenerateVariants (const SubcommandArgsRange& args,
114
- std::istream&, std::ostream& outs,
115
- std::ostream&) {
116
+ std::istream&, std::ostream& outs,
117
+ std::ostream&) {
116
118
if (args.empty ()) {
117
- return absl::InvalidArgumentError (
118
- " Missing file argument." );
119
+ return absl::InvalidArgumentError (" Missing file argument." );
119
120
}
120
121
121
122
const char * source_file = args[0 ];
@@ -126,23 +127,23 @@ static absl::Status GenerateVariants(const SubcommandArgsRange& args,
126
127
}
127
128
verilog::VerilogLexer lexer (source_contents);
128
129
verible::TokenSequence lexed_sequence;
129
- for (lexer.DoNextToken (); !lexer.GetLastToken ().isEOF ();
130
- lexer.DoNextToken ()) {
131
- // For now we will store the syntax tree tokens only, ignoring all the white-space characters.
132
- // however that should be stored to output the source code just like it was.
133
- if (verilog::VerilogLexer::KeepSyntaxTreeTokens (lexer.GetLastToken ())) lexed_sequence.push_back (lexer.GetLastToken ());
130
+ for (lexer.DoNextToken (); !lexer.GetLastToken ().isEOF ();
131
+ lexer.DoNextToken ()) {
132
+ // For now we will store the syntax tree tokens only, ignoring all the
133
+ // white-space characters. however that should be stored to output the
134
+ // source code just like it was.
135
+ if (verilog::VerilogLexer::KeepSyntaxTreeTokens (lexer.GetLastToken ()))
136
+ lexed_sequence.push_back (lexer.GetLastToken ());
134
137
}
135
138
136
139
verilog::FlowTree control_flow_tree (lexed_sequence);
137
140
auto status = control_flow_tree.GenerateControlFlowTree ();
138
141
status = control_flow_tree.DepthFirstSearch (0 );
139
- int cnt= 1 ;
140
- for (const auto & u: control_flow_tree.variants_ ){
141
- outs<< " Variant number " << cnt++<< " :\n " ;
142
- for (auto k: u) outs<<k<< ' \n ' ;
142
+ int cnt = 1 ;
143
+ for (const auto & u : control_flow_tree.variants_ ) {
144
+ outs << " Variant number " << cnt++ << " :\n " ;
145
+ for (auto k : u) outs << k << ' \n ' ;
143
146
puts (" " );
144
-
145
-
146
147
}
147
148
148
149
return absl::OkStatus ();
0 commit comments