tamer: {ir::=>}{asg, xir}

See the previous commit.  There is no sense in some common "IR" namespace,
since those IRs should live close to whatever system whose data they
represent.

In the case of these, they are general IRs that can apply to many different
parts of the system.  If that proves to be a false statement, they'll be
moved.

DEV-10863
main
Mike Gerwitz 2021-11-04 16:12:15 -04:00
parent 5a91db6d54
commit 428d508be4
30 changed files with 61 additions and 103 deletions

View File

@ -30,7 +30,7 @@ use test::Bencher;
mod base {
use super::*;
use tamer::ir::asg::{Asg, DefaultAsg, IdentKind, IdentObject, Source};
use tamer::asg::{Asg, DefaultAsg, IdentKind, IdentObject, Source};
use tamer::sym::{GlobalSymbolIntern, SymbolId};
type Sut = DefaultAsg<IdentObject>;
@ -312,9 +312,7 @@ mod object {
mod ident {
use super::*;
use tamer::ir::asg::{
IdentKind, IdentObject, IdentObjectState, Source,
};
use tamer::asg::{IdentKind, IdentObject, IdentObjectState, Source};
use tamer::sym::GlobalSymbolIntern;
type Sut = IdentObject;

View File

@ -24,9 +24,7 @@ extern crate test;
use test::Bencher;
use tamer::ir::asg::{
Asg, DataType, DefaultAsg, IdentKind, IdentObject, Source,
};
use tamer::asg::{Asg, DataType, DefaultAsg, IdentKind, IdentObject, Source};
use tamer::ld::xmle::{lower::sort, Sections};
use tamer::sym::{GlobalSymbolIntern, SymbolId};

View File

@ -40,8 +40,8 @@ extern crate tamer;
extern crate test;
use std::convert::{TryFrom, TryInto};
use tamer::ir::xir::{NCName, QName, Token};
use tamer::sym::{GlobalSymbolIntern, GlobalSymbolResolve, SymbolId};
use tamer::xir::{NCName, QName, Token};
use test::Bencher;
fn gen_strs(n: usize, suffix: &str) -> Vec<String> {
@ -119,7 +119,7 @@ mod name {
mod ws {
use super::*;
use tamer::ir::xir::Whitespace;
use tamer::xir::Whitespace;
#[bench]
fn whitespace_1000(bench: &mut Bencher) {
@ -138,8 +138,8 @@ mod writer {
Writer as QuickXmlWriter,
};
use std::borrow::Cow;
use tamer::ir::xir::{writer::XmlWriter, AttrValue, Text};
use tamer::span::Span;
use tamer::xir::{writer::XmlWriter, AttrValue, Text};
const FRAGMENT: &str = r#"<fragment>
This is pretend fragment text. We need a lot of it.

View File

@ -274,7 +274,7 @@ where
mod test {
use super::super::graph::AsgError;
use super::*;
use crate::ir::asg::{
use crate::asg::{
Dim, IdentObject, TransitionError, TransitionResult, UnresolvedError,
};
use crate::sym::{GlobalSymbolIntern, SymbolId};

View File

@ -61,7 +61,7 @@
//!
//! ```
//! use tamer::global;
//! use tamer::ir::asg::{Asg, DefaultAsg, IdentKind, IdentObject, Source};
//! use tamer::asg::{Asg, DefaultAsg, IdentKind, IdentObject, Source};
//! use tamer::sym::{Interner, DefaultProgInterner};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
@ -110,7 +110,7 @@
//!
//! ```
//! # use tamer::global;
//! # use tamer::ir::asg::{Asg, DefaultAsg, IdentKind, IdentObject, FragmentText, Source};
//! # use tamer::asg::{Asg, DefaultAsg, IdentKind, IdentObject, FragmentText, Source};
//! # use tamer::sym::{Interner, DefaultProgInterner};
//! #
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
@ -156,7 +156,7 @@
//!
//! ```
//! # use tamer::global;
//! # use tamer::ir::asg::{Asg, DefaultAsg, IdentKind, IdentObject, FragmentText, Source};
//! # use tamer::asg::{Asg, DefaultAsg, IdentKind, IdentObject, FragmentText, Source};
//! # use tamer::sym::{Interner, DefaultProgInterner};
//! #
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {

View File

@ -1,36 +0,0 @@
// Intermediate representations (IRs)
//
// Copyright (C) 2014-2021 Ryan Specialty Group, LLC.
//
// This file is part of TAME.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//! Intermediate representations for TAME programs.
//!
//! _This module is being removed in favor of more specific locations for
//! the contained IRs._
//!
//! [Intermediate representations][ir] (IRs) are data structures used to
//! represent source data in a manner most suitable for a particular phase
//! of compilation.
//! A single IR may be used by multiple compilation phases,
//! or by multiple systems (e.g. various compilers or [linkers][]).
//!
//! [ir]: https://en.wikipedia.org/wiki/Intermediate_representation
//! [linkers]: crate::ld
pub mod asg;
#[macro_use]
pub mod xir;

View File

@ -26,7 +26,7 @@
//! ====================
//! Iterators that can fail,
//! such as XIR's
//! [`TokenResultStream`](crate::ir::xir::TokenResultStream),
//! [`TokenResultStream`](crate::xir::TokenResultStream),
//! can be confounding and difficult to work with because
//! [`Iterator::next`] wraps the [`Result`] within an [`Option`].
//! Further,

View File

@ -92,7 +92,7 @@
//! 4. [`Sections`](xmle::Sections) is then lowered into a XIR token
//! stream by [`xmle::xir`] for writing.
//!
//! [ASG]: crate::ir::asg
//! [ASG]: crate::asg
//! [topo-sort]: https://en.wikipedia.org/wiki/Topological_sorting
//!
//! Steps 1 and 2 are performed at the same time:
@ -100,7 +100,7 @@
//! Since the ASG contains only partial information,
//! it must perform other validations (such as extern resolution) during
//! this process;
//! see [crate::ir::asg] for more information.
//! see [crate::asg] for more information.
//!
//! Because the topological sort only considered explicitly defined roots,
//! identifiers are only included in the final executable if they are

View File

@ -25,12 +25,12 @@ use super::xmle::{
xir::lower_iter,
XmleSections,
};
use crate::asg::{Asg, DefaultAsg, IdentObject};
use crate::global;
use crate::ir::asg::{Asg, DefaultAsg, IdentObject};
use crate::ir::xir::writer::XmlWriter;
use crate::obj::xmlo::{AsgBuilder, AsgBuilderState, XmloReader};
use crate::sym::SymbolId;
use crate::sym::{GlobalSymbolIntern, GlobalSymbolResolve};
use crate::xir::writer::XmlWriter;
use crate::{
fs::{
Filesystem, FsCanonicalizer, PathFile, VisitOnceFile,
@ -183,8 +183,8 @@ fn load_xmlo<'a, P: AsRef<Path>>(
#[cfg(feature = "wip-xmlo-xir-reader")]
{
use crate::ir::xir::reader::XmlXirReader;
use crate::iter::into_iter_while_ok;
use crate::xir::reader::XmlXirReader;
into_iter_while_ok(XmlXirReader::from(file), |toks| {
let xmlo: XmloReader<_> = toks.into();

View File

@ -17,13 +17,13 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//! Lowering of the [ASG](crate::ir::asg) into `xmle` [`XmleSections`].
//! Lowering of the [ASG](crate::asg) into `xmle` [`XmleSections`].
//!
//! See the [parent module](super) for more information.
use super::section::{SectionsError, XmleSections};
use crate::{
ir::asg::{Asg, BaseAsg, IdentKind, IdentObject, IndexType, ObjectRef},
asg::{Asg, BaseAsg, IdentKind, IdentObject, IndexType, ObjectRef},
sym::{st, GlobalSymbolResolve, SymbolId},
};
use petgraph::visit::DfsPostOrder;
@ -184,7 +184,7 @@ impl<Ix: IndexType> std::error::Error for SortError<Ix> {
mod test {
use super::*;
use crate::{
ir::asg::{Dim, FragmentText, IdentObject, Source},
asg::{Dim, FragmentText, IdentObject, Source},
ld::xmle::{section::PushResult, Sections},
obj::xmlo::SymDtype,
sym::GlobalSymbolIntern,

View File

@ -26,9 +26,7 @@
//! which places the relocatable object code fragments in the order
//! necessary for execution.
use crate::ir::asg::{
IdentKind, IdentObject, IdentObjectState, UnresolvedError,
};
use crate::asg::{IdentKind, IdentObject, IdentObjectState, UnresolvedError};
use crate::sym::SymbolId;
use fxhash::FxHashSet;
use std::mem::take;
@ -261,7 +259,7 @@ impl std::fmt::Display for SectionsError {
#[cfg(test)]
mod test {
use super::*;
use crate::ir::asg::{Dim, IdentKind, IdentObject, Source};
use crate::asg::{Dim, IdentKind, IdentObject, Source};
use crate::obj::xmlo::SymDtype;
use crate::sym::GlobalSymbolIntern;

View File

@ -26,19 +26,17 @@
//! writing).
//!
//! Use [`lower_iter`] to produce the lowering iterator,
//! which can then use [`XmlWriter`](crate::ir::xir::writer::XmlWriter)
//! which can then use [`XmlWriter`](crate::xir::writer::XmlWriter)
//! for writing.
use super::{super::LSPAN, section::XmleSections};
use crate::{
ir::{
asg::{IdentKind, IdentObject},
xir::{
iter::{elem_wrap, ElemWrapIter},
AttrValue, QName, Text, Token,
},
},
asg::{IdentKind, IdentObject},
sym::{st::*, SymbolId},
xir::{
iter::{elem_wrap, ElemWrapIter},
AttrValue, QName, Text, Token,
},
};
use arrayvec::ArrayVec;
use std::{array, collections::hash_set, iter::Chain, vec};
@ -351,7 +349,7 @@ impl<'a> Iterator for LowerIter<'a> {
type Item = Token;
/// Produce the next XIR [`Token`] representing the lowering of
/// [`XmleSections`] from the [ASG](crate::ir::asg).
/// [`XmleSections`] from the [ASG](crate::asg).
///
/// This produces a single token at a time,
/// but [`DepListIter`] buffers tokens before emitting them,
@ -367,7 +365,7 @@ impl<'a> Iterator for LowerIter<'a> {
///
/// This produces the final representation for the `xmle` file,
/// which can be written using
/// [`XmlWriter`](crate::ir::xir::writer::XmlWriter).
/// [`XmlWriter`](crate::xir::writer::XmlWriter).
#[inline]
pub fn lower_iter<'a, S: XmleSections<'a>>(
mut sections: S,

View File

@ -19,17 +19,17 @@
use super::*;
use crate::convert::ExpectInto;
use crate::ir::{
use crate::ld::xmle::section::PushResult;
use crate::ld::xmle::Sections;
use crate::obj::xmlo::SymDtype;
use crate::sym::{GlobalSymbolIntern, GlobalSymbolResolve};
use crate::{
asg::{Dim, IdentKind, Source},
xir::{
pred::{not, open},
tree::{parser_from, Attr},
},
};
use crate::ld::xmle::section::PushResult;
use crate::ld::xmle::Sections;
use crate::obj::xmlo::SymDtype;
use crate::sym::{GlobalSymbolIntern, GlobalSymbolResolve};
use std::collections::HashSet;
type TestResult = Result<(), Box<dyn std::error::Error>>;

View File

@ -55,10 +55,12 @@ extern crate lazy_static;
#[cfg(feature = "wip-frontends")]
pub mod frontend;
#[macro_use]
pub mod xir;
pub mod asg;
pub mod convert;
pub mod fs;
#[macro_use]
pub mod ir;
pub mod iter;
pub mod ld;
pub mod obj;

View File

@ -38,7 +38,7 @@
//! used to take ownership over the data.
use super::reader::{XmloError, XmloEvent, XmloResult};
use crate::ir::asg::{
use crate::asg::{
Asg, AsgError, IdentKind, IdentKindError, IdentObjectState, IndexType,
ObjectRef, Source,
};
@ -141,7 +141,7 @@ where
/// This is an IR lowering operation.
/// The [`XmloResult`] produces data gleaned from
/// [`xmlo`](crate::obj::xmlo),
/// and this process lowers it into the IR [`asg`](crate::ir::asg).
/// and this process lowers it into the IR [`asg`](crate::asg).
///
/// Each call to this method augments the provided [`AsgBuilderState`];
/// see its documentation for more information.
@ -325,7 +325,7 @@ impl Error for AsgBuilderError {
#[cfg(test)]
mod test {
use super::*;
use crate::ir::asg::{DefaultAsg, FragmentText, IdentObject};
use crate::asg::{DefaultAsg, FragmentText, IdentObject};
use crate::obj::xmlo::{PackageAttrs, SymAttrs, SymType};
use crate::sym::GlobalSymbolIntern;
use std::collections::hash_map::RandomState;

View File

@ -47,8 +47,8 @@ mod new {
//! it exists to make feature-flagging less confusing and error-prone.
use super::{XmloError, XmloEvent, XmloResult};
use crate::ir::xir::{Token, TokenStream};
use crate::sym::st::*;
use crate::xir::{Token, TokenStream};
qname_const! {
QN_LV_PACKAGE: L_LV:L_PACKAGE,

View File

@ -20,7 +20,7 @@
use std::assert_matches::assert_matches;
use super::*;
use crate::{convert::ExpectInto, ir::xir::Token, span::DUMMY_SPAN};
use crate::{convert::ExpectInto, span::DUMMY_SPAN, xir::Token};
type Sut<B> = XmloReader<B>;

View File

@ -37,10 +37,10 @@
//! among other things.
//!
//! ```
//! use tamer::ir::xir::QName;
//! use tamer::xir::QName;
//! use tamer::sym::GlobalSymbolIntern;
//!
//!# fn main() -> Result<(), tamer::ir::xir::Error> {
//!# fn main() -> Result<(), tamer::xir::Error> {
//! let src = "foo:bar".as_bytes();
//! let qname = QName::try_from(src)?;
//!
@ -114,13 +114,13 @@ impl QNameCompatibleStaticSymbolId for TameIdentStaticSymbolId {}
#[doc(hidden)]
macro_rules! qname_const_inner {
($name:ident = :$local:ident) => {
const $name: crate::ir::xir::QName =
crate::ir::xir::QName::st_cid_local(&$local);
const $name: crate::xir::QName =
crate::xir::QName::st_cid_local(&$local);
};
($name:ident = $prefix:ident:$local:ident) => {
const $name: crate::ir::xir::QName =
crate::ir::xir::QName::st_cid(&$prefix, &$local);
const $name: crate::xir::QName =
crate::xir::QName::st_cid(&$prefix, &$local);
};
}

View File

@ -82,7 +82,7 @@ impl<I: TokenStream> Iterator for ElemWrapIter<I> {
#[cfg(test)]
mod test {
use super::*;
use crate::{convert::ExpectInto, ir::xir::Token, span::DUMMY_SPAN};
use crate::{convert::ExpectInto, span::DUMMY_SPAN, xir::Token};
#[test]
fn elem_wrap_iter() {

View File

@ -22,7 +22,7 @@
//! This uses [`quick_xml`] as the parser.
use super::{AttrValue, Error, Token};
use crate::{ir::xir::Text, span::DUMMY_SPAN, sym::GlobalSymbolInternBytes};
use crate::{span::DUMMY_SPAN, sym::GlobalSymbolInternBytes, xir::Text};
use quick_xml::{
self,
events::{attributes::Attributes, BytesStart, Event as QuickXmlEvent},

View File

@ -20,8 +20,8 @@
use super::*;
use crate::{
convert::ExpectInto,
ir::xir::{AttrValue, Text, Token},
span::DUMMY_SPAN,
xir::{AttrValue, Text, Token},
};
/// These tests use [`quick_xml`] directly,

View File

@ -27,8 +27,8 @@
//! [`parser_from`] or [`parse`].
//!
//! ```
//! use tamer::ir::xir::tree::{ParserState, parse, parser_from};
//!# use tamer::ir::xir::Token;
//! use tamer::xir::tree::{ParserState, parse, parser_from};
//!# use tamer::xir::Token;
//!
//!# let token_stream: std::vec::IntoIter<Token> = vec![].into_iter();
//! // Lazily parse a stream of XIR tokens as an iterator, yielding the next
@ -999,8 +999,8 @@ pub enum Parsed {
/// iterator it scans returns [`None`].
///
/// ```
/// use tamer::ir::xir::tree::{ParserState, parse};
///# use tamer::ir::xir::Token;
/// use tamer::xir::tree::{ParserState, parse};
///# use tamer::xir::Token;
///
///# let token_stream: std::vec::IntoIter<Token> = vec![].into_iter();
/// // The above is equivalent to:
@ -1027,8 +1027,8 @@ pub fn parse(state: &mut ParserState, tok: Token) -> Option<Result<Parsed>> {
/// see the [module-level documentation](self).
///
/// ```
/// use tamer::ir::xir::tree::parser_from;
///# use tamer::ir::xir::Token;
/// use tamer::xir::tree::parser_from;
///# use tamer::xir::Token;
///
///# let token_stream: std::vec::IntoIter<Token> = vec![].into_iter();
/// // Lazily parse a stream of XIR tokens as an iterator.

View File

@ -31,7 +31,7 @@ lazy_static! {
}
mod tree {
use crate::ir::xir::Text;
use crate::xir::Text;
use super::*;

View File

@ -20,8 +20,8 @@
//! Lower XIR stream into an XML byte stream via [`Write`].
use super::{Error as XirError, QName, Token, TokenStream};
use crate::ir::xir::{AttrValue, Text};
use crate::sym::GlobalSymbolResolve;
use crate::xir::{AttrValue, Text};
use std::io::{Error as IoError, Write};
use std::result;
@ -336,9 +336,9 @@ mod test {
use super::*;
use crate::{
ir::xir::{AttrValue, QName, Text, Whitespace},
span::Span,
sym::GlobalSymbolIntern,
xir::{AttrValue, QName, Text, Whitespace},
};
type TestResult = std::result::Result<(), Error>;