label offset corretto
This commit is contained in:
parent
6cb8019f5f
commit
b3d8ee9825
@ -55,7 +55,6 @@ class VMAssembler:
|
||||
self.functions = []
|
||||
self.decrypt_ops(key)
|
||||
self.parse_functions()
|
||||
print(self.functions)
|
||||
main = next((x for x in self.functions if x.name == "main"), None)
|
||||
if main == None:
|
||||
print("Main has to be defined")
|
||||
@ -102,7 +101,6 @@ class VMAssembler:
|
||||
"""
|
||||
Intel syntax -> REG, IMM
|
||||
"""
|
||||
print(instruction.args)
|
||||
opcode = instruction.opcode
|
||||
reg = instruction.args[0]
|
||||
imm = instruction.args[1]
|
||||
@ -219,6 +217,7 @@ class VMAssembler:
|
||||
for i in f.instructions:
|
||||
if i.label == dst.name:
|
||||
val = f.offset_of_label(dst) + f.offset
|
||||
|
||||
if val == None:
|
||||
raise AssemblerException()
|
||||
# resolving the symbol
|
||||
@ -269,14 +268,11 @@ class VMFunction:
|
||||
line = code[i]
|
||||
ins = instruction_re.match(line)
|
||||
label = label_re.match(line)
|
||||
print(line)
|
||||
if label:
|
||||
label_name = label.group(1)
|
||||
print("APPENDING {} TO {}".format(code[i], self.name))
|
||||
self.instructions.append(VMInstruction(code[i+1], label_name))
|
||||
i += 2
|
||||
elif ins:
|
||||
print("APPENDING {} TO {}".format(code[i], self.name))
|
||||
self.instructions.append(VMInstruction(line))
|
||||
else:
|
||||
raise InvalidOperation(line)
|
||||
@ -293,9 +289,10 @@ class VMFunction:
|
||||
def offset_of_label(self, label):
|
||||
offset = 0
|
||||
for i in self.instructions:
|
||||
offset += i.size
|
||||
if i.label == label:
|
||||
if str(i.label) == str(label):
|
||||
break
|
||||
offset += i.size
|
||||
|
||||
return offset
|
||||
|
||||
def __repr__(self):
|
||||
@ -324,9 +321,7 @@ class VMInstruction:
|
||||
raise InvalidOperation(opcode)
|
||||
|
||||
args = [x for x in ins.groups()[1:] if x is not None]
|
||||
print(args)
|
||||
for a in args:
|
||||
print(a)
|
||||
if immediate_re.match(a) or symcall:
|
||||
# directly append the immediate
|
||||
self.args.append(VMComponent(a, a))
|
||||
|
Loading…
Reference in New Issue
Block a user