1*0fca6ea1SDimitry Andric //===-- NumberedValues.h - --------------------------------------*- C++ -*-===// 2*0fca6ea1SDimitry Andric // 3*0fca6ea1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0fca6ea1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0fca6ea1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0fca6ea1SDimitry Andric // 7*0fca6ea1SDimitry Andric //===----------------------------------------------------------------------===// 8*0fca6ea1SDimitry Andric 9*0fca6ea1SDimitry Andric #ifndef LLVM_ASMPARSER_NUMBEREDVALUES_H 10*0fca6ea1SDimitry Andric #define LLVM_ASMPARSER_NUMBEREDVALUES_H 11*0fca6ea1SDimitry Andric 12*0fca6ea1SDimitry Andric #include "llvm/ADT/DenseMap.h" 13*0fca6ea1SDimitry Andric 14*0fca6ea1SDimitry Andric namespace llvm { 15*0fca6ea1SDimitry Andric 16*0fca6ea1SDimitry Andric /// Mapping from value ID to value, which also remembers what the next unused 17*0fca6ea1SDimitry Andric /// ID is. 18*0fca6ea1SDimitry Andric template <class T> class NumberedValues { 19*0fca6ea1SDimitry Andric DenseMap<unsigned, T> Vals; 20*0fca6ea1SDimitry Andric unsigned NextUnusedID = 0; 21*0fca6ea1SDimitry Andric 22*0fca6ea1SDimitry Andric public: getNext()23*0fca6ea1SDimitry Andric unsigned getNext() const { return NextUnusedID; } get(unsigned ID)24*0fca6ea1SDimitry Andric T get(unsigned ID) const { return Vals.lookup(ID); } add(unsigned ID,T V)25*0fca6ea1SDimitry Andric void add(unsigned ID, T V) { 26*0fca6ea1SDimitry Andric assert(ID >= NextUnusedID && "Invalid value ID"); 27*0fca6ea1SDimitry Andric Vals.insert({ID, V}); 28*0fca6ea1SDimitry Andric NextUnusedID = ID + 1; 29*0fca6ea1SDimitry Andric } 30*0fca6ea1SDimitry Andric }; 31*0fca6ea1SDimitry Andric 32*0fca6ea1SDimitry Andric } // end namespace llvm 33*0fca6ea1SDimitry Andric 34*0fca6ea1SDimitry Andric #endif 35