36 lines
1.2 KiB
C++
36 lines
1.2 KiB
C++
#include "Visitor.hpp"
|
|
|
|
#include <llvm/IR/Constants.h>
|
|
#include <llvm/IR/Type.h>
|
|
#include <llvm/Support/raw_ostream.h>
|
|
|
|
Visitor::Visitor(std::string &moduleName) : _moduleName(moduleName),
|
|
_context(std::make_shared<llvm::LLVMContext>()),
|
|
_module(std::make_shared<llvm::Module>(moduleName, *_context)),
|
|
_builder(std::make_shared<llvm::IRBuilder<>>(*_context))
|
|
{
|
|
}
|
|
|
|
std::any Visitor::visitLiteral(HooParser::LiteralContext *ctx)
|
|
{
|
|
// Implement your custom logic for visiting a LiteralContext here
|
|
// Example: if it's a decimal literal, return its value as a string
|
|
if (ctx->DECIMAL_LITERAL())
|
|
{
|
|
return ctx->DECIMAL_LITERAL()->getText();
|
|
}
|
|
// Add handling for other literal types as needed
|
|
return visitChildren(ctx);
|
|
}
|
|
|
|
std::any Visitor::visitUnit(HooParser::UnitContext *ctx)
|
|
{
|
|
// Implement your custom logic for visiting a UnitContext here
|
|
// Example: if it's a literal, return its value as a string
|
|
if (ctx->literal())
|
|
{
|
|
return visit(ctx->literal());
|
|
}
|
|
// Add handling for other unit types as needed
|
|
return visitChildren(ctx);
|
|
} |