Module convert

Source
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§

ConversionError
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