1 //===-- include/flang/Evaluate/static-data.h --------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef FORTRAN_EVALUATE_STATIC_DATA_H_ 10 #define FORTRAN_EVALUATE_STATIC_DATA_H_ 11 12 // Represents constant static data objects 13 14 #include "formatting.h" 15 #include "type.h" 16 #include "flang/Common/idioms.h" 17 #include <cinttypes> 18 #include <memory> 19 #include <optional> 20 #include <string> 21 #include <vector> 22 23 namespace llvm { 24 class raw_ostream; 25 } 26 27 namespace Fortran::evaluate { 28 29 class StaticDataObject { 30 public: 31 using Pointer = std::shared_ptr<StaticDataObject>; 32 33 StaticDataObject(const StaticDataObject &) = delete; 34 StaticDataObject(StaticDataObject &&) = delete; 35 StaticDataObject &operator=(const StaticDataObject &) = delete; 36 StaticDataObject &operator=(StaticDataObject &&) = delete; 37 Create()38 static Pointer Create() { return Pointer{new StaticDataObject}; } 39 name()40 const std::string &name() const { return name_; } set_name(std::string n)41 StaticDataObject &set_name(std::string n) { 42 name_ = n; 43 return *this; 44 } 45 alignment()46 int alignment() const { return alignment_; } set_alignment(int a)47 StaticDataObject &set_alignment(int a) { 48 CHECK(a >= 0); 49 alignment_ = a; 50 return *this; 51 } 52 itemBytes()53 int itemBytes() const { return itemBytes_; } set_itemBytes(int b)54 StaticDataObject &set_itemBytes(int b) { 55 CHECK(b >= 1); 56 itemBytes_ = b; 57 return *this; 58 } 59 data()60 const std::vector<std::uint8_t> &data() const { return data_; } data()61 std::vector<std::uint8_t> &data() { return data_; } 62 63 StaticDataObject &Push(const std::string &); 64 StaticDataObject &Push(const std::u16string &); 65 StaticDataObject &Push(const std::u32string &); 66 std::optional<std::string> AsString() const; 67 std::optional<std::u16string> AsU16String() const; 68 std::optional<std::u32string> AsU32String() const; 69 llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const; 70 71 static bool bigEndian; 72 73 private: StaticDataObject()74 StaticDataObject() {} 75 76 std::string name_; 77 int alignment_{1}; 78 int itemBytes_{1}; 79 std::vector<std::uint8_t> data_; 80 }; 81 } // namespace Fortran::evaluate 82 #endif // FORTRAN_EVALUATE_STATIC_DATA_H_ 83