Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix several subtle bugs found during emscripten port
  • Loading branch information
ddevault committed Nov 17, 2014
1 parent d2044e7 commit 8bc31af
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
15 changes: 9 additions & 6 deletions CMakeLists.txt
Expand Up @@ -5,19 +5,22 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin/")
add_definitions("-Wall")
set(CMAKE_BUILD_TYPE Debug)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(INSTRUCTION_SET_PATH "${PROJECT_SOURCE_DIR}/tables/" CACHE PATH "Location to install instruction set tables.")
if(EMSCRIPTEN)
message("Building for emscripten")
set(INSTRUCTION_SET_PATH "/" CACHE PATH "Location to install instruction set tables.")
else()
set(INSTRUCTION_SET_PATH "/usr/share/scas/instruction_sets/" CACHE PATH "Location to install instruction set tables.")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(INSTRUCTION_SET_PATH "${PROJECT_SOURCE_DIR}/tables/" CACHE PATH "Location to install instruction set tables.")
else()
set(INSTRUCTION_SET_PATH "/usr/share/scas/instruction_sets/" CACHE PATH "Location to install instruction set tables.")
endif()
endif()

if(EMSCRIPTEN)
set(CMAKE_EXE_LINKER_FLAGS "-O2")
set(CMAKE_C_FLAGS "-O2")
set(INSTRUCTION_SET_PATH "/" CACHE PATH "Location to install instruction set tables.")
endif()

add_definitions(-DINSTRUCTION_SET_PATH="${INSTRUCTION_SET_PATH}/")
add_definitions(-DINSTRUCTION_SET_PATH="${INSTRUCTION_SET_PATH}")

include_directories(
assembler/
Expand Down
10 changes: 8 additions & 2 deletions assembler/assembler.c
Expand Up @@ -163,7 +163,9 @@ int try_expand_macro(struct assembler_state *state, char **line) {
list_add(newlines, newline);
} else {
/* Adding to extra_lines */
list_add(newlines, mline);
char *newline = malloc(strlen(mline) + 1);
strcpy(newline, mline);
list_add(newlines, newline);
}
}

Expand Down Expand Up @@ -468,7 +470,11 @@ object_t *assemble(FILE *file, const char *file_name, assembler_settings_t *sett
line = split_line(&state, line);
}
int i;
for (i = 0; i < sizeof(line_ops) / sizeof(void*); ++i) {
int l = sizeof(line_ops) / sizeof(void*);
if (state.nolist || (state.if_stack->length && !*(int*)stack_peek(state.if_stack))) {
l = sizeof(nolist_line_ops) / sizeof(void*);
}
for (i = 0; i < l; ++i) {
if (state.nolist || (state.if_stack->length && !*(int*)stack_peek(state.if_stack))) {
if (nolist_line_ops[i](&state, &line)) {
break;
Expand Down
8 changes: 7 additions & 1 deletion assembler/match.c
Expand Up @@ -80,7 +80,13 @@ instruction_match_t *try_match(instruction_set_t *set, instruction_t *inst, cons
j--;
}
} else if (inst->match[i] == '%' || inst->match[i] == '^' || inst->match[i] == '&') /* Immediate value */ {
char key = inst->match[++i]; while (inst->match[++i] != '>'); ++i;
char type = inst->match[i];
char key = inst->match[++i];
if (type != '&') {
while (inst->match[++i] != '>'); ++i;
} else {
++i;
}
char *value = get_operand_string(inst, &i, str, j);
if (value == NULL) {
match = 0;
Expand Down

0 comments on commit 8bc31af

Please sign in to comment.