simplify emit_debug with gas magic
This commit is contained in:
@@ -77,14 +77,12 @@ pub struct CodegenX86_64<'a> {
|
||||
data_counter: usize,
|
||||
pub symbol_table: &'a SymbolTable,
|
||||
pub expr_types: &'a HashMap<usize, String>,
|
||||
emit_debug: bool,
|
||||
}
|
||||
|
||||
impl<'a> CodegenX86_64<'a> {
|
||||
pub fn new(
|
||||
symbol_table: &'a SymbolTable,
|
||||
expr_types: &'a HashMap<usize, String>,
|
||||
emit_debug: bool,
|
||||
) -> CodegenX86_64<'a> {
|
||||
CodegenX86_64 {
|
||||
output: String::new(),
|
||||
@@ -93,7 +91,6 @@ impl<'a> CodegenX86_64<'a> {
|
||||
data_counter: 1,
|
||||
symbol_table,
|
||||
expr_types,
|
||||
emit_debug,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,10 +369,10 @@ _builtin_environ:
|
||||
exported,
|
||||
} => {
|
||||
let name = &name.lexeme;
|
||||
if self.emit_debug || *exported || name == "main" {
|
||||
if *exported || name == "main" {
|
||||
emit!(&mut self.output, ".globl {0}", name);
|
||||
emit!(&mut self.output, ".type {0}, @function", name);
|
||||
}
|
||||
emit!(&mut self.output, ".type {0}, @function", name);
|
||||
emit!(&mut self.output, ".section .text.{}", name);
|
||||
emit!(&mut self.output, "{}:", name);
|
||||
emit!(&mut self.output, " push rbp");
|
||||
|
||||
@@ -38,8 +38,7 @@ fn compile_file(args: Args) -> Result<(), ZernError> {
|
||||
typechecker.typecheck_stmt(&mut typechecker::Env::new(), stmt)?;
|
||||
}
|
||||
|
||||
let mut codegen =
|
||||
codegen_x86_64::CodegenX86_64::new(&symbol_table, &typechecker.expr_types, args.emit_debug);
|
||||
let mut codegen = codegen_x86_64::CodegenX86_64::new(&symbol_table, &typechecker.expr_types);
|
||||
codegen.emit_prologue(args.use_crt)?;
|
||||
for stmt in statements {
|
||||
codegen.compile_stmt(&mut codegen_x86_64::Env::new(), &stmt)?;
|
||||
@@ -50,7 +49,9 @@ fn compile_file(args: Args) -> Result<(), ZernError> {
|
||||
|
||||
fs::write(format!("{out}.s"), codegen.get_output()).unwrap();
|
||||
|
||||
run_command(format!("as --64 -o {out}.o {out}.s"));
|
||||
let debug_flag = if args.emit_debug { "-g" } else { "" };
|
||||
|
||||
run_command(format!("as --64 {debug_flag} -o {out}.o {out}.s"));
|
||||
|
||||
if args.use_crt {
|
||||
run_command(format!(
|
||||
|
||||
Reference in New Issue
Block a user