forked from chipsalliance/verible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verilog_filelist.h
94 lines (79 loc) · 3.67 KB
/
verilog_filelist.h
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
// Copyright 2017-2022 The Verible Authors.
//
// 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.
#ifndef VERIBLE_VERILOG_ANALYSIS_VERILOG_FILELIST_H_
#define VERIBLE_VERILOG_ANALYSIS_VERILOG_FILELIST_H_
#include <string>
#include <utility>
#include <vector>
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
namespace verilog {
// TODO(karimtera): Using "MacroDefiniton" struct might be better.
struct TextMacroDefinition {
TextMacroDefinition(std::string name, std::string value)
: name(std::move(name)), value(std::move(value)){};
std::string name;
std::string value;
bool operator==(const TextMacroDefinition &other) const {
return name == other.name && value == other.value;
}
};
// File list for compiling a System Verilog project.
// TODO: ideally, all the strings would be string_views, but we need to make
// sure to have the relevant backing store live.
// TODO: are there cases in which files and incdirs are interleaved so that
// the first files don't see all the incdirs yet, but after more incdirs
// are added, all of them are relevant ? If so, this would require some
// restructering.
// TODO: Introduce file_list_root field ?
struct FileList {
// A struct holding information relevant to "VerilogPreprocess" preprocessor.
struct PreprocessingInfo {
// Directories where to search for the included files.
std::vector<std::string> include_dirs;
// Defined macros.
std::vector<TextMacroDefinition> defines;
};
// Ordered list of files to compile.
std::vector<std::string> file_paths;
// Information relevant to the preprocessor.
PreprocessingInfo preprocessing;
// Returns the file list in Icarus Verilog format
// (http://iverilog.wikia.com/wiki/Command_File_Format)
std::string ToString() const;
};
// Reads in a list of files line-by-line from "file_list_file" and
// appends it to the given filelist.
// Sets the "file_list_path" in FileList.
// +incdir+ adds to include directories (TODO: +define+).
//
// TODO: Maybe remove this as it creates an ephemeral strings with the content.
// If we always use an externally owned string_view (see ..FromContent() below)
// we can replace std::string in FileList with string_views; that way, it is
// always possible to pinpoint back to the owning string view in case we want
// to provide detailed error messages.
absl::Status AppendFileListFromFile(absl::string_view file_list_file,
FileList *append_to);
// Reads in a list of files line-by-line from the given string. The include
// directories are prefixed by "+incdir+" (TODO: +define+)
absl::Status AppendFileListFromContent(absl::string_view file_list_path,
const std::string &file_list_content,
FileList *append_to);
// Parse positional parameters from command line and extract files,
// +incdir+ and +define+ and appends to FileList.
// TODO: Also support --file_list_path (and -f), --file_list_root
absl::Status AppendFileListFromCommandline(
const std::vector<absl::string_view> &cmdline, FileList *append_to);
} // namespace verilog
#endif // VERIBLE_VERILOG_ANALYSIS_VERILOG_FILELIST_H_