Output file and line info.

This commit is contained in:
chriseth
2023-05-22 23:15:12 +02:00
parent 918c67a463
commit 5d9c3fef33

View File

@@ -606,12 +606,22 @@ fn runtime() -> &'static str {
fn process_statement(s: Statement) -> Vec<String> {
match &s {
Statement::Label(l) => vec![format!("{}::", escape_label(l))],
Statement::Directive(directive, args) => match directive.as_str() {
".loc" => {
vec![]
Statement::Directive(directive, args) => match (directive.as_str(), &args[..]) {
(
".loc",
[Argument::Expression(Expression::Number(file)), Argument::Expression(Expression::Number(line)), Argument::Expression(Expression::Number(column)), ..],
) => {
vec![format!("debug loc {file}, {line}, {column};")]
}
".file" => {
vec![]
(
".file",
[Argument::Expression(Expression::Number(file_nr)), Argument::StringLiteral(directory), Argument::StringLiteral(file)],
) => {
vec![format!(
"debug file {file_nr}, {}, {};",
quote(std::str::from_utf8(directory).unwrap()),
quote(std::str::from_utf8(file).unwrap())
)]
}
_ if directive.starts_with(".cfi_") => vec![],
_ => panic!(
@@ -626,6 +636,11 @@ fn process_statement(s: Statement) -> Vec<String> {
}
}
fn quote(s: &str) -> String {
// TODO more things to quote
format!("\"{}\"", s.replace('\\', "\\\\").replace('\"', "\\\""))
}
fn escape_label(l: &str) -> String {
// TODO make this proper
l.replace('.', "_dot_").replace('/', "_slash_")