diff --git a/.travis.yml b/.travis.yml index 174cb67..271e5fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,14 +17,19 @@ install: - sudo pip install cpp-coveralls before_script: - - make setup + - ./bin/project.sh script: + - cd ./build/debug/ + - make parser - make test after_success: + - pwd - make coverage-report - - coveralls -b build/ -e build/bin -e build/lib -i build/coverage -i build/gen -i src/ --gcov-options "-f -b -c" + - pwd + - coveralls -i ../../src/ -i ./src -b .src/CMakeFiles/verilogparser.dir/ + after_failure: - echo "Failure" diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..48e1d6a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 2.8) + +project(verilog-parser) + +add_subdirectory(./src) +add_subdirectory(./docs) + +add_custom_target(test + COMMAND ./bin/run-tests.sh + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${EXECUTABLE_NAME} + COMMENT "Running Test Suite" + VERBATIM +) diff --git a/Makefile b/Makefile deleted file mode 100644 index e9f0ed3..0000000 --- a/Makefile +++ /dev/null @@ -1,37 +0,0 @@ - - -##------------------------------------------------------------------------ -## Auxiliary Rules and Actions -##------------------------------------------------------------------------ - -.PHONY : docs - -all: app docs - -app: - $(MAKE) -C build/ all - -app-with-coverage: - $(MAKE) -C build/ with-coverage - -coverage-report: - bin/test-coverage.sh - -view-coverage-report: coverage-report - xdg-open ./build/cov-report/index.html - -clean: - $(MAKE) -C build/ clean - $(MAKE) -C docs/ clean - -docs: - $(MAKE) -C docs/ docs - -test: app - bin/run-tests.sh - -setup: - bin/project.sh - -fromclean: clean all - diff --git a/README.md b/README.md index 229e9de..2ecc590 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,8 @@ Standard. This will get you going workspace wise. ```sh - $> make setup + $> ./bin/project + $> cd ./build/debug $> make test ``` diff --git a/bin/project.sh b/bin/project.sh index c05ec06..a9aba19 100755 --- a/bin/project.sh +++ b/bin/project.sh @@ -8,11 +8,21 @@ source ../bin/setup-tests.sh cd ../ # Create build directory structure. -mkdir -p build -mkdir -p build/obj -mkdir -p build/gen -mkdir -p build/lib -mkdir -p build/bin +mkdir -p build/release +mkdir -p build/debug +mkdir -p build/docs + +echo "Setup debug build environment..." + +cd ./build/debug +cmake -DCMAKE_BUILD_TYPE=Debug ../../ +cd - + +echo "Setup release build environment..." + +cd ./build/release +cmake -DCMAKE_BUILD_TYPE=Release ../../ +cd - echo " " echo "Project workspace setup complete." diff --git a/bin/run-tests.sh b/bin/run-tests.sh index 9116e84..ee762de 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -14,7 +14,7 @@ echo "------------------------- Running Test Script -------------------------" rm -rf build/tests.log -EXE=build/bin/verilog-app +EXE=./build/debug/src/parser TEST_FILES=`find tests/ -name *.v | sort` FAILED_TESTS=" " diff --git a/bin/setup-tests.sh b/bin/setup-tests.sh index 101c39b..a59e40e 100755 --- a/bin/setup-tests.sh +++ b/bin/setup-tests.sh @@ -23,14 +23,8 @@ function downloadModelTest { fi } -if [ "$CI" -eq "true" ] -then - echo "Not unpacking SPARC test set yet..." -else - echo "Unzipping SPARC test set..." - unzip -o ../bin/sparct1.zip -fi - +echo "Unzipping SPARC test set..." +unzip -o ../bin/sparct1.zip echo "Downloading Tests..." diff --git a/build/Makefile b/build/Makefile deleted file mode 100644 index 5e14de2..0000000 --- a/build/Makefile +++ /dev/null @@ -1,96 +0,0 @@ - -##------------------------------------------------------------------------ -## Compiler Tools & Flags -##------------------------------------------------------------------------ - -OBJ_DIR = ./obj -LIB_DIR = ./lib -BIN_DIR = ./bin -GEN_DIR = ./gen - -SRC_DIR = ../src - -CC = gcc -CC_FLAGS = -g -Wall -I$(SRC_DIR) -I$(GEN_DIR) -O0 - -COVERAGE_FLAGS = -fprofile-arcs -ftest-coverage --coverage - -AR = ar -AR_FLAGS = rcs - -##------------------------------------------------------------------------ -## Auxiliary Rules and Actions -##------------------------------------------------------------------------ - -all: parser-app parser-lib - -with-coverage: CC_FLAGS += -DDEBUG -g $(COVERAGE_FLAGS) -with-coverage: parser-app parser-lib - -clean: - rm -f $(OBJ_DIR)/* - rm -f $(LIB_DIR)/* - rm -f $(BIN_DIR)/* - rm -f $(GEN_DIR)/* - rm -f *.gcov *.info *.log - rm -rf ./coverage/* - -fromclean: clean all - -##------------------------------------------------------------------------ -## BISON & FLEX Source, Output and Options -##------------------------------------------------------------------------ - -FLEX_IN = $(SRC_DIR)/verilog_scanner.l -FLEX_OUT = $(GEN_DIR)/verilog_scanner.c - -BISON_IN = $(SRC_DIR)/verilog_parser.y -BISON_OUT = $(GEN_DIR)/verilog_parser.tab.c - -FLEX_OPTS = --yylineno -BISON_OPTS = - -$(GEN_DIR)/%.c : $(SRC_DIR)/%.l - flex $(FLEX_OPTS) -o $(FLEX_OUT) $(FLEX_IN) - -$(GEN_DIR)/%.tab.c : $(SRC_DIR)/%.y - bison $(BISON_OPTS) -o $(BISON_OUT) $(BISON_IN) - -##------------------------------------------------------------------------ -## C Source and Object Code -##------------------------------------------------------------------------ - -LIB_NAME = verilogparser -LIB_FILE = $(LIB_DIR)/lib$(LIB_NAME).a - -APP_NAME = verilog-app -APP_OUT = $(BIN_DIR)/$(APP_NAME) - -APP_OBJ = $(OBJ_DIR)/main.o - -SRC_OBJS = $(OBJ_DIR)/verilog_ast.o \ - $(OBJ_DIR)/verilog_ast_common.o \ - $(OBJ_DIR)/verilog_parser_wrapper.o \ - $(OBJ_DIR)/verilog_preprocessor.o - -GEN_OBJS = $(OBJ_DIR)/verilog_parser.tab.o \ - $(OBJ_DIR)/verilog_scanner.o - - -parser-lib : $(GEN_OBJS) $(FLEX_OUT) $(BISON_OUT) $(SRC_OBJS) - $(AR) $(AR_FLAGS) $(LIB_FILE) $(SRC_OBJS) $(GEN_OBJS) - -parser-app : parser-lib $(APP_OBJ) - $(CC) $(CC_FLAGS) \ - -static $(APP_OBJ) \ - -L$(LIB_DIR) \ - -l$(LIB_NAME) \ - -o $(APP_OUT) - -# Rule for human written source files. -$(OBJ_DIR)/%.o : $(SRC_DIR)/%.c - $(CC) $(CC_FLAGS) -o $@ -c $< - -# Rule for generated source files. -$(OBJ_DIR)/%.o : $(GEN_DIR)/%.c - $(CC) $(CC_FLAGS) -o $@ -c $< diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt new file mode 100644 index 0000000..ab5ff76 --- /dev/null +++ b/docs/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 2.8) + +project(verilog-parser-docs) + +find_package(Doxygen) +if(DOXYGEN_FOUND) + add_custom_target(docs + ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Generating API documentation with Doxygen" VERBATIM + ) +endif(DOXYGEN_FOUND) diff --git a/docs/project-organisation.dox b/docs/project-organisation.dox index bb2dff0..446a968 100644 --- a/docs/project-organisation.dox +++ b/docs/project-organisation.dox @@ -24,55 +24,17 @@ and source code. @section build-system Build System -The build system is purely GNU Make. There is a top level Makefile with -the most common commands needed for the project included. These are: +The build system uses CMake, and is split into debug and release builds. +These are setup by the `bin/project.sh` script, and are found in the +`build/debug` or `build/release` directories. -- `all` - This builds the parser library, tester app and documentation. -- `app` - Builds the library and test app only. -- `docs` - Builds the documentation for the project. -- `setup` - Initialises the project workspace. +From either of those directories, we can run the following commands: -The `app` and `docs` commands recurse into the `build/` and `docs/` -subdirectories respectively. - -@subsection build-system-docs Documentation - -All documentation is built using Doxygen. The command to do so is -wrapped in a Makefile with the single command `make docs` in -`docs/Makefile`. - -@subsection build-system-source Compilation - -Compilation of the source code is handled by the makefile in the `build/` -directory. This makefile should be self explanatory, but is essentially -responsible for generating the flex and bison parsers, compiling object -code, linking into a static library, and creating the test app which -uses this library. - -The `build/` folder contains five sub-folders (assuming that `make all` -has been run from the top of the project). These are: - -- `bin` - Contains exectuable binaries like the test app. -- `lib` - Static and dynamic libraries, once compiled. -- `obj` - All intermediate object files. -- `gen` - Generated C source code, like the Bison and Flex code. -- `docs` - Documentation Generator output. -- `coverage` - See @ref coverage-info - -@subsection coverage-info Coverage - -The project uses `gcov` to generate coverage information and `lcov` to -create html reports. The following `make` commands are useful in this case: - -- `make app-with-coverage` - This is infact an alias for the - `make with-coverage` in `build/Makefile`. It simply builds the parser - library and test app with the appropriate coverage flags set. -- `make coverage-report` - This runs the script `bin/test-coverage.sh` which - runs all of the available test programs through the test app. The coverage - results are then compiled into the `build/coverage` folder, and the - html reports are generated with lcov. -- `make view-coverage-report` - Opens the generated html coverage reports - in your default html file viewer. +- `make all` +- `make parser` - Builds the library and a small tester app +- `make test` - Runs the test suite against the most recent build. +- `make coverage-report` - Runs the coverage suite against the most recent +build, and puts the results in `./build/coverage/` @section ci-tool Continuous Integration @@ -80,6 +42,6 @@ This project uses the Travis-CI tool for continuous integration. This is a service that plugs into github, meaning that every commit, fork and pull request automatically triggers a build. This build is configured using the `.travis.yml` file in the root of the project. As a minium, all builds -must complete successfully, and tests should also be run. +must complete successfully, and all of the test should be run without errors. */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..1d715b6 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,98 @@ +cmake_minimum_required(VERSION 2.8) + +project(verilog-parser-src) + +message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}") + +set(LIBRARY_NAME verilogparser) +set(EXECUTABLE_NAME parser) + +FIND_PACKAGE(BISON REQUIRED) +FIND_PACKAGE(FLEX REQUIRED) + +set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) + +set(FLEX_INPUT verilog_scanner.l) +set(FLEX_OUTPUT verilog_scanner.c) + +set(BISON_INPUT verilog_parser.y) +set(BISON_OUTPUT verilog_parser.tab.c) + +SET(CMAKE_C_FLAGS_DEBUG "-g -O0 -Wall -W -fprofile-arcs -ftest-coverage") +SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "-fprofile-arcs -ftest-coverage") + +SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") +SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") + +# ------------------------------------------------------------------------ + +ADD_CUSTOM_COMMAND( + SOURCE ${SOURCE_DIR}/${BISON_INPUT} + COMMAND ${BISON_EXECUTABLE} + ARGS -y ${SOURCE_DIR}/${BISON_INPUT} -o ${BINARY_DIR}/${BISON_OUTPUT} + TARGET PARSER_LIB + OUTPUTS ${BINARY_DIR}/${BISON_OUTPUT} +) + +ADD_CUSTOM_COMMAND( + SOURCE ${SOURCE_DIR}/${FLEX_INPUT} + COMMAND ${FLEX_EXECUTABLE} + ARGS -o ${BINARY_DIR}/${FLEX_OUTPUT} ${SOURCE_DIR}/${FLEX_INPUT} + TARGET PARSER_LIB + DEPENDS ${BINARY_DIR}/${BISON_OUTPUT} + OUTPUTS ${BINARY_DIR}/${FLEX_OUTPUT} +) + +SET_SOURCE_FILES_PROPERTIES(${BINARY_DIR}/${FLEX_OUTPUT} GENERATED) +SET_SOURCE_FILES_PROPERTIES(${BINARY_DIR}/${BISON_OUTPUT} GENERATED) + +# ------------------------------------------------------------------------ + +INCLUDE_DIRECTORIES(${BINARY_DIR}) +INCLUDE_DIRECTORIES(${SOURCE_DIR}) + +set(PARSER_LIB_SRC ${BINARY_DIR}/${FLEX_OUTPUT} + ${BINARY_DIR}/${BISON_OUTPUT} + ${SOURCE_DIR}/verilog_ast.c + ${SOURCE_DIR}/verilog_ast_common.c + ${SOURCE_DIR}/verilog_parser_wrapper.c + ${SOURCE_DIR}/verilog_preprocessor.c +) + +add_library(${LIBRARY_NAME} ${PARSER_LIB_SRC}) + +set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1) + +add_executable(${EXECUTABLE_NAME} main.c) +target_link_libraries(${EXECUTABLE_NAME} ${LIBRARY_NAME}) + +# ------------------------------------------------------------------------ + +file(GLOB COVERAGE_TEST_FILE_LIST "../tests/*.v") + +file(GLOB COVERAGE_SRC_FILES "./*.c") + +set(COVERAGE_GEN_FILES + ${BINARY_DIR}/${FLEX_OUTPUT} ${BINARY_DIR}/${BISON_OUTPUT} +) + +add_custom_target(coverage-tests + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/parser ${COVERAGE_TEST_FILE_LIST} + WORKING_DIRECTORY ../ + DEPENDS ${EXECUTABLE_NAME} + COMMENT "Running Coverage Tests" + VERBATIM +) + +# -s ../../src/*.c ./src/*.c + +add_custom_target(coverage-report + COMMAND gcov -f -b -c -o ../../build/debug/src/CMakeFiles/verilogparser.dir -s ${COVERAGE_SRC_FILES} ${COVERAGE_GEN_FILES} + COMMAND lcov --directory . -c -o coverage.info -t "Verilog Parser" + COMMAND genhtml -o ./coverage -t "Verilog Parser Test Coverage" --num-spaces 4 coverage.info + DEPENDS coverage-tests + COMMENT "Generating Coverage Report With GCOV" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../ + VERBATIM +)