[PATCH] D33277: [Clang][x86][Inline Asm] - Enum support for MS syntax
Matan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 17 07:24:21 PDT 2017
mharoush created this revision.
mharoush added a project: clang-c.
Herald added a subscriber: eraman.
This patch enables the usage of constant Enum identifiers within Microsoft style inline assembly statements.
part 1 out of 2.
Repository:
rL LLVM
https://reviews.llvm.org/D33277
Files:
lib/Parse/ParseStmtAsm.cpp
test/CodeGen/x86-ms-inline-asm-enum_feature.cpp
Index: lib/Parse/ParseStmtAsm.cpp
===================================================================
--- lib/Parse/ParseStmtAsm.cpp
+++ lib/Parse/ParseStmtAsm.cpp
@@ -94,6 +94,23 @@
return Info.OpDecl;
}
+ // Try to evaluate the inline asm identifier lookup result as an
+ // enumerated type. This method expects LookupResult to be the
+ // result of a call to LookupInlineAsmIdentifier.
+ bool EvaluateLookupAsEnum(void *LookupResult, int64_t &Result) {
+ if (!LookupResult) return false;
+ Expr *Res = static_cast<Expr*> (LookupResult);
+ if (Res && isa<clang::EnumType>(Res->getType())) {
+ Expr::EvalResult EvlResult;
+ if (Res->EvaluateAsRValue(EvlResult,
+ TheParser.getActions().getASTContext())) {
+ Result = EvlResult.Val.getInt().getExtValue();
+ return true;
+ }
+ }
+ return false;
+ }
+
StringRef LookupInlineAsmLabel(StringRef Identifier, llvm::SourceMgr &LSM,
llvm::SMLoc Location,
bool Create) override {
Index: test/CodeGen/x86-ms-inline-asm-enum_feature.cpp
===================================================================
--- test/CodeGen/x86-ms-inline-asm-enum_feature.cpp
+++ test/CodeGen/x86-ms-inline-asm-enum_feature.cpp
@@ -0,0 +1,50 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 %s -fasm-blocks -emit-llvm -o - | FileCheck %s
+namespace x {
+enum { A = 12 };
+namespace y {
+enum { A = 17 };
+}
+}
+
+void x86_enum_only(){
+ const int a = 0;
+ // CHECK-NOT: mov eax, [$$0]
+ __asm mov eax, [a]
+}
+
+void x86_enum_namespaces() {
+ enum { A = 1 };
+ // CHECK: mov eax, $$12
+ __asm mov eax, x::A
+ // CHECK: mov eax, $$17
+ __asm mov eax, x::y::A
+ // CHECK: mov eax, $$1
+ __asm mov eax, A
+}
+
+void x86_enum_arithmethic() {
+ enum { A = 1, B };
+ // CHECK: mov eax, $$21
+ __asm mov eax, (A + 9) * 2 + A
+ // CHECK: mov eax, $$4
+ __asm mov eax, A << 2
+ // CHECK: mov eax, $$2
+ __asm mov eax, B & 3
+ // CHECK: mov eax, $$5
+ __asm mov eax, 3 + (B & 3)
+ // CHECK: mov eax, $$8
+ __asm mov eax, 2 << A * B
+}
+
+void x86_enum_mem() {
+ int arr[4];
+ enum { A = 4, B };
+
+ // CHECK: mov eax, [($$12 + $$9) + $$4 * $$5 + $$3 + $$3 + eax]
+ __asm { mov eax, [(x::A + 9) + A * B + 3 + 3 + eax] }
+ // CHECK: mov eax, dword ptr $$4$0
+ __asm { mov eax, [arr + A] }
+ // CHECK: mov eax, dword ptr $$8$0
+ __asm { mov eax, A[arr + A] }
+}
\ No newline at end of file
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33277.99295.patch
Type: text/x-patch
Size: 2552 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170517/44b4c646/attachment.bin>
More information about the llvm-commits
mailing list