Skip to content

src/TargetCode.h

Namespaces

Name
clang

Classes

Name
class TargetCode
A collection of all code from the input file that needs to be copied to the target source file.

Types

Name
using std::deque< std::shared_ptr< TargetCodeFragment >> TargetCodeFragmentDeque

Attributes

Name
int clauseparam

Types Documentation

using TargetCodeFragmentDeque

1
using TargetCodeFragmentDeque =  std::deque<std::shared_ptr<TargetCodeFragment>>;

Attributes Documentation

variable clauseparam

1
int clauseparam;

Source code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//===-- sotoc/src/TargetCode.h --------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#pragma once

#include <deque>
#include <memory>
#include <set>
#include <string>

#include "clang/Rewrite/Core/Rewriter.h"

#include "TargetCodeFragment.h"

namespace clang {
class SourceManager;
}

using TargetCodeFragmentDeque = std::deque<std::shared_ptr<TargetCodeFragment>>;

extern int clauseparam;
class TargetCode {

  TargetCodeFragmentDeque CodeFragments;
  std::set<std::string> SystemHeaders;
  clang::Rewriter &TargetCodeRewriter;
  clang::SourceManager &SM;

public:
  TargetCode(clang::Rewriter &TargetCodeRewriter)
      : TargetCodeRewriter(TargetCodeRewriter),
        SM(TargetCodeRewriter.getSourceMgr()){};

  bool addCodeFragment(std::shared_ptr<TargetCodeFragment> Frag,
                       bool PushFront = false);
  bool addCodeFragmentFront(std::shared_ptr<TargetCodeFragment> Fag);
  void generateCode(llvm::raw_ostream &Out);
  TargetCodeFragmentDeque::const_iterator getCodeFragmentsBegin() {
    return CodeFragments.begin();
  }
  TargetCodeFragmentDeque::const_iterator getCodeFragmentsEnd() {
    return CodeFragments.end();
  }
  void addHeader(const std::string &Header) { SystemHeaders.insert(Header); }

private:
  void generateVariableDecl(const TargetRegionVariable &Var,
                            llvm::raw_ostream &Out);
  void generateFunctionPrologue(TargetCodeRegion *TCR, llvm::raw_ostream &Out);
  void generateFunctionEpilogue(TargetCodeRegion *TCR, llvm::raw_ostream &Out);
  std::string generateFunctionName(TargetCodeRegion *TCR);
  void generateArgument(const TargetRegionVariable &Aarg,
                        llvm::raw_ostream &Out);
};

Last update: 2021-11-24
Back to top