[ms-inline asm] Enumerate the InlineAsm dialects and rename the nsdialect to

inteldialect.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163231 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chad Rosier 2012-09-05 19:00:49 +00:00
parent 7bebddf55e
commit 581600bfc3
11 changed files with 38 additions and 30 deletions

View File

@ -2894,19 +2894,18 @@ call void asm sideeffect "eieio", ""()
call void asm alignstack "eieio", ""()
</pre>
<p>Inline asms also support using non-standard assembly dialects. The standard
dialect is ATT, which is assumed when the '<tt>nsdialect</tt>' keyword is not
present. When the '<tt>nsdialect</tt>' keyword is present, the dialect is
assumed to be Intel. Currently, ATT and Intel are the only supported
dialects. An example is:</p>
<p>Inline asms also support using non-standard assembly dialects. The assumed
dialect is ATT. When the '<tt>inteldialect</tt>' keyword is present, the
inline asm is using the Intel dialect. Currently, ATT and Intel are the
only supported dialects. An example is:</p>
<pre class="doc_code">
call void asm nsdialect "eieio", ""()
call void asm inteldialect "eieio", ""()
</pre>
<p>If multiple keywords appear the '<tt>sideeffect</tt>' keyword must come
first, the '<tt>alignstack</tt>' keyword second and the
'<tt>nsdialect</tt>' keyword last.</p>
'<tt>inteldialect</tt>' keyword last.</p>
<!--
<p>TODO: The format of the asm and constraints string still need to be

View File

@ -168,7 +168,7 @@ namespace bitc {
CST_CODE_BLOCKADDRESS = 21, // CST_CODE_BLOCKADDRESS [fnty, fnval, bb#]
CST_CODE_DATA = 22, // DATA: [n x elements]
CST_CODE_INLINEASM = 23 // INLINEASM: [sideeffect|alignstack|
// nsdialect,asmstr,conststr]
// asmdialect,asmstr,conststr]
};
/// CastOpcodes - These are values used in the bitcode files to encode which

View File

@ -33,6 +33,13 @@ template<class ConstantClass, class TypeClass, class ValType>
struct ConstantCreator;
class InlineAsm : public Value {
public:
enum AsmDialect {
AD_ATT,
AD_Intel
};
private:
friend struct ConstantCreator<InlineAsm, PointerType, InlineAsmKeyType>;
friend class ConstantUniqueMap<InlineAsmKeyType, const InlineAsmKeyType&,
PointerType, InlineAsm, false>;
@ -43,12 +50,11 @@ class InlineAsm : public Value {
std::string AsmString, Constraints;
bool HasSideEffects;
bool IsAlignStack;
/// AsmDialect - 0 is AT&T (default) and 1 is the Intel dialect.
unsigned AsmDialect;
AsmDialect Dialect;
InlineAsm(PointerType *Ty, const std::string &AsmString,
const std::string &Constraints, bool hasSideEffects,
bool isAlignStack, unsigned asmDialect);
bool isAlignStack, AsmDialect asmDialect);
virtual ~InlineAsm();
/// When the ConstantUniqueMap merges two types and makes two InlineAsms
@ -60,11 +66,12 @@ public:
///
static InlineAsm *get(FunctionType *Ty, StringRef AsmString,
StringRef Constraints, bool hasSideEffects,
bool isAlignStack = false, unsigned asmDialect = 0);
bool isAlignStack = false,
AsmDialect asmDialect = AD_ATT);
bool hasSideEffects() const { return HasSideEffects; }
bool isAlignStack() const { return IsAlignStack; }
unsigned getDialect() const { return AsmDialect; }
AsmDialect getDialect() const { return Dialect; }
/// getType - InlineAsm's are always pointers.
///

View File

@ -510,7 +510,7 @@ lltok::Kind LLLexer::LexIdentifier() {
KEYWORD(asm);
KEYWORD(sideeffect);
KEYWORD(alignstack);
KEYWORD(nsdialect);
KEYWORD(inteldialect);
KEYWORD(gc);
KEYWORD(ccc);

View File

@ -2069,18 +2069,18 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) {
case lltok::kw_asm: {
// ValID ::= 'asm' SideEffect? AlignStack? STRINGCONSTANT ',' STRINGCONSTANT
bool HasSideEffect, AlignStack, NSDialect;
bool HasSideEffect, AlignStack, AsmDialect;
Lex.Lex();
if (ParseOptionalToken(lltok::kw_sideeffect, HasSideEffect) ||
ParseOptionalToken(lltok::kw_alignstack, AlignStack) ||
ParseOptionalToken(lltok::kw_nsdialect, NSDialect) ||
ParseOptionalToken(lltok::kw_inteldialect, AsmDialect) ||
ParseStringConstant(ID.StrVal) ||
ParseToken(lltok::comma, "expected comma in inline asm expression") ||
ParseToken(lltok::StringConstant, "expected constraint string"))
return true;
ID.StrVal2 = Lex.getStrVal();
ID.UIntVal = unsigned(HasSideEffect) | (unsigned(AlignStack)<<1) |
(unsigned(NSDialect)<<2);
(unsigned(AsmDialect)<<2);
ID.Kind = ValID::t_InlineAsm;
return false;
}
@ -2498,7 +2498,7 @@ bool LLParser::ConvertValIDToValue(Type *Ty, ValID &ID, Value *&V,
if (!FTy || !InlineAsm::Verify(FTy, ID.StrVal2))
return Error(ID.Loc, "invalid type for inline asm constraint string");
V = InlineAsm::get(FTy, ID.StrVal, ID.StrVal2, ID.UIntVal&1,
(ID.UIntVal>>1)&1, (ID.UIntVal>>2)&1);
(ID.UIntVal>>1)&1, (InlineAsm::AsmDialect(ID.UIntVal>>2)));
return false;
}
case ValID::t_MDNode:

