2005-05-01 11:48:36 +00:00
|
|
|
#include "Instruction.h"
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
@implementation Instruction
|
|
|
|
+ (id) opcode: (opcode_e) oc
|
|
|
|
{
|
2011-01-14 03:07:40 +00:00
|
|
|
return [[self alloc] initWithOpcode: oc operand: 0 label: nil];
|
2005-05-01 11:48:36 +00:00
|
|
|
}
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
+ (id) opcode: (opcode_e) oc operand: (int) op
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
2011-01-14 03:07:40 +00:00
|
|
|
return [[self alloc] initWithOpcode: oc operand: op label: nil];
|
2005-05-01 11:48:36 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 13:39:43 +00:00
|
|
|
+ (id) opcode: (opcode_e) oc label: (Instruction *) l
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
|
|
|
return [[self alloc] initWithOpcode: oc operand: 0 label: l];
|
|
|
|
}
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
- (id) initWithOpcode: (opcode_e) oc operand: (int) op label: (Instruction *) l
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
opcode = oc;
|
|
|
|
operand = op;
|
|
|
|
label = l;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
- (void) offset: (int) ofs
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
|
|
|
offset = ofs;
|
|
|
|
}
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
- (int) offset
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (opcode_e) opcode
|
|
|
|
{
|
|
|
|
return opcode;
|
|
|
|
}
|
|
|
|
|
2011-02-14 13:39:43 +00:00
|
|
|
- (void) emitStruct: (instruction_t *) program
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
|
|
|
program[offset].opcode = opcode;
|
|
|
|
if (label) {
|
|
|
|
program[offset].operand = [label offset];
|
|
|
|
} else {
|
|
|
|
program[offset].operand = operand;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-02 02:33:44 +00:00
|
|
|
- (void) markReachable
|
|
|
|
{
|
|
|
|
[label mark];
|
|
|
|
}
|
|
|
|
|
2005-05-01 11:48:36 +00:00
|
|
|
@end
|