OpenASIP 2.2
Loading...
Searching...
No Matches
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
43namespace TTAProgram {
44 class Program;
45 class InstructionReferenceManager;
46 class BasicBlock;
47}
48
49namespace 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 */
65public:
66 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
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
106private:
107
108 void reportError(size_t lineNum, const std::string& errorMsg);
109 void reportError(const std::string& errorMsg);
110
111 static void copyInstructions(
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
static bool isInlineAsm(const llvm::MachineInstr &mi)
const llvm::Mangler & mangler_
The symbol name mangler for MIs' symbolic references.
std::string substituteAsmString(const llvm::MachineInstr &mi, const std::map< std::string, unsigned > &symbolTable, const llvm::Mangler &mangler)
AssemblyParserDiagnostic parserDiagnostic_
The diagnostic object to report parse and compile warnings and errors to.
const AssemblyParserDiagnostic & diagnostics() const
std::string registerName(const llvm::MachineOperand &mo) const
InlineAsmParser(const InlineAsmParser &)=delete
static void addDebugInfoToInlineAsmBB(const llvm::MachineInstr &mi, TTAProgram::BasicBlock &bb)
InlineAsmParser()=delete
static void copyInstructions(TTAProgram::Program &prog, TTAProgram::BasicBlock &targetBB, TTAProgram::InstructionReferenceManager &irm)
bool sanityChecks(const llvm::MachineInstr &mi, TTAProgram::BasicBlock &bb) const
bool parse(const llvm::MachineInstr &inlineAsmMI, const std::map< std::string, unsigned > &symbolTable, TTAProgram::BasicBlock &bb, TTAProgram::InstructionReferenceManager &irm)
const llvm::TCETargetMachine & tm_
The target machine parsing context.
InlineAsmParser & operator=(const InlineAsmParser &)=delete
unsigned asmId_
The unique id for "%=" template strings. Each parse() call increases the count.
void reportError(size_t lineNum, const std::string &errorMsg)
void addLiveRangeData(const llvm::MachineInstr &mi, TTAProgram::BasicBlock &bb)