Skip to content

Commit 230ad6e

Browse files
Merge pull request #3667 from alainmarcel/alainmarcel-patch-1
purge parsers before elab
2 parents e181f12 + a98e275 commit 230ad6e

File tree

9 files changed

+59
-51
lines changed

9 files changed

+59
-51
lines changed

include/Surelog/DesignCompile/CompileDesign.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ class CompileDesign {
4949

5050
bool compile();
5151
bool elaborate();
52+
void purgeParsers();
5253
vpiHandle writeUHDM(PathId fileId);
5354

5455
Compiler* getCompiler() const { return m_compiler; }
5556
virtual UHDM::Serializer& getSerializer() { return m_serializer; }
5657
void lockSerializer() { m_serializerMutex.lock(); }
5758
void unlockSerializer() { m_serializerMutex.unlock(); }
58-
59+
UHDM::VectorOfinclude_file_info* getFileInfo() { return m_fileInfo; }
60+
5961
private:
6062
CompileDesign(const CompileDesign& orig) = delete;
6163

@@ -70,7 +72,7 @@ class CompileDesign {
7072
Compiler* const m_compiler;
7173
std::vector<SymbolTable*> m_symbolTables;
7274
std::vector<ErrorContainer*> m_errorContainers;
73-
75+
UHDM::VectorOfinclude_file_info* m_fileInfo = nullptr;
7476
std::mutex m_serializerMutex;
7577
UHDM::Serializer m_serializer;
7678
};

include/Surelog/SourceCompile/Compiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Compiler {
6666
virtual ~Compiler();
6767

6868
bool compile();
69+
void purgeParsers();
6970
CommandLineParser* getCommandLineParser() const {
7071
return m_commandLineParser;
7172
}

src/Common/PlatformFileSystem_test.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,26 +1035,15 @@ TEST(PlatformFileSystemTest, InMemoryTest) {
10351035

10361036
Compiler *const compiler = new Compiler(clp, errors, symbolTable);
10371037
compiler->compile();
1038+
Design *design = compiler->getDesign();
1039+
EXPECT_NE(design, nullptr);
10381040

1039-
const auto &compileSourceFiles = compiler->getCompileSourceFiles();
1040-
EXPECT_EQ(compileSourceFiles.size(), 1);
1041-
1042-
CompileSourceFile *const compileSourceFile = compileSourceFiles.front();
1043-
EXPECT_NE(compileSourceFile, nullptr);
1044-
1045-
ParseFile *const parseFile = compileSourceFile->getParser();
1046-
EXPECT_NE(parseFile, nullptr);
1047-
1048-
FileContent *const fC = parseFile->getFileContent();
1049-
EXPECT_NE(fC, nullptr);
1041+
const auto &compileSourceFiles = design->getAllFileContents();
1042+
EXPECT_EQ(compileSourceFiles.size(), 2);
10501043

10511044
CompileDesign *const compileDesign = compiler->getCompileDesign();
10521045
EXPECT_NE(compileDesign, nullptr);
10531046

1054-
// Preprocess, Parse, Compile, Elaborate
1055-
Design *const design = compiler->getDesign();
1056-
EXPECT_NE(design, nullptr);
1057-
10581047
const auto &insts = design->getTopLevelModuleInstances();
10591048
ModuleInstance *top = nullptr;
10601049
if (!insts.empty()) {

src/DesignCompile/CompileDesign.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <Surelog/Testbench/Program.h>
5050

5151
// UHDM
52+
#include <uhdm/include_file_info.h>
5253
#include <uhdm/param_assign.h>
5354
#include <uhdm/vpi_visitor.h>
5455

@@ -331,6 +332,28 @@ bool CompileDesign::compilation_() {
331332
builtin->addBuiltinClasses();
332333
}
333334

335+
// Compile Include file info
336+
FileSystem* const fileSystem = FileSystem::getInstance();
337+
m_fileInfo = m_serializer.MakeInclude_file_infoVec();
338+
for (const CompileSourceFile* sourceFile :
339+
getCompiler()->getCompileSourceFiles()) {
340+
const PreprocessFile* const pf = sourceFile->getPreprocessor();
341+
for (const IncludeFileInfo& ifi : pf->getIncludeFileInfo()) {
342+
if ((ifi.m_context == IncludeFileInfo::Context::INCLUDE) &&
343+
(ifi.m_action == IncludeFileInfo::Action::PUSH)) {
344+
UHDM::include_file_info* const pifi =
345+
m_serializer.MakeInclude_file_info();
346+
pifi->VpiFile(fileSystem->toPath(pf->getRawFileId()));
347+
pifi->VpiIncludedFile(fileSystem->toPath(ifi.m_sectionFileId));
348+
pifi->VpiLineNo(ifi.m_originalStartLine);
349+
pifi->VpiColumnNo(ifi.m_originalStartColumn);
350+
pifi->VpiEndLineNo(ifi.m_originalEndLine);
351+
pifi->VpiEndColumnNo(ifi.m_originalEndColumn);
352+
m_fileInfo->push_back(pifi);
353+
}
354+
}
355+
}
356+
334357
// Compile classes
335358
compileMT_<ClassDefinition, ClassNameClassDefinitionMultiMap,
336359
FunctorCompileClass>(
@@ -370,6 +393,8 @@ bool CompileDesign::elaboration_() {
370393
return true;
371394
}
372395

396+
void CompileDesign::purgeParsers() { m_compiler->purgeParsers(); }
397+
373398
vpiHandle CompileDesign::writeUHDM(PathId fileId) {
374399
UhdmWriter* uhdmwriter = new UhdmWriter(this, m_compiler->getDesign());
375400
vpiHandle h = uhdmwriter->write(fileId);

src/DesignCompile/ElaboratorHarness.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323

2424
#include <Surelog/CommandLine/CommandLineParser.h>
25+
#include <Surelog/Design/Design.h>
2526
#include <Surelog/DesignCompile/ElaboratorHarness.h>
2627
#include <Surelog/ErrorReporting/ErrorContainer.h>
2728
#include <Surelog/SourceCompile/CompileSourceFile.h>
@@ -47,10 +48,8 @@ std::tuple<Design*, FileContent*, CompileDesign*> ElaboratorHarness::elaborate(
4748
compiler->compile();
4849
Design* design = compiler->getDesign();
4950
FileContent* fC = nullptr;
50-
if (!compiler->getCompileSourceFiles().empty()) {
51-
CompileSourceFile* csf = compiler->getCompileSourceFiles().at(0);
52-
ParseFile* pf = csf->getParser();
53-
fC = pf->getFileContent();
51+
if (!design->getAllFileContents().empty()) {
52+
fC = design->getAllFileContents()[0].second;
5453
}
5554
result = std::make_tuple(design, fC, compiler->getCompileDesign());
5655
return result;

src/DesignCompile/UhdmWriter.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3901,26 +3901,7 @@ vpiHandle UhdmWriter::write(PathId uhdmFileId) {
39013901

39023902
// ---------------------------
39033903
// Include File Info
3904-
3905-
VectorOfinclude_file_info* fileInfos = s.MakeInclude_file_infoVec();
3906-
d->Include_file_infos(fileInfos);
3907-
for (const CompileSourceFile* sourceFile :
3908-
m_compileDesign->getCompiler()->getCompileSourceFiles()) {
3909-
const PreprocessFile* const pf = sourceFile->getPreprocessor();
3910-
for (const IncludeFileInfo& ifi : pf->getIncludeFileInfo()) {
3911-
if ((ifi.m_context == IncludeFileInfo::Context::INCLUDE) &&
3912-
(ifi.m_action == IncludeFileInfo::Action::PUSH)) {
3913-
include_file_info* const pifi = s.MakeInclude_file_info();
3914-
pifi->VpiFile(fileSystem->toPath(pf->getRawFileId()));
3915-
pifi->VpiIncludedFile(fileSystem->toPath(ifi.m_sectionFileId));
3916-
pifi->VpiLineNo(ifi.m_originalStartLine);
3917-
pifi->VpiColumnNo(ifi.m_originalStartColumn);
3918-
pifi->VpiEndLineNo(ifi.m_originalEndLine);
3919-
pifi->VpiEndColumnNo(ifi.m_originalEndColumn);
3920-
fileInfos->push_back(pifi);
3921-
}
3922-
}
3923-
}
3904+
d->Include_file_infos(m_compileDesign->getFileInfo());
39243905

39253906
// -------------------------------
39263907
// Non-Elaborated Model

src/SourceCompile/Compiler.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ Compiler::~Compiler() {
103103
cleanup_();
104104
}
105105

106+
void Compiler::purgeParsers() {
107+
for (auto& entry : m_antlrPpMap) {
108+
delete entry.second;
109+
}
110+
111+
m_antlrPpMap.clear();
112+
DeleteContainerPointersAndClear(&m_compilers);
113+
}
114+
106115
struct FunctorCompileOneFile {
107116
FunctorCompileOneFile(CompileSourceFile* compileSource,
108117
CompileSourceFile::Action action)
@@ -1042,6 +1051,8 @@ bool Compiler::compile() {
10421051
tmr.reset();
10431052
}
10441053

1054+
m_compileDesign->purgeParsers();
1055+
10451056
if (m_commandLineParser->elaborate()) {
10461057
m_compileDesign->elaborate();
10471058
m_errors->printMessages(m_commandLineParser->muteStdout());

third_party/antlr4

Submodule antlr4 updated 49 files

third_party/tests/CoresSweRVMP/CoresSweRVMP.log

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[WRN:CM0010] Command line argument "-Wno-UNOPTFLAT" ignored.
44

55
Running: cd ${SURELOG_DIR}/build/regression/CoresSweRVMP/slpp_all/mp_parser; cmake -G "Unix Makefiles" .; make -j 16
6-
-- Configuring done (0.0s)
6+
-- Configuring done (0.1s)
77
-- Generating done (0.0s)
88
-- Build files have been written to: ${SURELOG_DIR}/build/regression/CoresSweRVMP/slpp_all/mp_parser
99
[100%] Generating preprocessing
@@ -118,18 +118,18 @@ Running: cd ${SURELOG_DIR}/build/regression/CoresSweRVMP/slpp_all/mp_preprocess;
118118
-- Configuring done (0.0s)
119119
-- Generating done (0.0s)
120120
-- Build files have been written to: ${SURELOG_DIR}/build/regression/CoresSweRVMP/slpp_all/mp_preprocess
121-
[ 6%] Generating 10_lsu_bus_intf.sv
122-
[ 12%] Generating 11_ifu_bp_ctl.sv
123-
[ 18%] Generating 12_beh_lib.sv
124-
[ 25%] Generating 13_ifu_mem_ctl.sv
125-
[ 31%] Generating 14_mem_lib.sv
126-
[ 37%] Generating 15_exu.sv
121+
[ 6%] Generating 11_ifu_bp_ctl.sv
122+
[ 12%] Generating 13_ifu_mem_ctl.sv
123+
[ 25%] Generating 12_beh_lib.sv
124+
[ 25%] Generating 10_lsu_bus_intf.sv
125+
[ 31%] Generating 15_exu.sv
126+
[ 37%] Generating 14_mem_lib.sv
127127
[ 43%] Generating 16_dec_decode_ctl.sv
128128
[ 50%] Generating 1_lsu_stbuf.sv
129129
[ 56%] Generating 2_ahb_to_axi4.sv
130130
[ 62%] Generating 3_rvjtag_tap.sv
131-
[ 68%] Generating 5_lsu_bus_buffer.sv
132-
[ 75%] Generating 4_dec_tlu_ctl.sv
131+
[ 68%] Generating 4_dec_tlu_ctl.sv
132+
[ 75%] Generating 5_lsu_bus_buffer.sv
133133
[ 81%] Generating 6_dbg.sv
134134
[ 87%] Generating 7_axi4_to_ahb.sv
135135
[ 93%] Generating 8_ifu_aln_ctl.sv

0 commit comments

Comments
 (0)