X-Git-Url: https://jxself.org/git/?p=zilutils.git;a=blobdiff_plain;f=zilasm%2Fparser.h;h=2ed9ae7f0d6d9f840d549df7ccbb95527f911050;hp=c708f4d3bf75b5a3b0037b6d9a9eaafda1a3776d;hb=HEAD;hpb=37d32bd49e745a5c1686b6495f60172b24222361 diff --git a/zilasm/parser.h b/zilasm/parser.h index c708f4d..e867439 100644 --- a/zilasm/parser.h +++ b/zilasm/parser.h @@ -1,7 +1,7 @@ /* * parser.h -- part of ZilUtils/ZilAsm * - * Copyright (C) 2016 Jason Self + * Copyright (C) 2016, 2019, 2020 Jason Self * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -22,6 +22,88 @@ #ifndef ZILASM_PARSER #define ZILASM_PARSER 1 -int parse_file(const char *filename); -#endif /* ifndef ZILASM_PARSER */ +struct Instruction +{ + Byte *pCodes; + int size; +}; + +#define MAX_NUMBER_OF_INSTRUCTIONS 65536 + +struct Function +{ + Function() : index(0), address(0), number_of_local_variables(0) + { + } + + unsigned index; + unsigned address; + unsigned number_of_local_variables; +}; + + +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 m_functions; + vector 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 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 g_parsing_contexts; +//extern unsigned g_currentLineNumber; +//extern bool g_haveErrors; + +#endif /* ifndef ZILASM_PARSER */