Expand description
Conversion from parser types to IR types
This module handles the conversion from the parser’s string-based representation to the IR’s semantic representation.
§Learning Objectives
- Pattern matching on strings: Mapping clause names to semantic types
- Error handling: Using Result for fallible conversions
- Parsing clause data: Extracting semantic meaning from strings
- Gradual refinement: Starting simple, adding complexity incrementally
§Conversion Strategy
The parser gives us:
- Directive name as a string (e.g., “parallel for”)
- Clauses with names and optional content strings
We need to convert this to IR which has:
- DirectiveKind enum
- ClauseData with structured semantic information
§Example
Parser output:
Directive { name: "parallel for",
clauses: [
Clause { name: "private", kind: Parenthesized("x, y") },
Clause { name: "reduction".into(), kind: Parenthesized("+: sum") }
] }
IR output:
DirectiveIR {
kind: DirectiveKind::ParallelFor,
clauses: [
ClauseData::Private { items: [Identifier("x"), Identifier("y")] },
ClauseData::Reduction { operator: Add, items: [Identifier("sum")] }
],
...
}
Enums§
- Conversion
Error - Error type for conversion failures
Functions§
- convert_
directive - Convert a parser Directive to IR DirectiveIR
- parse_
clause_ data - Convert a parser Clause to IR ClauseData
- parse_
depend_ type - Parse a dependence type from a string
- parse_
directive_ kind - Convert a directive name string to DirectiveKind
- parse_
identifier_ list - Parse a simple identifier list from a string
- parse_
linear_ clause - Parse a linear clause
- parse_
map_ clause - Parse a map clause
- parse_
reduction_ operator - Parse a reduction operator from a string
- parse_
schedule_ clause - Parse a schedule clause