-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend reader for bootstrap compiler (#381)
- Loading branch information
1 parent
3723a60
commit 6805d45
Showing
91 changed files
with
677 additions
and
557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,5 @@ | ||
import "std/data/vector"; | ||
import "../../src-bootstrap/bindings/llvm/llvm" as llvm; | ||
import "../../src-bootstrap/reader/reader"; | ||
|
||
f<int> main() { | ||
//llvm::initializeAllTargets(); | ||
//llvm::initializeAllTargetInfos(); | ||
//llvm::initializeAllTargetMCs(); | ||
//llvm::initializeAllAsmPrinters(); | ||
llvm::initializeNativeTarget(); | ||
llvm::initializeNativeAsmPrinter(); | ||
|
||
heap string targetTriple = llvm::getDefaultTargetTriple(); | ||
string error; | ||
llvm::Target target = llvm::getTargetFromTriple(targetTriple, &error); | ||
llvm::TargetMachine targetMachine = target.createTargetMachine(targetTriple, "generic", "", llvm::LLVMCodeGenOptLevel::CodeGenLevelDefault, llvm::LLVMRelocMode::RelocDefault, llvm::LLVMCodeModel::CodeModelDefault); | ||
|
||
llvm::LLVMContext context; | ||
llvm::Module module = llvm::Module("test", context); | ||
module.setDataLayout(targetMachine.createDataLayout()); | ||
module.setTargetTriple(targetTriple); | ||
llvm::Builder builder = llvm::Builder(context); | ||
|
||
llvm::Type returnType = builder.getInt32Ty(); | ||
Vector<llvm::Type> argTypes; | ||
llvm::Type funcType = llvm::getFunctionType(returnType, argTypes); | ||
llvm::Function func = llvm::Function(module, "main", funcType); | ||
func.setLinkage(llvm::LLVMLinkage::ExternalLinkage); | ||
|
||
llvm::BasicBlock entry = llvm::BasicBlock(context, ""); | ||
func.pushBack(entry); | ||
builder.setInsertPoint(entry); | ||
|
||
llvm::Value calcResult = builder.createAdd(builder.getInt32(1), builder.getInt32(2), "calcResult"); | ||
|
||
llvm::Value helloWorldStr = builder.createGlobalStringPtr("Hello, world!\n", "helloWorldStr"); | ||
Vector<llvm::Type> printfArgTypes; | ||
printfArgTypes.pushBack(builder.getPtrTy()); | ||
printfArgTypes.pushBack(builder.getInt32Ty()); | ||
llvm::Type printfFuncType = llvm::getFunctionType(builder.getInt32Ty(), printfArgTypes, true); | ||
llvm::Function printfFunc = module.getOrInsertFunction("printf", printfFuncType); | ||
|
||
Vector<llvm::Value> printfArgs; | ||
printfArgs.pushBack(helloWorldStr); | ||
printfArgs.pushBack(calcResult); | ||
builder.createCall(printfFunc, printfArgs); | ||
|
||
builder.createRet(builder.getInt32(0)); | ||
|
||
assert !llvm::verifyFunction(func); | ||
string output; | ||
assert !llvm::verifyModule(module, &output); | ||
|
||
printf("%s", module.print()); | ||
|
||
llvm::PassBuilderOptions passBuilderOptions; | ||
//llvm::PassBuilder passBuilder = llvm::PassBuilder(module, passBuilderOptions); | ||
Reader reader = Reader("./test.spice"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
public type Driveable interface { | ||
public p drive(int); | ||
public f<bool> isDriving(); | ||
import "std/type/result"; | ||
import "std/type/error"; | ||
|
||
type FilePtr alias byte*; | ||
public type File struct { | ||
FilePtr* filePtr | ||
} | ||
|
||
#[test] | ||
f<bool> testDriveable() { | ||
return true; | ||
// Link external functions | ||
ext f<FilePtr*> fopen(string, string); | ||
|
||
public f<Result<File>> openFile(string path, string mode) { | ||
FilePtr* fp = fopen(path, mode); | ||
File file = File{fp}; | ||
return fp != nil<FilePtr*> ? ok(file) : err(file, Error("Failed to open file")); | ||
} |
1 change: 1 addition & 0 deletions
1
src-bootstrap/ast/AbstractASTVisitor.spice → src-bootstrap/ast/abstract-ast-visitor.spice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// Std imports | ||
import "std/type/any"; | ||
|
||
public type IAbstractAstVisitor interface { | ||
|
6 changes: 3 additions & 3 deletions
6
src-bootstrap/ast/ASTBuilder.spice → src-bootstrap/ast/ast-builder.spice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src-bootstrap/CompilerPass.spice → src-bootstrap/compiler-pass.spice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
src-bootstrap/exception/CliError.spice → src-bootstrap/exception/cli-error.spice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src-bootstrap/exception/LinkerError.spice → src-bootstrap/exception/linker-error.spice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
...tstrap/global/GlobalResourceManager.spice → ...trap/global/global-resource-manager.spice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
src-bootstrap/generator/generator.spice → src-bootstrap/irgenerator/ir-generator.spice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
// Imports | ||
// Std imports | ||
|
||
// Own imports | ||
|
||
public type Generator struct { | ||
|
||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.