c-compiler/src/binops.h

64 lines
1.4 KiB
C++

#ifndef BINOP_H
#define BINOP_H
#include <memory>
#include "types.h"
namespace types {
enum class BinOp {
Assignment,
Add,
Sub,
LessThan,
GreaterThan,
};
enum class Unary {
AddPostfix,
AddPrefix,
SubPostfix,
SubPrefix,
Not,
Negation,
Plus,
};
int operator_precedence(BinOp& op);
std::string format_operator(BinOp& op);
struct BinopDefinition {
std::shared_ptr<Type> lhs;
BinOp op;
std::shared_ptr<Type> rhs;
std::shared_ptr<Type> result;
bool lhs_lvalue;
llvm::Value* (*codegen)(codegen::Builder& builder, llvm::Value* lhs, llvm::Value* rhs);
};
std::vector<BinopDefinition> create_binops();
std::optional<BinopDefinition> find_binop(
std::vector<BinopDefinition>& binops,
std::shared_ptr<types::Type> lhs,
BinOp op,
std::shared_ptr<types::Type> rhs);
struct UnopDefinition {
std::shared_ptr<Type> value;
Unary op;
std::shared_ptr<Type> res;
llvm::Value* (*codegen)(codegen::Builder& builder, std::shared_ptr<Type> ty, llvm::Value* value);
};
std::vector<UnopDefinition> create_unops();
std::optional<UnopDefinition> find_unop(
std::vector<UnopDefinition>& unops,
std::shared_ptr<types::Type> value,
Unary op);
}
#endif