| 260 | }; |
| 261 | |
| 262 | struct StringLiteralNodeType : NodeType { |
| 263 | StringLiteralNodeType(LangModule& mod, std::string str) |
| 264 | : NodeType(mod, "strliteral", "string literal"), literalString(std::move(str)) { |
| 265 | makePure(); |
| 266 | |
| 267 | setDataOutputs({{"", mod.typeFromName("i8*")}}); |
| 268 | } |
| 269 | |
| 270 | Result codegen( |
| 271 | size_t /*execInputID*/, const llvm::DebugLoc& nodeLocation, |
| 272 | const std::vector<llvm::Value*>& io, llvm::BasicBlock* codegenInto, |
| 273 | const std::vector<llvm::BasicBlock*>& outputBlocks, |
| 274 | std::unordered_map<std::string, std::shared_ptr<void>>& /*compileCache*/) override { |
| 275 | assert(io.size() == 1 && codegenInto != nullptr && outputBlocks.size() == 1); |
| 276 | |
| 277 | llvm::IRBuilder<> builder(codegenInto); |
| 278 | builder.SetCurrentDebugLocation(nodeLocation); |
| 279 | |
| 280 | auto global = builder.CreateGlobalString(literalString); |
| 281 | |
| 282 | auto const0ID = llvm::ConstantInt::get(context().llvmContext(), llvm::APInt(32, 0, false)); |
| 283 | auto gep = builder.CreateGEP(global, |
| 284 | // LLVM 3.6- doesn't have std::initializer_list constructor to llvm::ArrayRef |
| 285 | #if LLVM_VERSION_LESS_EQUAL(3, 6) |
| 286 | std::vector<llvm::Value*> { |
| 287 | { const0ID, const0ID } |
| 288 | } |
| 289 | #else |
| 290 | { const0ID, const0ID } |
| 291 | #endif |
| 292 | ); |
| 293 | builder.CreateStore(gep, io[0], false); |
| 294 | |
| 295 | builder.CreateBr(outputBlocks[0]); |
| 296 | |
| 297 | return {}; |
| 298 | } |
| 299 | |
| 300 | std::unique_ptr<NodeType> clone() const override { |
| 301 | return std::make_unique<StringLiteralNodeType>(*this); |
| 302 | } |
| 303 | |
| 304 | nlohmann::json toJSON() const override { return literalString; } |
| 305 | std::string literalString; |
| 306 | }; |
| 307 | |
| 308 | struct IntToFloatNodeType : NodeType { |
| 309 | IntToFloatNodeType(LangModule& mod) : NodeType(mod, "inttofloat", "convert integer to float") { |
nothing calls this directly
no outgoing calls
no test coverage detected