From 0f6cbcaa883864343faf83f7b84119a731c6fc21 Mon Sep 17 00:00:00 2001 From: Ahmed Charles Date: Thu, 11 Sep 2014 23:00:07 -0700 Subject: [PATCH] Move uses of enum to bitflags!. There are still others, but this is the first batch. --- src/librustc/middle/trans/base.rs | 12 +----- src/librustc/middle/trans/foreign.rs | 4 +- src/librustc_llvm/lib.rs | 63 ++++++++++++++-------------- 3 files changed, 36 insertions(+), 43 deletions(-) diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index a814c9d624c..d7785d5b79c 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -191,21 +191,13 @@ pub fn decl_fn(ccx: &CrateContext, name: &str, cc: llvm::CallConv, match ty::get(output).sty { // functions returning bottom may unwind, but can never return normally ty::ty_bot => { - unsafe { - llvm::LLVMAddFunctionAttribute(llfn, - llvm::FunctionIndex as c_uint, - llvm::NoReturnAttribute as uint64_t) - } + llvm::SetFunctionAttribute(llfn, llvm::NoReturnAttribute) } _ => {} } if ccx.tcx().sess.opts.cg.no_redzone { - unsafe { - llvm::LLVMAddFunctionAttribute(llfn, - llvm::FunctionIndex as c_uint, - llvm::NoRedZoneAttribute as uint64_t) - } + llvm::SetFunctionAttribute(llfn, llvm::NoRedZoneAttribute) } llvm::SetFunctionCallConv(llfn, cc); diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index f3049dcee50..9cff7261806 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -998,7 +998,7 @@ fn add_argument_attributes(tys: &ForeignTypes, match tys.fn_ty.ret_ty.attr { Some(attr) => unsafe { - llvm::LLVMAddFunctionAttribute(llfn, i as c_uint, attr as u64); + llvm::LLVMAddFunctionAttribute(llfn, i as c_uint, attr.bits() as u64); }, None => {} } @@ -1014,7 +1014,7 @@ fn add_argument_attributes(tys: &ForeignTypes, match arg_ty.attr { Some(attr) => unsafe { - llvm::LLVMAddFunctionAttribute(llfn, i as c_uint, attr as u64); + llvm::LLVMAddFunctionAttribute(llfn, i as c_uint, attr.bits() as u64); }, None => () } diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index 690b288043d..271b19826b6 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -91,34 +91,35 @@ pub enum DiagnosticSeverity { Note, } -#[deriving(Clone)] -pub enum Attribute { - ZExtAttribute = 1 << 0, - SExtAttribute = 1 << 1, - NoReturnAttribute = 1 << 2, - InRegAttribute = 1 << 3, - StructRetAttribute = 1 << 4, - NoUnwindAttribute = 1 << 5, - NoAliasAttribute = 1 << 6, - ByValAttribute = 1 << 7, - NestAttribute = 1 << 8, - ReadNoneAttribute = 1 << 9, - ReadOnlyAttribute = 1 << 10, - NoInlineAttribute = 1 << 11, - AlwaysInlineAttribute = 1 << 12, - OptimizeForSizeAttribute = 1 << 13, - StackProtectAttribute = 1 << 14, - StackProtectReqAttribute = 1 << 15, - AlignmentAttribute = 31 << 16, - NoCaptureAttribute = 1 << 21, - NoRedZoneAttribute = 1 << 22, - NoImplicitFloatAttribute = 1 << 23, - NakedAttribute = 1 << 24, - InlineHintAttribute = 1 << 25, - StackAttribute = 7 << 26, - ReturnsTwiceAttribute = 1 << 29, - UWTableAttribute = 1 << 30, - NonLazyBindAttribute = 1 << 31, +bitflags! { + flags Attribute : u32 { + static ZExtAttribute = 1 << 0, + static SExtAttribute = 1 << 1, + static NoReturnAttribute = 1 << 2, + static InRegAttribute = 1 << 3, + static StructRetAttribute = 1 << 4, + static NoUnwindAttribute = 1 << 5, + static NoAliasAttribute = 1 << 6, + static ByValAttribute = 1 << 7, + static NestAttribute = 1 << 8, + static ReadNoneAttribute = 1 << 9, + static ReadOnlyAttribute = 1 << 10, + static NoInlineAttribute = 1 << 11, + static AlwaysInlineAttribute = 1 << 12, + static OptimizeForSizeAttribute = 1 << 13, + static StackProtectAttribute = 1 << 14, + static StackProtectReqAttribute = 1 << 15, + static AlignmentAttribute = 31 << 16, + static NoCaptureAttribute = 1 << 21, + static NoRedZoneAttribute = 1 << 22, + static NoImplicitFloatAttribute = 1 << 23, + static NakedAttribute = 1 << 24, + static InlineHintAttribute = 1 << 25, + static StackAttribute = 7 << 26, + static ReturnsTwiceAttribute = 1 << 29, + static UWTableAttribute = 1 << 30, + static NonLazyBindAttribute = 1 << 31, + } } #[repr(u64)] @@ -160,13 +161,13 @@ trait AttrHelper { impl AttrHelper for Attribute { fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) { unsafe { - LLVMAddFunctionAttribute(llfn, idx, *self as uint64_t); + LLVMAddFunctionAttribute(llfn, idx, self.bits() as uint64_t); } } fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) { unsafe { - LLVMAddCallSiteAttribute(callsite, idx, *self as uint64_t); + LLVMAddCallSiteAttribute(callsite, idx, self.bits() as uint64_t); } } } @@ -2009,7 +2010,7 @@ pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef { pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) { unsafe { - LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr as uint64_t) + LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr.bits() as uint64_t) } }