Esempio n. 1
0
File: bacon.c Progetto: wbhart/bacon
int main(void)
{
   ast_t * a;
   int jval;
   jit_t * jit;
   
   GC_INIT();
   GREG g;
 
   ast_init();
   sym_tab_init();
   types_init();
   scope_init();
   loc_tab_init();
   intrinsics_init();
   jit = llvm_init();
   ZZ_init(jit);
   
   yyinit(&g);

   printf("Welcome to Bacon v0.1\n\n");
   printf("> ");

   while (1)
   {
      if (!(jval = setjmp(exc)))
      {
         if (!yyparse(&g))
         {
            printf("Error parsing\n");
            abort();
         } else if (root)
         {
#if DEBUG1
            printf("\n");
            ast_print(root, 0);
#endif
            inference(root);
#if DEBUG2
            printf("\n");
            /*ast2_print(root, 0);*/
#endif
            exec_root(jit, root);
            root = NULL;
         }
      } else if (jval == 1)
         root = NULL;
      else /* jval == 2 */
         break;
      
      printf("\n> ");
   }

   llvm_cleanup(jit);
   yydeinit(&g);
    
   printf("\n");

   return 0;
}
Esempio n. 2
0
static void _parse_parent_child_nonterminal(){

	ParserContext context;
	Ast ast;
	AstBuilder builder;

	_build_child_rule_fsm(&fix.parser.fsm);

	ast_init(&ast, NULL, &fix.parser.table);

	ast_builder_init(&builder, &ast);
	ast_builder_append_follow(&builder, &(Token){1, 1, 'a'});
	ast_builder_append(&builder, &(Token){2, 1, 'b'});
	ast_builder_append(&builder, &(Token){3, 1, 'c'});
	ast_builder_done(&builder);
	ast_builder_dispose(&builder);

	parser_context_init(&context, &fix.parser);

	parser_context_set_source_ast(&context, &ast);

	int error = parser_context_execute(&context);

	t_assert(!error);

	parser_context_dispose(&context);
	ast_dispose(&ast);
}
Esempio n. 3
0
/* wrap parse routines */
ast_node* parse() {
  ast_node* tree = ast_init();
  lookahead_1 = get_next_token(stdin);
  lookahead_2 = get_next_token(stdin);
  parse_program(tree);
  return tree;
}
Esempio n. 4
0
void _parser_basic_parse(){

	ParserContext context;
	Ast ast;
	AstBuilder builder;

	_build_simple_ab_fsm(&fix.parser.fsm);

	ast_init(&ast, NULL, &fix.parser.table);

	ast_builder_init(&builder, &ast);
	ast_builder_append_follow(&builder, &(Token){1, 1, 'a'});
	ast_builder_append(&builder, &(Token){2, 1, 'b'});
	ast_builder_done(&builder);
	ast_builder_dispose(&builder);

	parser_context_init(&context, &fix.parser);

	parser_context_set_source_ast(&context, &ast);

	int error = parser_context_execute(&context);

	t_assert(!error);

	parser_context_dispose(&context);
	ast_dispose(&ast);
}
Esempio n. 5
0
static void _parse_sibling_with_children_test(){

	ParserContext context;
	Ast ast;
	AstBuilder builder;

	_build_siblings_with_children(&fix.parser.fsm);

	ast_init(&ast, NULL, &fix.parser.table);

	ast_builder_init(&builder, &ast);
	ast_builder_append_follow(&builder, &(Token){1, 1, 'a'});
	ast_builder_append(&builder, &(Token){2, 1, 'b'});
	ast_builder_append(&builder, &(Token){3, 1, 'c'});
	ast_builder_parent(&builder);
	ast_builder_append_follow(&builder, &(Token){4, 1, 'd'});
	ast_builder_append(&builder, &(Token){5, 1, 'e'});
	ast_builder_append(&builder, &(Token){6, 1, 'f'});
	ast_builder_done(&builder);
	ast_builder_dispose(&builder);

	parser_context_init(&context, &fix.parser);

	parser_context_set_source_ast(&context, &ast);

	int error = parser_context_execute(&context);

	t_assert(!error);

	parser_context_dispose(&context);
	ast_dispose(&ast);
}
Esempio n. 6
0
File: main.c Progetto: arnognulf/v7
static void dump_ast(const char *code) {
  struct ast ast;

  ast_init(&ast, 0);
  aparse(&ast, code, 1);
  ast_dump(stdout, &ast, 0);
  ast_free(&ast);
}
Esempio n. 7
0
int main(void) {
    GC_INIT();
    GREG g;
 
    int jval, jval2;
    char c;

    sym_tab_init();
    ast_init();
    type_init();
    scope_init();
    rel_assign_init();

    jit_t * jit = llvm_init();

    yyinit(&g);

    printf("Welcome to Cesium v 0.2\n");
    printf("To exit press CTRL-D\n\n");

    printf("> ");

    while (1)
    {
       if (!(jval = setjmp(exc)))
       {
          if (!yyparse(&g))
          {
             printf("Error parsing\n");
             abort();
          } else if (root != NULL)
          {
             rel_stack_init();
             rel_assign_mark();
             scope_mark();
             annotate_ast(root);
             if (TRACE) 
                ast_print(root, 0);
             unify(rel_stack, rel_assign);
             if (TRACE)
                print_assigns(rel_assign);
             exec_root(jit, root);
             if (root->tag != AST_FNDEC)
                 rel_assign_rewind();
           }
        } else if (jval == 1)
              root = NULL;
        else if (jval == 2)
              break;
        printf("\n> ");
    }
  
    yydeinit(&g);
    llvm_cleanup(jit);

    return 0;
}
Esempio n. 8
0
void iiInit(FILE* file)
{
	yyset_in(file);

	gint i;
	for(i=0; i < NUM_TRAC_STATEMENTS; i++) {
		statementsSucceed[i] = 0;
		statementsFail[i] = 0;
	}
	
	fileList = NULL;
	dirList = NULL;
	
	timing_init();
	ast_init();
	var_init();
	//groups_init();
}
Esempio n. 9
0
void lke(void)
{
	char		buff[MAX_LINE];
	$DESCRIPTOR	(command, buff);
	uint4		status;
	short		len;
	bool		dcl;
	DCL_THREADGBL_ACCESS;

	GTM_THREADGBL_INIT;
	gtm_imagetype_init(LKE_IMAGE);
	gtm_env_init();	/* read in all environment variables */
	util_out_open(0);
	SET_EXIT_HANDLER(exi_blk, generic_exit_handler, exi_condition);	/* Establish exit handler */
	ESTABLISH(util_base_ch);
	status =lp_id(&lkid);
	if (SS$_NORMAL != status)
		rts_error(VARLSTCNT(1) status);
	get_page_size();
	stp_init(STP_INITSIZE);
	rts_stringpool = stringpool;
	getjobname();
	INVOKE_INIT_SECSHR_ADDRS;
	ast_init();
	initialize_pattern_table();
	gvinit();
	region_init(TRUE);
	getjobnum();
	status = lib$get_foreign(&command, 0, &len, 0);
	if ((status & 1) && len > 0)
	{
		command.dsc$w_length = len;
		status = CLI$DCL_PARSE(&command, &lke_cmd, &lib$get_input, 0, 0);
		if (CLI$_NORMAL == status)
		{
			util_out_open(&output_qualifier);
			CLI$DISPATCH();
			util_out_close();
		}
		lke_exit();
	}
	for (;;)
		lke_process();
}
Esempio n. 10
0
File: ast.c Progetto: vic/waxeye
struct ast_t* ast_new(enum ast_type type, union ast_data data) {
    struct ast_t *a = malloc(sizeof(struct ast_t));
    assert(a != NULL);
    ast_init(a, type, data);
    return a;
}
Esempio n. 11
0
mupip()
{
	unsigned int	status;
	int4		inid = 0;
	int4		nid = 0;		/* system ID, node number */
	int4		days = 128;		/* days to expiration	*/
	int4		lic_x = 0;		/* license value	*/
	char		*h = NULL;		/* license data base	*/
	char		*pak = NULL;		/* pak record		*/
	int4		mdl = 0;		/* hardw. model type	*/
	$DESCRIPTOR(dprd, gtm_product);
	$DESCRIPTOR(dver, gtm_version);
	DCL_THREADGBL_ACCESS;

	GTM_THREADGBL_INIT;
	gtm_imagetype_init(MUPIP_IMAGE);
	gtm_env_init();	/* read in all environment variables */
	licensed = TRUE;
	TREF(transform) = TRUE;
	in_backup = FALSE;
	util_out_open(0);
	SET_EXIT_HANDLER(exi_blk, generic_exit_handler, exi_condition);	/* Establish exit handler */
	ESTABLISH(util_base_ch);
	get_page_size();
	getjobnum();
	INVOKE_INIT_SECSHR_ADDRS;
#	ifdef	NOLICENSE
	status = SS$_NORMAL;
	lid = 1;
	lic_x = 32767;
#	else
	if (NULL == (h = la_getdb(LMDB)))		/* license db in mem */
		status = LP_NOCNFDB;
	else
		status = SS$_NORMAL;
	if (1 == (status & 1))				/* licensing: node+ system  */
		status = lm_mdl_nid(&mdl, &nid, &inid);
	if (1 == (status & 1))				/* licensing: license */
	{
		dprd.dsc$w_length = gtm_product_len;
		dver.dsc$w_length = gtm_version_len;
		status = lp_licensed(h, &dprd, &dver, mdl, nid, &lid, &lic_x, &days, pak);
	}
#	endif
	if (1 == (status & 1))					/* licensing: license units  */
		status = LP_ACQUIRE(pak, lic_x, lid, &lkid);	/* def in cryptdef */
#	ifdef	NOLICENSE
	status = SS$_NORMAL;
#	else
	if (LP_NOCNFDB != status)
		la_freedb(h);
	if (1 == (status & 1))					/* licensing */
	{
		if (days < 14)
			lm_putmsgu(ERR_WILLEXPIRE, 0, 0);
	}
	else
	{
		licensed = FALSE;
		if (LP_INVCSM != status)
			rts_error(VARLSTCNT(1) status);
	}
#	endif
	ast_init();
	initialize_pattern_table();
	INIT_GBL_ROOT();
	stp_init(STP_INITSIZE);
	rts_stringpool = stringpool;
	mupip_getcmd();
	mupip_exit(SS$_NORMAL);
}
Esempio n. 12
0
/**
 * \brief Main Application Routine
 *  - Initialize the system clocks
 *  - Initialize the sleep manager
 *  - Initialize the power save measures
 *  - Initialize the ACIFB module
 *  - Initialize the AST to trigger ACIFB at regular intervals
 *  - Go to STATIC sleep mode and wake up on a touch status change
 */
