1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 12:43:36 +01:00

[flang][directives] Use TableGen information for clause classes in parse-tree

This patch takes advantage of the directive information and tablegen generation
to replace the clauses class parse tree and in the dump parse tree sections.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D85549
This commit is contained in:
Valentin Clement 2020-08-11 10:43:56 -04:00 committed by clementval
parent 674304dfb1
commit 402fcd0af2
6 changed files with 325 additions and 63 deletions

View File

@ -46,6 +46,9 @@ class DirectiveLanguage {
// EnumSet class name used for clauses to generated the allowed clauses map.
string clauseEnumSetClass = "";
// Class holding the clauses in the flang parse-tree.
string flangClauseBaseClass = "";
}
// Information about a specific clause.
@ -57,10 +60,20 @@ class Clause<string c> {
string alternativeName = "";
// Optional class holding value of the clause in clang AST.
string clangClass = ?;
string clangClass = "";
// Optional class holding the clause in flang AST. If left blank, the class
// is assumed to be the name of the clause with capitalized word and
// underscores removed.
// ex: async -> Async
// num_threads -> NumThreads
string flangClass = "";
// Optional class holding value of the clause in flang AST.
string flangClass = ?;
string flangClassValue = "";
// If set to 1, value is optional. Not optional by default.
bit isValueOptional = 0;
// Is clause implicit? If clause is set as implicit, the default kind will
// be return in get<LanguageName>ClauseKind instead of their own kind.

View File

@ -25,28 +25,30 @@ def OpenACC : DirectiveLanguage {
let enableBitmaskEnumInNamespace = 1;
let includeHeader = "llvm/Frontend/OpenACC/ACC.h.inc";
let clauseEnumSetClass = "AccClauseSet";
let flangClauseBaseClass = "AccClause";
}
//===----------------------------------------------------------------------===//
// Definition of OpenACC clauses
//===----------------------------------------------------------------------===//
// 2.16.1
def ACCC_Async : Clause<"async"> {
let flangClassValue = "ScalarIntExpr";
let isValueOptional = 1;
}
// 2.9.6
def ACCC_Auto : Clause<"auto"> {}
// 2.16.1
def ACCC_Async : Clause<"async"> {
let flangClass = "std::optional<ScalarIntExpr>";
}
// 2.7.11
def ACCC_Attach : Clause<"attach"> {
let flangClass = "AccObjectList";
let flangClassValue = "AccObjectList";
}
// 2.15.1
def ACCC_Bind : Clause<"bind"> {
let flangClass = "Name";
let flangClassValue = "Name";
}
// 2.12
@ -55,72 +57,73 @@ def ACCC_Capture : Clause<"capture"> {
// 2.9.1
def ACCC_Collapse : Clause<"collapse"> {
let flangClass = "ScalarIntConstantExpr";
let flangClassValue = "ScalarIntConstantExpr";
}
// 2.7.5
def ACCC_Copy : Clause<"copy"> {
let flangClass = "AccObjectList";
let flangClassValue = "AccObjectList";
}
// 2.7.6
def ACCC_Copyin : Clause<"copyin"> {
let flangClass = "AccObjectListWithModifier";
let flangClassValue = "AccObjectListWithModifier";
}
// 2.7.7
def ACCC_Copyout : Clause<"copyout"> {
let flangClass = "AccObjectListWithModifier";
let flangClassValue = "AccObjectListWithModifier";
}
// 2.7.8
def ACCC_Create : Clause<"create"> {
let flangClass = "AccObjectListWithModifier";
let flangClassValue = "AccObjectListWithModifier";
}
// 2.5.14
def ACCC_Default : Clause<"default"> {
let flangClass = "AccDefaultClause";
let flangClassValue = "AccDefaultClause";
}
// 2.4.12
def ACCC_DefaultAsync : Clause<"default_async"> {
let flangClass = "ScalarIntExpr";
let flangClassValue = "ScalarIntExpr";
}
// 2.7.10
def ACCC_Delete : Clause<"delete"> {
let flangClass = "AccObjectList";
let flangClassValue = "AccObjectList";
}
// 2.7.12
def ACCC_Detach : Clause<"detach"> {
let flangClass = "AccObjectList";
let flangClassValue = "AccObjectList";
}
// 2.14.4
def ACCC_Device : Clause<"device"> {
let flangClass = "AccObjectList";
let flangClassValue = "AccObjectList";
}
// 2.14.1
def ACCC_DeviceNum : Clause<"device_num"> {
let flangClass = "ScalarIntConstantExpr";
let flangClassValue = "ScalarIntConstantExpr";
}
// 2.7.3
def ACCC_DevicePtr : Clause<"deviceptr"> {
let flangClass = "AccObjectList";
let flangClassValue = "AccObjectList";
}
// 2.13
def ACCC_DeviceResident : Clause<"device_resident"> {
let flangClass = "AccObjectList";
let flangClassValue = "AccObjectList";
}
// 2.4
def ACCC_DeviceType : Clause<"device_type"> {
// (DeviceType, "*"
let flangClass = "std::optional<std::list<Name>>";
let flangClassValue = "std::list<Name>";
let isValueOptional = 1;
}
// 2.6.6
@ -128,22 +131,23 @@ def ACCC_Finalize : Clause<"finalize"> {}
// 2.5.12
def ACCC_FirstPrivate : Clause<"firstprivate"> {
let flangClass = "AccObjectList";
let flangClassValue = "AccObjectList";
}
// 2.9.2
def ACCC_Gang : Clause<"gang"> {
let flangClass = "std::optional<AccGangArgument>";
let flangClassValue = "AccGangArgument";
let isValueOptional = 1;
}
// 2.14.4
def ACCC_Host : Clause<"host"> {
let flangClass = "AccObjectList";
let flangClassValue = "AccObjectList";
}
// 2.5.4
def ACCC_If : Clause <"if"> {
let flangClass = "ScalarLogicalExpr";
let flangClassValue = "ScalarLogicalExpr";
}
// 2.14.4
@ -154,12 +158,12 @@ def ACCC_Independent : Clause<"independent"> {}
// 2.13
def ACCC_Link : Clause<"link"> {
let flangClass = "AccObjectList";
let flangClassValue = "AccObjectList";
}
// 2.7.9
def ACCC_NoCreate : Clause<"no_create"> {
let flangClass = "AccObjectList";
let flangClassValue = "AccObjectList";
}
// 2.15.1
@ -167,32 +171,32 @@ def ACCC_NoHost : Clause<"nohost"> {}
// 2.5.8
def ACCC_NumGangs : Clause<"num_gangs"> {
let flangClass = "ScalarIntExpr";
let flangClassValue = "ScalarIntExpr";
}
// 2.5.9
def ACCC_NumWorkers : Clause<"num_workers"> {
let flangClass = "ScalarIntExpr";
let flangClassValue = "ScalarIntExpr";
}
// 2.7.4
def ACCC_Present : Clause<"present"> {
let flangClass = "AccObjectList";
let flangClassValue = "AccObjectList";
}
// 2.5.11
def ACCC_Private : Clause<"private"> {
let flangClass = "AccObjectList";
let flangClassValue = "AccObjectList";
}
// 2.9.7
def ACCC_Tile : Clause <"tile"> {
let flangClass = "AccSizeExprList";
let flangClassValue = "AccSizeExprList";
}
// 2.8.1
def ACCC_UseDevice : Clause <"use_device"> {
let flangClass = "AccObjectList";
let flangClassValue = "AccObjectList";
}
// 2.12
@ -200,12 +204,13 @@ def ACCC_Read : Clause<"read"> {}
// 2.5.13
def ACCC_Reduction : Clause<"reduction"> {
let flangClass = "AccObjectListWithReduction";
let flangClassValue = "AccObjectListWithReduction";
}
// 2.5.5
def ACCC_Self : Clause<"self"> {
let flangClass = "std::optional<ScalarLogicalExpr>";
let flangClassValue = "ScalarLogicalExpr";
let isValueOptional = 1;
}
// 2.9.5
@ -213,22 +218,25 @@ def ACCC_Seq : Clause<"seq"> {}
// 2.9.4
def ACCC_Vector : Clause<"vector"> {
let flangClass = "std::optional<ScalarIntExpr>";
let flangClassValue = "ScalarIntExpr";
let isValueOptional = 1;
}
// 2.5.10
def ACCC_VectorLength : Clause<"vector_length"> {
let flangClass = "ScalarIntExpr";
let flangClassValue = "ScalarIntExpr";
}
// 2.16.2
def ACCC_Wait : Clause<"wait"> {
let flangClass = "std::optional<AccWaitArgument>";
let flangClassValue = "AccWaitArgument";
let isValueOptional = 1;
}
// 2.9.3
def ACCC_Worker: Clause<"worker"> {
let flangClass = "std::optional<ScalarIntExpr>";
let flangClassValue = "ScalarIntExpr";
let isValueOptional = 1;
}
// 2.12

View File

@ -25,6 +25,7 @@ def OpenMP : DirectiveLanguage {
let enableBitmaskEnumInNamespace = 1;
let includeHeader = "llvm/Frontend/OpenMP/OMP.h.inc";
let clauseEnumSetClass = "OmpClauseSet";
let flangClauseBaseClass = "OmpClause";
}
//===----------------------------------------------------------------------===//
@ -34,38 +35,87 @@ def OpenMP : DirectiveLanguage {
def OMPC_Allocator : Clause<"allocator"> {
let clangClass = "OMPAllocatorClause";
}
def OMPC_If : Clause<"if"> { let clangClass = "OMPIfClause"; }
def OMPC_Final : Clause<"final"> { let clangClass = "OMPFinalClause"; }
def OMPC_If : Clause<"if"> {
let clangClass = "OMPIfClause";
let flangClass = "OmpIfClause";
}
def OMPC_Final : Clause<"final"> {
let clangClass = "OMPFinalClause";
let flangClassValue = "ScalarLogicalExpr";
}
def OMPC_NumThreads : Clause<"num_threads"> {
let clangClass = "OMPNumThreadsClause";
let flangClassValue = "ScalarIntExpr";
}
def OMPC_SafeLen : Clause<"safelen"> {
let clangClass = "OMPSafelenClause";
let flangClassValue = "ScalarIntConstantExpr";
}
def OMPC_SimdLen : Clause<"simdlen"> {
let clangClass = "OMPSimdlenClause";
let flangClassValue = "ScalarIntConstantExpr";
}
def OMPC_Collapse : Clause<"collapse"> {
let clangClass = "OMPCollapseClause";
let flangClassValue = "ScalarIntConstantExpr";
}
def OMPC_Default : Clause<"default"> {
let clangClass = "OMPDefaultClause";
let flangClass = "OmpDefaultClause";
}
def OMPC_Private : Clause<"private"> {
let clangClass = "OMPPrivateClause";
let flangClassValue = "OmpObjectList";
}
def OMPC_SafeLen : Clause<"safelen"> { let clangClass = "OMPSafelenClause"; }
def OMPC_SimdLen : Clause<"simdlen"> { let clangClass = "OMPSimdlenClause"; }
def OMPC_Collapse : Clause<"collapse"> { let clangClass = "OMPCollapseClause"; }
def OMPC_Default : Clause<"default"> { let clangClass = "OMPDefaultClause"; }
def OMPC_Private : Clause<"private"> { let clangClass = "OMPPrivateClause"; }
def OMPC_FirstPrivate : Clause<"firstprivate"> {
let clangClass = "OMPFirstprivateClause";
let flangClassValue = "OmpObjectList";
}
def OMPC_LastPrivate : Clause<"lastprivate"> {
let clangClass = "OMPLastprivateClause";
let flangClassValue = "OmpObjectList";
}
def OMPC_Shared : Clause<"shared"> {
let clangClass = "OMPSharedClause";
let flangClassValue = "OmpObjectList";
}
def OMPC_Shared : Clause<"shared"> { let clangClass = "OMPSharedClause"; }
def OMPC_Reduction : Clause<"reduction"> {
let clangClass = "OMPReductionClause";
let flangClass = "OmpReductionClause";
}
def OMPC_Linear : Clause<"linear"> {
let clangClass = "OMPLinearClause";
let flangClass = "OmpLinearClause";
}
def OMPC_Aligned : Clause<"aligned"> {
let clangClass = "OMPAlignedClause";
let flangClass = "OmpAlignedClause";
}
def OMPC_Copyin : Clause<"copyin"> {
let clangClass = "OMPCopyinClause";
let flangClassValue = "OmpObjectList";
}
def OMPC_Linear : Clause<"linear"> { let clangClass = "OMPLinearClause"; }
def OMPC_Aligned : Clause<"aligned"> { let clangClass = "OMPAlignedClause"; }
def OMPC_Copyin : Clause<"copyin"> { let clangClass = "OMPCopyinClause"; }
def OMPC_CopyPrivate : Clause<"copyprivate"> {
let clangClass = "OMPCopyprivateClause";
let flangClassValue = "OmpObjectList";
}
def OMPC_ProcBind : Clause<"proc_bind"> {
let clangClass = "OMPProcBindClause";
let flangClass = "OmpProcBindClause";
}
def OMPC_Schedule : Clause<"schedule"> {
let clangClass = "OMPScheduleClause";
let flangClass = "OmpScheduleClause";
}
def OMPC_Ordered : Clause<"ordered"> {
let clangClass = "OMPOrderedClause";
let flangClassValue = "ScalarIntConstantExpr";
let isValueOptional = 1;
}
def OMPC_NoWait : Clause<"nowait"> {
let clangClass = "OMPNowaitClause";
let flangClass = "OmpNowait";
}
def OMPC_Schedule : Clause<"schedule"> { let clangClass = "OMPScheduleClause"; }
def OMPC_Ordered : Clause<"ordered"> { let clangClass = "OMPOrderedClause"; }
def OMPC_NoWait : Clause<"nowait"> { let clangClass = "OMPNowaitClause"; }
def OMPC_Untied : Clause<"untied"> { let clangClass = "OMPUntiedClause"; }
def OMPC_Mergeable : Clause<"mergeable"> {
let clangClass = "OMPMergeableClause";
@ -79,47 +129,70 @@ def OMPC_AcqRel : Clause<"acq_rel"> { let clangClass = "OMPAcqRelClause"; }
def OMPC_Acquire : Clause<"acquire"> { let clangClass = "OMPAcquireClause"; }
def OMPC_Release : Clause<"release"> { let clangClass = "OMPReleaseClause"; }
def OMPC_Relaxed : Clause<"relaxed"> { let clangClass = "OMPRelaxedClause"; }
def OMPC_Depend : Clause<"depend"> { let clangClass = "OMPDependClause"; }
def OMPC_Device : Clause<"device"> { let clangClass = "OMPDeviceClause"; }
def OMPC_Depend : Clause<"depend"> {
let clangClass = "OMPDependClause";
let flangClass = "OmpDependClause";
}
def OMPC_Device : Clause<"device"> {
let clangClass = "OMPDeviceClause";
let flangClassValue = "ScalarIntExpr";
}
def OMPC_Threads : Clause<"threads"> { let clangClass = "OMPThreadsClause"; }
def OMPC_Simd : Clause<"simd"> { let clangClass = "OMPSIMDClause"; }
def OMPC_Map : Clause<"map"> { let clangClass = "OMPMapClause"; }
def OMPC_Map : Clause<"map"> {
let clangClass = "OMPMapClause";
let flangClass = "OmpMapClause";
}
def OMPC_NumTeams : Clause<"num_teams"> {
let clangClass = "OMPNumTeamsClause";
let flangClassValue = "ScalarIntExpr";
}
def OMPC_ThreadLimit : Clause<"thread_limit"> {
let clangClass = "OMPThreadLimitClause";
let flangClassValue = "ScalarIntExpr";
}
def OMPC_Priority : Clause<"priority"> {
let clangClass = "OMPPriorityClause";
let flangClassValue = "ScalarIntExpr";
}
def OMPC_GrainSize : Clause<"grainsize"> {
let clangClass = "OMPGrainsizeClause";
let flangClassValue = "ScalarIntExpr";
}
def OMPC_NoGroup : Clause<"nogroup"> {
let clangClass = "OMPNogroupClause";
}
def OMPC_NumTasks : Clause<"num_tasks"> {
let clangClass = "OMPNumTasksClause";
let flangClassValue = "ScalarIntExpr";
}
def OMPC_Hint : Clause<"hint"> {
let clangClass = "OMPHintClause";
}
def OMPC_DistSchedule : Clause<"dist_schedule"> {
let clangClass = "OMPDistScheduleClause";
let flangClassValue = "ScalarIntExpr";
let isValueOptional = 1;
}
def OMPC_DefaultMap : Clause<"defaultmap"> {
let clangClass = "OMPDefaultmapClause";
let flangClass = "OmpDefaultmapClause";
}
def OMPC_To : Clause<"to"> {
let clangClass = "OMPToClause";
let flangClassValue = "OmpObjectList";
}
def OMPC_From : Clause<"from"> {
let clangClass = "OMPFromClause";
let flangClassValue = "OmpObjectList";
}
def OMPC_From : Clause<"from"> { let clangClass = "OMPFromClause"; }
def OMPC_UseDevicePtr : Clause<"use_device_ptr"> {
let clangClass = "OMPUseDevicePtrClause";
let flangClassValue = "std::list<Name>";
}
def OMPC_IsDevicePtr : Clause<"is_device_ptr"> {
let clangClass = "OMPIsDevicePtrClause";
let flangClassValue = "std::list<Name>";
}
def OMPC_TaskReduction : Clause<"task_reduction"> {
let clangClass = "OMPTaskReductionClause";
@ -144,6 +217,7 @@ def OMPC_AtomicDefaultMemOrder : Clause<"atomic_default_mem_order"> {
}
def OMPC_Allocate : Clause<"allocate"> {
let clangClass = "OMPAllocateClause";
let flangClass = "OmpAllocateClause";
}
def OMPC_NonTemporal : Clause<"nontemporal"> {
let clangClass = "OMPNontemporalClause";
@ -172,7 +246,9 @@ def OMPC_Affinity : Clause<"affinity"> {
def OMPC_UseDeviceAddr : Clause<"use_device_addr"> {
let clangClass = "OMPUseDeviceAddrClause";
}
def OMPC_Uniform : Clause<"uniform"> {}
def OMPC_Uniform : Clause<"uniform"> {
let flangClassValue = "std::list<Name>";
}
def OMPC_DeviceType : Clause<"device_type"> {}
def OMPC_Match : Clause<"match"> {}
def OMPC_Depobj : Clause<"depobj"> {
@ -191,7 +267,9 @@ def OMPC_Unknown : Clause<"unknown"> {
let isImplicit = 1;
let isDefault = 1;
}
def OMPC_Link : Clause<"link"> {}
def OMPC_Link : Clause<"link"> {
let flangClassValue = "OmpObjectList";
}
def OMPC_Inbranch : Clause<"inbranch"> {}
def OMPC_Notinbranch : Clause<"notinbranch"> {}

View File

@ -12,10 +12,15 @@ def TestDirectiveLanguage : DirectiveLanguage {
let clausePrefix = "TDLC_";
let makeEnumAvailableInNamespace = 1;
let enableBitmaskEnumInNamespace = 1;
let flangClauseBaseClass = "TdlClause";
}
def TDLC_ClauseA : Clause<"clausea"> {}
def TDLC_ClauseA : Clause<"clausea"> {
let flangClass = "TdlClauseA";
}
def TDLC_ClauseB : Clause<"clauseb"> {
let flangClassValue = "IntExpr";
let isValueOptional = 1;
let isDefault = 1;
}
@ -173,4 +178,27 @@ def TDL_DirA : Directive<"dira"> {
// GEN-NEXT: }
// GEN-EMPTY:
// GEN-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_MAP
// GEN-EMPTY:
// GEN-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES
// GEN-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_CLASSES
// GEN-EMPTY:
// GEN-NEXT: WRAPPER_CLASS(Clauseb, std::optional<IntExpr>);
// GEN-EMPTY:
// GEN-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES
// GEN-EMPTY:
// GEN-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
// GEN-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
// GEN-EMPTY:
// GEN-NEXT: TdlClauseA
// GEN-NEXT: , Clauseb
// GEN-EMPTY:
// GEN-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
// GEN-EMPTY:
// GEN-NEXT: #ifdef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
// GEN-NEXT: #undef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
// GEN-EMPTY:
// GEN-NEXT: NODE(TdlClause, Clauseb)
// GEN-EMPTY:
// GEN-NEXT: #endif // GEN_FLANG_DUMP_PARSE_TREE_CLAUSES

View File

@ -11,6 +11,7 @@ def TestDirectiveLanguage : DirectiveLanguage {
let directivePrefix = "TDLD_";
let clausePrefix = "TDLC_";
let includeHeader = "tdl.h.inc";
let flangClauseBaseClass = "TdlClause";
}
def TDLC_ClauseA : Clause<"clausea"> {
@ -18,6 +19,7 @@ def TDLC_ClauseA : Clause<"clausea"> {
}
def TDLC_ClauseB : Clause<"clauseb"> {
let isDefault = 1;
let flangClassValue = "IntExpr";
}
def TDL_DirA : Directive<"dira"> {
@ -164,3 +166,27 @@ def TDL_DirA : Directive<"dira"> {
// GEN-NEXT: }
// GEN-EMPTY:
// GEN-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_MAP
// GEN-EMPTY:
// GEN-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES
// GEN-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_CLASSES
// GEN-EMPTY:
// GEN-NEXT: EMPTY_CLASS(Clausea);
// GEN-NEXT: WRAPPER_CLASS(Clauseb, IntExpr);
// GEN-EMPTY:
// GEN-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES
// GEN-EMPTY:
// GEN-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
// GEN-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
// GEN-EMPTY:
// GEN-NEXT: Clausea
// GEN-NEXT: , Clauseb
// GEN-EMPTY:
// GEN-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
// GEN-EMPTY:
// GEN-NEXT: #ifdef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
// GEN-NEXT: #undef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
// GEN-EMPTY:
// GEN-NEXT: NODE(TdlClause, Clausea)
// GEN-NEXT: NODE(TdlClause, Clauseb)
// GEN-EMPTY:
// GEN-NEXT: #endif // GEN_FLANG_DUMP_PARSE_TREE_CLAUSES

View File

@ -19,6 +19,7 @@
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"
using namespace llvm;
namespace {
@ -68,6 +69,10 @@ public:
return Def->getValueAsString("clauseEnumSetClass");
}
StringRef getFlangClauseBaseClass() const {
return Def->getValueAsString("flangClauseBaseClass");
}
bool hasMakeEnumAvailableInNamespace() const {
return Def->getValueAsBit("makeEnumAvailableInNamespace");
}
@ -146,6 +151,35 @@ public:
return Def->getValueAsString("flangClass");
}
// Optional field.
StringRef getFlangClassValue() const {
return Def->getValueAsString("flangClassValue");
}
// Get the formatted name for Flang parser class. The generic formatted class
// name is constructed from the name were the first letter of each word is
// captitalized and the underscores are removed.
// ex: async -> Async
// num_threads -> NumThreads
std::string getFormattedParserClassName() {
StringRef Name = Def->getValueAsString("name");
std::string N = Name.str();
bool Cap = true;
std::transform(N.begin(), N.end(), N.begin(), [&Cap](unsigned char C) {
if (Cap == true) {
C = llvm::toUpper(C);
Cap = false;
} else if (C == '_') {
Cap = true;
}
return C;
});
N.erase(std::remove(N.begin(), N.end(), '_'), N.end());
return N;
}
bool isValueOptional() const { return Def->getValueAsBit("isValueOptional"); }
bool isImplict() const { return Def->getValueAsBit("isImplicit"); }
};
@ -489,15 +523,89 @@ void GenerateDirectiveClauseMap(const std::vector<Record *> &Directives,
OS << "}\n";
}
// Generate classes entry for Flang clauses in the Flang parse-tree
// If the clause as a non-generic class, no entry is generated.
// If the clause does not hold a value, an EMPTY_CLASS is used.
// If the clause class is generic then a WRAPPER_CLASS is used. When the value
// is optional, the value class is wrapped into a std::optional.
void GenerateFlangClauseParserClass(const std::vector<Record *> &Clauses,
raw_ostream &OS) {
IfDefScope Scope("GEN_FLANG_CLAUSE_PARSER_CLASSES", OS);
OS << "\n";
for (const auto &C : Clauses) {
Clause Clause{C};
// Clause has a non generic class.
if (!Clause.getFlangClass().empty())
continue;
// G
if (!Clause.getFlangClassValue().empty()) {
if (Clause.isValueOptional()) {
OS << "WRAPPER_CLASS(" << Clause.getFormattedParserClassName()
<< ", std::optional<" << Clause.getFlangClassValue() << ">);\n";
} else {
OS << "WRAPPER_CLASS(" << Clause.getFormattedParserClassName() << ", "
<< Clause.getFlangClassValue() << ");\n";
}
} else {
OS << "EMPTY_CLASS(" << Clause.getFormattedParserClassName() << ");\n";
}
}
}
// Generate a list of the different clause classes for Flang.
void GenerateFlangClauseParserClassList(const std::vector<Record *> &Clauses,
raw_ostream &OS) {
IfDefScope Scope("GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST", OS);
OS << "\n";
llvm::interleaveComma(Clauses, OS, [&](Record *C) {
Clause Clause{C};
if (Clause.getFlangClass().empty())
OS << Clause.getFormattedParserClassName() << "\n";
else
OS << Clause.getFlangClass() << "\n";
});
}
// Generate dump node list for the clauses holding a generic class name.
void GenerateFlangClauseDump(const std::vector<Record *> &Clauses,
const DirectiveLanguage &DirLang,
raw_ostream &OS) {
IfDefScope Scope("GEN_FLANG_DUMP_PARSE_TREE_CLAUSES", OS);
OS << "\n";
for (const auto &C : Clauses) {
Clause Clause{C};
// Clause has a non generic class.
if (!Clause.getFlangClass().empty())
continue;
OS << "NODE(" << DirLang.getFlangClauseBaseClass() << ", "
<< Clause.getFormattedParserClassName() << ")\n";
}
}
// Generate the implemenation section for the enumeration in the directive
// language
void EmitDirectivesFlangImpl(const std::vector<Record *> &Directives,
const std::vector<Record *> &Clauses,
raw_ostream &OS,
DirectiveLanguage &DirectiveLanguage) {
GenerateDirectiveClauseSets(Directives, OS, DirectiveLanguage);
GenerateDirectiveClauseMap(Directives, OS, DirectiveLanguage);
GenerateFlangClauseParserClass(Clauses, OS);
GenerateFlangClauseParserClassList(Clauses, OS);
GenerateFlangClauseDump(Clauses, DirectiveLanguage, OS);
}
// Generate the implemenation section for the enumeration in the directive
@ -513,8 +621,9 @@ void EmitDirectivesGen(RecordKeeper &Records, raw_ostream &OS) {
}
const auto &Directives = Records.getAllDerivedDefinitions("Directive");
const auto &Clauses = Records.getAllDerivedDefinitions("Clause");
DirectiveLanguage DirectiveLanguage{DirectiveLanguages[0]};
EmitDirectivesFlangImpl(Directives, OS, DirectiveLanguage);
EmitDirectivesFlangImpl(Directives, Clauses, OS, DirectiveLanguage);
}
// Generate the implemenation for the enumeration in the directive