Update readme about the "<result-id> = <opcode> <operand>..." format.

This commit is contained in:
Lei Zhang 2015-08-24 14:07:37 -04:00 committed by David Neto
parent 8a37520908
commit 902e5a8a52

View File

@ -95,16 +95,34 @@ text names from that specification. Here is an example.
```
OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint GLCompute $3 "main"
OpExecutionMode $3 LocalSize 64 64 1
OpEntryPoint GLCompute %3 "main"
OpExecutionMode %3 LocalSize 64 64 1
OpTypeVoid %1
OpTypeFunction %2 $1
OpFunction $1 %3 None $2
OpTypeFunction %2 %1
OpFunction %1 %3 None %2
OpLabel %4
OpReturn
OpFunctionEnd
```
In order to improve the text's readability, the `<result-id>` generated by an
instruction can be moved to the beginning of that instruction and followed by
an `=` sign. This allows us to distinguish between variable defs and uses and
locate variable defs more easily. So, the above example can also be written as:
```
OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint GLCompute %3 "main"
OpExecutionMode %3 LocalSize 64 64 1
%1 = OpTypeVoid
%2 = OpTypeFunction %1
%3 = OpFunction %1 None %2
%4 = OpLabel
OpReturn
OpFunctionEnd
```
Each line encapsulates one and only one instruction, or an OpCode and all of its
operands. OpCodes use the names provided in section 3.28 Instructions of the
SPIR-V specification, immediate values such as Addressing Model, Memory Model,
@ -114,11 +132,9 @@ Capability of the SPIR-V specification. Literals strings are enclosed in quotes
##### ID Definitions & Usage
An ID definition pertains to the `Result <id>` of an OpCode, and ID usage is any
input to an OpCode. To differentiate between definitions and uses, all ID
definitions are prefixed with `%` and take the form `%<id>`, meanwhile all ID
uses are prefixed with `$` and take the form `$<id>`. See the above example to
see this in action.
An ID definition pertains to the `<result-id>` of an OpCode, and ID usage is any
input to an OpCode. All IDs are prefixed with `%`. To differentiate between
defs and uses, we suggest using the second format shown in the above.
##### Named IDs
@ -130,12 +146,12 @@ following example will result in identical SPIR-V binary as the example above.
```
OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint GLCompute $main "main"
OpExecutionMode $main LocalSize 64 64 1
OpTypeVoid %void
OpTypeFunction %fnMain $void
OpFunction $void %main None $fnMain
OpLabel %lbMain
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 64 64 1
%void = OpTypeVoid
%fnMain = OpTypeFunction %void
%main = OpFunction %void None %fnMain
%lbMain = OpLabel
OpReturn
OpFunctionEnd
```