OpenASIP  2.0
InlineAsmParser.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2017 Tampere University.
3  *
4  * This file is part of TTA-Based Codesign Environment (TCE).
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  *
24 */
25 /**
26  * @file InlineAsmParser.hh
27  *
28  * Declaration of inline assembly parser.
29  *
30  * @author Henry Linjamäki (henry.linjamaki-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #ifndef INLINE_ASM_PARSER_HH
35 #define INLINE_ASM_PARSER_HH
36 
37 #include <map>
38 #include <vector>
39 #include <tuple>
40 
42 
43 namespace TTAProgram {
44  class Program;
45  class InstructionReferenceManager;
46  class BasicBlock;
47 }
48 
49 namespace llvm {
50  class TCETargetMachine;
51  class Mangler;
52  class MachineInstr;
53  class MachineOperand;
54 }
55 
56 /**
57  * The class for parsing TCE assembly listing written as inline assembly in C
58  * code.
59  *
60  * The inline assembly is parsed as parallel code that does not need or should
61  * be scheduled.
62  *
63  */
65 public:
66  InlineAsmParser() = delete;
67  InlineAsmParser(const InlineAsmParser&) = delete;
68  InlineAsmParser& operator=(const InlineAsmParser&) = delete;
69 
71  const llvm::TCETargetMachine& tm,
72  const llvm::Mangler& mangler);
73 
74  bool parse(
75  const llvm::MachineInstr& inlineAsmMI,
76  const std::map<std::string, unsigned>& symbolTable,
79 
80  std::string substituteAsmString(
81  const llvm::MachineInstr& mi,
82  const std::map<std::string, unsigned>& symbolTable,
83  const llvm::Mangler& mangler);
84 
85  static void addDebugInfoToInlineAsmBB(
86  const llvm::MachineInstr& mi,
88 
89  void addLiveRangeData(
90  const llvm::MachineInstr& mi,
92 
93  bool sanityChecks(
94  const llvm::MachineInstr& mi,
95  TTAProgram::BasicBlock& bb) const;
96 
97  std::string registerName(const llvm::MachineOperand& mo) const;
98 
100  return parserDiagnostic_;
101  }
102 
103  // Helper methods
104  static bool isInlineAsm(const llvm::MachineInstr& mi);
105 
106 private:
107 
108  void reportError(size_t lineNum, const std::string& errorMsg);
109  void reportError(const std::string& errorMsg);
110 
111  static void copyInstructions(
112  TTAProgram::Program& prog,
113  TTAProgram::BasicBlock& targetBB,
115 
116  /// The target machine parsing context.
118  /// The symbol name mangler for MIs' symbolic references.
119  const llvm::Mangler& mangler_;
120  /// The diagnostic object to report parse and compile warnings and
121  /// errors to.
123  /// The unique id for "%=" template strings. Each parse() call increases
124  /// the count.
125  unsigned asmId_ = 0;
126 };
127 
128 //#define DEBUG_INLINE_ASM_PARSER
129 
130 #endif // INLINE_ASM_PARSER_HH
InlineAsmParser::addLiveRangeData
void addLiveRangeData(const llvm::MachineInstr &mi, TTAProgram::BasicBlock &bb)
Definition: InlineAsmParser.cc:205
TTAProgram
Definition: Estimator.hh:65
InlineAsmParser::registerName
std::string registerName(const llvm::MachineOperand &mo) const
Definition: InlineAsmParser.cc:268
llvm
Definition: InlineAsmParser.hh:49
TTAProgram::Program
Definition: Program.hh:63
InlineAsmParser::diagnostics
const AssemblyParserDiagnostic & diagnostics() const
Definition: InlineAsmParser.hh:99
InlineAsmParser::parserDiagnostic_
AssemblyParserDiagnostic parserDiagnostic_
The diagnostic object to report parse and compile warnings and errors to.
Definition: InlineAsmParser.hh:122
InlineAsmParser::mangler_
const llvm::Mangler & mangler_
The symbol name mangler for MIs' symbolic references.
Definition: InlineAsmParser.hh:119
InlineAsmParser::addDebugInfoToInlineAsmBB
static void addDebugInfoToInlineAsmBB(const llvm::MachineInstr &mi, TTAProgram::BasicBlock &bb)
Definition: InlineAsmParser.cc:159
InlineAsmParser::tm_
const llvm::TCETargetMachine & tm_
The target machine parsing context.
Definition: InlineAsmParser.hh:117
AssemblyParserDiagnostic.hh
InlineAsmParser::parse
bool parse(const llvm::MachineInstr &inlineAsmMI, const std::map< std::string, unsigned > &symbolTable, TTAProgram::BasicBlock &bb, TTAProgram::InstructionReferenceManager &irm)
Definition: InlineAsmParser.cc:87
AssemblyParserDiagnostic
Definition: AssemblyParserDiagnostic.hh:68
InlineAsmParser::isInlineAsm
static bool isInlineAsm(const llvm::MachineInstr &mi)
Definition: InlineAsmParser.cc:450
InlineAsmParser::asmId_
unsigned asmId_
The unique id for "%=" template strings. Each parse() call increases the count.
Definition: InlineAsmParser.hh:125
InlineAsmParser::InlineAsmParser
InlineAsmParser()=delete
InlineAsmParser::copyInstructions
static void copyInstructions(TTAProgram::Program &prog, TTAProgram::BasicBlock &targetBB, TTAProgram::InstructionReferenceManager &irm)
Definition: InlineAsmParser.cc:502
InlineAsmParser::sanityChecks
bool sanityChecks(const llvm::MachineInstr &mi, TTAProgram::BasicBlock &bb) const
Definition: InlineAsmParser.cc:251
TTAProgram::BasicBlock
Definition: BasicBlock.hh:85
TTAProgram::InstructionReferenceManager
Definition: InstructionReferenceManager.hh:82
InlineAsmParser
Definition: InlineAsmParser.hh:64
llvm::TCETargetMachine
Definition: TCETargetMachine.hh:106
InlineAsmParser::operator=
InlineAsmParser & operator=(const InlineAsmParser &)=delete
InlineAsmParser::substituteAsmString
std::string substituteAsmString(const llvm::MachineInstr &mi, const std::map< std::string, unsigned > &symbolTable, const llvm::Mangler &mangler)
Definition: InlineAsmParser.cc:281
InlineAsmParser::reportError
void reportError(size_t lineNum, const std::string &errorMsg)
Definition: InlineAsmParser.cc:463