From: Mart Lubbers Date: Wed, 14 Dec 2016 09:55:20 +0000 (+0100) Subject: add tracing and stepping X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=48bddd6acbfceed71f699e937c750f0994cc00fc;p=mTask.git add tracing and stepping --- diff --git a/int/Makefile b/int/Makefile index 4539229..f6e3402 100644 --- a/int/Makefile +++ b/int/Makefile @@ -1,6 +1,6 @@ CFLAGS:=-g -Wall -Wextra -Werror all: mTaskSymbols.h int -mTaskSymbols.h: +mTaskSymbols.h: CLMFLAGS=-nr make -BC .. mTaskInterpret ../mTaskInterpret > $@ diff --git a/int/int.c b/int/int.c index a2dd745..9d6fde3 100644 --- a/int/int.c +++ b/int/int.c @@ -12,23 +12,36 @@ #include "mTaskSymbols.h" +#define PORT 8123 + #define MAXTASKS 5 #define MAXTASKSIZE 1024 #define MAXSDS 50 #define STACKSIZE 1024 +#define MSG_TASK 't' +#define MSG_SDS 's' + #define DEBUG + #ifdef DEBUG #define debug(s, ...) printf(s, ##__VA_ARGS__); +#define trace(op, ...) printf("pc: %d, sp: %d, op: " op, pc, sp, ##__VA_ARGS__); #else #define debug(s, ...) ; +#define trace(pc, sp, op) ; #endif #define pdie(s) {perror(s); exit(1);} #define die(s, ...) {fprintf(stderr, s, ##__VA_ARGS__); exit(1);} -char tasks[MAXTASKS][MAXTASKSIZE] = {0}; -bool tasks_used[MAXTASKS] = {0}; +struct task { + uint8_t bc[MAXTASKSIZE]; + uint16_t tlen; + bool used; +}; + +struct task tasks[MAXTASKS] = {0}; int sock_fd = -1; int fd = -1; @@ -54,146 +67,176 @@ void read_message(int fd_in, int fd_out) { //Find next task uint8_t c, ct; - uint16_t tasklen; for(ct = 0; ct MAXTASKSIZE) - die("Task is too long: %d\n", tasklen); - for(int i = 0; i MAXTASKSIZE) + die("Task is too long: %d\n", tasks[ct].tlen); + for(int i = 0; i 0 ? 0 : 1; break; case BCADD: + trace("add\n"); stack[sp-1] = stack[sp] + stack[sp-1]; sp -= 1; break; case BCSUB: + trace("sub\n"); stack[sp-1] = stack[sp] - stack[sp-1]; sp -= 1; break; case BCMUL: + trace("mul\n"); stack[sp-1] = stack[sp] * stack[sp-1]; sp -= 1; break; case BCDIV: + trace("div\n"); stack[sp-1] = stack[sp] / stack[sp-1]; sp -= 1; break; case BCAND: + trace("and\n"); stack[sp-1] = stack[sp] && stack[sp-1]; sp -= 1; break; case BCOR: + trace("or\n"); stack[sp-1] = stack[sp] || stack[sp-1]; sp -= 1; break; case BCEQ: + trace("eq\n"); stack[sp-1] = stack[sp] == stack[sp-1]; sp -= 1; break; case BCNEQ: + trace("neq\n"); stack[sp-1] = stack[sp] != stack[sp-1]; sp -= 1; break; - case BCLES: stack[sp-1] = stack[sp] < stack[sp-1]; + case BCLES: + trace("les\n"); + stack[sp-1] = stack[sp] < stack[sp-1]; sp -= 1; break; case BCGRE: + trace("gre\n"); stack[sp-1] = stack[sp] > stack[sp-1]; sp -= 1; break; case BCLEQ: + trace("leq\n"); stack[sp-1] = stack[sp] <= stack[sp-1]; sp -= 1; break; case BCGEQ: + trace("geq\n"); stack[sp-1] = stack[sp] >= stack[sp-1]; sp -= 1; break; case BCJMP: + trace("jmp to %d\n", program[pc]); pc = pc + program[pc]; break; case BCJMPT: + trace("jmpt to %d\n", program[pc]); pc += stack[sp] ? program[pc] : 1; break; case BCJMPF: + trace("jmpf to %d\n", program[pc]); pc += stack[sp] ? 1 : program[pc]; break; case BCSERIALAVAIL: - printf("SerialAvailable()\n"); + trace("SerialAvailable()\n"); break; case BCSERIALPRINT: - printf("SerialPrint()\n"); + trace("SerialPrint()\n"); break; case BCSERIALPRINTLN: - printf("SerialPrintln()\n"); + trace("SerialPrintln()\n"); break; case BCSERIALREAD: - printf("SerialRead()\n"); + trace("SerialRead()\n"); break; case BCSERIALPARSEINT: - printf("SerialParseInt()\n"); + trace("SerialParseInt()\n"); break; case BCANALOGREAD: - printf("AnalogRead(%d)\n", program[pc++]); + trace("AnalogRead(%d)\n", program[pc]); + pc++; break; case BCANALOGWRITE: - printf("AnalogWrite(%d)\n", program[pc++]); + trace("AnalogWrite(%d)\n", program[pc]); + pc++; break; case BCDIGITALREAD: - printf("DigitalRead(%d)\n", program[pc++]); + trace("DigitalRead(%d)\n", program[pc]); + pc++; break; case BCDIGITALWRITE: - printf("DigitalWrite(%d)\n", program[pc++]); + trace("DigitalWrite(%d)\n", program[pc]); + pc++; break; default: die("Unrecognized command: %d\n", program[--pc]); } } + debug("Task %d terminated\n", tasknum); } void open_filedescriptors() @@ -203,7 +246,7 @@ void open_filedescriptors() bzero((char *) &sa, sizeof(sa)); sa.sin_family = AF_INET; sa.sin_addr.s_addr = INADDR_ANY; - sa.sin_port = htons(8124); + sa.sin_port = htons(PORT); if((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) pdie("socket"); @@ -212,7 +255,7 @@ void open_filedescriptors() if(listen(sock_fd, 10) == -1) pdie("bind\n"); - printf("Listinging on 8123\n"); + printf("Listening on %d\n", PORT); fflush(stdout); if((fd = accept(sock_fd, (struct sockaddr*)NULL, NULL)) == -1) pdie("accept"); @@ -234,38 +277,30 @@ int main(void) while(true){ //Check for new tasks - if(input_available(fd)){ + if(input_available(fd)) read_message(fd, fd); - } //Run tasks for(ct = 0; ct= PROGRAMSIZE) - die("Max program size: %d\n", PROGRAMSIZE); - pl = pc; - debug("Done reading, program length: %d\n", pl); - - //Evaluate program - //Reset program counter and stack counter - pc = 0; - sp = 0; - while(pc != pl){ - } -*/ return 0; }