diff options
Diffstat (limited to '')
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | build.bat | 75 | ||||
| -rw-r--r-- | tools/tool.h | 36 |
3 files changed, 108 insertions, 4 deletions
| @@ -39,6 +39,7 @@ tools/results | |||
| 39 | *.pyd | 39 | *.pyd |
| 40 | *.dll | 40 | *.dll |
| 41 | *.exp | 41 | *.exp |
| 42 | *.exe | ||
| 42 | *.lib | 43 | *.lib |
| 43 | *.pdb | 44 | *.pdb |
| 44 | *.ilk | 45 | *.ilk |
| @@ -8,6 +8,7 @@ if [%1]==[/d] ( | |||
| 8 | ) | 8 | ) |
| 9 | 9 | ||
| 10 | SET CC=clang | 10 | SET CC=clang |
| 11 | SET CXX=clang++ | ||
| 11 | SET ARCH=PORTABLE | 12 | SET ARCH=PORTABLE |
| 12 | SET THREADS=1 | 13 | SET THREADS=1 |
| 13 | SET SANITIZE= | 14 | SET SANITIZE= |
| @@ -34,9 +35,9 @@ SET PYLIBS=%PYPATH%\libs | |||
| 34 | SET TARGET=%1 | 35 | SET TARGET=%1 |
| 35 | if not defined TARGET SET TARGET=nissy | 36 | if not defined TARGET SET TARGET=nissy |
| 36 | SET EXPR=%2 | 37 | SET EXPR=%2 |
| 37 | for %%a in (nissy python shell test config help) do ( | 38 | for %%a in (nissy python shell test config help clean tool cpp solvetest) do ( |
| 38 | if %TARGET%==%%a ( | 39 | if %TARGET%==%%a ( |
| 39 | call:build_%TARGET% | 40 | call:build_%TARGET% %* |
| 40 | exit /b | 41 | exit /b |
| 41 | ) | 42 | ) |
| 42 | ) | 43 | ) |
| @@ -56,11 +57,16 @@ exit /b 1 | |||
| 56 | echo nissy Build the nissy.o object file. | 57 | echo nissy Build the nissy.o object file. |
| 57 | echo python Build the Python module for nissy. | 58 | echo python Build the Python module for nissy. |
| 58 | echo shell Build the basic nissy shell (./run). | 59 | echo shell Build the basic nissy shell (./run). |
| 59 | echo help Show this help message. | 60 | echo cpp FILE Build and run the given C++ FILE. |
| 60 | echo config Show build configuration and exit. | ||
| 61 | echo test [EXPR] Build and run unit tests. If EXPR is provided, only the | 61 | echo test [EXPR] Build and run unit tests. If EXPR is provided, only the |
| 62 | echo tests whose name contains EXPR are run. The /d option is | 62 | echo tests whose name contains EXPR are run. The /d option is |
| 63 | echo is always implied. | 63 | echo is always implied. |
| 64 | echo tool EXPR Run the 'tool' matching the given EXPR. | ||
| 65 | echo solvetest Build nissy and run a collection of tools for testing" | ||
| 66 | echo various solvers. | ||
| 67 | echo help Show this help message. | ||
| 68 | echo config Show build configuration and exit. | ||
| 69 | echo clean Remove all build files. | ||
| 64 | echo. | 70 | echo. |
| 65 | echo The /d option activates debug mode (slower, used for testing). | 71 | echo The /d option activates debug mode (slower, used for testing). |
| 66 | echo Tests are automatically built in debug mode even without /d. | 72 | echo Tests are automatically built in debug mode even without /d. |
| @@ -115,6 +121,57 @@ exit /b | |||
| 115 | ) | 121 | ) |
| 116 | exit /b | 122 | exit /b |
| 117 | 123 | ||
| 124 | :build_clean | ||
| 125 | @echo on | ||
| 126 | del *.o *.so *.a *.ilk *.pdb *.exe | ||
| 127 | @echo off | ||
| 128 | exit /b | ||
| 129 | |||
| 130 | :build_tool | ||
| 131 | if not defined EXPR ( | ||
| 132 | @echo Please provide a valid EXPR to select a tool | ||
| 133 | exit /b 1 | ||
| 134 | ) | ||
| 135 | |||
| 136 | set toolname= | ||
| 137 | for /d %%d in ( tools\*%EXPR%* ) do ( | ||
| 138 | set toolname=%%~nd | ||
| 139 | ) | ||
| 140 | |||
| 141 | if [%toolname%]==[] ( | ||
| 142 | @echo Expression '%EXPR%' does not match any tool | ||
| 143 | exit /b 1 | ||
| 144 | ) | ||
| 145 | |||
| 146 | call:build_nissy || exit /b 1 | ||
| 147 | call:build_single_tool %* | ||
| 148 | exit /b | ||
| 149 | |||
| 150 | :build_cpp | ||
| 151 | if not defined EXPR ( | ||
| 152 | @echo Please provide a valid C++ source file. | ||
| 153 | exit /b 1 | ||
| 154 | ) | ||
| 155 | if not exist %EXPR% ( | ||
| 156 | @echo File %EXPR% does not exist. | ||
| 157 | exit /b 1 | ||
| 158 | ) | ||
| 159 | call:build_nissy || exit /b 1 | ||
| 160 | @echo on | ||
| 161 | %CXX% %ODFLAGS% -std=c++20 -o runcpp.exe cpp\nissy.cpp nissy.o %EXPR% ^ | ||
| 162 | || exit /b 1 | ||
| 163 | runcpp | ||
| 164 | @echo off | ||
| 165 | exit /b | ||
| 166 | |||
| 167 | :build_solvetest | ||
| 168 | call:build_nissy || exit /b 1 | ||
| 169 | for /d %%d in ( tools\*solvetest* ) do ( | ||
| 170 | set toolname=%%~nd | ||
| 171 | call:build_single_tool | ||
| 172 | ) | ||
| 173 | exit /b | ||
| 174 | |||
| 118 | :build_single_test | 175 | :build_single_test |
| 119 | call:odflags | 176 | call:odflags |
| 120 | %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o %1\*.c -o runtest.exe || exit /b 1 | 177 | %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o %1\*.c -o runtest.exe || exit /b 1 |
| @@ -138,6 +195,16 @@ exit /b | |||
| 138 | del runtest.* | 195 | del runtest.* |
| 139 | exit /b | 196 | exit /b |
| 140 | 197 | ||
| 198 | :build_single_tool | ||
| 199 | @echo on | ||
| 200 | %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o tools\%toolname%\*.c ^ | ||
| 201 | -o runtool.exe || exit /b 1 | ||
| 202 | @echo off | ||
| 203 | runtool %3 %4 %5 %6 %7 %8 %9 || exit /b 1 | ||
| 204 | @echo. | ||
| 205 | @echo (On Windows, the output of a tool is not saved to any file.) | ||
| 206 | exit /b | ||
| 207 | |||
| 141 | :odflags | 208 | :odflags |
| 142 | if %DEBUG%==1 ( | 209 | if %DEBUG%==1 ( |
| 143 | SET ODFLAGS=%DFLAGS% | 210 | SET ODFLAGS=%DFLAGS% |
diff --git a/tools/tool.h b/tools/tool.h index 47155c2..c6fafbc 100644 --- a/tools/tool.h +++ b/tools/tool.h | |||
| @@ -22,6 +22,40 @@ log_stderr(const char *str, void *unused) | |||
| 22 | fprintf(stderr, "%s", str); | 22 | fprintf(stderr, "%s", str); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | #ifdef _WIN32 | ||
| 26 | |||
| 27 | #include <windows.h> | ||
| 28 | |||
| 29 | static double | ||
| 30 | timerun(void (*run)(void)) | ||
| 31 | { | ||
| 32 | LARGE_INTEGER freq, start, end; | ||
| 33 | double tdiff; | ||
| 34 | |||
| 35 | fflush(stdout); | ||
| 36 | |||
| 37 | if (run == NULL) { | ||
| 38 | printf("nothing to run!\n"); | ||
| 39 | fflush(stdout); | ||
| 40 | return -1.0; | ||
| 41 | } | ||
| 42 | |||
| 43 | QueryPerformanceFrequency(&freq); | ||
| 44 | QueryPerformanceCounter(&start); | ||
| 45 | run(); | ||
| 46 | QueryPerformanceCounter(&end); | ||
| 47 | |||
| 48 | tdiff = (double)(end.QuadPart - start.QuadPart) / freq.QuadPart; | ||
| 49 | |||
| 50 | printf("---------\n"); | ||
| 51 | printf("\nTotal time: %.4fs\n", tdiff); | ||
| 52 | fflush(stdout); | ||
| 53 | |||
| 54 | return tdiff; | ||
| 55 | } | ||
| 56 | |||
| 57 | #else | ||
| 58 | |||
| 25 | static double | 59 | static double |
| 26 | timerun(void (*run)(void)) | 60 | timerun(void (*run)(void)) |
| 27 | { | 61 | { |
| @@ -51,6 +85,8 @@ timerun(void (*run)(void)) | |||
| 51 | return tdiff; | 85 | return tdiff; |
| 52 | } | 86 | } |
| 53 | 87 | ||
| 88 | #endif | ||
| 89 | |||
| 54 | static void | 90 | static void |
| 55 | writetable(const unsigned char *buf, int64_t size, const char *filename) | 91 | writetable(const unsigned char *buf, int64_t size, const char *filename) |
| 56 | { | 92 | { |
