blob: aa75f79e64fa9055cdbf1557e8a9f006442f741a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "code-generation.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
static void generate_global_variable(CcmmcAst *global_decl, CcmmcState *state)
{
fputs("\t.data\n", state->asm_output);
for (CcmmcAst *var_decl = global_decl->child->right_sibling;
var_decl != NULL; var_decl = var_decl->right_sibling) {
CcmmcSymbol *var_sym = ccmmc_symbol_table_retrieve(state->table,
var_decl->value_id.name);
switch (var_decl->value_id.kind) {
case CCMMC_KIND_ID_NORMAL:
fprintf(state->asm_output, "\t.comm %s, 4\n", var_sym->name);
break;
case CCMMC_KIND_ID_ARRAY:
break;
case CCMMC_KIND_ID_WITH_INIT:
break;
default:
assert(false);
}
}
}
static void generate_function(CcmmcAst *funcion, CcmmcState *state)
{
}
static void generate_program(CcmmcState *state)
{
for (CcmmcAst *global_decl = state->ast->child; global_decl != NULL;
global_decl = global_decl->right_sibling) {
switch (global_decl->value_decl.kind) {
case CCMMC_KIND_DECL_VARIABLE:
generate_global_variable(global_decl, state);
break;
case CCMMC_KIND_DECL_FUNCTION:
generate_function(global_decl, state);
break;
case CCMMC_KIND_DECL_FUNCTION_PARAMETER:
case CCMMC_KIND_DECL_TYPE:
default:
assert(false);
}
}
}
void ccmmc_code_generation(CcmmcState *state)
{
state->table->this_scope = NULL;
state->table->current = NULL;
ccmmc_symbol_table_reopen_scope(state->table);
generate_program(state);
}
// vim: set sw=4 ts=4 sts=4 et:
|