#![deny(nonstandard_style, warnings, unused)]
#![deny(
missing_docs,
missing_debug_implementations,
missing_copy_implementations,
trivial_casts,
trivial_numeric_casts,
unstable_features,
unused_import_braces,
unused_qualifications
)]
#![cfg_attr(feature = "cargo-clippy", deny(clippy::all, clippy::pedantic))]
extern crate cranelift;
extern crate cranelift_module;
extern crate cranelift_simplejit;
extern crate dot;
#[macro_use]
extern crate failure;
#[macro_use]
extern crate lalrpop_util;
#[macro_use]
extern crate log;
extern crate specs;
#[macro_use]
extern crate specs_derive;
extern crate specs_visitor;
#[macro_use]
extern crate specs_visitor_derive;
#[cfg(test)]
extern crate env_logger;
use std::fmt;
mod ast;
mod codegen;
mod ir;
mod parser;
#[cfg(test)]
mod test_util;
pub mod error;
pub mod graph;
pub mod module;
pub use error::Error;
pub use error::Result;
pub struct Tin {
ir: ir::Ir,
parser: <ast::Module<parser::Context> as parser::Parse>::Parser,
}
impl Tin {
pub fn new() -> Tin {
use parser::Parse;
let ir = ir::Ir::new();
let parser = ast::Module::new_parser();
Tin { ir, parser }
}
pub fn load(&mut self, source: &str) -> Result<()> {
let module = parser::Parser::parse(&mut self.parser, source)?;
self.ir.load(&module)?;
Ok(())
}
pub fn graph(&self) -> graph::Graph {
graph::Graph::new(&self.ir)
}
pub fn compile(&mut self) -> Result<module::Module> {
self.ir.check_types();
let module = codegen::Codegen::new(&self.ir).compile();
Ok(module)
}
}
impl Default for Tin {
fn default() -> Self {
Tin::new()
}
}
impl fmt::Debug for Tin {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Tin").finish()
}
}