Skip to content

Commit

Permalink
[frontent] parse alloca
Browse files Browse the repository at this point in the history
  • Loading branch information
floatshadow committed Mar 2, 2024
1 parent 026e6b7 commit 5565fef
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/frontend/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,28 @@ impl<'a, 'b: 'a> Parser {
)))
}

fn parse_alloca(
input: Tokens<'a>,
builder: Rc<RefCell<IRBuilder>>
) -> IResult<Tokens<'a>, ValueRef> {
let (input,(name, anno_ty)) =
delimited(token(Token::KwLet), parse_symbol, token(Token::Equal))(input)?;

let (input, (base_ty, region_size)) = preceded(
token(Token::TkAlloca),
separated_pair(
parse_type, token(Token::Comma), i64_literal)
)(input)?;

Ok((input, builder.borrow_mut().emit_alloca(
Some(String::from(name)),
base_ty,
usize::try_from(region_size)
.expect("expect non-negative integer literal in alloca region size"),
anno_ty
)))
}

fn parse_instruction(
input: Tokens<'a>,
builder: Rc<RefCell<IRBuilder>>,
Expand Down

0 comments on commit 5565fef

Please sign in to comment.