int main(void)
{
	/* Switch on the STATUS LED */
	gpio_clr_gpio_pin(STATUS_LED);
	/* Switch off the error LED. */
	gpio_set_gpio_pin(ERROR_LED);

	/*
	 * Initialize the system clock.
	 * Note: Clock settings are specified in conf_clock.h
	 */
	sysclk_init();

	/*
	 * Initialize the sleep manager.
	 * Note: CONFIG_SLEEPMGR_ENABLE should have been defined in conf_sleepmgr.h
	 */
	sleepmgr_init();
	/* Lock required sleep mode. */
	sleepmgr_lock_mode(SLEEPMGR_STATIC);

	/* Initialize the delay routines */
	delay_init(sysclk_get_cpu_hz());

	/* Initialize the power saving features */
	power_save_measures_init();

	/* Switch off the error LED. */
	gpio_set_gpio_pin(ERROR_LED);

#if DEBUG_MESSAGES
	/* Enable the clock to USART interface */
	sysclk_enable_peripheral_clock(DBG_USART);
	/* Initialize the USART interface to print trace messages */
	init_dbg_rs232(sysclk_get_pba_hz());

	print_dbg("\r Sleepwalking with ACIFB Module in UC3L \n");
	print_dbg("\r Initializing ACIFB Module..... \n");
#endif

	/* Initialize the Analog Comparator peripheral */
	if (ac_init() != STATUS_OK) {
#if DEBUG_MESSAGES
		/* Error initializing the ACIFB peripheral */
		print_dbg("\r Error initializing Analog Comparator module \n");
#endif
		while (1) {
			delay_ms(LED_DELAY);
			gpio_tgl_gpio_pin(ERROR_LED);
		}
	}

#if DEBUG_MESSAGES
	print_dbg("\r ACIFB Module initialized. \n");
	print_dbg("\r Initializing AST Module..... \n");
#endif

	/* Initialize the AST peripheral */
	if (ast_init() != STATUS_OK) {
#if DEBUG_MESSAGES
		print_dbg("\r Error initializing AST module \n");
#endif
		/* Error initializing the AST peripheral */
		while (1) {
			delay_ms(LED_DELAY);
			gpio_tgl_gpio_pin(ERROR_LED);
		}
	}

#if DEBUG_MESSAGES
	print_dbg("\r AST Module initialized. \n");
#endif

	/* Application routine */
	while (1) {
		/* Enable Asynchronous wake-up for ACIFB */
		pm_asyn_wake_up_enable(AVR32_PM_AWEN_ACIFBWEN_MASK);

#if DEBUG_MESSAGES
		print_dbg("\r Going to STATIC sleep mode \n");
		print_dbg(
				"\r Wake up only when input is higher than threshold \n");
#endif

		/* Switch off the status LED */
		gpio_set_gpio_pin(STATUS_LED);
		/* Disable GPIO clock before entering sleep mode */
		sysclk_disable_pba_module(SYSCLK_GPIO);
		AVR32_INTC.ipr[0];
		/* Enter STATIC sleep mode */
		sleepmgr_enter_sleep();
		/* Enable GPIO clock after waking from sleep mode */
		sysclk_enable_pba_module(SYSCLK_GPIO);
		/* Switch on the status LED */
		gpio_clr_gpio_pin(STATUS_LED);

#if DEBUG_MESSAGES
		print_dbg("\r Output higher than threshold \n");
		print_dbg("\n");
#else
		/* LED on for few ms */
		delay_ms(LED_DELAY);
#endif

		/* Clear the wake up & enable it to enter sleep mode again */
		pm_asyn_wake_up_disable(AVR32_PM_AWEN_ACIFBWEN_MASK);
		/* Clear All AST Interrupt request and clear SR */
		ast_clear_all_status_flags(&AVR32_AST);
	}

	return 0;
} /* End of main() */
Esempio n. 13
0
void t_setup(){
	input_init_buffer(&fix.input, buffer, strlen(buffer));
	symbol_table_init(&fix.table);
	ast_init(&fix.ast, &fix.input, &fix.table);
}
Esempio n. 14
0
gtcm_server()
{
	static readonly int4	reptim[2] = {-100000, -1};	/* 10ms */
       	static readonly int4	wait[2] =  {-1000000, -1};	/* 100ms */
	void		gtcm_ch(), gtcm_exi_handler(), gtcm_init_ast(), gtcm_int_unpack(), gtcm_mbxread_ast(),
			gtcm_neterr(), gtcm_read_ast(), gtcm_remove_from_action_queue(), gtcm_shutdown_ast(), gtcm_write_ast(),
			la_freedb();
	bool		gtcm_link_accept();
	bool		alid;
	char		buff[512];
	char		*h = NULL;
	char		*la_getdb();
	char		nbuff[256];
	char		*pak = NULL;
	char		reply;
	unsigned short	outlen;
	int4		closewait[2] = {0, -1};
	int4		inid = 0, mdl = 0, nid = 0, days = 0;
	int4		lic_status;
	int4		lic_x;
	int4		lm_mdl_nid();
	uint4		status;
	int		i, receive(), value;
	mstr		name1, name2;
	struct NTD	*cmu_ntdroot();
	connection_struct *prev_curr_entry;
	struct	dsc$descriptor_s	dprd;
	struct	dsc$descriptor_s	dver;
	$DESCRIPTOR(node_name, nbuff);
	$DESCRIPTOR(proc_name, "GTCM_SERVER");
	$DESCRIPTOR(timout, buff);
	DCL_THREADGBL_ACCESS;

	GTM_THREADGBL_INIT;
        assert(0 == EMPTY_QUEUE);       /* check so dont need gdsfhead everywhere */
	common_startup_init(GTCM_GNP_SERVER_IMAGE); /* Side-effect: Sets skip_dbtriggers to TRUE for non-trigger platforms */
	gtm_env_init();	/* read in all environment variables */
	name1.addr = "GTCMSVRNAM";
	name1.len = SIZEOF("GTCMSVRNAM") - 1;
	status = trans_log_name(&name1, &name2, nbuff);
	if (SS$_NORMAL == status)
	{
		proc_name.dsc$a_pointer = nbuff;
		proc_name.dsc$w_length = node_name.dsc$w_length = name2.len;
	} else if (SS$_NOLOGNAM == status)
	{
		MEMCPY_LIT(nbuff, "GTCMSVR");
		node_name.dsc$w_length = SIZEOF("GTCMSVR") - 1;
	} else
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) status);
	sys$setprn(&proc_name);
	status = lib$get_foreign(&timout, 0, &outlen, 0);
	if ((status & 1) && (6 > outlen))
	{
		for (i = 0;  i < outlen;  i++)
		{
			value = value * 10;
			if (buff[i] <= '9' && buff[i] >= '0')
				value += buff[i] - 48;
			else
				break;
		}
		if (outlen && (i == outlen))
		{
			cm_timeout = TRUE;
			closewait[0] = value * -10000000;
		}
	}
	dprd.dsc$w_length = cm_prd_len;
	dprd.dsc$b_dtype  = DSC$K_DTYPE_T;
	dprd.dsc$b_class  = DSC$K_CLASS_S;
	dprd.dsc$a_pointer= cm_prd_name;
	dver.dsc$w_length = cm_ver_len;
	dver.dsc$b_dtype  = DSC$K_DTYPE_T;
	dver.dsc$b_class  = DSC$K_CLASS_S;
	dver.dsc$a_pointer= cm_ver_name;
	ast_init();
	licensed = TRUE;
	lkid = 2;
