Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
//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;
}
Exemplo n.º 3
0
//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;
}
Exemplo n.º 4
0
//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;
}
Exemplo n.º 5
0
//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);
  }
}
Exemplo n.º 6
0
//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;
}
Exemplo n.º 7
0
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);
}
Exemplo n.º 8
0
//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);
  }


}
Exemplo n.º 9
0
/** @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);
      }

  }
}
Exemplo n.º 10
0
//done
void get_comma_or_error (void) {
  char* token = next_token();
  if(strcasecmp(token,",") != 0){
    asm_error(ERR_EXPECTED_COMMA);
  }
}