* © 2018 Aaron Taylor <ataylor at subgeniuskitty dot com>
* See LICENSE.txt file for copyright and license details.
#include "nedasm_structures.h"
seek_instruction_list_start(struct instruction
* instructions
)
if (instructions
== NULL
) return NULL
;
while (instructions
->prev
!= NULL
) instructions
= instructions
->prev
;
seek_instruction_list_end(struct instruction
* instructions
)
if (instructions
== NULL
) return NULL
;
while (instructions
->next
!= NULL
) instructions
= instructions
->next
;
insert_instruction_struct_before(struct instruction
* list
, struct instruction
* new_node
)
new_node
->prev
= list
->prev
;
if (new_node
->prev
!= NULL
) (new_node
->prev
)->next
= new_node
;
insert_instruction_struct_after(struct instruction
* list
, struct instruction
* new_node
)
new_node
->next
= list
->next
;
if (new_node
->next
!= NULL
) (new_node
->next
)->prev
= new_node
;
remove_instruction_struct(struct instruction
* instructions
)
//struct instruction * delete_me = instructions;
struct instruction
* return_me
= NULL
;
if (instructions
->prev
!= NULL
) {
instructions
->prev
->next
= instructions
->next
;
return_me
= instructions
->prev
;
if (instructions
->next
!= NULL
) {
instructions
->next
->prev
= instructions
->prev
;
if (return_me
!= NULL
) return_me
= instructions
->next
;
// TODO: Given the one-pass & die-early nature of this task, skip memory management entirely?
//if (delete_me->label != NULL) free(delete_me->label);
//if (delete_me->target != NULL) free(delete_me->target);
create_instruction_struct(void)
struct instruction
* new_struct
= malloc(sizeof(struct instruction
));
new_struct
->syllable
= 0;
new_struct
->target
= NULL
;
new_struct
->label
= NULL
;
insert_NOP_structs_after(struct instruction
* list
, uint8_t count
)
struct instruction
* new_struct
= create_instruction_struct();
new_struct
->syllable
= NOP
;
insert_instruction_struct_after(list
, new_struct
);
insert_NOP_structs_before(struct instruction
* list
, uint8_t count
)
struct instruction
* new_struct
= create_instruction_struct();
new_struct
->syllable
= NOP
;
insert_instruction_struct_before(list
, new_struct
);