/*
* parser.h -- part of ZilUtils/ZilAsm
*
- * Copyright (C) 2016, 2019 Jason Self <j@jxself.org>
+ * Copyright (C) 2016, 2019, 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
int size;
};
-void init_parser ();
+#define MAX_NUMBER_OF_INSTRUCTIONS 65536
+
+struct Function
+{
+ Function() : index(0), address(0), number_of_local_variables(0)
+ {
+ }
-int parse_file (const char *filename);
+ unsigned index;
+ unsigned address;
+ unsigned number_of_local_variables;
+};
-extern unsigned g_numberOfInstructions;
-#define MAX_NUMBER_OF_INSTRUCTIONS 65536
-extern ZMemblock (*g_codes[MAX_NUMBER_OF_INSTRUCTIONS]);
+class CParser
+{
+public:
+ CParser();
+ ~CParser();
+ void calculate_function_addresses();
+ unsigned get_number_of_instructions();
+ ZMemblock **get_codes();
+ bool have_errors();
+ unsigned output_codes(ZMemblock *zmem_code);
+ int parse_file();
+ void add_function(const char *s);
+ unsigned m_current_line_number;
+ unsigned m_current_address;
+
+
+ map <string, Function> m_functions;
+ vector<unsigned> m_function_addresses;
+ string m_start_function_name;
+
+private:
+ unsigned g_number_of_instructions;// = 0;
+
+
+ ZMemblock(*g_codes[MAX_NUMBER_OF_INSTRUCTIONS]);
+ bool g_haveErrors;
+ CDirectives *m_pdirectives;
+ vector<string> m_calls; // contains functions names' if current instruction is call/icall or empty string otherwise
+
+ string build_error_message(const char *message);
+ void checksep(const char *p);
+ void fatal_error(const char *errmsg);
+ int parse_line(const char *p);
+ const char *pass_spaces(const char *p);
+ int read_instructions_parameter(char *a, string& str);
+ int read_instructions_parameter2(char *a, string& str);
+ int tryparse_directive(const char *p);
+ int tryparse_startup_directive(const char *p);
+
+ int tryparse_name(const char *a);
+ int tryparse_label(const char *a, const char *b, const char *c);
+ int tryparse_instruction(const char *a);
+};
+
+//void init_parser ();
+
+//int parse_file();// const char *filename);
+
+//extern unsigned g_number_of_instructions;
+
+
+//extern ZMemblock (*g_codes[MAX_NUMBER_OF_INSTRUCTIONS]);
+
+struct Parsing_Context
+{
+ string current_directory;
+ string current_file_name;
+};
+
+extern stack<Parsing_Context> g_parsing_contexts;
+//extern unsigned g_currentLineNumber;
+//extern bool g_haveErrors;
#endif /* ifndef ZILASM_PARSER */