diff --git a/.appveyor.yml b/.appveyor.yml index 92f1417a..13e6a44a 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -13,7 +13,7 @@ environment: - GENERATOR: -G"Visual Studio 16 2019" -A x64 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 BUILD_TYPE: Release - PYTHON: "C:\\Python39-x64" + PYTHON: "C:\\Python312-x64" # add to path otherwise Cython is not found PATH: C:\Program Files\Java\jdk11\bin;$(PYTHON)\Scripts;$(PATH) PLATFORM: x64 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..06fbaefd --- /dev/null +++ b/.gitattributes @@ -0,0 +1,10 @@ +.appveyor.yml export-ignore +.circleci/ export-ignore +.github export-ignore +Dockerfile export-ignore +.dockerignore export-ignore +tests/** export-ignore +tests/ghdl/** export-ignore +tests/ghdl/ export-ignore +tests/ghdl/logo.png export-ignore +notebooks export-ignore diff --git a/.github/workflows/build_and_release.yml b/.github/workflows/build_and_release.yml index ff9cd40e..5a7e6419 100644 --- a/.github/workflows/build_and_release.yml +++ b/.github/workflows/build_and_release.yml @@ -8,14 +8,14 @@ permissions: jobs: # Create a Debug build and test it. build_and_test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: submodules: recursive - uses: actions/setup-python@v5 with: - python-version: "3.10" + python-version: "3.12" # Don't need to install Python / Create venv, as you are running in a container. # You don't even need to install g++/cmake as it comes with the docker image. @@ -26,6 +26,7 @@ jobs: libantlr4-runtime-dev antlr4 libssl-dev -yq pip install setuptools wheel cmake ninja patchelf auditwheel pip install -r requirements.txt + pip install build nbconvert - name: Check Your Environment run: | @@ -36,16 +37,18 @@ jobs: - name: Build run: | - echo Your Build Script here - echo Make sure the Debug and Coverage Switch is on, only in this job. + python -m build -Ccompile-args="--verbose" -Ccompile-args="-j4" . # -j4 because we do not have enough RAM + pip install dist/*.whl - name: Test run: | - echo Your Test Script here + mv hdlConvertor tmp_hdlConvertor + python -m tests.all + mv tmp_hdlConvertor hdlConvertor - name: Extract Coverage Report run: | - echo Your Coverage Report + echo "[todo] Coverage Report" # Build on Different Platform. @@ -63,8 +66,8 @@ jobs: strategy: matrix: - python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12" ] - runs-on: ubuntu-20.04 + python-version: [ "3.9", "3.10", "3.11", "3.12" ] + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: @@ -79,6 +82,7 @@ jobs: libantlr4-runtime-dev antlr4 libssl-dev -yq pip install setuptools wheel cmake ninja patchelf auditwheel pip install -r requirements.txt + pip install build # Include ANTLR4's License file as we are redistributing their binary - name: Adding ANTLR4 License @@ -91,11 +95,11 @@ jobs: # Use them with `-j 4` flag - name: Build Library run: | - python setup.py bdist_wheel -j 4 + python -m build . auditwheel repair --plat manylinux_2_31_x86_64 dist/*.whl - name: Archive Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: PythonPackage path: | @@ -105,7 +109,7 @@ jobs: # Developer can still build on their machine with the source bundle # (i.e. the original `pip install` flow if the platform is not included by above steps) build_sdist: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest if: ${{ success() }} needs: @@ -117,7 +121,7 @@ jobs: submodules: recursive - uses: actions/setup-python@v5 with: - python-version: "3.9" + python-version: "3.12" - name: Install Dependencies run: | sudo apt update -y @@ -133,7 +137,7 @@ jobs: python setup.py sdist - name: Archive Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: PythonPackage path: | @@ -160,7 +164,7 @@ jobs: steps: - name: Download Package Built - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: PythonPackage path: dist diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 29ee9b88..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,14 +0,0 @@ -include *.txt *.md -include MANIFEST.in -include README.md -include setup.py -include setup.cfg -include pyproject.toml -include LICENSE - -recursive-include include *.h -recursive-include src *.cpp *.h *.txt -recursive-include grammars *.g4 -recursive-include hdlConvertor *.cpp *.h *.txt *.pyx *.py -global-include *.gcno - diff --git a/grammars/verilogPreprocLexer.g4 b/grammars/verilogPreprocLexer.g4 index 8fb4adec..59cc0ee2 100644 --- a/grammars/verilogPreprocLexer.g4 +++ b/grammars/verilogPreprocLexer.g4 @@ -359,11 +359,15 @@ mode KEYWOORDS_MODE; // include argument processing mode INCLUDE_MODE; INCLUDE_MODE_STR - : STR -> type(STR),popMode + : STR -> type(STR) ; + INCLUDE_MODE_STR_CHEVRONS - : '<' ( ~('\\'|'>') )* '>' -> type(STR),popMode + : '<' ( ~('\\'|'>') )* '>' -> type(STR) ; + INCLUDE_LINE_COMMENT : LINE_COMMENT -> popMode,type(LINE_COMMENT),channel(CH_LINE_COMMENT); + INCLUDE_MODE_NEW_LINE: CRLF -> type(NEW_LINE),popMode,skip; + INCLUDE_MODE_MACRO_ENTER: '`' -> popMode,pushMode(DIRECTIVE_MODE),skip; INCLUDE_MODE_WS : WS ->skip; diff --git a/hdlConvertor/toPy.cpp b/hdlConvertor/toPy.cpp index d250a717..778f5edc 100644 --- a/hdlConvertor/toPy.cpp +++ b/hdlConvertor/toPy.cpp @@ -190,6 +190,8 @@ PyObject* ToPy::toPy(const CodePosition o) { return nullptr; if (toPy_property(py_inst, "stop_column", o.stop_column)) return nullptr; + if (toPy_property(py_inst, "file_name", o.file_name)) + return nullptr; return py_inst; } diff --git a/include/hdlConvertor/hdlAst/codePosition.h b/include/hdlConvertor/hdlAst/codePosition.h index 07e0e058..eb0f66d6 100644 --- a/include/hdlConvertor/hdlAst/codePosition.h +++ b/include/hdlConvertor/hdlAst/codePosition.h @@ -2,6 +2,8 @@ #include #include +#include + namespace hdlConvertor { namespace hdlAst { @@ -13,22 +15,34 @@ namespace hdlAst { class CodePosition { public: static constexpr size_t INVALID = std::numeric_limits::max(); + static constexpr char INVALID_STR[] = ""; size_t start_line; size_t stop_line; size_t start_column; size_t stop_column; + std::string file_name; CodePosition(); CodePosition(size_t startLine, size_t stopLine, size_t startColumn, - size_t stopColumn); + size_t stopColumn, std::string fileName); template void update_from_elem(ELEM_T *elem) { - start_line = elem->getStart()->getLine(); - stop_line = elem->getStop()->getLine(); - start_column = elem->getStart()->getCharPositionInLine() + 1; - stop_column = elem->getStop()->getCharPositionInLine() + - (elem->getStop()->getStopIndex() - elem->getStop()->getStartIndex()) + 1; + /* + * Cast antlr4::CommonToken to our custum hdlConvertorToken + * So we can retrive the file name information of origin of + * current token. + */ + hdlConvertor::hdlConvertorToken * tokenStart_ptr = dynamic_cast(elem->getStart()); + hdlConvertor::hdlConvertorToken * tokenStop_ptr = dynamic_cast(elem->getStop()); + + /* pick up data from token */ + start_line = tokenStart_ptr->getLine(); + stop_line = tokenStop_ptr->getLine(); + start_column = tokenStart_ptr->getCharPositionInLine() + 1; + stop_column = tokenStop_ptr->getCharPositionInLine() + + (tokenStop_ptr->getStopIndex() - tokenStop_ptr->getStartIndex()) + 1; + file_name = tokenStart_ptr->getSrcName(); } bool isKnown() const; }; diff --git a/include/hdlConvertor/hdlConvertor.h b/include/hdlConvertor/hdlConvertor.h index 66c0c180..faf031ab 100644 --- a/include/hdlConvertor/hdlConvertor.h +++ b/include/hdlConvertor/hdlConvertor.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace hdlConvertor { diff --git a/include/hdlConvertor/hdlConvertorToken.h b/include/hdlConvertor/hdlConvertorToken.h new file mode 100644 index 00000000..64e7720e --- /dev/null +++ b/include/hdlConvertor/hdlConvertorToken.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +namespace hdlConvertor { + +class hdlConvertorToken : public antlr4::CommonToken { + public: + hdlConvertorToken(size_t type); + hdlConvertorToken(std::pair source, size_t type, size_t channel, size_t start, size_t stop); + hdlConvertorToken(size_t type, const std::string &text); + hdlConvertorToken(antlr4::Token *oldToken); + + void setSrcName(const std::string fileName); + std::string getSrcName(); + std::string toString() const override; + + private: + std::string srcName; + +}; + +} diff --git a/include/hdlConvertor/hdlConvertorTokenFactory.h b/include/hdlConvertor/hdlConvertorTokenFactory.h new file mode 100644 index 00000000..886ad04b --- /dev/null +++ b/include/hdlConvertor/hdlConvertorTokenFactory.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include +#include +namespace hdlConvertor { + +class hdlConvertorTokenFactory : public antlr4::CommonTokenFactory { + public: + static const std::unique_ptr> DEFAULT; + + hdlConvertorTokenFactory(bool copy_text); + hdlConvertorTokenFactory(); + void setFileLineMap( verilog_pp::FileLineMap * file_line_map); + + std::unique_ptr create( + std::pair source, + size_t type, + const std::string &text, + size_t channel, + size_t start, + size_t stop, + size_t line, + size_t charPositionInLine) override; + + std::unique_ptr create( + size_t type, + const std::string &text) override; + + + private: + static verilog_pp::FileLineMap *_file_line_map; + +}; + +} diff --git a/meson.build b/meson.build index 199820b4..bdf3d8e9 100644 --- a/meson.build +++ b/meson.build @@ -23,7 +23,7 @@ cc = meson.get_compiler('cpp') EXTRA_CXX_FLAGS = [] EXTRA_LD_FLAGS = [] if meson.get_compiler('cpp').get_id() == 'msvc' - EXTRA_CXX_FLAGS.append('/bigobj') + EXTRA_CXX_FLAGS += ['-MP /wd4251', '/bigobj'] # https://github.com/antlr/antlr4/blob/dev/runtime/Cpp/demo/CMakeLists.txt # using /MD flag for antlr4_runtime (for Visual C++ compilers only) elif host_machine.system() == 'cygwin' EXTRA_CXX_FLAGS += ['-Wa,-mbig-obj'] @@ -50,7 +50,7 @@ endif antlr4_runtime_opt.set_install(false) # because meson-python does not know where to install it antlr4_runtime_proj = cmake.subproject('antlr4-runtime', options: antlr4_runtime_opt) antlr4_cpp_dep = antlr4_runtime_proj.dependency('antlr4_static') - antlr4_cpp_version = '4.13.1' + antlr4_cpp_version = '4.13.2' # :note: must match version in antlr4-runtime.wrap import('java') # to check that java is installed antlr4_jar = join_paths(meson.current_build_dir() , 'antlr4-complete.jar') fs = import('fs') @@ -88,6 +88,7 @@ curSrcDir = meson.current_source_dir() mainIncludeDir = 'include/' mainIncludeDir_inc = include_directories(mainIncludeDir) all_parser_libs = [] +all_parser_deps = [] foreach parserTuple : ANTLR_PARSERS name = parserTuple[0] folder_name = parserTuple[1] @@ -157,6 +158,9 @@ foreach parserTuple : ANTLR_PARSERS include_directories: [mainIncludeDir_inc, include_directories(genIncludeDir)], ) all_parser_libs += parser_lib + parser_lib_dependency = declare_dependency( + link_with : [parser_lib],) + all_parser_deps += parser_lib_dependency endforeach subdir('src') @@ -164,3 +168,11 @@ subdir('src') if get_option('python_package') subdir('hdlConvertor') endif + +# if tests files are in the package mark them as test data +test_data = run_command(python_prog, 'utils/rec_glob.py', 'tests', '*', check:true)\ + .stdout().strip().split('\n') +message('test_data:\n' + '\n'.join(test_data)) + +install_data(test_data, install_tag : 'tests') + diff --git a/pyproject.toml b/pyproject.toml index 588b6a5b..05f31ba7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,8 +3,8 @@ requires = [ "wheel", # python package distribution lib. "Cython", "cmake>=3.26.3", # cmake buildsystem for antrl - "meson>=1.1.0", # meson buildsystem - 'meson-python>=0.12.1', # meson to pip adapter + "meson>=1.8.2", # meson buildsystem + 'meson-python>=0.18.0', # meson to pip adapter "pybind11>=2.10.4", # c++ to Python binding "ninja>=1.11.1", # build tool for meson to use ] @@ -19,7 +19,7 @@ dynamic = ["version", ] # specified in meson.build # readme = {file = ["README.md"]} readme = "README.md" license = { file = 'LICENSE' } -keyword = ['FPGA', 'ASIC', 'compiler', 'RTL', 'synthesis', 'logicsynthesis', +keywords = ['FPGA', 'ASIC', 'compiler', 'RTL', 'synthesis', 'logicsynthesis', 'hdl', 'vhdl', 'parser', 'preprocessor', 'antlr4', 'verification', 'Verilog', 'SystemVerilog', 'system verilog'] authors = [ diff --git a/src/hdlAst/codePosition.cpp b/src/hdlAst/codePosition.cpp index 7c9f1fbf..105dfde6 100644 --- a/src/hdlAst/codePosition.cpp +++ b/src/hdlAst/codePosition.cpp @@ -4,20 +4,21 @@ namespace hdlConvertor { namespace hdlAst { CodePosition::CodePosition() : - CodePosition(INVALID, INVALID, INVALID, INVALID) { + CodePosition(INVALID, INVALID, INVALID, INVALID,INVALID_STR) { } CodePosition::CodePosition(size_t startLine, size_t stopLine, size_t startColumn, - size_t stopColumn) { + size_t stopColumn,std::string fileName) { this->start_line = startLine; this->stop_line = stopLine; this->start_column = startColumn; this->stop_column = stopColumn; + this->file_name = fileName; } bool CodePosition::isKnown() const { return start_line != INVALID || stop_line != INVALID || start_column != INVALID - || stop_column != INVALID; + || stop_column != INVALID || file_name != INVALID_STR; } } diff --git a/src/hdlConvertor.cpp b/src/hdlConvertor.cpp index 9af35b77..b8e7c843 100644 --- a/src/hdlConvertor.cpp +++ b/src/hdlConvertor.cpp @@ -25,6 +25,20 @@ class VHDLParserContainer: public iParserContainer { using iParserContainer::iParserContainer; virtual void parseFn() override { + + /* + * Customize Lexer with our hdlConvertorToken factory + * This allow us to enrich antlr4::CommonToken with filename on + * each token, then spread this kind of detail everywhere token are + * use. + * Dummy structure for vhdl, since no processing step exist. + * */ + verilog_pp::FileLineMap dummy_file_line_map; + hdlConvertorTokenFactory factory; + factory.setFileLineMap(&dummy_file_line_map); + lexer.get()->setTokenFactory(factory.DEFAULT.get()); + + vhdl_antlr::vhdlParser::Design_fileContext *tree = antlrParser->design_file(); syntaxErrLogger.check_errors(); // Throw exception if errors @@ -56,6 +70,14 @@ class SVParserContainer: public iParserContainer_parse(input_for_parser, hierarchyOnly); @@ -77,8 +99,28 @@ class SVParserContainer: public iParserContainerlanguage_version = lang; + + /* + * Customize Lexer with our hdlConvertorToken factory + * This allow us to enrich antlr4::CommonToken with filename on + * each token, then spread this kind of detail everywhere token are + * use + * */ + hdlConvertorTokenFactory factory; + factory.setFileLineMap(&file_line_map); + lexer.get()->setTokenFactory(factory.DEFAULT.get()); + + /* Debug print hdlConvertorToken list + tokens.get()->fill(); + for (auto token : tokens.get()->getTokens()) { + std::cout << token->toString() << std::endl; + } + */ + sv2017_antlr::sv2017Parser::Source_textContext *tree = antlrParser->source_text(); + + syntaxErrLogger.check_errors(); // Throw exception if errors hdlParser->visitSource_text(tree); } diff --git a/src/hdlConvertorToken.cpp b/src/hdlConvertorToken.cpp new file mode 100644 index 00000000..9d6fba90 --- /dev/null +++ b/src/hdlConvertorToken.cpp @@ -0,0 +1,38 @@ +#include + + +namespace hdlConvertor { + +using namespace std; + +hdlConvertorToken::hdlConvertorToken(size_t type) : CommonToken(type) { +} + +hdlConvertorToken::hdlConvertorToken(pair source, size_t type, size_t channel, size_t start, size_t stop) : + CommonToken(source,type,channel,start,stop),srcName("cornichon") { + +} + +hdlConvertorToken::hdlConvertorToken(size_t type, const std::string &text) : + CommonToken(type,text),srcName("corniChon") { +} + +hdlConvertorToken::hdlConvertorToken(antlr4::Token *oldToken) : + CommonToken(oldToken) { +} + + +void hdlConvertorToken::setSrcName(const string fileName) { + srcName = fileName; +} + +std::string hdlConvertorToken::getSrcName() { + return srcName; +} + +string hdlConvertorToken::toString() const { + string rt_value = srcName + CommonToken::toString(); + return rt_value; +} + +} diff --git a/src/hdlConvertorTokenFactory.cpp b/src/hdlConvertorTokenFactory.cpp new file mode 100644 index 00000000..dd80c03a --- /dev/null +++ b/src/hdlConvertorTokenFactory.cpp @@ -0,0 +1,84 @@ +#include + +namespace hdlConvertor { + +using namespace std; + +const std::unique_ptr> hdlConvertorTokenFactory::DEFAULT(new hdlConvertorTokenFactory); + +verilog_pp::FileLineMap* hdlConvertorTokenFactory::_file_line_map = nullptr; + + +hdlConvertorTokenFactory::hdlConvertorTokenFactory( + bool copyText) : + CommonTokenFactory(copyText) { +} + +hdlConvertorTokenFactory::hdlConvertorTokenFactory() { +} + +void hdlConvertorTokenFactory::setFileLineMap( verilog_pp::FileLineMap * file_line_map){ + hdlConvertorTokenFactory::_file_line_map = file_line_map; +} + +std::unique_ptr +hdlConvertorTokenFactory::create( + std::pair source, + size_t type, + const std::string &text, + size_t channel, + size_t start, + size_t stop, + size_t line, + size_t charPositionInLine) { + + bool found = false; + + std::unique_ptr t(new hdlConvertorToken( + source, type, channel, start, stop + ) + ); + + hdlConvertorToken * ptr = dynamic_cast(t.get()); + + std::vector::iterator fileLineMap_iter; + fileLineMap_iter = (*hdlConvertorTokenFactory::_file_line_map).begin(); + while (fileLineMap_iter != (*hdlConvertorTokenFactory::_file_line_map).end() && found==false) { + + if (line == (fileLineMap_iter->line+1)) { + found = true; + ptr->setLine(fileLineMap_iter->line_override+1); + ptr->setSrcName(fileLineMap_iter->file_override); + } + + fileLineMap_iter++; + } + if (found == false) { + ptr->setLine(line); + /* line not found ! For time beeing keep original data + std::cout << "Drama! " + << text + << "line: "<< line << " not found" << std::endl; + */ + } + ptr->setCharPositionInLine(charPositionInLine); + if (text != "") { + ptr->setText(text); + } else if (copyText && source.second != nullptr) { + ptr->setText(source.second->getText(antlr4::misc::Interval(start, stop))); + } + + return t; +} + + + +std::unique_ptr +hdlConvertorTokenFactory::create( + size_t type, + const std::string &text) { + return std::unique_ptr(new hdlConvertorToken(type, text)); + +} + +} diff --git a/src/meson.build b/src/meson.build index a139be7b..1b8c6bed 100644 --- a/src/meson.build +++ b/src/meson.build @@ -8,6 +8,8 @@ hdlConvertor_core_src = [ 'conversion_exception.cpp', 'universal_fs.cpp', 'encodingConversions.cpp', + 'hdlConvertorToken.cpp', + 'hdlConvertorTokenFactory.cpp' ] hdlConvertor_core_src += run_command(py3, '../utils/rec_glob.py', './hdlAst', '*.cpp', check:true)\ .stdout().strip().split('\n') @@ -17,7 +19,7 @@ hdlConvertor_core_src += run_command(py3, '../utils/rec_glob.py', './baseHdlPars hdlConvertor_core_static_lib = static_library('hdlConvertor_core_static', hdlConvertor_core_src, cpp_args: EXTRA_CXX_FLAGS, - dependencies: [antlr4_cpp_dep], + dependencies: [antlr4_cpp_dep, all_parser_deps], include_directories: [mainIncludeDir_inc], #link_with: [libtracker_common], ) @@ -34,7 +36,7 @@ if get_option('python_package') hdlConvertor_cpp_static = static_library('hdlConvertor_cpp_static', hdlConvertor_cpp_src, cpp_args: EXTRA_CXX_FLAGS, - dependencies: [antlr4_cpp_dep], + dependencies: [antlr4_cpp_dep, all_parser_deps], include_directories: [mainIncludeDir_inc], link_with: [hdlConvertor_core_static_lib, all_parser_libs], ) @@ -44,7 +46,7 @@ else hdlConvertor_cpp_shared = shared_library('hdlConvertor_cpp_shared', hdlConvertor_cpp_src, cpp_args: EXTRA_CXX_FLAGS, - dependencies: [antlr4_cpp_dep], + dependencies: [antlr4_cpp_dep, ] + all_parser_deps, include_directories: [mainIncludeDir_inc], link_with: [hdlConvertor_core_static_lib, all_parser_libs], ) diff --git a/src/toString.cpp b/src/toString.cpp index e6743bfb..2eb5354b 100644 --- a/src/toString.cpp +++ b/src/toString.cpp @@ -172,6 +172,7 @@ void ToString::dump(const CodePosition * o, int indent) { dump_size_t("stopLine", o->stop_line); dump_size_t("startColumn", o->start_column); dump_size_t("stopColumn", o->stop_column); + dump_size_t("fileName",o->file_name); indent -= INDENT_INCR; mkIndent(indent) << "}"; } diff --git a/src/verilogPreproc/out_buffer.cpp b/src/verilogPreproc/out_buffer.cpp index 68d863e5..ee11c42d 100644 --- a/src/verilogPreproc/out_buffer.cpp +++ b/src/verilogPreproc/out_buffer.cpp @@ -60,7 +60,6 @@ VerilogPreprocOutBuffer& VerilogPreprocOutBuffer::operator<<( VerilogPreprocOutBuffer& VerilogPreprocOutBuffer::operator<<( const VerilogPreprocOutBuffer &other) { - (*this) << endl; (*static_cast(this)) << other.str(); for (auto &i : other.file_line_map) { FileLineMapItem i_new(i.line + output_line, i.file_override, diff --git a/subprojects/antlr4-runtime.wrap b/subprojects/antlr4-runtime.wrap index 3809ea71..c677cfa5 100644 --- a/subprojects/antlr4-runtime.wrap +++ b/subprojects/antlr4-runtime.wrap @@ -1,5 +1,5 @@ [wrap-git] url = https://github.com/antlr/antlr4.git -revision = 4.13.1 +revision = 4.13.2 diff_files=0001-add-CMakeLists.txt-to-root.patch depth=1 \ No newline at end of file diff --git a/tests/sv_pp/expected/debug_macro.txt b/tests/sv_pp/expected/debug_macro.txt index a1a5103d..8a8ee519 100644 --- a/tests/sv_pp/expected/debug_macro.txt +++ b/tests/sv_pp/expected/debug_macro.txt @@ -5,6 +5,4 @@ - - $display(">> %s, %d: %s", "sv_pp/src/debug_macro.txt", 3, "msg") diff --git a/tests/sv_pp/expected/include_many_dir/dir0-a/dir1-a/spec_incdir.txt b/tests/sv_pp/expected/include_many_dir/dir0-a/dir1-a/spec_incdir.txt index 807a1ca1..1124e96b 100644 --- a/tests/sv_pp/expected/include_many_dir/dir0-a/dir1-a/spec_incdir.txt +++ b/tests/sv_pp/expected/include_many_dir/dir0-a/dir1-a/spec_incdir.txt @@ -1,2 +1 @@ - "good content" \ No newline at end of file diff --git a/tests/sv_pp/expected/include_many_dir/dir0-a/local_include_higher_priority.txt b/tests/sv_pp/expected/include_many_dir/dir0-a/local_include_higher_priority.txt index 807a1ca1..1124e96b 100644 --- a/tests/sv_pp/expected/include_many_dir/dir0-a/local_include_higher_priority.txt +++ b/tests/sv_pp/expected/include_many_dir/dir0-a/local_include_higher_priority.txt @@ -1,2 +1 @@ - "good content" \ No newline at end of file diff --git a/tests/sv_pp/expected/include_many_dir/from_subdirectory.txt b/tests/sv_pp/expected/include_many_dir/from_subdirectory.txt index 8528768f..d1f22783 100644 --- a/tests/sv_pp/expected/include_many_dir/from_subdirectory.txt +++ b/tests/sv_pp/expected/include_many_dir/from_subdirectory.txt @@ -1,6 +1 @@ - -"file2-a.txt" - -"file2-a.txt" - -"file2-a.txt" +"file2-a.txt""file2-a.txt""file2-a.txt" \ No newline at end of file diff --git a/tests/sv_pp/expected/include_many_dir/from_subdirectory2.txt b/tests/sv_pp/expected/include_many_dir/from_subdirectory2.txt new file mode 100644 index 00000000..53e98acd --- /dev/null +++ b/tests/sv_pp/expected/include_many_dir/from_subdirectory2.txt @@ -0,0 +1,3 @@ +"file2-a.txt" +"file2-a.txt" +"file2-a.txt" diff --git a/tests/sv_pp/expected/include_many_dir/transitive.txt b/tests/sv_pp/expected/include_many_dir/transitive.txt index a7c0eed4..92cde8dc 100644 --- a/tests/sv_pp/expected/include_many_dir/transitive.txt +++ b/tests/sv_pp/expected/include_many_dir/transitive.txt @@ -1,8 +1,4 @@ - "transitive-0" - "transitive-1" - "transitive-2" - "transitive-3" \ No newline at end of file diff --git a/tests/sv_pp/expected/include_same_dir/basic_include.txt b/tests/sv_pp/expected/include_same_dir/basic_include.txt index 12fb4c89..5e2ef389 100644 --- a/tests/sv_pp/expected/include_same_dir/basic_include.txt +++ b/tests/sv_pp/expected/include_same_dir/basic_include.txt @@ -1,4 +1,3 @@ - "a.vh" diff --git a/tests/sv_pp/expected/include_same_dir/basic_include2times.txt b/tests/sv_pp/expected/include_same_dir/basic_include2times.txt index dd0b6a63..5e2ef389 100644 --- a/tests/sv_pp/expected/include_same_dir/basic_include2times.txt +++ b/tests/sv_pp/expected/include_same_dir/basic_include2times.txt @@ -1,6 +1,3 @@ - "a.vh" - - diff --git a/tests/sv_pp/src/include_many_dir/dir0-a/dir1-a/file2-b.txt b/tests/sv_pp/src/include_many_dir/dir0-a/dir1-a/file2-b.txt new file mode 100644 index 00000000..ba5cbc4f --- /dev/null +++ b/tests/sv_pp/src/include_many_dir/dir0-a/dir1-a/file2-b.txt @@ -0,0 +1 @@ +"file2-a.txt" diff --git a/tests/sv_pp/src/include_many_dir/from_subdirectory2.txt b/tests/sv_pp/src/include_many_dir/from_subdirectory2.txt new file mode 100644 index 00000000..dbf9d3d1 --- /dev/null +++ b/tests/sv_pp/src/include_many_dir/from_subdirectory2.txt @@ -0,0 +1,3 @@ +`include "dir0-a/dir1-a/file2-b.txt" +`include "./dir0-a/dir1-a/file2-b.txt" +`include "./dir0-a/../dir0-a/dir1-a/file2-b.txt" diff --git a/tests/test_verilog_preproc_include.py b/tests/test_verilog_preproc_include.py index 92187d68..a906c78e 100644 --- a/tests/test_verilog_preproc_include.py +++ b/tests/test_verilog_preproc_include.py @@ -43,6 +43,9 @@ def test_basic_include2times(self): def test_from_subdirectory(self): self.run_test(["include_many_dir", "from_subdirectory.txt"], []) + + def test_from_subdirectory2(self): + self.run_test(["include_many_dir", "from_subdirectory2.txt"], []) def test_local_include_higher_priority(self): self.run_test( diff --git a/utils/rec_glob.py b/utils/rec_glob.py index 5e15f65c..487769b3 100644 --- a/utils/rec_glob.py +++ b/utils/rec_glob.py @@ -7,7 +7,7 @@ def call_glob(): if len(sys.argv) != 3: - print("[Error] Usage `glob.py path 'module'|pattern`, but provided `%r`" % sys.argv, file=sys.stderr) + print("[Error] Usage `glob.py path 'module'|any|pattern`, but provided `%r`" % sys.argv, file=sys.stderr) sys.exit(1) root, mode = sys.argv[1:] @@ -23,10 +23,15 @@ def call_glob(): print(d) seen_module_directories.add(d) + elif mode == '*': + for path in Path(root).rglob(mode): + if path.is_file(): + print(path.as_posix()) else: # list files by extension in a folder for path in Path(root).glob(mode): - print(path.as_posix()) + if path.is_file(): + print(path.as_posix()) if __name__ == "__main__":