Parse parses the SPIR-V assembly string source, returning the parse results.
(source string)
| 731 | |
| 732 | // Parse parses the SPIR-V assembly string source, returning the parse results. |
| 733 | func Parse(source string) (Results, error) { |
| 734 | toks, diags, err := lex(source) |
| 735 | if err != nil { |
| 736 | return Results{}, err |
| 737 | } |
| 738 | lines := strings.SplitAfter(source, "\n") |
| 739 | p := parser{ |
| 740 | lines: lines, |
| 741 | toks: toks, |
| 742 | idents: map[string]*Identifier{}, |
| 743 | mappings: map[*Token]interface{}{}, |
| 744 | extInstImports: map[string]schema.OpcodeMap{}, |
| 745 | } |
| 746 | if err := p.parse(); err != nil { |
| 747 | return Results{}, err |
| 748 | } |
| 749 | diags = append(diags, p.diags...) |
| 750 | return Results{ |
| 751 | Lines: lines, |
| 752 | Tokens: toks, |
| 753 | Diagnostics: p.diags, |
| 754 | Identifiers: p.idents, |
| 755 | Mappings: p.mappings, |
| 756 | }, nil |
| 757 | } |
| 758 | |
| 759 | // IsResult returns true if k is used to store the result of an instruction. |
| 760 | func IsResult(k *schema.OperandKind) bool { |