Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define BUFSIZE 512
- struct inst_clk {
- char *inst;
- char *avr_clk;
- char *lgt_clk;
- };
- static struct inst_clk inst_entry[] = {
- /* inst AVR LGT8x */
- {"adiw", "2", "1"},
- {"sbiw", "2", "1"},
- {"mul", "2", "1"},
- {"muls", "2", "1"},
- {"mulsu", "2", "1"},
- {"fmul", "2", "1"},
- {"fmuls", "2", "1"},
- {"fmulsu", "2", "1"},
- {"rjmp", "2", "1"},
- {"ijmp", "2", "1"},
- {"jmp", "3", NULL},
- {"rcall", "3", "1"},
- {"icall", "3", "1"},
- {"call", "4", NULL},
- {"ret", "4", "2"},
- {"reti", "4", "2"},
- {"cpse", "1/2/3", "1/2"},
- {"sbrc", "1/2/3", "1/2"},
- {"sbrs", "1/2/3", "1/2"},
- {"sbic", "1/2/3", "1/2"},
- {"sbis", "1/2/3", "1/2"},
- {"brbs", "1/2", NULL},
- {"brbc", "1/2", NULL},
- {"breq", "1/2", NULL},
- {"brne", "1/2", NULL},
- {"brcs", "1/2", NULL},
- {"brcc", "1/2", NULL},
- {"brsh", "1/2", NULL},
- {"brlo", "1/2", NULL},
- {"brmi", "1/2", NULL},
- {"brpl", "1/2", NULL},
- {"brge", "1/2", NULL},
- {"brlt", "1/2", NULL},
- {"brhs", "1/2", NULL},
- {"brhc", "1/2", NULL},
- {"brts", "1/2", NULL},
- {"brtc", "1/2", NULL},
- {"brvs", "1/2", NULL},
- {"brvc", "1/2", NULL},
- {"brie", "1/2", NULL},
- {"brid", "1/2", NULL},
- {"sbi", "2", NULL},
- {"cbi", "2", NULL},
- {"ld", "2", "1"},
- {"ldd", "2", "1"},
- {"lds", "2", NULL},
- {"st", "2", "1"},
- {"std", "2", "1"},
- {"sts", "2", NULL},
- {"lpm", "3", "2"},
- {"push", "2", "1"},
- {"pop", "2", "1"},
- };
- static char *get_clk(char *str, int mode)
- {
- int i;
- for (i = 0; i < sizeof(inst_entry) / sizeof(struct inst_clk); i++) {
- if (!strcmp(str, inst_entry[i].inst)) {
- if (mode && inst_entry[i].lgt_clk != NULL)
- return inst_entry[i].lgt_clk;
- else
- return inst_entry[i].avr_clk;
- }
- }
- return NULL;
- }
- static char *find(char *str, int mode)
- {
- char *p, *l, *r;
- char buf[BUFSIZE];
- strncpy(buf, str, sizeof(buf));
- for ((p = strtok_r(buf, " \t", &l)); p;
- (p = strtok_r(NULL, " \t", &l))) {
- r = get_clk(p, mode);
- if (r != NULL)
- return r;
- }
- return "1";
- }
- int main(int argc, char *argv[])
- {
- char *p;
- char buf[BUFSIZE];
- while (fgets(buf, sizeof(buf), stdin) != NULL) {
- p = strpbrk(buf, "\n\r");
- if (p != NULL)
- *p = '\0';
- p = strchr(buf, ':');
- if (p == NULL || !strlen(p + 1))
- p = "";
- else
- p = find(p + 1, argc > 1);
- printf("%-5s %s\n", p, buf);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement