-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.py
More file actions
30 lines (24 loc) · 902 Bytes
/
Program.py
File metadata and controls
30 lines (24 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from Instruction import *
from Label import *
from typing import List
from Exceptions import PreprocessorError
import os.path
class Program():
def __init__(self, sourceFile: str):
self.sourceFile: str = sourceFile
self.sourceFolder: str = os.path.dirname(self.sourceFile)
self.bootstrapSize: int = 4
self.assembled: bool = False
self.instructions: List[Instruction] = []
self.labels: List[Label] = []
self.binary: List[int] = []
self.source = Program.LoadFile(self.sourceFile)
self.preprocessed: List[str] = []
@staticmethod
def LoadFile(filename: str) -> str:
if os.path.isfile(filename) == False:
raise PreprocessorError(f"File not found : {filename}", 0, "")
source: str = ""
with open(filename, "r") as file:
source = file.read()
return source