Example #1
0
def main():
    parser = argparse.ArgumentParser(prog="mipsal", description='Assemble and link a MIPS assembly program.')
    parser.add_argument("files", action="store", nargs="+", type=str, help="list of assembly files to process")
    parser.add_argument("--int", action="store_true", default=False, help="output intermediate files")
    parser.add_argument("--obj", action="store_true", default=False, help="output object files")
    parser.add_argument("-o", action="store", dest="out_name", type=str, default="mips.out", help="override output file name", metavar="file_name")
    parser.add_argument("-l", "--link", action="append", help="add file to program when linking. This option can be used more than once", metavar="file_name")
    args = parser.parse_args()

    obj_code = []
    for input_file in args.files:
        ints, objs = assembler.assemble(input_file)
        obj_code.append(objs)
        file_name = utils.get_file_name(input_file)
        if args.int:
            int_file = file_name + ".int"
            utils.write_file_from_list(int_file, ints)
        if args.obj:
            obj_file = file_name + ".o"
            utils.write_file_from_list(obj_file, objs)
    if args.link != None:
        for link_file in args.link:
            obj_code.append([x.strip() for x in utils.read_file_to_list(link_file)])
    output = linker.link(obj_code)
    utils.write_file_from_list(args.out_name, output)
Example #2
0
def assembleFile(f_in_name, f_out_name):
    """
        Okay, so this is the entry point for the assembler.
        This calls the lexer, which calls the parser, which
        calls the assembler, which calls the s19 generator.

        The flow will look like this
        f_in_name >> lexer >> parser >> assembler >> s19_gen >> f_out_name

        The lexer will take in the in file, and return a token stream
        The parser will take in the token stream and return an ast
        The assembler will take in an ast and return a list of binary data, with it's memory location
        The s19 gen will take that list, and return the list of records.
        Then this function, now that it has this list of records, will write them to the file.
    """
    print(f_in_name + " >> " + f_out_name)

    toks = lex(f_in_name)
    # print("\n".join(str(x) for x in toks))
    # print("\n\n")

    ast = parse(toks)
    # print("\n".join([str(x) for x in ast]))
    outFile = link([assemble(ast)])
    with open(f_out_name, "w+") as f:
        f.write(outFile)
        f.write("\n")
Example #3
0
def generate():
    if request.method == 'POST':
        files = (request.form['files']).split(',')
        offset = int(request.form['offset'])
        loadfile = files[-1].split('.')[0]
        mainfile = loadfile + '.asm'
        symbols, symbol_table = assembler.assemble(files)
        linker.link(mainfile, symbols)
        loader.load(mainfile, offset)
        machine.convert(mainfile)
        f = open("Output/" + loadfile + '.pass1', 'r')
        code = f.read()
        f.close()
        code = code.split('\n')
        for i in range(0, len(code)):
            code[i] = code[i].replace(' ', ' ')
            code[i] = "<span id=\"" + str(i +
                                          1) + "\">" + code[i] + "</span><br>"
        pass1code = ''.join(code)

        f = open("Output/" + loadfile + '.pass2', 'r')
        code = f.read()
        f.close()
        code = code.split('\n')
        for i in range(0, len(code)):
            code[i] = "<span id=\"" + str(i +
                                          1) + "\">" + code[i] + "</span><br>"
        pass2code = ''.join(code)

        f = open("Output/" + loadfile + '.asm', 'r')
        code = f.read()
        f.close()
        code = code.split('\n')
        for i in range(0, len(code)):
            code[i] = "<span id=\"" + str(i +
                                          1) + "\">" + code[i] + "</span><br>"
        link_code = ''.join(code)

        return json.dumps({
            'symbols': symbols,
            'symbol_table': symbol_table,
            'loadfile': loadfile,
            'pass1code': pass1code,
            'pass2code': pass2code,
            'link_code': link_code
        })
