This commit is contained in:
Panagiotis Christopoulos Charitos 2016-12-15 20:46:10 +01:00
Родитель 946f7796c1
Коммит 7f69f9395e
6 изменённых файлов: 54 добавлений и 28 удалений

Просмотреть файл

@ -16,11 +16,7 @@ cmake_minimum_required(VERSION 2.8)
project(SPIRV-Cross)
enable_testing()
option(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS "Instead of throwing exceptions assert. Only applies to the library targets" OFF)
if(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
add_definitions(-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
endif()
option(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS "Instead of throwing exceptions assert" OFF)
if(${CMAKE_GENERATOR} MATCHES "Makefile")
if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
@ -56,30 +52,35 @@ target_link_libraries(spirv-cross-msl spirv-cross-glsl)
target_link_libraries(spirv-cross-cpp spirv-cross-glsl)
target_include_directories(spirv-cross-core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
set(spirv-compiler-options "")
set(spirv-compiler-defines "")
if(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
set(spirv-compiler-defines ${spirv-compiler-defines} SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
endif()
# To specify special debug or optimization options, use
# -DCMAKE_CXX_COMPILE_FLAGS
# However, we require the C++11 dialect.
if (NOT "${MSVC}")
set(spirv-compiler-options -std=c++11 -Wall -Wextra -Werror -Wshadow)
set(spirv-compiler-defines __STDC_LIMIT_MACROS)
set(spirv-compiler-options ${spirv-compiler-options} -std=c++11 -Wall -Wextra -Werror -Wshadow)
set(spirv-compiler-defines ${spirv-compiler-defines} __STDC_LIMIT_MACROS)
set(spirv-exe-options ${spirv-compiler-options})
if(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
set(spirv-compiler-options ${spirv-compiler-options} -fno-exceptions)
endif()
target_compile_options(spirv-cross-core PRIVATE ${spirv-compiler-options})
target_compile_options(spirv-cross-glsl PRIVATE ${spirv-compiler-options})
target_compile_options(spirv-cross-msl PRIVATE ${spirv-compiler-options})
target_compile_options(spirv-cross-cpp PRIVATE ${spirv-compiler-options})
target_compile_options(spirv-cross PRIVATE ${spirv-exe-options})
target_compile_definitions(spirv-cross-core PRIVATE ${spirv-compiler-defines})
target_compile_definitions(spirv-cross-glsl PRIVATE ${spirv-compiler-defines})
target_compile_definitions(spirv-cross-msl PRIVATE ${spirv-compiler-defines})
target_compile_definitions(spirv-cross-cpp PRIVATE ${spirv-compiler-defines})
target_compile_definitions(spirv-cross PRIVATE ${spirv-compiler-defines})
endif()
target_compile_options(spirv-cross-core PRIVATE ${spirv-compiler-options})
target_compile_options(spirv-cross-glsl PRIVATE ${spirv-compiler-options})
target_compile_options(spirv-cross-msl PRIVATE ${spirv-compiler-options})
target_compile_options(spirv-cross-cpp PRIVATE ${spirv-compiler-options})
target_compile_options(spirv-cross PRIVATE ${spirv-compiler-options})
target_compile_definitions(spirv-cross-core PRIVATE ${spirv-compiler-defines})
target_compile_definitions(spirv-cross-glsl PRIVATE ${spirv-compiler-defines})
target_compile_definitions(spirv-cross-msl PRIVATE ${spirv-compiler-defines})
target_compile_definitions(spirv-cross-cpp PRIVATE ${spirv-compiler-defines})
target_compile_definitions(spirv-cross PRIVATE ${spirv-compiler-defines})
# Set up tests, using only the simplest modes of the test_shaders
# script. You have to invoke the script manually to:

Просмотреть файл

@ -18,6 +18,10 @@ else
CXXFLAGS += -O2 -DNDEBUG
endif
ifeq ($(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS), 1)
CXXFLAGS += -DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS -fno-exceptions
endif
all: $(TARGET)
-include $(DEPS)

Просмотреть файл

@ -23,6 +23,8 @@ However, most missing features are expected to be "trivial" improvements at this
SPIRV-Cross has been tested on Linux, OSX and Windows.
The make and CMake build flavors offer the option to treat exceptions as assertions. To disable exceptions for make just append SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS=1 to the command line. For CMake append -DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS=ON. By default exceptions are enabled.
### Linux and macOS
Just run `make` on the command line. A recent GCC (4.8+) or Clang (3.x+) compiler is required as SPIRV-Cross uses C++11 extensively.

Просмотреть файл

@ -30,6 +30,17 @@ using namespace spv;
using namespace spirv_cross;
using namespace std;
#ifdef SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS
#define THROW(x) \
do \
{ \
fprintf(stderr, "%s.", x); \
exit(1); \
} while (0)
#else
#define THROW(x) runtime_error(x)
#endif
struct CLIParser;
struct CLICallbacks
{
@ -53,7 +64,9 @@ struct CLIParser
bool parse()
{
#ifndef SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS
try
#endif
{
while (argc && !ended_state)
{
@ -69,7 +82,7 @@ struct CLIParser
auto itr = cbs.callbacks.find(next);
if (itr == ::end(cbs.callbacks))
{
throw logic_error("Invalid argument.\n");
THROW("Invalid argument");
}
itr->second(*this);
@ -78,6 +91,7 @@ struct CLIParser
return true;
}
#ifndef SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS
catch (...)
{
if (cbs.error_handler)
@ -86,6 +100,7 @@ struct CLIParser
}
return false;
}
#endif
}
void end()
@ -97,13 +112,13 @@ struct CLIParser
{
if (!argc)
{
throw logic_error("Tried to parse uint, but nothing left in arguments.\n");
THROW("Tried to parse uint, but nothing left in arguments");
}
uint32_t val = stoul(*argv);
if (val > numeric_limits<uint32_t>::max())
{
throw out_of_range("next_uint() out of range.\n");
THROW("next_uint() out of range");
}
argc--;
@ -116,7 +131,7 @@ struct CLIParser
{
if (!argc)
{
throw logic_error("Tried to parse double, but nothing left in arguments.\n");
THROW("Tried to parse double, but nothing left in arguments");
}
double val = stod(*argv);
@ -131,7 +146,7 @@ struct CLIParser
{
if (!argc)
{
throw logic_error("Tried to parse string, but nothing left in arguments.\n");
THROW("Tried to parse string, but nothing left in arguments");
}
const char *ret = *argv;

Просмотреть файл

@ -26,12 +26,16 @@ namespace spirv_cross
{
#ifdef SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS
[[noreturn]] inline void report_and_abort(const std::string &msg)
#ifndef _MSC_VER
[[noreturn]]
#endif
inline void
report_and_abort(const std::string &msg)
{
#ifdef NDEBUG
(void)msg;
#else
fprintf(stderr, "There was a compiler error: %s\n", std::string(msg).c_str());
fprintf(stderr, "There was a compiler error: %s\n", msg.c_str());
#endif
abort();
}

Просмотреть файл

@ -4766,7 +4766,7 @@ bool CompilerGLSL::is_non_native_row_major_matrix(uint32_t id)
// swaps matrix elements while retaining the original dimensional form of the matrix.
const auto type = expression_type(id);
if (type.columns != type.vecsize)
throw CompilerError("Row-major matrices must be square on this platform.");
SPIRV_CROSS_THROW("Row-major matrices must be square on this platform.");
return true;
}
@ -4787,7 +4787,7 @@ bool CompilerGLSL::member_is_non_native_row_major_matrix(const SPIRType &type, u
// swaps matrix elements while retaining the original dimensional form of the matrix.
const auto mbr_type = get<SPIRType>(type.member_types[index]);
if (mbr_type.columns != mbr_type.vecsize)
throw CompilerError("Row-major matrices must be square on this platform.");
SPIRV_CROSS_THROW("Row-major matrices must be square on this platform.");
return true;
}