Enum Language

Source
#[repr(C)]
pub enum Language { C = 0, Cpp = 1, Fortran = 2, Unknown = 3, }
Expand description

Source programming language

OpenMP supports multiple host languages: C, C++, and Fortran. The IR needs to track the source language because:

  • Pragma syntax: C/C++ use #pragma omp, Fortran uses !$omp
  • Expression parsing: Different languages have different expression syntax
  • Type systems: Languages have different type semantics
  • Pretty-printing: Need to output correct syntax for the language

§Learning: Enums as Tagged Unions

In Rust, enum is much more powerful than in C. Each variant can:

  • Carry no data (like these variants)
  • Carry data (we’ll see this in later types)
  • Have different types of data per variant

§Learning: repr(C) on Enums

For FFI, we need stable discriminant values. #[repr(C)] ensures:

  • Discriminant is a C-compatible integer
  • Size and alignment match C expectations
  • Variants have predictable numeric values

We explicitly assign values (0, 1, 2, 3) so C code can rely on them.

§Example

use roup::ir::Language;

let lang = Language::C;
assert_eq!(lang as u32, 0);

let cpp = Language::Cpp;
assert_eq!(cpp as u32, 1);

Variants§

§

C = 0

C language

Uses #pragma omp syntax

§

Cpp = 1

C++ language

Uses #pragma omp syntax (same as C)

§

Fortran = 2

Fortran language

Uses !$omp syntax

§

Unknown = 3

Unknown or unspecified language

Used when language cannot be determined

Implementations§

Source§

impl Language

Source

pub const fn pragma_prefix(self) -> &'static str

Get the pragma prefix for this language

Returns the string used to start OpenMP directives.

§Example
use roup::ir::Language;

assert_eq!(Language::C.pragma_prefix(), "#pragma omp ");
assert_eq!(Language::Cpp.pragma_prefix(), "#pragma omp ");
assert_eq!(Language::Fortran.pragma_prefix(), "!$omp ");
Source

pub const fn is_c_family(self) -> bool

Check if this language uses C-style syntax

Both C and C++ use the same OpenMP syntax.

§Example
use roup::ir::Language;

assert!(Language::C.is_c_family());
assert!(Language::Cpp.is_c_family());
assert!(!Language::Fortran.is_c_family());
Source

pub const fn is_fortran(self) -> bool

Check if this language is Fortran

§Example
use roup::ir::Language;

assert!(!Language::C.is_fortran());
assert!(Language::Fortran.is_fortran());

Trait Implementations§

Source§

impl Clone for Language

Source§

fn clone(&self) -> Language

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Language

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Language

Source§

fn default() -> Self

Default to unknown language

Source§

impl Display for Language

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Format language name for display

§Example
use roup::ir::Language;

assert_eq!(format!("{}", Language::C), "C");
assert_eq!(format!("{}", Language::Cpp), "C++");
assert_eq!(format!("{}", Language::Fortran), "Fortran");
Source§

impl Hash for Language

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Language

Source§

fn eq(&self, other: &Language) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Language

Source§

impl Eq for Language

Source§

impl StructuralPartialEq for Language

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.