From 7bd092b054444e9800e8de1d8d71c408dbdc8ead Mon Sep 17 00:00:00 2001 From: Chad Rosier Date: Wed, 15 Aug 2012 16:53:30 +0000 Subject: [PATCH] [ms-inline asm] Add the left brace source location and improve the pretty printer. Patch by Enea Zaffanella . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161958 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Stmt.h | 13 +++++++++---- include/clang/Sema/Sema.h | 1 + lib/AST/Stmt.cpp | 5 +++-- lib/AST/StmtPrinter.cpp | 7 ++++++- lib/Parse/ParseStmt.cpp | 3 ++- lib/Sema/SemaStmt.cpp | 16 +++++++++------- lib/Sema/TreeTransform.h | 6 ++++-- 7 files changed, 34 insertions(+), 17 deletions(-) diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 05d054918d..943e005d1f 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -1620,7 +1620,7 @@ public: /// MSAsmStmt - This represents a MS inline-assembly statement extension. /// class MSAsmStmt : public Stmt { - SourceLocation AsmLoc, EndLoc; + SourceLocation AsmLoc, LBraceLoc, EndLoc; std::string AsmStr; bool IsSimple; @@ -1634,15 +1634,20 @@ class MSAsmStmt : public Stmt { StringRef *Clobbers; public: - MSAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, - bool isvolatile, ArrayRef asmtoks, StringRef asmstr, - ArrayRef clobbers, SourceLocation endloc); + MSAsmStmt(ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc, + bool issimple, bool isvolatile, ArrayRef asmtoks, + StringRef asmstr, ArrayRef clobbers, + SourceLocation endloc); SourceLocation getAsmLoc() const { return AsmLoc; } void setAsmLoc(SourceLocation L) { AsmLoc = L; } + SourceLocation getLBraceLoc() const { return LBraceLoc; } + void setLBraceLoc(SourceLocation L) { LBraceLoc = L; } SourceLocation getEndLoc() const { return EndLoc; } void setEndLoc(SourceLocation L) { EndLoc = L; } + bool hasBraces() const { return LBraceLoc.isValid(); } + unsigned getNumAsmToks() { return NumAsmToks; } Token *getAsmToks() { return AsmToks; } diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 2cd58279d4..2966a33ea1 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -2542,6 +2542,7 @@ public: bool MSAsm = false); StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, + SourceLocation LBraceLoc, ArrayRef AsmToks, SourceLocation EndLoc); diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 9aa7f5ba55..680ebc81c8 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -583,11 +583,12 @@ AsmStmt::AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, std::copy(clobbers, clobbers + NumClobbers, Clobbers); } -MSAsmStmt::MSAsmStmt(ASTContext &C, SourceLocation asmloc, +MSAsmStmt::MSAsmStmt(ASTContext &C, + SourceLocation asmloc, SourceLocation lbraceloc, bool issimple, bool isvolatile, ArrayRef asmtoks, StringRef asmstr, ArrayRef clobbers, SourceLocation endloc) - : Stmt(MSAsmStmtClass), AsmLoc(asmloc), EndLoc(endloc), + : Stmt(MSAsmStmtClass), AsmLoc(asmloc), LBraceLoc(lbraceloc), EndLoc(endloc), AsmStr(asmstr.str()), IsSimple(issimple), IsVolatile(isvolatile), NumAsmToks(asmtoks.size()), NumClobbers(clobbers.size()) { diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 2f7cb55c7c..85d5a79569 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -432,7 +432,12 @@ void StmtPrinter::VisitAsmStmt(AsmStmt *Node) { void StmtPrinter::VisitMSAsmStmt(MSAsmStmt *Node) { // FIXME: Implement MS style inline asm statement printer. - Indent() << "asm ()"; + Indent() << "__asm "; + if (Node->hasBraces()) + OS << "{\n"; + OS << *(Node->getAsmString()) << "\n"; + if (Node->hasBraces()) + Indent() << "}\n"; } void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) { diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 0ff1c8a96a..0af1d08298 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -1752,7 +1752,8 @@ StmtResult Parser::ParseMicrosoftAsmStatement(SourceLocation AsmLoc) { } // FIXME: We should be passing source locations for better diagnostics. - return Actions.ActOnMSAsmStmt(AsmLoc, llvm::makeArrayRef(AsmToks), EndLoc); + return Actions.ActOnMSAsmStmt(AsmLoc, LBraceLoc, + llvm::makeArrayRef(AsmToks), EndLoc); } /// ParseAsmStatement - Parse a GNU extended asm statement. diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 5bcc33f107..74e8cfed2e 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -2852,6 +2852,7 @@ static std::string buildMSAsmString(Sema &SemaRef, } StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, + SourceLocation LBraceLoc, ArrayRef AsmToks, SourceLocation EndLoc) { // MS-style inline assembly is not fully supported, so emit a warning. @@ -2862,9 +2863,9 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, if (AsmToks.empty()) { StringRef AsmString; MSAsmStmt *NS = - new (Context) MSAsmStmt(Context, AsmLoc, /* IsSimple */ true, - /* IsVolatile */ true, AsmToks, AsmString, - Clobbers, EndLoc); + new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, + /* IsSimple */ true, /* IsVolatile */ true, + AsmToks, AsmString, Clobbers, EndLoc); return Owned(NS); } @@ -2888,9 +2889,9 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, // patchMSAsmStrings doesn't correctly patch non-simple asm statements. if (!IsSimple) { MSAsmStmt *NS = - new (Context) MSAsmStmt(Context, AsmLoc, /* IsSimple */ true, - /* IsVolatile */ true, AsmToks, AsmString, - Clobbers, EndLoc); + new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, + /* IsSimple */ true, /* IsVolatile */ true, + AsmToks, AsmString, Clobbers, EndLoc); return Owned(NS); } @@ -2980,7 +2981,8 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, } MSAsmStmt *NS = - new (Context) MSAsmStmt(Context, AsmLoc, IsSimple, /* IsVolatile */ true, + new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, + IsSimple, /* IsVolatile */ true, AsmToks, AsmString, Clobbers, EndLoc); return Owned(NS); diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 0516768ac4..6c7e9b0025 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -1185,9 +1185,10 @@ public: /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, + SourceLocation LBraceLoc, ArrayRef AsmToks, SourceLocation EndLoc) { - return getSema().ActOnMSAsmStmt(AsmLoc, AsmToks, EndLoc); + return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc); } /// \brief Build a new Objective-C \@try statement. @@ -5610,7 +5611,8 @@ TreeTransform::TransformMSAsmStmt(MSAsmStmt *S) { ArrayRef AsmToks = llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); - return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), AsmToks, S->getEndLoc()); + return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), + AsmToks, S->getEndLoc()); } template -- 2.40.0