Don't add -frtti for tests. Use newer googletest.
[platform/upstream/SPIRV-Tools.git] / README.md
1 # SPIR-V Tools
2
3 ## Overview
4
5 The SPIR-V Tools project provides an API and commands for processing SPIR-V
6 modules.
7
8 The project includes an assembler, binary module parser, disassembler, and
9 validator for SPIR-V, all based on a common static library. The library contains
10 all of the implementation details, and is used in the standalone tools whilst
11 also enabling integration into other code bases directly.
12
13 The interfaces are still under development, and are expected to change.
14
15 SPIR-V is defined by the Khronos Group Inc.
16 See the [SPIR-V Registry](https://www.khronos.org/registry/spir-v/) for the
17 SPIR-V specification, headers, and XML registry.
18
19 ## Supported features
20
21 ### Assembler, binary parser, and disassembler
22
23 * Based on SPIR-V 1.0 Revision 2.
24   * Supports GLSL std450 extended instructions.
25   * Supports OpenCL extended instructions.
26 * Assembler only does basic syntax checking.  No cross validation of
27   IDs or types is performed, except to check literal arguments to
28   `OpConstant`, `OpSpecConstant`, and `OpSwitch`.
29
30 See [`syntax.md`](syntax.md) for the assembly language syntax.
31
32 ### Validator
33
34 *Warning:* The validator is incomplete.
35
36 ## Source code
37
38 The SPIR-V Tools are maintained by members of the The Khronos Group Inc.,
39 at [https://github.com/KhronosGroup/SPIRV-Tools](https://github.com/KhronosGroup/SPIRV-Tools).
40
41 Contributions via merge request are welcome. Changes should:
42 * Be provided under the [Khronos license](#license).
43 * Include tests to cover updated functionality.
44 * C++ code should follow the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html).
45 * Code should be formatted with `clang-format`.  Settings are defined by
46   the included [.clang-format](.clang-format) file.
47
48 We intend to maintain a linear history on the GitHub `master` branch.
49
50 ### Source code organization
51
52 * `external/headers`: Standard SPIR-V header files used by the implementation,
53    from the SPIR-V Registry
54 * `external/googletest`: Intended location for the
55   [googletest](https://github.com/google/googletest) sources, not provided.
56 * `include/libspirv/libspirv.h`: C API public interface
57 * `source/`: API implementation
58 * `test/`: Tests, using the [googletest](https://github.com/google/googletest)
59   framework.
60 * `tools/`: Command line executables
61
62 ### Tests
63
64 The project contains a number of tests, used to drive development
65 and ensure correctness.  The tests are written using the
66 [googletest](https://github.com/google/googletest) framework.  The `googletest`
67 source is not provided with this project.  Download the `googletest` source
68 into the `<spirv-dir>/external/googletest` directory before configuring
69 and building the project.
70
71 *Note*: You must use a version of googletest that includes
72 [a fix](https://github.com/google/googletest/pull/612) for
73 [googletest issue 610](https://github.com/google/googletest/issues/610).
74 The fix is included on the googletest master branch any time after 2015-11-10.
75 In particular, googletest must be newer than version 1.7.0.
76
77 ## Build
78
79 The project uses [CMake](https://cmake.org/) to generate platform-specific
80 build configurations.  To generate these build files, issue the following
81 commands:
82
83 ```
84 mkdir <spirv-dir>/build
85 cd <spirv-dir>/build
86 cmake [-G <platform-generator>] <spirv-dir>
87 ```
88
89 Once the build files have been generated, build using your preferred
90 development environment.
91
92 ### CMake options
93
94 The following CMake options are supported:
95
96 * `SPIRV_COLOR_TERMINAL=ON` - Enables color console output, enabled by default.
97 * `SPIRV_SKIP_EXECUTABLES=ON` - Build only the library, not the command line
98   tools.  This will also prevent the tests from being built.
99 * `SPIRV_USE_SANITIZER=<sanitizer>` - On UNIX platforms with an appropriate
100   version of `clang` this option enables the use of the sanitizers documented
101   [here](http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation).
102   This should only be used with a debug build. Disabled by default.
103 * `SPIRV_WARN_EVERYTHING=OFF` - On UNIX platforms enable the `-Weverything`
104   compiler front end option, disabled by default.
105 * `SPIRV_WERROR=ON` - Forces a compilation error on any warnings encountered by
106   enabling the compiler-specific compiler front-end option, enabled by default.
107
108 ## Library
109
110 ### Usage
111
112 The library provides a C API, but the internals use C++11.
113
114 In order to use the library from an application, the include path should point to
115 `<spirv-dir>/include`, which will enable the application to include the header
116 `<spirv-dir>/include/libspirv/libspirv.h` then linking against the static
117 library in `<spirv-build-dir>/libSPIRV-Tools.a` or
118 `<spirv-build-dir>/SPIRV-Tools.lib`.
119
120 * `SPIRV-Tools` CMake target: Creates the static library:
121   * `<spirv-build-dir>/libSPIRV-Tools.a` on Linux and OS X.
122   * `<spirv-build-dir>/libSPIRV-Tools.lib` on Windows.
123
124 #### Entry points
125
126 The interfaces are still under development, and are expected to change.
127
128 There are three main entry points into the library.
129
130 * `spvTextToBinary`: An assembler, translating text to a binary SPIR-V module.
131 * `spvBinaryToText`: A disassembler, translating a binary SPIR-V module to
132   text.
133 * `spvBinaryParse`: The entry point to a binary parser API.  It issues callbacks
134   for the header and each parsed instruction.  The disassembler is implemented
135   as a client of `spvBinaryParse`.
136 * `spvValidate` implements the validator functionality. *Incomplete*
137
138 ## Command line tools
139
140 ### Assembler tool
141
142 The assembler reads the assembly language text, and emits the binary form.
143
144 The standalone assembler is the exectuable called `spirv-as`, and is located in
145 `<spirv-build-dir>/spirv-as`.  The functionality of the assembler is implemented
146 by the `spvTextToBinary` library function.
147
148 * `spirv-as` - the standalone assembler
149   * `<spirv-dir>/spirv-as`
150
151 Use option `-h` to print help.
152
153 ### Disassembler tool
154
155 The disassembler reads the binary form, and emits assembly language text.
156
157 The standalone disassembler is the executable called `spirv-dis`, and is located in
158 `<spirv-build-dir>/spirv-dis`. The functionality of the disassembler is implemented
159 by the `spvBinaryToText` library function.
160
161 * `spirv-dis` - the standalone disassembler
162   * `<spirv-dir>/spirv-dis`
163
164 Use option `-h` to print help.
165
166 The output includes syntax colouring when printing to the standard output stream,
167 on Linux, Windows, and OS X.
168
169 ### Validator tool
170
171 *Warning:* This functionality is under development, and is incomplete.
172
173 The standalone validator is the executable called `spirv-val`, and is located in
174 `<spirv-build-dir>/spirv-val`. The functionality of the validator is implemented
175 by the `spvValidate` library function.
176
177 The validator operates on the binary form.
178
179 * `spirv-val` - the standalone validator
180   * `<spirv-dir>/spirv-val`
181
182 ### UnitSPIRV tool
183
184 The `<spirv-build-dir>/UnitSPIRV` executable runs the project tests.
185 It supports the standard `googletest` command line options.
186
187 ## Future Work
188 <a name="future"></a>
189
190 ### Assembler and disassembler
191
192 * Support 16-bit floating point literals.
193 * The disassembler could emit helpful annotations in comments.  For example:
194   * Use variable name information from debug instructions to annotate
195     key operations on variables.
196   * Show control flow information by annotating `OpLabel` instructions with
197     that basic block's predecessors.
198 * Error messages could be improved.
199
200 ### Validator
201
202 This is a work in progress.
203
204 ## Licence
205 <a name="license"></a>
206 ```
207 Copyright (c) 2015 The Khronos Group Inc.
208
209 Permission is hereby granted, free of charge, to any person obtaining a
210 copy of this software and/or associated documentation files (the
211 "Materials"), to deal in the Materials without restriction, including
212 without limitation the rights to use, copy, modify, merge, publish,
213 distribute, sublicense, and/or sell copies of the Materials, and to
214 permit persons to whom the Materials are furnished to do so, subject to
215 the following conditions:
216
217 The above copyright notice and this permission notice shall be included
218 in all copies or substantial portions of the Materials.
219
220 MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
221 KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
222 SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
223    https://www.khronos.org/registry/
224
225 THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
226 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
227 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
228 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
229 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
230 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
231 MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
232 ```