From bedaa8e503da80c0b846567f4a1a6f535442ba71 Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Thu, 25 Mar 2021 20:43:35 -0700 Subject: [PATCH] Added function attributes and properties needed for C --- .../maple_ir/include/all_attributes.def | 3 +++ src/mapleall/maple_ir/include/mir_function.h | 21 +++++++++++++++++ src/mapleall/maple_ir/src/mir_function.cpp | 23 +++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/src/mapleall/maple_ir/include/all_attributes.def b/src/mapleall/maple_ir/include/all_attributes.def index 3c81c25506..7c10fae96a 100644 --- a/src/mapleall/maple_ir/include/all_attributes.def +++ b/src/mapleall/maple_ir/include/all_attributes.def @@ -77,3 +77,6 @@ ATTR(localrefvar) ATTR(rcunownedthis) #endif +#ifdef FUNC_ATTR + ATTR(firstarg_return) +#endif diff --git a/src/mapleall/maple_ir/include/mir_function.h b/src/mapleall/maple_ir/include/mir_function.h index bdb9b16733..8e2defaa1d 100644 --- a/src/mapleall/maple_ir/include/mir_function.h +++ b/src/mapleall/maple_ir/include/mir_function.h @@ -204,6 +204,14 @@ class MIRFunction { MIRSymbol *GetLocalOrGlobalSymbol(const StIdx &idx, bool checkFirst = false); void SetAttrsFromSe(uint8 specialEffect); + + FuncAttrs GetAttrs() const { + return funcAttrs; + } + void SetAttrs(FuncAttrs attr) { + funcAttrs = attr; + } + bool GetAttr(FuncAttrKind attrKind) const { return funcAttrs.GetAttr(attrKind); } @@ -290,6 +298,10 @@ class MIRFunction { return funcAttrs.GetAttr(FUNCATTR_pure); } + bool IsFirstArgReturn() const { + return funcAttrs.GetAttr(FUNCATTR_firstarg_return); + } + void SetVarArgs() { funcAttrs.SetAttr(FUNCATTR_varargs); } @@ -326,6 +338,10 @@ class MIRFunction { funcAttrs.SetAttr(FUNCATTR_pure); } + void SetFirstArgReturn() { + funcAttrs.SetAttr(FUNCATTR_firstarg_return); + } + void UnsetNoDefArgEffect() { funcAttrs.SetAttr(FUNCATTR_nodefargeffect, true); } @@ -371,6 +387,11 @@ class MIRFunction { void SetNoReturn(); bool NeverReturns() const; + void SetHasSetjmp(); + bool HasSetjmp() const; + + void SetReturnStruct(MIRType *retType); + bool IsEmpty() const; bool IsClinit() const; uint32 GetInfo(GStrIdx strIdx) const; diff --git a/src/mapleall/maple_ir/src/mir_function.cpp b/src/mapleall/maple_ir/src/mir_function.cpp index 1ea335b8a4..aff5fa9ebf 100644 --- a/src/mapleall/maple_ir/src/mir_function.cpp +++ b/src/mapleall/maple_ir/src/mir_function.cpp @@ -30,6 +30,7 @@ enum FuncProp : uint32_t { // than once per function since they // can only be printed at the beginning of a block kFuncPropNeverReturn = 1U << 4, // the function when called never returns + kFuncPropHasSetjmp = 1U << 5, // the function contains call to setjmp }; } // namespace @@ -150,6 +151,20 @@ void MIRFunction::SetReturnStruct(MIRType &retType) { flag |= kFuncPropRetStruct; } } +void MIRFunction::SetReturnStruct(MIRType *retType) { + switch (retType->GetKind()) { + case kTypeUnion: + case kTypeStruct: + case kTypeStructIncomplete: + case kTypeClass: + case kTypeClassIncomplete: + case kTypeInterface: + case kTypeInterfaceIncomplete: + flag |= kFuncPropRetStruct; + break; + default:; + } +} bool MIRFunction::IsUserFunc() const { return flag & kFuncPropUserFunc; @@ -175,6 +190,14 @@ bool MIRFunction::NeverReturns() const { return flag & kFuncPropNeverReturn; } +void MIRFunction::SetHasSetjmp() { + flag |= kFuncPropHasSetjmp; +} + +bool MIRFunction::HasSetjmp() const { + return flag & kFuncPropHasSetjmp; +} + void MIRFunction::SetAttrsFromSe(uint8 specialEffect) { // NoPrivateDefEffect if ((specialEffect & kDefEffect) == kDefEffect) { -- Gitee