Parse basic blocks and instructions.

Create map entries for ebbs and values as they are defined, but leave ebb and
value operands unresolved on instructions as they are parsed. Instruction
operands can refer to ebbs and values that may not have been defined yet.

Don't infer or check result types yet.
This commit is contained in:
Jakob Stoklund Olesen
2016-05-17 11:54:46 -07:00
parent 2dc15b78ae
commit 1dcac579fb
4 changed files with 371 additions and 16 deletions

View File

@@ -36,7 +36,7 @@ pub enum Token<'a> {
Integer(&'a str), // Integer immediate
Type(types::Type), // i32, f32, b32x4, ...
ValueDirect(u32), // v12
ValueExtended(u32), // vx7
ValueTable(u32), // vx7
Ebb(u32), // ebb3
StackSlot(u32), // ss3
Identifier(&'a str), // Unrecognized identifier (opcode, enumerator, ...)
@@ -290,7 +290,7 @@ impl<'a> Lexer<'a> {
match prefix {
"v" => Some(Token::ValueDirect(value)),
"vx" => Some(Token::ValueExtended(value)),
"vx" => Some(Token::ValueTable(value)),
"ebb" => Some(Token::Ebb(value)),
"ss" => Some(Token::StackSlot(value)),
_ => None,
@@ -452,7 +452,7 @@ mod tests {
assert_eq!(lex.next(), token(Token::Identifier("ebb5234567890"), 1));
assert_eq!(lex.next(), token(Token::Entry, 1));
assert_eq!(lex.next(), token(Token::Identifier("v1x"), 1));
assert_eq!(lex.next(), token(Token::ValueExtended(1), 1));
assert_eq!(lex.next(), token(Token::ValueTable(1), 1));
assert_eq!(lex.next(), token(Token::Identifier("vxvx4"), 1));
assert_eq!(lex.next(), token(Token::Identifier("function0"), 1));
assert_eq!(lex.next(), token(Token::Function, 1));