Update parser

This commit is contained in:
bjorn3
2021-10-10 15:23:39 +02:00
parent 20463d60f3
commit a894594ae5
2 changed files with 10 additions and 18 deletions

View File

@@ -251,7 +251,7 @@ impl Context {
self.map.def_ss(ss, loc)?; self.map.def_ss(ss, loc)?;
while self.function.stack_slots.next_key().index() <= ss.index() { while self.function.stack_slots.next_key().index() <= ss.index() {
self.function self.function
.create_stack_slot(StackSlotData::new(StackSlotKind::SpillSlot, 0)); .create_stack_slot(StackSlotData::new(StackSlotKind::ExplicitSlot, 0));
} }
self.function.stack_slots[ss] = data; self.function.stack_slots[ss] = data;
Ok(()) Ok(())
@@ -1431,15 +1431,7 @@ impl<'a> Parser<'a> {
if bytes > i64::from(u32::MAX) { if bytes > i64::from(u32::MAX) {
return err!(self.loc, "stack slot too large"); return err!(self.loc, "stack slot too large");
} }
let mut data = StackSlotData::new(kind, bytes as u32); let data = StackSlotData::new(kind, bytes as u32);
// Take additional options.
while self.optional(Token::Comma) {
match self.match_any_identifier("expected stack slot flags")? {
"offset" => data.offset = Some(self.match_imm32("expected byte offset")?),
other => return err!(self.loc, "Unknown stack slot flag '{}'", other),
}
}
// Collect any trailing comments. // Collect any trailing comments.
self.token(); self.token();
@@ -3122,8 +3114,8 @@ mod tests {
fn stack_slot_decl() { fn stack_slot_decl() {
let (func, _) = Parser::new( let (func, _) = Parser::new(
"function %foo() system_v { "function %foo() system_v {
ss3 = incoming_arg 13 ss3 = explicit_slot 13
ss1 = spill_slot 1 ss1 = explicit_slot 1
}", }",
) )
.parse_function() .parse_function()
@@ -3133,12 +3125,12 @@ mod tests {
let _ss0 = iter.next().unwrap(); let _ss0 = iter.next().unwrap();
let ss1 = iter.next().unwrap(); let ss1 = iter.next().unwrap();
assert_eq!(ss1.to_string(), "ss1"); assert_eq!(ss1.to_string(), "ss1");
assert_eq!(func.stack_slots[ss1].kind, StackSlotKind::SpillSlot); assert_eq!(func.stack_slots[ss1].kind, StackSlotKind::ExplicitSlot);
assert_eq!(func.stack_slots[ss1].size, 1); assert_eq!(func.stack_slots[ss1].size, 1);
let _ss2 = iter.next().unwrap(); let _ss2 = iter.next().unwrap();
let ss3 = iter.next().unwrap(); let ss3 = iter.next().unwrap();
assert_eq!(ss3.to_string(), "ss3"); assert_eq!(ss3.to_string(), "ss3");
assert_eq!(func.stack_slots[ss3].kind, StackSlotKind::IncomingArg); assert_eq!(func.stack_slots[ss3].kind, StackSlotKind::ExplicitSlot);
assert_eq!(func.stack_slots[ss3].size, 13); assert_eq!(func.stack_slots[ss3].size, 13);
assert_eq!(iter.next(), None); assert_eq!(iter.next(), None);
@@ -3146,8 +3138,8 @@ mod tests {
assert_eq!( assert_eq!(
Parser::new( Parser::new(
"function %bar() system_v { "function %bar() system_v {
ss1 = spill_slot 13 ss1 = explicit_slot 13
ss1 = spill_slot 1 ss1 = explicit_slot 1
}", }",
) )
.parse_function() .parse_function()
@@ -3338,7 +3330,7 @@ mod tests {
let (func, Details { comments, .. }) = Parser::new( let (func, Details { comments, .. }) = Parser::new(
"; before "; before
function %comment() system_v { ; decl function %comment() system_v { ; decl
ss10 = outgoing_arg 13 ; stackslot. ss10 = explicit_slot 13 ; stackslot.
; Still stackslot. ; Still stackslot.
jt10 = jump_table [block0] jt10 = jump_table [block0]
; Jumptable ; Jumptable

View File

@@ -227,7 +227,7 @@ mod tests {
fn details() { fn details() {
let tf = parse_test( let tf = parse_test(
"function %detail() { "function %detail() {
ss10 = incoming_arg 13 ss10 = explicit_slot 13
jt10 = jump_table [block0] jt10 = jump_table [block0]
block0(v4: i32, v7: i32): block0(v4: i32, v7: i32):
v10 = iadd v4, v7 v10 = iadd v4, v7