View File

@ -72,7 +72,7 @@ namespace lltok {
kw_asm,
kw_sideeffect,
kw_alignstack,
kw_nsdialect,
kw_inteldialect,
kw_gc,
kw_c,

View File

@ -1245,7 +1245,7 @@ bool BitcodeReader::ParseConstants() {
V = ConstantExpr::getICmp(Record[3], Op0, Op1);
break;
}
// This maintains backward compatibility, pre-'nsdialect'.
// This maintains backward compatibility, pre-asm dialect keywords.
// FIXME: Remove with the 4.0 release.
case bitc::CST_CODE_INLINEASM_OLD: {
if (Record.size() < 2) return Error("Invalid INLINEASM record");
@ -1268,7 +1268,8 @@ bool BitcodeReader::ParseConstants() {
AsmStr, ConstrStr, HasSideEffects, IsAlignStack);
break;
}
// This version adds support for the 'nsdialect' keyword.
// This version adds support for the asm dialect keywords (e.g.,
// inteldialect).
case bitc::CST_CODE_INLINEASM: {
if (Record.size() < 2) return Error("Invalid INLINEASM record");
std::string AsmStr, ConstrStr;
@ -1289,7 +1290,7 @@ bool BitcodeReader::ParseConstants() {
PointerType *PTy = cast<PointerType>(CurTy);
V = InlineAsm::get(cast<FunctionType>(PTy->getElementType()),
AsmStr, ConstrStr, HasSideEffects, IsAlignStack,
AsmDialect);
InlineAsm::AsmDialect(AsmDialect));
break;
}
case bitc::CST_CODE_BLOCKADDRESS:{

View File

@ -1029,8 +1029,9 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
Out << "sideeffect ";
if (IA->isAlignStack())
Out << "alignstack ";
if (IA->getDialect() != 0)
Out << "nsdialect ";
// We don't emit the AD_ATT dialect as it's the assumed default.
if (IA->getDialect() == InlineAsm::AD_Intel)
Out << "inteldialect ";
Out << '"';
PrintEscapedString(IA->getAsmString(), Out);
Out << "\", \"";

View File

@ -352,7 +352,7 @@ struct ExprMapKeyType {
struct InlineAsmKeyType {
InlineAsmKeyType(StringRef AsmString,
StringRef Constraints, bool hasSideEffects,
bool isAlignStack, unsigned asmDialect)
bool isAlignStack, InlineAsm::AsmDialect asmDialect)
: asm_string(AsmString), constraints(Constraints),
has_side_effects(hasSideEffects), is_align_stack(isAlignStack),
asm_dialect(asmDialect) {}
@ -360,7 +360,7 @@ struct InlineAsmKeyType {
std::string constraints;
bool has_side_effects;
bool is_align_stack;
unsigned asm_dialect;
InlineAsm::AsmDialect asm_dialect;
bool operator==(const InlineAsmKeyType& that) const {
return this->asm_string == that.asm_string &&
this->constraints == that.constraints &&

View File

@ -1056,7 +1056,7 @@ LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
const char *Constraints,
LLVMBool HasSideEffects,
LLVMBool IsAlignStack,
unsigned AsmDialect) {
InlineAsm::AsmDialect AsmDialect) {
return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
Constraints, HasSideEffects, IsAlignStack,
AsmDialect));

View File

@ -27,7 +27,7 @@ InlineAsm::~InlineAsm() {
InlineAsm *InlineAsm::get(FunctionType *Ty, StringRef AsmString,
StringRef Constraints, bool hasSideEffects,
bool isAlignStack, unsigned asmDialect) {
bool isAlignStack, AsmDialect asmDialect) {
InlineAsmKeyType Key(AsmString, Constraints, hasSideEffects, isAlignStack,
asmDialect);
LLVMContextImpl *pImpl = Ty->getContext().pImpl;
@ -36,11 +36,11 @@ InlineAsm *InlineAsm::get(FunctionType *Ty, StringRef AsmString,
InlineAsm::InlineAsm(PointerType *Ty, const std::string &asmString,
const std::string &constraints, bool hasSideEffects,
bool isAlignStack, unsigned asmDialect)
bool isAlignStack, AsmDialect asmDialect)
: Value(Ty, Value::InlineAsmVal),
AsmString(asmString), Constraints(constraints),
HasSideEffects(hasSideEffects), IsAlignStack(isAlignStack),
AsmDialect(asmDialect) {
Dialect(asmDialect) {
// Do various checks on the constraint string and type.
assert(Verify(getFunctionType(), constraints) &&