#	ifdef NOLICENSE
	lid = 1;
#	else
	/* this code used to be scattered to discourage reverse engineering, but since it now disabled, that seems pointless */
	lic_status = ((NULL == (h = la_getdb(LMDB))) ? LP_NOCNFDB : SS$_NORMAL);
	lic_status = ((1 == (lic_status & 1)) ? lm_mdl_nid(&mdl, &nid, &inid) : lic_status);
	lic_status = ((1 == (lic_status & 1)) ? lp_licensed(h, &dprd, &dver, mdl, nid, &lid, &lic_x, &days, pak) : lic_status);
	if (LP_NOCNFDB != lic_status)
		la_freedb(h);
	if (1 == (lic_status & 1))
	{
		licensed = TRUE;
		if (days < 14)
			rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_WILLEXPIRE);
	} else
	{
		licensed = FALSE;
		sys$exit(lic_status);
	}
#	endif
	gtcm_ast_avail = astq_dyn_avail - GTCM_AST_OVRHD;
	stp_init(STP_INITSIZE);
	rts_stringpool = stringpool;
	cache_init();
	procnum = 0;
	get_proc_info(0, TADR(login_time), &image_count);
        memset(proc_to_clb, 0, SIZEOF(proc_to_clb));
	status = cmi_init(&node_name, 0, 0, gtcm_init_ast, gtcm_link_accept);
	if (!(status & 1))
	{
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ((status ^ 3) | 4));
		sys$exit(status);
	}
	ntd_root = cmu_ntdroot();
	ntd_root->mbx_ast =  gtcm_mbxread_ast;
	ntd_root->err = gtcm_neterr;
	gtcm_connection = FALSE;
	lib$establish(gtcm_ch);
	gtcm_exi_blk.exit_hand = &gtcm_exi_handler;
	gtcm_exi_blk.arg_cnt = 1;
	gtcm_exi_blk.cond_val = &gtcm_exi_condition;
	sys$dclexh(&gtcm_exi_blk);
	INVOKE_INIT_SECSHR_ADDRS;
	initialize_pattern_table();
	assert(run_time); /* Should have been set by common_startup_init */
	while (!cm_shutdown)
	{
		if (blkdlist)
			gtcml_chkreg();

		assert(!lib$ast_in_prog());
		status = sys$dclast(&gtcm_remove_from_action_queue, 0, 0);
		if (SS$_NORMAL != status)
			rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) CMERR_CMSYSSRV, 0, status, 0);
		if (INTERLOCK_FAIL == curr_entry)
			rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) CMERR_CMINTQUE);
		if (EMPTY_QUEUE != curr_entry)
		{
			switch (*curr_entry->clb_ptr->mbf)
			{
				case CMMS_L_LKCANALL:
					reply = gtcmtr_lkcanall();
					break;
				case CMMS_L_LKCANCEL:
					reply = gtcmtr_lkcancel();
					break;
				case CMMS_L_LKREQIMMED:
					reply = gtcmtr_lkreqimmed();
					break;
				case CMMS_L_LKREQNODE:
					reply = gtcmtr_lkreqnode();
					break;
				case CMMS_L_LKREQUEST:
					reply = gtcmtr_lkrequest();
					break;
				case CMMS_L_LKRESUME:
					reply = gtcmtr_lkresume();
					break;
				case CMMS_L_LKACQUIRE:
					reply = gtcmtr_lkacquire();
					break;
				case CMMS_L_LKSUSPEND:
					reply = gtcmtr_lksuspend();
					break;
				case CMMS_L_LKDELETE:
					reply = gtcmtr_lkdelete();
					break;
				case CMMS_Q_DATA:
					reply = gtcmtr_data();
					break;
				case CMMS_Q_GET:
					reply = gtcmtr_get();
					break;
				case CMMS_Q_KILL:
					reply = gtcmtr_kill();
					break;
				case CMMS_Q_ORDER:
					reply = gtcmtr_order();
					break;
				case CMMS_Q_PREV:
					reply = gtcmtr_zprevious();
					break;
				case CMMS_Q_PUT:
					reply = gtcmtr_put();
					break;
				case CMMS_Q_QUERY:
					reply = gtcmtr_query();
					break;
				case CMMS_Q_ZWITHDRAW:
					reply = gtcmtr_zwithdraw();
					break;
				case CMMS_S_INITPROC:
					reply = gtcmtr_initproc();
					break;
				case CMMS_S_INITREG:
					reply = gtcmtr_initreg();
					break;
				case CMMS_S_TERMINATE:
					reply = gtcmtr_terminate(TRUE);
					break;
				case CMMS_E_TERMINATE:
					reply = gtcmtr_terminate(FALSE);
					break;
				case CMMS_U_LKEDELETE:
					reply = gtcmtr_lke_clearrep(curr_entry->clb_ptr, curr_entry->clb_ptr->mbf);
					break;
				case CMMS_U_LKESHOW:
					reply = gtcmtr_lke_showrep(curr_entry->clb_ptr, curr_entry->clb_ptr->mbf);
					break;
				case CMMS_B_BUFRESIZE:
					reply = CM_WRITE;
					value = *(unsigned short *)(curr_entry->clb_ptr->mbf + 1);
					if (value > curr_entry->clb_ptr->mbl)
					{
						free(curr_entry->clb_ptr->mbf);
						curr_entry->clb_ptr->mbf = malloc(value);
					}
					*curr_entry->clb_ptr->mbf = CMMS_C_BUFRESIZE;
					curr_entry->clb_ptr->mbl = value;
					curr_entry->clb_ptr->cbl = 1;
					break;
				case CMMS_B_BUFFLUSH:
					reply = gtcmtr_bufflush();
					break;
				case CMMS_Q_INCREMENT:
					reply = gtcmtr_increment();
					break;
				default:
					reply = FALSE;
					if (SS$_NORMAL == status)
                                                rts_error_csa(CSA_ARG(NULL)
							VARLSTCNT(3) ERR_BADGTMNETMSG, 1, (int)*curr_entry->clb_ptr->mbf);
					break;
			}
			if (curr_entry)		/* curr_entry can be NULL if went through gtcmtr_terminate */
			{
				status = sys$gettim(&curr_entry->lastact[0]);
				if (SS$_NORMAL != status)
					rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) status);
				/* curr_entry is used by gtcm_mbxread_ast to determine if it needs to defer the interrupt message */
				prev_curr_entry = curr_entry;
				if (CM_WRITE == reply)
				{	/* if ast == gtcm_write_ast, let it worry */
					curr_entry->clb_ptr->ast = gtcm_write_ast;
					curr_entry = EMPTY_QUEUE;
					cmi_write(prev_curr_entry->clb_ptr);
				} else
				{
					curr_entry = EMPTY_QUEUE;
					if (1 == (prev_curr_entry->int_cancel.laflag & 1))
					{  /* valid interrupt cancel msg, handle in gtcm_mbxread_ast */
						status = sys$dclast(gtcm_int_unpack, prev_curr_entry, 0);
						if (SS$_NORMAL != status)
							rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) status);
					} else  if (CM_READ == reply)
					{
						prev_curr_entry->clb_ptr->ast = gtcm_read_ast;
						cmi_read(prev_curr_entry->clb_ptr);
					}
				}
			}
		} else  if (1 < astq_dyn_avail)
		{
#			ifdef GTCM_REPTIM
			/* if reptim is not needed - and smw doesn't know why it would be - remove this	*/
			status = sys$schdwk(0, 0, &wait[0], &reptim[0]);
#			else
			status = sys$schdwk(0, 0, &wait[0], 0);
#			endif
			sys$hiber();
			sys$canwak(0, 0);
		}
		if (cm_timeout && (0 == gtcm_users))
                        sys$setimr(efn_ignore, closewait, gtcm_shutdown_ast, &cm_shutdown, 0);
	}
}
Esempio n. 15
0
/**
 * \brief Main Application Routine
 *  - Initialize the system clocks
 *  - Initialize the sleep manager
 *  - Initialize the power save measures
 *  - Initialize the touch library and sensors
 *  - Initialize the AST to trigger CAT at regular intervals
 *  - Go to STATIC sleep mode and wake up on a touch status change
 */
