From be30820023e45a3e3654e85e06c849e15b694349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C3=A9veill=C3=A9?= Date: Sun, 9 Aug 2015 15:20:43 +0200 Subject: [PATCH 1/7] windows build: Add build scripts + appveyor.yml In order to guarantee that Hammer can build on Windows, an appveyor.yml and associated build scripts will build hammer and its examples. The idea is that as soon as the appveyor.yml exists in the repository, pull requests that would impede Windows portability would be immediately detected. The scripts expect CL.EXE to be in the path, and will produce their results in build/ The highest level of warning is enabled on CL.EXE, minus warnings that bring CL.EXE to a level that ressembles C99. The only notable warning that was disabled is the one that tells you about implicit truncating conversions. Hammer's source code has quite a few implicit conversions say from a 64bit unsigned integer to a integer of a lesser size (signed or otherwise) --- appveyor.yml | 18 ++++++++++ tools/windows/README.md | 1 + tools/windows/build.bat | 47 ++++++++++++++++++++++++++ tools/windows/build_examples.bat | 56 +++++++++++++++++++++++++++++++ tools/windows/clvars.bat | 37 ++++++++++++++++++++ tools/windows/env.bat | 16 +++++++++ tools/windows/hammer_lib_src_list | 48 ++++++++++++++++++++++++++ tools/windows/status.bat | 1 + 8 files changed, 224 insertions(+) create mode 100644 appveyor.yml create mode 100644 tools/windows/README.md create mode 100644 tools/windows/build.bat create mode 100644 tools/windows/build_examples.bat create mode 100644 tools/windows/clvars.bat create mode 100644 tools/windows/env.bat create mode 100644 tools/windows/hammer_lib_src_list create mode 100644 tools/windows/status.bat diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..b0d87a7 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,18 @@ +platform: +- x86 +- x64 +version: 1.0.{build} +os: Visual Studio 2015 +build_script: +- '@echo off' +- setlocal +- ps: >- + If ($env:Platform -Match "x86") { + $env:VCVARS_PLATFORM="x86" + } Else { + $env:VCVARS_PLATFORM="amd64" + } +- call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" %VCVARS_PLATFORM% +- call tools\windows\build.bat +- call tools\windows\build_examples.bat +- exit /b 0 diff --git a/tools/windows/README.md b/tools/windows/README.md new file mode 100644 index 0000000..3b28eea --- /dev/null +++ b/tools/windows/README.md @@ -0,0 +1 @@ +Support tools for the Windows (win32/win64) port. \ No newline at end of file diff --git a/tools/windows/build.bat b/tools/windows/build.bat new file mode 100644 index 0000000..20f878a --- /dev/null +++ b/tools/windows/build.bat @@ -0,0 +1,47 @@ +@echo off +setlocal + +REM This script must be run after vcvarsall.bat has been run, +REM so that cl.exe is in your path. +where cl.exe || goto vsmissing_err + +REM HEREPATH is : +set HEREPATH=%~d0%~p0 + +REM Set up SRC, BUILD and CLFLAGS +call %HEREPATH%\env.bat +call %HEREPATH%\clvars.bat + +echo SRC=%SRC%, BUILD=%BUILD% +echo Building with flags: %CLFLAGS% + +pushd %SRC% +mkdir %BUILD%\obj +del /Q %BUILD%\obj\ + +cl.exe -nologo -FC -EHsc -Z7 -Oi -GR- -Gm- %CLFLAGS% -c ^ + @%HEREPATH%\hammer_lib_src_list ^ + -Fo%BUILD%\obj\ +if %errorlevel% neq 0 goto err + +lib.exe %BUILD%\obj\*.obj -OUT:%BUILD%\hammer.lib +echo STATIC_LIBRARY %BUILD%\hammer.lib +if %errorlevel% neq 0 goto err +popd + +REM TODO(uucidl): how to build and run the tests? They are written with glib.h +REM which might be a challenge on windows. On the other hand the API of glib.h +REM does not seem too hard to reimplement. + +echo SUCCESS: Successfully built +endlocal +exit /b 0 + +:vsmissing_err +echo ERROR: CL.EXE missing. Have you run vcvarsall.bat? +exit /b 1 + +:err +endlocal +echo ERROR: Failed to build +exit /b %errorlevel% diff --git a/tools/windows/build_examples.bat b/tools/windows/build_examples.bat new file mode 100644 index 0000000..3bbcccb --- /dev/null +++ b/tools/windows/build_examples.bat @@ -0,0 +1,56 @@ +@echo off +setlocal + +REM This script must be run after vcvarsall.bat has been run, +REM so that cl.exe is in your path. +where cl.exe || goto vsmissing_err + +REM HEREPATH is : +set HEREPATH=%~d0%~p0 + +REM Set up SRC, BUILD and CLFLAGS +call %HEREPATH%\env.bat +call %HEREPATH%\clvars.bat + +REM type conversion of a return value +set CLFLAGS=%CLFLAGS% -wd4242 + +echo SRC=%SRC%, BUILD=%BUILD% +echo CLFLAGS=%CLFLAGS% + +set HAMMERLIB=%BUILD%\hammer.lib + +REM Now let's build some example programs + +cl.exe -nologo %CLFLAGS% examples\base64.c %HAMMERLIB% -Fo%BUILD%\ -Fe%BUILD%\ +if %errorlevel% neq 0 goto err +echo PROGRAM build\base64.exe +cl.exe -nologo %CLFLAGS% examples\base64_sem1.c %HAMMERLIB% -Fo%BUILD%\ -Fe%BUILD%\ +if %errorlevel% neq 0 goto err +echo PROGRAM build\base64_sem1.exe +cl.exe -nologo %CLFLAGS% examples\base64_sem2.c %HAMMERLIB% -Fo%BUILD%\ -Fe%BUILD%\ +if %errorlevel% neq 0 goto err +echo PROGRAM build\base64_sem2.exe + +REM FIXME(windows) TODO(uucidl): dns.c only works on posix +REM cl.exe -nologo %CLFLAGS% examples\dns.c %HAMMERLIB% -Fo%BUILD%\ -Fe%BUILD%\ +REM if %errorlevel% neq 0 goto err +REM echo PROGRAM build\dns.exe + +REM FIXME(windows) TODO(uucidl): grammar.c needs to be fixed +cl.exe -nologo %CLFLAGS% examples\ties.c examples\grammar.c %HAMMERLIB% -Fo%BUILD%\ -Fe%BUILD%\ +if %errorlevel% neq 0 goto err +echo PROGRAM build\ties.exe + +echo SUCCESS: Successfully built +endlocal +exit /b 0 + +:vsmissing_err +echo ERROR: CL.EXE missing. Have you run vcvarsall.bat? +exit /b 1 + +:err +echo ERROR: Failed to build +endlocal +exit /b %errorlevel% diff --git a/tools/windows/clvars.bat b/tools/windows/clvars.bat new file mode 100644 index 0000000..c08ed17 --- /dev/null +++ b/tools/windows/clvars.bat @@ -0,0 +1,37 @@ +REM Don't call me directly +REM Exports CLFLAGS + +REM Start with the most strict warning level +set WARNINGS=-W4 -Wall -WX + +REM We disable implicit casting warnings (c4244), as they occur too often here. +REM Its gcc/clang counterpart is Wconversion which does not seem to +REM be enabled by default. +REM See: [[https://gcc.gnu.org/wiki/NewWconversion#Frequently_Asked_Questions]] +set WARNINGS=%WARNINGS% -wd4244 + +REM c4100 (unreferenced formal parameter) is equivalent to -Wno-unused-parameter +set WARNINGS=%WARNINGS% -wd4100 + +REM c4200 (zero-sized array) is a C idiom supported by C99 +set WARNINGS=%WARNINGS% -wd4200 + +REM c4204 (non-constant aggregate initializers) ressembles C99 support +set WARNINGS=%WARNINGS% -wd4204 + +REM c4820 (warnings about padding) is not useful +set WARNINGS=%WARNINGS% -wd4820 + +REM c4710 (inlining could not be performed) is not useful +set WARNINGS=%WARNINGS% -wd4710 + +REM c4255 ( () vs (void) ambiguity) is not useful +set WARNINGS=%WARNINGS% -wd4255 + +REM c4996 (deprecated functions) +set WARNINGS=%WARNINGS% -wd4996 + +REM we use sprintf +set DEFINES=-D_CRT_SECURE_NO_WARNINGS + +set CLFLAGS=%DEFINES% %WARNINGS% diff --git a/tools/windows/env.bat b/tools/windows/env.bat new file mode 100644 index 0000000..4037578 --- /dev/null +++ b/tools/windows/env.bat @@ -0,0 +1,16 @@ +REM Don't call me directly. +REM +REM Expects HEREPATH (this directory) +REM Exports SRC (hammer's src directory) +REM Exports BUILD (hammer's build directory) + +set TOP=%HEREPATH%..\.. + +REM Get canonical path for TOP +pushd . +cd %TOP% +set TOP=%CD% +popd + +set SRC=%TOP%\src +set BUILD=%TOP%\build diff --git a/tools/windows/hammer_lib_src_list b/tools/windows/hammer_lib_src_list new file mode 100644 index 0000000..342b634 --- /dev/null +++ b/tools/windows/hammer_lib_src_list @@ -0,0 +1,48 @@ +asprintf.c +platform_win32.c +allocator.c +benchmark.c +bitreader.c +bitwriter.c +cfgrammar.c +datastructures.c +desugar.c +glue.c +hammer.c +pprint.c +registry.c +system_allocator.c +parsers/action.c +parsers/and.c +parsers/attr_bool.c +parsers/bind.c +parsers/bits.c +parsers/butnot.c +parsers/ch.c +parsers/charset.c +parsers/difference.c +parsers/end.c +parsers/endianness.c +parsers/epsilon.c +parsers/ignore.c +parsers/ignoreseq.c +parsers/indirect.c +parsers/int_range.c +parsers/many.c +parsers/not.c +parsers/nothing.c +parsers/optional.c +parsers/permutation.c +parsers/sequence.c +parsers/token.c +parsers/unimplemented.c +parsers/whitespace.c +parsers/xor.c +parsers/value.c +backends/packrat.c +backends/llk.c +backends/regex.c +backends/glr.c +backends/lalr.c +backends/lr.c +backends/lr0.c diff --git a/tools/windows/status.bat b/tools/windows/status.bat new file mode 100644 index 0000000..4f8bd11 --- /dev/null +++ b/tools/windows/status.bat @@ -0,0 +1 @@ +git grep "FIXME(windows)" From e7620e3e4bed281818b505933ac425d28b5a3c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C3=A9veill=C3=A9?= Date: Sun, 9 Aug 2015 17:02:49 +0200 Subject: [PATCH 2/7] windows build: Build with debug symbols --- tools/windows/clvars.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/windows/clvars.bat b/tools/windows/clvars.bat index c08ed17..4f63bd1 100644 --- a/tools/windows/clvars.bat +++ b/tools/windows/clvars.bat @@ -34,4 +34,4 @@ set WARNINGS=%WARNINGS% -wd4996 REM we use sprintf set DEFINES=-D_CRT_SECURE_NO_WARNINGS -set CLFLAGS=%DEFINES% %WARNINGS% +set CLFLAGS=-Od -Z7 %DEFINES% %WARNINGS% -Debug From 6b9ba6033eda93ea595da25540fd6a467f9e1d32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C3=A9veill=C3=A9?= Date: Sun, 9 Aug 2015 17:44:47 +0200 Subject: [PATCH 3/7] Allow windows users to include hammer.h We substitute H_GCC_ATTRIBUTE to any occurence of __attribute__ and disable its function with non gcc, non clang compilers. We use a H_ macro so as to not pollute users' namespaces. On windows build without c4201 so as to allow anonymous struct. This shows hammer is not C99 compliant but rather C11. --- src/hammer.h | 13 ++++++++++--- tools/windows/clvars.bat | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/hammer.h b/src/hammer.h index 50b3de5..95f8c98 100644 --- a/src/hammer.h +++ b/src/hammer.h @@ -17,6 +17,13 @@ #ifndef HAMMER_HAMMER__H #define HAMMER_HAMMER__H + +#if defined(__clang__) || defined(__GNUC__) +#define H_GCC_ATTRIBUTE(x) __attribute__(x) +#else +#define H_GCC_ATTRIBUTE(x) +#endif + #ifndef HAMMER_INTERNAL__NO_STDARG_H #include #endif // HAMMER_INTERNAL__NO_STDARG_H @@ -434,7 +441,7 @@ HAMMER_FN_DECL_NOARG(HParser*, h_nothing_p); * * Result token type: TT_SEQUENCE */ -HAMMER_FN_DECL_VARARGS_ATTR(__attribute__((sentinel)), HParser*, h_sequence, HParser* p); +HAMMER_FN_DECL_VARARGS_ATTR(H_GCC_ATTRIBUTE((sentinel)), HParser*, h_sequence, HParser* p); /** * Given an array of parsers, p_array, apply each parser in order. The @@ -443,7 +450,7 @@ HAMMER_FN_DECL_VARARGS_ATTR(__attribute__((sentinel)), HParser*, h_sequence, HPa * * Result token type: The type of the first successful parser's result. */ -HAMMER_FN_DECL_VARARGS_ATTR(__attribute__((sentinel)), HParser*, h_choice, HParser* p); +HAMMER_FN_DECL_VARARGS_ATTR(H_GCC_ATTRIBUTE((sentinel)), HParser*, h_choice, HParser* p); /** * Given a null-terminated list of parsers, match a permutation phrase of these @@ -469,7 +476,7 @@ HAMMER_FN_DECL_VARARGS_ATTR(__attribute__((sentinel)), HParser*, h_choice, HPars * * Result token type: TT_SEQUENCE */ -HAMMER_FN_DECL_VARARGS_ATTR(__attribute__((sentinel)), HParser*, h_permutation, HParser* p); +HAMMER_FN_DECL_VARARGS_ATTR(H_GCC_ATTRIBUTE((sentinel)), HParser*, h_permutation, HParser* p); /** * Given two parsers, p1 and p2, this parser succeeds in the following diff --git a/tools/windows/clvars.bat b/tools/windows/clvars.bat index 4f63bd1..ba54900 100644 --- a/tools/windows/clvars.bat +++ b/tools/windows/clvars.bat @@ -19,6 +19,9 @@ set WARNINGS=%WARNINGS% -wd4200 REM c4204 (non-constant aggregate initializers) ressembles C99 support set WARNINGS=%WARNINGS% -wd4204 +REM c4201 (anonymous unions) ressembles C11 support +set WARNINGS=%WARNINGS% -wd4201 + REM c4820 (warnings about padding) is not useful set WARNINGS=%WARNINGS% -wd4820 From c8726244aeb5e65775e5d6038aa4d7aacfbb3378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C3=A9veill=C3=A9?= Date: Sun, 9 Aug 2015 18:37:07 +0200 Subject: [PATCH 4/7] Wrap remaining __attribute__ We wrap all remaining references to __attribute__ into a macro call to H_GCC_ATTRIBUTE, to allow compilation with MSVC CL.EXE --- src/backends/contextfree.h | 2 +- src/bindings/cpp/hammer/hammer_test.hpp | 2 +- src/bindings/desugar-header.pl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backends/contextfree.h b/src/backends/contextfree.h index 9105636..29b51a0 100644 --- a/src/backends/contextfree.h +++ b/src/backends/contextfree.h @@ -22,7 +22,7 @@ struct HCFStack_ { }; #ifndef UNUSED -#define UNUSED __attribute__((unused)) +#define UNUSED H_GCC_ATTRIBUTE((unused)) #endif static inline HCFChoice* h_cfstack_new_choice_raw(HAllocator *mm__, HCFStack *stk__) UNUSED; diff --git a/src/bindings/cpp/hammer/hammer_test.hpp b/src/bindings/cpp/hammer/hammer_test.hpp index 77e6daa..f3ab77a 100644 --- a/src/bindings/cpp/hammer/hammer_test.hpp +++ b/src/bindings/cpp/hammer/hammer_test.hpp @@ -5,7 +5,7 @@ #include #include -#define HAMMER_DECL_UNUSED __attribute__((unused)) +#define HAMMER_DECL_UNUSED H_GCC_ATTRIBUTE((unused)) static ::testing::AssertionResult ParseFails (hammer::Parser parser, const std::string &input) HAMMER_DECL_UNUSED; diff --git a/src/bindings/desugar-header.pl b/src/bindings/desugar-header.pl index 5bdd11e..e836ad7 100644 --- a/src/bindings/desugar-header.pl +++ b/src/bindings/desugar-header.pl @@ -11,7 +11,7 @@ while(<>) { } elsif (/^HAMMER_FN_DECL\(([^,]*), ([^,]*), ([^)]*)\);/) { print "$1 $2($3);\n"; print "$1 $2__m(HAllocator* mm__, $3);\n"; - } elsif (/^HAMMER_FN_DECL_VARARGS_ATTR\((__attribute__\(\([^)]*\)\)), ([^,]*), ([^,]*), ([^)]*)\);/) { + } elsif (/^HAMMER_FN_DECL_VARARGS_ATTR\((H_GCC_ATTRIBUTE\(\([^)]*\)\)), ([^,]*), ([^,]*), ([^)]*)\);/) { print "$2 $3($4, ...);\n"; print "$2 $3__m(HAllocator *mm__, $4, ...);\n"; print "$2 $3__a(void* args);\n"; From 0c35525e30f7e817c2e8850d228534483f2ffdc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C3=A9veill=C3=A9?= Date: Sun, 9 Aug 2015 18:38:27 +0200 Subject: [PATCH 5/7] Convert usages of errx to h_platform_errx This BSD call will have to be implemented on windows. Right now we have a stub that just exits the process. --- src/SConscript | 2 ++ src/backends/packrat.c | 6 +++--- src/compiler_specifics.h | 16 ++++++++++++++++ src/hammer.c | 1 - src/hammer.h | 6 +----- src/internal.h | 4 ++-- src/parsers/many.c | 2 +- src/platform.h | 18 ++++++++++++++++++ src/platform_bsdlike.c | 10 ++++++++++ src/platform_win32.c | 10 ++++++++++ 10 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 src/compiler_specifics.h create mode 100644 src/platform.h create mode 100644 src/platform_bsdlike.c create mode 100644 src/platform_win32.c diff --git a/src/SConscript b/src/SConscript index e192b05..05ffa98 100644 --- a/src/SConscript +++ b/src/SConscript @@ -5,6 +5,7 @@ Import('env testruns') dist_headers = [ "hammer.h", "allocator.h", + "compiler_specifics.h", "glue.h", "internal.h" ] @@ -61,6 +62,7 @@ misc_hammer_parts = [ 'desugar.c', 'glue.c', 'hammer.c', + 'platform_bsdlike.c', 'pprint.c', 'registry.c', 'system_allocator.c'] diff --git a/src/backends/packrat.c b/src/backends/packrat.c index 33082c6..e6f86f2 100644 --- a/src/backends/packrat.c +++ b/src/backends/packrat.c @@ -126,7 +126,7 @@ HParseResult* grow(HParserCacheKey *k, HParseState *state, HRecursionHead *head) h_hashtable_put(state->recursion_heads, &k->input_pos, head); HParserCacheValue *old_cached = h_hashtable_get(state->cache, k); if (!old_cached || PC_LEFT == old_cached->value_type) - errx(1, "impossible match"); + h_platform_errx(1, "impossible match"); HParseResult *old_res = old_cached->right; // rewind the input @@ -148,7 +148,7 @@ HParseResult* grow(HParserCacheKey *k, HParseState *state, HRecursionHead *head) state->input_stream = cached->input_stream; return cached->right; } else { - errx(1, "impossible match"); + h_platform_errx(1, "impossible match"); } } } else { @@ -173,7 +173,7 @@ HParseResult* lr_answer(HParserCacheKey *k, HParseState *state, HLeftRec *growab return grow(k, state, growable->head); } } else { - errx(1, "lrAnswer with no head"); + h_platform_errx(1, "lrAnswer with no head"); } } diff --git a/src/compiler_specifics.h b/src/compiler_specifics.h new file mode 100644 index 0000000..ed09d66 --- /dev/null +++ b/src/compiler_specifics.h @@ -0,0 +1,16 @@ +#ifndef HAMMER_COMPILER_SPECIFICS__H +#define HAMMER_COMPILER_SPECIFICS__H + +#if defined(__clang__) || defined(__GNUC__) +#define H_GCC_ATTRIBUTE(x) __attribute__(x) +#else +#define H_GCC_ATTRIBUTE(x) +#endif + +#if defined(_MSC_VER) +#define H_MSVC_DECLSPEC(x) __declspec(x) +#else +#define H_MSVC_DECLSPEC(x) +#endif + +#endif diff --git a/src/hammer.c b/src/hammer.c index 6bb9ebb..443c77b 100644 --- a/src/hammer.c +++ b/src/hammer.c @@ -17,7 +17,6 @@ #include #include -#include #include #include #include diff --git a/src/hammer.h b/src/hammer.h index 95f8c98..42c7345 100644 --- a/src/hammer.h +++ b/src/hammer.h @@ -18,11 +18,7 @@ #ifndef HAMMER_HAMMER__H #define HAMMER_HAMMER__H -#if defined(__clang__) || defined(__GNUC__) -#define H_GCC_ATTRIBUTE(x) __attribute__(x) -#else -#define H_GCC_ATTRIBUTE(x) -#endif +#include "compiler_specifics.h" #ifndef HAMMER_INTERNAL__NO_STDARG_H #include diff --git a/src/internal.h b/src/internal.h index ed1bd08..9aac4ee 100644 --- a/src/internal.h +++ b/src/internal.h @@ -24,9 +24,9 @@ #define HAMMER_INTERNAL__H #include #include -#include #include #include "hammer.h" +#include "platform.h" /* "Internal" in this case means "we're not ready to commit * to a public API." Many structures and routines here will be @@ -38,7 +38,7 @@ #else #define assert_message(check, message) do { \ if (!(check)) \ - errx(1, "Assertion failed (programmer error): %s", message); \ + h_platform_errx(1, "Assertion failed (programmer error): %s", message); \ } while(0) #endif diff --git a/src/parsers/many.c b/src/parsers/many.c index 1e3b022..51d733f 100644 --- a/src/parsers/many.c +++ b/src/parsers/many.c @@ -246,7 +246,7 @@ static HParseResult* parse_length_value(void *env, HParseState *state) { if (!len) return NULL; if (len->ast->token_type != TT_UINT) - errx(1, "Length parser must return an unsigned integer"); + h_platform_errx(1, "Length parser must return an unsigned integer"); // TODO: allocate this using public functions HRepeat repeat = { .p = lv->value, diff --git a/src/platform.h b/src/platform.h new file mode 100644 index 0000000..0c05bfe --- /dev/null +++ b/src/platform.h @@ -0,0 +1,18 @@ +#ifndef HAMMER_PLATFORM__H +#define HAMMER_PLATFORM__H + +/** + * @file interface between hammer and the operating system / + * underlying platform. + */ + +#include "compiler_specifics.h" + +/* Error Reporting */ + +/* BSD errx function, seen in err.h */ +H_MSVC_DECLSPEC(noreturn) \ +void h_platform_errx(int err, const char* format, ...) \ + H_GCC_ATTRIBUTE((noreturn, format (printf,2,3))); + +#endif diff --git a/src/platform_bsdlike.c b/src/platform_bsdlike.c new file mode 100644 index 0000000..ebb38d9 --- /dev/null +++ b/src/platform_bsdlike.c @@ -0,0 +1,10 @@ +#include "platform.h" + +#include +#include + +void h_platform_errx(int err, const char* format, ...) { + va_list ap; + va_start(ap, format); + verrx(err, format, ap); +} diff --git a/src/platform_win32.c b/src/platform_win32.c new file mode 100644 index 0000000..30af168 --- /dev/null +++ b/src/platform_win32.c @@ -0,0 +1,10 @@ +#include "platform.h" + +#define WIN32_LEAN_AND_MEAN +#include "windows.h" + +void h_platform_errx(int err, const char* format, ...) { + // FIXME(windows) TODO(uucidl): to be implemented + ExitProcess(err); +} + From c0ab06736fb3ebc705f183d861dafb46a2842392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C3=A9veill=C3=A9?= Date: Sun, 9 Aug 2015 18:40:04 +0200 Subject: [PATCH 6/7] Deactivate compiler warnings from CL.EXE that fire in hammer Some of them are completely spurious however some (marked FIXME(windows)) may benefit from being looked at. --- tools/windows/build_examples.bat | 3 --- tools/windows/clvars.bat | 33 +++++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/tools/windows/build_examples.bat b/tools/windows/build_examples.bat index 3bbcccb..c431fae 100644 --- a/tools/windows/build_examples.bat +++ b/tools/windows/build_examples.bat @@ -12,9 +12,6 @@ REM Set up SRC, BUILD and CLFLAGS call %HEREPATH%\env.bat call %HEREPATH%\clvars.bat -REM type conversion of a return value -set CLFLAGS=%CLFLAGS% -wd4242 - echo SRC=%SRC%, BUILD=%BUILD% echo CLFLAGS=%CLFLAGS% diff --git a/tools/windows/clvars.bat b/tools/windows/clvars.bat index ba54900..8e29226 100644 --- a/tools/windows/clvars.bat +++ b/tools/windows/clvars.bat @@ -4,11 +4,25 @@ REM Exports CLFLAGS REM Start with the most strict warning level set WARNINGS=-W4 -Wall -WX +REM c4457 (declaration shadowing function parameter) +REM FIXME(windows) TODO(uucidl): remove occurence of c4457 and reactivate +REM FIXME(windows) TODO(uucidl): remove occurence of c4456 and reactivate +REM see -Wshadow +set WARNINGS=%WARNINGS% -wd4457 -wd4456 + +REM c4701 (potentially unitialized local variable) +REM FIXME(windows) TODO(uucidl): remove occurence of c4701 if possible +set WARNINGS=%WARNINGS% -wd4701 + REM We disable implicit casting warnings (c4244), as they occur too often here. REM Its gcc/clang counterpart is Wconversion which does not seem to REM be enabled by default. REM See: [[https://gcc.gnu.org/wiki/NewWconversion#Frequently_Asked_Questions]] -set WARNINGS=%WARNINGS% -wd4244 +REM +REM Likewise for c4242 (conversion with potential loss of data) and c4267 +REM (conversion away from size_t to a smaller type) and c4245 (conversion +REM from int to size_t signed/unsigned mismatch) +set WARNINGS=%WARNINGS% -wd4242 -wd4244 -wd4245 -wd4267 REM c4100 (unreferenced formal parameter) is equivalent to -Wno-unused-parameter set WARNINGS=%WARNINGS% -wd4100 @@ -19,11 +33,13 @@ set WARNINGS=%WARNINGS% -wd4200 REM c4204 (non-constant aggregate initializers) ressembles C99 support set WARNINGS=%WARNINGS% -wd4204 -REM c4201 (anonymous unions) ressembles C11 support +REM c4201 (anonymous unions) ressembles C11 support. +REM see -std=gnu99 vs -std=c99 set WARNINGS=%WARNINGS% -wd4201 -REM c4820 (warnings about padding) is not useful -set WARNINGS=%WARNINGS% -wd4820 +REM c4820 (warnings about padding) and c4324 (intentional padding) are +REM not useful +set WARNINGS=%WARNINGS% -wd4820 -wd4324 REM c4710 (inlining could not be performed) is not useful set WARNINGS=%WARNINGS% -wd4710 @@ -31,10 +47,13 @@ set WARNINGS=%WARNINGS% -wd4710 REM c4255 ( () vs (void) ambiguity) is not useful set WARNINGS=%WARNINGS% -wd4255 -REM c4996 (deprecated functions) -set WARNINGS=%WARNINGS% -wd4996 +REM c4127 (conditional expression is constant) is not useful +set WARNINGS=%WARNINGS% -wd4127 -REM we use sprintf +REM c4668 (an undefined symbol in a preprocessor directive) is not useful +set WARNINGS=%WARNINGS% -wd4668 + +REM we use sprintf so this should be enabled set DEFINES=-D_CRT_SECURE_NO_WARNINGS set CLFLAGS=-Od -Z7 %DEFINES% %WARNINGS% -Debug From 226cad2ab2bca6371fa327ecaad9122686f26744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C3=A9veill=C3=A9?= Date: Sun, 9 Aug 2015 18:40:44 +0200 Subject: [PATCH 7/7] Don't build all of Hammer on AppVeyor just now Since the port is not finished yet, we remove some source files and the compilation of examples. --- appveyor.yml | 3 ++- tools/windows/hammer_lib_src_list | 10 ---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index b0d87a7..2aef9c9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,5 +14,6 @@ build_script: } - call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" %VCVARS_PLATFORM% - call tools\windows\build.bat -- call tools\windows\build_examples.bat +# FIXME(windows) TODO(uucidl): reactivate examples +# - call tools\windows\build_examples.bat - exit /b 0 diff --git a/tools/windows/hammer_lib_src_list b/tools/windows/hammer_lib_src_list index 342b634..4c85a43 100644 --- a/tools/windows/hammer_lib_src_list +++ b/tools/windows/hammer_lib_src_list @@ -1,22 +1,14 @@ -asprintf.c platform_win32.c allocator.c -benchmark.c bitreader.c bitwriter.c cfgrammar.c -datastructures.c desugar.c glue.c hammer.c -pprint.c -registry.c -system_allocator.c parsers/action.c parsers/and.c parsers/attr_bool.c -parsers/bind.c -parsers/bits.c parsers/butnot.c parsers/ch.c parsers/charset.c @@ -30,7 +22,6 @@ parsers/indirect.c parsers/int_range.c parsers/many.c parsers/not.c -parsers/nothing.c parsers/optional.c parsers/permutation.c parsers/sequence.c @@ -41,7 +32,6 @@ parsers/xor.c parsers/value.c backends/packrat.c backends/llk.c -backends/regex.c backends/glr.c backends/lalr.c backends/lr.c