-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a09ecdd
commit ab23eb6
Showing
19 changed files
with
835 additions
and
793 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "Setup.h" | ||
#include <filesystem> | ||
#include <string> | ||
|
||
namespace Riddle { | ||
|
||
binaryOpMapTeleTy binaryOpMapTele; | ||
|
||
const std::unordered_map<std::string, std::function<llvm::Type *(llvm::IRBuilder<> &)>> SampleType = { | ||
{"int", [](llvm::IRBuilder<> &Builder) { return Builder.getInt32Ty(); }}, | ||
{"short", [](llvm::IRBuilder<> &Builder) { return Builder.getInt16Ty(); }}, | ||
{"char", [](llvm::IRBuilder<> &Builder) { return Builder.getInt8Ty(); }}, | ||
{"bool", [](llvm::IRBuilder<> &Builder) { return Builder.getInt1Ty(); }}, | ||
{"double", [](llvm::IRBuilder<> &Builder) { return Builder.getDoubleTy(); }}, | ||
{"float", [](llvm::IRBuilder<> &Builder) { return Builder.getFloatTy(); }}, | ||
}; | ||
|
||
|
||
void __attribute__((constructor)) initSetup() { | ||
#define BOM_ARG llvm::IRBuilder<> &builder, llvm::Value *v1, llvm::Value *v2 | ||
llvm::LLVMContext ctx; | ||
llvm::IRBuilder<> builder(ctx); | ||
for(const auto &[name, func]: SampleType) { | ||
llvm::Type* type = func(builder); | ||
binaryOpMapTele[""][type][type] = [](BOM_ARG) { return v2; }; | ||
binaryOpMapTele["+"][type][type] = [](BOM_ARG) { return builder.CreateAdd(v1, v2, "AddV"); }; | ||
binaryOpMapTele["-"][type][type] = [](BOM_ARG) { return builder.CreateSub(v1, v2, "SubV"); }; | ||
binaryOpMapTele["*"][type][type] = [](BOM_ARG) { return builder.CreateMul(v1, v2, "MulV"); }; | ||
binaryOpMapTele["/"][type][type] = [](BOM_ARG) { return builder.CreateFDiv(v1, v2, "DivV"); }; | ||
binaryOpMapTele["%"][type][type] = [](BOM_ARG) { return builder.CreateSRem(v1, v2, "ModV"); }; | ||
binaryOpMapTele["<<"][type][type] = [](BOM_ARG) { return builder.CreateShl(v1, v2, "ShlV"); }; | ||
binaryOpMapTele[">>"][type][type] = [](BOM_ARG) { return builder.CreateAShr(v1, v2, "AShrV"); }; | ||
binaryOpMapTele[">>>"][type][type] = [](BOM_ARG) { return builder.CreateLShr(v1, v2, "LShrV"); }; | ||
binaryOpMapTele["^"][type][type] = [](BOM_ARG) { return builder.CreateXor(v1, v2, "XorV"); }; | ||
binaryOpMapTele["&"][type][type] = [](BOM_ARG) { return builder.CreateAnd(v1, v2, "AndV"); }; | ||
binaryOpMapTele["&&"][type][type] = [](BOM_ARG) { return builder.CreateAnd(v1, v2, "LAndV"); }; | ||
binaryOpMapTele["|"][type][type] = [](BOM_ARG) { return builder.CreateOr(v1, v2, "OrV"); }; | ||
binaryOpMapTele["||"][type][type] = [](BOM_ARG) { return builder.CreateOr(v1, v2, "LOrV"); }; | ||
binaryOpMapTele[">"][type][type] = [](BOM_ARG) { return builder.CreateICmpSGT(v1, v2, "cmpV"); }; | ||
binaryOpMapTele[">="][type][type] = [](BOM_ARG) { return builder.CreateICmpSGE(v1, v2, "cmpV"); }; | ||
binaryOpMapTele["<"][type][type] = [](BOM_ARG) { return builder.CreateICmpSLT(v1, v2, "cmpV"); }; | ||
binaryOpMapTele["<="][type][type] = [](BOM_ARG) { return builder.CreateICmpSLE(v1, v2, "cmpV"); }; | ||
if(type == SampleType.at("double")(builder) || type == SampleType.at("float")(builder)) { | ||
binaryOpMapTele["!="][type][type] = [](BOM_ARG) { return builder.CreateFCmpUNE(v1, v2, "fne"); }; | ||
} else { | ||
binaryOpMapTele["!="][type][type] = [](BOM_ARG) { return builder.CreateICmpNE(v1, v2, "ne"); }; | ||
} | ||
} | ||
#undef BOM_ARG | ||
} | ||
}// namespace Riddle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#ifndef RIDDLE_LANGUAGE_SETUP_H | ||
#define RIDDLE_LANGUAGE_SETUP_H | ||
|
||
#include <functional> | ||
#include <llvm/IR/IRBuilder.h> | ||
#include <llvm/IR/Value.h> | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
namespace Riddle { | ||
typedef std::unordered_map<std::string, std::unordered_map<std::string, std::function<llvm::Value *(llvm::IRBuilder<> &, llvm::Value *)>>>castMapTy; | ||
typedef std::unordered_map<std::string, std::unordered_map<llvm::Type*, std::pmr::unordered_map<llvm::Type*, std::function<llvm::Value *(llvm::IRBuilder<> &, llvm::Value *, llvm::Value *)>>>> binaryOpMapTeleTy; | ||
const static castMapTy castMapTemplate = { | ||
{"int", | ||
{ | ||
{"float", [](llvm::IRBuilder<> &builder, llvm::Value *value) -> llvm::Value * { | ||
return builder.CreateSIToFP(value, builder.getFloatTy(), "IntToFloat"); | ||
}}, | ||
{"double", [](llvm::IRBuilder<> &builder, llvm::Value *value) -> llvm::Value * { | ||
return builder.CreateSIToFP(value, builder.getDoubleTy(), "IntToDouble"); | ||
}}, | ||
{"short", [](llvm::IRBuilder<> &builder, llvm::Value *value) -> llvm::Value * { | ||
return builder.CreateTrunc(value, builder.getInt16Ty(), "IntToShort"); | ||
}}, | ||
{"char", [](llvm::IRBuilder<> &builder, llvm::Value *value) -> llvm::Value * { | ||
return builder.CreateTrunc(value, builder.getInt8Ty(), "IntToChar"); | ||
}}, | ||
}}, | ||
{"float", | ||
|
||
{ | ||
{"int", [](llvm::IRBuilder<> &builder, llvm::Value *value) -> llvm::Value * { | ||
return builder.CreateFPToSI(value, builder.getInt32Ty(), "FloatToInt"); | ||
}}, | ||
{"short", [](llvm::IRBuilder<> &builder, llvm::Value *value) -> llvm::Value * { | ||
return builder.CreateFPToSI(value, builder.getInt16Ty(), "FloatToShort"); | ||
}}, | ||
{"char", [](llvm::IRBuilder<> &builder, llvm::Value *value) -> llvm::Value * { | ||
return builder.CreateFPToSI(value, builder.getInt8Ty(), "FloatToChar"); | ||
}}, | ||
{"double", [](llvm::IRBuilder<> &builder, llvm::Value *value) -> llvm::Value * { | ||
return builder.CreateFPExt(value, builder.getDoubleTy(), "FloatToDouble"); | ||
}}, | ||
}}, | ||
{"double", | ||
|
||
{ | ||
{"int", [](llvm::IRBuilder<> &builder, llvm::Value *value) -> llvm::Value * { | ||
return builder.CreateFPToSI(value, builder.getInt32Ty(), "DoubleToInt"); | ||
}}, | ||
{"short", [](llvm::IRBuilder<> &builder, llvm::Value *value) -> llvm::Value * { | ||
return builder.CreateFPToSI(value, builder.getInt16Ty(), "DoubleToShort"); | ||
}}, | ||
{"char", [](llvm::IRBuilder<> &builder, llvm::Value *value) -> llvm::Value * { | ||
return builder.CreateFPToSI(value, builder.getInt8Ty(), "DoubleToChar"); | ||
}}, | ||
{"float", [](llvm::IRBuilder<> &builder, llvm::Value *value) -> llvm::Value * { | ||
return builder.CreateFPExt(value, builder.getFloatTy(), "DoubleToFloat"); | ||
}}, | ||
}}}; | ||
extern binaryOpMapTeleTy binaryOpMapTele; | ||
extern const std::unordered_map<std::string, std::function<llvm::Type *(llvm::IRBuilder<> &)>> SampleType; | ||
}// namespace Riddle | ||
|
||
#endif//RIDDLE_LANGUAGE_SETUP_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.