LLVM  15.0.0git
WebAssemblyAsmTypeCheck.h
Go to the documentation of this file.
1 //==- WebAssemblyAsmTypeCheck.h - Assembler for WebAssembly -*- 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 /// \file
10 /// This file is part of the WebAssembly Assembler.
11 ///
12 /// It contains code to translate a parsed .s file into MCInsts.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_ASMPARSER_TYPECHECK_H
17 #define LLVM_LIB_TARGET_WEBASSEMBLY_ASMPARSER_TYPECHECK_H
18 
19 #include "llvm/BinaryFormat/Wasm.h"
20 #include "llvm/MC/MCInstrInfo.h"
23 #include "llvm/MC/MCSymbol.h"
24 
25 namespace llvm {
26 
28  MCAsmParser &Parser;
29  const MCInstrInfo &MII;
30 
34  wasm::WasmSignature LastSig;
35  bool TypeErrorThisFunction = false;
36  bool Unreachable = false;
37  bool is64;
38 
39  void dumpTypeStack(Twine Msg);
40  bool typeError(SMLoc ErrorLoc, const Twine &Msg);
41  bool popType(SMLoc ErrorLoc, Optional<wasm::ValType> EVT);
42  bool popRefType(SMLoc ErrorLoc);
43  bool getLocal(SMLoc ErrorLoc, const MCInst &Inst, wasm::ValType &Type);
44  bool checkEnd(SMLoc ErrorLoc, bool PopVals = false);
45  bool checkSig(SMLoc ErrorLoc, const wasm::WasmSignature &Sig);
46  bool getSymRef(SMLoc ErrorLoc, const MCInst &Inst,
47  const MCSymbolRefExpr *&SymRef);
48  bool getGlobal(SMLoc ErrorLoc, const MCInst &Inst, wasm::ValType &Type);
49  bool getTable(SMLoc ErrorLoc, const MCInst &Inst, wasm::ValType &Type);
50 
51 public:
52  WebAssemblyAsmTypeCheck(MCAsmParser &Parser, const MCInstrInfo &MII, bool is64);
53 
54  void funcDecl(const wasm::WasmSignature &Sig);
55  void localDecl(const SmallVector<wasm::ValType, 4> &Locals);
56  void setLastSig(const wasm::WasmSignature &Sig) { LastSig = Sig; }
57  bool endOfFunction(SMLoc ErrorLoc);
58  bool typeCheck(SMLoc ErrorLoc, const MCInst &Inst, OperandVector &Operands);
59 
60  void Clear() {
61  Stack.clear();
62  LocalTypes.clear();
63  ReturnTypes.clear();
64  TypeErrorThisFunction = false;
65  Unreachable = false;
66  }
67 };
68 
69 } // end namespace llvm
70 
71 #endif // LLVM_LIB_TARGET_WEBASSEMBLY_ASMPARSER_TYPECHECK_H
llvm::MCAsmParser
Generic assembler parser interface, for use by target specific assembly parsers.
Definition: MCAsmParser.h:124
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::WebAssemblyAsmTypeCheck
Definition: WebAssemblyAsmTypeCheck.h:27
llvm::SmallVector< wasm::ValType, 8 >
llvm::WebAssemblyAsmTypeCheck::setLastSig
void setLastSig(const wasm::WasmSignature &Sig)
Definition: WebAssemblyAsmTypeCheck.h:56
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::Optional
Definition: APInt.h:33
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
MCAsmParser.h
MCTargetAsmParser.h
llvm::WebAssemblyAsmTypeCheck::WebAssemblyAsmTypeCheck
WebAssemblyAsmTypeCheck(MCAsmParser &Parser, const MCInstrInfo &MII, bool is64)
Definition: WebAssemblyAsmTypeCheck.cpp:47
llvm::WebAssemblyAsmTypeCheck::localDecl
void localDecl(const SmallVector< wasm::ValType, 4 > &Locals)
Definition: WebAssemblyAsmTypeCheck.cpp:57
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
llvm::EVT
Extended Value Type.
Definition: ValueTypes.h:34
MCInstrInfo.h
MCSymbol.h
llvm::WebAssemblyAsmTypeCheck::typeCheck
bool typeCheck(SMLoc ErrorLoc, const MCInst &Inst, OperandVector &Operands)
Definition: WebAssemblyAsmTypeCheck.cpp:226
llvm::wasm::ValType
ValType
Definition: Wasm.h:423
Operands
mir Rename Register Operands
Definition: MIRNamerPass.cpp:74
llvm::WebAssemblyAsmTypeCheck::Clear
void Clear()
Definition: WebAssemblyAsmTypeCheck.h:60
llvm::MCSymbolRefExpr
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
llvm::WebAssemblyAsmTypeCheck::endOfFunction
bool endOfFunction(SMLoc ErrorLoc)
Definition: WebAssemblyAsmTypeCheck.cpp:212
llvm::AMDGPU::SendMsg::Msg
const CustomOperand< const MCSubtargetInfo & > Msg[]
Definition: AMDGPUAsmUtils.cpp:39
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::MCInstrInfo
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:26
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:591
Wasm.h
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
llvm::WebAssemblyAsmTypeCheck::funcDecl
void funcDecl(const wasm::WasmSignature &Sig)
Definition: WebAssemblyAsmTypeCheck.cpp:52
llvm::wasm::WasmSignature
Definition: Wasm.h:433