Example #4
0
def generate():
	if request.method == 'POST':
		files = (request.form['files']).split(',')
		offset = int(request.form['offset'])

		loadfile = files[-1].split('.')[0]
		mainfile=loadfile+'.asm'
		symbols,symbol_table=assembler.assemble(files)
		linker.link(mainfile, symbols)
		loader.load(mainfile, offset)
		machine.convert(mainfile)

		f=open("Output/"+loadfile+'.pass1','r')
		code=f.read()
		f.close()
		code = code.split('\n')
		for i in range(0,len(code)):
			code[i] = code[i].replace(' ','&nbsp;')
			code[i] = "<span id=\""+str(i+1)+"\">"+code[i]+"</span><br>"
		pass1code = ''.join(code)

		f=open("Output/"+loadfile+'.pass2','r')
		code=f.read()
		f.close()
		code = code.split('\n')
		for i in range(0,len(code)):
			code[i] = "<span id=\""+str(i+1)+"\">"+code[i]+"</span><br>"
		pass2code = ''.join(code)

		f=open("Output/"+loadfile+'.asm','r')
		code=f.read()
		f.close()
		code = code.split('\n')
		for i in range(0,len(code)):
			code[i] = "<span id=\""+str(i+1)+"\">"+code[i]+"</span><br>"
		link_code = ''.join(code)

		return json.dumps({'symbols':symbols,'symbol_table':symbol_table,'loadfile':loadfile,'pass1code':pass1code,'pass2code':pass2code,'link_code':link_code})
Example #5
0
def main():
    parser = argparse.ArgumentParser(
        prog="mipsal",
        description='Assemble and link a MIPS assembly program.')
    parser.add_argument("files",
                        action="store",
                        nargs="+",
                        type=str,
                        help="list of assembly files to process")
    parser.add_argument("--int",
                        action="store_true",
                        default=False,
                        help="output intermediate files")
    parser.add_argument("--obj",
                        action="store_true",
                        default=False,
                        help="output object files")
    parser.add_argument("-o",
                        action="store",
                        dest="out_name",
                        type=str,
                        default="mips.out",
                        help="override output file name",
                        metavar="file_name")
    parser.add_argument(
        "-l",
        "--link",
        action="append",
        help=
        "add file to program when linking. This option can be used more than once",
        metavar="file_name")
    args = parser.parse_args()

    obj_code = []
    for input_file in args.files:
        ints, objs = assembler.assemble(input_file)
        obj_code.append(objs)
        file_name = utils.get_file_name(input_file)
        if args.int:
            int_file = file_name + ".int"
            utils.write_file_from_list(int_file, ints)
        if args.obj:
            obj_file = file_name + ".o"
            utils.write_file_from_list(obj_file, objs)
    if args.link != None:
        for link_file in args.link:
            obj_code.append(
                [x.strip() for x in utils.read_file_to_list(link_file)])
    output = linker.link(obj_code)
    utils.write_file_from_list(args.out_name, output)
Example #6
0
File: nlp01.py Project: yniyec/NLP
priority = 0
# priority-Code -> 0=Longest priority search, 1=Shortest priority search

while i < length:

    if priority == 0:

        if scan[i] == "。" or scan[i] == "、" and scan[i + 1] != "\n":
            print(scan[i])
            print("[句点 or 読点]")
            print()
            i = i + 1

        while j >= i:

            openfile = linker.link(scan[i])

            for line in open(openfile, "r"):
                line = line.split(",")
                list(line)

                if scan[i:j] + "\n" == line[4] and int(line[3]) < min:
                    min = int(line[3])
                    out = line
                    flag = 1

            if flag == 0 and j >= i:
                if option == 0:
                    print(scan[i:j] + " is UN-HIT")
                j = j - 1
Example #7
0
import re
import assembler, linker, loader, machine

files = []
print 'Enter files to processed together (in order of execution):'
while True:
    print 'File Name:',
    fname = raw_input()
    if fname is '':
        break
    files.append(fname)
