-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
132 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
from ohre.abcre.enum.BaseEnum import BaseEnum | ||
|
||
|
||
class NAC_LV(BaseEnum): | ||
class CODE_LV(BaseEnum): | ||
def __init__(self): | ||
super().__init__() | ||
NATIVE = 0 | ||
NATIVE_BLOCK_SPLITED = 1 | ||
IR_LV1 = 2 | ||
TAC = 2 | ||
IR_LV2 = 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import copy | ||
from typing import Any, Dict, Iterable, List, Tuple | ||
|
||
from ohre.abcre.dis.NAC import NAC | ||
from ohre.abcre.dis.TAC import TAC | ||
from ohre.abcre.dis.NACTYPE import NACTYPE | ||
|
||
|
||
class CodeBlock(): # asm instruction(NAC) cantained | ||
def __init__(self, in_l: List[List[str]] | List[NAC] | List[NAC]): | ||
assert len(in_l) >= 0 | ||
self.insts: List[NAC] | List[TAC] = list() | ||
if (isinstance(in_l[0], NAC)): # NAC in list | ||
self.insts = copy.deepcopy(in_l) | ||
else: # maybe list in list # anyway, try init NAC using element in list | ||
for inst in in_l: | ||
assert len(inst) > 0 | ||
self.insts.append(NAC(inst)) | ||
|
||
def get_slice_block(self, idx_start: int, idx_end: int): | ||
return CodeBlock(copy.deepcopy(self.insts[idx_start: idx_end])) | ||
|
||
def __str__(self): | ||
return self.debug_short() | ||
|
||
def __len__(self): | ||
return len(self.insts) | ||
|
||
def debug_short(self): | ||
out = f"CodeBlock: insts {len(self.insts)}" | ||
return out | ||
|
||
def debug_deep(self): | ||
out = f"CodeBlock: insts {len(self.insts)}\n" | ||
for i in range(len(self.insts)): | ||
if (self.insts[i].type == NACTYPE.LABEL): | ||
out += f"{i} {self.insts[i].debug_deep()}\n" | ||
else: | ||
out += f"{i}\t{self.insts[i].debug_deep()}\n" | ||
return out.strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import copy | ||
from typing import Any, Dict, Iterable, List, Tuple | ||
|
||
from ohre.abcre.dis.NAC import NAC | ||
from ohre.abcre.dis.CODE_LV import CODE_LV | ||
from ohre.abcre.dis.CodeBlock import CodeBlock | ||
from ohre.abcre.dis.NACTYPE import NACTYPE | ||
|
||
|
||
class CodeBlocks(): # NAC block contained, build control flow graph inside a single CodeBlocks for one method | ||
def __init__(self, in_l: List[List[str]] | List[CodeBlock]): | ||
assert len(in_l) >= 0 | ||
self.blocks: List[CodeBlock] = list() | ||
self.IR_lv = CODE_LV.NATIVE # native | ||
|
||
if (isinstance(in_l[0], CodeBlock)): # CodeBlock in list | ||
self.blocks = copy.deepcopy(in_l) | ||
else: # maybe list(str) in list # anyway, try init CodeBlock using element(asm codea str list) in list | ||
self.blocks: List[CodeBlock] = [CodeBlock(in_l)] | ||
|
||
def __str__(self): | ||
return self.debug_short() | ||
|
||
@property | ||
def len(self): | ||
return len(self.blocks) | ||
|
||
def __len__(self): | ||
return len(self.blocks) | ||
|
||
def debug_short(self): | ||
out = f"CodeBlocks: blocks({len(self.blocks)}) {CODE_LV.get_code_name(self.IR_lv)}" | ||
return out | ||
|
||
def debug_deep(self): | ||
out = f"{self.debug_short()}\n" | ||
for i in range(len(self.blocks)): | ||
out += f"[{i}/{len(self.blocks)}]-block: {self.blocks[i].debug_deep()}\n" | ||
return out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from typing import Any, Dict, Iterable, List, Tuple | ||
|
||
from ohre.abcre.dis.NACTYPE import NACTYPE | ||
|
||
|
||
class TAC(): # Three Address Code | ||
|
||
def __init__(self, optype, op_args: List): | ||
self.optype = optype | ||
self.args = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters