这是indexloc提供的服务,不要输入任何密码
Skip to content

[wgsl] Support #line directive #606

@dj2

Description

@dj2

In order to support representing source locations corresponding to an author’s original source different from the current source we should add #line and #endline support into WGSL.

Rename comment operator

The current comment operator is # this should be changed to // to make it clearer that the #line and #endline are not comments. This also provides room if we need to extend the tokens we accept after # in the future.

Restrictions on the String Literal

In order to handle strings with quotes in them, we need to allow escaped " and \ in the string literal.

The STRING_LITERAL token needs to be updated with the following:

  • A string may contain a \\ which is translated to a single \
  • A string may contain a \" which is translated to a single "
  • A string may not contain a \0
  • Otherwise, any UTF-8 character is valid within a string.

Syntax

#line 12 "a / filepath\""
...
#endline

The #line must be followed by a positive integer line number. The line number may be followed by an optional quoted string. A line number of 1 corresponds to the first line of an original source program.

Grammar updates

Add Tokens:

  • LINE == #line
  • ENDLINE == #endline

In order to support the directives they need to be add to both the statement and global_decl rules:

 | LINE INT_LITERAL STRING_LITERAL?
 | ENDLINE

This allows you to put the directives before any functions and within function bodies. It does not allow a #line or #endline to be inserted in the middle of another statement.

A #line directive may not appear as the last statement in a block.

Handling

The #line statement sets the line number in the parser until the next #line or #endline is encountered . They have no semantic effect.

The #endline restarts the parser counting line numbers. The line immediately after the #endline has a line number of 1 greater then the value set with the #line. If no #line was seen, the #endline has no effect and is counted as a regular line.

The usage of the #line operator is up to the processing software. It, should be passed through and emitted in the target language if possible.

In SPIR-V this will translate into OpLine and OpString entries for #line and OpNoLine for #endline. If the provided filename is blank the OpString will be an empty string.

%1 = OpString "a /filepath \""
         OpLine %1 12 0
...
         OpNoLIne

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalwgslWebGPU Shading Language Issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions