void verify_variable_name(char *name, int line) { if (!IS_A_LETTER(name[0])) kasm_exit("Variable name must start with a letter.", line); int i; for (i = 1; name[i]; i++) { // This many parentheses aren't needed but the compiler wanted them. if ((!IS_A_LETTER(name[i])) && (!IS_A_NUMBER(name[i])) && (name[i] != '_')) kasm_exit("Only alphanumeric characters and underscores allowed " "for variable name.", line); } }
/* Set for each worker the buffer slice to handle */ static int buff_init(uint32_t tid) { char *buff; off_t worker_end; if(fa_read_init()) return -1; worker_slice = file_size / nb_thread; worker_current = worker_slice * tid; /* Last thread handle remaining bytes */ if(tid == (nb_thread-1)) worker_slice += file_size % nb_thread; worker_end = worker_current + worker_slice; /* Balance worker_slice to include words at the ends */ /* skip first letters if we are not the first thread */ do { if(tid == 0) break; if(fa_read(tid, &buff, 1, worker_current) != 1) return -1; if(!IS_A_LETTER(*buff)) break; dmsg3("%d skipping letter %c\n", tid, *buff); worker_current++; worker_slice--; } while(*buff); /* add letters of the last word if we are not the last thread */ do { if(tid == (nb_thread-1)) break; if(fa_read(tid, &buff, 1, worker_end) != 1) return -1; if(!IS_A_LETTER(*buff)) break; dmsg3("%d adding letter %c\n", tid, *buff); worker_end++; worker_slice++; } while(*buff); dmsg2("%d: slice start %d, slice size %d, slice end %d\n", tid, worker_current, worker_slice, worker_end); return 0; }
static int buff_hdl(uint32_t tid, char* buff, size_t size, char last) { dmsg2("start %s, %d: word %s, count %d, *buff %c\n", __FUNCTION__, tid, word, count, *buff); for( ; size; size--, buff++) { if(!IS_A_LETTER(*buff)) { /*Not a letter */ if(add_sep(tid)) return -1; continue; } /* A letter */ if(add_letter(*buff)) return -1; } /* If this is the last buffer, end the word (if any)*/ if(last) { add_sep(tid); } dmsg3("end %s, %d: word %s, count %d, *buff %c\n", __FUNCTION__, tid, word, count, *buff); return 0; }
uint32_t insn_addr19(Instruction *i, VarList *vlist) { StrNode *n = i->list->head; n = n->next; int dest = get_register_index(n->str); n = n->next; int imm = 0; if (IS_A_NUMBER(n->str[0])) { imm = immediate_convert(n->str, i->page); } else if (IS_A_LETTER(n->str[0])) { int addr = link_var_name_to_address(vlist, n->str); if (addr == -1) kasm_exit("Invalid variable label.", i->page); imm = addr + data_offset; } index_in_range(dest, i->page); return i->op1 | i->op2 << 5 | dest << 8 | imm << 13; }