* not exactly sure how codegen would work for the C compiler as of yet
* and also I plan to allow inline assembly for the compiler.
*/
-static const char *const asm_instr[] = {
- [INSTR_DONE] = "DONE",
- [INSTR_MUL_F] = "MUL_F",
- [INSTR_MUL_V] = "MUL_V",
- [INSTR_MUL_FV] = "MUL_FV",
- [INSTR_MUL_VF] = "MUL_VF",
- [INSTR_DIV_F] = "DIV",
- [INSTR_ADD_F] = "ADD_F",
- [INSTR_ADD_V] = "ADD_V",
- [INSTR_SUB_F] = "SUB_F",
- [INSTR_SUB_V] = "DUB_V",
- [INSTR_EQ_F] = "EQ_F",
- [INSTR_EQ_V] = "EQ_V",
- [INSTR_EQ_S] = "EQ_S",
- [INSTR_EQ_E] = "EQ_E",
- [INSTR_EQ_FNC] = "ES_FNC",
- [INSTR_NE_F] = "NE_F",
- [INSTR_NE_V] = "NE_V",
- [INSTR_NE_S] = "NE_S",
- [INSTR_NE_E] = "NE_E",
- [INSTR_NE_FNC] = "NE_FNC",
- [INSTR_LE] = "LE",
- [INSTR_GE] = "GE",
- [INSTR_LT] = "LT",
- [INSTR_GT] = "GT",
- [INSTR_LOAD_F] = "FIELD_F",
- [INSTR_LOAD_V] = "FIELD_V",
- [INSTR_LOAD_S] = "FIELD_S",
- [INSTR_LOAD_ENT] = "FIELD_ENT",
- [INSTR_LOAD_FLD] = "FIELD_FLD",
- [INSTR_LOAD_FNC] = "FIELD_FNC",
- [INSTR_ADDRESS] = "ADDRESS",
- [INSTR_STORE_F] = "STORE_F",
- [INSTR_STORE_V] = "STORE_V",
- [INSTR_STORE_S] = "STORE_S",
- [INSTR_STORE_ENT] = "STORE_ENT",
- [INSTR_STORE_FLD] = "STORE_FLD",
- [INSTR_STORE_FNC] = "STORE_FNC",
- [INSTR_STOREP_F] = "STOREP_F",
- [INSTR_STOREP_V] = "STOREP_V",
- [INSTR_STOREP_S] = "STOREP_S",
- [INSTR_STOREP_ENT] = "STOREP_ENT",
- [INSTR_STOREP_FLD] = "STOREP_FLD",
- [INSTR_STOREP_FNC] = "STOREP_FNC",
- [INSTR_RETURN] = "RETURN",
- [INSTR_NOT_F] = "NOT_F",
- [INSTR_NOT_V] = "NOT_V",
- [INSTR_NOT_S] = "NOT_S",
- [INSTR_NOT_ENT] = "NOT_ENT",
- [INSTR_NOT_FNC] = "NOT_FNC",
- [INSTR_IF] = "IF",
- [INSTR_IFNOT] = "IFNOT",
- [INSTR_CALL0] = "CALL0",
- [INSTR_CALL1] = "CALL1",
- [INSTR_CALL2] = "CALL2",
- [INSTR_CALL3] = "CALL3",
- [INSTR_CALL4] = "CALL4",
- [INSTR_CALL5] = "CALL5",
- [INSTR_CALL6] = "CALL6",
- [INSTR_CALL7] = "CALL7",
- [INSTR_CALL8] = "CALL8",
- [INSTR_STATE] = "STATE",
- [INSTR_GOTO] = "GOTO",
- [INSTR_AND] = "AND",
- [INSTR_OR] = "OR",
- [INSTR_BITAND] = "AND",
- [INSTR_BITOR] = "OR"
+static const struct {
+ const char *m; /* menomic */
+ const size_t o; /* operands */
+ const size_t l; /* menomic len */
+} const asm_instr[] = {
+ [INSTR_DONE] = { "DONE" , 0, 4 },
+ [INSTR_MUL_F] = { "MUL_F" , 0, 5 },
+ [INSTR_MUL_V] = { "MUL_V" , 0, 5 },
+ [INSTR_MUL_FV] = { "MUL_FV" , 0, 6 },
+ [INSTR_MUL_VF] = { "MUL_VF" , 0, 6 },
+ [INSTR_DIV_F] = { "DIV" , 0, 3 },
+ [INSTR_ADD_F] = { "ADD_F" , 0, 5 },
+ [INSTR_ADD_V] = { "ADD_V" , 0, 5 },
+ [INSTR_SUB_F] = { "SUB_F" , 0, 5 },
+ [INSTR_SUB_V] = { "DUB_V" , 0, 5 },
+ [INSTR_EQ_F] = { "EQ_F" , 0, 4 },
+ [INSTR_EQ_V] = { "EQ_V" , 0, 4 },
+ [INSTR_EQ_S] = { "EQ_S" , 0, 4 },
+ [INSTR_EQ_E] = { "EQ_E" , 0, 4 },
+ [INSTR_EQ_FNC] = { "ES_FNC" , 0, 6 },
+ [INSTR_NE_F] = { "NE_F" , 0, 4 },
+ [INSTR_NE_V] = { "NE_V" , 0, 4 },
+ [INSTR_NE_S] = { "NE_S" , 0, 4 },
+ [INSTR_NE_E] = { "NE_E" , 0, 4 },
+ [INSTR_NE_FNC] = { "NE_FNC" , 0, 6 },
+ [INSTR_LE] = { "LE" , 0, 2 },
+ [INSTR_GE] = { "GE" , 0, 2 },
+ [INSTR_LT] = { "LT" , 0, 2 },
+ [INSTR_GT] = { "GT" , 0, 2 },
+ [INSTR_LOAD_F] = { "FIELD_F" , 0, 7 },
+ [INSTR_LOAD_V] = { "FIELD_V" , 0, 7 },
+ [INSTR_LOAD_S] = { "FIELD_S" , 0, 7 },
+ [INSTR_LOAD_ENT] = { "FIELD_ENT" , 0, 9 },
+ [INSTR_LOAD_FLD] = { "FIELD_FLD" , 0, 9 },
+ [INSTR_LOAD_FNC] = { "FIELD_FNC" , 0, 9 },
+ [INSTR_ADDRESS] = { "ADDRESS" , 0, 7 },
+ [INSTR_STORE_F] = { "STORE_F" , 0, 7 },
+ [INSTR_STORE_V] = { "STORE_V" , 0, 7 },
+ [INSTR_STORE_S] = { "STORE_S" , 0, 7 },
+ [INSTR_STORE_ENT] = { "STORE_ENT" , 0, 9 },
+ [INSTR_STORE_FLD] = { "STORE_FLD" , 0, 9 },
+ [INSTR_STORE_FNC] = { "STORE_FNC" , 0, 9 },
+ [INSTR_STOREP_F] = { "STOREP_F" , 0, 8 },
+ [INSTR_STOREP_V] = { "STOREP_V" , 0, 8 },
+ [INSTR_STOREP_S] = { "STOREP_S" , 0, 8 },
+ [INSTR_STOREP_ENT] = { "STOREP_ENT", 0, 10},
+ [INSTR_STOREP_FLD] = { "STOREP_FLD", 0, 10},
+ [INSTR_STOREP_FNC] = { "STOREP_FNC", 0, 10},
+ [INSTR_RETURN] = { "RETURN" , 0, 6 },
+ [INSTR_NOT_F] = { "NOT_F" , 0, 5 },
+ [INSTR_NOT_V] = { "NOT_V" , 0, 5 },
+ [INSTR_NOT_S] = { "NOT_S" , 0, 5 },
+ [INSTR_NOT_ENT] = { "NOT_ENT" , 0, 7 },
+ [INSTR_NOT_FNC] = { "NOT_FNC" , 0, 7 },
+ [INSTR_IF] = { "IF" , 0, 2 },
+ [INSTR_IFNOT] = { "IFNOT" , 0, 5 },
+ [INSTR_CALL0] = { "CALL0" , 0, 5 },
+ [INSTR_CALL1] = { "CALL1" , 0, 5 },
+ [INSTR_CALL2] = { "CALL2" , 0, 5 },
+ [INSTR_CALL3] = { "CALL3" , 0, 5 },
+ [INSTR_CALL4] = { "CALL4" , 0, 5 },
+ [INSTR_CALL5] = { "CALL5" , 0, 5 },
+ [INSTR_CALL6] = { "CALL6" , 0, 5 },
+ [INSTR_CALL7] = { "CALL7" , 0, 5 },
+ [INSTR_CALL8] = { "CALL8" , 0, 5 },
+ [INSTR_STATE] = { "STATE" , 0, 5 },
+ [INSTR_GOTO] = { "GOTO" , 0, 4 },
+ [INSTR_AND] = { "AND" , 0, 3 },
+ [INSTR_OR] = { "OR" , 0, 2 },
+ [INSTR_BITAND] = { "BITAND" , 0, 6 },
+ [INSTR_BITOR] = { "BITOR" , 0, 5 }
};
/*
*byte = read;
if (read == -1) {
free (line);
- //exit (1);
return NULL;
}
return line;
.name = offset_chars /* location of name in string table (for name)*/
});
});
- /* FUNCTION */ DECLTYPE(asm_keys[5], {});
+ /* FUNCTION */
+ DECLTYPE(asm_keys[5], {
+ /* TODO: parse */
+ code_defs_add((prog_section_def){
+ .type = TYPE_VOID,
+ .offset = offset_globals,
+ .name = offset_chars
+ });
+ code_globals_add(offset_functions);
+ code_functions_add((prog_section_function){
+ .entry = offset_code,
+ .firstlocal = 0,
+ .locals = 0,
+ .profile = 0,
+ .name = offset_chars,
+ .file = 0,
+ .nargs = 0,
+ .argsize = {0}
+ });
+ });
/* if we make it this far then we have statements */
{
size_t i = 0;
for (; i < sizeof(asm_instr)/sizeof(*asm_instr); i++) {
- if (!strncmp(skip, asm_instr[i], strlen(asm_instr[i]))) {
+ if (!strncmp(skip, asm_instr[i].m, asm_instr[i].l)) {
/* TODO */
goto end;
}