Support for file input and output, including multiple input files with proper position tracking.
This commit is contained in:
@@ -512,9 +512,17 @@ impl<'a> Codegen<'a> {
|
||||
pub fn generate_rust(&self) -> Result<String, Error> {
|
||||
let mut code = String::new();
|
||||
writeln!(&mut code, "// GENERATED BY ISLE. DO NOT EDIT!")?;
|
||||
writeln!(&mut code, "//")?;
|
||||
writeln!(
|
||||
&mut code,
|
||||
"use super::*; // Pulls in all external types and ctors/etors"
|
||||
"// Generated automatically from the instruction-selection DSL code in:",
|
||||
)?;
|
||||
for file in &self.typeenv.filenames {
|
||||
writeln!(&mut code, "// - {}", file)?;
|
||||
}
|
||||
writeln!(
|
||||
&mut code,
|
||||
"\nuse super::*; // Pulls in all external types and ctors/etors"
|
||||
)?;
|
||||
self.generate_internal_types(&mut code)?;
|
||||
Ok(code)
|
||||
@@ -533,10 +541,11 @@ impl<'a> Codegen<'a> {
|
||||
let name = &self.typeenv.syms[name.index()];
|
||||
writeln!(
|
||||
code,
|
||||
"\n// Internal type {}: defined at {}.",
|
||||
"\n/// Internal type {}: defined at {}.",
|
||||
name,
|
||||
pos.pretty_print_line(&self.typeenv.filename)
|
||||
pos.pretty_print_line(&self.typeenv.filenames[..])
|
||||
)?;
|
||||
writeln!(code, "#[derive(Clone, Debug)]")?;
|
||||
writeln!(code, "enum {} {{", name)?;
|
||||
for variant in variants {
|
||||
let name = &self.typeenv.syms[variant.name.index()];
|
||||
@@ -546,7 +555,7 @@ impl<'a> Codegen<'a> {
|
||||
let ty_name = self.typeenv.types[field.ty.index()].name(&self.typeenv);
|
||||
writeln!(code, " {}: {},", name, ty_name)?;
|
||||
}
|
||||
writeln!(code, " }}")?;
|
||||
writeln!(code, " }},")?;
|
||||
}
|
||||
writeln!(code, "}}")?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user