summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2985d77)
raw | patch | inline | side by side (parent: 2985d77)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Sun, 13 Aug 2017 12:07:17 +0000 (15:07 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Sun, 13 Aug 2017 12:07:17 +0000 (15:07 +0300) |
12 files changed:
diff --git a/Test.obn b/Test.obn
index 82fbedbbc7c705e6e6a7a46f3cfb2a2e3c34c7d2..f76917867cb0d1bcb880b7e0cf655f116919947f 100644 (file)
--- a/Test.obn
+++ b/Test.obn
i : SHORTINT;
s : SET;
+PROCEDURE X;
+END X;
+
BEGIN
i := SHORT(12345);
END Test.
diff --git a/include/oberon.h b/include/oberon.h
index b2f24b4f2750fa0c3296cbf703bdaa2ce04fd83d..2f51a775393c8f68488e6b2d3d8d7d8913274f02 100644 (file)
--- a/include/oberon.h
+++ b/include/oberon.h
oberon_compile_module(oberon_context_t * ctx, const char * code);
extern void
-oberon_generate_code(oberon_context_t * ctx);
-
-extern void
-oberon_generator_dump(oberon_context_t * ctx, char * path);
-
-extern void *
-oberon_generator_get_procedure(oberon_context_t * ctx, const char * name);
-
-extern void *
-oberon_generator_get_var(oberon_context_t * ctx, const char * name);
+oberon_set_out_directory(oberon_context_t * ctx, const char * path);
#endif // OBERON_H
diff --git a/obn-compile.sh b/obn-compile.sh
index f89bf035f3a57daddffd3a16a00ec9198460c552..c02d17844da1710aead79959c210e33962572e5c 100755 (executable)
--- a/obn-compile.sh
+++ b/obn-compile.sh
set -e
-rm -rf classes
-rm -f *.j *.jad
-mkdir -p classes
+rm -rf classes tmp
+mkdir -p classes tmp
-./a.out $1
+./a.out -d tmp $1
-jasmin -d classes *.j
+jasmin -d classes tmp/*.j
javac -d classes rtl/*.java
diff --git a/obn-dev-test.sh b/obn-dev-test.sh
index 424cf4e63190019d4b97d3b1689d85e4e9402d4d..5d49ab893630ed4a42d9c7afca088db6b875320b 100755 (executable)
--- a/obn-dev-test.sh
+++ b/obn-dev-test.sh
# -a -- for asm as comments
# -noinner
-jad -o -b -noinner classes/*
+jad -d tmp -o -b -noinner classes/*
./obn-run.sh Test
diff --git a/obn-gdb-compile.sh b/obn-gdb-compile.sh
--- a/obn-gdb-compile.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-set -e
-
-exec gdb ./a.out $*
index b404fca454e4d62bd85c1ba6471bce291c0abe1b..8d966cbe4877ac404487fbd308d8bc2d5a359deb 100644 (file)
abscname = "SYSTEM$FRAME";
cname = jvm_get_field_full_name_safe(proc);
cname = new_string("%s$FRAME", cname);
- class = jvm_create_class(cname);
+ class = jvm_create_class(proc -> gen_proc -> class -> dir, cname);
fp = class -> fp;
class -> full_name = cname;
index 4aee145479330f49cb12751047bf244bc14b72a4..1d1220d0ecac4b99f7e81d2eee7e96deb241a54e 100644 (file)
}
struct gen_class *
-jvm_create_class(char * full_name)
+jvm_create_class(const char * dir, char * full_name)
{
struct gen_class * class = GC_MALLOC(sizeof *class);
memset(class, 0, sizeof *class);
- char * fname = new_string("%s.j", full_name);
+ char * fname = new_string("%s/%s.j", dir, full_name);
class -> full_name = new_string(full_name);
class -> fp = fopen(fname, "w");
- assert(class -> fp);
+ class -> dir = new_string(dir);
+
+ if(class -> fp == NULL)
+ {
+ gen_error("unable to create file %s", fname);
+ }
return class;
}
index 2b5911cdd23045b5bf93f3ebbe7ec44f35f991ff..b6084c5ee6fd095e2f92318945c9d943261eb7ff 100644 (file)
struct gen_class *
-jvm_create_class(char * full_name);
+jvm_create_class(const char * dir, char * full_name);
void
jvm_destroy_class(struct gen_class * class);
index 5b45cc166bca184d32d0640a24f9f90a016617ef..2456aa79cd9bafd5a6b4e71f26c5715ea250e9e8 100644 (file)
memset(gen_context, 0, sizeof *gen_context);
ctx -> gen_context = gen_context;
+ gen_context -> dir = ".";
}
void
}
static void
-oberon_generate_procedure_class(oberon_type_t * proc)
+oberon_generate_procedure_class(const char * dir, oberon_type_t * proc)
{
FILE * fp;
char * cname;
struct gen_class * class;
cname = jvm_get_class_full_name(proc);
- class = jvm_create_class(cname);
+ class = jvm_create_class(dir, cname);
fp = class -> fp;
fprintf(fp, ".source SYSTEM\n");
}
static void
-oberon_generate_procedure_pointer_class(oberon_object_t * proc)
+oberon_generate_procedure_pointer_class(const char * dir, oberon_object_t * proc)
{
FILE * fp;
char * cname;
struct gen_class * class;
cname = jvm_get_field_full_name_safe(proc);
- class = jvm_create_class(cname);
+ class = jvm_create_class(dir, cname);
abscname = jvm_get_class_full_name(proc -> type);
absdesc = jvm_get_descriptor(proc -> type);
fp = class -> fp;
}
static void
-oberon_generate_record_class(gen_module_t * m, oberon_type_t * rec)
+oberon_generate_record_class(const char * dir, gen_module_t * m, oberon_type_t * rec)
{
char * cname;
struct gen_class * class;
m -> rec_id += 1;
cname = jvm_get_class_full_name(rec);
- class = jvm_create_class(cname);
+ class = jvm_create_class(dir, cname);
fprintf(class -> fp, ".source %s\n", rec -> module -> name);
fprintf(class -> fp, ".class public %s\n", cname);
memset(t, 0, sizeof *t);
type -> gen_type = t;
+ gen_context_t * c;
+ c = ctx -> gen_context;
+
gen_module_t * m;
switch(type -> class)
{
break;
case OBERON_TYPE_RECORD:
m = type -> module -> gen_mod;
- oberon_generate_record_class(m, type);
+ oberon_generate_record_class(c -> dir, m, type);
break;
case OBERON_TYPE_PROCEDURE:
- oberon_generate_procedure_class(type);
+ oberon_generate_procedure_class(c -> dir, type);
break;
default:
gen_error("oberon_generator_init_type: unk calss %i", type -> class);
memset(m, 0, sizeof *m);
mod -> gen_mod = m;
+ gen_context_t * c;
+ c = ctx -> gen_context;
+
struct gen_class * class;
- class = jvm_create_class(mod -> name);
+ class = jvm_create_class(c -> dir, mod -> name);
fprintf(class -> fp, ".source %s\n", mod -> name);
fprintf(class -> fp, ".class %s\n", mod -> name);
m -> class = class;
- ctx -> gen_context -> current_m = m;
+ c -> current_m = m;
}
void
}
else
{
- oberon_generate_procedure_pointer_class(proc);
+ oberon_generate_procedure_pointer_class(p -> class -> dir, proc);
signature = jvm_get_procedure_signature(proc -> type);
}
jvm_generate(p, 2, 0, "invokestatic SYSTEM/HALT(J)V");
}
+void
+oberon_set_out_directory(oberon_context_t * ctx, const char * path)
+{
+ gen_context_t * c;
+
+ c = ctx -> gen_context;
+
+ c -> dir = new_string(path);
+}
index 00c3e50757a2d58a1628dc49110182193c11b899..5e10df4be2e1616ad4b801973eb088a1bbb2f091 100644 (file)
FILE * fp;
gen_proc_t * p;
struct gen_class * base;
+ const char * dir;
};
enum gen_storage
struct gen_context_t
{
gen_module_t * current_m;
+ const char * dir;
};
struct gen_module_t
diff --git a/src/generator.h b/src/generator.h
index 80bab13d0c270e3436effea08c95cd3615ea0f6d..5617e79796ac450128ab6536c7f9c35b7448ad9b 100644 (file)
--- a/src/generator.h
+++ b/src/generator.h
void oberon_generate_trap(oberon_context_t * ctx, int64_t n);
void oberon_generate_halt(oberon_context_t * ctx, int64_t n);
void oberon_generate_return(oberon_context_t * ctx, oberon_expr_t * expr);
+
+void oberon_set_out_directory(oberon_context_t * ctx, const char * path);
diff --git a/src/main.c b/src/main.c
index a97f2d7d71606da039bf0ded4764654dd8b64005..994ae806747dc34788ee8c76e9b247e27dd8202b 100644 (file)
--- a/src/main.c
+++ b/src/main.c
static oberon_context_t * ctx;
static oberon_module_t * mod;
+static const char * module;
+static const char * out_path;
static const char *
import_module(const char * name)
return source;
}
+static void
+init(int argc, char ** argv)
+{
+ int i = 1;
+ out_path = ".";
+
+ if(argc > 2 && strcmp(argv[i], "-d") == 0)
+ {
+ out_path = argv[i + 1];
+ argc -= 2;
+ i += 2;
+ }
+
+ if(argc != 2 || argv[i][0] == '-')
+ {
+ printf("usage: obn [-d out_dir] module\n");
+ exit(1);
+ }
+
+ module = argv[i];
+}
+
int
main(int argc, char ** argv)
{
const char * code;
- if(argc != 2)
- {
- printf("use: %s <module>\n", argv[0]);
- return 1;
- }
+ init(argc, argv);
- code = import_module(argv[1]);
+ code = import_module(module);
ctx = oberon_create_context(import_module);
+ oberon_set_out_directory(ctx, out_path);
+
mod = oberon_compile_module(ctx, code);
oberon_destroy_context(ctx);
+
return 0;
}