Skip to content

Commit 62a7c3d

Browse files
authored
Merge pull request #255 from yui-915/debuginfo2
Add variables debuginfo for gas-x86_64-* targets
2 parents 893427d + e08d1e7 commit 62a7c3d

3 files changed

Lines changed: 295 additions & 14 deletions

File tree

src/b.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ pub unsafe fn declare_var(c: *mut Compiler, name: *const c_char, loc: Loc, stora
180180
return bump_error_count(c);
181181
}
182182

183+
if let Storage::Auto {index} = storage {
184+
da_append(&mut (*c).func_scope_events, ScopeEvent::Declare {name, index});
185+
}
186+
183187
da_append(scope, Var {name, loc, storage});
184188
Some(())
185189
}
@@ -286,7 +290,7 @@ impl Binop {
286290
}
287291

288292
pub unsafe fn push_opcode(opcode: Op, loc: Loc, c: *mut Compiler) {
289-
da_append(&mut (*c).func_body, OpWithLocation {opcode, loc});
293+
da_append(&mut (*c).func_body, OpWithLocation {opcode, loc, scope_events_count: (*c).func_scope_events.count });
290294
}
291295

292296
/// Allocator of Auto Vars
@@ -601,14 +605,21 @@ pub unsafe fn compile_expression(l: *mut Lexer, c: *mut Compiler) -> Option<(Arg
601605
}
602606

603607
pub unsafe fn compile_block(l: *mut Lexer, c: *mut Compiler) -> Option<()> {
608+
let index = (*c).func_blocks_count;
609+
(*c).func_blocks_count += 1;
610+
da_append(&mut (*c).func_scope_events, ScopeEvent::BlockBegin {index});
611+
604612
loop {
605613
let saved_point = (*l).parse_point;
606614
lexer::get_token(l)?;
607-
if (*l).token == Token::CCurly { return Some(()); }
615+
if (*l).token == Token::CCurly { break }
608616
(*l).parse_point = saved_point;
609617

610618
compile_statement(l, c)?
611619
}
620+
621+
da_append(&mut (*c).func_scope_events, ScopeEvent::BlockEnd {index});
622+
Some(())
612623
}
613624
unsafe fn compile_function_call(l: *mut Lexer, c: *mut Compiler, fun: Arg) -> Option<Arg> {
614625
let mut args: Array<Arg> = zeroed();
@@ -899,6 +910,8 @@ pub struct Compiler {
899910
pub func_body: Array<OpWithLocation>,
900911
pub func_goto_labels: Array<GotoLabel>,
901912
pub func_gotos: Array<Goto>,
913+
pub func_scope_events: Array<ScopeEvent>,
914+
pub func_blocks_count: usize,
902915
pub used_funcs: Array<UsedFunc>,
903916
pub op_label_count: usize,
904917
pub switch_stack: Array<Switch>,
@@ -1025,12 +1038,15 @@ pub unsafe fn compile_program(l: *mut Lexer, c: *mut Compiler) -> Option<()> {
10251038
name,
10261039
name_loc,
10271040
body: (*c).func_body,
1041+
scope_events: (*c).func_scope_events,
10281042
params_count,
10291043
auto_vars_count: (*c).auto_vars_ator.max,
10301044
});
10311045
(*c).func_body = zeroed();
10321046
(*c).func_goto_labels.count = 0;
10331047
(*c).func_gotos.count = 0;
1048+
(*c).func_scope_events = zeroed();
1049+
(*c).func_blocks_count = 0;
10341050
(*c).auto_vars_ator = zeroed();
10351051
(*c).op_label_count = 0;
10361052
}

0 commit comments

Comments
 (0)