From ecccc0d649088720a8c4af86e1722b9a26ca31dc Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Sat, 9 Mar 2013 22:37:50 -0800 Subject: Parse inline assembly. --- src/libsyntax/ast.rs | 2 ++ src/libsyntax/fold.rs | 1 + src/libsyntax/parse/parser.rs | 10 +++++++++- src/libsyntax/parse/token.rs | 1 + src/libsyntax/print/pprust.rs | 8 ++++++++ src/libsyntax/visit.rs | 1 + 6 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 27dba9c2b5e..b7c30360613 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -600,6 +600,8 @@ pub enum expr_ { expr_again(Option), expr_ret(Option<@expr>), expr_log(log_level, @expr, @expr), + + expr_inline_asm(@~str /* asm */, @~str /* constraints */), expr_mac(mac), diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 427760c920f..15097f57b02 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -560,6 +560,7 @@ pub fn noop_fold_expr(e: &expr_, fld: @ast_fold) -> expr_ { fld.fold_expr(e) ) } + expr_inline_asm(*) => copy *e, expr_mac(ref mac) => expr_mac(fold_mac((*mac))), expr_struct(path, ref fields, maybe_expr) => { expr_struct( diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 99c1c2cb1fe..6076ad0ce0e 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -27,7 +27,7 @@ use ast::{expr_field, expr_fn_block, expr_if, expr_index}; use ast::{expr_lit, expr_log, expr_loop, expr_loop_body, expr_mac}; use ast::{expr_method_call, expr_paren, expr_path, expr_repeat}; use ast::{expr_ret, expr_swap, expr_struct, expr_tup, expr_unary}; -use ast::{expr_vec, expr_vstore, expr_vstore_mut_box}; +use ast::{expr_vec, expr_vstore, expr_vstore_mut_box, expr_inline_asm}; use ast::{expr_vstore_fixed, expr_vstore_slice, expr_vstore_box}; use ast::{expr_vstore_mut_slice, expr_while, extern_fn, field, fn_decl}; use ast::{expr_vstore_uniq, TyClosure, TyBareFn, Onceness, Once, Many}; @@ -1184,6 +1184,14 @@ pub impl Parser { } } hi = self.span.hi; + } else if self.eat_keyword(&~"__asm__") { + self.expect(&token::LPAREN); + let asm = self.parse_str(); + self.expect(&token::COMMA); + let cons = self.parse_str(); + ex = expr_inline_asm(asm, cons); + hi = self.span.hi; + self.expect(&token::RPAREN); } else if self.eat_keyword(&~"log") { self.expect(&token::LPAREN); let lvl = self.parse_expr(); diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 81aacbf173d..5cfe0bef9b8 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -488,6 +488,7 @@ pub fn temporary_keyword_table() -> HashMap<~str, ()> { pub fn strict_keyword_table() -> HashMap<~str, ()> { let words = HashMap(); let keys = ~[ + ~"__asm__", ~"as", ~"assert", ~"break", ~"const", ~"copy", diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 62f593f15c1..350ab0cf9b2 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1398,6 +1398,14 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) { } } } + ast::expr_inline_asm(a, c) => { + word(s.s, ~"__asm__"); + popen(s); + print_string(s, *a); + word_space(s, ~", "); + print_string(s, *c); + pclose(s); + } ast::expr_mac(ref m) => print_mac(s, (*m)), ast::expr_paren(e) => { popen(s); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index f04894729bd..95ab603f584 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -562,6 +562,7 @@ pub fn visit_expr(ex: @expr, e: E, v: vt) { } expr_mac(ref mac) => visit_mac((*mac), e, v), expr_paren(x) => (v.visit_expr)(x, e, v), + expr_inline_asm(*) => (), } (v.visit_expr_post)(ex, e, v); } -- cgit 1.4.1-3-g733a5