int check_len(int f, char *str, int pos) { if (f == 5) { if (ft_strlen(str) >= PROG_NAME_LENGTH) asm_error(NM_TOO_LONG, 0, pos); } if (f == 8) { if (ft_strlen(str) >= COMMENT_LENGTH) asm_error(CMT_TOO_LONG, 0, pos); } return (OK); }
//done FILE *open_write_or_error (char* file_name) { FILE* fw = fopen(file_name,"w"); if(fw == NULL){ asm_error(ERR_OPEN_WRITE,file_name); } return fw; }
//done FILE *open_read_or_error (char* file_name) { FILE* fp = fopen(file_name,"r"); if(fp == NULL){ asm_error(ERR_OPEN_READ, file_name); } return fp; }
//done int get_reg_or_error (char *token) { int get = util_get_reg(token); if(get == -1){ asm_error(ERR_EXPECTED_REG,token); } return get; }
//done void get_immediate_or_error (char* token, int width, int isSigned) { //field fits //value widith issighned int value = 0; int bob = lc3_get_int(token,&value); if(!bob) asm_error(ERR_BAD_IMM,token); if(fieldFits (value,width,isSigned) != 0){ //set something equal to it currInfo -> immediate = value; } else{ asm_error(ERR_EXPECT_REG_IMM); } }
//done char* check_for_label (char* token) { if(util_get_opcode (token) == -1){ //if it is then is it a vaild label? if(util_is_valid_label(token)){ //if it is a vaild label add that shit //return the next token broski //fprintf(stderr, "adding symbol: %s\n",token); if(symbol_add(lc3_sym_tab,token,currAddr) == 0){ asm_error(ERR_DUPLICATE_LABEL,token); } return next_token(); } else{ //damn that shit anint wokring right asm_error(ERR_BAD_LABEL,token); } } return token; }
int find_quote(char *str, int pos) { int i; int len; i = 0; len = ft_strlen(str); if (str[i++] != '"') asm_error(ERR_SYNTAX, 0, pos); while (str[i]) { if (str[i] == ';') asm_error(U_STRING, 0, pos); if (str[i] == '"' && i != len - 1) asm_error(ERR_SYNTAX, i, pos); i++; } return (OK); }
//done void get_PC_offset_or_error (char* token) { //PCoffset.. printf("TOKEN %s\n",token); if(util_is_valid_label(token) != 0){ currInfo -> reference = strdup(token); } else{ asm_error(ERR_BAD_LABEL,token); } }
/** @todo implement this function */ void encode_PC_offset_or_error (int width) { printf("REFERENCE: %s\n",currInfo->reference); symbol_t* symbol = symbol_find_by_name (lc3_sym_tab, currInfo->reference); printf("SYMBOL: %s,%d\n",symbol->name,symbol->addr); if(symbol != NULL){ int offset = symbol->addr-currInfo->address-1; int whatever = fieldFits(offset,width,1); if(whatever == 1){ currInfo -> machineCode = setField(currInfo->machineCode,width-1,0,offset); } else{ asm_error(ERR_BAD_PCOFFSET,currInfo->reference); } } }
//done void get_comma_or_error (void) { char* token = next_token(); if(strcasecmp(token,",") != 0){ asm_error(ERR_EXPECTED_COMMA); } }