2 * parser.h -- part of ZilUtils/ZilAsm
4 * Copyright (C) 2016, 2019, 2020 Jason Self <j@jxself.org>
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.
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.
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/>
19 * SPDX-License-Identifier: AGPL-3.0-or-later
23 #define ZILASM_PARSER 1
32 #define MAX_NUMBER_OF_INSTRUCTIONS 65536
36 Function() : index(0), address(0), number_of_local_variables(0)
42 unsigned number_of_local_variables;
51 void calculate_function_addresses();
52 unsigned get_number_of_instructions();
53 ZMemblock **get_codes();
55 unsigned output_codes(ZMemblock *zmem_code);
57 void add_function(const char *s);
58 unsigned m_current_line_number;
59 unsigned m_current_address;
62 map <string, Function> m_functions;
63 vector<unsigned> m_function_addresses;
64 string m_start_function_name;
67 unsigned g_number_of_instructions;// = 0;
70 ZMemblock(*g_codes[MAX_NUMBER_OF_INSTRUCTIONS]);
72 CDirectives *m_pdirectives;
73 vector<string> m_calls; // contains functions names' if current instruction is call/icall or empty string otherwise
75 string build_error_message(const char *message);
76 void checksep(const char *p);
77 void fatal_error(const char *errmsg);
78 int parse_line(const char *p);
79 const char *pass_spaces(const char *p);
80 int read_instructions_parameter(char *a, string& str);
81 int read_instructions_parameter2(char *a, string& str);
82 int tryparse_directive(const char *p);
83 int tryparse_startup_directive(const char *p);
85 int tryparse_name(const char *a);
86 int tryparse_label(const char *a, const char *b, const char *c);
87 int tryparse_instruction(const char *a);
90 //void init_parser ();
92 //int parse_file();// const char *filename);
94 //extern unsigned g_number_of_instructions;
97 //extern ZMemblock (*g_codes[MAX_NUMBER_OF_INSTRUCTIONS]);
99 struct Parsing_Context
101 string current_directory;
102 string current_file_name;
105 extern stack<Parsing_Context> g_parsing_contexts;
106 //extern unsigned g_currentLineNumber;
107 //extern bool g_haveErrors;
109 #endif /* ifndef ZILASM_PARSER */