int main(void)
{
#if DEF_TOUCH_QDEBUG_ENABLE == 1
	uint32_t delay_counter;
#endif
	uint32_t i;
	/* Switch on the STATUS LED */
	gpio_clr_gpio_pin(STATUS_LED);
	/* Switch off the error LED. */
	gpio_set_gpio_pin(ERROR_LED);

	/*
	 * Initialize the system clock.
	 * Note: Clock settings are specified in conf_clock.h
	 */
	sysclk_init();

	/*
	 * Initialize the sleep manager.
	 * Note: CONFIG_SLEEPMGR_ENABLE should have been defined in conf_sleepmgr.h
	 */
	sleepmgr_init();
	/* Lock required sleep mode. */
	sleepmgr_lock_mode(SLEEPMGR_STATIC);

	/* Initialize the power saving features */
	power_save_measures_init();

	/* Switch off the error LED. */
	gpio_set_gpio_pin(ERROR_LED);

#if DEF_TOUCH_QDEBUG_ENABLE == 0
	/* Initialize the AST peripheral */
	if (ast_init() != STATUS_OK) {
		/* Error initializing the AST peripheral */
		while (1) {
			for (i = 0; i < 10000; i++) {
			}
			gpio_tgl_gpio_pin(ERROR_LED);
		}
	}

#endif

	/* Initialize the touch library */
	if (touch_api_init() != STATUS_OK) {
		/* Error initializing the touch sensors */
		while (1) {
			for (i = 0; i < 10000; i++) {
			}
			gpio_tgl_gpio_pin(ERROR_LED);
		}
	}

#if DEF_TOUCH_QDEBUG_ENABLE == 1
	/* Enable PBA clock for AST clock to switch its source */
	sysclk_enable_peripheral_clock(QDEBUG_USART);
	/* 
	 * Initialize the QDebug interface.
	 * QT600 USB Bridge two-way QDebug communication.
	 */
	QDebug_Init();
#endif

	/* Turn OFF the Status LED */
	gpio_set_gpio_pin(STATUS_LED);

	/* Loop forever */
	while (1) {
#if DEF_TOUCH_QDEBUG_ENABLE == 1
		/* Process any commands received from QTouch Studio. */
		QDebug_ProcessCommands();

		/*
		 * Send out the Touch debug information data each time when
		 * Touch measurement process is completed.
		 * param - 0x000A -> Enable TOUCH_STATUS_CHANGE &
		 * TOUCH_CHANNEL_REF_CHANGE
		 * qt_lib_flags always for Autonomous QTouch.
		 */
		QDebug_SendData(0x000A);

		/* Delay to avoid sending the data to QTouch Studio too frequently. */
		for (delay_counter = 0u; delay_counter < 1200u;
				delay_counter++) {
		}

#else
		/* Enable Asynchronous Wakeup for CAT module */
		pm_asyn_wake_up_enable(AVR32_PM_AWEN_CATWEN_MASK);
		/* Disable GPIO clock after waking from sleep mode */
		sysclk_disable_pba_module(SYSCLK_GPIO);

		/* Enter STATIC sleep mode */
		sleepmgr_enter_sleep();

		/* Disable Asynchronous Wakeup for CAT module. */
		pm_asyn_wake_up_disable(AVR32_PM_AWEN_CATWEN_MASK);

		/* Clear All AST Interrupt request and clear SR */
		ast_clear_all_status_flags(&AVR32_AST);

		/**
		 * When woken up by Autonomous QTouch interrupt, the
		 * touch_at_status_change_interrupt_callback() is called that
		 * updates the autonomous_qtouch_in_touch status flag.
		 */

		/* Host application code goes here */
#endif
	}
} /* End of main() */
Esempio n. 16
0
int main(int argc, char** argv) {
    if(argc != 2 && argc != 3) {
        c_print_format("Usage: %s FILE [cartridge/folder]\n", argv[0]);
        return 0;
    }
    Arena arena = arena_create(MB(512));

    String cartridge_folder_path_name = (argc > 2)
        ? string_from_c_string(argv[2])
        : L("SuperMarioWorld.sfc");
    Path cartridge_folder_path;
    path_init(&cartridge_folder_path, cartridge_folder_path_name);
    Path manifest_path;
    path_init_from_c(&manifest_path, &cartridge_folder_path, "manifest.bml");
    Buffer manifest_buffer = path_read_file(&manifest_path, &arena);

    Wdc65816MapperBuilder rom_builder = { };
    
    char name[256];
    Buffer name_buffer = buffer(name, 256);
    Buffer rom_buffer;
    for(Wdc65816RomLoader loader = wdc65816_rom_loader_begin(&rom_builder,
                                                             string_from_buffer(manifest_buffer));
        wdc65816_rom_loader_end(&loader);
        wdc65816_rom_loader_next(&loader)) {
        Wdc65816MemoryBufferRequest request = wdc65816_rom_loader_get_buffer_request(&loader,
                                                                                     name_buffer);
        Buffer file_buffer = buffer(arena_alloc_array(&arena, request.size, u8), request.size);
        if(string_equal(request.name, L("program.rom")) &&
           request.type == WDC65816_MEMORY_ROM) {
            rom_buffer = file_buffer;
        }
        wdc65816_rom_loader_set_buffer(&loader, file_buffer);
    }

    uint mapper_buffer_size = wdc65816_mapper_get_buffer_size();
    u8* work_buffer = arena_alloc_array(&arena, mapper_buffer_size, u8);
    Wdc65816Mapper rom;
    wdc65816_mapper_init(&rom, &rom_builder, (u8**)work_buffer);

    nuts_global_init();

    Path working_dir;
    path_init_working_directory(&working_dir);
    FreeList sentinel;
    free_list_init(&sentinel);
    ErrorList error_list;
    error_list_init(&error_list, arena_subarena(&arena, MB(10)));


    AST ast;
    ast_init(&ast, &arena);
    String file_name = string_from_c_string(argv[1]); 
    /* struct timespec lex_start,      lex_end,      lex_time = { 0 }; */
    /* struct timespec parse_start,    parse_end,    parse_time = { 0 }; */
    /* struct timespec assemble_start, assemble_end, assemble_time = { 0 }; */
    /* struct timespec all_start,      all_end,      all_time; */
    

    /* clock_gettime(CLOCK_REALTIME, &all_start); */
    Parser parser;
    parser_init(&parser, &arena, &sentinel, &error_list, &ast);
    int error_num = 0;
    while(1) {
        Path file;
        path_init(&file, file_name);
        Buffer file_buffer = path_read_file(&file, &arena);
        TokenList token_list;
        //c_print_format("read %.*s\n", file_name.length, file_name.data);
        Text file_text = {
            .buffer = file_buffer,
            .name   = file_name
        };
        /* clock_gettime(CLOCK_REALTIME, &lex_start); */
        Result result = lex(file_text, &token_list, &arena, &error_list, &ast.identifier_map);
        if(result == RESULT_ERROR) {
            for(;error_num < error_list.length; error_num++) {
                describe_error(error_list.errors[error_num]);
            }
        }
        /* clock_gettime(CLOCK_REALTIME, &lex_end); */
        /* lex_time = timespec_add(lex_time, timespec_sub(lex_start, lex_end)); */
        /* clock_gettime(CLOCK_REALTIME, &parse_start); */
        /* result = parse(&parser, token_list); */
        /* clock_gettime(CLOCK_REALTIME, &parse_end); */
        /* parse_time = timespec_add(parse_time, timespec_sub(parse_start, parse_end)); */

        if(result == RESULT_NEED_TOKEN_STREAM) {
            file_name = parser.needed_token_stream_file_name;
            continue;
        } else if(result == RESULT_OK) {
            break;
        } else if(result == RESULT_ERROR) {
            for(;error_num < error_list.length; error_num++) {
                describe_error(error_list.errors[error_num]);
            }
            return 1;
        } else {
            invalid_code_path;
        }
    }

    /* clock_gettime(CLOCK_REALTIME, &assemble_start); */
    Assembler assembler;
    assembler_init(&assembler, &error_list, &ast, &rom);
    Result result = RESULT_ERROR;
    while(result != RESULT_OK) {
        result = assemble(&assembler);
        if(result == RESULT_NEED_FILE) {
            String file_name = assembler_get_file_name(&assembler);
            Path file;
            path_init(&file, file_name);
            Buffer file_buffer = path_read_file(&file, &arena);
            assembler_give_buffer(&assembler, file_buffer);
        } else if(result == RESULT_ERROR) {
            break;
        }
    }
    /* clock_gettime(CLOCK_REALTIME, &assemble_end); */
    /* assemble_time = timespec_add(assemble_time, timespec_sub(assemble_start, assemble_end)); */

    for(int i = 0; i < error_list.length; i++) {
        describe_error(error_list.errors[i]);
    }

    /* parser_deinit(&parser); */
    /* clock_gettime(CLOCK_REALTIME, &all_end); */
    /* all_time = timespec_sub(all_start, all_end); */
    /* c_print_format("Lex:      %li.%06lims\n",      lex_time.tv_sec * 1000 +      lex_time.tv_nsec / 1000000,      lex_time.tv_nsec % 1000000); */
    /* c_print_format("Parse:    %li.%06lims\n",    parse_time.tv_sec * 1000 +    parse_time.tv_nsec / 1000000,    parse_time.tv_nsec % 1000000); */
    /* c_print_format("Assemble: %li.%06lims\n", assemble_time.tv_sec * 1000 + assemble_time.tv_nsec / 1000000, assemble_time.tv_nsec % 1000000); */
    /* c_print_format("All:      %li.%06lims\n",      all_time.tv_sec * 1000 +      all_time.tv_nsec / 1000000,      all_time.tv_nsec % 1000000); */

    Path rom_path;
    path_create_from(&rom_path, &cartridge_folder_path, L("program.rom"));
    path_write_file(&rom_path, rom_buffer);
    
    return 0;
}