write all functions

This commit is contained in:
2024-08-24 01:28:40 +00:00
parent 8781d58776
commit 2168e402d3
3 changed files with 186 additions and 5 deletions

View File

@ -336,6 +336,7 @@ class PhiItem : public ActionItem {
}
};
class SelectItem : public ActionItem {
friend class IRBuilder;
std::string result_full;
std::string cond_full;
std::string true_val_full;
@ -449,6 +450,7 @@ class FunctionDeclareItem : public LLVMIRItemBase {
}
};
class ConstStrItem : public LLVMIRItemBase {
friend std::shared_ptr<ModuleItem> BuildIR(std::shared_ptr<Program_ASTNode> src);
friend class IRBuilder;
std::string string_raw;
size_t const_str_id;

View File

@ -181,7 +181,7 @@ inline LLVMType Type_AST2LLVM(const ExprTypeInfo &src) {
return LLVMIRPTRType();
}
inline std::string StringLiteralDeEscape(const std::string src) {
inline std::string StringLiteralDeEscape(const std::string &src) {
std::stringstream ss;
for (size_t i = 1; i < src.size() - 1; i++) {
if (src[i] != '\\')
@ -207,4 +207,37 @@ inline std::string StringLiteralDeEscape(const std::string src) {
}
}
return ss.str();
}
inline std::string FmtStrLiteralDeEscape(const std::string &src) {
std::stringstream ss;
for (size_t i = 0; i < src.size(); i++) {
if (src[i] == '\\') {
i++;
if (src[i] == 'n')
ss << '\n';
else if (src[i] == 'r')
ss << '\r';
else if (src[i] == 't')
ss << '\t';
else if (src[i] == '\\')
ss << '\\';
else if (src[i] == '\'')
ss << '\'';
else if (src[i] == '\"')
ss << '\"';
else if (src[i] == '0')
ss << '\0';
else
throw std::runtime_error("Invalid escape character");
} else if (src[i] == '$') {
i++;
if (src[i] == '$')
ss << '$';
else
throw std::runtime_error("Invalid escape character");
} else
ss << src[i];
}
return ss.str();
}