print 'Enter Offset:',
# offset=int(raw_input())
offset = 0

print ""
mainfile = files[-1].split('.')[0] + '.asm'
symbols, symbol_table = assembler.assemble(files)
linker.link(mainfile, symbols)
loader.load(mainfile, offset)
machine.convert(mainfile)

print '\nSymbol Table:'
for key in symbols:
    print 'File: ' + key
    print symbols[key]
Example #8
0
def generate():
    if request.method == 'POST':
        files = (request.form['files']).split(',')
        offset = int(request.form['offset'])

        loadfile = files[-1].split('.')[0]
        mainfile = loadfile + '.asm'
        symbols1, symbols, symbol_table = assembler.assemble(files)
        linker.link(mainfile, symbols)
        f = open("Output/" + loadfile + '.asm', 'r')
        data = f.read()
        f.close()
        finallink = ""
        data = data.splitlines()
        temp = []
        for line in data:
            if line.startswith('DC') or line.startswith('DM'):
                temp.append(line)
            else:
                finallink += line + "\n"
        for line in temp:
            finallink += line + "\n"
        f = open("Output/" + loadfile + "1" + '.asm', 'w')
        f.write(finallink)
        f.close()
        loader.load(mainfile, offset)
        machine.convert(mainfile)

        f = open("Output/" + loadfile + "1" + '.pass1', 'r')
        code = f.read()
        f.close()
        code = code.split('\n')
        for i in range(0, len(code)):
            code[i] = code[i].replace(' ', '&nbsp;')
            code[i] = "<span id=\"" + str(i +
                                          1) + "\">" + code[i] + "</span><br>"
        pass1code = ''.join(code)

        f = open("Output/" + loadfile + "1" + '.pass2', 'r')
        code = f.read()
        f.close()
        code = code.split('\n')
        for i in range(0, len(code)):
            code[i] = code[i].replace(' ', '&nbsp;')
            code[i] = "<span id=\"" + str(i +
                                          1) + "\">" + code[i] + "</span><br>"
        pass2code = ''.join(code)

        f = open("Output/" + loadfile + "1" + '.asm', 'r')
        code = f.read()
        f.close()
        code = code.split('\n')
        for i in range(0, len(code)):
            code[i] = code[i].replace(' ', '&nbsp;')
            code[i] = "<span id=\"" + str(i +
                                          1) + "\">" + code[i] + "</span><br>"
        link_code = ''.join(code)

        return json.dumps({
            'symbols': symbols1,
            'symbol_table': symbol_table,
            'loadfile': loadfile,
            'pass1code': pass1code,
            'pass2code': pass2code,
            'link_code': link_code
        })
Example #9
0
import re, compiler, linker, assembler, loader

files = []
offsets = []
print 'Enter file names(in descending order of execution):'
while True:
    print 'File Name:',
    fname = raw_input()
    if fname is '':
        break
    files.append(fname)
main = 'concatenated' + '.link'
symbols = compiler.convtoassembly(files)
print(symbols)
assembler.pass1(files)
assembler.pass2(files)
for filec in files:
    print '\nEnter Loading location for  ' + filec
    offset = int(raw_input())
    offsets.append(offset)
offsets2 = offsets[:]
linker.link(main, symbols, offsets)
loader.load('concatinated.link', offsets2)
import re, compiler, linker, assembler, loader
files = []
print 'Enter file names(in descending order of execution):'
while True:
    print 'File Name:',
    fname = raw_input()
    if fname is '':
        break
    files.append(fname)
main = 'concatenated' + '.link'
symbols = compiler.convtoassembly(files)
assembler.pass1(files)
assembler.pass2(files)
linker.link(main, symbols)
print '\nEnter Loading location'
offset = int(raw_input())
loader.load(main, offset)
Example #11
0
def runlin():
    linker.link(x)