summaryrefslogtreecommitdiff
path: root/src/precedent.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/precedent.c')
-rw-r--r--src/precedent.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/precedent.c b/src/precedent.c
index 44ca1ed..0b04b33 100644
--- a/src/precedent.c
+++ b/src/precedent.c
@@ -8,11 +8,13 @@
#include "hashtable.h"
#include "parse.h"
#include "eval.h"
+#include "compile.h"
int main(int argc, char** argv) {
clock_t initTime = clock();
char visual = 0;
char debug = 0;
+ char compiled = 0;
if (argc > 1) {
for (int i = 1; i < argc; i++) {
if (strcmp("--version", argv[i]) == 0) {
@@ -31,6 +33,9 @@ int main(int argc, char** argv) {
else if (strcmp("--debug", argv[i]) == 0) {
debug = 1;
}
+ else if (strcmp("--compiled", argv[i]) == 0) {
+ compiled = 1;
+ }
}
}
else {
@@ -59,17 +64,24 @@ int main(int argc, char** argv) {
write_symbol_visual(finalSymbol, 0);
printf("--END VISUALIZATION--\n");
}
- hashtable_t* rootTable = init_hashtable(500, NULL);
- clock_t setupTime = clock();
- sym_t* sym = eval(finalSymbol, rootTable);
- clock_t evalTime = clock();
- if (debug) {
- printf("time taken to set up environment: %.5f secs\n", (float)(setupTime - initTime) / (float)CLOCKS_PER_SEC);
- printf("time taken to execute program: %.5f secs\n", ((float)(evalTime - setupTime) - initTime) / (float)CLOCKS_PER_SEC);
+ if (compiled) {
+ char* res = compile_to_asm(finalSymbol);
+ destroy_sym_tree(finalSymbol);
+ printf("%s\n", res);
+ }
+ else {
+ hashtable_t* rootTable = init_hashtable(500, NULL);
+ clock_t setupTime = clock();
+ sym_t* sym = eval(finalSymbol, rootTable);
+ clock_t evalTime = clock();
+ if (debug) {
+ printf("time taken to set up environment: %.5f secs\n", (float)(setupTime - initTime) / (float)CLOCKS_PER_SEC);
+ printf("time taken to execute program: %.5f secs\n", ((float)(evalTime - setupTime) - initTime) / (float)CLOCKS_PER_SEC);
+ }
+ destroy_sym_tree(finalSymbol);
+ destroy_sym(sym);
+ destroy_hashtable(rootTable);
}
- destroy_sym_tree(finalSymbol);
- destroy_sym(sym);
- destroy_hashtable(rootTable);
return 0;
}
char* read_file(char* path) {