Added ability to define multiple functions (without parameters) and
[zilutils.git] / zilasm / compiler.h
diff --git a/zilasm/compiler.h b/zilasm/compiler.h
new file mode 100644 (file)
index 0000000..a885819
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * compiler.h -- part of ZilUtils/ZilAsm
+ *
+ * Copyright (C) 2020 Jason Self <j@jxself.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+#ifndef ZILASM_COMPILER
+#define ZILASM_COMPILER
+
+
+typedef struct
+{
+       int todo;
+} Opcode_dict;
+
+
+
+struct String_Table_Elem
+{
+       string value;                   // value in ASCII format
+       int index;
+};
+
+
+class CCompiler
+{
+public:
+       CCompiler();
+       int assembly();
+       void fill_config(void);
+       void get_arguments(int argc, char *argv[], char *envp[]);
+       char *get_output_file_name();
+       CParser parser;
+
+private:
+       char *m_output_file;
+       list < String_Table_Elem > m_string_table;
+       int m_code_size;
+
+       char *build_output_filename(const char basename[], const char *suffix);
+       void fill_zserial(void);
+       void new_file_suffix(char *result, size_t maxlen, const char *src,
+               const char *newsuffix);
+       void output_code_section();
+       void output_function_table(FILE *file);
+       void parse_intarg(int *dest, const char name[], int min, int max,
+               int defval);
+       void parse_zserial(void);
+       void print_usage(int failed);
+       void print_version();
+       void wrong_arg(const char *err, ...);
+};
+
+enum
+{
+       FAIL = -1, OK = 0, NEED_RESTART = 1
+};
+
+#endif