7 #include <llvm/ADT/StringRef.h>
14 #include <unordered_map>
15 #include <unordered_set>
17 #include "core/adt/hash.h"
18 #include "core/adt/sexp.h"
19 #include "core/calling_conv.h"
20 #include "core/error.h"
21 #include "core/inst.h"
22 #include "core/lexer.h"
23 #include "core/visibility.h"
24 #include "core/xtor.h"
45 using VRegMap = std::unordered_map<ConstRef<Inst>,
unsigned>;
49 std::optional<unsigned> Align;
61 Section(
Data *data) : D(data) {}
70 Parser(llvm::StringRef buf, std::string_view ident);
80 std::unique_ptr<Prog>
Parse();
84 void ParseDirective(
const std::string_view op);
86 void ParseSection(
bool push);
94 void ParseItem(Type ty);
95 void ParseItems(Type ty);
96 void ParseComm(Visibility visibility);
100 void ParseStackObject();
103 void ParsePersonality();
105 void ParseVisibility();
106 void ParseNoInline();
110 void ParseThreadLocal();
111 void ParsePopSection();
117 void ParseAddrsigSym();
118 void ParseProtected();
126 void CreateBlock(
Func *func,
const std::string_view name);
129 Section &GetSection();
131 Object *GetOrCreateObject();
133 Atom *GetOrCreateAtom();
139 void Align(int64_t alignment);
144 [[nodiscard]]
static llvm::Error PhiPlacement(
Func &func, VRegMap vregs);
149 const std::vector<std::pair<const char *, T>> &options,
150 const std::string_view str
156 Type ParseType(std::string_view str);
158 TypeFlag ParseTypeFlags(
const std::string_view op);
160 CallingConv ParseCallingConv(
const std::string_view str);
162 Visibility ParseVisibility(
const std::string_view str);
164 std::string_view ParseName(std::string_view ident);
177 Operand(Register reg) : kind_(Kind::REGISTER), reg_(reg) {}
178 Operand(
Value *val) : kind_(Kind::VALUE), val_(val) {}
180 std::optional<uintptr_t> ToVReg()
const
182 if (kind_ == Kind::VALUE) {
183 auto val =
reinterpret_cast<uintptr_t
>(val_);
184 return (val & 1) == 1 ? std::optional<uintptr_t>(val) : std::nullopt;
189 std::optional<Value *> ToVal()
const
191 if (kind_ == Kind::VALUE)
return val_;
195 std::optional<Register> ToReg()
const
197 if (kind_ == Kind::REGISTER)
return reg_;
211 void ParseInstruction(
212 const std::string_view op,
220 const std::string &op,
221 const std::vector<Operand> &ops,
222 const std::vector<std::pair<unsigned, TypeFlag>> &flags,
223 const std::optional<Cond> &ccs,
224 const std::optional<size_t> &sizes,
225 const std::vector<Type> &ts,
226 const std::optional<CallingConv> &conv,
231 void ParseAnnotation(
const std::string_view name,
AnnotSet &annot);
237 std::unique_ptr<Prog> prog_;
241 std::unordered_set<std::string> globls_;
243 std::unordered_set<std::string> hidden_;
245 std::unordered_set<std::string> weak_;
247 std::stack<Section> stk_;