Commits

Jordan Earls committed 763f15e

First opcode handled. xor

Comments (0)

Files changed (3)

 }
 
 
+#define assert_that(x) if(!(x)){return -1;}
+
+int lasm_handle_opcode(lasm_parse_state_t* parse, char** groups)
+{
+  if(!strcmp("xor", groups[0]))
+  {
+    assert_that(groups[2][0]=='\0');
+    assert_that(groups[3][0]=='\0');
+    parse->template=0x0100;
+    if(!groups[1][0]=='\0')
+    {
+      assert_that(!strcmp("8", groups[1]));
+      parse->is_8bit=true;
+    }
+  }
+  else
+  {
+    return -1;
+  }
+  return 0;
+}
+#undef assert_that
+
+
 int lasm_parse_part(lasm_parse_state_t* parse, char* part)
 {
   int len=strlen(part);
   bool is_8bit;
   bool is_indirect;
   bool is_immediate;
-  int primary_op;
+  unsigned int template;
   int arg1;
   int arg2;
   int immediate;
 void lasm_resolve_labels(lasm_state_t* state);
 int lasm_parse_part(lasm_parse_state_t *parse, char* part);
 int lasm_parse_opcode(char* op, char** groups);
+int lasm_handle_opcode(lasm_parse_state_t* parse, char** groups);
 
 
 #endif

liblasm/unittests/unittests.c

 #pragma GCC diagnostic ignored "-Wunused-variable"
 #include "minunit.h"
 #include <stdlib.h>
+#include <string.h>
 
 #include "../lasm.h"
 
   }
 }
 
+MU_TEST(handle_opcode_creates_proper_state)
+{
+  char* tmp[4]={"xor", "8", "", ""};
+  lasm_parse_state_t parse;
+  mu_check(lasm_handle_opcode(&parse, tmp)==0);
+  mu_check(parse.template==0x0100);
+  mu_check(parse.is_8bit==true);
+  
+  tmp[3]="foo";
+  mu_check(lasm_handle_opcode(&parse, tmp)==-1);
+  tmp[3]="";
+  tmp[1]="foo";
+  mu_check(lasm_handle_opcode(&parse, tmp)==-1);
+  
+  
+ 
+}
 
 
 MU_TEST_SUITE(test_suite) {
     MU_RUN_TEST(correctly_handles_end_of_line);
     MU_RUN_TEST(correctly_handles_beginning_comments);
     MU_RUN_TEST(opcodes_split_properly);
+    MU_RUN_TEST(handle_opcode_creates_proper_state);
     
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.