1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 * Inline assembly support.
30 fn next_state(s: State) -> Option<State> {
33 Outputs => Some(Inputs),
34 Inputs => Some(Clobbers),
35 Clobbers => Some(Options),
40 pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
42 let p = parse::new_parser_from_tts(cx.parse_sess(),
44 vec::from_slice(tts));
47 let mut outputs = ~[];
50 let mut volatile = false;
51 let mut alignstack = false;
52 let mut dialect = ast::asm_att;
56 // Not using labeled break to get us through one round of bootstrapping.
57 let mut continue = true;
61 asm = expr_to_str(cx, p.parse_expr(),
62 ~"inline assembly must be a string literal.");
65 while *p.token != token::EOF &&
66 *p.token != token::COLON &&
67 *p.token != token::MOD_SEP {
69 if outputs.len() != 0 {
73 let constraint = p.parse_str();
74 p.expect(&token::LPAREN);
75 let out = p.parse_expr();
76 p.expect(&token::RPAREN);
78 let out = @ast::expr {
80 callee_id: cx.next_id(),
82 node: ast::expr_addr_of(ast::m_mutbl, out)
85 outputs.push((constraint, out));
89 while *p.token != token::EOF &&
90 *p.token != token::COLON &&
91 *p.token != token::MOD_SEP {
93 if inputs.len() != 0 {
97 let constraint = p.parse_str();
98 p.expect(&token::LPAREN);
99 let in = p.parse_expr();
100 p.expect(&token::RPAREN);
102 inputs.push((constraint, in));
107 while *p.token != token::EOF &&
108 *p.token != token::COLON &&
109 *p.token != token::MOD_SEP {
111 if clobs.len() != 0 {
112 p.eat(&token::COMMA);
115 let clob = ~"~{" + *p.parse_str() + ~"}";
119 cons = str::connect(clobs, ",");
122 let option = *p.parse_str();
124 if option == ~"volatile" {
126 } else if option == ~"alignstack" {
128 } else if option == ~"intel" {
129 dialect = ast::asm_intel;
132 if *p.token == token::COMMA {
133 p.eat(&token::COMMA);
138 while *p.token == token::COLON ||
139 *p.token == token::MOD_SEP ||
140 *p.token == token::EOF {
141 state = if *p.token == token::COLON {
143 match next_state(state) {
150 } else if *p.token == token::MOD_SEP {
152 let s = match next_state(state) {
159 match next_state(s) {
166 } else if *p.token == token::EOF {
177 callee_id: cx.next_id(),
178 node: ast::expr_inline_asm(ast::inline_asm {
184 alignstack: alignstack,