Exemplo n.º 1
0
def main():
	if len(sys.argv) < 2:
		print "usage:"
		print "  java Oodle filename"
		return

	#HACK - add readint() and writeint() declarations
	G.typeMap().addExtern(ExternDecl('readint', 'int'))
	G.typeMap().addExtern(ExternDecl('writeint')).addParam(LocalVarDecl('i', 'int'))

	G.options().parseArgs(sys.argv[1:])

	flist = G.fileConcat ()
	for f in G.options().getFileList():
		flist.appendFile(f)

	st_node = None
	print 'Lexing...'
	lex = Lexer(flist.getConcatFile().getAbsolutePath())
	print 'Parsing...'
	par = Parser(lex)
	try:
		st_node = par.parse()
	except ParserException, e:
		G.errors().syntax().add(e.getMessage())
Exemplo n.º 2
0
def main():
    if len(sys.argv) < 2:
        print "usage:"
        print "  java Oodle filename"
        return

    #HACK - add readint() and writeint() declarations
    G.typeMap().addExtern(ExternDecl('readint', 'int'))
    G.typeMap().addExtern(ExternDecl('writeint')).addParam(
        LocalVarDecl('i', 'int'))

    G.options().parseArgs(sys.argv[1:])

    flist = G.fileConcat()
    for f in G.options().getFileList():
        flist.appendFile(f)

    st_node = None
    print 'Lexing...'
    lex = Lexer(flist.getConcatFile().getAbsolutePath())
    print 'Parsing...'
    par = Parser(lex)
    try:
        st_node = par.parse()
    except ParserException, e:
        G.errors().syntax().add(e.getMessage())
Exemplo n.º 3
0
	def printNoError(self, tok_name, txt=None):
		'''Print non-error messages
		   @tok_name: token name
		   @txt: custom token text'''
		#don't display tokens when -ds option is off
		if not G.options().displayTokens():
			return
		self.printMsg(tok_name, txt)
Exemplo n.º 4
0
    def buildBinary(self, sopt=False):
        '''generate the binary using GCC
		   if -S option is given, the generates a *.s assembly file instead'''
        #make new file with .s extension
        fn = G.options().getFileList()[-1]
        fn = fn[:fn.rfind('.ood')]
        asm_fn = fn + '.s'
        bin_fn = fn
        f = file(asm_fn, 'w')

        #write asm to .s file
        for l in self.asm_list:
            f.write(l)
            f.write('\n')
        f.write('\t.data\n')
        for l in self.asm_data_list:
            f.write(l)
            f.write('\n')
        f.write('\t.text\n')
        for l in self.asm_text_list:
            f.write(l)
            f.write('\n')
        f.flush()
        f.close()

        #do not build the binary if -S is given
        if sopt:
            return

        #compile asm with stdlib.c
        proc = subprocess.Popen(
            ['gcc', '-g', '-m32', '-o', bin_fn, 'stdlib.c', asm_fn])
        proc.wait()
        if proc.stderr:
            print '------------------'
            print 'GCC Error Output:'
            print '------------------'
            print proc.stderr
Exemplo n.º 5
0
	def buildBinary(self, sopt=False):
		'''generate the binary using GCC
		   if -S option is given, the generates a *.s assembly file instead'''
		#make new file with .s extension
		fn = G.options().getFileList()[-1]
		fn = fn[:fn.rfind('.ood')]
		asm_fn = fn + '.s'
		bin_fn = fn
		f = file(asm_fn, 'w')
		
		#write asm to .s file
		for l in self.asm_list:
			f.write(l)
			f.write('\n')
		f.write('\t.data\n')
		for l in self.asm_data_list:
			f.write(l)
			f.write('\n')
		f.write('\t.text\n')
		for l in self.asm_text_list:
			f.write(l)
			f.write('\n')
		f.flush()
		f.close()

		#do not build the binary if -S is given
		if sopt:
			return

		#compile asm with stdlib.c
		proc = subprocess.Popen(['gcc', '-g', '-m32', '-o', bin_fn, 'stdlib.c', asm_fn])
		proc.wait()
		if proc.stderr:
			print '------------------'
			print 'GCC Error Output:'
			print '------------------'
			print proc.stderr
Exemplo n.º 6
0
    def printFunc(self, f, node=None):
        '''print the name of the node function and its node string
		   only works if 'printDebug()' is enabled'''
        n = (': ' + node.toString().strip()) if node else ''
        if G.options().printDebug():
            print 'TypeMapBuilder: ' + f.__name__ + n
Exemplo n.º 7
0
	def printFunc(self, f, node=None):
		'''print the name of the node function and its node string
		   only works if 'printDebug()' is enabled'''
		n = (': ' + node.toString().strip()) if node else ''
		if G.options().printDebug():
			print 'CodeGenx86: ' + f.__name__ + n
Exemplo n.º 8
0
	if G.errors().hasErrors():
		G.errors().printErrors()
		return

	#Pass 1
	#build the TypeMap for all the input
	print 'Building Type Map...'
	tp_map_builder = TypeMapBuilder()
	st_node.apply(tp_map_builder)  #invoke TypeMapBuilder traversal

	#Pass 2
	#perform semantic checks (new code)
	print 'Error Checking...'
	sem_check = SemanticChecker()
	st_node.apply(sem_check)  #invoke SemanticChecker traversal

	if G.errors().hasErrors():
		print str(G.typeMap())
		G.errors().printErrors()
		return

	print 'Compiling...'
	code_gen = CodeGenx86()
	st_node.apply(code_gen)
	code_gen.buildBinary(G.options().generateAssembly())
	
	print 'DONE'

if __name__ == "__main__":
	main()
Exemplo n.º 9
0
        G.errors().printErrors()
        return

    #Pass 1
    #build the TypeMap for all the input
    print 'Building Type Map...'
    tp_map_builder = TypeMapBuilder()
    st_node.apply(tp_map_builder)  #invoke TypeMapBuilder traversal

    #Pass 2
    #perform semantic checks (new code)
    print 'Error Checking...'
    sem_check = SemanticChecker()
    st_node.apply(sem_check)  #invoke SemanticChecker traversal

    if G.errors().hasErrors():
        print str(G.typeMap())
        G.errors().printErrors()
        return

    print 'Compiling...'
    code_gen = CodeGenx86()
    st_node.apply(code_gen)
    code_gen.buildBinary(G.options().generateAssembly())

    print 'DONE'


if __name__ == "__main__":
    main()