about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBaitinq <[email protected]>2025-06-03 22:53:03 +0200
committerBaitinq <[email protected]>2025-06-03 22:57:40 +0200
commit08abe6f88042d3f734453e47e4a410391fd4e9f9 (patch)
treef1f2f7fad6368eb26cde09ac5d712cf536fde28f
parentBootstrap: Parser: Add enough implementation to parse example -2 (diff)
downloadpry-lang-08abe6f88042d3f734453e47e4a410391fd4e9f9.tar.gz
pry-lang-08abe6f88042d3f734453e47e4a410391fd4e9f9.tar.bz2
pry-lang-08abe6f88042d3f734453e47e4a410391fd4e9f9.zip
Bootstrap: Codegen: Start implementation
-rw-r--r--src/bootstrap/codegen.src43
-rw-r--r--src/bootstrap/llvm.src14
-rw-r--r--src/bootstrap/main.src6
3 files changed, 63 insertions, 0 deletions
diff --git a/src/bootstrap/codegen.src b/src/bootstrap/codegen.src
new file mode 100644
index 0000000..e4d3102
--- /dev/null
+++ b/src/bootstrap/codegen.src
@@ -0,0 +1,43 @@
+import "llvm.src";
+
+let codegen = struct {
+	llvm_module: *void,
+	llvm_context: *void,
+	builder: *void,
+};
+
+let codegen_init = (alloc: *arena) => *codegen {
+	LLVMInitializeX86TargetInfo();
+	LLVMInitializeX86TargetMC();
+	LLVMInitializeX86Target();
+	LLVMInitializeX86AsmPrinter();
+	LLVMInitializeX86AsmParser();
+
+	let module = LLVMModuleCreateWithName("module");
+        let context = LLVMGetGlobalContext();
+        let builder = LLVMCreateBuilder();
+	
+	let c = cast(*codegen, arena_alloc(alloc, sizeof(codegen)));
+	
+	(*c).llvm_module = module;
+	(*c).llvm_context = context;
+	(*c).builder = builder;
+
+	return c;
+};
+
+let codegen_generate = (c: *codegen) => i64 {
+	return 0;
+};
+
+let codegen_compile = (c: *codegen) => i64 {
+	LLVMDumpModule((*c).llvm_module);
+	return 0;
+};
+
+let codegen_deinit = (c: *codegen) => void {
+        LLVMDisposeModule((*c).llvm_module);
+        LLVMShutdown();
+        LLVMDisposeBuilder((*c).builder);
+	return;
+};
diff --git a/src/bootstrap/llvm.src b/src/bootstrap/llvm.src
new file mode 100644
index 0000000..70a5065
--- /dev/null
+++ b/src/bootstrap/llvm.src
@@ -0,0 +1,14 @@
+extern LLVMInitializeX86TargetInfo = () => void;
+extern LLVMInitializeX86TargetMC = () => void;
+extern LLVMInitializeX86Target = () => void;
+extern LLVMInitializeX86AsmPrinter = () => void;
+extern LLVMInitializeX86AsmParser = () => void;
+
+extern LLVMModuleCreateWithName = (*i8) => *void;
+extern LLVMGetGlobalContext = () => *void;
+extern LLVMCreateBuilder = () => *void; /* TODO: Create types */
+extern LLVMDisposeModule = (*void) => void;
+extern LLVMShutdown = () => void;
+extern LLVMDisposeBuilder = (*void) => void;
+
+extern LLVMDumpModule = (*void) => void;
diff --git a/src/bootstrap/main.src b/src/bootstrap/main.src
index 3ff89b3..23defd1 100644
--- a/src/bootstrap/main.src
+++ b/src/bootstrap/main.src
@@ -16,6 +16,7 @@ let slice = struct {
 
 import "tokenizer.src";
 import "parser.src";
+import "codegen.src";
 
 let read_file = (filename: *i8, alloc: *arena) => slice {
 	let file = fopen(filename, "r");
@@ -57,6 +58,11 @@ let main = (argc: i64, argv: **i8) => i64 {
 	let p = parser_init(cast(*token, ts.data), ts.data_len, alloc);
 	let ns = parse(p);
 
+	let c = codegen_init(alloc);
+	let res = codegen_generate(c);
+	let res = codegen_compile(c);
+	codegen_deinit(c);
+
 	arena_free(alloc);
 
 	return 0;