Move entry_block() into Layout.

The single entry block in a function is simply the first block in the layout.

Remove the 'entry' keyword from the textual IL, the lexer and parser.
This commit is contained in:
Jakob Stoklund Olesen
2016-07-22 10:06:51 -07:00
parent 38815dcca3
commit f116f03327
8 changed files with 29 additions and 37 deletions

View File

@@ -32,7 +32,6 @@ pub enum Token<'a> {
Equal, // '='
Arrow, // '->'
Function, // 'function'
Entry, // 'entry'
Float(&'a str), // Floating point immediate
Integer(&'a str), // Integer immediate
Type(types::Type), // i32, f32, b32x4, ...
@@ -270,7 +269,6 @@ impl<'a> Lexer<'a> {
fn keyword(text: &str) -> Option<Token<'a>> {
match text {
"function" => Some(Token::Function),
"entry" => Some(Token::Entry),
_ => None,
}
}
@@ -444,7 +442,7 @@ mod tests {
#[test]
fn lex_identifiers() {
let mut lex = Lexer::new("v0 v00 vx01 ebb1234567890 ebb5234567890 entry v1x vx1 vxvx4 \
let mut lex = Lexer::new("v0 v00 vx01 ebb1234567890 ebb5234567890 v1x vx1 vxvx4 \
function0 function b1 i32x4 f32x5");
assert_eq!(lex.next(),
token(Token::Value(Value::direct_with_number(0).unwrap()), 1));
@@ -453,7 +451,6 @@ mod tests {
assert_eq!(lex.next(),
token(Token::Ebb(Ebb::with_number(1234567890).unwrap()), 1));
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::Value(Value::table_with_number(1).unwrap()), 1));

View File

@@ -15,7 +15,7 @@ use cretonne::ir::types::{Type, VOID, FunctionName, Signature, ArgumentType, Arg
use cretonne::ir::immediates::{Imm64, Ieee32, Ieee64};
use cretonne::ir::entities::*;
use cretonne::ir::instructions::{Opcode, InstructionFormat, InstructionData, VariableArgs,
JumpData, BranchData, ReturnData};
JumpData, BranchData, ReturnData};
use cretonne::ir::{Function, StackSlotData};
pub use lexer::Location;
@@ -578,22 +578,14 @@ impl<'a> Parser<'a> {
// Parse an extended basic block, add contents to `ctx`.
//
// extended-basic-block ::= * ebb-header { instruction }
// ebb-header ::= ["entry"] Ebb(ebb) [ebb-args] ":"
// ebb-header ::= Ebb(ebb) [ebb-args] ":"
//
fn parse_extended_basic_block(&mut self, ctx: &mut Context) -> Result<()> {
let is_entry = self.optional(Token::Entry);
let ebb_num = try!(self.match_ebb("expected EBB header"));
let ebb = try!(ctx.add_ebb(ebb_num, &self.loc));
if is_entry {
if ctx.function.entry_block != NO_EBB {
return err!(self.loc, "multiple entry blocks in function");
}
ctx.function.entry_block = ebb;
}
if !self.optional(Token::Colon) {
// ebb-header ::= ["entry"] Ebb(ebb) [ * ebb-args ] ":"
// ebb-header ::= Ebb(ebb) [ * ebb-args ] ":"
try!(self.parse_ebb_args(ctx, ebb));
try!(self.match_token(Token::Colon, "expected ':' after EBB arguments"));
}