begin getting ready to emit C
This commit is contained in:
parent
e1f1bbcbb8
commit
2d76d34bc7
10
src/main.cc
10
src/main.cc
@ -38,12 +38,20 @@ bool preprocess(const char * input_fname)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void emit_c(Node * node)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
bool preprocess_successful = preprocess(argv[1]);
|
bool preprocess_successful = preprocess(argv[1]);
|
||||||
if (preprocess_successful)
|
if (preprocess_successful)
|
||||||
{
|
{
|
||||||
parse(preprocessed_fname);
|
Node * node = parse(preprocessed_fname);
|
||||||
|
if (node != nullptr)
|
||||||
|
{
|
||||||
|
emit_c(node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* Clean up temporary files. */
|
/* Clean up temporary files. */
|
||||||
if (preprocessed_fname_created)
|
if (preprocessed_fname_created)
|
||||||
|
@ -11,21 +11,23 @@ std::unordered_set<std::string> type_names;
|
|||||||
extern FILE * yyin;
|
extern FILE * yyin;
|
||||||
|
|
||||||
static const char * input_fname;
|
static const char * input_fname;
|
||||||
|
static Node * translation_unit_node = nullptr;
|
||||||
|
|
||||||
void parse(const char * filename)
|
Node * parse(const char * filename)
|
||||||
{
|
{
|
||||||
input_fname = filename;
|
input_fname = filename;
|
||||||
yyin = fopen(filename, "r");
|
yyin = fopen(filename, "r");
|
||||||
if (yyin == NULL)
|
if (yyin == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error opening \"%s\"\n", filename);
|
fprintf(stderr, "Error opening \"%s\"\n", filename);
|
||||||
return;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (yyparse() != 0)
|
if (yyparse() != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Parsing error\n");
|
fprintf(stderr, "Parsing error\n");
|
||||||
return;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
return translation_unit_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char * read_file(const char * filename, size_t * length)
|
static char * read_file(const char * filename, size_t * length)
|
||||||
@ -253,3 +255,8 @@ bool is_type_name(const std::string & type_name)
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_translation_unit_node(Node * _translation_unit_node)
|
||||||
|
{
|
||||||
|
translation_unit_node = _translation_unit_node;
|
||||||
|
}
|
||||||
|
@ -10,9 +10,10 @@
|
|||||||
|
|
||||||
extern std::unordered_set<std::string> type_names;
|
extern std::unordered_set<std::string> type_names;
|
||||||
|
|
||||||
void parse(const char * filename);
|
Node * parse(const char * filename);
|
||||||
void handle_parse_error(const char * str, const YYLTYPE * yylloc);
|
void handle_parse_error(const char * str, const YYLTYPE * yylloc);
|
||||||
void observe_type_name(const Node * node);
|
void observe_type_name(const Node * node);
|
||||||
bool is_type_name(const std::string & type_name);
|
bool is_type_name(const std::string & type_name);
|
||||||
|
void set_translation_unit_node(Node * _translation_unit_node);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1225,11 +1225,15 @@ primary_expressions
|
|||||||
;
|
;
|
||||||
|
|
||||||
translation_unit
|
translation_unit
|
||||||
: external_declaration { $$ = $1; }
|
: external_declaration {
|
||||||
|
$$ = $1;
|
||||||
|
set_translation_unit_node($$);
|
||||||
|
}
|
||||||
| translation_unit external_declaration {
|
| translation_unit external_declaration {
|
||||||
$$ = new Node(NODE_TYPE_LIST);
|
$$ = new Node(NODE_TYPE_LIST);
|
||||||
$$->list->push_back($1);
|
$$->list->push_back($1);
|
||||||
$$->list->push_back($2);
|
$$->list->push_back($2);
|
||||||
|
set_translation_unit_node($$);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user