Added ability to define multiple functions (without parameters) and
[zilutils.git] / zilasm / compiler.h
1 /*
2  * compiler.h -- part of ZilUtils/ZilAsm
3  *
4  * Copyright (C) 2020 Jason Self <j@jxself.org>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as
8  * published by the Free Software Foundation, either version 3 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>
18  *
19  * SPDX-License-Identifier: AGPL-3.0-or-later
20  */
21 #ifndef ZILASM_COMPILER
22 #define ZILASM_COMPILER
23
24
25 typedef struct
26 {
27         int todo;
28 } Opcode_dict;
29
30
31
32 struct String_Table_Elem
33 {
34         string value;                   // value in ASCII format
35         int index;
36 };
37
38
39 class CCompiler
40 {
41 public:
42         CCompiler();
43         int assembly();
44         void fill_config(void);
45         void get_arguments(int argc, char *argv[], char *envp[]);
46         char *get_output_file_name();
47         CParser parser;
48
49 private:
50         char *m_output_file;
51         list < String_Table_Elem > m_string_table;
52         int m_code_size;
53
54         char *build_output_filename(const char basename[], const char *suffix);
55         void fill_zserial(void);
56         void new_file_suffix(char *result, size_t maxlen, const char *src,
57                 const char *newsuffix);
58         void output_code_section();
59         void output_function_table(FILE *file);
60         void parse_intarg(int *dest, const char name[], int min, int max,
61                 int defval);
62         void parse_zserial(void);
63         void print_usage(int failed);
64         void print_version();
65         void wrong_arg(const char *err, ...);
66 };
67
68 enum
69 {
70         FAIL = -1, OK = 0, NEED_RESTART = 1
71 };
72
73 #endif