From cc7b9b34e99fa17357e14ac69f5fb2d1535b5512 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 3 Mar 2026 07:22:19 +0000 Subject: Added all built-in functions --- include/cps/StringConversionHandler.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 include/cps/StringConversionHandler.h (limited to 'include/cps/StringConversionHandler.h') diff --git a/include/cps/StringConversionHandler.h b/include/cps/StringConversionHandler.h new file mode 100644 index 0000000..db493bf --- /dev/null +++ b/include/cps/StringConversionHandler.h @@ -0,0 +1,33 @@ +#pragma once +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" + +namespace cps { + +class StringConversionHandler { + llvm::LLVMContext &Context; + llvm::IRBuilder<> &Builder; + llvm::Module &Module; + + llvm::FunctionCallee SprintfFunc; + llvm::FunctionCallee StrtolFunc; + llvm::FunctionCallee StrtodFunc; + llvm::FunctionCallee MallocFunc; + +public: + StringConversionHandler(llvm::LLVMContext &Ctx, llvm::IRBuilder<> &B, llvm::Module &M); + + void setupExternalFunctions(); + + // NUM TO STR(x) RETURNS STRING + llvm::Value *emitNumToStr(llvm::Value *Num, bool IsReal); + + // STR TO NUM(x) RETURNS NUMBER + llvm::Value *emitStrToNum(llvm::Value *Str, bool AsReal); + + // IS NUM(ThisString) RETURNS BOOLEAN + llvm::Value *emitIsNum(llvm::Value *Str); +}; + +} // namespace cps -- cgit v1.3.1-4-g156e