lib.rs 1.96 KB
Newer Older
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1
// Copyright 2017 The Australian National University
2
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
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
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
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;
qinsoon's avatar
qinsoon committed
36 37 38 39 40
extern crate simple_logger;
#[macro_use]
extern crate lazy_static;
extern crate utils;

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

59
/// select between two values based on condition
qinsoon's avatar
qinsoon committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
macro_rules! select_value {
    ($cond: expr, $res1 : expr, $res2 : expr) => {
        if $cond {
            $res1
        } else {
            $res2
        }
    }
}

#[macro_use]
pub mod ir;
pub mod inst;
pub mod types;
pub mod ptr;
75
pub mod op;