#[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
impl Language
Sourcepub const fn pragma_prefix(self) -> &'static str
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 ");
Sourcepub const fn is_c_family(self) -> bool
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());
Sourcepub const fn is_fortran(self) -> bool
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§
impl Copy for Language
impl Eq for Language
impl StructuralPartialEq for Language
Auto Trait Implementations§
impl Freeze for Language
impl RefUnwindSafe for Language
impl Send for Language
impl Sync for Language
impl Unpin for Language
impl UnwindSafe for Language
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more