Skip to content

TargetCode

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

#include <TargetCode.h>

Public Functions

Name
TargetCode(clang::Rewriter & TargetCodeRewriter)
bool addCodeFragment(std::shared_ptr< TargetCodeFragment > Frag, bool PushFront =false)
Add a piece of code from the input file to this collection.
bool addCodeFragmentFront(std::shared_ptr< TargetCodeFragment > Fag)
See addCodeFragment.
void generateCode(llvm::raw_ostream & Out)
Generate target code from all fragments and system headers added to this collection.
TargetCodeFragmentDeque::const_iterator getCodeFragmentsBegin()
Get an iterate over all code fragments in this collection.
TargetCodeFragmentDeque::const_iterator getCodeFragmentsEnd()
See getCodeFragmentsBegin.
void addHeader(const std::string & Header)
Add a header file to be included by the target code.

Private Functions

Name
void generateVariableDecl(const TargetRegionVariable & Var, llvm::raw_ostream & Out)
Generate the variable declaration of a transferred variable.
void generateFunctionPrologue(TargetCodeRegion * TCR, llvm::raw_ostream & Out)
Generates a function prologue for a target region.
void generateFunctionEpilogue(TargetCodeRegion * TCR, llvm::raw_ostream & Out)
Generates a function epilogue for a target region.
std::string generateFunctionName(TargetCodeRegion * TCR)
Generate a function name for a target region.
void generateArgument(const TargetRegionVariable & Aarg, llvm::raw_ostream & Out)
Generate function arguments.

Private Attributes

Name
TargetCodeFragmentDeque CodeFragments
Collection of all code locations that need to be copied.
std::set< std::string > SystemHeaders
Header files which will also be present on the target.
clang::Rewriter & TargetCodeRewriter
clang::SourceManager & SM

Public Functions Documentation

function TargetCode

1
2
3
inline TargetCode(
    clang::Rewriter & TargetCodeRewriter
)

function addCodeFragment

1
2
3
4
bool addCodeFragment(
    std::shared_ptr< TargetCodeFragment > Frag,
    bool PushFront =false
)

Add a piece of code from the input file to this collection.

Parameters:

  • Frag Target code fragment to add
  • PushFront Whether to push it to the front or the back

Adds a code fragment.

This function uses the fragments source location to check wether it was already added and where in the list of code fragments to add it.

Adds a TargetCodeFragment to Target Code

function addCodeFragmentFront

1
2
3
bool addCodeFragmentFront(
    std::shared_ptr< TargetCodeFragment > Fag
)

See addCodeFragment.

function generateCode

1
2
3
void generateCode(
    llvm::raw_ostream & Out
)

Generate target code from all fragments and system headers added to this collection.

Parameters:

  • Out Out stream

Generate target code.

Generates the actual target code

function getCodeFragmentsBegin

1
inline TargetCodeFragmentDeque::const_iterator getCodeFragmentsBegin()

Get an iterate over all code fragments in this collection.

function getCodeFragmentsEnd

1
inline TargetCodeFragmentDeque::const_iterator getCodeFragmentsEnd()

See getCodeFragmentsBegin.

function addHeader

1
2
3
inline void addHeader(
    const std::string & Header
)

Add a header file to be included by the target code.

Private Functions Documentation

function generateVariableDecl

1
2
3
4
void generateVariableDecl(
    const TargetRegionVariable & Var,
    llvm::raw_ostream & Out
)

Generate the variable declaration of a transferred variable.

Parameters:

  • Var The variable for which to print the declaration
  • Out The output stream to which to write the variable declaration

Generate the variable declaration (including setting the variable to the proper value) of a transferred variable and print it to the specified output stream.

function generateFunctionPrologue

1
2
3
4
void generateFunctionPrologue(
    TargetCodeRegion * TCR,
    llvm::raw_ostream & Out
)

Generates a function prologue for a target region.

Parameters:

  • TCR Code region
  • Out Out stream

Generate function prologue.

This prologue consists of a function declaration and code to copy local variables into scope.

Generates everything that comes before the actual target code, like the function head, local variables and helper functions.

function generateFunctionEpilogue

1
2
3
4
void generateFunctionEpilogue(
    TargetCodeRegion * TCR,
    llvm::raw_ostream & Out
)

Generates a function epilogue for a target region.

Parameters:

  • TCR Target code
  • Out Out stream

Generate function epilogue.

This prologue consists of a code to copy variables from the local scope back.

Generates everything that comes after the actual target code, like '}' and scalar copies.

function generateFunctionName

1
2
3
std::string generateFunctionName(
    TargetCodeRegion * TCR
)

Generate a function name for a target region.

Parameters:

  • TCR Target code region

Return: std::string Function name

Generates function name.

function generateArgument

1
2
3
4
void generateArgument(
    const TargetRegionVariable & Aarg,
    llvm::raw_ostream & Out
)

Generate function arguments.

Parameters:

  • Arg Argument
  • Out Out stream

Generates the argument list for the target function.

Private Attributes Documentation

variable CodeFragments

1
TargetCodeFragmentDeque CodeFragments;

Collection of all code locations that need to be copied.

variable SystemHeaders

1
std::set< std::string > SystemHeaders;

Header files which will also be present on the target.

Instead of copying the code declarations in them, we can simply add #include directives for these headers to the target code.

variable TargetCodeRewriter

1
clang::Rewriter & TargetCodeRewriter;

variable SM

1
clang::SourceManager & SM;

Last update: 2021-11-24
Back to top