tamer: bin/tamec: wip-asg-derive-xmli-gated xmli output

This will begin to derive `xmli` output from the graph.

DEV-13708
main
Mike Gerwitz 2023-02-01 13:03:23 -05:00
parent 8d618654d4
commit 52e5242af2
2 changed files with 57 additions and 10 deletions

View File

@ -58,3 +58,9 @@ parser-trace-stderr = []
# cause issues in production TAME code.
wip-nir-to-air = []
# Derive `xmli` file from the ASG rather than a XIR token stream. This
# proves that enough information has been added to the graph for the entire
# program to be reconstructed. The `xmli` file will be a new program
# _derived from_ the original, and so will not match exactly.
wip-asg-derived-xmli = ["wip-nir-to-air"]

View File

@ -49,15 +49,11 @@ use tamer::{
InterpError, InterpolateNir, Nir, NirToAir, NirToAirError, XirfToNir,
XirfToNirError,
},
parse::{
FinalizeError, Lower, ParseError, Parsed, ParsedObject, ParsedResult,
UnknownToken,
},
parse::{FinalizeError, Lower, ParseError, ParsedObject, UnknownToken},
xir::{
self,
flat::{RefinedText, XirToXirf, XirToXirfError, XirfToken},
reader::XmlXirReader,
writer::XmlWriter,
DefaultEscaper, Error as XirError, Token as XirToken,
},
};
@ -92,10 +88,14 @@ fn src_reader<'a>(
/// transition period between the XSLT-based TAME and TAMER.
/// Writing XIR proves that the source file is being successfully parsed and
/// helps to evaluate system performance.
#[cfg(not(feature = "wip-asg-derived-xmli"))]
fn copy_xml_to<'e, W: io::Write + 'e>(
mut fout: W,
escaper: &'e DefaultEscaper,
) -> impl FnMut(&ParsedResult<ParsedObject<XirToken, XirError>>) + 'e {
) -> impl FnMut(&tamer::parse::ParsedResult<ParsedObject<XirToken, XirError>>) + 'e
{
use tamer::{parse::Parsed, xir::writer::XmlWriter};
let mut xmlwriter = Default::default();
move |tok_result| match tok_result {
@ -117,7 +117,8 @@ fn compile<R: Reporter>(
reporter: &mut R,
) -> Result<(), UnrecoverableError> {
let dest = Path::new(&dest_path);
let fout = BufWriter::new(fs::File::create(dest)?);
#[allow(unused_mut)] // wip-asg-derived-xmli
let mut fout = BufWriter::new(fs::File::create(dest)?);
let escaper = DefaultEscaper::default();
@ -139,14 +140,23 @@ fn compile<R: Reporter>(
// TODO: We're just echoing back out XIR,
// which will be the same sans some formatting.
let src = &mut src_reader(src_path, &escaper)?
.inspect(copy_xml_to(fout, &escaper))
.inspect({
#[cfg(not(feature = "wip-asg-derived-xmli"))]
{
copy_xml_to(fout, &escaper)
}
#[cfg(feature = "wip-asg-derived-xmli")]
{
|_| ()
}
})
.map(|result| result.map_err(RecoverableError::from));
// TODO: Determine a good default capacity once we have this populated
// and can come up with some heuristics.
let asg = DefaultAsg::with_capacity(1024, 2048);
let _ = Lower::<
let (_, asg) = Lower::<
ParsedObject<XirToken, XirError>,
XirToXirf<64, RefinedText>,
_,
@ -173,13 +183,44 @@ fn compile<R: Reporter>(
})?;
match reporter.has_errors() {
false => Ok(()),
false => {
#[cfg(feature = "wip-asg-derived-xmli")]
{
derive_xmli(asg, fout)
}
#[cfg(not(feature = "wip-asg-derived-xmli"))]
{
let _ = asg; // unused_variables
Ok(())
}
}
true => Err(UnrecoverableError::ErrorsDuringLowering(
reporter.error_count(),
)),
}
}
/// Derive an `xmli` file from the ASG.
///
/// The `xmli` file is an intermediate file that allows us to incrementally
/// transition responsibilities away from the old XSLT-based compiler and
/// into TAMER.
/// It will represent a program that is derived from the program the user
/// originally defined,
/// and must be an equivalent program,
/// but will look different;
/// TAMER reasons about the system using a different paradigm.
#[cfg(feature = "wip-asg-derived-xmli")]
fn derive_xmli(
_asg: tamer::asg::Asg,
mut fout: impl std::io::Write,
) -> Result<(), UnrecoverableError> {
fout.write_all(b"<it-has-begun />")?;
Ok(())
}
/// Entrypoint for the compiler
pub fn main() -> Result<(), UnrecoverableError> {
let args: Vec<String> = env::args().collect();