本文整理汇总了Python中Translator.Translator.getHexFromAsm方法的典型用法代码示例。如果您正苦于以下问题:Python Translator.getHexFromAsm方法的具体用法?Python Translator.getHexFromAsm怎么用?Python Translator.getHexFromAsm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translator.Translator
的用法示例。
在下文中一共展示了Translator.getHexFromAsm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exit
# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import getHexFromAsm [as 别名]
import sys
from Translator import Translator
if __name__ == '__main__':
if(len(sys.argv) < 2):
print "ERROR: input file not specified"
exit(1)
tr = Translator()
instructionList = list()
with open(sys.argv[1],"r") as source:
text = source.read()
lastLine = text.split("\n")[-1]
if "END" not in lastLine.split(";")[0]:
print "ERROR: END instruction not detected"
exit(1)
instructionList = tr.getHexFromAsm(text)
outputFileName = "out.coe"
if("-o" in sys.argv and (sys.argv.index("-o") < (len(sys.argv)-1))):
outputFileName = sys.argv[sys.argv.index("-o")+1]
with open(outputFileName, "w+") as outFile:
outFile.write('memory_initialization_radix=16;\nmemory_initialization_vector=\n')
for line in instructionList:
separator = str()
if line == instructionList[-1]:
separator = ';'
else:
separator = ',\n'
outFile.write(line+separator)