mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Move InlineAsmTemplatePiece and InlineAsmOptions to librustc_ast
This commit is contained in:
parent
330bdf89b1
commit
a656349b55
@ -3625,13 +3625,13 @@ dependencies = [
|
||||
name = "rustc_ast"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"log",
|
||||
"rustc_data_structures",
|
||||
"rustc_index",
|
||||
"rustc_lexer",
|
||||
"rustc_macros",
|
||||
"rustc_span",
|
||||
"rustc_target",
|
||||
"scoped-tls",
|
||||
"serialize",
|
||||
"smallvec 1.4.0",
|
||||
|
@ -19,4 +19,4 @@ rustc_index = { path = "../librustc_index" }
|
||||
rustc_lexer = { path = "../librustc_lexer" }
|
||||
rustc_macros = { path = "../librustc_macros" }
|
||||
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
|
||||
rustc_target = { path = "../librustc_target" }
|
||||
bitflags = "1.2.1"
|
||||
|
@ -34,7 +34,6 @@ use rustc_serialize::{self, Decoder, Encoder};
|
||||
use rustc_span::source_map::{respan, Spanned};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_target::asm::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt;
|
||||
@ -1876,6 +1875,60 @@ pub enum InlineAsmRegOrRegClass {
|
||||
RegClass(Symbol),
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
#[derive(RustcEncodable, RustcDecodable, HashStable_Generic)]
|
||||
pub struct InlineAsmOptions: u8 {
|
||||
const PURE = 1 << 0;
|
||||
const NOMEM = 1 << 1;
|
||||
const READONLY = 1 << 2;
|
||||
const PRESERVES_FLAGS = 1 << 3;
|
||||
const NORETURN = 1 << 4;
|
||||
const NOSTACK = 1 << 5;
|
||||
const ATT_SYNTAX = 1 << 6;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
|
||||
pub enum InlineAsmTemplatePiece {
|
||||
String(String),
|
||||
Placeholder { operand_idx: usize, modifier: Option<char>, span: Span },
|
||||
}
|
||||
|
||||
impl fmt::Display for InlineAsmTemplatePiece {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::String(s) => {
|
||||
for c in s.chars() {
|
||||
match c {
|
||||
'{' => f.write_str("{{")?,
|
||||
'}' => f.write_str("}}")?,
|
||||
_ => write!(f, "{}", c.escape_debug())?,
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Self::Placeholder { operand_idx, modifier: Some(modifier), .. } => {
|
||||
write!(f, "{{{}:{}}}", operand_idx, modifier)
|
||||
}
|
||||
Self::Placeholder { operand_idx, modifier: None, .. } => {
|
||||
write!(f, "{{{}}}", operand_idx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl InlineAsmTemplatePiece {
|
||||
/// Rebuilds the asm template string from its pieces.
|
||||
pub fn to_string(s: &[Self]) -> String {
|
||||
use fmt::Write;
|
||||
let mut out = String::new();
|
||||
for p in s.iter() {
|
||||
let _ = write!(out, "{}", p);
|
||||
}
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
/// Inline assembly operand.
|
||||
///
|
||||
/// E.g., `out("eax") result` as in `asm!("mov eax, 2", out("eax") result)`.
|
||||
|
@ -980,7 +980,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
struct_span_err!(self.sess, sp, E0472, "asm! is unsupported on this target").emit();
|
||||
return hir::ExprKind::Err;
|
||||
};
|
||||
if asm.options.contains(asm::InlineAsmOptions::ATT_SYNTAX) {
|
||||
if asm.options.contains(InlineAsmOptions::ATT_SYNTAX) {
|
||||
match asm_arch {
|
||||
asm::InlineAsmArch::X86 | asm::InlineAsmArch::X86_64 => {}
|
||||
_ => self
|
||||
@ -1070,7 +1070,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
|
||||
// Validate template modifiers against the register classes for the operands
|
||||
for p in &asm.template {
|
||||
if let asm::InlineAsmTemplatePiece::Placeholder {
|
||||
if let InlineAsmTemplatePiece::Placeholder {
|
||||
operand_idx,
|
||||
modifier: Some(modifier),
|
||||
span: placeholder_span,
|
||||
|
@ -5,6 +5,7 @@ use rustc_ast::ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
|
||||
use rustc_ast::ast::{Attribute, GenericArg, MacArgs};
|
||||
use rustc_ast::ast::{GenericBound, SelfKind, TraitBoundModifier};
|
||||
use rustc_ast::ast::{InlineAsmOperand, InlineAsmRegOrRegClass};
|
||||
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
use rustc_ast::attr;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, BinOpToken, DelimToken, Nonterminal, Token, TokenKind};
|
||||
@ -15,7 +16,6 @@ use rustc_span::edition::Edition;
|
||||
use rustc_span::source_map::{SourceMap, Spanned};
|
||||
use rustc_span::symbol::{kw, sym, Ident, IdentPrinter, Symbol};
|
||||
use rustc_span::{BytePos, FileName, Span};
|
||||
use rustc_target::asm::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
|
@ -10,14 +10,13 @@ use rustc_expand::base::{self, *};
|
||||
use rustc_parse::parser::Parser;
|
||||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
use rustc_span::{InnerSpan, Span};
|
||||
use rustc_target::asm::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
|
||||
struct AsmArgs {
|
||||
template: P<ast::Expr>,
|
||||
operands: Vec<(ast::InlineAsmOperand, Span)>,
|
||||
named_args: FxHashMap<Symbol, usize>,
|
||||
reg_args: FxHashSet<usize>,
|
||||
options: InlineAsmOptions,
|
||||
options: ast::InlineAsmOptions,
|
||||
options_span: Option<Span>,
|
||||
}
|
||||
|
||||
@ -57,7 +56,7 @@ fn parse_args<'a>(
|
||||
operands: vec![],
|
||||
named_args: FxHashMap::default(),
|
||||
reg_args: FxHashSet::default(),
|
||||
options: InlineAsmOptions::empty(),
|
||||
options: ast::InlineAsmOptions::empty(),
|
||||
options_span: None,
|
||||
};
|
||||
|
||||
@ -204,22 +203,22 @@ fn parse_args<'a>(
|
||||
}
|
||||
}
|
||||
|
||||
if args.options.contains(InlineAsmOptions::NOMEM)
|
||||
&& args.options.contains(InlineAsmOptions::READONLY)
|
||||
if args.options.contains(ast::InlineAsmOptions::NOMEM)
|
||||
&& args.options.contains(ast::InlineAsmOptions::READONLY)
|
||||
{
|
||||
let span = args.options_span.unwrap();
|
||||
ecx.struct_span_err(span, "the `nomem` and `readonly` options are mutually exclusive")
|
||||
.emit();
|
||||
}
|
||||
if args.options.contains(InlineAsmOptions::PURE)
|
||||
&& args.options.contains(InlineAsmOptions::NORETURN)
|
||||
if args.options.contains(ast::InlineAsmOptions::PURE)
|
||||
&& args.options.contains(ast::InlineAsmOptions::NORETURN)
|
||||
{
|
||||
let span = args.options_span.unwrap();
|
||||
ecx.struct_span_err(span, "the `pure` and `noreturn` options are mutually exclusive")
|
||||
.emit();
|
||||
}
|
||||
if args.options.contains(InlineAsmOptions::PURE)
|
||||
&& !args.options.intersects(InlineAsmOptions::NOMEM | InlineAsmOptions::READONLY)
|
||||
if args.options.contains(ast::InlineAsmOptions::PURE)
|
||||
&& !args.options.intersects(ast::InlineAsmOptions::NOMEM | ast::InlineAsmOptions::READONLY)
|
||||
{
|
||||
let span = args.options_span.unwrap();
|
||||
ecx.struct_span_err(
|
||||
@ -245,14 +244,14 @@ fn parse_args<'a>(
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if args.options.contains(InlineAsmOptions::PURE) && !have_real_output {
|
||||
if args.options.contains(ast::InlineAsmOptions::PURE) && !have_real_output {
|
||||
ecx.struct_span_err(
|
||||
args.options_span.unwrap(),
|
||||
"asm with `pure` option must have at least one output",
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
if args.options.contains(InlineAsmOptions::NORETURN) && !outputs_sp.is_empty() {
|
||||
if args.options.contains(ast::InlineAsmOptions::NORETURN) && !outputs_sp.is_empty() {
|
||||
let err = ecx
|
||||
.struct_span_err(outputs_sp, "asm outputs are not allowed with the `noreturn` option");
|
||||
|
||||
@ -270,20 +269,20 @@ fn parse_options<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> Result<(), Diagn
|
||||
|
||||
while !p.eat(&token::CloseDelim(token::DelimToken::Paren)) {
|
||||
if p.eat(&token::Ident(sym::pure, false)) {
|
||||
args.options |= InlineAsmOptions::PURE;
|
||||
args.options |= ast::InlineAsmOptions::PURE;
|
||||
} else if p.eat(&token::Ident(sym::nomem, false)) {
|
||||
args.options |= InlineAsmOptions::NOMEM;
|
||||
args.options |= ast::InlineAsmOptions::NOMEM;
|
||||
} else if p.eat(&token::Ident(sym::readonly, false)) {
|
||||
args.options |= InlineAsmOptions::READONLY;
|
||||
args.options |= ast::InlineAsmOptions::READONLY;
|
||||
} else if p.eat(&token::Ident(sym::preserves_flags, false)) {
|
||||
args.options |= InlineAsmOptions::PRESERVES_FLAGS;
|
||||
args.options |= ast::InlineAsmOptions::PRESERVES_FLAGS;
|
||||
} else if p.eat(&token::Ident(sym::noreturn, false)) {
|
||||
args.options |= InlineAsmOptions::NORETURN;
|
||||
args.options |= ast::InlineAsmOptions::NORETURN;
|
||||
} else if p.eat(&token::Ident(sym::nostack, false)) {
|
||||
args.options |= InlineAsmOptions::NOSTACK;
|
||||
args.options |= ast::InlineAsmOptions::NOSTACK;
|
||||
} else {
|
||||
p.expect(&token::Ident(sym::att_syntax, false))?;
|
||||
args.options |= InlineAsmOptions::ATT_SYNTAX;
|
||||
args.options |= ast::InlineAsmOptions::ATT_SYNTAX;
|
||||
}
|
||||
|
||||
// Allow trailing commas
|
||||
@ -395,7 +394,9 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
|
||||
let mut template = vec![];
|
||||
for piece in unverified_pieces {
|
||||
match piece {
|
||||
parse::Piece::String(s) => template.push(InlineAsmTemplatePiece::String(s.to_string())),
|
||||
parse::Piece::String(s) => {
|
||||
template.push(ast::InlineAsmTemplatePiece::String(s.to_string()))
|
||||
}
|
||||
parse::Piece::NextArgument(arg) => {
|
||||
let span = arg_spans.next().unwrap_or(template_sp);
|
||||
|
||||
@ -467,7 +468,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
|
||||
|
||||
if let Some(operand_idx) = operand_idx {
|
||||
used[operand_idx] = true;
|
||||
template.push(InlineAsmTemplatePiece::Placeholder {
|
||||
template.push(ast::InlineAsmTemplatePiece::Placeholder {
|
||||
operand_idx,
|
||||
modifier,
|
||||
span,
|
||||
|
@ -6,6 +6,7 @@ use crate::type_of::LayoutLlvmExt;
|
||||
use crate::value::Value;
|
||||
|
||||
use rustc_ast::ast::LlvmAsmDialect;
|
||||
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
use rustc_codegen_ssa::mir::operand::OperandValue;
|
||||
use rustc_codegen_ssa::mir::place::PlaceRef;
|
||||
use rustc_codegen_ssa::traits::*;
|
||||
|
@ -1,11 +1,12 @@
|
||||
use super::BackendTypes;
|
||||
use crate::mir::operand::OperandRef;
|
||||
use crate::mir::place::PlaceRef;
|
||||
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{GlobalAsm, LlvmInlineAsmInner};
|
||||
use rustc_middle::ty::Instance;
|
||||
use rustc_span::Span;
|
||||
use rustc_target::asm::{InlineAsmOptions, InlineAsmRegOrRegClass, InlineAsmTemplatePiece};
|
||||
use rustc_target::asm::InlineAsmRegOrRegClass;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum InlineAsmOperandRef<'tcx, B: BackendTypes + ?Sized> {
|
||||
|
@ -15,7 +15,7 @@ macro_rules! arena_types {
|
||||
[few] hir_krate: rustc_hir::Crate<$tcx>,
|
||||
[] arm: rustc_hir::Arm<$tcx>,
|
||||
[] asm_operand: rustc_hir::InlineAsmOperand<$tcx>,
|
||||
[] asm_template: rustc_target::asm::InlineAsmTemplatePiece,
|
||||
[] asm_template: rustc_ast::ast::InlineAsmTemplatePiece,
|
||||
[] attribute: rustc_ast::ast::Attribute,
|
||||
[] block: rustc_hir::Block<$tcx>,
|
||||
[] bare_fn_ty: rustc_hir::BareFnTy<$tcx>,
|
||||
|
@ -7,6 +7,7 @@ use rustc_ast::ast::{self, CrateSugar, LlvmAsmDialect};
|
||||
use rustc_ast::ast::{AttrVec, Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, UintTy};
|
||||
pub use rustc_ast::ast::{BorrowKind, ImplPolarity, IsAuto};
|
||||
pub use rustc_ast::ast::{CaptureBy, Movability, Mutability};
|
||||
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
use rustc_ast::node_id::NodeMap;
|
||||
use rustc_ast::util::parser::ExprPrecedence;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
@ -15,7 +16,7 @@ use rustc_macros::HashStable_Generic;
|
||||
use rustc_span::source_map::{SourceMap, Spanned};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{MultiSpan, Span, DUMMY_SP};
|
||||
use rustc_target::asm::{InlineAsmOptions, InlineAsmRegOrRegClass, InlineAsmTemplatePiece};
|
||||
use rustc_target::asm::InlineAsmRegOrRegClass;
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
use smallvec::SmallVec;
|
||||
|
@ -12,7 +12,6 @@ use rustc_hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier};
|
||||
use rustc_span::source_map::{SourceMap, Spanned};
|
||||
use rustc_span::symbol::{kw, Ident, IdentPrinter, Symbol};
|
||||
use rustc_span::{self, BytePos, FileName};
|
||||
use rustc_target::asm::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
use std::borrow::Cow;
|
||||
@ -1414,11 +1413,11 @@ impl<'a> State<'a> {
|
||||
enum AsmArg<'a> {
|
||||
Template(String),
|
||||
Operand(&'a hir::InlineAsmOperand<'a>),
|
||||
Options(InlineAsmOptions),
|
||||
Options(ast::InlineAsmOptions),
|
||||
}
|
||||
|
||||
let mut args = vec![];
|
||||
args.push(AsmArg::Template(InlineAsmTemplatePiece::to_string(&a.template)));
|
||||
args.push(AsmArg::Template(ast::InlineAsmTemplatePiece::to_string(&a.template)));
|
||||
args.extend(a.operands.iter().map(|o| AsmArg::Operand(o)));
|
||||
if !a.options.is_empty() {
|
||||
args.push(AsmArg::Options(a.options));
|
||||
@ -1485,25 +1484,25 @@ impl<'a> State<'a> {
|
||||
s.word("options");
|
||||
s.popen();
|
||||
let mut options = vec![];
|
||||
if opts.contains(InlineAsmOptions::PURE) {
|
||||
if opts.contains(ast::InlineAsmOptions::PURE) {
|
||||
options.push("pure");
|
||||
}
|
||||
if opts.contains(InlineAsmOptions::NOMEM) {
|
||||
if opts.contains(ast::InlineAsmOptions::NOMEM) {
|
||||
options.push("nomem");
|
||||
}
|
||||
if opts.contains(InlineAsmOptions::READONLY) {
|
||||
if opts.contains(ast::InlineAsmOptions::READONLY) {
|
||||
options.push("readonly");
|
||||
}
|
||||
if opts.contains(InlineAsmOptions::PRESERVES_FLAGS) {
|
||||
if opts.contains(ast::InlineAsmOptions::PRESERVES_FLAGS) {
|
||||
options.push("preserves_flags");
|
||||
}
|
||||
if opts.contains(InlineAsmOptions::NORETURN) {
|
||||
if opts.contains(ast::InlineAsmOptions::NORETURN) {
|
||||
options.push("noreturn");
|
||||
}
|
||||
if opts.contains(InlineAsmOptions::NOSTACK) {
|
||||
if opts.contains(ast::InlineAsmOptions::NOSTACK) {
|
||||
options.push("nostack");
|
||||
}
|
||||
if opts.contains(InlineAsmOptions::ATT_SYNTAX) {
|
||||
if opts.contains(ast::InlineAsmOptions::ATT_SYNTAX) {
|
||||
options.push("att_syntax");
|
||||
}
|
||||
s.commasep(Inconsistent, &options, |s, &opt| {
|
||||
|
@ -19,6 +19,7 @@ use rustc_target::abi::VariantIdx;
|
||||
|
||||
use polonius_engine::Atom;
|
||||
pub use rustc_ast::ast::Mutability;
|
||||
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_data_structures::graph::dominators::{dominators, Dominators};
|
||||
use rustc_data_structures::graph::{self, GraphSuccessors};
|
||||
@ -28,7 +29,7 @@ use rustc_macros::HashStable;
|
||||
use rustc_serialize::{Decodable, Encodable};
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_target::asm::{InlineAsmOptions, InlineAsmRegOrRegClass, InlineAsmTemplatePiece};
|
||||
use rustc_target::asm::InlineAsmRegOrRegClass;
|
||||
use std::borrow::Cow;
|
||||
use std::fmt::{self, Debug, Display, Formatter, Write};
|
||||
use std::ops::{Index, IndexMut};
|
||||
|
@ -259,6 +259,8 @@ CloneTypeFoldableAndLiftImpls! {
|
||||
String,
|
||||
crate::middle::region::Scope,
|
||||
::rustc_ast::ast::FloatTy,
|
||||
::rustc_ast::ast::InlineAsmOptions,
|
||||
::rustc_ast::ast::InlineAsmTemplatePiece,
|
||||
::rustc_ast::ast::NodeId,
|
||||
::rustc_span::symbol::Symbol,
|
||||
::rustc_hir::def::Res,
|
||||
@ -267,9 +269,7 @@ CloneTypeFoldableAndLiftImpls! {
|
||||
::rustc_hir::MatchSource,
|
||||
::rustc_hir::Mutability,
|
||||
::rustc_hir::Unsafety,
|
||||
::rustc_target::asm::InlineAsmOptions,
|
||||
::rustc_target::asm::InlineAsmRegOrRegClass,
|
||||
::rustc_target::asm::InlineAsmTemplatePiece,
|
||||
::rustc_target::spec::abi::Abi,
|
||||
crate::mir::Local,
|
||||
crate::mir::Promoted,
|
||||
|
@ -3,12 +3,12 @@
|
||||
use crate::build::expr::category::{Category, RvalueFunc};
|
||||
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
|
||||
use crate::hair::*;
|
||||
use rustc_ast::ast::InlineAsmOptions;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation};
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_target::asm::InlineAsmOptions;
|
||||
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
//! structures.
|
||||
|
||||
use self::cx::Cx;
|
||||
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::infer::canonical::Canonical;
|
||||
@ -15,7 +16,7 @@ use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::{AdtDef, Const, Ty, UpvarSubsts, UserType};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::VariantIdx;
|
||||
use rustc_target::asm::{InlineAsmOptions, InlineAsmRegOrRegClass, InlineAsmTemplatePiece};
|
||||
use rustc_target::asm::InlineAsmRegOrRegClass;
|
||||
|
||||
crate mod constant;
|
||||
crate mod cx;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use rustc_ast::ast::{FloatTy, IntTy, UintTy};
|
||||
use rustc_ast::ast::{FloatTy, InlineAsmTemplatePiece, IntTy, UintTy};
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
@ -11,7 +11,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_session::lint;
|
||||
use rustc_span::{sym, Span, Symbol, DUMMY_SP};
|
||||
use rustc_target::abi::{Pointer, VariantIdx};
|
||||
use rustc_target::asm::{InlineAsmRegOrRegClass, InlineAsmTemplatePiece, InlineAsmType};
|
||||
use rustc_target::asm::{InlineAsmRegOrRegClass, InlineAsmType};
|
||||
use rustc_target::spec::abi::Abi::RustIntrinsic;
|
||||
|
||||
fn check_mod_intrinsics(tcx: TyCtxt<'_>, module_def_id: DefId) {
|
||||
|
@ -96,6 +96,7 @@
|
||||
use self::LiveNodeKind::*;
|
||||
use self::VarKind::*;
|
||||
|
||||
use rustc_ast::ast::InlineAsmOptions;
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir as hir;
|
||||
@ -109,7 +110,6 @@ use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_session::lint;
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::asm::InlineAsmOptions;
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::fmt;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::abi::Size;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_macros::HashStable_Generic;
|
||||
use rustc_span::{Span, Symbol};
|
||||
use rustc_span::Symbol;
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
|
||||
@ -417,60 +417,6 @@ impl fmt::Display for InlineAsmRegOrRegClass {
|
||||
}
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
#[derive(RustcEncodable, RustcDecodable, HashStable_Generic)]
|
||||
pub struct InlineAsmOptions: u8 {
|
||||
const PURE = 1 << 0;
|
||||
const NOMEM = 1 << 1;
|
||||
const READONLY = 1 << 2;
|
||||
const PRESERVES_FLAGS = 1 << 3;
|
||||
const NORETURN = 1 << 4;
|
||||
const NOSTACK = 1 << 5;
|
||||
const ATT_SYNTAX = 1 << 6;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
|
||||
pub enum InlineAsmTemplatePiece {
|
||||
String(String),
|
||||
Placeholder { operand_idx: usize, modifier: Option<char>, span: Span },
|
||||
}
|
||||
|
||||
impl fmt::Display for InlineAsmTemplatePiece {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::String(s) => {
|
||||
for c in s.chars() {
|
||||
match c {
|
||||
'{' => f.write_str("{{")?,
|
||||
'}' => f.write_str("}}")?,
|
||||
_ => write!(f, "{}", c.escape_debug())?,
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Self::Placeholder { operand_idx, modifier: Some(modifier), .. } => {
|
||||
write!(f, "{{{}:{}}}", operand_idx, modifier)
|
||||
}
|
||||
Self::Placeholder { operand_idx, modifier: None, .. } => {
|
||||
write!(f, "{{{}}}", operand_idx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl InlineAsmTemplatePiece {
|
||||
/// Rebuilds the asm template string from its pieces.
|
||||
pub fn to_string(s: &[Self]) -> String {
|
||||
use fmt::Write;
|
||||
let mut out = String::new();
|
||||
for p in s.iter() {
|
||||
let _ = write!(out, "{}", p);
|
||||
}
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
/// Set of types which can be used with a particular register class.
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum InlineAsmType {
|
||||
|
@ -31,4 +31,4 @@ pub mod spec;
|
||||
/// Requirements for a `StableHashingContext` to be used in this crate.
|
||||
/// This is a hack to allow using the `HashStable_Generic` derive macro
|
||||
/// instead of implementing everything in librustc_middle.
|
||||
pub trait HashStableContext: rustc_span::HashStableContext {}
|
||||
pub trait HashStableContext {}
|
||||
|
@ -38,7 +38,6 @@ use rustc_middle::ty::{AdtKind, Visibility};
|
||||
use rustc_span::hygiene::DesugaringKind;
|
||||
use rustc_span::source_map::Span;
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_target::asm::InlineAsmOptions;
|
||||
use rustc_trait_selection::traits::{self, ObligationCauseCode};
|
||||
|
||||
use std::fmt::Display;
|
||||
@ -1873,7 +1872,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
}
|
||||
if asm.options.contains(InlineAsmOptions::NORETURN) {
|
||||
if asm.options.contains(ast::InlineAsmOptions::NORETURN) {
|
||||
self.tcx.types.never
|
||||
} else {
|
||||
self.tcx.mk_unit()
|
||||
|
Loading…
Reference in New Issue
Block a user