diff options
| author | Kai Gunger <kgunger12@gmail.com> | 2026-02-28 17:49:43 -0500 |
|---|---|---|
| committer | Kai Gunger <kgunger12@gmail.com> | 2026-02-28 17:49:43 -0500 |
| commit | 411733084c3f64872657e6803ecf4380c907626e (patch) | |
| tree | 78d9e926d6211034178c6c2ad2ac17e5822a16c6 | |
| parent | 3b0dd26823b62e13bf38376f0a0211ce7861c150 (diff) | |
[tnslc] flags to control stages of comporigin
| -rw-r--r-- | tnslc/compile/codegen.tnsl | 41 | ||||
| -rw-r--r-- | tnslc/tnslc.tnsl | 60 |
2 files changed, 88 insertions, 13 deletions
diff --git a/tnslc/compile/codegen.tnsl b/tnslc/compile/codegen.tnsl index ae67442..05d0fb7 100644 --- a/tnslc/compile/codegen.tnsl +++ b/tnslc/compile/codegen.tnsl @@ -4,18 +4,26 @@ ;/ ;/ -/; generate (~utils.File fin, fout) +/; parse_tree(~utils.File fin) # Parse files into AST parse.Node ast = parse.generate_ast(fin) ast.update_children() + # Print parse tree parse.print_ast(~ast) + ast.end() +;/ + +/; mod_tree(~utils.File fin) + # Parse files into AST + parse.Node ast = parse.generate_ast(fin) + ast.update_children() + # Create output buffer CompBuf buffer buffer.init() - # Transform into a module tree Module mod mod.init(~ast, ~buffer) _gen_prims(~mod) @@ -27,6 +35,31 @@ mod.print() + # Free all structs + mod.end() + buffer.end() + ast.end() +;/ + +/; generate (~utils.File fin, fout) + # Parse files into AST + parse.Node ast = parse.generate_ast(fin) + ast.update_children() + + # Create output buffer + CompBuf buffer + buffer.init() + + # Transform into a module tree + Module mod + mod.init(~ast, ~buffer) + _gen_prims(~mod) + mod.update_children() + mod.collect_methods(~ast) + + # Compile code + mod.compile(~buffer) + # Write assembly to output file fout.create() buffer.write_to(fout) @@ -38,6 +71,7 @@ ast.end() ;/ +# Generate a primitive type with the specified size and specified name /; _gen_prim(~Module m, int size, ~uint8 id) ~Module mds = m`._create_methods(id) @@ -53,6 +87,9 @@ m`.structs.push(~s) ;/ +# This function generates the generic language primitives on +# the root module so that resolution will work when creating +# a variable or struct /; _gen_prims (~Module m) # One byte prims diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl index e95a63b..d49bcc9 100644 --- a/tnslc/tnslc.tnsl +++ b/tnslc/tnslc.tnsl @@ -5,10 +5,20 @@ ~uint8 DEFAULT_FOUT = "out.asm\0" ~uint8 USAGE = " -TNSLC v0.6.0 (C) 2024 CircleShift (MPL 2.0) +TNSLC v0.7.0 (C) 2026 CircleShift (MPL 2.0) usage: - tnslc (file in) [file out] + tnslc [options] (file in) + +options: + -o [output file] + Sets the file to output asm code to (default is \"out.asm\") + + -p + Print the parse tree and exit without compiling + + -m + Print the module tree and exit without compiling \0" @@ -25,20 +35,48 @@ usage: _printf(USAGE) return 1 ;/ - + utils.File fin, fout - fin.init(argv{1}) - - /; if (argc > 2) - fout.init(argv{2}) - ;; else - fout.init(DEFAULT_FOUT) + int arg_counter = 1 + int mode = 0 + ~uint8 first_str = argv{arg_counter} + + /; if (first_str{0} == '-') + /; if (utils.strcmp(argv{arg_counter}, "-p\0") == true) + mode = 1 + arg_counter++ + ;; else if (utils.strcmp(argv{arg_counter}, "-m\0") == true) + mode = 2 + arg_counter++ + ;; else if (utils.strcmp(argv{arg_counter}, "-o\0") == true) + arg_counter++ + /; if (arg_counter !< argc) + _printf(USAGE) + return 1 + ;/ + fout.init(argv{arg_counter}) + ;; else + fout.init(DEFAULT_FOUT) + ;/ ;/ - compile.generate(~fin, ~fout) + /; if (arg_counter !< argc) + _printf(USAGE) + return 1 + ;/ + + fin.init(argv{arg_counter}) + + /; if (mode == 0) + compile.generate(~fin, ~fout) + fout.end() + ;; else if (mode == 1) + compile.parse_tree(~fin) + ;; else if (mode == 2) + compile.mod_tree(~fin) + ;/ fin.end() - fout.end() return 0 ;/ |