public ScriptDefinition assemble(InputStream in) throws IOException
	{
		// Get our lexer
		rs2asmLexer lexer = new rs2asmLexer(new ANTLRInputStream(new InputStreamReader(in, StandardCharsets.UTF_8)));

		LexerErrorListener errorListener = new LexerErrorListener();
		lexer.addErrorListener(errorListener);

		// Get a list of matched tokens
		CommonTokenStream tokens = new CommonTokenStream(lexer);

		// Pass the tokens to the parser
		rs2asmParser parser = new rs2asmParser(tokens);

		// Specify our entry point
		ProgContext progContext = parser.prog();

		if (errorListener.getErrors() > 0)
		{
			throw new RuntimeException("syntax error");
		}

		// Walk it and attach our listener
		ParseTreeWalker walker = new ParseTreeWalker();

		// walk through first and resolve labels
		LabelVisitor labelVisitor = new LabelVisitor();
		walker.walk(labelVisitor, progContext);

		ScriptWriter listener = new ScriptWriter(instructions, labelVisitor);
		walker.walk(listener, progContext);

		return listener.buildScript();
	}
@Test
	public void testAssemble() throws Exception
	{
		InputStream in = AssemblerTest.class.getResourceAsStream(script);
		Assert.assertNotNull(in);

		Instructions instructions = new Instructions();
		instructions.init();

		Assembler assembler = new Assembler(instructions);
		ScriptDefinition script = assembler.assemble(in);

		// compare with disassembler
		Disassembler disassembler = new Disassembler();
		String out = disassembler.disassemble(script);

		in = AssemblerTest.class.getResourceAsStream(this.script);
		Assert.assertNotNull(in);

		String original = new String(IOUtils.toByteArray(in), StandardCharsets.UTF_8).replaceAll("\r\n", "\n");

		logger.info(original);
		logger.info("-----------------------");
		logger.info(out);

		Assert.assertEquals(original, out);
	}