blob: 1bbe2724f0ab94683c9a00be33261e4ad91bf70d [file] [log] [blame]
Zachary Turner63055452017-06-15 22:24:24 +00001//===- FormatUtil.cpp ----------------------------------------- *- C++ --*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "FormatUtil.h"
11#include "llvm/ADT/STLExtras.h"
12#include "llvm/ADT/StringExtras.h"
13#include "llvm/Support/FormatAdapters.h"
14#include "llvm/Support/FormatVariadic.h"
15
16using namespace llvm;
17using namespace llvm::pdb;
18
19std::string llvm::pdb::typesetItemList(ArrayRef<std::string> Opts,
Zachary Turner47d9a562017-06-16 00:04:24 +000020 uint32_t IndentLevel, uint32_t GroupSize,
Zachary Turner63055452017-06-15 22:24:24 +000021 StringRef Sep) {
22 std::string Result;
23 while (!Opts.empty()) {
24 ArrayRef<std::string> ThisGroup;
25 ThisGroup = Opts.take_front(GroupSize);
26 Opts = Opts.drop_front(ThisGroup.size());
27 Result += join(ThisGroup, Sep);
28 if (!Opts.empty()) {
29 Result += Sep;
30 Result += "\n";
31 Result += formatv("{0}", fmt_repeat(' ', IndentLevel));
32 }
33 }
34 return Result;
35}
36
37std::string llvm::pdb::typesetStringList(uint32_t IndentLevel,
38 ArrayRef<StringRef> Strings) {
39 std::string Result = "[";
40 for (const auto &S : Strings) {
41 Result += formatv("\n{0}{1}", fmt_repeat(' ', IndentLevel), S);
42 }
43 Result += "]";
44 return Result;
45}
46
47std::string llvm::pdb::formatSegmentOffset(uint16_t Segment, uint32_t Offset) {
48 return formatv("{0:4}:{1:4}", Segment, Offset);
49}