Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a few llvm19 api change #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ OBJS = parser.o \
native.o \

LLVMCONFIG = llvm-config
CPPFLAGS = `$(LLVMCONFIG) --cppflags` -std=c++14
CPPFLAGS = `$(LLVMCONFIG) --cppflags` -std=c++20
LDFLAGS = `$(LLVMCONFIG) --ldflags` -lpthread -ldl -lz -lncurses -rdynamic
LIBS = `$(LLVMCONFIG) --libs`

Expand Down
16 changes: 10 additions & 6 deletions codegen.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#include "node.h"
#include "codegen.h"
#include "parser.hpp"

#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Compiler.h"
#include "llvm/ADT/ArrayRef.h"
using namespace std;

using namespace llvm;
/* Compile the AST into a module */
void CodeGenContext::generateCode(NBlock& root)
{
std::cout << "Generating code...\n";

/* Create the top level interpreter function to call as entry */
vector<Type*> argTypes;
FunctionType *ftype = FunctionType::get(Type::getVoidTy(MyContext), makeArrayRef(argTypes), false);
FunctionType *ftype = FunctionType::get(Type::getVoidTy(MyContext),ArrayRef(argTypes), false);
mainFunction = Function::Create(ftype, GlobalValue::InternalLinkage, "main", module);
BasicBlock *bblock = BasicBlock::Create(MyContext, "entry", mainFunction, 0);

Expand Down Expand Up @@ -93,7 +97,7 @@ Value* NMethodCall::codeGen(CodeGenContext& context)
for (it = arguments.begin(); it != arguments.end(); it++) {
args.push_back((**it).codeGen(context));
}
CallInst *call = CallInst::Create(function, makeArrayRef(args), "", context.currentBlock());
CallInst *call = CallInst::Create(function, ArrayRef(args), "", context.currentBlock());
std::cout << "Creating method call: " << id.name << endl;
return call;
}
Expand Down Expand Up @@ -172,7 +176,7 @@ Value* NExternDeclaration::codeGen(CodeGenContext& context)
for (it = arguments.begin(); it != arguments.end(); it++) {
argTypes.push_back(typeOf((**it).type));
}
FunctionType *ftype = FunctionType::get(typeOf(type), makeArrayRef(argTypes), false);
FunctionType *ftype = FunctionType::get(typeOf(type), ArrayRef(argTypes), false);
Function *function = Function::Create(ftype, GlobalValue::ExternalLinkage, id.name.c_str(), context.module);
return function;
}
Expand All @@ -184,7 +188,7 @@ Value* NFunctionDeclaration::codeGen(CodeGenContext& context)
for (it = arguments.begin(); it != arguments.end(); it++) {
argTypes.push_back(typeOf((**it).type));
}
FunctionType *ftype = FunctionType::get(typeOf(type), makeArrayRef(argTypes), false);
FunctionType *ftype = FunctionType::get(typeOf(type), ArrayRef(argTypes), false);
Function *function = Function::Create(ftype, GlobalValue::InternalLinkage, id.name.c_str(), context.module);
BasicBlock *bblock = BasicBlock::Create(MyContext, "entry", function, 0);

Expand Down
92 changes: 92 additions & 0 deletions compile_commands.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
[
{
"directory": "/home/sgj/codes/fy/my_toy_compiler",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be updated to avoid hard coding paths or this entire file should be removed since it's not related to the changes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad. I'll be careful next time.

"arguments": [
"clang++",
"-gfull",
"-c",
"-I/usr/include",
"-D_GNU_SOURCE",
"-D__STDC_CONSTANT_MACROS",
"-D__STDC_FORMAT_MACROS",
"-D__STDC_LIMIT_MACROS",
"-std=c++20",
"-o",
"parser.o",
"parser.cpp"
],
"file": "parser.cpp"
},
{
"directory": "/home/sgj/codes/fy/my_toy_compiler",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

"arguments": [
"clang++",
"-gfull",
"-c",
"-I/usr/include",
"-D_GNU_SOURCE",
"-D__STDC_CONSTANT_MACROS",
"-D__STDC_FORMAT_MACROS",
"-D__STDC_LIMIT_MACROS",
"-std=c++20",
"-o",
"codegen.o",
"codegen.cpp"
],
"file": "codegen.cpp"
},
{
"directory": "/home/sgj/codes/fy/my_toy_compiler",
"arguments": [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

"clang++",
"-gfull",
"-c",
"-I/usr/include",
"-D_GNU_SOURCE",
"-D__STDC_CONSTANT_MACROS",
"-D__STDC_FORMAT_MACROS",
"-D__STDC_LIMIT_MACROS",
"-std=c++20",
"-o",
"main.o",
"main.cpp"
],
"file": "main.cpp"
},
{
"directory": "/home/sgj/codes/fy/my_toy_compiler",
"arguments": [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

"clang++",
"-gfull",
"-c",
"-I/usr/include",
"-D_GNU_SOURCE",
"-D__STDC_CONSTANT_MACROS",
"-D__STDC_FORMAT_MACROS",
"-D__STDC_LIMIT_MACROS",
"-std=c++20",
"-o",
"corefn.o",
"corefn.cpp"
],
"file": "corefn.cpp"
},
{
"directory": "/home/sgj/codes/fy/my_toy_compiler",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

"arguments": [
"clang++",
"-gfull",
"-c",
"-I/usr/include",
"-D_GNU_SOURCE",
"-D__STDC_CONSTANT_MACROS",
"-D__STDC_FORMAT_MACROS",
"-D__STDC_LIMIT_MACROS",
"-std=c++20",
"-o",
"native.o",
"native.cpp"
],
"file": "native.cpp"
}
]
4 changes: 2 additions & 2 deletions corefn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern NBlock* programBlock;
llvm::Function* createPrintfFunction(CodeGenContext& context)
{
std::vector<llvm::Type*> printf_arg_types;
printf_arg_types.push_back(llvm::Type::getInt8PtrTy(MyContext)); //char*
printf_arg_types.push_back(llvm::Type::getInt8Ty(MyContext)); //char*

std::cout << "printf" << std::endl;

Expand Down Expand Up @@ -69,7 +69,7 @@ void createEchoFunction(CodeGenContext& context, llvm::Function* printfFn)
toPrint->setName("toPrint");
args.push_back(toPrint);

CallInst *call = CallInst::Create(printfFn, makeArrayRef(args), "", bblock);
CallInst *call = CallInst::Create(printfFn, ArrayRef(args), "", bblock);
ReturnInst::Create(MyContext, bblock);
context.popBlock();
}
Expand Down
Loading