G

G Programming Language
git clone http://git.omkov.net/G
Log | Tree | Refs | README | Download

AuthorJakob Wakeling <[email protected]>
Date2022-05-03 07:23:38
Commitac4740cf8284bb5bc7de65772e1c5452805adfaa
Parent1248335294f943f0ef91b8ce334e9a17b1a94cc1

Merge compile.c into main.c

Diffstat

D src/compile.c | 47 -----------------------------------------------
D src/compile.h | 17 -----------------
M src/main.c | 38 ++++++++++++++++++++++++++++++++++++++

3 files changed, 38 insertions, 64 deletions

diff --git a/src/compile.c b/src/compile.c
deleted file mode 100644
index 2beb0eb..0000000
--- a/src/compile.c
+++ /dev/null
@@ -1,47 +0,0 @@
-// compile.h
-// Compiler source file for G
-// Copyright (C) 2021, Jakob Wakeling
-// All rights reserved.
-
-#include "analyse.h"
-#include "compile.h"
-#include "init.h"
-#include "llvm.h"
-#include "parse.h"
-#include "util/error.h"
-#include "util/util.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-
-bool bflag = false, Bflag = false, cflag = false, Eflag = false;
-bool dpflag = false, daflag = false;
-
-void compile(const char * file, char *src, UINT len) {
-	initialise();
-	
-	lex l = lex_init(file, src, len);
-	if (Eflag) { lex_debug(&l); goto end; }
-	
-	ast *a = parse(&l);
-	if (dpflag) { ast_print(a, 0); goto end; }
-	
-	analyse(a);
-	if (daflag) { ast_print(a, 0); goto end; }
-	
-	llvm(a);
-	
-	end:; return;
-}
-
-void compile_file(const char *file) {
-	FILE *fi; char *fb; size_t fl;
-	
-	if (!(fi = fopen(file, "r"))) { error(1, "%s: %s", file, serr()); }
-	fseek(fi, 0, SEEK_END); fl = ftell(fi); rewind(fi);
-	
-	fb = malloc((fl + 1) * sizeof (*fb));
-	fread(fb, 1, fl, fi); fb[fl] = 0; fclose(fi);
-	
-	compile(file, fb, fl); free(fb); return;
-}
diff --git a/src/compile.h b/src/compile.h
deleted file mode 100644
index 97acc73..0000000
--- a/src/compile.h
+++ /dev/null
@@ -1,17 +0,0 @@
-// compile.h
-// Compiler header file for G
-// Copyright (C) 2021, Jakob Wakeling
-// All rights reserved.
-
-#ifndef G_COMPILE_H_DSDZQ0ZM
-#define G_COMPILE_H_DSDZQ0ZM
-
-#include "util/util.h"
-
-extern bool bflag, Bflag, cflag, Eflag;
-extern bool dpflag, daflag;
-
-extern void compile(const char *file, char *src, UINT len);
-extern void compile_file(const char *file);
-
-#endif // G_COMPILE_H_DSDZQ0ZM
diff --git a/src/main.c b/src/main.c
index 5d5ea95..db50480 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3,7 +3,10 @@
 // Copyright (C) 2021, Jakob Wakeling
 // All rights reserved.
 
-#include "compile.h"
+#include "analyse.h"
+#include "init.h"
+#include "llvm.h"
+#include "parse.h"
 #include "util/error.h"
 #include "util/optget.h"
 #include "util/util.h"
@@ -25,6 +28,12 @@ static char *aw[] = {
 	"g", "/home/deus/Workspace/G/examples/main.g", NULL
 };
 
+static bool bflag = false, Bflag = false, cflag = false, Eflag = false;
+static bool dpflag = false, daflag = false;
+
+static void compile(const char *file, char *src, UINT len);
+static void compile_file(const char *file);
+
 static void hlp(void);
 static void ver(void);
 
@@ -51,6 +60,35 @@ int main(int ac, char *av[]) { A0 = av[0];
 	return 0;
 }
 
+static void compile(const char * file, char *src, UINT len) {
+	initialise();
+	
+	lex l = lex_init(file, src, len);
+	if (Eflag) { lex_debug(&l); goto end; }
+	
+	ast *a = parse(&l);
+	if (dpflag) { ast_print(a, 0); goto end; }
+	
+	analyse(a);
+	if (daflag) { ast_print(a, 0); goto end; }
+	
+	llvm(a);
+	
+	end:; return;
+}
+
+static void compile_file(const char *file) {
+	FILE *fi; char *fb; size_t fl;
+	
+	if (!(fi = fopen(file, "r"))) { error(1, "%s: %s", file, serr()); }
+	fseek(fi, 0, SEEK_END); fl = ftell(fi); rewind(fi);
+	
+	fb = malloc((fl + 1) * sizeof (*fb));
+	fread(fb, 1, fl, fi); fb[fl] = 0; fclose(fi);
+	
+	compile(file, fb, fl); free(fb); return;
+}
+
 /* Print help information. */
 static void hlp(void) {
 	puts("G - G Programming Language\n");