diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index 72245affccde0759788be6263f2edfa91305f718..d1697c9aa6a858786ec095967180d2775efa3145 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index 22bb015508943636089b8cdb800aae03ba936e46..9d1e972d5de66cd13f16ec647917287b45977604 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/deplibs/libmplphase.a b/src/deplibs/libmplphase.a index 83f0173bed4525f5d4bc7fdfffcb27fd2d233ed8..96518c8332a69e435583ca579f84fad3c9255382 100644 Binary files a/src/deplibs/libmplphase.a and b/src/deplibs/libmplphase.a differ diff --git a/src/maple_ipa/src/callgraph.cpp b/src/maple_ipa/src/callgraph.cpp index 0f6a94554fe1e31e6bfc43f65b6972881d9be31b..83a05ee9d858e29fa9ef468c7c928505e7349304 100644 --- a/src/maple_ipa/src/callgraph.cpp +++ b/src/maple_ipa/src/callgraph.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. @@ -105,7 +105,7 @@ void CGNode::DumpDetail() const { CallInfo *ci = callSite.first; CGNode *node = cgIt; MIRFunction *mf = node->GetMIRFunction(); - if (mf != nullptr) { + if (mf) { LogInfo::MapleLogger() << "\tcallee in module : " << mf->GetName() << " "; } else { LogInfo::MapleLogger() << "\tcallee external: " << ci->GetCalleeName(); @@ -131,12 +131,12 @@ void CGNode::Dump(std::ofstream &fout) const { for (auto &cgIt : *callSite.second) { CallInfo *ci = callSite.first; CGNode *node = cgIt; - if (node == nullptr) { + if (!node) { continue; } MIRFunction *func = node->GetMIRFunction(); fout << "\"" << mirFunc->GetName() << "\" -> "; - if (func != nullptr) { + if (func) { if (node->GetSCCNode() != nullptr && node->GetSCCNode()->GetCGNodes().size() > 1) { fout << "\"" << func->GetName() << "\"[label=" << node->GetSCCNode()->id << " color=red];\n"; } else { @@ -530,7 +530,7 @@ void CallGraph::HandleBody(MIRFunction *func, BlockNode *body, CGNode *node, uin ASSERT(klass != nullptr, "Klass not found"); MapleVector *cands = klass->GetCandidates(calleeFunc->GetBaseFuncNameWithTypeStrIdx()); // continue to search its implinterfaces - if (cands == nullptr) { + if (!cands) { for (Klass *implinterface : klass->GetImplInterfaces()) { cands = implinterface->GetCandidates(calleeFunc->GetBaseFuncNameWithTypeStrIdx()); if (cands && !cands->empty()) { @@ -538,7 +538,7 @@ void CallGraph::HandleBody(MIRFunction *func, BlockNode *body, CGNode *node, uin } } } - if (cands == nullptr || cands->empty()) { + if (!cands || cands->empty()) { continue; // Fix CI } MIRFunction *actualMirfunc = cands->at(0); @@ -600,7 +600,7 @@ static void ResetInferredType(std::vector &inferredSymbols) { } static void ResetInferredType(std::vector &inferredSymbols, MIRSymbol *s) { - if (s == nullptr) { + if (!s) { return; } if (s->GetInferredTyIdx() == kInitTyIdx || s->GetInferredTyIdx() == kNoneTyIdx) { @@ -614,6 +614,7 @@ static void ResetInferredType(std::vector &inferredSymbols, MIRSymbo break; } } + // ASSERT(i &inferredSymbols, MIRSymbol *s, TyIdx idx) { @@ -874,7 +875,7 @@ void IPODevirtulize::SearchDefInMemberMethods(const Klass *klass) { void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { MIRClassType *classtype = static_cast(klass->GetMIRStructType()); for (auto &func : klass->GetMethods()) { - if (func->GetBody() == nullptr) { + if (!func->GetBody()) { continue; } StmtNode *stmtNext = nullptr; @@ -990,7 +991,7 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { for (MIRFunction *const &method : iklass->GetMethods()) { if (calleefunc->GetBaseFuncNameWithTypeStrIdx() == method->GetBaseFuncNameWithTypeStrIdx() && !method->GetFuncAttrs().GetAttr(FUNCATTR_abstract)) { - if (tmpInterface == nullptr || klassh->IsSuperKlassForInterface(tmpInterface, iklass)) { + if (!tmpInterface || klassh->IsSuperKlassForInterface(tmpInterface, iklass)) { tmpInterface = iklass; tmpMethod = method; } @@ -999,7 +1000,7 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { } } // Add this check for the thirdparty APP compile - if (tmpMethod == nullptr) { + if (!tmpMethod) { Klass *parentKlass = klassh->GetKlassFromName(calleefunc->GetBaseClassName()); CHECK_FATAL(parentKlass != nullptr, "null ptr check"); bool flag = false; @@ -1028,7 +1029,7 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { << currKlass->GetKlassName() << std::endl; } } - if (tmpMethod == nullptr) { // SearchWithoutRettype, search only in current class now. + if (!tmpMethod) { // SearchWithoutRettype, search only in current class now. MIRType *retType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(calleefunc->GetReturnTyIdx()); Klass *targetKlass = nullptr; bool isCalleeScalar = false; @@ -1040,7 +1041,7 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { } else { targetKlass = klassh->GetKlassFromTyIdx(retType->GetTypeIndex()); } - if (targetKlass == nullptr && !isCalleeScalar) { + if (!targetKlass && !isCalleeScalar) { CHECK_FATAL(targetKlass != nullptr, "null ptr check"); } Klass *curRetKlass = nullptr; @@ -1058,7 +1059,7 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { } else { tmpKlass = klassh->GetKlassFromTyIdx(tmpType->GetTypeIndex()); } - if (tmpKlass == nullptr && !isCurrVtabScalar) { + if (!tmpKlass && !isCurrVtabScalar) { CHECK_FATAL(tmpKlass != nullptr, "null ptr check"); } if (isCalleeScalar || isCurrVtabScalar) { @@ -1073,7 +1074,7 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { continue; } if (targetKlass->IsClass() && klassh->IsSuperKlass(tmpKlass, targetKlass) && - (curRetKlass == nullptr || klassh->IsSuperKlass(curRetKlass, tmpKlass))) { + (!curRetKlass || klassh->IsSuperKlass(curRetKlass, tmpKlass))) { curRetKlass = tmpKlass; tmpMethod = method; } @@ -1084,12 +1085,12 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { if (!targetKlass->IsClass()) { CHECK_FATAL(tmpKlass != nullptr, "Klass null ptr check"); if (tmpKlass->IsClass() && klassh->IsInterfaceImplemented(targetKlass, tmpKlass) && - (curRetKlass == nullptr || klassh->IsSuperKlass(curRetKlass, tmpKlass))) { + (!curRetKlass || klassh->IsSuperKlass(curRetKlass, tmpKlass))) { curRetKlass = tmpKlass; tmpMethod = method; } if (!tmpKlass->IsClass() && klassh->IsSuperKlassForInterface(tmpKlass, targetKlass) && - (curRetKlass == nullptr || klassh->IsSuperKlass(curRetKlass, tmpKlass))) { + (!curRetKlass || klassh->IsSuperKlass(curRetKlass, tmpKlass))) { curRetKlass = tmpKlass; tmpMethod = method; } @@ -1097,12 +1098,12 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { } } } - if (tmpMethod == nullptr && (currKlass->IsClass() || currKlass->IsInterface())) { + if (!tmpMethod && (currKlass->IsClass() || currKlass->IsInterface())) { LogInfo::MapleLogger() << "warning: func " << calleefunc->GetName() << " is not found in DeVirtual!" << std::endl; stmt->SetOpCode(OP_callassigned); break; - } else if (tmpMethod == nullptr) { + } else if (!tmpMethod) { LogInfo::MapleLogger() << "Error: func " << calleefunc->GetName() << " is not found!" << std::endl; ASSERT(tmpMethod, "Must not be null"); } @@ -1215,24 +1216,25 @@ void IPODevirtulize::DevirtualFinal() { } } +using CallSite = std::pair; void CallGraph::GenCallGraph() { - // Read existing call graph from mplt, std::map > + // Read existing call graph from mplt, std::map > // caller_PUIdx and all call site info are needed. Rebuild all other info of CGNode using CHA for (auto const &it : mirModule->GetMethod2TargetMap()) { CGNode *node = GetOrGenCGNode(it.first); CHECK_FATAL(node != nullptr, "node is null"); - std::vector callees = it.second; + std::vector callees = it.second; for (auto itInner = callees.begin(); itInner != callees.end(); ++itInner) { - CallInfo *info = *itInner; + CallInfo *info = (*itInner).first; CGNode *calleeNode = GetOrGenCGNode(info->GetFunc()->GetPuidx(), info->GetCallType() == kCallTypeVirtualCall, info->GetCallType() == kCallTypeInterfaceCall); CHECK_FATAL(calleeNode != nullptr, "calleeNode is null"); if (info->GetCallType() == kCallTypeVirtualCall) { - node->AddCallsite(*itInner, &calleeNode->GetVcallCandidates()); + node->AddCallsite((*itInner).first, &calleeNode->GetVcallCandidates()); } else if (info->GetCallType() == kCallTypeInterfaceCall) { - node->AddCallsite(*itInner, &calleeNode->GetIcallCandidates()); + node->AddCallsite((*itInner).first, &calleeNode->GetIcallCandidates()); } else if (info->GetCallType() == kCallTypeCall) { - node->AddCallsite(*itInner, calleeNode); + node->AddCallsite((*itInner).first, calleeNode); } else if (info->GetCallType() == kCallTypeSuperCall) { const MIRFunction *calleefunc = info->GetFunc(); Klass *klass = klassh->GetKlassFromFunc(calleefunc); @@ -1273,7 +1275,7 @@ void CallGraph::GenCallGraph() { for (auto it = GlobalTables::GetFunctionTable().GetFuncTable().begin(); it != GlobalTables::GetFunctionTable().GetFuncTable().end(); it++) { MIRFunction *mirFunc = *it; - if (mirFunc == nullptr || mirFunc->GetBody() == nullptr) { + if (!mirFunc || !mirFunc->GetBody()) { continue; } mirModule->SetCurFunction(mirFunc); @@ -1502,7 +1504,7 @@ void SCCNode::Setup() { for (auto &callSite : node->GetCallee()) { for (auto &cgIt : *callSite.second) { CGNode *calleeNode = cgIt; - if (calleeNode == nullptr) { + if (!calleeNode) { continue; } if (calleeNode->GetSCCNode() == this) { @@ -1535,7 +1537,7 @@ void CallGraph::BuildSCCDFS(CGNode *caller, uint32 &visitIndex, std::vectorGetCallee()) { for (auto &cgIt : *callSite.second) { CGNode *calleeNode = cgIt; - if (calleeNode == nullptr) { + if (!calleeNode) { continue; } uint32 calleeId = calleeNode->GetID(); @@ -1646,9 +1648,9 @@ void CGNode::AddCandsForCallNode(const KlassHierarchy *kh) { } CHECK_FATAL(mirFunc != nullptr, ""); Klass *klass = kh->GetKlassFromFunc(mirFunc); - if (klass != nullptr) { + if (klass) { MapleVector *v = klass->GetCandidates(mirFunc->GetBaseFuncNameWithTypeStrIdx()); - if (v != nullptr) { + if (v) { vcallCands = *v; // Vector copy } } @@ -1668,7 +1670,7 @@ MIRFunction *CGNode::HasOneCandidate() const { } if (!vcallCands[i]->IsEmpty()) { count++; - if (cand == nullptr) { + if (!cand) { cand = vcallCands[i]; } } @@ -1679,19 +1681,18 @@ MIRFunction *CGNode::HasOneCandidate() const { AnalysisResult *DoCallGraph::Run(MIRModule *module, ModuleResultMgr *m) { MemPool *memPool = memPoolCtrler.NewMemPool("callgraph mempool"); KlassHierarchy *cha = static_cast(m->GetAnalysisResult(MoPhase_CHA, module)); - CHECK_FATAL(cha != nullptr, "CHA can't be null"); + CHECK_FATAL(cha != nullptr, ""); CallGraph *cg = memPool->New(module, memPool, cha, module->GetFileName().c_str()); cg->debug_flag = TRACE_PHASE; cg->BuildCallGraph(); m->AddResult(GetPhaseID(), *module, *cg); - if (!module->IsInIPA()) { - // do retype - MemPool *localMp = memPoolCtrler.NewMemPool(PhaseName()); - maple::MIRBuilder dexMirbuilder(module); - Retype retype(module, localMp, dexMirbuilder, cha); - retype.DoRetype(); - memPoolCtrler.DeleteMemPool(localMp); - } + // do retype + MemPool *localMp = memPoolCtrler.NewMemPool(PhaseName()); + maple::MIRBuilder dexMirbuilder(module); + KlassHierarchy *retypeKh = static_cast(m->GetAnalysisResult(MoPhase_CHA, module)); + Retype retype(module, localMp, dexMirbuilder, retypeKh); + retype.DoRetype(); + memPoolCtrler.DeleteMemPool(localMp); return cg; } diff --git a/src/maple_ir/include/bin_mpl_import.h b/src/maple_ir/include/bin_mpl_import.h index c7cebc57744c84d2ff1106801ba6d99e630a8fbb..d75acb20c43264cbf8d8086d71a9235a3a632400 100644 --- a/src/maple_ir/include/bin_mpl_import.h +++ b/src/maple_ir/include/bin_mpl_import.h @@ -22,6 +22,7 @@ namespace maple { class BinaryMplImport { public: + using CallSite = std::pair; explicit BinaryMplImport(MIRModule &md) : mod(md), mirBuilder(&md) {} BinaryMplImport &operator=(const BinaryMplImport&) = delete; BinaryMplImport(const BinaryMplImport&) = delete; diff --git a/src/maple_ir/include/metadata_layout.h b/src/maple_ir/include/metadata_layout.h index 945748b9a4f77b93044dfa1c84f3ab9de973c230..c28e6a9c66c6651bd77436322042d96060c75aa3 100644 --- a/src/maple_ir/include/metadata_layout.h +++ b/src/maple_ir/include/metadata_layout.h @@ -18,13 +18,6 @@ // metadata layout is shared between maple compiler and runtime, thus not in namespace maplert -// data types for address offset -#ifdef USE_32BIT_REF -using AddrOffset = int32_t; -#else -using AddrOffset = intptr_t; -#endif - // some of the reference field of metadata is stored as relative offset // for example, declaring class of Fields/Methods // which can be negative @@ -64,16 +57,40 @@ static inline void EncodeValueAsRelOffset64(const void *value, int64_t *addr) { // DataRefOffset is meant to have pointer size and aligned to at least 4 bytes. struct DataRefOffset32 { int32_t refOffset; - inline void SetDataRef(void *ref); - inline void *GetDataRef() const; + template + inline void SetDataRef(T ref); + template + inline T GetDataRef() const; + inline int32_t GetRawValue() const; + inline void SetRawValue(int64_t value); }; -struct DataRefOffset { +struct DataRefOffset64 { intptr_t refOffset; - inline void SetDataRef(void *ref); - inline void *GetDataRef() const; + template + inline void SetDataRef(T ref); + template + inline T GetDataRef() const; + inline bool IsCompact() const; + template + inline T GetCompactData() const; + inline int64_t GetRawValue() const; + inline void SetRawValue(int64_t value); }; +struct DataRefOffset { +#ifdef USE_32BIT_REF + DataRefOffset32 refOffset; +#else + DataRefOffset64 refOffset; +#endif + template + inline void SetDataRef(T ref); + template + inline T GetDataRef() const; + inline int64_t GetRawValue() const; + inline void SetRawValue(int64_t value); +}; /* DataRef aims for reference to data in maple file (generated by maple compiler) and is aligned to at least 4 bytes. Perhaps MDataRef is more fit, still DataRef is chosen to make it common. DataRef allows 4 formats of value: @@ -83,7 +100,7 @@ struct DataRefOffset { 3. "indirect.label_name - . + 3" for indirect reference this format aims to support lld which does not support expression "global_symbol - ." DataRef is self-decoded by also encoding the format and is defined for binary compatibility. - If no compatibility problem is involved, DataRefOffset is preferred. + If no compatibility problem is involved, DataRefOffset64 is preferred. */ enum DataRefFormat { @@ -97,14 +114,22 @@ enum DataRefFormat { struct DataRef32 { // be careful when *refVal* is treated as an offset which is a signed integer actually. uint32_t refVal; - inline void *GetDataRef() const; - inline void SetDataRef(void *ref, DataRefFormat format = kDataRefIsDirect); + template + inline T GetDataRef() const; + template + inline void SetDataRef(T ref, DataRefFormat format = kDataRefIsDirect); + template + inline T GetRawValue() const; }; struct DataRef { - void *refVal; - inline void *GetDataRef() const; - inline void SetDataRef(void *ref, DataRefFormat format = kDataRefIsDirect); + uint64_t refVal; + template + inline T GetDataRef() const; + template + inline void SetDataRef(T ref, DataRefFormat format = kDataRefIsDirect); + template + inline T GetRawValue() const; }; /* GctibRef aims to represent a reference to gctib in maple file, which is an offset by default. @@ -125,21 +150,25 @@ enum GctibRefFormat { struct GctibRef32 { // be careful when *refVal* is treated as an offset which is a signed integer actually. uint32_t refVal; - inline void *GetGctibRef() const; - inline void SetGctibRef(void *ref, GctibRefFormat format = kGctibRefIsOffset); + template + inline T GetGctibRef() const; + template + inline void SetGctibRef(T ref, GctibRefFormat format = kGctibRefIsOffset); }; struct GctibRef { - void *refVal; - inline void *GetGctibRef() const; - inline void SetGctibRef(void *ref, GctibRefFormat format = kGctibRefIsOffset); + uint64_t refVal; + template + inline T GetGctibRef() const; + template + inline void SetGctibRef(T ref, GctibRefFormat format = kGctibRefIsOffset); }; // MByteRef is meant to represent a reference to data defined in maple file. It is a direct reference or an offset. // MByteRef is self-encoded/decoded and aligned to 1 byte. // Unlike DataRef, the format of MByteRef is determined by its value. struct MByteRef { - void *refVal; // initializer prefers this field to be a pointer + uint64_t refVal; // initializer prefers this field to be a pointer enum { kBiasBitPosition = sizeof(refVal) * 8 - 4, // the most significant 3 bits }; @@ -150,8 +179,10 @@ struct MByteRef { static constexpr uintptr_t PositiveOffsetMin = 0 + PositiveOffsetBias; static constexpr uintptr_t PositiveOffsetMax = FarthestOffset + PositiveOffsetBias; - inline void *GetRef() const; - inline void SetRef(void *ref); + template + inline T GetRef() const; + template + inline void SetRef(T ref); inline bool IsOffset() const; }; @@ -169,8 +200,10 @@ struct MByteRef32 { static constexpr int32_t NegativeOffsetMin = -FarthestOffset; static constexpr int32_t NegativeOffsetMax = 0; - inline void *GetRef() const; - inline void SetRef(void *ref); + template + inline T GetRef() const; + template + inline void SetRef(T ref); inline bool IsOffset() const; inline bool IsPositiveOffset() const; inline bool IsNegativeOffset() const; @@ -195,11 +228,11 @@ struct MethodDesc { // update aarch64rtsupport.h if you modify this definition. struct ClassMetadataRO { MByteRef className; - int64_t fields; // point to info of fields - int64_t methods; // point to info of methods + DataRefOffset64 fields; // point to info of fields + DataRefOffset64 methods; // point to info of methods union { // Element classinfo of array, others parent classinfo DataRef superclass; - struct ClassMetadata *componentClass; + DataRef componentClass; }; uint16_t numOfFields; @@ -211,9 +244,9 @@ struct ClassMetadataRO { uint32_t padding; #endif // !USE_32BIT_REF - uint32_t mod; // 32 bit 0X00000000 modifier: 0x00FFFFFF override: 0x80000000 - int32_t annotation; - int32_t clinitAddr; + uint32_t mod; + DataRefOffset32 annotation; + DataRefOffset32 clinitAddr; }; static constexpr size_t PageSize = 4096; @@ -270,16 +303,20 @@ struct ClassMetadata { GctibRef gctib; // for rc union { - DataRef classinforo64; // ifndef USE_32BIT_REF + DataRef ro; struct { - DataRef32 classinforo32; // ifdef USE_32BIT_REF - uint32_t cacheFalseClass; + #ifdef USE_32BIT_REF + DataRef32 classinforo; + DataRef32 cacheFalseClass; + #else + DataRef classinforo; + #endif }; }; union { - void *initState; // a readable address for initState means initialized - void *cacheTrueClass; + uint64_t initState; // a readable address for initState means initialized + DataRef cacheTrueClass; }; public: @@ -288,12 +325,13 @@ struct ClassMetadata { return reinterpret_cast(&(base->initState)); } - void *GetInitStateRawValue() { + uint64_t GetInitStateRawValue() { return __atomic_load_n(&initState, __ATOMIC_ACQUIRE); } - void SetInitStateRawValue(void *val) { - __atomic_store_n(&initState, val, __ATOMIC_RELEASE); + template + void SetInitStateRawValue(T val) { + __atomic_store_n(&initState, reinterpret_cast(val), __ATOMIC_RELEASE); } }; diff --git a/src/maple_ir/include/mir_module.h b/src/maple_ir/include/mir_module.h index ac7ecef60d5113a13ab14e2ffdd59230d3b88be9..24ed8f9f0717408c08a00324caf07ece02f20fa2 100644 --- a/src/maple_ir/include/mir_module.h +++ b/src/maple_ir/include/mir_module.h @@ -432,33 +432,33 @@ class MIRModule { return classList; } - const std::map> &GetMethod2TargetMap() const { + const std::map> &GetMethod2TargetMap() const { return method2TargetMap; } - std::vector &GetMemFromMethod2TargetMap(PUIdx methodPuIdx) { + std::vector &GetMemFromMethod2TargetMap(PUIdx methodPuIdx) { return method2TargetMap[methodPuIdx]; } - void SetMethod2TargetMap(const std::map> &map) { + void SetMethod2TargetMap(const std::map> &map) { method2TargetMap = map; } - void AddMemToMethod2TargetMap(PUIdx idx, const std::vector &callSite) { + void AddMemToMethod2TargetMap(PUIdx idx, const std::vector &callSite) { method2TargetMap[idx] = callSite; } - bool HasTargetHash(PUIdx idx, uint32 key) const { + bool HasTargetHash(PUIdx idx, uint64 key) const { auto it = method2TargetHash.find(idx); if (it == method2TargetHash.end()) { return false; } return it->second.find(key) != it->second.end(); } - void InsertTargetHash(PUIdx idx, uint32 key) { + void InsertTargetHash(PUIdx idx, uint64 key) { method2TargetHash[idx].insert(key); } - void AddValueToMethod2TargetHash(PUIdx idx, const std::unordered_set &value) { + void AddValueToMethod2TargetHash(PUIdx idx, const std::unordered_set &value) { method2TargetHash[idx] = value; } @@ -520,8 +520,8 @@ class MIRModule { MapleVector importPaths; MapleSet classList; - std::map> method2TargetMap; - std::map> method2TargetHash; + std::map> method2TargetMap; + std::map> method2TargetHash; std::map eaSummary; MIRFunction *entryFunc = nullptr; diff --git a/src/maple_ir/src/mir_nodes.cpp b/src/maple_ir/src/mir_nodes.cpp index f25bc6559d3880c90890bf2ea4a352ca1cc9e49c..0dc21f67fcde91373c3707f566609fd585223b8d 100644 --- a/src/maple_ir/src/mir_nodes.cpp +++ b/src/maple_ir/src/mir_nodes.cpp @@ -245,6 +245,7 @@ void RetypeNode::Dump(int32 indent) const { ty->Dump(indent + 1); } DumpOpnd(*theMIRModule, indent); + LogInfo::MapleLogger() << "\n"; } void ExtractbitsNode::Dump(int32 indent) const { diff --git a/src/maple_me/include/dominance.h b/src/maple_me/include/dominance.h index 5c9360ecba6588619c93b8203f8748352eb80449..25096d4bf2a9840ea47b5befec207d3eeb54359f 100644 --- a/src/maple_me/include/dominance.h +++ b/src/maple_me/include/dominance.h @@ -50,7 +50,7 @@ class Dominance : public AnalysisResult { void ComputeDomChildren(); void ComputeDtPreorder(const BB &bb, size_t &num); void ComputeDtDfn(); - bool Dominate(const BB &bb1, BB &bb2); // true if bb1 dominates bb2 + bool Dominate(const BB &bb1, const BB &bb2); // true if bb1 dominates bb2 void DumpDoms(); void PdomGenPostOrderID(); void ComputePostDominance(); diff --git a/src/maple_me/include/irmap.h b/src/maple_me/include/irmap.h index 57298d79f90fe3584f7fb25dc630e6f7c9765bba..f91c098d7db650c44d568f2d55ddb62e5c331cf8 100644 --- a/src/maple_me/include/irmap.h +++ b/src/maple_me/include/irmap.h @@ -245,7 +245,7 @@ class IRMap : public AnalysisResult { void BuildMustDefList(MeStmt &meStmt, MapleVector&, MapleVector&); void BuildMuList(MapleMap&, MapleMap&); void BuildPhiMeNode(BB&); - BB *GetFalseBrBB(CondGotoMeStmt&); + BB *GetFalseBrBB(const CondGotoMeStmt&); void SetMeExprOpnds(MeExpr &meExpr, BaseNode &mirNode); static bool InitMeStmtFactory(); MeStmt *BuildDassignMeStmt(StmtNode &stmt, AccessSSANodes &ssaPart); diff --git a/src/maple_me/include/me_analyze_rc.h b/src/maple_me/include/me_analyze_rc.h index e166f7a32cdc7a3ceeb4a4013a2c41d0654ab8c5..60b19260df7488122cd0dbe0b5b964b3c0e07499 100644 --- a/src/maple_me/include/me_analyze_rc.h +++ b/src/maple_me/include/me_analyze_rc.h @@ -70,7 +70,7 @@ class AnalyzeRC { void RemoveUnneededCleanups(); void RenameUses(MeStmt &meStmt); RCItem *FindOrCreateRCItem(const OriginalSt &ost); - OriginalSt *GetOriginalSt(MeExpr &refLHS); + OriginalSt *GetOriginalSt(const MeExpr &refLHS); VarMeExpr *GetZeroVersionVarMeExpr(const VarMeExpr &var); bool NeedIncref(const MeStmt &stmt); UnaryMeStmt *CreateIncrefZeroVersion(const OriginalSt &ost); @@ -78,7 +78,7 @@ class AnalyzeRC { void TraverseStmt(BB &bb); bool NeedDecRef(RCItem &rcItem, MeExpr &expr); bool NeedDecRef(IvarMeExpr &ivar); - bool NeedDecRef(VarMeExpr &var); + bool NeedDecRef(const VarMeExpr &var); friend class MeDoAnalyzeRC; MeFunction &func; diff --git a/src/maple_me/include/me_bypath_eh.h b/src/maple_me/include/me_bypath_eh.h index dcec8375254b1e1a826c2dce330ae4a4ced6c846..4b7683fc18305b945e39eca336b4240f5429897f 100644 --- a/src/maple_me/include/me_bypath_eh.h +++ b/src/maple_me/include/me_bypath_eh.h @@ -31,10 +31,10 @@ class MeDoBypathEH : public MeFuncPhase { return "bypatheh"; } private: - bool DoBypathException(BB *tryBB, BB *catchBB, Klass *catchClass, StIdx e, KlassHierarchy *kh, MeFunction *func, - StmtNode *syncExitStmt); + bool DoBypathException(BB *tryBB, BB *catchBB, const Klass *catchClass, const StIdx &stIdx, + const KlassHierarchy *kh, MeFunction *func, const StmtNode *syncExitStmt); StmtNode *IsSyncExit(BB *syncBB, MeFunction *func, LabelIdx secondLabel); - void BypathException(MeFunction *func, KlassHierarchy *kh); + void BypathException(MeFunction *func, const KlassHierarchy *kh); }; } // namespace maple #endif diff --git a/src/maple_me/include/me_cond_based.h b/src/maple_me/include/me_cond_based.h index e78903c8d1840b2e55fffbbb0f9cdc371a1035b9..36045f2a5fcc02630cd3c337b203bc312b7eb7a2 100644 --- a/src/maple_me/include/me_cond_based.h +++ b/src/maple_me/include/me_cond_based.h @@ -25,19 +25,19 @@ class MeCondBased { MeCondBased(MeFunction *func, Dominance *dom) : func(func), dominance(dom) {} ~MeCondBased() = default; - bool NullValueFromTestCond(VarMeExpr&, BB&, bool); - bool IsNotNullValue(VarMeExpr&, UnaryMeStmt&, BB*); + bool NullValueFromTestCond(const VarMeExpr&, const BB&, bool); + bool IsNotNullValue(const VarMeExpr&, const UnaryMeStmt&, const BB*); const MeFunction *GetFunc() const { return func; } private: - bool NullValueFromOneTestCond(const VarMeExpr&, BB&, BB&, bool); - bool PointerWasDereferencedBefore(VarMeExpr&, const UnaryMeStmt&, BB*); - bool PointerWasDereferencedRightAfter(VarMeExpr&, const UnaryMeStmt&); - bool IsIreadWithTheBase(VarMeExpr&, MeExpr&); - bool StmtHasDereferencedBase(MeStmt&, VarMeExpr&); + bool NullValueFromOneTestCond(const VarMeExpr&, const BB&, const BB&, bool); + bool PointerWasDereferencedBefore(const VarMeExpr&, const UnaryMeStmt&, const BB*); + bool PointerWasDereferencedRightAfter(const VarMeExpr&, const UnaryMeStmt&); + bool IsIreadWithTheBase(const VarMeExpr&, const MeExpr&); + bool StmtHasDereferencedBase(const MeStmt&, const VarMeExpr&); MeFunction *func; Dominance *dominance; diff --git a/src/maple_me/include/me_delegate_rc.h b/src/maple_me/include/me_delegate_rc.h index fd98afbd1b90ee93c9cbcf937e19870ec54f150c..e18408c83fda1cf4de46b1dfd44f95a8e54e8913 100644 --- a/src/maple_me/include/me_delegate_rc.h +++ b/src/maple_me/include/me_delegate_rc.h @@ -41,7 +41,7 @@ class DelegateRC { void CleanUpDeadLocalRefVar(const std::set &liveLocalrefvars); private: - bool IsCopiedOrDerefedOp(const Opcode op); + bool IsCopiedOrDerefedOp(const Opcode op) const; void CollectVstCantDecrefEarly(MeExpr &opnd0, MeExpr &opnd1); void CollectUseCounts(const MeExpr &x); void FindAndDecrUseCount(VarMeExpr *rhsVar, MeExpr *x, int32 &remainingUses); diff --git a/src/maple_me/include/me_ir.h b/src/maple_me/include/me_ir.h index dca6e145167fbc10b92d486baed5da3174bc39b9..c99036a2d6b7c09a0cf71c967834eeaddde4406b 100644 --- a/src/maple_me/include/me_ir.h +++ b/src/maple_me/include/me_ir.h @@ -223,7 +223,7 @@ class VarMeExpr final : public MeExpr { // indicate if the variable is local variable but not a function formal variable bool IsPureLocal(const SSATab&, const MIRFunction&) const; bool IsZeroVersion(const SSATab&) const; - BB *GetDefByBBMeStmt(const Dominance&, MeStmtPtr&); + BB *GetDefByBBMeStmt(const Dominance&, MeStmtPtr&) const; bool IsSameVariableValue(const VarMeExpr&) const override; VarMeExpr &ResolveVarMeValue(); bool PointsToStringLiteral(); @@ -1945,14 +1945,34 @@ class NaryMeStmt : public MeStmt { opnds[idx] = val; } - MapleVector &GetOpnds() { + const MapleVector &GetOpnds() const { return opnds; } + void PushBackOpnd(MeExpr *val) { + opnds.push_back(val); + } + + void PopBackOpnd() { + opnds.pop_back(); + } + void SetOpnds(MapleVector &opndsVal) { opnds = opndsVal; } + void EraseOpnds(const MapleVector::const_iterator begin, const MapleVector::const_iterator end) { + opnds.erase(begin, end); + } + + void EraseOpnds(const MapleVector::const_iterator it) { + opnds.erase(it); + } + + void InsertOpnds(const MapleVector::const_iterator begin, MeExpr *expr) { + opnds.insert(begin, expr); + } + void DumpOpnds(IRMap*) const; void Dump(IRMap*) const; virtual MapleMap *GetMuList() { @@ -2407,7 +2427,7 @@ class CondGotoMeStmt : public UnaryMeStmt { ~CondGotoMeStmt() = default; - uint32 GetOffset() { + uint32 GetOffset() const { return offset; } diff --git a/src/maple_me/include/ssa_devirtual.h b/src/maple_me/include/ssa_devirtual.h index d96702b58a299a14d9000b9f77977061c4d6ad4e..b69838368cb52863e676431a79b04c100b96a1c8 100644 --- a/src/maple_me/include/ssa_devirtual.h +++ b/src/maple_me/include/ssa_devirtual.h @@ -57,7 +57,7 @@ class SSADevirtual { void VisitMeExpr(MeExpr*); void PropVarInferredType(VarMeExpr*); void PropIvarInferredType(IvarMeExpr*); - void ReturnTyIdxInferring(RetMeStmt*); + void ReturnTyIdxInferring(const RetMeStmt*); bool NeedNullCheck(MeExpr*) const; void InsertNullCheck(CallMeStmt*, MeExpr*); bool DevirtualizeCall(CallMeStmt*); diff --git a/src/maple_me/src/dominance.cpp b/src/maple_me/src/dominance.cpp index d6c11818bf44dc894ddb2224bd1cbd4597620f59..d52a5cebbaadfa56740781f7f278b70608048029 100644 --- a/src/maple_me/src/dominance.cpp +++ b/src/maple_me/src/dominance.cpp @@ -154,14 +154,14 @@ void Dominance::ComputeDtDfn() { } // true if b1 dominates b2 -bool Dominance::Dominate(const BB &bb1, BB &bb2) { +bool Dominance::Dominate(const BB &bb1, const BB &bb2) { if (&bb1 == &bb2) { return true; } if (doms[bb2.GetBBId()] == nullptr) { return false; } - BB *immediateDom = &bb2; + const BB *immediateDom = &bb2; do { if (immediateDom == nullptr) { return false; diff --git a/src/maple_me/src/irmap.cpp b/src/maple_me/src/irmap.cpp index 3f6b9b59da8ae74cc23a3d3f24e20443a4032901..09c3783e10d7c4b7be3132cce8c0bd81830cba33 100644 --- a/src/maple_me/src/irmap.cpp +++ b/src/maple_me/src/irmap.cpp @@ -495,7 +495,7 @@ MeStmt *IRMap::BuildCallMeStmt(StmtNode &stmt, AccessSSANodes &ssaPart) { auto &intrinNode = static_cast(stmt); callMeStmt->SetPUIdx(intrinNode.GetPUIdx()); for (size_t i = 0; i < intrinNode.NumOpnds(); ++i) { - callMeStmt->GetOpnds().push_back(BuildExpr(*intrinNode.Opnd(i))); + callMeStmt->PushBackOpnd(BuildExpr(*intrinNode.Opnd(i))); } BuildMuList(ssaPart.GetMayUseNodes(), *(callMeStmt->GetMuList())); if (kOpcodeInfo.IsCallAssigned(stmt.GetOpCode())) { @@ -513,7 +513,7 @@ MeStmt *IRMap::BuildNaryMeStmt(StmtNode &stmt, AccessSSANodes &ssaPart) { : static_cast(NewInPool(&stmt)); auto &naryStmtNode = static_cast(stmt); for (size_t i = 0; i < naryStmtNode.NumOpnds(); ++i) { - naryMeStmt->GetOpnds().push_back(BuildExpr(*naryStmtNode.Opnd(i))); + naryMeStmt->PushBackOpnd(BuildExpr(*naryStmtNode.Opnd(i))); } BuildMuList(ssaPart.GetMayUseNodes(), *(naryMeStmt->GetMuList())); if (kOpcodeInfo.IsCallAssigned(op)) { @@ -527,7 +527,7 @@ MeStmt *IRMap::BuildRetMeStmt(StmtNode &stmt, AccessSSANodes &ssaPart) { auto &retStmt = static_cast(stmt); auto *meStmt = NewInPool(&stmt); for (size_t i = 0; i < retStmt.NumOpnds(); ++i) { - meStmt->GetOpnds().push_back(BuildExpr(*retStmt.Opnd(i))); + meStmt->PushBackOpnd(BuildExpr(*retStmt.Opnd(i))); } BuildMuList(ssaPart.GetMayUseNodes(), *(meStmt->GetMuList())); return meStmt; @@ -557,7 +557,7 @@ MeStmt *IRMap::BuildSyncMeStmt(StmtNode &stmt, AccessSSANodes &ssaPart) { auto &naryNode = static_cast(stmt); auto *naryStmt = NewInPool(&stmt); for (size_t i = 0; i < naryNode.NumOpnds(); ++i) { - naryStmt->GetOpnds().push_back(BuildExpr(*naryNode.Opnd(i))); + naryStmt->PushBackOpnd(BuildExpr(*naryNode.Opnd(i))); } BuildMuList(ssaPart.GetMayUseNodes(), *(naryStmt->GetMuList())); BuildChiList(*naryStmt, ssaPart.GetMayDefNodes(), *(naryStmt->GetChiList())); @@ -843,7 +843,7 @@ RegassignMeStmt *IRMap::CreateRegassignMeStmt(MeExpr &lhs, MeExpr &rhs, BB &curr // get the false goto bb, if condgoto is brtrue, take the other bb of brture @lable // otherwise, take the bb of @lable -BB *IRMap::GetFalseBrBB(CondGotoMeStmt &condgoto) { +BB *IRMap::GetFalseBrBB(const CondGotoMeStmt &condgoto) { LabelIdx lblIdx = (LabelIdx)condgoto.GetOffset(); BB *gotoBB = GetBBForLabIdx(lblIdx); BB *bb = condgoto.GetBB(); @@ -908,7 +908,7 @@ IntrinsiccallMeStmt *IRMap::CreateIntrinsicCallMeStmt(MIRIntrinsicID idx, std::v auto *meStmt = NewInPool(tyIdx == 0u ? OP_intrinsiccall : OP_intrinsiccallwithtype, idx, tyIdx); for (MeExpr *opnd : opnds) { - meStmt->GetOpnds().push_back(opnd); + meStmt->PushBackOpnd(opnd); } return meStmt; } @@ -918,7 +918,7 @@ IntrinsiccallMeStmt *IRMap::CreateIntrinsicCallAssignedMeStmt(MIRIntrinsicID idx auto *meStmt = NewInPool( tyIdx == 0u ? OP_intrinsiccallassigned : OP_intrinsiccallwithtypeassigned, idx, tyIdx); for (MeExpr *opnd : opnds) { - meStmt->GetOpnds().push_back(opnd); + meStmt->PushBackOpnd(opnd); } if (ret != nullptr) { ASSERT(ret->GetMeOp() == kMeOpReg || ret->GetMeOp() == kMeOpVar, "unexpected opcode"); diff --git a/src/maple_me/src/me_analyze_rc.cpp b/src/maple_me/src/me_analyze_rc.cpp index 8f67462c18267289f9332bf33ddf4b9462b2c4d3..2dad12daf52b2da55df9861f69cbc06423c308a6 100644 --- a/src/maple_me/src/me_analyze_rc.cpp +++ b/src/maple_me/src/me_analyze_rc.cpp @@ -102,13 +102,13 @@ RCItem *AnalyzeRC::FindOrCreateRCItem(const OriginalSt &ost) { return rcItem; } -OriginalSt *AnalyzeRC::GetOriginalSt(MeExpr &refLHS) { +OriginalSt *AnalyzeRC::GetOriginalSt(const MeExpr &refLHS) { if (refLHS.GetMeOp() == kMeOpVar) { - auto &varMeExpr = static_cast(refLHS); + auto &varMeExpr = static_cast(refLHS); return ssaTab.GetSymbolOriginalStFromID(varMeExpr.GetOStIdx()); } ASSERT(refLHS.GetMeOp() == kMeOpIvar, "GetOriginalSt: unexpected node type"); - auto &ivarMeExpr = static_cast(refLHS); + auto &ivarMeExpr = static_cast(refLHS); if (ivarMeExpr.GetMu() != nullptr) { return ssaTab.GetSymbolOriginalStFromID(ivarMeExpr.GetMu()->GetOStIdx()); } @@ -371,7 +371,7 @@ bool AnalyzeRC::NeedDecRef(IvarMeExpr &ivar) { return ivar.GetMu()->GetVstIdx() != ost->GetZeroVersionIndex() && ivar.GetMu()->GetDefBy() != kDefByNo; } -bool AnalyzeRC::NeedDecRef(VarMeExpr &var) { +bool AnalyzeRC::NeedDecRef(const VarMeExpr &var) { OriginalSt *ost = GetOriginalSt(var); return var.GetVstIdx() != ost->GetZeroVersionIndex() && var.GetDefBy() != kDefByNo; } @@ -394,17 +394,17 @@ void AnalyzeRC::RemoveUnneededCleanups() { size_t nextPos = 0; size_t i = 0; for (; i < intrn->NumMeStmtOpnds(); ++i) { - auto varMeExpr = static_cast(intrn->GetOpnds()[i]); + auto varMeExpr = static_cast(intrn->GetOpnd(i)); if (varMeExpr->IsZeroVersion(ssaTab)) { continue; } if (nextPos != i) { - intrn->GetOpnds()[nextPos] = varMeExpr; + intrn->SetOpnd(nextPos, varMeExpr); } ++nextPos; } while (nextPos < i) { - intrn->GetOpnds().pop_back(); + intrn->PopBackOpnd(); --i; } if (intrn->NumMeStmtOpnds() > kCleanupLocalRefVarsLimit) { diff --git a/src/maple_me/src/me_bypath_eh.cpp b/src/maple_me/src/me_bypath_eh.cpp index b761812a570c54d4d894a305c4371de08cf7b0d1..16d9330465466f6a51e6c27a9bc5ecd45058ba43 100644 --- a/src/maple_me/src/me_bypath_eh.cpp +++ b/src/maple_me/src/me_bypath_eh.cpp @@ -20,8 +20,8 @@ #include "me_function.h" namespace maple { -bool MeDoBypathEH::DoBypathException(BB *tryBB, BB *catchBB, Klass *catchClass, StIdx e, KlassHierarchy *kh, - MeFunction *func, StmtNode *syncExitStmt) { +bool MeDoBypathEH::DoBypathException(BB *tryBB, BB *catchBB, const Klass *catchClass, const StIdx &stIdx, + const KlassHierarchy *kh, MeFunction *func, const StmtNode *syncExitStmt) { std::vector tryBBV; std::set tryBBS; tryBBV.push_back(tryBB); @@ -65,7 +65,7 @@ bool MeDoBypathEH::DoBypathException(BB *tryBB, BB *catchBB, Klass *catchClass, continue; } MIRBuilder *mBuilder = func->GetMIRModule().GetMIRBuilder(); - DassignNode *copyStmt = mBuilder->CreateStmtDassign(e, 0, rhExpr); + DassignNode *copyStmt = mBuilder->CreateStmtDassign(stIdx, 0, rhExpr); bb->InsertStmtBefore(stmt, copyStmt); GotoNode *gotoNode = mBuilder->CreateStmtGoto(OP_goto, catchBB->GetBBLabel()); bb->ReplaceStmt(stmt, gotoNode); @@ -196,7 +196,7 @@ StmtNode *MeDoBypathEH::IsSyncExit(BB *syncBB, MeFunction *func, LabelIdx second return syncExitStmt; } -void MeDoBypathEH::BypathException(MeFunction *func, KlassHierarchy *kh) { +void MeDoBypathEH::BypathException(MeFunction *func, const KlassHierarchy *kh) { // Condition check: // 1. There is only one catch statement, and the catch can handle the thrown exception auto labelIdx = static_cast(-1); diff --git a/src/maple_me/src/me_cond_based_opt.cpp b/src/maple_me/src/me_cond_based_opt.cpp index e9de6d842878c58292ed51299204f4bcbe2ce692..d059b217d79efaae41afd616a38fd3637d898824 100644 --- a/src/maple_me/src/me_cond_based_opt.cpp +++ b/src/maple_me/src/me_cond_based_opt.cpp @@ -36,7 +36,7 @@ namespace maple { // check if varmeexpr is under the condition varmeexpr == 0 when expectedEq0 is true, // or varmeexpr != 0 if expectedEq0 is false -bool MeCondBased::NullValueFromOneTestCond(const VarMeExpr &varMeExpr, BB &cdBB, BB &bb, bool expectedEq0) { +bool MeCondBased::NullValueFromOneTestCond(const VarMeExpr &varMeExpr, const BB &cdBB, const BB &bb, bool expectedEq0) { auto &meStmts = cdBB.GetMeStmts(); if (meStmts.empty()) { return false; @@ -44,7 +44,7 @@ bool MeCondBased::NullValueFromOneTestCond(const VarMeExpr &varMeExpr, BB &cdBB, if (!meStmts.back().IsCondBr()) { return false; } - auto &condBrMeStmt = static_cast(meStmts.back()); + auto &condBrMeStmt = static_cast(meStmts.back()); bool isTrueBr = condBrMeStmt.GetOp() == OP_brtrue; MeExpr *testMeExpr = condBrMeStmt.GetOpnd(); if (testMeExpr->GetOp() != OP_eq && testMeExpr->GetOp() != OP_ne) { @@ -62,9 +62,9 @@ bool MeCondBased::NullValueFromOneTestCond(const VarMeExpr &varMeExpr, BB &cdBB, if (!cmpMeExpr->GetOpnd(0)->IsSameVariableValue(varMeExpr)) { return false; } - BB *sucDomBB = nullptr; + const BB *sucDomBB = nullptr; for (size_t i = 0; i < cdBB.GetSucc().size(); ++i) { - BB *sucBB = cdBB.GetSucc(i); + const BB *sucBB = cdBB.GetSucc(i); if (dominance->Dominate(*sucBB, bb)) { sucDomBB = sucBB; break; @@ -80,7 +80,7 @@ bool MeCondBased::NullValueFromOneTestCond(const VarMeExpr &varMeExpr, BB &cdBB, return isJumptoBB ? ((isTrueBr && !isEq) || (!isTrueBr && isEq)) : ((isTrueBr && isEq) || (!isTrueBr && !isEq)); } -bool MeCondBased::NullValueFromTestCond(VarMeExpr &varMeExpr, BB &bb, bool expectedEq0) { +bool MeCondBased::NullValueFromTestCond(const VarMeExpr &varMeExpr, const BB &bb, bool expectedEq0) { MapleSet *pdomFrt = &dominance->GetPdomFrontierItem(bb.GetBBId()); size_t bbSize = dominance->GetBBVecSize(); std::vector visitedMap(bbSize, false); @@ -100,9 +100,9 @@ bool MeCondBased::NullValueFromTestCond(VarMeExpr &varMeExpr, BB &bb, bool expec return provenNull; } -bool MeCondBased::IsIreadWithTheBase(VarMeExpr &var, MeExpr &meExpr) { +bool MeCondBased::IsIreadWithTheBase(const VarMeExpr &var, const MeExpr &meExpr) { if (meExpr.GetOp() == OP_iread) { - auto &ivarMeExpr = static_cast(meExpr); + auto &ivarMeExpr = static_cast(meExpr); if (ivarMeExpr.GetBase()->GetExprID() == var.GetExprID()) { return true; } @@ -115,16 +115,16 @@ bool MeCondBased::IsIreadWithTheBase(VarMeExpr &var, MeExpr &meExpr) { return false; } -bool MeCondBased::StmtHasDereferencedBase(MeStmt &stmt, VarMeExpr &var) { +bool MeCondBased::StmtHasDereferencedBase(const MeStmt &stmt, const VarMeExpr &var) { if (stmt.GetOp() == OP_iassign) { - auto &iassStmt = static_cast(stmt); + auto &iassStmt = static_cast(stmt); if (iassStmt.GetLHSVal()->GetBase()->GetExprID() == var.GetExprID()) { return true; } } if (stmt.GetOp() == OP_syncenter || stmt.GetOp() == OP_syncexit) { - auto &syncMeStmt = static_cast(stmt); - MapleVector &opnds = syncMeStmt.GetOpnds(); + auto &syncMeStmt = static_cast(stmt); + const MapleVector &opnds = syncMeStmt.GetOpnds(); for (auto it = opnds.begin(); it != opnds.end(); ++it) { if ((*it)->GetExprID() == var.GetExprID()) { return true; @@ -140,7 +140,7 @@ bool MeCondBased::StmtHasDereferencedBase(MeStmt &stmt, VarMeExpr &var) { return false; } -bool MeCondBased::PointerWasDereferencedBefore(VarMeExpr &var, const UnaryMeStmt &assertMeStmt, BB *bb) { +bool MeCondBased::PointerWasDereferencedBefore(const VarMeExpr &var, const UnaryMeStmt &assertMeStmt, const BB *bb) { // If var is defined in the function, let BBx be the BB that defines var. // If var is not defined, then let BBx be the function entry BB. // Let BBy be the current BB that contains the assertnonnull. @@ -180,7 +180,7 @@ bool MeCondBased::PointerWasDereferencedBefore(VarMeExpr &var, const UnaryMeStmt return false; } -bool MeCondBased::PointerWasDereferencedRightAfter(VarMeExpr &var, const UnaryMeStmt &assertMeStmt) { +bool MeCondBased::PointerWasDereferencedRightAfter(const VarMeExpr &var, const UnaryMeStmt &assertMeStmt) { // assertnonnull(var) // t = iread(var, 0) // we can safely delete assertnonnull(var) @@ -194,7 +194,7 @@ bool MeCondBased::PointerWasDereferencedRightAfter(VarMeExpr &var, const UnaryMe return (nextMeStmt != nullptr) && StmtHasDereferencedBase(*nextMeStmt, var); } -bool MeCondBased::IsNotNullValue(VarMeExpr &varMeExpr, UnaryMeStmt &assertMeStmt, BB *bb) { +bool MeCondBased::IsNotNullValue(const VarMeExpr &varMeExpr, const UnaryMeStmt &assertMeStmt, const BB *bb) { const OriginalSt *varOst = func->GetMeSSATab()->GetSymbolOriginalStFromID(varMeExpr.GetOStIdx()); if (varOst->IsFormal() && varOst->GetMIRSymbol()->GetName() == kStrThisPointer) { return true; diff --git a/src/maple_me/src/me_delegate_rc.cpp b/src/maple_me/src/me_delegate_rc.cpp index f2d33d5d78ab15cfa7ad19b52a13ef96e26335ec..231e097a6aced4ebb77065ae5d088eb144eb5a2c 100644 --- a/src/maple_me/src/me_delegate_rc.cpp +++ b/src/maple_me/src/me_delegate_rc.cpp @@ -107,7 +107,7 @@ void DelegateRC::SaveDerefedOrCopiedVst(const MeExpr *expr) { } } -bool DelegateRC::IsCopiedOrDerefedOp(const Opcode op) { +bool DelegateRC::IsCopiedOrDerefedOp(const Opcode op) const { return op == OP_dassign || op == OP_maydassign || op == OP_regassign || op == OP_syncenter || op == OP_syncexit || op == OP_throw || op == OP_return || op == OP_iassign || // cause var copied kOpcodeInfo.IsCall(op); // callstmt need considering parameter @@ -763,7 +763,7 @@ void DelegateRC::CleanUpDeadLocalRefVar(const std::set &liveLocalrefvars } ++nextPos; } - intrin->GetOpnds().erase(intrin->GetOpnds().begin() + nextPos, intrin->GetOpnds().end()); + intrin->EraseOpnds(intrin->GetOpnds().begin() + nextPos, intrin->GetOpnds().end()); } } diff --git a/src/maple_me/src/me_ir.cpp b/src/maple_me/src/me_ir.cpp index 3de43c41837064a505f47c29543204bccd8cac51..793b45e4d9fbb5791b8d628f7e02316db15a646a 100644 --- a/src/maple_me/src/me_ir.cpp +++ b/src/maple_me/src/me_ir.cpp @@ -439,7 +439,7 @@ MeExpr *IvarMeExpr::GetIdenticalExpr(MeExpr &expr) const { return nullptr; } -BB *VarMeExpr::GetDefByBBMeStmt(const Dominance &dominance, MeStmtPtr &defMeStmt) { +BB *VarMeExpr::GetDefByBBMeStmt(const Dominance &dominance, MeStmtPtr &defMeStmt) const { switch (defBy) { case kDefByNo: return &dominance.GetCommonEntryBB(); diff --git a/src/maple_me/src/me_lower_globals.cpp b/src/maple_me/src/me_lower_globals.cpp index 298b0bed700a595069190153d04bac0f83ae0ddd..e98cda45af5b36f3264113578a8b1eee5bea58d0 100644 --- a/src/maple_me/src/me_lower_globals.cpp +++ b/src/maple_me/src/me_lower_globals.cpp @@ -143,12 +143,12 @@ void MeLowerGlobals::Run() { } MeExpr *addroffuncExpr = irMap->CreateAddroffuncMeExpr(callee.GetPuidx()); auto insertpos = callStmt.GetOpnds().begin(); - callStmt.GetOpnds().insert(insertpos, addroffuncExpr); + callStmt.InsertOpnds(insertpos, addroffuncExpr); IcallMeStmt *icallStmt = irMap->NewInPool(stmt.GetOp() == OP_call ? OP_icall : OP_icallassigned); icallStmt->SetIsLive(callStmt.GetIsLive()); icallStmt->SetSrcPos(callStmt.GetSrcPosition()); for (MeExpr *o : callStmt.GetOpnds()) { - icallStmt->GetOpnds().push_back(o); + icallStmt->PushBackOpnd(o); } icallStmt->GetMuList()->insert(callStmt.GetMuList()->begin(), callStmt.GetMuList()->end()); icallStmt->GetChiList()->insert(callStmt.GetChiList()->begin(), callStmt.GetChiList()->end()); diff --git a/src/maple_me/src/me_rc_lowering.cpp b/src/maple_me/src/me_rc_lowering.cpp index 3fe6599922ece9714bdb518f127bf245b86a3905..89b202af7a9da81076801c0913d4fb7fd1abf39c 100644 --- a/src/maple_me/src/me_rc_lowering.cpp +++ b/src/maple_me/src/me_rc_lowering.cpp @@ -641,11 +641,11 @@ void RCLowering::HandleReturnRegread(RetMeStmt &ret) { bb->InsertMeStmtBefore(&ret, incCall); } else { // remove argument from intrinsiccall MPL_CLEANUP_LOCALREFVARS (dread ref %Reg1_R5678, ... - MapleVector *opnds = &cleanup->GetOpnds(); + const MapleVector *opnds = &cleanup->GetOpnds(); for (auto iter = opnds->begin(); iter != opnds->end(); ++iter) { if (*iter == retVar || (!isAnalyzed && static_cast(*iter)->GetOStIdx() == retVar->GetOStIdx())) { - opnds->erase(iter); - opnds->push_back(retVar); // pin it to end of std::vector + cleanup->EraseOpnds(iter); + cleanup->PushBackOpnd(retVar); // pin it to end of std::vector cleanup->SetIntrinsic(INTRN_MPL_CLEANUP_LOCALREFVARS_SKIP); break; } @@ -712,7 +712,7 @@ void RCLowering::HandleReturnWithCleanup() { IntrinsiccallMeStmt *cleanup = FindCleanupIntrinsic(*ret); if (cleanup != nullptr && !tmpLocalRefVars.empty()) { // new localrefvar introduced in this phase for (auto tmpVar : tmpLocalRefVars) { - cleanup->GetOpnds().push_back(tmpVar); + cleanup->PushBackOpnd(tmpVar); } } if (ret->GetOpnds().empty()) { diff --git a/src/maple_me/src/me_stmt_pre.cpp b/src/maple_me/src/me_stmt_pre.cpp index 02ad99facf916917a4f55af33ed7d55e9e392b17..8bd47b14bf7930675c12b8f5db66db8c30bd1587 100644 --- a/src/maple_me/src/me_stmt_pre.cpp +++ b/src/maple_me/src/me_stmt_pre.cpp @@ -282,8 +282,8 @@ void MeStmtPre::CollectVarForMeStmt(MeStmt *meStmt, MeExpr *meExpr, std::vector< case OP_callassigned: { auto *nStmt = static_cast(meStmt); for (size_t i = 0; i < nStmt->NumMeStmtOpnds(); ++i) - if (nStmt->GetOpnds()[i]->GetMeOp() == kMeOpVar || nStmt->GetOpnds()[i]->GetMeOp() == kMeOpReg) { - varVec.push_back(nStmt->GetOpnds()[i]); + if (nStmt->GetOpnd(i)->GetMeOp() == kMeOpVar || nStmt->GetOpnd(i)->GetMeOp() == kMeOpReg) { + varVec.push_back(nStmt->GetOpnd(i)); } if (meExpr != nullptr) { CHECK_FATAL(meExpr->GetMeOp() == kMeOpVar, "CollectVarForMeStmt:bad meExpr field in realocc node"); @@ -360,9 +360,9 @@ MeStmt *MeStmtPre::PhiOpndFromRes4Stmt(MeRealOcc *realZ, size_t j, MeExpr *&lhsV case OP_callassigned: { auto *nStmtQ = static_cast(stmtQ); for (size_t i = 0; i < nStmtQ->NumMeStmtOpnds(); ++i) { - MeExpr *retOpnd = GetReplaceMeExpr(nStmtQ->GetOpnds()[i], phiBB, j); + MeExpr *retOpnd = GetReplaceMeExpr(nStmtQ->GetOpnd(i), phiBB, j); if (retOpnd != nullptr) { - nStmtQ->GetOpnds()[i] = retOpnd; + nStmtQ->SetOpnd(i, retOpnd); } } break; @@ -506,7 +506,7 @@ void MeStmtPre::ComputeVarAndDfPhis() { case OP_callassigned: { auto *nStmt = static_cast(stmt); for (size_t i = 0; i < nStmt->NumMeStmtOpnds(); ++i) { - SetVarPhis(nStmt->GetOpnds()[i]); + SetVarPhis(nStmt->GetOpnd(i)); } if (realOcc->GetMeExpr() != nullptr) { SetVarPhis(realOcc->GetMeExpr()); @@ -971,7 +971,7 @@ void MeStmtPre::BuildWorkListBB(BB *bb) { auto &intrnStmt = static_cast(stmt); bool allOperandsAreLeaf = true; for (size_t i = 0; i < intrnStmt.NumMeStmtOpnds(); ++i) { - if (!intrnStmt.GetOpnds()[i]->IsLeaf()) { + if (!intrnStmt.GetOpnd(i)->IsLeaf()) { allOperandsAreLeaf = false; break; } diff --git a/src/maple_me/src/prop.cpp b/src/maple_me/src/prop.cpp index 0bdde361e03ec999939462be976ea2aee46ecbff..c76228b3cb5e4d392377110d722b15f8d8f76342 100644 --- a/src/maple_me/src/prop.cpp +++ b/src/maple_me/src/prop.cpp @@ -525,7 +525,7 @@ void Prop::TraversalMeStmt(MeStmt &meStmt) { } case OP_return: { auto &retMeStmt = static_cast(meStmt); - MapleVector &opnds = retMeStmt.GetOpnds(); + const MapleVector &opnds = retMeStmt.GetOpnds(); // java return operand cannot be expression because cleanup intrinsic is // inserted before the return statement if (JAVALANG && opnds.size() == 1 && opnds[0]->GetMeOp() == kMeOpVar) { @@ -533,7 +533,7 @@ void Prop::TraversalMeStmt(MeStmt &meStmt) { } for (size_t i = 0; i < opnds.size(); ++i) { MeExpr *opnd = opnds[i]; - opnds[i] = &PropMeExpr(utils::ToRef(opnd), subProped, false); + retMeStmt.SetOpnd(i, &PropMeExpr(utils::ToRef(opnd), subProped, false)); } break; } diff --git a/src/maple_me/src/ssa_devirtual.cpp b/src/maple_me/src/ssa_devirtual.cpp index 38dd25d56b779f1af5c87e698e27c3c977f11c61..224a82a58d66a0869be4ff6b58ee4ae8ea66b597 100644 --- a/src/maple_me/src/ssa_devirtual.cpp +++ b/src/maple_me/src/ssa_devirtual.cpp @@ -96,8 +96,7 @@ void SSADevirtual::ReplaceCall(CallMeStmt *callStmt, MIRFunction *targetFunc) { if (callStmt->GetOp() == OP_virtualicall || callStmt->GetOp() == OP_virtualicallassigned || callStmt->GetOp() == OP_interfaceicall || callStmt->GetOp() == OP_interfaceicallassigned) { // delete 1st argument - MapleVector::iterator opndIt = callStmt->GetOpnds().begin(); - callStmt->GetOpnds().erase(opndIt); + callStmt->EraseOpnds(callStmt->GetOpnds().begin()); } MeExpr *receiver = callStmt->GetOpnd(0); if (NeedNullCheck(receiver)) { @@ -401,8 +400,8 @@ void SSADevirtual::VisitMeExpr(MeExpr *meExpr) { } } -void SSADevirtual::ReturnTyIdxInferring(RetMeStmt *retMeStmt) { - MapleVector &opnds = retMeStmt->GetOpnds(); +void SSADevirtual::ReturnTyIdxInferring(const RetMeStmt *retMeStmt) { + const MapleVector &opnds = retMeStmt->GetOpnds(); CHECK_FATAL(opnds.size() <= 1, "Assume at most one return value for now"); for (size_t i = 0; i < opnds.size(); ++i) { MeExpr *opnd = opnds[i]; @@ -447,7 +446,7 @@ void SSADevirtual::TraversalMeStmt(MeStmt *meStmt) { case OP_syncenter: case OP_syncexit: { auto *syncMeStmt = static_cast(meStmt); - MapleVector &opnds = syncMeStmt->GetOpnds(); + const MapleVector &opnds = syncMeStmt->GetOpnds(); for (size_t i = 0; i < opnds.size(); ++i) { MeExpr *opnd = opnds[i]; VisitMeExpr(opnd); @@ -483,7 +482,7 @@ void SSADevirtual::TraversalMeStmt(MeStmt *meStmt) { case OP_customcallassigned: case OP_polymorphiccallassigned: { auto *callMeStmt = static_cast(meStmt); - MapleVector &opnds = callMeStmt->GetOpnds(); + const MapleVector &opnds = callMeStmt->GetOpnds(); for (size_t i = 0; i < opnds.size(); ++i) { MeExpr *opnd = opnds[i]; VisitMeExpr(opnd); @@ -498,7 +497,7 @@ void SSADevirtual::TraversalMeStmt(MeStmt *meStmt) { case OP_icall: case OP_icallassigned: { auto *icallMeStmt = static_cast(meStmt); - MapleVector &opnds = icallMeStmt->GetOpnds(); + const MapleVector &opnds = icallMeStmt->GetOpnds(); for (size_t i = 0; i < opnds.size(); ++i) { MeExpr *opnd = opnds[i]; VisitMeExpr(opnd); @@ -512,7 +511,7 @@ void SSADevirtual::TraversalMeStmt(MeStmt *meStmt) { case OP_intrinsiccallassigned: case OP_xintrinsiccallassigned: { auto *intrinCallStmt = static_cast(meStmt); - MapleVector &opnds = intrinCallStmt->GetOpnds(); + const MapleVector &opnds = intrinCallStmt->GetOpnds(); for (size_t i = 0; i < opnds.size(); ++i) { MeExpr *opnd = opnds[i]; VisitMeExpr(opnd); @@ -532,7 +531,7 @@ void SSADevirtual::TraversalMeStmt(MeStmt *meStmt) { } case OP_return: { auto *retMeStmt = static_cast(meStmt); - MapleVector &opnds = retMeStmt->GetOpnds(); + const MapleVector &opnds = retMeStmt->GetOpnds(); for (size_t i = 0; i < opnds.size(); ++i) { MeExpr *opnd = opnds[i]; VisitMeExpr(opnd); diff --git a/src/maple_me/src/ssa_pre.cpp b/src/maple_me/src/ssa_pre.cpp index 40e5192bcdf07782626f4075cbbfe31cfc4d4fba..78be95dcf60b903779a6f1879793ae2153e4bd7a 100644 --- a/src/maple_me/src/ssa_pre.cpp +++ b/src/maple_me/src/ssa_pre.cpp @@ -1483,7 +1483,7 @@ void SSAPre::BuildWorkListStmt(MeStmt *meStmt, uint32 seqStmt, bool isRebuilt, M case OP_syncenter: case OP_syncexit: { auto *syncMeStmt = static_cast(meStmt); - MapleVector &opnds = syncMeStmt->GetOpnds(); + const MapleVector &opnds = syncMeStmt->GetOpnds(); for (auto it = opnds.begin(); it != opnds.end(); ++it) { BuildWorkListExpr(meStmt, seqStmt, *it, isRebuilt, tempVar, true); } @@ -1491,7 +1491,7 @@ void SSAPre::BuildWorkListStmt(MeStmt *meStmt, uint32 seqStmt, bool isRebuilt, M } case OP_return: { auto *retMeStmt = static_cast(meStmt); - MapleVector &opnds = retMeStmt->GetOpnds(); + const MapleVector &opnds = retMeStmt->GetOpnds(); for (auto it = opnds.begin(); it != opnds.end(); ++it) { if ((*it)->IsLeaf() && (*it)->GetPrimType() == PTY_ref) { // affects LPRE only; will cause CI failure if this is allowed @@ -1531,7 +1531,7 @@ void SSAPre::BuildWorkListStmt(MeStmt *meStmt, uint32 seqStmt, bool isRebuilt, M case OP_polymorphiccallassigned: case OP_icallassigned: { auto *naryMeStmt = static_cast(meStmt); - MapleVector &opnds = naryMeStmt->GetOpnds(); + const MapleVector &opnds = naryMeStmt->GetOpnds(); for (auto it = opnds.begin(); it != opnds.end(); ++it) { BuildWorkListExpr(meStmt, seqStmt, *it, isRebuilt, tempVar, true); } @@ -1553,7 +1553,7 @@ void SSAPre::BuildWorkListStmt(MeStmt *meStmt, uint32 seqStmt, bool isRebuilt, M case OP_xintrinsiccallassigned: case OP_intrinsiccallwithtypeassigned: { auto *naryMeStmt = static_cast(meStmt); - MapleVector &opnds = naryMeStmt->GetOpnds(); + const MapleVector &opnds = naryMeStmt->GetOpnds(); for (auto it = opnds.begin(); it != opnds.end(); ++it) { if (!GetRcLoweringOn() && (*it)->IsLeaf() && (*it)->GetMeOp() == kMeOpVar) { // affects LPRE only; some later phase needs to transform dread to addrof diff --git a/test/README.md b/test/README.md new file mode 100644 index 0000000000000000000000000000000000000000..bc590f7cf3c6d2a38ba0e7f4ccac343f19870f31 --- /dev/null +++ b/test/README.md @@ -0,0 +1,235 @@ +# Maple 测试框架 + +## 目录结构 + +``` +test +├── main.py 运行测试套路口 +├── README.md +├── testsuite/irbuild_test Maple测试套 +└── maple_test 测试框架代码 + ├── compare.py 结果校验模块 + ├── configs.py + ├── __init__.py + ├── main.py + ├── maple_test.cfg + ├── run.py + ├── template.cfg + ├── task.py + ├── test.py + └── utils.py +``` + +## 运行要求 + +* python版本>=3.5.2 + +## 修改框架配置 + +文件:maple_test.cfg + +```ini +[test-home] +# 指定测试套路径,以‘:’划分 +dir = + ../testsuite/irbuild_test: + +[running] +#指定运行时的临时路径 +temp_dir = ../test_temp/run + +[logging] +#指定运行时保存日志的路径 +name = ../test_temp/log +level = INFO +``` + +## 运行说明 + +依赖环境变量:MAPLE_ROOT + +### 运行单个irbuild用例 + +```shell +python3 main.py -pFAIL -pPASS --timeout=180 --test_cfg=testsuite/irbuild_test/test.cfg testsuite/irbuild_test/I0001-mapleall-irbuild-edge-addf32 +``` + +### 运行文件夹内的所有用例 + +```shell +python3 main.py -pFAIL -pPASS --timeout=180 --test_cfg=testsuite/irbuild_test/test.cfg testsuite/irbuild_test +``` + +### 运行已配置的所有测试套 + +```shell +python3 test/main.py -j20 --timeout=120 +``` + +参数说明:指定参数会覆盖框架配置文件中的设置 + +```shell +usage: main.py [-h] [--cfg CFG] [-j ] [--retry ] [--output ] + [--debug] + [-p {PASS,FAIL,XFAIL,XPASS,NOT_RUN,UNRESOLVED,UNSUPPORTED}] + [--progress {silent,normal,no_flush_progress}] + [--test_cfg ] [--test_list ] + [-c config_set_name] [-C key=value] [-E key=value] + [--temp_dir ] [--timeout TIMEOUT] + [--encoding ENCODING] [--log_dir ] + [--log_level LOG_LEVEL] [--verbose] + [test_paths [test_paths ...]] + +optional arguments: + -h, --help show this help message and exit + +Test FrameWork arguments: + --cfg CFG Test framework configuration file + -j Run cases in parallel + --retry Re-run unsuccessful test cases + --output Store test result at + --debug keep test temp file + -p {PASS,FAIL,XFAIL,XPASS,NOT_RUN,UNRESOLVED,UNSUPPORTED} + Print test cases with specified results, -pPASS + -pFAIL, to print all test case that failed or passed + --progress {silent,normal,no_flush_progress} + set progress type, silent: Don't show progress, + normal: one line progress bar, update per + second,no_flush_progress: print test progress per 10 + seconds + +Test Suite arguments: + test_paths Test suite path + --test_cfg + test suite config file, needed when run a single case + or with --test_list + --test_list + testlist path for filter test cases + -c config_set_name, --config_set config_set_name + Run a test set with the specified config set name + -C key=value, --config key=value + Add 'key' = 'val' to the user defined configs + -E key=value, --env key=value + Add 'key' = 'val' to the user defined environment + variable + +Running arguments: + --temp_dir + Location for test execute. + --timeout TIMEOUT test case timeout + --encoding ENCODING Specify the test case encoding format, default + encoding is platform dependent, but any encoding + supported by Python can be passed. Can specify + multiple encoding formats. + +Log arguments: + --log_dir + Where to store test log + --log_level LOG_LEVEL, -l LOG_LEVEL + set log level from: CRITICAL, ERROR, WARNING, INFO, + DEBUG, NOTSET + --verbose enable verbose output + +``` + +## irbuild测试套配置说明 + +irbuild测试套配置:testsuite/irbuild_test/test.cfg +如果涉及脚本的运行路径需要填写绝对路径或者在环境变量(PATH)中 +例如配置文件中:如果cmp在PATH中,则 cmp = cmp 即可,如果不在则 cmp = /usr/bin/cmp + +```ini +[suffix] +mpl = # + +[internal-var] +irbuild = ${MAPLE_ROOT}/output/bin/irbuild +cmp = /usr/bin/cmp -s + +[description] +title = Maple Irbuild Test +``` + +### suffix说明 + +```ini +[suffix] +mpl = # +``` + +* 测试用例以"mpl"作为文件后缀 +* 文件后缀"mpl"的测试用例内以"#"作为注释符 + +### 内部变量说明 + +```ini +[internal-var] +irbuild = ${MAPLE_ROOT}/output/bin/irbuild +cmp = /usr/bin/cmp -s +``` + +* 所有测试用例中的EXEC语句内的"%irbuild"会被替换为"${MAPLE_ROOT}/output/bin/irbuild" +* 所有测试用例中的EXEC语句内的"%cmp"会被替换为"/usr/bin/cmp -s" + +#### irbuild测试套文件结构 + +```shell + testsuite/irbuild 测试套路径 + ├── I0001-mapleall-irbuild-edge-addf32 + │ ├── Main.mpl 测试用例 + ├── ... + └── ... +``` + +## 测试用例说明 + +### 完整Main.mpl + +``` + func &addf32r( + var %i f32, var %j f32 + ) f32 { + return ( + add f32(dread f32 %i, dread f32 %j))} + + func &addf32I ( + var %i f32 + ) f32 { + return ( + add f32(dread f32 %i, + constval f32 1.234f))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl +``` + +#### 1. 测试案例部分 + +``` + func &addf32r( + var %i f32, var %j f32 + ) f32 { + return ( + add f32(dread f32 %i, dread f32 %j))} + + func &addf32I ( + var %i f32 + ) f32 { + return ( + add f32(dread f32 %i, + constval f32 1.234f))} +``` + +#### 2. 测试案例运行部分 + +``` + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl +``` + +三条执行语句: + +1. EXEC语句,利用%irbuild,编译Main.mpl为Main.irb.mpl +2. EXEC语句,利用%irbuild,编译Main.irb.mpl为Main.irb.irb.mpl +3. EXEC语句,利用%cmp,比较Main.irb.irb.mpl与Main.irb.mpl是否一致,一致测试通过 diff --git a/test/main.py b/test/main.py new file mode 100644 index 0000000000000000000000000000000000000000..7bae4afb775ba1d3e4259aacc74ab065f4df88c6 --- /dev/null +++ b/test/main.py @@ -0,0 +1,20 @@ +#!/usr/bin/python3 +# -*- coding:utf-8 -*- +# +# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. +# +# OpenArkCompiler is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# +# http://license.coscl.org.cn/MulanPSL +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v1 for more details. +# +from maple_test import main + +if __name__ == "__main__": + main() diff --git a/test/maple_test/__init__.py b/test/maple_test/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..c83556bb3ac2294c04dc47771c5b1e1e03c5b7ff --- /dev/null +++ b/test/maple_test/__init__.py @@ -0,0 +1,17 @@ +#!/usr/bin/python3 +# -*- coding:utf-8 -*- +# +# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. +# +# OpenArkCompiler is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# +# http://license.coscl.org.cn/MulanPSL +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v1 for more details. +# +from .main import main diff --git a/test/maple_test/compare.py b/test/maple_test/compare.py new file mode 100644 index 0000000000000000000000000000000000000000..c54d9365c8a5c12171ddfabe9917db694ad6bbe8 --- /dev/null +++ b/test/maple_test/compare.py @@ -0,0 +1,155 @@ +#!/usr/bin/python3 +# -*- coding:utf-8 -*- +# +# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. +# +# OpenArkCompiler is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# +# http://license.coscl.org.cn/MulanPSL +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v1 for more details. +# + +import argparse +import logging +import re +import sys +from textwrap import indent + +from utils import complete_path, read_file +from utils import split_comment, filter_line + + +def main(): + opts = parse_cli() + case_path = opts.case_path + comment = opts.comment + compare_object = opts.compare_object + assert_flags = opts.assert_flag + if not assert_flags: + assert_flags.append("ASSERT") + content = compare_object.read() + + print("compare.py input:") + print(indent(content, "\t", lambda line: True)) + print("compare.py input end\n") + + if compare_object.isatty(): + sys.stderr.write("ERROR: require compare objects, filepath or stdin \n") + sys.exit(253) + comment_lines = split_comment(comment, read_file(case_path))[1] + result = True + for assert_flag in assert_flags: + assert_lines = [ + line for line in comment_lines if filter_line(line, assert_flag) + ] + if not assert_lines: + print( + "ASSERT flag: {}, No regex find, " + "make sure you write the assert line".format(assert_flag) + ) + passed = True + for assert_line in assert_lines: + found = False + flag, pattern = extract_pattern(assert_line, assert_flag) + if pattern is None: + logging.error( + "ASSERT flag: {}, Failed Reason: " + "Not found valid match pattern".format(assert_flag) + ) + sys.exit(1) + try: + re.compile(pattern) + except re.error: + passed = False + logging.error( + "ASSERT flag: {}, Failed Reason: " + "Error pattern: {!r}".format(assert_flag, pattern) + ) + break + print( + "ASSERT flag: {}, Match regex: {}, " + "is not-scan: {}".format(assert_flag, pattern, not flag) + ) + if pattern: + found = is_match(pattern, content) + if found == flag: + passed = True + else: + passed = False + logging.error( + "Failed Reason: regex: {}, is not-scan: {}, Matched: {}, exit".format( + pattern, not flag, found + ) + ) + break + if passed is False: + result = False + if result is True: + print( + "ASSERT flag: {}, Compare Passed: {}".format(" ".join(assert_flags), result) + ) + return 0 + sys.exit(1) + + +def extract_pattern(line, flag): + line_flag = line.strip().split(":")[0].strip() + if line_flag != flag: + return None, None + + line = line.strip()[len(line_flag) + 1 :].strip().lstrip(":").strip() + if line[:5] == "scan ": + words = line[4:].strip().split() + pattern = r"\s*".join([word.strip() for word in words]) + return True, pattern + if line[:9] == "scan-not ": + words = line[8:].strip().split() + pattern = r"\s*".join([word.strip() for word in words]) + return False, pattern + if line[:10] == "scan-auto ": + words = line[9:].strip().split() + pattern = r"\s*".join([re.escape(word.strip()) for word in words]) + return True, pattern + return None, None + + +def is_match(pattern, test_str): + if re.findall(pattern, test_str, re.MULTILINE): + return True + return False + + +def parse_cli(): + parser = argparse.ArgumentParser(prog="compare") + parser.add_argument("--comment", help="Test case comment") + parser.add_argument( + "--assert_flag", + help="Test case assert flag, default ASSERT", + action="append", + default=[], + ) + parser.add_argument( + "case_path", type=complete_path, help="Source path: read compare rules" + ) + parser.add_argument( + "compare_object", + nargs="?", + type=argparse.FileType("r"), + default=sys.stdin, + help="compare object, default stdin", + ) + opts = parser.parse_args() + return opts + + +if __name__ == "__main__": + logging.basicConfig( + format="\t%(message)s", level=logging.DEBUG, stream=sys.stderr, + ) + main() diff --git a/test/maple_test/configs.py b/test/maple_test/configs.py new file mode 100644 index 0000000000000000000000000000000000000000..a0f61f15113c4e031dbd7bb5357f6fd43c6d7b88 --- /dev/null +++ b/test/maple_test/configs.py @@ -0,0 +1,363 @@ +#!/usr/bin/python3 +# -*- coding:utf-8 -*- +# +# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. +# +# OpenArkCompiler is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# +# http://license.coscl.org.cn/MulanPSL +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v1 for more details. +# +""" +store config file and command line config + +""" +import argparse +import logging +import sys +from pathlib import Path + +from maple_test.utils import ALL, ENCODING +from maple_test.utils import complete_path, read_config, get_config_value, BASE_DIR + +TEST_CONFIG = {} +LOGGER = None +LOG_CONFIG = {} +CASE_ENCODING = [] + + +def parse_args(): + parser = argparse.ArgumentParser() + test_framework_parser = parser.add_argument_group("Test FrameWork arguments") + test_framework_parser.add_argument( + "--cfg", + default=Path(BASE_DIR / "maple_test.cfg"), + type=complete_path, + help="Test framework configuration file", + ) + test_framework_parser.add_argument( + "-j", + type=int, + metavar="", + dest="processes", + default=1, + help="Run cases in parallel", + ) + test_framework_parser.add_argument( + "--retry", + metavar="", + default=0, + type=int, + help="Re-run unsuccessful test cases", + ) + test_framework_parser.add_argument( + "--output", + metavar="", + type=complete_path, + help="Store test result at ", + ) + test_framework_parser.add_argument( + "--debug", action="store_true", help="keep test temp file" + ) + test_framework_parser.add_argument( + "-p", + type=str, + dest="print_type", + action="append", + default=[], + choices=ALL[:], + help="Print test cases with specified results, " + "-pPASS -pFAIL, to print all test case that failed or passed", + ) + test_framework_parser.add_argument( + "--progress", + choices=["silent", "normal", "no_flush_progress"], + default="normal", + help="set progress type, silent: Don't show progress, " + "normal: one line progress bar, update per second," + "no_flush_progress: print test progress per 10 seconds", + ) + + test_suite_parser = parser.add_argument_group("Test Suite arguments") + test_suite_parser.add_argument( + "test_paths", nargs="*", type=complete_path, help="Test suite path" + ) + test_suite_parser.add_argument( + "--test_cfg", + metavar="", + type=complete_path, + help="test suite config file, " + "needed when run a single case or with --test_list", + ) + test_suite_parser.add_argument( + "--test_list", + metavar="", + type=complete_path, + help="testlist path for filter test cases", + ) + test_suite_parser.add_argument( + "-c", + "--config_set", + dest="user_config_set", + metavar="config_set_name", + help="Run a test set with the specified config set name", + type=str, + ) + test_suite_parser.add_argument( + "-C", + "--config", + dest="user_config", + metavar="key=value", + help="Add 'key' = 'val' to the user defined configs", + type=str, + action=StoreDictKeyPair, + default={}, + ) + test_suite_parser.add_argument( + "-E", + "--env", + dest="user_env", + metavar="key=value", + help="Add 'key' = 'val' to the user defined environment variable", + action=StoreDictKeyPair, + default={}, + ) + + running_parser = parser.add_argument_group("Running arguments") + running_parser.add_argument( + "--temp_dir", + metavar="", + type=complete_path, + help="Location for test execute. ", + ) + running_parser.add_argument( + "--timeout", type=float, dest="timeout", default=600, help="test case timeout" + ) + running_parser.add_argument( + "--encoding", + action="append", + default=[ENCODING], + help="Specify the test case encoding format, default encoding is platform " + "dependent, but any encoding supported by Python can be passed. " + "Can specify multiple encoding formats.", + ) + + log_parser = parser.add_argument_group("Log arguments") + log_parser.add_argument( + "--log_dir", + metavar="", + type=complete_path, + help="Where to store test log", + ) + log_parser.add_argument( + "--log_level", + "-l", + type=get_level_name, + help="set log level from: CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET", + ) + log_parser.add_argument( + "--verbose", action="store_true", help="enable verbose output" + ) + + args = parser.parse_args() + if args.test_paths: + for path in args.test_paths: + if path.is_file and not args.test_cfg: + print( + "Error: When specify test case, need also specify test configure file\n" + ) + parser.print_help() + sys.exit(0) + if args.test_list and not args.test_cfg: + print("Error: When specify test list, need also specify test configure file\n") + parser.print_help() + sys.exit(0) + if args.retry < 0: + print("The number of retry must be a positive integer.\n") + parser.print_help() + sys.exit(0) + + test_framework_config = { + "cfg": args.cfg or None, + "processes": args.processes or None, + "retry": args.retry or 0, + "output": args.output or None, + "debug": args.debug or None, + "print_type": args.print_type, + "progress": args.progress, + } + + test_suite_config = { + "test_paths": args.test_paths or None, + "cli_running_config": { + "test_cfg": args.test_cfg or None, + "test_list": args.test_list or None, + "user_config_set": args.user_config_set or None, + "user_config": args.user_config or {}, + "user_env": args.user_env or {}, + }, + } + + running_config = { + "temp_dir": args.temp_dir or None, + "timeout": args.timeout or None, + "encoding": args.encoding or None, + } + + log_config = { + "dir": args.log_dir or None, + "level": args.log_level or None, + "verbose": args.verbose, + } + + return test_framework_config, test_suite_config, running_config, log_config + + +def parser_maple_test_config_file(maple_test_cfg_file): + raw_config = read_config(maple_test_cfg_file) + test_suite_config = { + "test_paths": [ + BASE_DIR / path + for path in get_config_value(raw_config, "test-home", "dir") + .replace("\n", "") + .split(":") + if path + ] + or None, + } + log_config = { + "dir": complete_path( + BASE_DIR / Path(get_config_value(raw_config, "logging", "name")) + ) + or None, + "level": get_level_name(get_config_value(raw_config, "logging", "level")) + or None, + } + + running_config = { + "temp_dir": complete_path( + BASE_DIR / Path(get_config_value(raw_config, "running", "temp_dir")) + ) + or None, + } + + return test_suite_config, running_config, log_config + + +def init_config(): + global TEST_CONFIG + ( + TEST_CONFIG, + cli_test_suite_config, + cli_running_config, + cli_log_config, + ) = parse_args() + + ( + file_test_suite_config, + file_running_config, + file_log_config, + ) = parser_maple_test_config_file(TEST_CONFIG.get("cfg")) + + test_suite_config = merge_config(cli_test_suite_config, file_test_suite_config) + running_config = merge_config(cli_running_config, file_running_config) + log_config = merge_config(cli_log_config, file_log_config) + + if log_config.get("dir") is None: + log_dir = complete_path(Path("./maple_test_log")) + print( + "No log dir find in cfg file and cli args, will create lod gir at: {}".format( + log_dir + ) + ) + log_config["dir"] = log_dir + + global CASE_ENCODING + CASE_ENCODING = TEST_CONFIG.get("encoding") + + global LOGGER + maple_test_log_config = log_config.copy() + maple_test_log_config["verbose"] = True + stream_fmt = logging.Formatter("%(message)s") + log_dir = maple_test_log_config.get("dir") + if not log_dir.exists(): + log_dir.mkdir(parents=True, exist_ok=True) + LOGGER = construct_logger( + maple_test_log_config, "Maple_Test", stream_fmt=stream_fmt + ) + LOGGER.info("Test log saved to {}".format(log_dir)) + + running_config["log_config"] = log_config.copy() + + return test_suite_config, running_config, log_config + + +def merge_config(cli_config, maple_test_config): + config = {} + config.update(maple_test_config) + for key, value in cli_config.items(): + if value is not None: + config[key] = value + return config + + +def get_val(key): + global TEST_CONFIG + return TEST_CONFIG.get(key) + + +class StoreDictKeyPair(argparse.Action): + def __init__(self, option_strings, dest, nargs=None, **kwargs): + self._nargs = nargs + super().__init__(option_strings, dest, nargs=nargs, **kwargs) + + def __call__(self, parser, namespace, value, option_string=None): + my_dict = getattr(namespace, self.dest) + k = value.strip().split("=")[0].strip() + v = "=".join(value.strip().split("=")[1:]).strip() + my_dict[k] = v + setattr(namespace, self.dest, my_dict) + + +def construct_logger(log_config, name, stream_fmt=None, file_fmt=None): + name = str(name) + log_dir = str(log_config["dir"]) + level = log_config["level"] + verbose = log_config["verbose"] + formatter = logging.Formatter( + "%(asctime)s %(levelname)s %(name)s %(message)s", datefmt="%Y-%m-%d %H:%M:%S" + ) + if stream_fmt is None: + stream_fmt = formatter + if file_fmt is None: + file_fmt = formatter + logger = logging.getLogger(name) + if logger.handlers: + return logger + logger.setLevel(level) + + handler1 = logging.StreamHandler() + handler1.setLevel(level) + handler1.setFormatter(stream_fmt) + if not verbose: + handler1.setLevel(logging.WARNING) + logger.addHandler(handler1) + + handler2 = logging.FileHandler(filename="{}/{}.log".format(log_dir, name), mode="w") + handler2.setLevel(level) + handler2.setFormatter(file_fmt) + logger.addHandler(handler2) + + logger.info("Log file at: {}/{}.log".format(log_dir, name)) + return logger + + +def get_level_name(name: str): + name = name.upper() + return logging.getLevelName(name) diff --git a/test/maple_test/main.py b/test/maple_test/main.py new file mode 100644 index 0000000000000000000000000000000000000000..6f3d35f550417dab08ac1b18f136cafacf75ef20 --- /dev/null +++ b/test/maple_test/main.py @@ -0,0 +1,75 @@ +#!/usr/bin/python3 +# -*- coding:utf-8 -*- +# +# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. +# +# OpenArkCompiler is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# +# http://license.coscl.org.cn/MulanPSL +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v1 for more details. +# +""" +maple test - Maple Tester + + +""" +import shutil +import time + +from maple_test import configs +from maple_test.task import TestSuiteTask +from maple_test.utils import timer + + +@timer +def main(): + test_suite_config, running_config, log_config = configs.init_config() + logger = configs.LOGGER + + test_paths = test_suite_config.get("test_paths") + cli_running_config = test_suite_config.get("cli_running_config") + + retry = configs.get_val("retry") + result = [] + for test in test_paths: + if test.exists(): + task = TestSuiteTask( + test, test / "test.cfg", running_config, cli_running_config + ) + if not task.task_set: + continue + for run_times in range(1, retry + 2): + task.run(configs.get_val("processes")) + result.append(task.gen_summary([])) + else: + print("Test path: {} does not exist, please check".format(test)) + + output = configs.get_val("output") + if output: + if output.exists() and output.is_file(): + name = "{}_{}{}".format(output.stem, int(time.time()), output.suffix) + logger.info( + "result file: {} exists, will rename as: {}".format(output, name) + ) + shutil.move(str(output), str(output.parent / name)) + logger.info("Save test result at: {}".format(output)) + with output.open("w") as f: + for summary in result: + f.write(summary) + + temp_dir = running_config.get("temp_dir") + if configs.get_val("debug"): + logger.debug("Keep temp file at %s", temp_dir) + else: + logger.debug("remove temp_dir %s", temp_dir) + shutil.rmtree(str(temp_dir)) + + +if __name__ == "__main__": + main() diff --git a/test/maple_test/maple_test.cfg b/test/maple_test/maple_test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..e2c0cab928fd7bef9fa6ae4cbb2fbfbd64e557a5 --- /dev/null +++ b/test/maple_test/maple_test.cfg @@ -0,0 +1,14 @@ +# 测试框架配置文件,当前框架仅支持通过配置文件配置测试套,测试运行时的临时路径,测试日志的保存 +[test-home] +# 指定测试套路径,以‘:’划分 +dir = + ../testsuite/irbuild_test: + +[running] +#指定运行时的临时路径 +temp_dir = ../test_temp/run + +[logging] +#指定运行时保存日志的路径 +name = ../test_temp/log +level = INFO \ No newline at end of file diff --git a/test/maple_test/run.py b/test/maple_test/run.py new file mode 100644 index 0000000000000000000000000000000000000000..1bacafb09dd089a0420d290db5dccd451a848ad5 --- /dev/null +++ b/test/maple_test/run.py @@ -0,0 +1,132 @@ +#!/usr/bin/python3 +# -*- coding:utf-8 -*- +# +# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. +# +# OpenArkCompiler is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# +# http://license.coscl.org.cn/MulanPSL +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v1 for more details. +# +import os +import signal +import subprocess +import sys +import time +import timeit +from textwrap import indent, shorten + +from maple_test.configs import construct_logger +from maple_test.utils import PASS, FAIL, UNRESOLVED, ENCODING +from maple_test.utils import add_run_path + + +class TestError(Exception): + pass + + +def run_command(cmd, work_dir, timeout, logger, env=None): + """Run commands using subprocess""" + new_env = add_run_path(str(work_dir)) + new_env.update(env) + process_command = subprocess.Popen( + cmd, + shell=True, + cwd=str(work_dir), + env=new_env, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + close_fds=True, + start_new_session=True, + ) + logger.debug("execute cmd: %s", cmd) + return_code = com_out = com_err = None + try: + com_out, com_err = process_command.communicate(timeout=timeout) + except subprocess.CalledProcessError as err: + return_code, com_out, com_err = err.returncode, "", err + logger.exception(err) + return return_code, com_out, com_err + except subprocess.TimeoutExpired: + return_code, com_out, com_err = 3, "TimeOut", "TimeOut" + return return_code, com_out, com_err + else: + return_code = process_command.returncode + com_out = com_out.decode(ENCODING, errors="ignore") + com_err = com_err.decode(ENCODING, errors="ignore") + return return_code, com_out, com_err + finally: + process_command.kill() + try: + os.killpg(process_command.pid, signal.SIGTERM) + except ProcessLookupError: + pass + logger.debug("return code: %d", return_code) + logger.debug("stdout : \n%s", indent(com_out, "+\t", lambda line: True)) + logger.debug("stderr : \n%s", indent(com_err, "@\t", lambda line: True)) + + +def run_commands(position, commands, work_dir, timeout, log_config, env=None): + name = "{}_{}".format(log_config[1], int(time.time())) + logger = construct_logger(log_config[0], name) + remain_time = timeout + result = (PASS, None) + if not commands: + return position, (UNRESOLVED, None) + for command in commands: + start = timeit.default_timer() + try: + return_code, com_out, com_err = run_command( + command, work_dir, remain_time, logger, env + ) + if return_code != 0: + result = (FAIL, (return_code, command, shorten(com_err, width=84))) + err = "Run task exit unexpected : {}, Log file at: {}.log".format( + result[-1], log_config[0].get("dir") / name + ) + raise TestError(err) + except TestError as err: + logger.error(err) + break + else: + run_time = timeit.default_timer() - start + remain_time = remain_time - run_time + logger.debug( + "Run time: {:.2}, remain time: {:.2}".format(run_time, remain_time) + ) + if result[0] == PASS: + logger.info("Task executed successfully") + handlers = logger.handlers[:] + for handler in handlers: + handler.close() + logger.removeHandler(handler) + return position, result + + +def progress(results, progress_type): + """Output test progress""" + + if progress_type == "silent": + return 0 + if progress_type == "normal": + time_gape = 1 + print_progress = sys.stdout.write + else: + time_gape = 10 + print_progress = print + finished = 0 + total = len(results) + while total != finished: + time.sleep(time_gape) + finished = sum([result.ready() for result in results]) + rate = finished / total + print_progress( + "\rRunning test cases: {:.2%} ({}/{}) ".format(rate, finished, total) + ) + sys.stdout.flush() diff --git a/test/maple_test/task.py b/test/maple_test/task.py new file mode 100644 index 0000000000000000000000000000000000000000..1a8298675c6fd7f6e8e79beb02648d812ab4ba9d --- /dev/null +++ b/test/maple_test/task.py @@ -0,0 +1,434 @@ +#!/usr/bin/python3 +# -*- coding:utf-8 -*- +# +# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. +# +# OpenArkCompiler is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# +# http://license.coscl.org.cn/MulanPSL +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v1 for more details. +# +import copy +import multiprocessing +import shlex +import shutil +import time +from collections import defaultdict +from pathlib import Path + +from maple_test import configs +from maple_test.run import run_commands, progress, TestError +from maple_test.test import Case, read_list +from maple_test.utils import ( + EXECUTABLE, + COMPARE, + PASS, + NOT_RUN, + UNRESOLVED, + read_config, + config_section_to_dict, + ls_all, +) + + +class TaskConfig: + def __init__(self, name, path, upper_config, user_config=None, user_env=None): + if user_env is None: + user_env = {} + if user_config is None: + user_config = {} + if upper_config is None: + self.internal_var = {} + self.env = {} + self.suffix_comments = {} + else: + self.internal_var = copy.deepcopy(upper_config.internal_var) + self.env = copy.deepcopy(upper_config.env) + self.suffix_comments = copy.deepcopy(upper_config.suffix_comments) + if path.exists(): + self.name = name + else: + self.name = upper_config.name + self.path = path + self.update_sub_config() + self.update_by_user_config(user_config, user_env) + + def update_by_user_config(self, user_config, user_env): + self.internal_var.update(user_config) + self.env.update(user_env) + + def update_sub_config(self): + if self.path.exists(): + config = read_config(self.path) + self.internal_var.update(config_section_to_dict(config, "internal-var")) + self.env.update(config_section_to_dict(config, "env")) + self.suffix_comments.update(config_section_to_dict(config, "suffix")) + else: + print( + "config file: {}, not exists, will use upper config".format(self.path) + ) + + def get_case_config(self, case): + case_config = { + "internal_var": copy.deepcopy(self.internal_var), + "env": copy.deepcopy(self.env), + } + case_config["internal_var"]["f"] = str(case.path) + case_config["internal_var"]["n"] = str(case.path.stem) + case_config["internal_var"]["d"] = str(case.path.parent) + return case_config + + +class TestSuiteTask: + def __init__(self, test_path, cfg_path, running_config, cli_running_config=None): + if cli_running_config is None: + cli_running_config = {} + user_test_cfg = cli_running_config.get("test_cfg") + user_test_list = cli_running_config.get("test_list") + user_config_set = cli_running_config.get("user_config_set") + user_config = cli_running_config.get("user_config") + user_env = cli_running_config.get("user_env") + + self.path = test_path + self.cfg_path = user_test_cfg or cfg_path + + config = read_config(self.cfg_path) + if config is None: + raise TestError( + "Test suite config path:{} not found, skip!!!!!".format(self.cfg_path) + ) + try: + self.name = config["description"]["title"].replace(" ", "") + except KeyError: + self.name = test_path.name + self.suffix_comments = config_section_to_dict(config, "suffix") + + self.result = defaultdict(int) + + self.config_set = {} + self.testlist_set = {} + + self._form_config(test_path, config, user_config_set, user_config, user_env) + self._form_testlist( + test_path, + config, + running_config["encoding"], + user_config_set, + user_test_list, + ) + + self.task_set = {} + self.task_set_result = {} + self._form_task_set(running_config) + + def _form_config(self, test_path, config, user_config_set, user_config, user_env): + top_config = TaskConfig(self.name, self.cfg_path, None, user_config, user_env) + if not user_config_set: + self.config_set[self.name] = top_config + for name, config_path in config_section_to_dict(config, "config-set").items(): + if not user_config_set or name == user_config_set: + self.config_set[name] = TaskConfig( + name, test_path / config_path, top_config, user_config, user_env + ) + + def _form_testlist( + self, test_path, config, encoding, user_config_set, user_test_list + ): + for name, testlist_path in config_section_to_dict(config, "testlist").items(): + if not user_config_set or name == user_config_set: + if user_test_list is None: + self.testlist_set[name] = read_list( + test_path / testlist_path, encoding + ) + else: + self.testlist_set[name] = read_list(user_test_list, encoding) + if self.testlist_set.get("default") is None: + self.testlist_set["default"] = set("*"), set() + if test_path.is_file(): + self.testlist_set["default"] = set("."), set() + if (test_path / "testlist").exists(): + testlist = read_list(test_path / "testlist", encoding) + else: + testlist = self.testlist_set["default"] + self.testlist_set[self.name] = testlist + self.all_cases = {} + self._search_list(test_path, encoding) + + def _search_list(self, test_path, encoding): + suffixes = self.suffix_comments.keys() + for name, testlist in self.testlist_set.items(): + self.testlist_set[name] = [] + include, exclude = testlist + case_files = set() + if test_path.is_file(): + case_files = [test_path] + else: + for glob_pattern in include: + for include_path in test_path.glob(glob_pattern): + case_files.update(ls_all(include_path, suffixes)) + for glob_pattern in exclude: + for exclude_path in test_path.glob(glob_pattern): + case_files -= set(ls_all(exclude_path, suffixes)) + case_files = [file.relative_to(test_path) for file in case_files] + for case_file in case_files: + case_name = str(case_file).replace(".", "_") + comment = self.suffix_comments[case_file.suffix[1:]] + if case_name in self.all_cases: + self.testlist_set[name].append(self.all_cases[case_name]) + else: + case = Case(case_file, test_path, comment, encoding,) + self.all_cases[case_name] = case + self.testlist_set[name].append(self.all_cases[case_name]) + + def _form_task_set(self, running_config): + for name in self.config_set: + config = self.config_set.get(name) + cases = self.testlist_set.get(name) + if cases is None: + cases = self.testlist_set.get("default") + self.task_set[name] = [] + self.task_set_result[name] = defaultdict(int) + for case in cases: + self.task_set[name].append(SingleTask(case, config, running_config)) + self.task_set_result[name][NOT_RUN] += 1 + + def serial_run_task(self): + for tasks_name in self.task_set: + for index, task in enumerate(self.task_set[tasks_name]): + print("Running task: {}. {}".format(index, task.name)) + if task.result[0] == PASS: + continue + self.task_set_result[tasks_name][task.result[0]] -= 1 + _, task.result = run_commands( + (tasks_name, index), task.commands, **task.running_config + ) + status, _ = task.result + print("Task result: {}".format(task.result)) + self.task_set_result[tasks_name][status] += 1 + + def parallel_run_task(self, process_num): + multiprocessing.freeze_support() + pool = multiprocessing.Pool(min(multiprocessing.cpu_count(), process_num)) + result_queue = [] + for tasks_name in self.task_set: + for index, task in enumerate(self.task_set[tasks_name]): + if not task.commands: + self.task_set_result[tasks_name][task.result[0]] -= 1 + task.result = (UNRESOLVED, None) + self.task_set_result[tasks_name][UNRESOLVED] += 1 + continue + if task.result[0] == PASS: + continue + result_queue.append( + pool.apply_async( + run_commands, + args=((tasks_name, index), task.commands,), + kwds=task.running_config, + ) + ) + progress(result_queue, configs.get_val("progress")) + pool.close() + pool.join() + + result_queue = [result.get() for result in result_queue] + for position, result in result_queue: + tasks_name, index = position + task = self.task_set[tasks_name][index] + self.task_set_result[tasks_name][task.result[0]] -= 1 + task.result = result + self.task_set_result[tasks_name][result[0]] += 1 + + def run(self, process_num=1): + logger = configs.LOGGER + if process_num < 0: + logger.error("The number of running processes needs to be greater than 1") + if process_num == 1: + logger.debug("The number of running processes is 1, which will run serial") + self.serial_run_task() + else: + logger.debug( + "The number of running processes is {}, and will run in parallel".format( + process_num + ) + ) + self.parallel_run_task(process_num) + print_type = configs.get_val("print_type") + for line in self.gen_summary(print_type).splitlines(): + logger.info(line) + + def gen_summary(self, print_type=None): + self.result = defaultdict(int) + for name in self.task_set_result: + for status, num in self.task_set_result[name].items(): + self.result[status] += num + if print_type is None: + print_type = configs.get_val("print_type") + + summary = "\nTestSuiteTask: {}\n".format(self.name) + summary += "Path: {}\n".format(self.path) + total = sum(self.result.values()) + result = "".join( + [ + "{}: {}, ".format(k, v) + for k, v in sorted( + self.result.items(), key=lambda item: item[1], reverse=True + ) + ] + ) + summary += "Total: {}, {}\n".format(total, result) + if not total: + return summary + for tasks_name in self.task_set: + result = "".join( + [ + "{}: {}, ".format(k, v) + for k, v in sorted( + self.task_set_result[tasks_name].items(), + key=lambda item: item[1], + reverse=True, + ) + ] + ) + summary += "\n {}, {}\n".format(tasks_name, result) + for task in self.task_set[tasks_name]: + reason = "" + if task.result[-1] is not None: + reason = ", Reason: {}".format(task.result[-1]) + result = task.result[0] + if not print_type or task.result[0] in configs.get_val("print_type"): + summary += " {}, Case: {}, Result: {} {}\n".format( + task.name, task.case_path, result, reason + ) + summary += "-" * 120 + return summary + + @staticmethod + def _is_cli_mode(cli_running_config): + return bool([x for x in cli_running_config.values() if x]) + + +class SingleTask: + def __init__(self, case, config, running_config): + self.name = "{}_task/{}".format(config.name, case.name) + self.path = Path("{}_task/{}".format(config.name, case.name)) + config = config.get_case_config(case) + self.commands = [] + self._form_commands(case, config) + env = config["env"] + temp_dir = "{}_{}".format(self.path.name.replace(".", "_"), int(time.time())) + self.work_dir = running_config["temp_dir"] / self.path.parent / temp_dir + timeout = running_config["timeout"] + self.running_config = { + "work_dir": self.work_dir, + "log_config": (running_config["log_config"], self.name), + "timeout": timeout, + "env": env, + } + self.case_path = case.relative_path + self.prepare_temp(case.path, self.work_dir) + log_dir = (running_config.get("log_config").get("dir") / self.name).parent + self.prepare_dir(log_dir) + self.result = (NOT_RUN, None) + + def prepare_temp(self, src, dest): + logger = configs.LOGGER + if not src.exists(): + logger.debug("Source: {} is not existing.\n".format(src)) + return + self.prepare_dir(dest) + shutil.copy(str(src), str(dest)) + for command in self.commands: + self.move_needed_files(command, src, dest) + + @staticmethod + def prepare_dir(directory): + logger = configs.LOGGER + if not directory.exists(): + try: + directory.mkdir(parents=True, exist_ok=True) + logger.debug("Create directory: {}".format(directory)) + except FileExistsError as err: + logger.debug(err) + logger.debug( + "File: {} is not an existing non-directory file.".format(directory) + ) + + def _form_commands(self, case, config): + for command in case.commands: + for key, value in config.get("internal_var").items(): + end = 0 + while end < len(command): + start = command.find("%{}".format(key), end) + if start == -1: + break + end = len(key) + start + 1 + if end == len(command): + command = command[:start] + value + command[end:] + continue + if command[end].isalnum() or command[end] == "_": + continue + else: + command = command[:start] + value + command[end:] + compare_cmd = " {} {} --comment={} ".format( + EXECUTABLE, COMPARE, shlex.quote(case.comment) + ) + self.commands.append(format_compare_command(command, compare_cmd)) + + @staticmethod + def move_needed_files(command, src, dest): + """Move required files to temporary directory""" + logger = configs.LOGGER + copy_file = "" + for part in set(shlex.split(command)): + if not part: + continue + if part[0] in ["/", "|", "%", "$"] or part in [".", "..", "~"]: + pass + else: + temp_src = src.parent / part + if temp_src.exists(): + dest_path = (dest / part).parent + if not dest_path.exists(): + dest_path.mkdir() + logger.debug("Mkdir: {}".format(dest_path)) + if temp_src.is_file(): + shutil.copy(str(temp_src), str(dest_path)) + copy_file += "{}, ".format(temp_src) + if temp_src.is_dir(): + shutil.copytree(str(temp_src), str(dest / part)) + copy_file += "{}, ".format(temp_src) + if copy_file: + logger.debug("copy file: {}to {}".format(copy_file, dest)) + + +def format_compare_command(raw_command, compare_cmd): + end = 0 + while end < len(raw_command): + start = raw_command.find("compare ", end) + if start == -1: + break + end = start + len("compare ") + if start == 0: + prev_char = "" + else: + prev_char = raw_command[start - 1] + if end == len(raw_command): + next_char = "" + else: + next_char = raw_command[end] + if ( + prev_char.isalnum() + or prev_char == "_" + or next_char.isalnum() + or next_char == "_" + ): + continue + else: + raw_command = raw_command[:start] + compare_cmd + raw_command[end:] + return raw_command diff --git a/test/maple_test/template.cfg b/test/maple_test/template.cfg new file mode 100644 index 0000000000000000000000000000000000000000..e7b991274cde1151277aa03e907210b92cb95758 --- /dev/null +++ b/test/maple_test/template.cfg @@ -0,0 +1,15 @@ +# template.cfg: 测试套模板配置文件,编写测试套时,可参考该文件,注意测试套下的配置文件名应为test.cfg +# 当前主要由三个部分组成: +# suffix: 测试用例后缀和测试用例中的注释符 +# internal-val: 测试用例中的内置变量,变量名由支持字符串和下划线构成,运行时将替换,例如:%swarn -S 2.c -o - ==》 gcc -S 2.c -o - +# description: 测试套描述 + +[suffix] +s=// +c=// + +[internal-var] +swarn=gcc + +[description] +title=C Test diff --git a/test/maple_test/test.py b/test/maple_test/test.py new file mode 100644 index 0000000000000000000000000000000000000000..cbc4acba3fbfb674a078be444c2aa01a2a9fb286 --- /dev/null +++ b/test/maple_test/test.py @@ -0,0 +1,95 @@ +#!/usr/bin/python3 +# -*- coding:utf-8 -*- +# +# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. +# +# OpenArkCompiler is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# +# http://license.coscl.org.cn/MulanPSL +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v1 for more details. +# + +from maple_test.utils import PASS, EXEC_FLAG, EXPECT_FLAG +from maple_test.utils import read_file_with_multi_encoding +from maple_test.utils import split_comment, filter_line + + +class Case: + def __init__(self, path, test_path, comment, encoding): + self.name = str(path).replace(".", "_") + self.path = test_path / path + self.relative_path = path + self.test_path = test_path + self.comment = comment + _, comment_lines = split_comment( + comment, read_file_with_multi_encoding(self.path, encoding), + ) + self.commands = [ + command for command in self.extract_commands(comment_lines) if command + ] + self.expect = self.extract_expect(comment_lines) + + @staticmethod + def extract_expect(comment_lines): + expect_line = [filter_line(line, EXPECT_FLAG) for line in comment_lines] + expect_line = [line for line in expect_line if line] + if not expect_line: + expect = PASS + else: + expect = expect_line[-1] + return expect + + @staticmethod + def extract_commands(comment_lines): + commands = [] + command_lines = [filter_line(line, EXEC_FLAG) for line in comment_lines] + flag = False + merge_command = "" + for command in command_lines: + if command is None: + continue + if command.strip()[-1] == "\\": + flag = True + merge_command += "{} ".format(command.strip()[:-1]) + else: + if flag: + merge_command += "{} ".format(command) + flag = False + if merge_command == "": + commands.append(command) + else: + commands.append(merge_command) + if not commands: + commands.append(merge_command) + return commands + + +def read_list(path, encoding): + if not path.exists(): + return {"**"}, {} + valid_lines, _ = split_comment("#", read_file_with_multi_encoding(path, encoding)) + include_flag = "[ALL-TEST-CASE]" + exclude_flag = "[EXCLUDE-TEST-CASE]" + case_list = set() + exclude_case_list = set() + is_exclude = True + for line in valid_lines: + if line.find(include_flag) != -1: + is_exclude = False + continue + if line.find(exclude_flag) != -1: + is_exclude = True + continue + if is_exclude: + exclude_case_list.add(line) + else: + case_list.add(line) + if not case_list: + case_list = ["**"] + return case_list, exclude_case_list diff --git a/test/maple_test/utils.py b/test/maple_test/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..5c92a22e3dd32afdfcca16bd9a3eb8854f401066 --- /dev/null +++ b/test/maple_test/utils.py @@ -0,0 +1,193 @@ +#!/usr/bin/python3 +# -*- coding:utf-8 -*- +# +# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. +# +# OpenArkCompiler is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# +# http://license.coscl.org.cn/MulanPSL +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v1 for more details. +# + +import configparser +import locale +import os +import sys +import timeit +from functools import wraps +from pathlib import Path + +EXEC_FLAG = "EXEC" +ASSERT_FLAG = "ASSERT" +EXPECT_FLAG = "EXPECT" +PASS = "PASS" +FAIL = "FAIL" +XFAIL = "XFAIL" +XPASS = "XPASS" +NOT_RUN = "NOT_RUN" +UNRESOLVED = "UNRESOLVED" +UNSUPPORTED = "UNSUPPORTED" +UNSUCCESSFUL = [FAIL, UNSUPPORTED, UNRESOLVED, NOT_RUN] +ALL = [PASS, FAIL, XFAIL, XPASS, NOT_RUN, UNRESOLVED, UNSUPPORTED] +RESULT = { + PASS: 0, + FAIL: 0, + NOT_RUN: 0, + UNRESOLVED: 0, + XFAIL: 0, + XPASS: 0, +} +BASE_DIR = Path(__file__).parent.absolute() + +ENCODING = locale.getdefaultlocale()[1] if locale.getdefaultlocale()[1] else "UTF-8" +EXECUTABLE = sys.executable +COMPARE = BASE_DIR / "compare.py" + + +def read_file(file_path, encoding=ENCODING): + """Read files based on encoding and return all file lines + + :param file_path: Path + :param encoding: str + :return: + """ + lines = [] + with file_path.open(encoding=encoding) as file: + all_lines = file.readlines() + for line in all_lines: + if line.strip(): + lines.append(line.strip()) + return lines + + +def read_file_with_multi_encoding(file_path, encoding_list): + """Read files according to the encoding list and return all file lines""" + if not isinstance(encoding_list, list): + return [] + lines = [] + for encoding in encoding_list: + try: + return read_file(file_path, encoding=encoding) + except UnicodeDecodeError: + pass + return lines + + +def read_config(file_path): + """Read config file based on encoding and return test config""" + if not file_path.exists(): + return None + config = configparser.ConfigParser() + config.optionxform = str + config.read(str(file_path), encoding=ENCODING) + return config + + +def get_config_value(config, section, option): + """Read config value from test config""" + try: + return config[section][option] + except KeyError: + return None + + +def config_section_to_dict(config, section): + try: + return {k: v for k, v in config.items(section)} + except configparser.NoSectionError: + return {} + + +def ls_all(path, suffix=None): + """Output all files in a directory""" + all_files = [] + if path.is_file() and is_case(path, suffix): + all_files.append(path) + return all_files + for name, _, files in os.walk(str(path)): + for file in files: + if is_case(Path(name) / file, suffix): + all_files.append(Path(name) / file) + return all_files + + +def is_case(path, suffix): + """Determine if it is a test case based on the suffix + + :param suffix: tuple + :param path: Path + :return: + """ + if suffix is None: + return True + elif isinstance(suffix, str): + return path.suffix[1:] == suffix + return path.suffix[1:] in suffix + + +def complete_path(path): + """Returns the canonical path of a path""" + path = Path(path) + if not path.exists(): + return Path(os.path.realpath(str(path))) + return path.expanduser().resolve() + + +def filter_line(line, flag=None): + """Returns the line starting with the flag""" + if flag is None: + return line + line_flag = line.strip().split(":")[0].strip() + if line_flag == flag: + start = len(line_flag) + 1 + new_line = line.strip()[start:].strip().lstrip(":").strip() + return new_line + return None + + +def split_comment(comment, lines): + """Split text based on comments""" + comment_lines = [] + uncomment_lines = [] + comment_len = len(comment) + for line in lines: + if line.strip()[:comment_len] == comment: + comment_lines.append(line.strip()[comment_len:]) + else: + uncomment_lines.append(line) + return uncomment_lines, comment_lines + + +def add_run_path(new_path): + """Add path to PATH""" + run_env = os.environ.copy() + old_path = run_env.get("PATH") + if old_path: + run_env["PATH"] = old_path + ":" + new_path + else: + run_env["PATH"] = new_path + return run_env + + +def timer(func): + """Decorator that reports the execution time.""" + + @wraps(func) + def wrapper(*args, **kwargs): + start = timeit.default_timer() + result = func(*args, **kwargs) + end = timeit.default_timer() + print( + "Function: {}, args: {}, kwargs: {}, Time Consuming: {}s\n".format( + func.__name__, str(args), str(kwargs), end - start + ) + ) + return result + + return wrapper diff --git a/test/testsuite/irbuild_test/I0001-mapleall-irbuild-edge-addf32/Main.mpl b/test/testsuite/irbuild_test/I0001-mapleall-irbuild-edge-addf32/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..ed1c250fcdf70fc71419fbbb69e39c86aa0c1180 --- /dev/null +++ b/test/testsuite/irbuild_test/I0001-mapleall-irbuild-edge-addf32/Main.mpl @@ -0,0 +1,15 @@ + func &addf32r( + var %i f32, var %j f32 + ) f32 { + return ( + add f32(dread f32 %i, dread f32 %j))} + + func &addf32I ( + var %i f32 + ) f32 { + return ( + add f32(dread f32 %i, + constval f32 1.234f))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0002-mapleall-irbuild-edge-addi64/Main.mpl b/test/testsuite/irbuild_test/I0002-mapleall-irbuild-edge-addi64/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..b93dc8e37e7b9e31edbb1d181f3d54481aea05fe --- /dev/null +++ b/test/testsuite/irbuild_test/I0002-mapleall-irbuild-edge-addi64/Main.mpl @@ -0,0 +1,15 @@ + func $fooi64 ( + var %i i64, var %j i64 + ) i64 { + return ( + add i64(dread i64 %i, dread i64 %j))} + + func $addi64I ( + var %i i64 + ) i64 { + return ( +#add i64(dread i64 %i, constval i64 0x123456789))} + add i64(dread i64 %i, constval i64 0x800000115))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0003-mapleall-irbuild-edge-addi/Main.mpl b/test/testsuite/irbuild_test/I0003-mapleall-irbuild-edge-addi/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..4164e27feb5fcfc12b594bec646e87429eb9e62b --- /dev/null +++ b/test/testsuite/irbuild_test/I0003-mapleall-irbuild-edge-addi/Main.mpl @@ -0,0 +1,17 @@ + func $foo1 ( + var %i i32, var %j i32 + ) i32 { + return ( + add i32(dread i32 %i, dread i32 %j))} + + func $addi32I ( + var %i i32 + ) i32 { + return ( + add i32(dread i32 %i, +#constval i32 0xfff))} +# constval i32 0xffff))} + constval i32 0xfffff))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0004-mapleall-irbuild-edge-add/Main.mpl b/test/testsuite/irbuild_test/I0004-mapleall-irbuild-edge-add/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..f0229b09393423172997ee3f56ca7795d711216a --- /dev/null +++ b/test/testsuite/irbuild_test/I0004-mapleall-irbuild-edge-add/Main.mpl @@ -0,0 +1,69 @@ + func $foo ( + var %i i32 +#var %i1 i32, var %j1 i32, var %k1 i32 + ) i32 { + return ( + add i32(dread i32 %i, + constval i32 -998))} + + func $foo1 ( + var %i i32, var %j i32, var %k i32, + var %i1 i32, var %j1 i32, var %k1 i32 + ) i32 { + return ( + add i32(dread i32 %i, dread i32 %j))} + + func $foo2 ( + var %i i32, var %j i32, var %k i32 + ) i32 { + return ( + add i32(dread i32 %i, constval i32 0x111111111))} + + func $foo3 ( + var %i i64, var %j i64, var %k i32 + ) i64 { + return ( + add i64(dread i64 %i, constval i64 0x111111111))} + + func $foo4 ( + var %i i64, var %j i64, var %k i32 + )i64 { + return ( + add i64(dread i64 %i, dread i64 %j))} + + func $foo5 ( + var %i i64, var %j i64, var %k i32 + ) i64 { + return ( + add i64(dread i64 %i, constval i64 0x11111))} + + func $foo6 ( + var %i f64, var %j f64, var %k i32 + ) f64 { + return ( + add f64(dread f64 %i, constval f64 2.237))} + + func $foo66 ( + var %i f64, var %j f64, var %k i32 + ) f64 { + return ( + add f64(dread f64 %i, constval f64 2.237))} + func $foo7 ( + var %i f32, var %j f32, var %k i32 + ) f32 { + return ( + add f32(dread f32 %i, dread f32 %j))} + + func $foo8 ( + var %i f32, var %j f32, var %k i32 + ) f32 { + return ( + add f32(dread f32 %i, constval f32 2.237f))} + + func $foo9 ( + var %i i8, var %j u8, var %k i32) i32 { + return ( + add i32(dread i32 %i, dread u32 %j))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0005-mapleall-irbuild-edge-arrayadd/Main.mpl b/test/testsuite/irbuild_test/I0005-mapleall-irbuild-edge-arrayadd/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..6a12bf5e8c4014a5c556bf8d1f8946cad643fbc1 --- /dev/null +++ b/test/testsuite/irbuild_test/I0005-mapleall-irbuild-edge-arrayadd/Main.mpl @@ -0,0 +1,24 @@ +var $arr1 <[10] i32> +var $arr2 <[10] i32> +var $arr3 <[10] i32> + +func $ArrayAdd () void { + var %i i32 + doloop %i ( + constval i32 0, + lt i32 i32 (dread i32 %i, constval i32 10), + add i32(dread i32 %i, constval i32 1)){ + iassign <* [10] i32>( + array 1 a32 <* [10] i32>(addrof a32 $arr1, dread i32 %i), + add i32( + iread i32 <* [10] i32>( + array 1 a32 <* [10] i32>(addrof a32 $arr2, dread i32 %i)), + iread i32 <* [10] i32>( + array 1 a32 <* [10] i32>(addrof a32 $arr3, dread i32 %i)) + )) + } + return() +} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0006-mapleall-irbuild-edge-arrayinit/Main.mpl b/test/testsuite/irbuild_test/I0006-mapleall-irbuild-edge-arrayinit/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..3f0dd9f3814eb67a6c31c9f1bb03414579ba1105 --- /dev/null +++ b/test/testsuite/irbuild_test/I0006-mapleall-irbuild-edge-arrayinit/Main.mpl @@ -0,0 +1,12 @@ +var $iconst1 <[4] [4] i32> = [ [1007, 707, -273, 75], [0113, 0x4b, 75u, 75l], [75ul, 75lu, 31425926, 60223], [60223, 1619, 30, 314159]] +var $fconst1 <[4] [4] f64> = [ [1007.0, 707.0, -273.0, 75.0], [113.1, 4.0, 75.0, 75.1], [75.0, 75.1, 3.1425926, 6.02e23], [6.02e+23, 1.6e-19, 3.0, 3.14159]] +func &printf (var %p1 <* i8>)void +func &main ( ) i32 { + call &printf (addrof a32 $fconst1) + return (constval i32 0) } + + + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0007-mapleall-irbuild-edge-attributes/Main.mpl b/test/testsuite/irbuild_test/I0007-mapleall-irbuild-edge-attributes/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..82200c59f71e249301b6c4fefb811eb4b7a8dae3 --- /dev/null +++ b/test/testsuite/irbuild_test/I0007-mapleall-irbuild-edge-attributes/Main.mpl @@ -0,0 +1,19 @@ +var $i i32 align(4) = 987 +type $SS1 +var $iconst1 <[4] [4] i32> const = [ [1007, 707, -273, 75], [0113, 0x4b, 75u, 75l], [75ul, 75lu, 31425926, 60223], [60223, 1619, 30, 314159]] +var $fconst1 <[4] [4] f64 > volatile = [ [1007.0, 707.0, -273.0, 75.0], [113.1, 4.0, 75.0, 75.1], [75.0, 75.1, 3.1425926, 6.02e23], [6.02e+23, 1.6e-19, 3.0, 3.14159]] +func &printf const static varargs (var %p1 <* i8 > volatile const, var %p2 <* i32> volatile)void +func &noarg varargs ( ... ) void +func $main static ( ) i32 { + var %jj i32 volatile align(16) + call &printf (addrof a32 $fconst1) + return (constval i32 0) } + + + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0008-mapleall-irbuild-edge-band/Main.mpl b/test/testsuite/irbuild_test/I0008-mapleall-irbuild-edge-band/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..6b716d0e83ed8c381af78ebf3ce46eb3f8e73b8d --- /dev/null +++ b/test/testsuite/irbuild_test/I0008-mapleall-irbuild-edge-band/Main.mpl @@ -0,0 +1,41 @@ + func $band32I ( + var %i i32 + ) i32 { + return ( + band i32(dread i32 %i, + constval i32 0x12))} + func $band32I_2 ( + var %i i32 + ) i32 { + return ( + band i32(dread i32 %i, + constval i32 0x112))} + func $band32RR ( + var %i i32, var %j i32 + ) i32 { + return ( + band i32(dread i32 %i, + dread i32 %j))} + + func $band64I ( + var %i i64 + ) i64 { + return ( + band i64(dread i64 %i, + constval i64 0x1200000015))} + func $band64I_2 ( + var %i i64 + ) i64 { + return ( + band i64(dread i64 %i, + constval i64 0x1200000115))} + func $band64RR ( + var %i i64, + var %j i64 + ) i64 { + return ( + band i64(dread i64 %i, + dread i64 %j))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0009-mapleall-irbuild-edge-binary/Main.mpl b/test/testsuite/irbuild_test/I0009-mapleall-irbuild-edge-binary/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..1dcae2c67515a5a94043e0e666c2d37414537327 --- /dev/null +++ b/test/testsuite/irbuild_test/I0009-mapleall-irbuild-edge-binary/Main.mpl @@ -0,0 +1,32 @@ + # a function returning (i + j) * -998 + func $foo ( +# var %i xxx, + var %i i32, var %j i32, var %k i32, + var %i1 i32, var %j1 i32, var %k1 i32 + ) i32 { + assertge (dread i32 %i, constval i32 0) + assertlt (dread i32 %i, dread i32 %k) + return ( + ashr i32( + mul i32 ( + add i32 ( + band i32 (dread i32 %i, dread i32 %j), + bior i32 ( + bxor i32(dread i32 %i1, dread i32 %k1), + eq i32 i32 ( + depositbits i32 1 23 ( + land i32 (dread i32 %j1, dread i32 %k), + lior i32 ( + min i32 ( + shl i32 (dread i32 %k1, dread i32 %j), + sub i32 (dread i32 %j1, dread i32 %i)), + rem i32 (dread i32 %i, dread i32 %k))), + div i32( + lshr i32 ( dread i32 %k, dread i32 %i), + max i32 ( dread i32 %i, dread i32 %j))))), + constval i32 -998), + dread i32 %i))} + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0010-mapleall-irbuild-edge-bior/Main.mpl b/test/testsuite/irbuild_test/I0010-mapleall-irbuild-edge-bior/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..7f5f81bb65f0dc026ae77f120f478fde986cc779 --- /dev/null +++ b/test/testsuite/irbuild_test/I0010-mapleall-irbuild-edge-bior/Main.mpl @@ -0,0 +1,41 @@ + func $bior32I ( + var %i i32 + ) i32 { + return ( + bior i32(dread i32 %i, + constval i32 0x12))} + func $bior32I_2 ( + var %i i32 + ) i32 { + return ( + bior i32(dread i32 %i, + constval i32 0x112))} + func $bior32RR ( + var %i i32, var %j i32 + ) i32 { + return ( + bior i32(dread i32 %i, + dread i32 %j))} + + func $bior64I ( + var %i i64 + ) i64 { + return ( + bior i64(dread i64 %i, + constval i64 0x1200000015))} + func $bior64I_2 ( + var %i i64 + ) i64 { + return ( + bior i64(dread i64 %i, + constval i64 0x1200000115))} + func $bior64RR ( + var %i i64, + var %j i64 + ) i64 { + return ( + bior i64(dread i64 %i, + dread i64 %j))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0011-mapleall-irbuild-edge-bnot/Main.mpl b/test/testsuite/irbuild_test/I0011-mapleall-irbuild-edge-bnot/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..67004f9cf3559aadc39fd54273cbebf9b4e74884 --- /dev/null +++ b/test/testsuite/irbuild_test/I0011-mapleall-irbuild-edge-bnot/Main.mpl @@ -0,0 +1,37 @@ + func $foo ( + var %i i32 +#var %i1 i32, var %j1 i32, var %k1 i32 + ) i32 { + return ( + bnot i32(dread i32 %i))} + + func $foo1 ( + var %i i32, var %j i32, var %k i32, + var %i1 i32, var %j1 i32, var %k1 i32 + ) i32 { + return ( + bnot i32(dread i32 %i))} + + func $foo2 ( + var %i i32, var %j i32, var %k i32 + ) i32 { + return ( + bnot i32(constval i32 0x111111111))} + + func $foo3 ( + var %i i64, var %j i64, var %k i32 + ) i64 { + return ( + bnot i64(dread i64 %i))} + + + func $foo5 ( + var %i i64, var %j i64, var %k i32 + ) i64 { + return ( + bnot i64(constval i64 0x11111))} + +# todo float bnot + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0012-mapleall-irbuild-edge-br/Main.mpl b/test/testsuite/irbuild_test/I0012-mapleall-irbuild-edge-br/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..1ab362e93145a2e23cdce26fa55806c416ca0f45 --- /dev/null +++ b/test/testsuite/irbuild_test/I0012-mapleall-irbuild-edge-br/Main.mpl @@ -0,0 +1,12 @@ +func $fact ( + var %n i32) i32 { +@fred2 + if (ne i32 i32 (dread i32 %n, constval i32 1)) { + brfalse @fred2 (dread i32 %n) +@fred1 + return (constval i32 0) } + else { + return (constval i32 1) } } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0013-mapleall-irbuild-edge-callassigned/Main.mpl b/test/testsuite/irbuild_test/I0013-mapleall-irbuild-edge-callassigned/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..8f622b06a1ec5b674f9bebea4bd9ed0b8a34f242 --- /dev/null +++ b/test/testsuite/irbuild_test/I0013-mapleall-irbuild-edge-callassigned/Main.mpl @@ -0,0 +1,23 @@ +func $singlefoo(var %a i32) i32 { + return (dread i32 %a) +} + +func $fact(var %n i32) i32 { + var %m i32 + var %r1 i32 + var %r2 i32 + var %r3 i32 + callassigned &singlefoo(dread i32 %n) { + dassign %m 0 + } + # Not correct, but for parse and dump test. + callassigned &singlefoo(dread i32 %n) { + dassign %r1 1 + dassign %r2 2 + dassign %r3 3 + } + return (dread i32 %n) +} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0014-mapleall-irbuild-edge-ceil/Main.mpl b/test/testsuite/irbuild_test/I0014-mapleall-irbuild-edge-ceil/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..452853a54d985de2e3cdffec63b7965ff8661cf3 --- /dev/null +++ b/test/testsuite/irbuild_test/I0014-mapleall-irbuild-edge-ceil/Main.mpl @@ -0,0 +1,29 @@ + func $ceilf64toi32 ( + var %i f64 + ) i32 { + return ( + ceil i32 f64(dread f64 %i))} + + func $ceilf64toi64 ( + var %i f64 + ) i64 { + return ( + ceil i64 f64(dread f64 %i))} + + func $ceilf32toi32 ( + var %i f32 + ) i32 { + return ( + ceil i32 f32(dread f32 %i))} + + + func $ceilf32toi64 ( + var %i f32 + ) i64 { + return ( + ceil i64 f32(dread f32 %i))} + +# todo float ceil + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0015-mapleall-irbuild-edge-ciorcand/Main.mpl b/test/testsuite/irbuild_test/I0015-mapleall-irbuild-edge-ciorcand/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..8e05e65c4c36851a22091b6477713bfaa2c83c03 --- /dev/null +++ b/test/testsuite/irbuild_test/I0015-mapleall-irbuild-edge-ciorcand/Main.mpl @@ -0,0 +1,21 @@ + flavor 1 + func &ciori32 ( + var %i i32, var %j i32, var %k i32 + ) i32 { + if (cior i32 ( cior i32(dread i32 %i, dread i32 %j), dread i32 %k)) { + return (constval i32 1) + } + return ( + cior i32(dread i32 %i, dread i32 %j))} + + func &candi64 ( + var %i i64, var %j i64, var %k i64 + ) i32 { + if (cand i32 (cand i32(dread i32 %i, dread i32 %j), dread i32 %k)) { + return (constval i32 1) + } + return ( + cand i64(dread i64 %i, dread i64 %j))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0016-mapleall-irbuild-edge-classequal/Main.mpl b/test/testsuite/irbuild_test/I0016-mapleall-irbuild-edge-classequal/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..a2c9a0952c01e35aa66c27e97e3cbae948813cd4 --- /dev/null +++ b/test/testsuite/irbuild_test/I0016-mapleall-irbuild-edge-classequal/Main.mpl @@ -0,0 +1,11 @@ +type $RR +type $SS {@f1 i32, @f2 i8, @f3 i8}> +type $TT +type $UU {@f1 i32, @f2 i8, @f3 i8}> +func &foo ( var %x <$SS>) void { + var %y <$UU> + dassign %y 0 ( dread agg %x 0 ) + return () } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0017-mapleall-irbuild-edge-class_type/Main.mpl b/test/testsuite/irbuild_test/I0017-mapleall-irbuild-edge-class_type/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..5c446b85b76fe2954a1e5951ade166130449e877 --- /dev/null +++ b/test/testsuite/irbuild_test/I0017-mapleall-irbuild-edge-class_type/Main.mpl @@ -0,0 +1,10 @@ +type $RR +type $SS {@f1 i32, @f2 i8, @f3 i8}> +javaclass $TT <$SS> public static +func &foo ( + var %x <$SS>) i32 { + dassign %x 2 ( constval i32 32 ) + return ( dread i32 %x 2 ) } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0018-mapleall-irbuild-edge-constfloat/Main.mpl b/test/testsuite/irbuild_test/I0018-mapleall-irbuild-edge-constfloat/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..d476e46c4586f3ba3a39abfb9bae814690b0fe04 --- /dev/null +++ b/test/testsuite/irbuild_test/I0018-mapleall-irbuild-edge-constfloat/Main.mpl @@ -0,0 +1,15 @@ +var $nan_f32 = nanf +var $nan_f64 = nan +var $inf_f32 = -inff +var $inf_f64 = inf +var $g_f32 = -1.2f +var $g_f64 = 1.2 +func $add_f32 () f32 { + return ( + add f32(dread f32 $g_f32, constval f32 inff))} +func $add_f64 () f64 { + return ( + add f64(dread f64 $g_f64, constval f64 -inf))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0019-mapleall-irbuild-edge-constFoldTest/Main.mpl b/test/testsuite/irbuild_test/I0019-mapleall-irbuild-edge-constFoldTest/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..d0b562cc934797ab3ecb9e62d007de68e85cb57c --- /dev/null +++ b/test/testsuite/irbuild_test/I0019-mapleall-irbuild-edge-constFoldTest/Main.mpl @@ -0,0 +1,582 @@ +# 1 + 8 -> 9 +func $testSum (var %i i32) i32 { + return ( + add i32(constval i32 1, constval i32 8)) +} + +# sqrt(4.0) -> 2.0 +func $testSqrt (var %i i32) f32 { + return ( + sqrt f32(constval f32 4.0f)) +} + +# 5 + (5 + a) -> a + 10 +func &testConstVarFold00 (var %a i32) i32 { + return (add i32 ( + constval i32 5, + add i32 (constval i32 5, dread i32 %a))) +} + +# 5 + (5 - a) -> 10 - a +func &testConstVarFold01 (var %a i32) i32 { + return (add i32 ( + constval i32 5, + sub i32 (constval i32 5, dread i32 %a))) +} + +# 5 + (a + 5) -> a + 10 +func &testConstVarFold02 (var %a i32) i32 { + return (add i32 ( + constval i32 5, + add i32 (dread i32 %a, constval i32 5))) +} + +# 6 + (a - 5) -> a + 1 +func &testConstVarFold03 (var %a i32) i32 { + return (add i32 ( + constval i32 6, + sub i32 (dread i32 %a, constval i32 5))) +} + +# 5 * (5 * a) -> 5 * (5 * a) +func &testConstVarFold04 (var %a i32) i32 { + return (mul i32 ( + constval i32 5, + mul i32 (constval i32 5, dread i32 %a))) +} + +# 5 * (a * 5) -> 5 * (a * 5) +func &testConstVarFold05 (var %a i32) i32 { + return (mul i32 ( + constval i32 5, + mul i32 (dread i32 %a, constval i32 5))) +} + +# 3 - (2 - a) -> a + 1 +func &testConstVarFold06 (var %a i32) i32 { + return (sub i32 ( + constval i32 3, + sub i32 (constval i32 2, dread i32 %a))) +} + +# 3 - (2 + a) -> 1 - a +func &testConstVarFold07 (var %a i32) i32 { + return (sub i32 ( + constval i32 3, + add i32 (constval i32 2, dread i32 %a))) +} + +# 3 - (a + 2) -> 1 - a +func &testConstVarFold08 (var %a i32) i32 { + return (sub i32 ( + constval i32 3, + add i32 (dread i32 %a, constval i32 2))) +} + +# 3 - (a - 2) -> 5 - a +func &testConstVarFold09 (var %a i32) i32 { + return (sub i32 ( + constval i32 3, + sub i32 (dread i32 %a, constval i32 2))) +} + +# (2 + a) - 3 -> a - 1 +func &testConstVarFold10 (var %a i32) i32 { + return (sub i32 ( + add i32 (constval i32 2, dread i32 %a), + constval i32 3)) +} + +# (2 - a) - 3 -> -a - 1 +func &testConstVarFold11 (var %a i32) i32 { + return (sub i32 ( + sub i32 (constval i32 2, dread i32 %a), + constval i32 3)) +} + +# (a + 2) - 3 -> a - 1 +func &testConstVarFold12 (var %a i32) i32 { + return (sub i32 ( + add i32 (dread i32 %a, constval i32 2), + constval i32 3)) +} + +# (a - 2) - 3 -> a - 5 +func &testConstVarFold13 (var %a i32) i32 { + return (sub i32 ( + sub i32 (dread i32 %a, constval i32 2), + constval i32 3)) +} + +# 1 + (5 + ((5 - a) - 3)) -> 8 - a +func &testConstVarFold15 (var %a i32) i32 { + return (add i32 ( + constval i32 1, + add i32 ( + constval i32 5, + sub i32 ( + sub i32 (constval i32 5, dread i32 %a), + constval i32 3)))) +} + +# 1 + (5 + ((5 - a) * 3)) -> ((5 - a) * 3) + 6 +func &testConstVarFold16 (var %a i32) i32 { + return (add i32 ( + constval i32 1, + add i32 ( + constval i32 5, + mul i32 ( + sub i32 (constval i32 5, dread i32 %a), + constval i32 3)))) +} + +# (-a) + b --> (-a) + b +func &testConstantFoldAdd00 (var %a i32, var %b i32) i32 { + return (add i32 ( + neg i32 (dread i32 %a), + dread i32 %b)) +} + +# a + (-b) --> a + (-b) +func &testConstantFoldAdd01 (var %a i32, var %b i32) i32 { + return (add i32 ( + dread i32 %a, + neg i32 (dread i32 %b))) +} + + +# 5.0f + (5 - a) -> same, no folding with floating point numbers +func &testConstVarFold20 (var %a i32) i32 { + return (add f32 ( + constval f32 5.0f, + sub i32 (constval i32 5, dread i32 %a))) +} + + +func &testConstFold0 (var %a i32, var %b i32, var %c i32) i32 { + # ((a + 5) + ((2 + c) + (4 + 2))) -> ((a + c) + 13) + return (add i32 ( + add i32 (dread i32 %a, constval i32 0x5), + add i32 ( + add i32 (constval i32 0x2, dread i32 %c), + add i32 (constval i32 0x4, constval i32 0x2)))) +} + +func &testConstFold1 (var %a i32, var %b i32, var %c i32) i32 { + # ((a + 5) + (2 + c)) -> ((a + c) + 7) + return (add i32 ( + add i32 (dread i32 %a, constval i32 0x5), + add i32 (constval i32 0x2, dread i32 %c))) +} + +func &testConstFold2 (var %a i32, var %b i32, var %c i32) i32 { + # ((a - 5) - ((b - c) - (4 - 2))) -> ((a - (b - c)) - 3) + return (sub i32 ( + sub i32 (dread i32 %a, constval i32 0x5), + sub i32 ( + sub i32 (dread i32 %b, dread i32 %c), + sub i32 (constval i32 0x4, constval i32 0x2)))) +} + +func &testConstFold3 (var %a i32, var %b i32, var %c i32) i32 { + # ((a - 5) + ((b - c) - (4 - 2))) -> ((a + (b - c)) - 7) + return (add i32 ( + sub i32 (dread i32 %a, constval i32 0x5), + sub i32 ( + sub i32 (dread i32 %b, dread i32 %c), + sub i32 (constval i32 0x4, constval i32 0x2)))) +} + +func &testConstFold4 (var %a i32, var %b i32, var %c i32) i32 { + # ((a - 5) - ((4 - 2) - (4 - b))) -> ((a - b) - 3) + return (sub i32 ( + sub i32 (dread i32 %a, constval i32 0x5), + sub i32 ( + sub i32 (constval i32 0x4, constval i32 0x2), + sub i32 (constval i32 0x4, dread i32 %b)))) +} + +func &testConstFold5 (var %a i32, var %b i32, var %c i32) i32 { + # ((5 - a) - ((b - 4) - (4 - b))) -> (((-a) - (b - (-b))) + 13) + return (sub i32 ( + sub i32 (constval i32 0x5, dread i32 %a), + sub i32 ( + sub i32 (dread i32 %b, constval i32 0x4), + sub i32 (constval i32 0x4, dread i32 %b)))) +} + +func &testConstFold6 (var %a i32, var %b i32, var %c i32) i32 { + # ((5 - a) - ((4 - b) - (b - 4))) -> (((-a) - ((-b) - b)) - 3) + return (sub i32 ( + sub i32 (constval i32 0x5, dread i32 %a), + sub i32 ( + sub i32 (constval i32 0x4, dread i32 %b), + sub i32 (dread i32 %b, constval i32 0x4)))) +} + +func &testConstFold7 (var %a i32, var %b i32, var %c i32) i32 { + # ((a - 5) - ((4 + 2) - (4 - (b - c)))) -> ((a - (b - c)) - 7) + return (sub i32 ( + sub i32 (dread i32 %a, constval i32 0x5), + sub i32 ( + add i32 (constval i32 0x4, constval i32 0x2), + sub i32 ( + constval i32 0x4, + sub i32 (dread i32 %b, dread i32 %c))))) +} + +func &testConstFold8 (var %a i32, var %b i32, var %c i32) i32 { + # ((a - 5) - ((4 + 2) - (4 * (b - c)))) -> ((a - (-(4 * (b - c)))) - 11) + return (sub i32 ( + sub i32 (dread i32 %a, constval i32 0x5), + sub i32 ( + add i32 (constval i32 0x4, constval i32 0x2), + mul i32 ( + constval i32 0x4, + sub i32 (dread i32 %b, dread i32 %c))))) +} + +func &testConstFold9 (var %a i32, var %b i32, var %c i32) i32 { + # ((a - 5) - ((4 + 2) - (-(4 - (b - c))))) -> ((a - (-(b - c))) - 15) + return (sub i32 ( + sub i32 (dread i32 %a, constval i32 0x5), + sub i32 ( + add i32 (constval i32 0x4, constval i32 0x2), + neg i32 (sub i32 ( + constval i32 0x4, + sub i32 (dread i32 %b, dread i32 %c)))))) +} + +func &testConstFold10 (var %a i32, var %b i32, var %c i32) i32 { + # ((4 + 2) * (-(4 - (3 - c)))) -> (6 * ((-c) - 1)) + return (mul i32 ( + add i32 (constval i32 0x4, constval i32 0x2), + neg i32 (sub i32 ( + constval i32 0x4, + sub i32 (constval i32 0x3, dread i32 %c))))) +} + +func &testConstFold11 (var %a i32, var %b i32, var %c i32) i32 { + # ((4 + 2) * (4 - (3 - c))) -> (6 * (c + 1)) + return (mul i32 ( + add i32 (constval i32 0x4, constval i32 0x2), + sub i32 ( + constval i32 0x4, + sub i32 (constval i32 0x3, dread i32 %c)))) +} + +func &testConstFold12 (var %a i32, var %b i32, var %c i32) i32 { + # ((4 + 2) * (~(4 - (3 - c)))) -> (6 * (~(c + 1))) + return (mul i32 ( + add i32 (constval i32 0x4, constval i32 0x2), + bnot i32 (sub i32 ( + constval i32 0x4, + sub i32 (constval i32 0x3, dread i32 %c))))) +} + +func &testConstFold13 (var %a i32, var %b i32, var %c i32) i32 { + # (5 * (((4 - 2) + (2 & 4)) - (4 - (c | 3)))) -> (5 * ((c | 3) - 2)) + return (mul i32 ( + constval i32 0x5, + sub i32 ( + add i32 ( + sub i32 (constval i32 0x4, constval i32 0x2), + band i32 (constval i32 0x2, constval i32 0x4)), + sub i32 ( + constval i32 0x4, + bior i32 (dread i32 %c, constval i32 0x3))))) +} + +func &testConstFold14 (var %a i32, var %b i32, var %c i32) i32 { + # (5 * (((4 - 2) + (2 & 4)) * (4 - (c | 3)))) -> (5 * (2 * (4 - (c | 3)))) + return (mul i32 ( + constval i32 0x5, + mul i32 ( + add i32 ( + sub i32 (constval i32 0x4, constval i32 0x2), + band i32 (constval i32 0x2, constval i32 0x4)), + sub i32 ( + constval i32 0x4, + bior i32 (dread i32 %c, constval i32 0x3))))) +} + +func &testConstFold15 (var %a i32, var %b i32, var %c i32) i32 { + # ((1 + 0) * (~(4 - (0 * c)))) -> (~4) + return (mul i32 ( + add i32 (constval i32 0x1, constval i32 0x0), + bnot i32 (sub i32 ( + constval i32 0x4, + mul i32 (constval i32 0x0, dread i32 %c))))) +} + +func &testConstFold16 (var %a i32, var %b i32, var %c i32) i32 { + # ((~(4 - (c * 0))) * (1 + 0)) -> (~4) + return (mul i32 ( + bnot i32 (sub i32 ( + constval i32 0x4, + mul i32 (dread i32 %c, constval i32 0x0))), + add i32 (constval i32 0x1, constval i32 0x0))) +} + + +func &testConstFoldDiv0 (var %a i32, var %b i32, var %c i32) i32 { + # (5 / 0) * (1 + 1) -> 2 + return (mul i32 ( + div i32 (constval i32 0x5, constval i32 0x0), + add i32 (constval i32 0x1, constval i32 0x1))) +} + +func &testConstFoldFloor00 (var %a i32, var %b i32, var %c i32) i32 { + # (floor(4.25) + c) * (1 + 1) -> (c + 4) * 2 + return (mul i32 ( + add i32 (floor i32 f32 (constval f32 4.25f), dread i32 %c), + add i32 (constval i32 0x1, constval i32 0x1))) +} + +func &testConstFoldFloor01 (var %a i32, var %b i32, var %c i32) i32 { + # (floor(4.25) + 2) * (1 + 1) -> 12 + return (mul i32 ( + add i32 (floor i32 f32 (constval f32 4.25f), constval i32 0x2), + add i32 (constval i32 0x1, constval i32 0x1))) +} + +func &testConstFoldFloor02 (var %a i32, var %b i32, var %c i32) i32 { + # floor((floor(4.25) + 1) + (1 + a)) -> floor(a + 6) + return (floor i32 i32 (add i32 ( + add i32 (floor i32 f32 (constval f32 4.25f), constval i32 0x1), + add i32 (constval i32 0x1, dread i32 %a)))) +} + +func &testConstFoldExtractbitsNode00 () i32 { + # 487 = 00111100111 + # extractbits i32 6 5 (487) = 7 = 0111 + return (extractbits i32 6 5 (constval i32 487)) +} + +func &testConstFoldExtractbitsNode01 () i32 { + # 487 = 00111100111 + # extractbits i32 4 5 (487) = -2 = 0xfffffffffffffffe + return (extractbits i32 4 5 (constval i32 487)) +} + +func &testConstFoldExtractbitsNode02 (var %a i32, var %b i32, var %c i32) i32 { + # 487 = 00111100111 + # extractbits i32 4 5 (487) = -2 = 0xfffffffffffffffe + # extractbits((extractbits(487) + 1) + (1 + a)) -> extractbits(a) + return (extractbits i32 4 5 (add i32 ( + add i32 (extractbits i32 4 5 (constval i32 487), constval i32 0x1), + add i32 (constval i32 0x1, dread i32 %a)))) +} + +func &testConstFoldExtractbitsNode03 (var %a i32, var %b i32, var %c i32) i32 { + # 487 = 00111100111 + # extractbits i32 6 5 (487) = 7 = 0111 + # extractbits((extractbits(487) + 1) + (1 + a)) -> extractbits(a + 9) + return (extractbits i32 6 5 (add i32 ( + add i32 (extractbits i32 6 5 (constval i32 487), constval i32 0x1), + add i32 (constval i32 0x1, dread i32 %a)))) +} + +func &testConstFoldCompareNode00 (var %a i32, var %b i32, var %c i32) i32 { + # (ge(6, 2) + 1) + (1 + 2) -> 5 + return (add i32 ( + add i32 ( + ge i32 i32 (constval i32 6, constval i32 2), + constval i32 1), + add i32 (constval i32 1, constval i32 2))) +} + +func &testConstFoldCompareNode01 (var %a i32, var %b i32, var %c i32) i32 { + # ge((ge(6, 2) + 1), (1 + a)) -> ge(2, a + 1) + return (ge i32 i32 ( + add i32 ( + ge i32 i32 (constval i32 6, constval i32 2), + constval i32 1), + add i32 (constval i32 1, dread i32 %a))) +} + +func &testConstFoldTernaryNode00 (var %a i32, var %b i32, var %c i32) i32 { + # (6 > 2 ? 5 : 0) + (1 + 2) -> 8 + return ( add i32 ( + select i32 ( + ge i32 i32 (constval i32 6, constval i32 2), + constval i32 5, + constval i32 0), + add i32 (constval i32 1, constval i32 2))) +} + +func &testConstFoldTernaryNode01 (var %a i32, var %b i32, var %c i32) i32 { + # (6 > 10 ? 5 : 0) + (1 + a) -> (a + 1) + return ( add i32 ( + select i32 ( + ge i32 i32 (constval i32 6, constval i32 10), + constval i32 5, + constval i32 0), + add i32 (constval i32 1, dread i32 %a))) +} + +func &testConstFoldTernaryNode02 (var %a i32, var %b i32, var %c i32) i32 { + # 6 > a ? (1 + 6) + (1 + a) : 0 -> 6 > a ? a + 8 : 0 + return ( select i32 ( + ge i32 i32 (constval i32 6, dread i32 %a), + add i32 ( + add i32 (constval i32 1, constval i32 6), + add i32 (constval i32 1, dread i32 %a)), + constval i32 0)) +} + +type $Hello + +type $Person , + @sex u1}> + + +func &testConstFoldIassignNode00 (var %a i32) void { + # this is equivalent to dassign %a 0 (constval i32 0x6) + iassign <* i32> 0 (addrof ptr %a 0, add i32 (constval i32 1, constval i32 5)) +} + +func &testConstFoldIassignNode01 (var %a i32) void { + var %bob $Person + + # this is equivalent to dassign %bob 5 (constval i32 0x6) + iassign <* $Hello> 3 (addrof ptr %bob 2, add i32 (constval i32 1, constval i32 5)) +} + + +func &testConstFoldIassignNode02 (var %a i32) void { + # this is equivalent to dassign %a 0 (constval i32 0x6) + iassign <* i32> 0 ( + iaddrof ptr <* i32> 0 (addrof ptr %a 0), + add i32 (constval i32 1, constval i32 5)) +} + +func &testConstFoldIassignNode03 (var %a i32) void { + + var %bob $Person + # this is equivalent to dassign %bob 5 (constval i32 0x6) + iassign <* <$Hello>> 3 ( + iaddrof ptr <* <$Person>> 2 (addrof ptr %bob 0), + add i32 (constval i32 1, constval i32 5)) +} + +func &testConstFoldIassignNode04 (var %a i32) void { + + var %bob $Person + # this is equivalent to dassign %bob 5 (constval i32 0x6) + iassign <* <$Hello>> 3 ( + iaddrof ptr <* <$Hello>> 0 (addrof ptr %bob 2), + add i32 (constval i32 1, constval i32 5)) +} + + +func &testConstFoldIassignNode05 (var %a i32) void { + var %b <* i32> + + dassign %b (addrof ptr %a 0) + + # this is equivalent to iassign <* i32> 0 (dread ptr %a, constval i32 0x6) + iassign <* i32> 0 ( + iaddrof ptr <* i32> 0 (dread ptr %a), + add i32 (constval i32 1, constval i32 5)) +} + +func &testConstFoldIassignNode06 (var %a i32) void { + var %bob $Person + # this is equivalent to dassign %a 0 (dread i32 %bob 1) + dassign %a 0 (iread agg <* <$Person>> 1 (addrof ptr %bob 0)) +} + +func &testConstFoldSwitchNode00 () void { + # switch (1+4) ... -> goto @lab1 + switch ( add i32 (constval i32 1, constval i32 4)) @labdft { + -2: goto @lab0 + 5: goto @lab1 + 8: goto @lab9 } + + @lab0 + return (constval i32 1) + @labdft + return (constval i32 2) + @lab9 + return (constval i32 3) + @lab1 + return (constval i32 4) +} + +func &testConstFoldSwitchNode01 () void { + # switch (1 + 10) ... -> goto @labdft + switch ( add i32 (constval i32 1, constval i32 10)) @labdft { + -2: goto @lab0 + 5: goto @lab1 + 8: goto @lab9 } + + @lab0 + return (constval i32 1) + @labdft + return (constval i32 2) + @lab9 + return (constval i32 3) + @lab1 + return (constval i32 4) +} + +func &testConstFoldSwitchNode02 (var %a i32) void { + # switch (5 + (5 - a)) ... -> switch (10 - a) ... + switch (add i32 ( + constval i32 5, + sub i32 (constval i32 5, dread i32 %a))) @labdft { + -2: goto @lab0 + 5: goto @lab1 + 8: goto @lab9 } + + @lab0 + return (constval i32 1) + @labdft + return (constval i32 2) + @lab9 + return (constval i32 3) + @lab1 + return (constval i32 4) +} + + +func &testConstFoldArrayNode00 (var %x i32) void { + var %a <* [15][15] i32> + # fold indexes -> array ptr <* <[15][15] i32>> (constval i32 0x6, constval i32 0x4) + dassign %x ( + iread i32 <* i32> ( + array 1 ptr <* [15][15] i32> (addrof ptr %a, + add i32 (constval i32 1, constval i32 5), + sub i32 (constval i32 5, constval i32 1)))) +} + +func &testDepositbitsNodeNode00 (var %a i32, var %c i32) i32 { + return ( depositbits i32 1 23 ( + add i32 ( + add i32 (dread i32 %a, constval i32 0x5), + add i32 ( + add i32 (constval i32 0x2, dread i32 %c), + add i32 (constval i32 0x4, constval i32 0x2))), + add i32 (constval i32 0x4, constval i32 0x8))) +} + +func &testDepositbitsNodeNode01 () i32 { + return ( depositbits i32 1 23 ( + add i32 ( + add i32 (constval i32 0x5, constval i32 0x5), + add i32 ( + add i32 (constval i32 0x2, constval i32 0x2), + add i32 (constval i32 0x4, constval i32 0x2))), + add i32 (constval i32 0x4, constval i32 0x8))) +} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0020-mapleall-irbuild-edge-cvtllutof32/Main.mpl b/test/testsuite/irbuild_test/I0020-mapleall-irbuild-edge-cvtllutof32/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..b3a908413eb2eed59812f58d46face8b5c1503f3 --- /dev/null +++ b/test/testsuite/irbuild_test/I0020-mapleall-irbuild-edge-cvtllutof32/Main.mpl @@ -0,0 +1,8 @@ + func $cvtu64tof32 ( + var %i u64 + ) f32 { + return ( + cvt f32 u64(dread u64 %i))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0021-mapleall-irbuild-edge-cvtllutof64/Main.mpl b/test/testsuite/irbuild_test/I0021-mapleall-irbuild-edge-cvtllutof64/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..8cfabdb80ae05938b81b862982b79bb3bcdccb07 --- /dev/null +++ b/test/testsuite/irbuild_test/I0021-mapleall-irbuild-edge-cvtllutof64/Main.mpl @@ -0,0 +1,8 @@ + func $cvtu64tof64 ( + var %i u64 + ) f64 { + return ( + cvt f64 u64(dread u64 %i))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0022-mapleall-irbuild-edge-depositbits1/Main.mpl b/test/testsuite/irbuild_test/I0022-mapleall-irbuild-edge-depositbits1/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..80efe03affd5546fc7b9db7a81a16ba23539695e --- /dev/null +++ b/test/testsuite/irbuild_test/I0022-mapleall-irbuild-edge-depositbits1/Main.mpl @@ -0,0 +1,10 @@ + func $foo ( + var %i i32 +#var %i1 i32, var %j1 i32, var %k1 i32 + ) i32 { + return ( + depositbits i32 1 23( + constval i32 0xfff, constval i32 0x11))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0023-mapleall-irbuild-edge-DirectStorageAccess/Main.mpl b/test/testsuite/irbuild_test/I0023-mapleall-irbuild-edge-DirectStorageAccess/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..daf3d347ea19797fdba977e824add6046ea88b6a --- /dev/null +++ b/test/testsuite/irbuild_test/I0023-mapleall-irbuild-edge-DirectStorageAccess/Main.mpl @@ -0,0 +1,61 @@ +#This test case covers the following items: + +#MapleIR Direct read/write +#Direct acfgrecesses are associated with scalar variables and fixed fields inside +#structures. Direct accesses can be mapped to pseudo-register if the variable +#or field has no alias. +#In MAPLE IR, dassign and dread are the opcodes for direct assignments and +#direct references; + +#Syntax +#dread +#dassign() +#Type syntax +#type +func $strcpy ( var %dest <*i8>, var %src <*i8> ) <*i8> + +type $People < struct{ + @name <[10] i8>, + @age i8 }> + +type $Info < struct{ + @number i32, + @employee <$People> }> + +var $p <$People> +var $temp<[6] i8>= [ 104, 117, 97, 119, 101, 105 ] + +func $main ( )i32 { + var %a i8 + dassign %a ( constval i8 120 ) + var %b i8 + dassign %b ( dread i32 %a ) + var %i i32 + dassign %i ( constval i32 5 ) + var %ii i32 + dassign %ii ( dread i32 %i ) + var %j f32 + dassign %j ( constval f32 12.9f ) + var %jj f32 + dassign %jj ( dread f32 %j ) + var %k f64 + dassign %k ( constval f64 20.5 ) + var %kk f64 + dassign %kk ( dread f64 %k ) + var %p < $People > + var %pp < $People > + dassign $p 2 ( constval i32 25) + # dassign $p 1 ( constval i32 0 ) + #call (,...,) + call &strcpy ( addrof a64 %p, addrof a64 $temp) + call &strcpy ( addrof a64 %pp, addrof a64 %p) + var %info < $Info > + var %info2 < $Info > + dassign %info 2( dread agg %p ) + dassign %info2 2( dread agg %info 2) + return ( constval i32 444 ) +} + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0024-mapleall-irbuild-edge-dowhile/Main.mpl b/test/testsuite/irbuild_test/I0024-mapleall-irbuild-edge-dowhile/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..67b210a10c947e8fefa363e1db8c5c391e3bd07d --- /dev/null +++ b/test/testsuite/irbuild_test/I0024-mapleall-irbuild-edge-dowhile/Main.mpl @@ -0,0 +1,12 @@ +func $foo (var %i i32) i32 { + dowhile { + dassign %i ( + mul i32 (dread i32 %i, dread i32 %i)) + dassign %i ( + add i32 (dread i32 %i, constval i32 1) )} ( + lt i32 i32 ( dread i32 %i, constval i32 10) ) + return ( constval i32 0 ) +} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0025-mapleall-irbuild-edge-dupvardecl/Main.mpl b/test/testsuite/irbuild_test/I0025-mapleall-irbuild-edge-dupvardecl/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..880fd8705f0a5a85ed6f46d5721c1bcb79334cd8 --- /dev/null +++ b/test/testsuite/irbuild_test/I0025-mapleall-irbuild-edge-dupvardecl/Main.mpl @@ -0,0 +1,7 @@ +var $g <*ptr> +var $h <*ptr> = addrof ptr $g +var $g <*ptr> = addrof ptr $h +var $h <*ptr> + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0026-mapleall-irbuild-edge-externfunc/Main.mpl b/test/testsuite/irbuild_test/I0026-mapleall-irbuild-edge-externfunc/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..3a797ae50b147b854397f72ee724e260840ae412 --- /dev/null +++ b/test/testsuite/irbuild_test/I0026-mapleall-irbuild-edge-externfunc/Main.mpl @@ -0,0 +1,19 @@ +func $foo ( var %i i32 ) i32 +func $fact ( var %n i32) i32 +func $fact ( var %n i32) i32 +func $foo ( var %i i32 ) i32 + +func $fact ( + var %n i32) i32 { + if (ne i32 i32 (dread i32 %n, constval i32 1)) { + call &foo( + sub i32 (dread i32 %n, constval i32 1)) + return (regread i32 %%retval)} + else { + return (constval i32 1) } } + +func $foo ( var %i i32 ) i32 { + return (dread i32 %i) } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0027-mapleall-irbuild-edge-externvar/Main.mpl b/test/testsuite/irbuild_test/I0027-mapleall-irbuild-edge-externvar/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..8739173e937d4869d8ea5bf327a6ddbaadbbab8e --- /dev/null +++ b/test/testsuite/irbuild_test/I0027-mapleall-irbuild-edge-externvar/Main.mpl @@ -0,0 +1,7 @@ +var $extern_var extern i32 public + +func $test_extern_var ( var %i i32 ) i32 { + return (dread i32 $extern_var) } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0028-mapleall-irbuild-edge-extractbits/Main.mpl b/test/testsuite/irbuild_test/I0028-mapleall-irbuild-edge-extractbits/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..4b33225b45ac0c3615f02dc00297bde74bd6d9ef --- /dev/null +++ b/test/testsuite/irbuild_test/I0028-mapleall-irbuild-edge-extractbits/Main.mpl @@ -0,0 +1,83 @@ + func $foo ( + var %i i32 +#var %i1 i32, var %j1 i32, var %k1 i32 + ) i32 { + return ( + extractbits i32 1 23( + constval i32 -998))} + + func $foo1 ( + var %i i32, var %j i32, var %k i32, + var %i1 i32, var %j1 i32, var %k1 i32 + ) i32 { + return ( + extractbits i32 0 5(dread i32 %i))} + + func $foo11 ( + var %i i32, var %j i32, var %k i32, + var %i1 i32, var %j1 i32, var %k1 i32 + ) u32 { + return ( + extractbits u32 0 5(dread i32 %i))} + + func $foo2 ( + var %i i32, var %j i32, var %k i32 + ) i32 { + return ( + extractbits i32 3 20(constval i32 0x111111111))} + + func $foo3 ( + var %i i64, var %j i64, var %k i32 + ) i64 { + return ( + extractbits i64 5 50(dread i64 %i))} + + func $foo4 ( + var %i i64, var %j i64, var %k i32 + )i64 { + return ( + extractbits i64 6 44 (dread i64 %i))} + + func $foo5 ( + var %i i64, var %j i64, var %k i32 + ) i64 { + return ( + extractbits i64 1 10(constval i64 0x11111))} + + func $foo9 ( + var %i i8, var %j u8, var %k i32) u32 { + return ( + extractbits u32 1 31(dread u32 %j))} + + func $foo51 ( + var %i u64 + ) u64 { + return ( + extractbits u64 0 15(constval i64 0x11111))} + + func $foo52 ( + var %i i32 + ) i32 { + return ( + sext i32 11 (constval i32 99))} + + func $foo53 ( + var %i u64 + ) u64 { + return ( + zext u64 11 (constval u64 88))} + + func $foo54 ( + var %i i32 + ) i32 { + return ( + sext i32 11 (dread i32 %i))} + + func $foo55 ( + var %i u64 + ) u64 { + return ( + zext u64 41 (dread u64 %i))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0029-mapleall-irbuild-edge-fact/Main.mpl b/test/testsuite/irbuild_test/I0029-mapleall-irbuild-edge-fact/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..31a0f83b6c8f2854e8adf0bc09555df2d874588b --- /dev/null +++ b/test/testsuite/irbuild_test/I0029-mapleall-irbuild-edge-fact/Main.mpl @@ -0,0 +1,17 @@ +#int fact(int n) { +# if (n == 1) +# return 1; +# return n * fact(n-1); +#} + +func $fact (var %n i32) i32 { + if (ne i32 i32 (dread i32 %n, constval i32 1)) { + call &fact (sub i32 (dread i32 %n, constval i32 1)) + return (mul i32 (dread i32 %n, regread i32 %%retval)) + } + return (constval i32 1) +} + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0030-mapleall-irbuild-edge-farray/Main.mpl b/test/testsuite/irbuild_test/I0030-mapleall-irbuild-edge-farray/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..a329387a2862f5e25d90e3bbf08806dfe07918d4 --- /dev/null +++ b/test/testsuite/irbuild_test/I0030-mapleall-irbuild-edge-farray/Main.mpl @@ -0,0 +1,18 @@ +# typedef struct { int f1, char f2, unsigned short f3[]} SS; +# void foo(SS *x, SS *y) { +# int i, j; +# x->f3[ij] = y->f3[j]; +# } + +type $SS }> +func $foo ( var %x <*<$SS>>, var %y <*<$SS>>) void { + var %i i32 + var %j i32 + iassign <* u16> ( array 1 ptr <*[]u16> ( + iaddrof ptr <* <$SS>> 3 (dread ptr %x), dread i32 %i), + iread u16 <* u16> ( array 1 ptr <*[]u16> ( + iaddrof ptr <* <$SS>> 3 (dread ptr %y), dread i32 %j))) + return() } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0031-mapleall-irbuild-edge-fileinfo/Main.mpl b/test/testsuite/irbuild_test/I0031-mapleall-irbuild-edge-fileinfo/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..5bb0c2903e534d3fa66d7c2c16a6a0067464d350 --- /dev/null +++ b/test/testsuite/irbuild_test/I0031-mapleall-irbuild-edge-fileinfo/Main.mpl @@ -0,0 +1,38 @@ +fileinfo{ + @magic 345, + @filename "adir/thisisafile.dex", + @dexoffset 560, + @flags 0x01ef, + @linksize 100 +} +type $SS +var $sconst1 , + @f33 i32, + @accessflag 0x45e, + @classdataoffset 118, + @f44 i32, + @f55 f32, + @f66 f32, + @superclassid 3333 + }> +func $fact () i32 { + funcinfo{ + @funcname "afunc", + @registers 345, + @ins 560, + @outs 444 + } + return (dread i32 $sconst1 1) + funcinfo{ + @funcidx 345, + @classidx 560 + } +} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0032-mapleall-irbuild-edge-first/Main.mpl b/test/testsuite/irbuild_test/I0032-mapleall-irbuild-edge-first/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..911d3a1d307e80de543ab6d0bfe28b53c46b3306 --- /dev/null +++ b/test/testsuite/irbuild_test/I0032-mapleall-irbuild-edge-first/Main.mpl @@ -0,0 +1,13 @@ + # a function returning (i + j) * -998 + func $foo ( +# var %i xxx, + var %i i32, + var %j i32) i32 { + return ( + mul i32 ( + add i32 ( dread i32 %i, dread i32 %j), + constval i32 -998))} + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0033-mapleall-irbuild-edge-floor/Main.mpl b/test/testsuite/irbuild_test/I0033-mapleall-irbuild-edge-floor/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..9e14dbb7d094b91c67fec8de6880f6d23143eef9 --- /dev/null +++ b/test/testsuite/irbuild_test/I0033-mapleall-irbuild-edge-floor/Main.mpl @@ -0,0 +1,29 @@ + func $floorf64toi32 ( + var %i f64 + ) i32 { + return ( + floor i32 f64(dread f64 %i))} + + func $floorf64toi64 ( + var %i f64 + ) i64 { + return ( + floor i64 f64(dread f64 %i))} + + func $floorf32toi32 ( + var %i f32 + ) i32 { + return ( + floor i32 f32(dread f32 %i))} + + + func $floorf32toi64 ( + var %i f32 + ) i64 { + return ( + floor i64 f32(dread f32 %i))} + +# todo float floor + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0034-mapleall-irbuild-edge-foreachelem/Main.mpl b/test/testsuite/irbuild_test/I0034-mapleall-irbuild-edge-foreachelem/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..3a903d4dfd942181c787ac7bbe5183f6f39c0e89 --- /dev/null +++ b/test/testsuite/irbuild_test/I0034-mapleall-irbuild-edge-foreachelem/Main.mpl @@ -0,0 +1,14 @@ +var $arr1 <[10] f32> + +func $ArrayAdd () f32 { + var %ff i32 + var %sum f32 + dassign %sum ( constval f32 0.0f ) + foreachelem %ff $arr1 { + dassign %sum ( add f32 ( dread f32 %sum, dread f32 %ff ) ) + } + return ( dread f32 %sum ) +} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0035-mapleall-irbuild-edge-forwarddeclare/Main.mpl b/test/testsuite/irbuild_test/I0035-mapleall-irbuild-edge-forwarddeclare/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..f84b8d638026709ef8f764f798d49cefa5f40550 --- /dev/null +++ b/test/testsuite/irbuild_test/I0035-mapleall-irbuild-edge-forwarddeclare/Main.mpl @@ -0,0 +1,10 @@ +var $test_var i32 public + +func $test_extern_var ( var %i i32 ) i32 { + return (dread i32 $test_var) +} + +var $test_var i32 public = 0 + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0036-mapleall-irbuild-edge-funcptr/Main.mpl b/test/testsuite/irbuild_test/I0036-mapleall-irbuild-edge-funcptr/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..20e537607e60a307e1a9f6d4046efdfbe7292903 --- /dev/null +++ b/test/testsuite/irbuild_test/I0036-mapleall-irbuild-edge-funcptr/Main.mpl @@ -0,0 +1,12 @@ +func $fact ( + var %n i32) i32 { + var %foo + if (ne i32 i32 (dread i32 %n, constval i32 1)) { + icall ( dread a64 %foo, + sub i32 (dread i32 %n, constval i32 1)) + return (regread i32 %%retval)} + else { + return (constval i32 1) } } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0037-mapleall-irbuild-edge-generics/Main.mpl b/test/testsuite/irbuild_test/I0037-mapleall-irbuild-edge-generics/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..d3875879ee5b2321a4c34fd2828552cc283e5549 --- /dev/null +++ b/test/testsuite/irbuild_test/I0037-mapleall-irbuild-edge-generics/Main.mpl @@ -0,0 +1,31 @@ +type $ss1 , + @x <* f32>}> +type $ss2 , + @x <* f32>}>, + @pa <* }>>, + @x1 <[10] f64>, + @dx }> +type $ss3 <[] > +func &foo (var %x ) i32 { + var %y + dassign %y (dread agg %x) + return (dread i32 %y 1) +} +var $g <$ss1{!T=i32}> +var $h <$ss2{!U=i32,!SS=<$ss1{!T=f32}>}> +func &bar () i32 { + var %i i32 + callinstant &foo<{!W=<$ss2{!U=f32,!SS=i32}>}>( dread agg $g ) + callinstantassigned &foo<{!W=<$ss1{!T=i32}>}>( dread agg $g ) { dassign %i 0 } + virtualcallinstant &foo<{!W=<$ss2{!U=f32,!SS=i32}>}>( dread agg $g ) + virtualcallinstantassigned &foo<{!W=<$ss1{!T=i32}>}>( dread agg $g ) { dassign %i 0 } + superclasscallinstant &foo<{!W=<$ss2{!U=f32,!SS=i32}>}>( dread agg $g ) + superclasscallinstantassigned &foo<{!W=<$ss1{!T=i32}>}>( dread agg $g ) { dassign %i 0 } + interfacecallinstant &foo<{!W=<$ss2{!U=f32,!SS=i32}>}>( dread agg $g ) + interfacecallinstantassigned &foo<{!W=<$ss1{!T=i32}>}>( dread agg $g ) { dassign %i 0 } + return ( dread i32 %i ) +} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0038-mapleall-irbuild-edge-global/Main.mpl b/test/testsuite/irbuild_test/I0038-mapleall-irbuild-edge-global/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..37e344e4952365c8ef1546107276b9eb9e6356ac --- /dev/null +++ b/test/testsuite/irbuild_test/I0038-mapleall-irbuild-edge-global/Main.mpl @@ -0,0 +1,114 @@ +var $g_i8_u +var $g_i8 = 8 +var $g_u8_u +var $g_u8 = 8 + +var $g_i16_u +var $g_i16 = 16 +var $g_u16_u +var $g_u16 = 16 + +var $g_i32_u +var $g_i32 = 32 +var $g_u32_u +var $g_u32 = 32 + +var $g_i64_u +var $g_i64 = 0x123456789a +var $g_u64_u +var $g_u64 = 0x123456789a + +var $g_f32_u +var $g_f32 = 1.2f + +var $g_f64_u +var $g_f64 = 2.4 + +# i8/u8 +func $add_i8_u () i8 { + return ( + add i32(dread i32 $g_i8_u, constval i32 0))} + +func $add_i8 () i8 { + return ( + add i32(dread i32 $g_i8, constval i32 0))} + +func $add_u8_u () u8 { + return ( + add u32(dread u32 $g_u8_u, constval u32 0))} + +func $add_u8 () u8 { + return ( + add u32(dread u32 $g_u8, constval u32 0))} + +# i16/u16 +func $add_i16_u () i16 { + return ( + add i32(dread i32 $g_i16_u, constval i32 0))} + +func $add_i16 () i16 { + return ( + add i32(dread i32 $g_i16, constval i32 0))} + +func $add_u16_u () u16 { + return ( + add u32(dread u32 $g_u16_u, constval u32 0))} + +func $add_u16 () u16 { + return ( + add u32(dread u32 $g_u16, constval u32 0))} + +# i32/u32 +func $add_i32_u () i32 { + return ( + add i32(dread i32 $g_i32_u, constval i32 0))} + +func $add_i32 () i32 { + return ( + add i32(dread i32 $g_i32, constval i32 0))} + +func $add_u32_u () u32 { + return ( + add u32(dread u32 $g_u32_u, constval u32 0))} + +func $add_u32 () u32 { + return ( + add u32(dread u32 $g_u32, constval u32 0))} + +# i64/u64 +func $add_i64_u () i64 { + return ( + add i64(dread i64 $g_i64_u, constval i64 0))} + +func $add_i64 () i64 { + return ( + add i64(dread i64 $g_i64, constval i64 0))} + +func $add_u64_u () u64 { + return ( + add u64(dread u64 $g_u64_u, constval u64 0))} + +func $add_u64 () u64 { + return ( + add u64(dread u64 $g_u64, constval u64 0))} + +# # f32 +# func $add_f32_u () f32 { + # return ( + # add f32(dread f32 $g_f32_u, constval f32 0.0f))} + +# func $add_f32 () f32 { + # return ( + # add f32(dread f32 $g_f32, constval f32 0.0f))} + +# # f64 +# func $add_f64_u () f64 { + # return ( + # add f64(dread f64 $g_f64_u, constval f64 0))} + +# func $add_f64 () f64 { + # return ( + # add f64(dread f64 $g_f64, constval f64 0))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0039-mapleall-irbuild-edge-hello/Main.mpl b/test/testsuite/irbuild_test/I0039-mapleall-irbuild-edge-hello/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..6983956b7ccf14a7801288ec8887bf70579dbfc1 --- /dev/null +++ b/test/testsuite/irbuild_test/I0039-mapleall-irbuild-edge-hello/Main.mpl @@ -0,0 +1,11 @@ +var $const1 <[13] i8> = [ 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 10, 0 ] +func $printf (var %p1 <* i8>)void +func $main ( ) i32 { + call &printf (addrof a32 $const1) + return (constval i32 0) } + + + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0040-mapleall-irbuild-edge-icallassigned/Main.mpl b/test/testsuite/irbuild_test/I0040-mapleall-irbuild-edge-icallassigned/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..0a253eb2ee7cc4a4b61403d9a4c2734562f855ba --- /dev/null +++ b/test/testsuite/irbuild_test/I0040-mapleall-irbuild-edge-icallassigned/Main.mpl @@ -0,0 +1,24 @@ +func $fact ( + var %n i32) i32 { + var %foo + var %r1 i32 + var %r2 i32 + var %r3 i32 + if (ne i32 i32 (dread i32 %n, constval i32 1)) { + icallassigned ( dread a64 %foo, + sub i32 (dread i32 %n, constval i32 1)) { + dassign %r1 0 + } + # Not correct, but for parse and dump test. + icallassigned ( dread a64 %foo, + sub i32 (dread i32 %n, constval i32 1)) { + dassign %r1 1 + dassign %r2 2 + dassign %r3 3 + } + return (dread i32 %n) + } +} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0041-mapleall-irbuild-edge-if1/Main.mpl b/test/testsuite/irbuild_test/I0041-mapleall-irbuild-edge-if1/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..cf4e726d1e75fab5eeec53aa40476ff0470a8ec4 --- /dev/null +++ b/test/testsuite/irbuild_test/I0041-mapleall-irbuild-edge-if1/Main.mpl @@ -0,0 +1,13 @@ +#int fact (int n) { +# if(n != 1) +# return foo(n - 1); +# else return 1; +#} + +func $fact ( + var %n i32) i32 { + if (ne i32 i32 (dread i32 %n, constval i32 1)) { + return (constval i32 0) } } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0042-mapleall-irbuild-edge-if/Main.mpl b/test/testsuite/irbuild_test/I0042-mapleall-irbuild-edge-if/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..640bba9d4007aff19ef3460b6c74d17c05b3d301 --- /dev/null +++ b/test/testsuite/irbuild_test/I0042-mapleall-irbuild-edge-if/Main.mpl @@ -0,0 +1,15 @@ +#int fact (int n) { +# if(n != 1) +# return foo(n - 1); +# else return 1; +#} + +func $fact ( + var %n i32) i32 { + if (ne i32 i32 (dread i32 %n, constval i32 1)) { + return (constval i32 0) } + else { + return (constval i32 1) } } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0043-mapleall-irbuild-edge-if_then_else/Main.mpl b/test/testsuite/irbuild_test/I0043-mapleall-irbuild-edge-if_then_else/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..4a29fa4fe34b7e25cc49e14be1b25673fd4c9386 --- /dev/null +++ b/test/testsuite/irbuild_test/I0043-mapleall-irbuild-edge-if_then_else/Main.mpl @@ -0,0 +1,21 @@ +type $atyp <[10] f32> +var $fff = 7789 +func $foo ( var %i i32 )i32 + +func $fact ( + var %n i32, var %m f32) i32 { + type %i32ty + var %alocal <%i32ty> + dassign %alocal (constval i32 999) + if (ne i32 i32 (dread i32 %n, constval i32 1)) { + eval (dread i32 %n) + call &foo( + add i32 (dread i32 %n, constval i32 1)) + return (regread i32 %%retval)} + else { + return (constval i32 1) } } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0044-mapleall-irbuild-edge-importpath/Main.mpl b/test/testsuite/irbuild_test/I0044-mapleall-irbuild-edge-importpath/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..a6810f4fe2fd556964c776f3e9bd713f9a3aadbb --- /dev/null +++ b/test/testsuite/irbuild_test/I0044-mapleall-irbuild-edge-importpath/Main.mpl @@ -0,0 +1,11 @@ +importpath "." +importpath ".." +importpath "../ff" +var $x i32 +importpath "/a/bb/ccc/" +func $foo (var %y i32) void { + dassign $x (dread i32 %y) +} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0045-mapleall-irbuild-edge-indirect/Main.mpl b/test/testsuite/irbuild_test/I0045-mapleall-irbuild-edge-indirect/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..743f6913fa4ad0756e9812d8b312871e93ca51e4 --- /dev/null +++ b/test/testsuite/irbuild_test/I0045-mapleall-irbuild-edge-indirect/Main.mpl @@ -0,0 +1,12 @@ +var $p <* i32> +func $Foo (var %i i32) void { + iassign <* i32>( + dread a64 $p, + add i32( + iread i32 <* i32> ( dread a64 $p ), + dread i32 %i)) + return() +} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0046-mapleall-irbuild-edge-InDirectStorageAccess/Main.mpl b/test/testsuite/irbuild_test/I0046-mapleall-irbuild-edge-InDirectStorageAccess/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..7abf80f7dd59d7f1a0f09af448f8e3ef9340269d --- /dev/null +++ b/test/testsuite/irbuild_test/I0046-mapleall-irbuild-edge-InDirectStorageAccess/Main.mpl @@ -0,0 +1,191 @@ +#indirect access are associated with pionters and arrays +#iassign(, ) +# type gives the high level type of and must be a pointer type +# is computed to return an address +# return a value +#iread() +# +func $new ( var %n i32 )a64 +func $strcpy ( var %dest <*i8>, var %src <*i8> )<*i8> +type $People < struct{ + @name < * i8 >, + @number < * i32> }> +func $addition ( var %a i32, var %b i32 )i32 { + return( + add i32( dread i32 %a, dread i32 %b ))} +var $name < [6] i8 > = [ 104, 117, 97, 119, 101, 105 ] +var $temp<[6] i8> = [ 104, 117, 97, 119, 101, 105 ] +func $main ( ) i32 { + var %cPtr < * i8 > + dassign %cPtr ( constval a64 0) + dassign %cPtr ( + addrof a64 $name) + + var %cPtr1 i8 + dassign %cPtr1( + iread i32 < * i8 >( dread a64 %cPtr )) + dassign %cPtr( + add u64( + dread a64 %cPtr, + constval u64 1)) + var %cPtr2 <* i8> + dassign %cPtr2( + add u64( + dread a64 %cPtr, + constval u64 1)) + + var %iPtr1 <* i32 > + var %iPtr2 <* i32 > + iassign < * i32>( + dread a64 %iPtr1, + constval i32 10) + iassign < * i32 >( + dread a64 %iPtr2, + iread i32 < * i32> ( + dread a64 %iPtr1)) + var %sPtr <* $People > + #call $new( + # iread <>) + call &new (constval u32 128) + dassign %sPtr( + regread a64 %%retval + ) + call &strcpy ( dread a64 %sPtr 0 , + addrof a64 $temp) + iassign <* i32>( + dread a64 %sPtr 0, + constval i32 5) + var %i i32 + var %j i32 + var %aPtr1 < [10] i32 > + var %aPtr2 < [10][10] i32 > + var %aPtr3 < [10][10][10] i32 > + dassign %i ( constval i32 0 ) + while( + lt i32 i32 ( dread i32 %i, constval i32 10 )){ + iassign < *[10] i32 >( + array 1 a64 < *[10] i32 >(addrof a64 %aPtr1, + dread i32 %i), + constval i32 10 ) + + iassign< *[10] i32 >( + array 1 a64 < *[10] i32 >( addrof a64 %aPtr1, + dread i32 %i), + dread i32 %i ) + + iassign < *[10] i32 >( + array 1 a64 < *[10] i32 >( addrof a64 %aPtr1, + dread i32 %i ), + iread i32 <* i32 >( + addrof a64 %aPtr1 )) + dassign %i( + add i32( + dread i32 %i, + constval i32 1))} + + + dassign %i ( constval i32 0 ) + while( + lt i32 i32 ( dread i32 %i, constval i32 10 )){ + dassign %j ( constval i32 0 ) + while( + lt i32 i32 ( dread i32 %j, constval i32 10 )){ + iassign < *[10][10] i32 >( + array 1 a64 < *[10][10] i32 >( addrof a64 %aPtr2, + dread i32 %i, + dread i32 %j), + constval i32 10 ) + iassign < *[10][10] i32 >( + array 1 a64< *[10][10] i32 >( addrof a64 %aPtr2, + dread i32 %i, + dread i32 %j), + mul i32 ( + dread i32 %i, + dread i32 %j)) + iassign< *[10][10] i32 >( + array 1 a64 < *[10][10] i32 >( addrof a64 %aPtr2, + dread i32 %i, + dread i32 %j), + iread i32 < *[10] i32 >( + array 1 a64< *[10] i32 >( + addrof a64 %aPtr1, + rem i32 ( + mul i32 ( + dread i32 %i, + dread i32 %j), + constval i32 10)))) + dassign %j( + add i32( + dread i32 %j, + constval i32 1))} + dassign %i( + add i32( + dread i32 %i, + constval i32 1))} + var %k i32 + dassign %i ( constval i32 0) + while( + lt i32 i32 ( dread i32 %i, constval i32 10 )){ + dassign %j ( constval i32 0) + while( + lt i32 i32 ( dread i32 %j, constval i32 10)){ + while( + lt i32 i32 ( dread i32 %k, constval i32 10)){ + iassign < *[10][10][10] i32 >( + array 1 a64 < *[10][10][10] i32 >(addrof a64 %aPtr3, + dread i32 %i, + dread i32 %j, + dread i32 %k), + constval i32 10) + iassign < *[10][10][10] i32 >( + array 1 a64 < *[10][10][10] i32>(addrof a64 %aPtr3, + dread i32 %i, + dread i32 %j, + dread i32 %k), + mul i32 ( + mul i32 ( + dread i32 %i, + dread i32 %j), + dread i32 %k)) + iassign < *[10][10][10] i32 >( + array 1 a64 < *[10][10][10] i32 >(addrof a64 %aPtr3, + dread i32 %i, + dread i32 %j, + dread i32 %k), + mul i32 ( + iread i32 < *[10][10] i32>( + array 1 a64 <*[10][10] i32>( addrof a64 %aPtr1, + dread i32 %i, + dread i32 %j)), + constval i32 10)) + dassign %k( + add i32( + dread i32 %k, + constval i32 1))} + dassign %j( + add i32( + dread i32 %j, + constval i32 1))} + dassign %i( + add i32( + dread i32 %i, + constval i32 1))} + + var %fPtr1 + var %fPtr2 + + dassign %fPtr1( + addrof a64 $addition) + dassign %fPtr2( + addrof a64 $addition) + var %result i32 + icall ( dread a64 %fPtr1, constval i32 2, constval i32 3) + dassign %result( + regread i32 %%retval) + return ( dread i32 %result)} + + + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0047-mapleall-irbuild-edge-interface/Main.mpl b/test/testsuite/irbuild_test/I0047-mapleall-irbuild-edge-interface/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..f4c0354e7f513018cdfffc17dc64f8cd1a7b09c0 --- /dev/null +++ b/test/testsuite/irbuild_test/I0047-mapleall-irbuild-edge-interface/Main.mpl @@ -0,0 +1,9 @@ +type $I1 +type $I2 +type $RR <$I2> {@e1 i32, &method1(agg)agg, &method2(void)void}> +javainterface $UU <$RR> public static +type $CC +type $TT {@f1 i32, @f2 i8, @f3 i8, $I1, $I2, $RR}> + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0048-mapleall-irbuild-edge-jarray/Main.mpl b/test/testsuite/irbuild_test/I0048-mapleall-irbuild-edge-jarray/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..02dfd61c5161647183736fddc408c1032e8cab79 --- /dev/null +++ b/test/testsuite/irbuild_test/I0048-mapleall-irbuild-edge-jarray/Main.mpl @@ -0,0 +1,13 @@ +srclang 3 +type $SS }> +func $foo ( var %x <*<$SS>>, var %y <*<$SS>>) void { + var %i i32 + var %j i32 + iassign <* u16> ( array 1 ptr <*[]u16> ( + iaddrof ptr <* <$SS>> 3 (dread ptr %x), dread i32 %i), + iread u16 <* u16> ( array 1 ptr <*[]u16> ( + iaddrof ptr <* <$SS>> 3 (dread ptr %y), dread i32 %j))) + return() } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0049-mapleall-irbuild-edge-just_ret/Main.mpl b/test/testsuite/irbuild_test/I0049-mapleall-irbuild-edge-just_ret/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..1a95394d113ffa191e4887dfe1fd0b536d2389c3 --- /dev/null +++ b/test/testsuite/irbuild_test/I0049-mapleall-irbuild-edge-just_ret/Main.mpl @@ -0,0 +1,10 @@ +type $atyp <[10] f32> +var $fff = 7789 +func $foo ( var %i i32 )i32 + +func $fact ( + var %n i32, var %m f32) void { + return () } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0050-mapleall-irbuild-edge-land/Main.mpl b/test/testsuite/irbuild_test/I0050-mapleall-irbuild-edge-land/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..a69899900b708d617827eb390e793be96bb06431 --- /dev/null +++ b/test/testsuite/irbuild_test/I0050-mapleall-irbuild-edge-land/Main.mpl @@ -0,0 +1,14 @@ + func $landi32 ( + var %i i32, var %j i32 + ) i32 { + return ( + land i32(dread i32 %i, dread i32 %j))} + + func $landi64 ( + var %i i64, var %j i64 + ) i32 { + return ( + land i64(dread i64 %i, dread i64 %j))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0051-mapleall-irbuild-edge-lior/Main.mpl b/test/testsuite/irbuild_test/I0051-mapleall-irbuild-edge-lior/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..900ffdf6706556ad56c9170525f2e0a7f332c8ea --- /dev/null +++ b/test/testsuite/irbuild_test/I0051-mapleall-irbuild-edge-lior/Main.mpl @@ -0,0 +1,14 @@ + func $liori32 ( + var %i i32, var %j i32 + ) i32 { + return ( + lior i32(dread i32 %i, dread i32 %j))} + + func $liori64 ( + var %i i64, var %j i64 + ) i32 { + return ( + lior i64(dread i64 %i, dread i64 %j))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0052-mapleall-irbuild-edge-lnot/Main.mpl b/test/testsuite/irbuild_test/I0052-mapleall-irbuild-edge-lnot/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..84b8db30091eeeb9ba22d273cdad94f6a7d5c0c6 --- /dev/null +++ b/test/testsuite/irbuild_test/I0052-mapleall-irbuild-edge-lnot/Main.mpl @@ -0,0 +1,37 @@ + func $foo ( + var %i i32 +#var %i1 i32, var %j1 i32, var %k1 i32 + ) i32 { + return ( + lnot i32(dread i32 %i))} + + func $foo1 ( + var %i i32, var %j i32, var %k i32, + var %i1 i32, var %j1 i32, var %k1 i32 + ) i32 { + return ( + lnot i32(dread i32 %i))} + + func $foo2 ( + var %i i32, var %j i32, var %k i32 + ) i32 { + return ( + lnot i32(constval i32 0x111111111))} + + func $foo3 ( + var %i i64, var %j i64, var %k i32 + ) i64 { + return ( + lnot i64(dread i64 %i))} + + + func $foo5 ( + var %i i64, var %j i64, var %k i32 + ) i64 { + return ( + lnot i64(constval i64 0x11111))} + +# todo float lnot + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0053-mapleall-irbuild-edge-loop/Main.mpl b/test/testsuite/irbuild_test/I0053-mapleall-irbuild-edge-loop/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..3b8711cb5f6b2307bf4a3e30da208114bc67be4a --- /dev/null +++ b/test/testsuite/irbuild_test/I0053-mapleall-irbuild-edge-loop/Main.mpl @@ -0,0 +1,22 @@ +# float a[10]; +# void init(void) { +# int i; +# for (i=0; i<10; i++) +# a[i] = i*3; +# } + +var $a <[10] f32> +var $f1 f32 +func $init () void { + var %i i32 + dassign %i ( constval i32 0 ) + while ( + lt i32 i32 ( dread i32 %i, constval i32 10) ) { + iassign <* [10] f32> ( + array 1 a32 <* [10] f32> (addrof a32 $a, dread i32 %i), + mul f32 (dread f32 $f1, constval f32 3.33f) ) + dassign %i ( + add i32 (dread i32 %i, constval i32 1) )} } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0054-mapleall-irbuild-edge-malloc/Main.mpl b/test/testsuite/irbuild_test/I0054-mapleall-irbuild-edge-malloc/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..9f93b5a3d9b94f69fb189e2aa8609e0e562f288e --- /dev/null +++ b/test/testsuite/irbuild_test/I0054-mapleall-irbuild-edge-malloc/Main.mpl @@ -0,0 +1,12 @@ +func &foo ( var %i i32 ) void { + var %p ptr + dassign %p ( malloc ptr ( constval i32 8 )) + dassign %p ( alloca ptr ( constval i32 16 )) + dassign %p ( gcmalloc ref i32 ) + dassign %p ( gcmallocjarray ref <[] i32> ( constval i32 5 )) + free ( dread ref %p) +} + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0055-mapleall-irbuild-edge-methods2/Main.mpl b/test/testsuite/irbuild_test/I0055-mapleall-irbuild-edge-methods2/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..96ff02f6b439a646334b5bff704ed4d7f77b361e --- /dev/null +++ b/test/testsuite/irbuild_test/I0055-mapleall-irbuild-edge-methods2/Main.mpl @@ -0,0 +1,15 @@ +type $RR +type $SS { @accessflag 1234, + &method1(agg)agg, + &method2(void)void}> +func $foo ( + var %x <$SS>) i32 { + dassign %x 2 ( constval i32 32 ) + return ( dread i32 %x 2 ) } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0056-mapleall-irbuild-edge-methods/Main.mpl b/test/testsuite/irbuild_test/I0056-mapleall-irbuild-edge-methods/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..178efb2aacea200a522e16652939f486bc6bf9d7 --- /dev/null +++ b/test/testsuite/irbuild_test/I0056-mapleall-irbuild-edge-methods/Main.mpl @@ -0,0 +1,21 @@ +func &meth1() void +func &meth3() i32 +var $sconst1 = [ 6=10.07f, 2=699, 3=-273, 4=75, 1=31425926, 5=6.02e+23f ] +func &printf (var %p1 <* i8>)void +func &main ( ) i32 { + call &printf (addrof a32 $sconst1) + return (constval i32 0) } + + + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0057-mapleall-irbuild-edge-multiway/Main.mpl b/test/testsuite/irbuild_test/I0057-mapleall-irbuild-edge-multiway/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..bf7891e3f110b036719a3e9487acf6baf492f50b --- /dev/null +++ b/test/testsuite/irbuild_test/I0057-mapleall-irbuild-edge-multiway/Main.mpl @@ -0,0 +1,20 @@ +var $g i32 +var $h i32 +func $multiwayfunc ( var %n i32) i32 { + multiway (dread i32 %n) @labdft { + (add i32 (dread i32 $g, dread i32 $h)): goto @lab0 + (dread i32 $h): goto @lab1 + (constval i32 888): goto @lab0 + (constval i32 'Y'): goto @lab0 + (neg i32 (dread i32 $h)) : goto @lab9 } +@lab0 + return (constval i32 -3) +@labdft + return (constval i32 100) +@lab9 + return (constval i32 9) +@lab1 + return (constval i32 1) } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0058-mapleall-irbuild-edge-multiwaystr/Main.mpl b/test/testsuite/irbuild_test/I0058-mapleall-irbuild-edge-multiwaystr/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..de974cbccd567b7c4d3b64835b2104cf7a1d1da1 --- /dev/null +++ b/test/testsuite/irbuild_test/I0058-mapleall-irbuild-edge-multiwaystr/Main.mpl @@ -0,0 +1,18 @@ +var $g ptr +var $h i32 +func $multiwayfunc ( var %p ptr) ptr { + multiway (dread ptr %p) @labdft { + (dread ptr $g): goto @lab1 + (add ptr (dread i32 $g, dread i32 $h)): goto @lab0 + (conststr ptr "world"): goto @lab9 } +@lab0 + return (dread ptr $g) +@labdft + return (conststr ptr "hello") +@lab9 + return (add ptr (conststr ptr "foo", dread i32 $h)) +@lab1 + return (addrof ptr $h) } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0059-mapleall-irbuild-edge-neg/Main.mpl b/test/testsuite/irbuild_test/I0059-mapleall-irbuild-edge-neg/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..c06bc9c2dc1ae05dea9f5f4fe868265d9c01833e --- /dev/null +++ b/test/testsuite/irbuild_test/I0059-mapleall-irbuild-edge-neg/Main.mpl @@ -0,0 +1,60 @@ + func $foo ( + var %i i32 +#var %i1 i32, var %j1 i32, var %k1 i32 + ) i32 { + return ( + neg i32(dread i32 %i))} + + func $foo1 ( + var %i i32, var %j i32, var %k i32, + var %i1 i32, var %j1 i32, var %k1 i32 + ) i32 { + return ( + neg i32(dread i32 %i))} + + func $foo2 ( + var %i i32, var %j i32, var %k i32 + ) i32 { + return ( + neg i32(constval i32 0x111111111))} + + func $foo3 ( + var %i i64, var %j i64, var %k i32 + ) i64 { + return ( + neg i64(dread i64 %i))} + + + func $foo5 ( + var %i i64, var %j i64, var %k i32 + ) i64 { + return ( + neg i64(constval i64 0x11111))} + + func $foo6 ( + var %i f64 + ) f64 { + return ( + neg f64(dread f64 %i))} + + func $foo7 ( + var %i f32 + ) f32 { + return ( + neg f32(dread f32 %i))} + + func $foo8 ( + var %i f64 + ) f64 { + return ( + neg f64(constval f64 -1.24))} + + func $foo9 ( + var %i f32 + ) f32 { + return ( + neg f32(constval f32 -1.24f))} +# todo float neg + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0060-mapleall-irbuild-edge-parentfields/Main.mpl b/test/testsuite/irbuild_test/I0060-mapleall-irbuild-edge-parentfields/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..d10a0c552fb09ee5e75b886b371159aa59d9d2a9 --- /dev/null +++ b/test/testsuite/irbuild_test/I0060-mapleall-irbuild-edge-parentfields/Main.mpl @@ -0,0 +1,10 @@ +type $RR +type $SS {^f1 i32, @f2 i8, ^f3 i8}> +javaclass $TT <$SS> public static +func &foo ( + var %x <$SS>) i32 { + dassign %x -1 ( constval i32 32 ) + return ( dread i32 %x -2 ) } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0061-mapleall-irbuild-edge-polymorphiccallassigned/Main.mpl b/test/testsuite/irbuild_test/I0061-mapleall-irbuild-edge-polymorphiccallassigned/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..693163aa4e9b8647df64e52ee812ac1e311a4351 --- /dev/null +++ b/test/testsuite/irbuild_test/I0061-mapleall-irbuild-edge-polymorphiccallassigned/Main.mpl @@ -0,0 +1,15 @@ +type $SS +javaclass $TT <$SS> public static + +func &bar (var %y i32) i32 { + return (dread i32 %y) +} + +func &foo (var %x <$SS>) i32 { + var %ret i32 + polymorphiccallassigned &bar (dread i32 %x 1) {dassign %ret 0} + return (dread i32 %ret) +} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0062-mapleall-irbuild-edge-pregs/Main.mpl b/test/testsuite/irbuild_test/I0062-mapleall-irbuild-edge-pregs/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..cb0fed58de37945afa50bf4e958e411d7e8d77cd --- /dev/null +++ b/test/testsuite/irbuild_test/I0062-mapleall-irbuild-edge-pregs/Main.mpl @@ -0,0 +1,20 @@ +type $atyp <[10] f32> +type $aaaa +var $fff <$atyp> +func $foo ( var %i i32 )i32 + +func $fact ( + var %n i32, var %m f32) i32 { + regassign i32 %987 (constval i32 '0') + if (ne i32 i32 (regread i32 %987, constval i32 10)) { + eval (regread i32 %987) + call &foo( + sub i32 (regread i32 %1, constval i32 1)) + return (regread i32 %%retval)} + else { + regassign i32 %987 (constval i32 111) + return (constval i32 '1') } + } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0063-mapleall-irbuild-edge-PrimTypes/Main.mpl b/test/testsuite/irbuild_test/I0063-mapleall-irbuild-edge-PrimTypes/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..8222d5e88729be1684f178d5341f398d7ff92176 --- /dev/null +++ b/test/testsuite/irbuild_test/I0063-mapleall-irbuild-edge-PrimTypes/Main.mpl @@ -0,0 +1,46 @@ +var $myStruct < struct{ + @number i32, + @p <* i8> }> +func $main ()i32{ + #Character + var %sChar i8 + var %usChar i8 + #signed and unsigned short integer + var %shortInt i16 + var %shortInt2 i16 + var %sShortInt i16 + var %sShortInt2 i16 + var %usShortInt i16 + var %usShortInt2 i16 + #signed and unsigned integer + var %int1 i32 + var %sInt i32 + var %usInt i32 + var %usInt2 i32 + #signed and unsigned long integer + var %long1 i64 + var %long2 i64 + var %sLong1 i64 + var %sLong2 i64 + var %usLong i64 + var %usLong2 i64 + var %lLong1 i64 + var %iLong2 i64 + var %sLlong1 i64 + var %sLlonog2 i64 + var %usLlong i64 + var %usLlong2 i64 + #float + var %Float f32 + #double + var %Double f64 + #long double + var %lDouble f64 + #Address + var %array <[10] i8> + iassign<* i8>( + array 1 a64<*[10] i8>(addrof a64 %array, constval i64 1), + constval i32 120)} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0064-mapleall-irbuild-edge-recip/Main.mpl b/test/testsuite/irbuild_test/I0064-mapleall-irbuild-edge-recip/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..e1f91e8403cba11e0be313b1778910f20a6976ae --- /dev/null +++ b/test/testsuite/irbuild_test/I0064-mapleall-irbuild-edge-recip/Main.mpl @@ -0,0 +1,27 @@ + func $foo6 ( + var %i f64 + ) f64 { + return ( + recip f64(dread f64 %i))} + + func $foo7 ( + var %i f32 + ) f32 { + return ( + recip f32(dread f32 %i))} + + func $foo8 ( + var %i f64 + ) f64 { + return ( + recip f64(constval f64 -1.24))} + + func $foo9 ( + var %i f32 + ) f32 { + return ( + recip f32(constval f32 -1.24f))} +# todo float recip + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0065-mapleall-irbuild-edge-retype/Main.mpl b/test/testsuite/irbuild_test/I0065-mapleall-irbuild-edge-retype/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..7ac65fa78234fc15668f4661677acc4ff28ee764 --- /dev/null +++ b/test/testsuite/irbuild_test/I0065-mapleall-irbuild-edge-retype/Main.mpl @@ -0,0 +1,26 @@ + func $retypef64toi64 ( + var %i f64 + ) i64 { + return ( + retype i64 (dread f64 %i))} + + func $retypei64tof64 ( + var %i i64 + ) f64 { + return ( + retype f64 (dread i64 %i))} + + func $retypef32toi32 ( + var %i f32 + ) i32 { + return ( + retype i32 (dread f32 %i))} + + func $retypei32tof32 ( + var %i i32 + ) f32 { + return ( + retype f32 (dread i32 %i))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0066-mapleall-irbuild-edge-select/Main.mpl b/test/testsuite/irbuild_test/I0066-mapleall-irbuild-edge-select/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..6a5e4beebaa091088129cf5c4f9b621a9cbfe697 --- /dev/null +++ b/test/testsuite/irbuild_test/I0066-mapleall-irbuild-edge-select/Main.mpl @@ -0,0 +1,42 @@ + func $selecti32 ( + var %i i32, + var %j i32, + var %k i32) i32 { + return ( + select i32 ( + dread i32 %i, + dread i32 %j, + dread i32 %k))} + + func $selecti64 ( + var %i i32, + var %j i64, + var %k i64) i64 { + return ( + select i64 ( + dread i32 %i, + dread i64 %j, + dread i64 %k))} + + func $selectf32 ( + var %i i32, + var %j f32, + var %k f32) f32 { + return ( + select f32 ( + dread i32 %i, + dread f32 %j, + dread f32 %k))} + + func $selectf64 ( + var %i i32, + var %j f64, + var %k f64) f64 { + return ( + select f64 ( + dread i32 %i, + dread f64 %j, + dread f64 %k))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0067-mapleall-irbuild-edge-specialchar/Main.mpl b/test/testsuite/irbuild_test/I0067-mapleall-irbuild-edge-specialchar/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..741f792157a2a19c6c36b013260e4b746d45a159 --- /dev/null +++ b/test/testsuite/irbuild_test/I0067-mapleall-irbuild-edge-specialchar/Main.mpl @@ -0,0 +1,10 @@ +# ;, / and | are allowed name characters, but they cannot be the starting char + func $foo ( + var %i; i32, + var %j|/ i32 + ) i32 { + return ( + add i32(dread i32 %i;, dread i32 %j|/))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0068-mapleall-irbuild-edge-sqrt/Main.mpl b/test/testsuite/irbuild_test/I0068-mapleall-irbuild-edge-sqrt/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..5ce01267dbaf3f0ef76a58313b389d49e89b76c9 --- /dev/null +++ b/test/testsuite/irbuild_test/I0068-mapleall-irbuild-edge-sqrt/Main.mpl @@ -0,0 +1,27 @@ + func $foo6 ( + var %i f64 + ) f64 { + return ( + sqrt f64(dread f64 %i))} + + func $foo7 ( + var %i f32 + ) f32 { + return ( + sqrt f32(dread f32 %i))} + + func $foo8 ( + var %i f64 + ) f64 { + return ( + sqrt f64(constval f64 4.0))} + + func $foo9 ( + var %i f32 + ) f32 { + return ( + sqrt f32(constval f32 4.0f))} +# todo float sqrt + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0069-mapleall-irbuild-edge-struct2/Main.mpl b/test/testsuite/irbuild_test/I0069-mapleall-irbuild-edge-struct2/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..6996dfacb541147bc0e40680b8d1ac0f26384817 --- /dev/null +++ b/test/testsuite/irbuild_test/I0069-mapleall-irbuild-edge-struct2/Main.mpl @@ -0,0 +1,16 @@ +type $SS +var $sconst1 , + @f33 i32, + @f44 i32, + @f55 f32, + @f66 f32}> = [ 1=1007, 2= [1=11.11f, 2=22.22f], 5=-273, 6=75, 4=6023.1f ] +func $fact () i32 { + return (dread i32 $sconst1 1) +} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0070-mapleall-irbuild-edge-structarrayinit/Main.mpl b/test/testsuite/irbuild_test/I0070-mapleall-irbuild-edge-structarrayinit/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..41ff062188c1aedd365c357399d0f84399d9d0de --- /dev/null +++ b/test/testsuite/irbuild_test/I0070-mapleall-irbuild-edge-structarrayinit/Main.mpl @@ -0,0 +1,13 @@ +type $__field_meta__ , + @type <* void>}> +var $v1 <* void> public +var $v2 <* void> public +var $vs <[1] <$__field_meta__>> public = [[1= 0x35ad1b, 2= 0xabcd, 3= addrof ptr $v2, 4= addrof ptr $v1]] +var $vvs <[2][1] <$__field_meta__>> public = [[[1= 11, 2= 22, 3= addrof ptr $v1, 4= addrof ptr $v1]], + [[1= 33, 2= 44, 3= addrof ptr $v2, 4= addrof ptr $v2]]] + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0071-mapleall-irbuild-edge-structinit/Main.mpl b/test/testsuite/irbuild_test/I0071-mapleall-irbuild-edge-structinit/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..84c7a1cebd7852237570d41822cce2f7c25c634f --- /dev/null +++ b/test/testsuite/irbuild_test/I0071-mapleall-irbuild-edge-structinit/Main.mpl @@ -0,0 +1,17 @@ +var $sconst1 = [ 6=10.07f, 2=699, 3=-273, 4=75, 1=31425926, 5=6.02e+23f ] +func &printf (var %p1 <* i8>)void +func &main ( ) i32 { + call &printf (addrof a32 $sconst1) + return (constval i32 0) } + + + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0072-mapleall-irbuild-edge-struct/Main.mpl b/test/testsuite/irbuild_test/I0072-mapleall-irbuild-edge-struct/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..972dfaabacc967135306ac668068391c9d282ad7 --- /dev/null +++ b/test/testsuite/irbuild_test/I0072-mapleall-irbuild-edge-struct/Main.mpl @@ -0,0 +1,17 @@ +# typedef struct ss { +# int f1; +# char f2:3; +# char f3:5; +# } SS; +# SS foo(SS x) { +# x.f2 = 32; +# return x; +# } +type $SS +func $foo ( + var %x <$SS>) i32 { + dassign %x 2 ( constval i32 32 ) + return ( dread i32 %x 2 ) } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0073-mapleall-irbuild-edge-struct_type/Main.mpl b/test/testsuite/irbuild_test/I0073-mapleall-irbuild-edge-struct_type/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..8ec155e6f829f1a086a61fa49f3f0df909bddc44 --- /dev/null +++ b/test/testsuite/irbuild_test/I0073-mapleall-irbuild-edge-struct_type/Main.mpl @@ -0,0 +1,54 @@ +#struct aa{ +# double b; +# float *x; +#}; + +#struct bb { +# struct aa b1; +# struct aa *pa; +# double x1[10]; +# double dx; +#}; + +#typedef struct ss { +# int f1; +# char f2:3; +# struct aa a3; +# struct aa *pa1; +# char f3:5; +# struct bb *b3; +# struct bb *b2; +# struct aa xt[23]; +# struct aa(* funcc)(int, int, double); +#}SS; + +type $unname1 }> +type $unname2 }>, + @pa <* }>>, + @x1 <[10] f64>, + @dx f64}> +type $SS }>, + @pa1 <* } >>, + @f3:5 i32, + @b3 <* }>, + @pa <* }>>, + @x1 <[10] f64>, + @dx f64}>>, + @b2 <* $unname2>, + @xt <[23] }>>, + @funcc }>>}> + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0074-mapleall-irbuild-edge-sub/Main.mpl b/test/testsuite/irbuild_test/I0074-mapleall-irbuild-edge-sub/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..3d75348527b70cb616949e1d317070b8870a1152 --- /dev/null +++ b/test/testsuite/irbuild_test/I0074-mapleall-irbuild-edge-sub/Main.mpl @@ -0,0 +1,64 @@ + func $foo ( + var %i i32 +#var %i1 i32, var %j1 i32, var %k1 i32 + ) i32 { + return ( + sub i32(dread i32 %i, + constval i32 -998))} + + func $foo1 ( + var %i i32, var %j i32, var %k i32, + var %i1 i32, var %j1 i32, var %k1 i32 + ) i32 { + return ( + sub i32(dread i32 %i, dread i32 %j))} + + func $foo2 ( + var %i i32, var %j i32, var %k i32 + ) i32 { + return ( + sub i32(dread i32 %i, constval i32 0x111111111))} + + func $foo3 ( + var %i i64, var %j i64, var %k i32 + ) i64 { + return ( + sub i64(dread i64 %i, constval i64 0x111111111))} + + func $foo4 ( + var %i i64, var %j i64, var %k i32 + )i64 { + return ( + sub i64(dread i64 %i, dread i64 %j))} + + func $foo5 ( + var %i i64, var %j i64, var %k i32 + ) i64 { + return ( + sub i64(dread i64 %i, constval i64 0x11111))} + + func $foo6 ( + var %i f64, var %j f64, var %k i32 + ) f64 { + return ( + sub f64(dread f64 %i, constval f64 2.237))} + + func $foo66 ( + var %i f64, var %j f64, var %k i32 + ) f64 { + return ( + sub f64(dread f64 %i, constval f64 2.237))} + func $foo7 ( + var %i f32, var %j f32, var %k i32 + ) f32 { + return ( + sub f32(dread f32 %i, dread f32 %j))} + + func $foo8 ( + var %i f32, var %j f64, var %k i32 + ) f32 { + return ( + sub f32(dread f32 %i, constval f32 2.237f))} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0075-mapleall-irbuild-edge-substructinit/Main.mpl b/test/testsuite/irbuild_test/I0075-mapleall-irbuild-edge-substructinit/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..710e9b1d5713fa553519a09d822e5d319392e5e2 --- /dev/null +++ b/test/testsuite/irbuild_test/I0075-mapleall-irbuild-edge-substructinit/Main.mpl @@ -0,0 +1,20 @@ +type $SS +var $sconst1 , + @f33 i32, + @f44 i32, + @f55 f32, + @f66 f32}> = [ 6=1007, 2= [1=11.11f, 2=22.22f], 3=-273.2f, 4=75.3f, 1=1425926, 5=6023 ] +func $printf (var %p1 <* i8>)void +func $main ( ) i32 { + call &printf (addrof a32 $sconst1) + return (constval i32 0) } + + + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0076-mapleall-irbuild-edge-switch/Main.mpl b/test/testsuite/irbuild_test/I0076-mapleall-irbuild-edge-switch/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..8750d119201ac691f3c2c067808eb86ec0f2c23b --- /dev/null +++ b/test/testsuite/irbuild_test/I0076-mapleall-irbuild-edge-switch/Main.mpl @@ -0,0 +1,17 @@ +func $switchfunc ( var %n i32) i32 { + var %alocal i32 + switch (dread i32 %n) @labdft { + -3: goto @lab0 + 1: goto @lab1 + 9: goto @lab9 } +@lab0 + return (constval i32 -3) +@labdft + return (constval i32 100) +@lab9 + return (constval i32 9) +@lab1 + return (constval i32 1) } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0077-mapleall-irbuild-edge-sync/Main.mpl b/test/testsuite/irbuild_test/I0077-mapleall-irbuild-edge-sync/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..bac9bc95caf5a9ae4a8d54c0fd0735f5c063ada5 --- /dev/null +++ b/test/testsuite/irbuild_test/I0077-mapleall-irbuild-edge-sync/Main.mpl @@ -0,0 +1,42 @@ +# 1 public class sync { +# 2 private Object go = new Object(); +# 3 private int waiters = 0; +# 4 +# 5 public void foo() { +# 6 synchronized (go) { +# 7 waiters++; +# 8 } +# 9 } +# 10 } + +# some unrelated functions are removed +type $Ljava/lang/Object; +type $Lsync; { + @go <* <$Ljava/lang/Object;>> private, + @waiters i32 private, + &Lsync;|foo|__V|(<* <$Lsync;>>) void}> +func &Lsync;|foo|__V| (var %_this <* <$Lsync;>>) void { + var %Reg1_R33 <* <$Ljava/lang/Object;>> + var %Reg0_I i32 + var %Reg0_R38 <* void> + #LINE sync.java:6 + dassign %Reg1_R33 0 (iread ptr <* <$Lsync;>> 1 (dread ptr %_this 0)) + syncenter (dread ptr %Reg1_R33 0) + #LINE sync.java:7 + dassign %Reg0_I 0 (iread i32 <* <$Lsync;>> 2 (dread ptr %_this 0)) + dassign %Reg0_I 0 (add i32 ( + dread i32 %Reg0_I 0, + cvt i32 i8 (constval i8 1))) + iassign <* <$Lsync;>> 2 (dread ptr %_this 0, dread i32 %Reg0_I 0) + #LINE sync.java:8 + syncexit (dread ptr %Reg1_R33 0) + #LINE sync.java:9 + return () + #LINE sync.java:8 + dassign %Reg0_R38 0 (regread ptr %%thrownval) + syncexit (dread ptr %Reg1_R33 0) + throw (dread ptr %Reg0_R38 0) +} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0078-mapleall-irbuild-edge-ternary/Main.mpl b/test/testsuite/irbuild_test/I0078-mapleall-irbuild-edge-ternary/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..12acd02e4a9d9cc1617d25cfab42c5ff660b8eb0 --- /dev/null +++ b/test/testsuite/irbuild_test/I0078-mapleall-irbuild-edge-ternary/Main.mpl @@ -0,0 +1,15 @@ + # a function returning (i + j) * -998 + func $foo ( +# var %i xxx, + var %i i32, + var %j i32, + var %k i32) i32 { + return ( + select i32 ( + dread i32 %i, + dread i32 %j, + dread i32 %k))} + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0079-mapleall-irbuild-edge-testconst/Main.mpl b/test/testsuite/irbuild_test/I0079-mapleall-irbuild-edge-testconst/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..e88694db1e68f23b1867e83018b1fe3fd68b2783 --- /dev/null +++ b/test/testsuite/irbuild_test/I0079-mapleall-irbuild-edge-testconst/Main.mpl @@ -0,0 +1,15 @@ +#var $const1 <[13] i8> [ 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 10, 0 ] +var $fconst1 <[18] f64> = [ 1007, 707, -273, 75, 0113, 0x4b, 75u, 75l, 75ul, 75lu, 3.1425926, 6.02e23, 6.02e+23, 1.6e-19, 3.0, 3.14159, 6.02e23, .233 ] +func $printf (var %p1 <* i8>)void +func $main ( ) i32 { + call &printf (addrof a32 $fconst1) + call &printf (conststr ptr "\"hello maple\"", conststr a32 "\nworld\n") + # 你好: E4 BD A0 E5 A5 BD 中国: E4 B8 AD E5 9B BD + call &printf (conststr16 ptr "\xE4\xBD\xA0\xE5\xA5\xBD", conststr16 a32 "\xE4\xB8\xAD\xE5\x9B\xBD") + return (constval i32 0) } + + + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0081-mapleall-irbuild-edge-test_type/Main.mpl b/test/testsuite/irbuild_test/I0081-mapleall-irbuild-edge-test_type/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..9f79476c5eae1a8a1a207845375cb1bbae5a9114 --- /dev/null +++ b/test/testsuite/irbuild_test/I0081-mapleall-irbuild-edge-test_type/Main.mpl @@ -0,0 +1,50 @@ +func $foo1 (var %p1 i8, var %p2 i16, var %p3 i32, var %p4 i64, ...)i32 { + return ( + constval i32 33)} +func $foo2 (var %p1 u8, var %p2 u16, var %p3 u32, var %p4 u64,...) i32 { + return ( + constval i32 33)} +func $foo4 (var %p1 f32, var %p2 f64, ... ) i32 { + return ( + constval i32 33)} + +func $foo5 (var %p1 a32, var %p2 a64,...) i32 +func $foo6 (var %p1 c64, var %p2 c128, ...) i32 + +func $foo7 (var %p1 <* i8>, var %p2 <* i16>, var %p3 <* i32>, var %p4 <* i64>) i32 { + return ( + constval i32 33)} +func $foo8 (var %p1 <* u8>, var %p2 <* u16>, var %p3 <* u32>, var %p4 <* u64>) i32 { + return ( + constval i32 33)} +func $foo9 (var %p1 <* u1>) i32 { + return ( + constval i32 33)} +func $foo10 (var %p1 <* f32>, var %p2 <* f64>) i32 { + return ( + constval i32 33)} +func $foo11 (var %p1 <* void>)void + +func $foo12 (var %p1 <[10] i8>) i32 { + return ( + constval i32 33)} +func $foo13 (var %p1 <[10][32] i32>) i32 { + return ( + constval i32 33)} +func $foo14 (var %p1 <[10][32][43] i32>) i32 { + return ( + constval i32 33)} +func $foo15 (var %p1 <[10][32][43][54][56][78][90][122][223][334] i32>) i32 { + return ( + constval i32 33)} + +type $SS +func $foo16 (var %x <$SS>) i32 { + return ( + constval i32 33)} + + + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0082-mapleall-irbuild-edge-twofunc/Main.mpl b/test/testsuite/irbuild_test/I0082-mapleall-irbuild-edge-twofunc/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..3aa3c48c666596cdfeb9f0a77fe301eadaeebc5b --- /dev/null +++ b/test/testsuite/irbuild_test/I0082-mapleall-irbuild-edge-twofunc/Main.mpl @@ -0,0 +1,21 @@ +#int fact (int n) { +# if(n != 1) +# return foo(n - 1); +# else return 1; +#} +func $foo varargs ( var %i i32, ... ) i32 { + return (dread i32 %i) } +func $foo1 varargs ( ... ) i32 { + return (constval i32 99) } + +func $fact ( + var %n i32) i32 { + if (ne i32 i32 (dread i32 %n, constval i32 1)) { + call &foo( + sub i32 (dread i32 %n, constval i32 1)) + return (regread i32 %%retval)} + else { + return (constval i32 1) } } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0083-mapleall-irbuild-edge-tyconvertion/Main.mpl b/test/testsuite/irbuild_test/I0083-mapleall-irbuild-edge-tyconvertion/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..1ee6f5f094c9ebf9bc4d9b8c82986505690ee583 --- /dev/null +++ b/test/testsuite/irbuild_test/I0083-mapleall-irbuild-edge-tyconvertion/Main.mpl @@ -0,0 +1,13 @@ + # a function returning unary(i + j) * -998 +#type $SS + func $foo ( + var %k , + var %f f32, + var %i i32, + var %j i32)i64 { + return ( + cvt i64 i32 (constval i32 12345))} + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0084-mapleall-irbuild-edge-unary/Main.mpl b/test/testsuite/irbuild_test/I0084-mapleall-irbuild-edge-unary/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..a6e95d9cb500cfd1abc4b544e778c26dc97f53ea --- /dev/null +++ b/test/testsuite/irbuild_test/I0084-mapleall-irbuild-edge-unary/Main.mpl @@ -0,0 +1,15 @@ + # a function returning unary(i + j) * -998 + func $foo ( + var %i i32, + var %j i32) f32 { + return ( + recip f32( + sqrt f32( + cvt f32 i32( + mul i32 ( + extractbits i32 1 23 ( add i32 ( bnot i32 (dread i32 %i), lnot i32 (dread i32 %j))), + neg i32 ( constval i32 -998))))))} + + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0085-mapleall-irbuild-edge-virtualcallassigned/Main.mpl b/test/testsuite/irbuild_test/I0085-mapleall-irbuild-edge-virtualcallassigned/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..3529c000291396e1a9125c91d7d3294bff33d3da --- /dev/null +++ b/test/testsuite/irbuild_test/I0085-mapleall-irbuild-edge-virtualcallassigned/Main.mpl @@ -0,0 +1,29 @@ +type $RR +type $SS { &method1(agg)agg, + &method2(void)void}> +func $foo ( + var %x <$SS>) i32 { + var %r1 i32 + var %r2 i32 + var %r3 i32 + dassign %x 2 ( constval i32 32 ) + # Not correct, but for parse and dump test. + virtualcallassigned &method2(addrof ptr %x) { + dassign %r1 1 + dassign %r2 2 + dassign %r3 3 + } + superclasscallassigned &method2(addrof ptr %x) { + dassign %r1 1 + dassign %r2 2 + dassign %r3 3 + } + interfacecallassigned &method2(addrof ptr %x) { + dassign %r1 1 + dassign %r2 2 + dassign %r3 3 + } + return ( dread i32 %x 2 ) } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0086-mapleall-irbuild-edge-virtualcall/Main.mpl b/test/testsuite/irbuild_test/I0086-mapleall-irbuild-edge-virtualcall/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..02a30ee4d9a7178e22106ac402dbbe802fda2db8 --- /dev/null +++ b/test/testsuite/irbuild_test/I0086-mapleall-irbuild-edge-virtualcall/Main.mpl @@ -0,0 +1,13 @@ +type $RR +type $SS { &method1(agg)agg, + &method2(void)void}> +func $foo ( + var %x <$SS>) i32 { + dassign %x 2 ( constval i32 32 ) + virtualcall &method2(addrof ptr %x) + superclasscall &method2(addrof ptr %x) + interfacecall &method2(addrof ptr %x) + return ( dread i32 %x 2 ) } + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/I0087-mapleall-irbuild-edge-while/Main.mpl b/test/testsuite/irbuild_test/I0087-mapleall-irbuild-edge-while/Main.mpl new file mode 100644 index 0000000000000000000000000000000000000000..b00128d06ff9aa81b73e85db6abae1a9bf934348 --- /dev/null +++ b/test/testsuite/irbuild_test/I0087-mapleall-irbuild-edge-while/Main.mpl @@ -0,0 +1,19 @@ +# int foo(void) { +# int n = 1; +# int i; +# for (i=1; i<10; i++) +# n = n * i; +# } + +func $foo (var %i i32) i32 { + while ( + lt i32 i32 ( dread i32 %i, constval i32 10) ) { + dassign %i ( + mul i32 (dread i32 %i, dread i32 %i)) + dassign %i ( + add i32 (dread i32 %i, constval i32 1) )} + return ( constval i32 1 ) +} + # EXEC: %irbuild Main.mpl + # EXEC: %irbuild Main.irb.mpl + # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl diff --git a/test/testsuite/irbuild_test/test.cfg b/test/testsuite/irbuild_test/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..50b7c368c1f1e4909c9ae0de8311704f3b70973c --- /dev/null +++ b/test/testsuite/irbuild_test/test.cfg @@ -0,0 +1,10 @@ +[suffix] +mpl = # + +[internal-var] +irbuild = ${MAPLE_ROOT}/output/bin/irbuild +cmp = /usr/bin/cmp -s + +[description] +title = Maple Irbuild Test +