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.
14 * Inline assembly support.
34 fn next_state(s: State) -> Option<State> {
37 Outputs => Some(Inputs),
38 Inputs => Some(Clobbers),
39 Clobbers => Some(Options),
44 pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
46 let p = parse::new_parser_from_tts(cx.parse_sess(),
48 vec::from_slice(tts));
51 let mut outputs = ~[];
54 let mut volatile = false;
55 let mut alignstack = false;
56 let mut dialect = ast::asm_att;
62 asm = expr_to_str(cx, p.parse_expr(),
63 ~"inline assembly must be a string literal.");
66 while *p.token != token::EOF &&
67 *p.token != token::COLON &&
68 *p.token != token::MOD_SEP {
70 if outputs.len() != 0 {
74 let constraint = p.parse_str();
75 p.expect(&token::LPAREN);
76 let out = p.parse_expr();
77 p.expect(&token::RPAREN);
79 let out = @ast::expr {
81 callee_id: cx.next_id(),
83 node: ast::expr_addr_of(ast::m_mutbl, out)
86 outputs.push((constraint, out));
90 while *p.token != token::EOF &&
91 *p.token != token::COLON &&
92 *p.token != token::MOD_SEP {
94 if inputs.len() != 0 {
98 let constraint = p.parse_str();
99 p.expect(&token::LPAREN);
100 let in = p.parse_expr();
101 p.expect(&token::RPAREN);
103 inputs.push((constraint, in));
108 while *p.token != token::EOF &&
109 *p.token != token::COLON &&
110 *p.token != token::MOD_SEP {
112 if clobs.len() != 0 {
113 p.eat(&token::COMMA);
116 let clob = ~"~{" + *p.parse_str() + ~"}";
120 cons = str::connect(clobs, ",");
123 let option = *p.parse_str();
125 if option == ~"volatile" {
127 } else if option == ~"alignstack" {
129 } else if option == ~"intel" {
130 dialect = ast::asm_intel;
133 if *p.token == token::COMMA {
134 p.eat(&token::COMMA);
139 while *p.token == token::COLON ||
140 *p.token == token::MOD_SEP ||
141 *p.token == token::EOF {
142 state = if *p.token == token::COLON {
144 match next_state(state) {
148 } else if *p.token == token::MOD_SEP {
150 let s = match next_state(state) {
154 match next_state(s) {
158 } else if *p.token == token::EOF {
168 callee_id: cx.next_id(),
169 node: ast::expr_inline_asm(ast::inline_asm {
175 alignstack: alignstack,
188 // indent-tabs-mode: nil
190 // buffer-file-coding-system: utf-8-unix