WIP fix stack overflow
This commit is contained in:
2
rust_compiler/Cargo.lock
generated
2
rust_compiler/Cargo.lock
generated
@@ -930,7 +930,7 @@ checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slang"
|
name = "slang"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ impl<'a> Compiler<'a> {
|
|||||||
|
|
||||||
fn next_label_name(&mut self) -> Cow<'a, str> {
|
fn next_label_name(&mut self) -> Cow<'a, str> {
|
||||||
self.label_counter += 1;
|
self.label_counter += 1;
|
||||||
Cow::from(format!("L{}", self.label_counter))
|
Cow::from(format!("__internal_L{}", self.label_counter))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expression(
|
fn expression(
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ pub fn find_leaf_functions(instructions: &[InstructionNode]) -> HashSet<String>
|
|||||||
for node in instructions {
|
for node in instructions {
|
||||||
match &node.instruction {
|
match &node.instruction {
|
||||||
Instruction::LabelDef(label) => {
|
Instruction::LabelDef(label) => {
|
||||||
|
if label.starts_with("__internal_L") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// If we were tracking a function, and it remained a leaf until now, save it.
|
// If we were tracking a function, and it remained a leaf until now, save it.
|
||||||
if let Some(name) = current_label.take()
|
if let Some(name) = current_label.take()
|
||||||
&& is_current_leaf
|
&& is_current_leaf
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ fn optimize_leaf_functions<'a>(
|
|||||||
// First scan: Identify instructions to remove and capture RA offsets
|
// First scan: Identify instructions to remove and capture RA offsets
|
||||||
for (i, node) in input.iter().enumerate() {
|
for (i, node) in input.iter().enumerate() {
|
||||||
match &node.instruction {
|
match &node.instruction {
|
||||||
Instruction::LabelDef(label) => {
|
Instruction::LabelDef(label) if !label.starts_with("__internal_L") => {
|
||||||
current_function = Some(label.to_string());
|
current_function = Some(label.to_string());
|
||||||
function_start_indices.insert(label.to_string(), i);
|
function_start_indices.insert(label.to_string(), i);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ struct Args {
|
|||||||
/// The output file for the compiled program. If not set, output will go to stdout.
|
/// The output file for the compiled program. If not set, output will go to stdout.
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
output_file: Option<PathBuf>,
|
output_file: Option<PathBuf>,
|
||||||
|
/// Should Slang attempt to optimize the output?
|
||||||
|
#[arg(short = 'z', long)]
|
||||||
|
optimize: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_logic<'a>() -> Result<(), Error<'a>> {
|
fn run_logic<'a>() -> Result<(), Error<'a>> {
|
||||||
@@ -107,7 +110,11 @@ fn run_logic<'a>() -> Result<(), Error<'a>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if args.optimize {
|
||||||
optimizer::optimize(instructions).write(&mut writer)?;
|
optimizer::optimize(instructions).write(&mut writer)?;
|
||||||
|
} else {
|
||||||
|
instructions.write(&mut writer)?;
|
||||||
|
}
|
||||||
|
|
||||||
writer.flush()?;
|
writer.flush()?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user