[llvm] [llvm-objcopy] Support SREC output format (PR #75874)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 19 01:06:01 PST 2024


================
@@ -399,95 +423,81 @@ struct SRecord {
   ArrayRef<uint8_t> Data;
   SRecLineData toString() const;
   uint8_t getCount() const;
-  // get address size in characters
+  // Get address size in characters.
   uint8_t getAddressSize() const;
   uint8_t getChecksum() const;
   size_t getSize() const;
   static SRecord getHeader(StringRef FileName);
   static uint8_t getType(uint32_t Address);
+
   enum Type : uint8_t {
-    // Vendor specific text comment
+    // Vendor specific text comment.
     S0 = 0,
-    // Data that starts at a 16 bit address
+    // Data that starts at a 16 bit address.
     S1 = 1,
-    // Data that starts at a 24 bit address
+    // Data that starts at a 24 bit address.
     S2 = 2,
-    // Data that starts at a 32 bit address
+    // Data that starts at a 32 bit address.
     S3 = 3,
-    // Reserved
+    // Reserved.
     S4 = 4,
-    // 16 bit count of S1/S2/S3 records (optional)
+    // 16 bit count of S1/S2/S3 records (optional).
     S5 = 5,
-    // 32 bit count of S1/S2/S3 records (optional)
+    // 32 bit count of S1/S2/S3 records (optional).
     S6 = 6,
-    // Terminates a series of S3 records
+    // Terminates a series of S3 records.
     S7 = 7,
-    // Terminates a series of S2 records
+    // Terminates a series of S2 records.
     S8 = 8,
-    // Terminates a series of S1 records
+    // Terminates a series of S1 records.
     S9 = 9
   };
 };
 
-/// The real writer
-class SRECWriter : public Writer {
-  StringRef OutputFileName;
-  size_t TotalSize = 0;
-  std::vector<const SectionBase *> Sections;
-
-  size_t writeHeader(uint8_t *Buf);
-  size_t writeTerminator(uint8_t *Buf, uint8_t Type);
-  Error checkSection(const SectionBase &S) const;
-
-public:
-  ~SRECWriter() = default;
-  Error finalize() override;
-  Error write() override;
-  SRECWriter(Object &Obj, raw_ostream &OS, StringRef OutputFile)
-      : Writer(Obj, OS), OutputFileName(OutputFile) {}
-};
-
 /// Base class for SRecSectionWriter
 /// This class does not actually write anything. It is only used for size
 /// calculation.
 class SRECSectionWriterBase : public BinarySectionWriter {
-protected:
-  // Offset in the output buffer
-  uint64_t Offset;
-  // Sections start after the header
-  uint64_t HeaderSize;
-  // Type of records to write
-  uint8_t Type = SRecord::S1;
-  std::vector<SRecord> Records;
-  void writeSection(const SectionBase &S, ArrayRef<uint8_t> Data);
-
 public:
   explicit SRECSectionWriterBase(WritableMemoryBuffer &Buf,
                                  uint64_t StartOffset)
       : BinarySectionWriter(Buf), Offset(StartOffset), HeaderSize(StartOffset) {
   }
 
-  // Once the type of all records is known, write the records
+  using BinarySectionWriter::visit;
+
+  // Once the type of all records is known, write the records.
   virtual void writeRecords(uint32_t Entry);
----------------
jh7370 wrote:

Should this be `override` rather than `virtual`?

https://github.com/llvm/llvm-project/pull/75874


More information about the llvm-commits mailing list