Initial commit
This commit is contained in:
commit
a969707ddb
36
.devcontainer/devcontainer.json
Normal file
36
.devcontainer/devcontainer.json
Normal file
@ -0,0 +1,36 @@
|
||||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
|
||||
{
|
||||
"name": "Existing Dockerfile",
|
||||
"build": {
|
||||
// Sets the run context to one level up instead of the .devcontainer folder.
|
||||
"context": "..",
|
||||
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
|
||||
"dockerfile": "../Dockerfile"
|
||||
},
|
||||
|
||||
// Features to add to the dev container. More info: https://containers.dev/features.
|
||||
// "features": {},
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
|
||||
// Uncomment the next line to run commands after the container is created.
|
||||
// "postCreateCommand": "cat /etc/os-release",
|
||||
|
||||
// Configure tool-specific properties.
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"twxs.cmake",
|
||||
"ms-vscode.cmake-tools",
|
||||
"codeium.codeium",
|
||||
"mike-lischke.vscode-antlr4",
|
||||
"ms-vscode.cpptools-extension-pack"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
|
||||
// "remoteUser": "devcontainer"
|
||||
}
|
||||
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
build/
|
||||
CMakeCache.txt
|
||||
**/CMakeCache.txt
|
||||
Makefile
|
||||
18
.vscode/c_cpp_properties.json
vendored
Normal file
18
.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**",
|
||||
"/usr/local/include/antlr4-runtime",
|
||||
"${workspaceFolder}/build/antlr4/generated"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/clang-19",
|
||||
"cStandard": "c17",
|
||||
"cppStandard": "c++17",
|
||||
"intelliSenseMode": "linux-clang-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
48
CMakeLists.txt
Normal file
48
CMakeLists.txt
Normal file
@ -0,0 +1,48 @@
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.30 FATAL_ERROR)
|
||||
PROJECT(HOOLANG)
|
||||
|
||||
SET (CMAKE_CXX_STANDARD 17)
|
||||
SET (ANTLR_JAR /usr/local/lib/antlr4-4.13.2-complete.jar)
|
||||
SET (ANTLR_INCLUDE_DIR /usr/local/include/antlr4-runtime/)
|
||||
SET (ANTLR_GENERATED_DIR "${CMAKE_BINARY_DIR}/antlr4/generated")
|
||||
SET (GRAMMAR_FILE "${CMAKE_SOURCE_DIR}/Hoo.g4")
|
||||
SET (LLVM_LIBRARY_DIRS "/usr/lib/llvm-19/lib")
|
||||
# SET (LLVM_LIBS
|
||||
# ${LLVM_LIBRARY_DIRS}/libLLVMCore.a
|
||||
# ${LLVM_LIBRARY_DIRS}/libLLVMIRReader.a
|
||||
# ${LLVM_LIBRARY_DIRS}/libLLVMSupport.a
|
||||
# )
|
||||
|
||||
FIND_PACKAGE(LLVM REQUIRED CONFIG)
|
||||
|
||||
MESSAGE (STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
|
||||
MESSAGE (${LLVM_DEFINITIONS})
|
||||
|
||||
LLVM_MAP_COMPONENTS_TO_LIBNAMES(llvm_libs support core irreader)
|
||||
MESSAGE (${llvm_libs})
|
||||
|
||||
# ADD_CUSTOM_COMMAND(OUTPUT ${ANTLR_GENERATED_DIR}/HooBaseVisitor.cpp
|
||||
# COMMAND java -jar ${ANTLR_JAR} -no-listener -visitor -o ${ANTLR_GENERATED_DIR} -Dlanguage=Cpp ${GRAMMAR_FILE}
|
||||
# WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
# DEPENDS ${GRAMMAR_FILE})
|
||||
|
||||
EXECUTE_PROCESS(
|
||||
COMMAND java -jar ${ANTLR_JAR} -no-listener -visitor -o ${ANTLR_GENERATED_DIR} -Dlanguage=Cpp ${GRAMMAR_FILE}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_FILE ${ANTLR_GENERATED_DIR}/HooBaseVisitor.cpp
|
||||
)
|
||||
|
||||
ADD_CUSTOM_TARGET(HooBaseVisitor ALL DEPENDS ${ANTLR_GENERATED_DIR}/HooBaseVisitor.cpp)
|
||||
|
||||
INCLUDE_DIRECTORIES(${ANTLR_GENERATED_DIR} ${ANTLR_INCLUDE_DIR})
|
||||
|
||||
ADD_EXECUTABLE(hoo
|
||||
Hoo.cpp Visitor.cpp
|
||||
${ANTLR_GENERATED_DIR}/HooBaseVisitor.cpp
|
||||
${ANTLR_GENERATED_DIR}/HooVisitor.cpp
|
||||
${ANTLR_GENERATED_DIR}/HooLexer.cpp
|
||||
${ANTLR_GENERATED_DIR}/HooParser.cpp)
|
||||
|
||||
ADD_DEPENDENCIES(hoo HooBaseVisitor)
|
||||
|
||||
TARGET_LINK_LIBRARIES(hoo antlr4-runtime ${LLVM_LIBS})
|
||||
40
Dockerfile
Normal file
40
Dockerfile
Normal file
@ -0,0 +1,40 @@
|
||||
FROM ubuntu:oracular AS build
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y git
|
||||
RUN apt-get install -y cmake clang-19
|
||||
RUN apt-get install -y openjdk-21-jdk-headless maven
|
||||
|
||||
RUN mkdir /builds
|
||||
WORKDIR /builds
|
||||
RUN git clone https://github.com/antlr/antlr4.git
|
||||
WORKDIR /builds/antlr4
|
||||
RUN git checkout 4.13.2
|
||||
ENV MAVEN_OPTS="-Xmx1G"
|
||||
|
||||
RUN mvn clean
|
||||
RUN mvn -DskipTests install
|
||||
RUN echo "if [ ! -f /root/.m2/repository/org/antlr/antlr4/4.13.2/antlr4-4.13.2-complete.jar ]; then exit 1; fi" > verify.sh
|
||||
RUN chmod +x verify.sh
|
||||
RUN ./verify.sh
|
||||
|
||||
RUN mkdir -p /custom/antlr4
|
||||
RUN cp /root/.m2/repository/org/antlr/antlr4/4.13.2/antlr4-4.13.2-complete.jar /custom/antlr4/antlr4-4.13.2-complete.jar
|
||||
RUN mkdir -p /custom/antlr4-cpp-runtime
|
||||
WORKDIR /builds/antlr4/runtime/Cpp
|
||||
RUN mkdir build
|
||||
WORKDIR /builds/antlr4/runtime/Cpp/build
|
||||
ENV CXX=/usr/bin/clang++-19
|
||||
RUN cmake .. -DANTLR4_INSTALL=ON
|
||||
RUN make
|
||||
RUN DESTDIR=/custom/antlr4-cpp-runtime make install
|
||||
|
||||
FROM ubuntu:oracular AS runtime
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y git
|
||||
RUN apt-get install -y cmake clang-19
|
||||
RUN apt-get install -y openjdk-21-jdk-headless maven
|
||||
RUN apt-get install -y llvm llvm-dev
|
||||
RUN apt-get install -y libedit-dev libzstd-dev libcurlpp-dev
|
||||
COPY --from=build /custom/antlr4-cpp-runtime/usr/ /usr/
|
||||
COPY --from=build /custom/antlr4/antlr4-4.13.2-complete.jar /usr/local/lib/antlr4-4.13.2-complete.jar
|
||||
ENV CXX=/usr/bin/clang++-19
|
||||
13
Hoo.g4
Normal file
13
Hoo.g4
Normal file
@ -0,0 +1,13 @@
|
||||
grammar Hoo;
|
||||
|
||||
import hoolexer;
|
||||
|
||||
literal:
|
||||
DECIMAL_LITERAL |
|
||||
FLOAT_LITERAL |
|
||||
BOOL_LITERAL |
|
||||
CHAR_LITERAL |
|
||||
STRING_LITERAL |
|
||||
TEXT_BLOCK;
|
||||
|
||||
unit: literal;
|
||||
5
Hoo.hpp
Normal file
5
Hoo.hpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "Visitor.hpp"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
return 0;
|
||||
}
|
||||
40
HooLexer.g4
Normal file
40
HooLexer.g4
Normal file
@ -0,0 +1,40 @@
|
||||
lexer grammar HooLexer;
|
||||
|
||||
IDENTIFIER: Letter LetterOrDigit*;
|
||||
|
||||
DECIMAL_LITERAL : '0' | [1-9] [0-9]*;
|
||||
// HEX_LITERAL : '0' [xX] [0-9a-fA-F] ([0-9a-fA-F_]* [0-9a-fA-F])? [lL]?;
|
||||
// OCT_LITERAL : '0' '_'* [0-7] ([0-7_]* [0-7])? [lL]?;
|
||||
// BINARY_LITERAL : '0' [bB] [01] ([01_]* [01])? [lL]?;
|
||||
|
||||
FLOAT_LITERAL: (Digits '.' Digits? | '.' Digits);
|
||||
|
||||
BOOL_LITERAL: 'true' | 'false';
|
||||
|
||||
CHAR_LITERAL: '\'' (~['\\\r\n] | EscapeSequence) '\'';
|
||||
|
||||
STRING_LITERAL: '"' (~["\\\r\n] | EscapeSequence)* '"';
|
||||
|
||||
TEXT_BLOCK: '"""' [ \t]* [\r\n] (. | EscapeSequence)*? '"""';
|
||||
|
||||
NULL_LITERAL: 'null';
|
||||
|
||||
WS: [ \t\r\n\u000C]+ -> channel(HIDDEN);
|
||||
COMMENT: '/*' .*? '*/' -> channel(HIDDEN);
|
||||
LINE_COMMENT: '//' ~[\r\n]* -> channel(HIDDEN);
|
||||
|
||||
fragment EscapeSequence:
|
||||
'\\' 'u005c'? [btnfr"'\\]
|
||||
| '\\' 'u005c'? ([0-3]? [0-7])? [0-7]
|
||||
| '\\' 'u'+ HexDigit HexDigit HexDigit HexDigit;
|
||||
|
||||
fragment HexDigit: [0-9a-fA-F];
|
||||
|
||||
fragment Digits: [0-9];
|
||||
|
||||
fragment LetterOrDigit: Letter | [0-9];
|
||||
|
||||
fragment Letter:
|
||||
[a-zA-Z$_]
|
||||
| ~[\u0000-\u007F\uD800-\uDBFF]
|
||||
| [\uD800-\uDBFF] [\uDC00-\uDFFF];
|
||||
36
Visitor.cpp
Normal file
36
Visitor.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#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);
|
||||
}
|
||||
23
Visitor.hpp
Normal file
23
Visitor.hpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "HooVisitor.h"
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <llvm/IR/LLVMContext.h>
|
||||
#include <llvm/IR/Module.h>
|
||||
#include <llvm/IR/IRBuilder.h>
|
||||
|
||||
class Visitor : public HooVisitor
|
||||
{
|
||||
private:
|
||||
std::string &_moduleName;
|
||||
std::shared_ptr<llvm::LLVMContext> _context;
|
||||
std::shared_ptr<llvm::Module> _module;
|
||||
std::shared_ptr<llvm::IRBuilder<>> _builder;
|
||||
|
||||
public:
|
||||
Visitor(std::string &moduleName);
|
||||
|
||||
public:
|
||||
std::any visitLiteral(HooParser::LiteralContext *ctx) override;
|
||||
std::any visitUnit(HooParser::UnitContext *ctx) override;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user