| 203 | }; |
| 204 | |
| 205 | struct ExitNodeType : NodeType { |
| 206 | ExitNodeType(LangModule& mod, std::vector<NamedDataType> dataOutputs, |
| 207 | std::vector<std::string> execOutputs) |
| 208 | : NodeType{mod, "exit", "Return from a function"} { |
| 209 | // outputs to the function are inputs to the node |
| 210 | setExecInputs(std::move(execOutputs)); |
| 211 | |
| 212 | setDataInputs(std::move(dataOutputs)); |
| 213 | } |
| 214 | |
| 215 | Result codegen( |
| 216 | size_t execInputID, const llvm::DebugLoc& nodeLocation, const std::vector<llvm::Value*>& io, |
| 217 | llvm::BasicBlock* codegenInto, const std::vector<llvm::BasicBlock*>& /*outputBlocks*/, |
| 218 | std::unordered_map<std::string, std::shared_ptr<void>>& /*compileCache*/) override { |
| 219 | assert(execInputID < execInputs().size() && io.size() == dataInputs().size() && |
| 220 | codegenInto != nullptr); |
| 221 | |
| 222 | // assign the return types |
| 223 | llvm::IRBuilder<> builder(codegenInto); |
| 224 | builder.SetCurrentDebugLocation(nodeLocation); |
| 225 | |
| 226 | llvm::Function* f = codegenInto->getParent(); |
| 227 | size_t ret_start = |
| 228 | f->arg_size() - io.size(); // returns are after args, find where returns start |
| 229 | auto arg_iter = f->arg_begin(); |
| 230 | std::advance(arg_iter, ret_start); |
| 231 | for (auto& value : io) { |
| 232 | builder.CreateStore(value, &*arg_iter, false); // TODO: volitility? |
| 233 | ++arg_iter; |
| 234 | } |
| 235 | |
| 236 | builder.CreateRet(builder.getInt32(execInputID)); |
| 237 | |
| 238 | return {}; |
| 239 | } |
| 240 | |
| 241 | std::unique_ptr<NodeType> clone() const override { |
| 242 | return std::make_unique<ExitNodeType>(*this); |
| 243 | } |
| 244 | |
| 245 | nlohmann::json toJSON() const override { |
| 246 | nlohmann::json ret = nlohmann::json::object(); |
| 247 | |
| 248 | auto& data = ret["data"]; |
| 249 | data = nlohmann::json::array(); |
| 250 | for (auto& pair : dataInputs()) { |
| 251 | data.push_back({{pair.name, pair.type.qualifiedName()}}); |
| 252 | } |
| 253 | |
| 254 | auto& exec = ret["exec"]; |
| 255 | exec = nlohmann::json::array(); |
| 256 | for (auto& name : execInputs()) { exec.push_back(name); } |
| 257 | |
| 258 | return ret; |
| 259 | } |
| 260 | }; |
| 261 | |
| 262 | struct StringLiteralNodeType : NodeType { |
nothing calls this directly
no outgoing calls
no test coverage detected