From be3ace834ee7438915e73d2115365d57d03ceb99 Mon Sep 17 00:00:00 2001 From: Chad Rosier Date: Fri, 24 Aug 2012 17:05:45 +0000 Subject: [PATCH] [ms-inline asm] Refactor code. No functional change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162568 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Stmt.h | 2 ++ lib/AST/Stmt.cpp | 21 +++++++++++++++++++++ lib/CodeGen/CGStmt.cpp | 19 ++----------------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 58de1e9cf1..97598db6d2 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -1458,6 +1458,8 @@ public: unsigned AnalyzeAsmString(SmallVectorImpl &Pieces, ASTContext &C, unsigned &DiagOffs) const; + /// GenerateAsmString - Assemble final asm string. + std::string GenerateAsmString(ASTContext &C) const; //===--- Output operands ---===// diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 6b14ae5fd2..ec9b4c4568 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -20,6 +20,7 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/ASTDiagnostic.h" #include "clang/Basic/TargetInfo.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/raw_ostream.h" using namespace clang; @@ -547,6 +548,26 @@ unsigned AsmStmt::AnalyzeAsmString(SmallVectorImpl&Pieces, return diag::err_asm_invalid_escape; } } +/// GenerateAsmString - Assemble final asm string. +std::string AsmStmt::GenerateAsmString(ASTContext &C) const { + // Analyze the asm string to decompose it into its pieces. We know that Sema + // has already done this, so it is guaranteed to be successful. + SmallVector Pieces; + unsigned DiagOffs; + AnalyzeAsmString(Pieces, C, DiagOffs); + + std::string AsmString; + for (unsigned i = 0, e = Pieces.size(); i != e; ++i) { + if (Pieces[i].isString()) + AsmString += Pieces[i].getString(); + else if (Pieces[i].getModifier() == '\0') + AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo()); + else + AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' + + Pieces[i].getModifier() + '}'; + } + return AsmString; +} Expr *MSAsmStmt::getOutputExpr(unsigned i) { return cast(Exprs[i]); diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index c07fbf0454..ed27442cd8 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -1395,23 +1395,8 @@ static llvm::MDNode *getAsmSrcLocInfo(const StringLiteral *Str, } void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) { - // Analyze the asm string to decompose it into its pieces. We know that Sema - // has already done this, so it is guaranteed to be successful. - SmallVector Pieces; - unsigned DiagOffs; - S.AnalyzeAsmString(Pieces, getContext(), DiagOffs); - - // Assemble the pieces into the final asm string. - std::string AsmString; - for (unsigned i = 0, e = Pieces.size(); i != e; ++i) { - if (Pieces[i].isString()) - AsmString += Pieces[i].getString(); - else if (Pieces[i].getModifier() == '\0') - AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo()); - else - AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' + - Pieces[i].getModifier() + '}'; - } + // Assemble the final asm string. + std::string AsmString = S.GenerateAsmString(getContext()); // Get all the output and input constraints together. SmallVector OutputConstraintInfos; -- 2.40.0