lib.rs 2.04 KB
Newer Older
1
// Copyright 2017 The Australian National University
2
//
3 4 5
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9 10 11 12 13 14
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

15 16 17
//! # MuIR AST crate
//!
//! This crate provides data structures to allow construct MuIR in Rust code, including:
qinsoon's avatar
qinsoon committed
18
//!
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
//! * types
//! * ir
//!   * MuFunction
//!   * MuFunctionVersion
//!     * FunctionContent
//!       * Block
//!         * BlockContent
//!           * TreeNode
//!             * Value
//!             * Instruction
//! * inst
//! * op (operators)
//!
//! Client should not create MuIR via this crate, use API instead.

34 35
#[macro_use]
extern crate rodal;
36
extern crate log;
37 38 39
extern crate simple_logger;
#[macro_use]
extern crate lazy_static;
40
extern crate mu_utils as utils;
41

42 43
/// all data structures for MuIR is an *MuEntity*
/// which has a unique MuID, and an optional MuName
44 45 46 47 48
#[macro_export]
macro_rules! impl_mu_entity {
    ($entity: ty) => {
        impl MuEntity for $entity {
            #[inline(always)]
49 50 51
            fn id(&self) -> MuID {
                self.hdr.id()
            }
52
            #[inline(always)]
53 54 55
            fn name(&self) -> MuName {
                self.hdr.name()
            }
56
            fn as_entity(&self) -> &MuEntity {
57
                let ref_ty: &$entity = self;
58 59 60
                ref_ty as &MuEntity
            }
        }
61
    };
62 63
}

64
/// select between two values based on condition
65 66 67 68 69 70 71
macro_rules! select_value {
    ($cond: expr, $res1 : expr, $res2 : expr) => {
        if $cond {
            $res1
        } else {
            $res2
        }
72
    };
73 74 75 76 77
}

#[macro_use]
pub mod ir;
pub mod inst;
78
pub mod op;
79 80
pub mod ptr;
pub mod types;