void DoDo(void)
{
        char code[MAXMSG];
        char l1[MAXLBL];
        char l2[MAXLBL];

        Match('d');
        NewLabel();
        strncpy(l1, label, MAXLBL);
        NewLabel();
        strncpy(l2, label, MAXLBL); // exit point
	printf("# DO\n");

	Expression(); // expr1 = repeat count
	EmitLn("pushl %eax\t\t# repeat count");

        PostLabel(l1);
	Block(l2);

	EmitLn("popl %ecx");
	EmitLn("dec %ecx");
	EmitLn("pushl %ecx");

	// test
        snprintf(code, MAXMSG, "jnz .%s", l1);
        EmitLn(code);
	
	Match('e'); // ENDWHILE
	printf("#ENDDO\n");
	PostLabel(l2);
}
void DoIf(char *L)
{
    char L1[MAX_BUF];
    char L2[MAX_BUF];
    strcpy(L1, NewLabel());
    strcpy(L2, L1);

    Match('i');
    BoolExpression();

    sprintf(tmp, "jz %s", L1);
    EmitLn(tmp);

    Block(L);
    dprint("DoIf: Got Look = %c\n", Look);

    if (Look == 'l') {
        /* match *else* statement */
        Match('l');
        strcpy(L2, NewLabel());

        sprintf(tmp, "jmp %s", L2);
        EmitLn(tmp);

        PostLabel(L1);

        Block(L);
    }

    Match('e');
    PostLabel(L2);
}
Exemple #3
0
	//////////////////////////////////////////////////////////////////////////
	//
	// Class IfElseStmt
	// 
	void IfElseStmt::Gen( int b, int a, bool bASM )
	{
		if ( bASM ) GenMovLineno( m_lineno );

		int label1 = NewLabel();
		int label2 = NewLabel();

		m_pExpr->Jumping( -1, label2 );

		if ( m_pIfStmt )
		{
			EmitLabel( label1 );
			m_pIfStmt->Gen( label1, a, bASM );
		}

		char code[ 10 ];
		sprintf_s( code, "goto L%d", a );
		Emit( code );

		if ( m_pElseStmt ) 
		{
			EmitLabel( label2 );
			m_pElseStmt->Gen( label2, a, bASM );
		}
	}
/* I haven't test the actual generated x86 code here, so you're free to
 * inform me if there are bugs. :) */
void DoFor()
{
    char L1[MAX_BUF];
    char L2[MAX_BUF];

    Match('f');
    strcpy(L1, NewLabel());
    strcpy(L2, NewLabel());
    char name = GetName();
    Match('=');
    Expression();
    EmitLn("subl %eax, $1");  /* SUBQ #1, D0*/
    sprintf(tmp, "lea %c, %%edx", name);
    EmitLn(tmp);
    EmitLn("movl %eax, (%edx)");
    Expression();
    EmitLn("push %eax"); /* save the execution of expression */
    PostLabel(L1);
    sprintf(tmp, "lea %c, %%edx", name);
    EmitLn(tmp);
    EmitLn("movl (%edx), %eax");
    EmitLn("addl %eax, 1");
    EmitLn("movl %eax, (%edx)");
    EmitLn("cmp (%esp), %eax");
    sprintf(tmp, "jg %s", L2);
    EmitLn(tmp);
    Block(L2);
    Match('e');
    sprintf(tmp, "jmp %s", L1);
    EmitLn(tmp);
    PostLabel(L2);
    EmitLn("pop %eax");
}
void DoIf(char *exit_label)
{
        char code[MAXMSG];
	char l1[MAXLBL];
	char l2[MAXLBL];

	Match('i');
	printf("# IF\n");
	NewLabel();
	strncpy(l1, label, MAXLBL);
	strncpy(l2, label, MAXLBL);
	BoolExpression();

        snprintf(code, MAXMSG, "je .%s", l1);
	EmitLn(code);
	printf("# TRUE\n");
	// here, tutorial 05 only matches 'e' once, after the if statement
	// this doesn't seem to work unless i add Look=='l' to the test in
	// Blocks().

	Block(exit_label);
	if (Look=='l') {
		Match('l');
		printf("#ELSE\n");
		NewLabel();
		strncpy(l2, label, MAXLBL);
		snprintf(code, MAXMSG, "jmp .%s", l2); 
		EmitLn(code);
		PostLabel(l1);
		Block(exit_label);
	}
	Match('e'); // ENDIF
	printf("#ENDIF\n");
	PostLabel(l2);
}
void DoWhile(void)
{
        char code[MAXMSG];
        char l1[MAXLBL];
        char l2[MAXLBL];

        Match('w');
        NewLabel();
        strncpy(l1, label, MAXLBL);
	NewLabel();
        strncpy(l2, label, MAXLBL);

        PostLabel(l1);
	BoolExpression();

        snprintf(code, MAXMSG, "je .%s", l2);
        EmitLn(code);
	Block(l2);

	Match('e'); // ENDWHILE
	printf("#ENDWHILE\n");
	snprintf(code, MAXMSG, "jmp .%s", l1);
	EmitLn(code);

	PostLabel(l2);
}
void DoFor() {
  char L1[100];
  char L2[100];

  Match('f');
  strcpy(L1, NewLabel());
  strcpy(L2, NewLabel());
  char Name = GetName();

  Match('=');
  Expression();
  EmitLn("dec rax");
  sprintf(tmp, "mov qword [%c], rax", Name);
  EmitLn(tmp);
  Expression();
  EmitLn("push rax");
  PostLabel(L1);
  sprintf(tmp, "mov rax, qword [%c]", Name);
  EmitLn(tmp);
  EmitLn("inc rax");
  sprintf(tmp, "mov qword [%c], rax", Name);
  EmitLn(tmp);
  EmitLn("cmp rax, qword [rsp]");
  sprintf(tmp, "jg %s", L2);
  EmitLn(tmp);
  Block();
  Match('e'); 
  sprintf(tmp, "jmp %s", L1);
  EmitLn(tmp);
  PostLabel(L2);
  EmitLn("add rsp, 8");

}
void DoIf()
{
    Condition();
    char L1[MAX_BUF];
    char L2[MAX_BUF];
    strcpy(L1, NewLabel());
    strcpy(L2, L1);

    sprintf(tmp, "jz %s", L1);
    EmitLn(tmp);

    Block();

    if (Token == 'l') {
        /* match *else* statement */
        strcpy(L2, NewLabel());

        sprintf(tmp, "jmp %s", L2);
        EmitLn(tmp);

        PostLabel(L1);

        Block();
    }

    PostLabel(L2);
    MatchString("ENDIF");
}
void DoFor(void)
{
	char name;
        char code[MAXMSG];
        char l1[MAXLBL];
        char l2[MAXLBL];

        Match('f');
	printf("# FOR\n");
        NewLabel();
        strncpy(l1, label, MAXLBL);
	NewLabel();
        strncpy(l2, label, MAXLBL);

	// could call Assignment here, but I need to keep the loop counter handle
	name = GetName();
	Match('=');
	Expression(); // expr1 = initial value
	snprintf(code, MAXMSG, "movl $%c,%%edx", name);
	EmitLn(code);
	EmitLn("movl %eax,(%edx)\t\t# assignment");

	Expression(); // expr2 = target value
	EmitLn("pushl %eax    \t\t # put target count on stack");

        // Loop: 
	PostLabel(l1);
	EmitLn("popl %eax  \t\t# recover tgt");
	EmitLn("pushl %eax");
        snprintf(code, MAXMSG, "movl $%c,%%edx", name);
        EmitLn(code);
	EmitLn("movl (%edx), %ecx  \t\t # Grab loop counter");

	// test
	EmitLn("cmpl %eax, %ecx\t\t# for test");
        snprintf(code, MAXMSG, "jg .%s", l2);
        EmitLn(code);
	
	Block(l2);
	//EmitLn("popl %ecx  \t\t# don't need return val");

	// loopback
        snprintf(code, MAXMSG, "movl $%c,%%edx", name); 
	EmitLn(code);
	EmitLn("movl (%edx), %ecx    \t\t # grab loop counter");
	EmitLn("inc %ecx  \t\t # i++");
	EmitLn("movl %ecx, (%edx)");
	snprintf(code, MAXMSG, "jmp .%s", l1);
        EmitLn(code);
	PostLabel(l2);

	Match('e'); // ENDWHILE 
	EmitLn("popl %eax");

	printf("#ENDFOR\n");

}
void DoLoop()
{
    char L1[MAX_BUF];
    char L2[MAX_BUF];
    Match('p');
    strcpy(L1, NewLabel());
    strcpy(L2, NewLabel());
    PostLabel(L1);
    Block(L2);
    Match('e');
    sprintf(tmp, "jmp %s", L1);
    EmitLn(tmp);
    PostLabel(L2);
}
void DoWhile() {
  char L1[100];
  char L2[100];

  strcpy(L1, NewLabel());
  strcpy(L2, NewLabel());
  PostLabel(L1);
  BoolExpression();
  BranchFalse(L2);
  Block();
  MatchString("ENDWHILE");
  Branch(L1);
  PostLabel(L2);
}
void DoWhile()
{
    Next();
    char L1[MAX_BUF];
    char L2[MAX_BUF];
    sprintf(L1, NewLabel());
    sprintf(L2, NewLabel());
    PostLabel(L1);
    BoolExpression();
    BranchFalse(L2);
    Block();
    MatchString("ENDWHILE");
    Branch(L1);
    PostLabel(L2);
}
void DoRepeat()
{
    char L1[MAX_BUF];
    char L2[MAX_BUF];
    Match('r');
    strcpy(L1, NewLabel());
    strcpy(L2, NewLabel());
    PostLabel(L1);
    Block(L2);
    Match('u');
    BoolExpression();

    sprintf(tmp, "jz %s", L1);
    EmitLn(tmp);
    PostLabel(L2);
}
Exemple #14
0
	//////////////////////////////////////////////////////////////////////////
	//
	// Class OrOperator
	// 
	void OrOperator::Jumping( int t, int f )
	{
		int label = t != -1 ? t : NewLabel();
		m_pExpr1->Jumping( label, -1 );
		m_pExpr2->Jumping( t, f );
		if ( t == -1 ) EmitLabel( label );
	}
Exemple #15
0
extern  b       *BENewBack(sym s) {
//=================================

    b   *bk;

    Action( "BENewBack" );
    if( NewBackReturn == FAKE_NULL ) {
        bk = NULL;
    } else if( NewBackReturn != NULL ) {
        bk = NewBackReturn;
    } else {
        bk = CGAlloc( sizeof( b  ));
        bk->n = BackList;
        bk->s = s;
        bk->loc = -1;
        bk->i = ++BackId;
        bk->lp = NewLabel();
        BackList = bk;
        if( !IS_REAL_BACK( bk ) ) {
            CGError( "Internal error - odd memory" );
        }
    }
    Action( "( %s ) -> %p%n", FEName( s ), bk );
    return(bk);
}
dNewtonLuaCompiler::dLuaClosure::dLuaClosure()
	:dCIL()
	,m_parent(NULL)
	,m_returnLabel(NewLabel())
	,m_returnVariable(NewTemp())
{
}
// write output to .clu file - with 1 added to cluster numbers, and empties removed.
void SaveOutput(Array<int> &OutputClass, double* OutputArray) {
	int p, c;
	int MaxClass = 0;
	Array<int> NotEmpty(MaxPossibleClusters);
	Array<int> NewLabel(MaxPossibleClusters);

	// find non-empty clusters
	for(c=0;c<MaxPossibleClusters;c++) NewLabel[c] = NotEmpty[c] = 0;
	for(p=0; p<OutputClass.size(); p++) NotEmpty[OutputClass[p]] = 1;

	// make new cluster labels so we don't have empty ones
    NewLabel[0] = 1;
	MaxClass = 1;
	for(c=1;c<MaxPossibleClusters;c++) {
		if (NotEmpty[c]) {
			MaxClass++;
			NewLabel[c] = MaxClass;
		}
	}

	// print file
	//sprintf(fname, "%s.clu.%d", FileBase, ElecNo);
	//fp = fopen_safe(fname, "w");

	//fprintf(fp, "%d\n", MaxClass);
	int q = 0;
	for (p=0; p<OutputClass.size(); p++) 
		OutputArray[q++] = (int)NewLabel[OutputClass[p]];

	//		fprintf(fp, "%d\n", NewLabel[OutputClass[p]]);
	//fclose(fp);
}
Exemple #18
0
	//////////////////////////////////////////////////////////////////////////
	//
	// Class AndOperator
	// 
	void AndOperator::Jumping( int t, int f )
	{
		int label = f != -1 ? f : NewLabel();
		m_pExpr1->Jumping( -1, label );
		m_pExpr2->Jumping( t, f );
		if ( f == -1 ) EmitLabel( label );
	}
Exemple #19
0
//---------------------------------------------------------------------------
void __fastcall TForm21::TntButton1Click(TObject *Sender)
{
  TTextValue xPos;
  TTextValue yPos;
  xPos.Value = MakeFloat(Edit1);
  yPos.Value = MakeFloat(Edit2);
  xPos.Text = ToWString(Edit1->Text);
  yPos.Text = ToWString(Edit2->Text);

  int Index = ComboBox1->ItemIndex;
  if(Index == -1)
    Index = 0;

  boost::shared_ptr<TTextLabel> NewLabel(new TTextLabel(
    Label->GetText(),
    IndexToPlacement[Index],
    xPos,
    yPos,
    Label->GetBackgroundColor(),
    Label->GetRotation(),
    Label->GetOleLink()
  ));
  UndoList.Push(TUndoChange(Label, NewLabel));
  Data.Replace(Label, NewLabel);
  NewLabel->Update();
  ModalResult = mrOk;
}
void DoWhile() {
  char L1[100];
  char L2[100];

  Match('w');
  strcpy(L1, NewLabel());
  strcpy(L2, NewLabel());
  PostLabel(L1);
  BoolExpression();
  sprintf(tmp, "jz %s", L2);
  EmitLn(tmp);
  Block();
  Match('e');
  sprintf(tmp, "jmp %s", L1);
  EmitLn(tmp);
  PostLabel(L2);
}
Exemple #21
0
extern  l       *BENewLabel() {
//=============================

    l   *nl;
    nl = NewLabel();
    Action( "BENewLabel() -> %s%n", Label(nl) );
    return(nl);
}
int SetTransitionTime(unsigned int trans_time)
{
  char msg[128]={0};
  sprintf(msg,"Slide duration = %ums\n",trans_time);
  NewLabel(frame.desired_x,frame.desired_y,(char *) msg);
  fprintf(stderr,"%s",msg);
  frame.time_ms_between_two_transitions=trans_time;
  return 0;
}
void DoIf() {
  char L1[100];
  char L2[100];
  BoolExpression();
  strcpy(L1,  NewLabel());
  strcpy(L2,  L1);
  BranchFalse(L1);
  Block();
  if(Token == 'l') {
    Match('l');
    strcpy(L2,  NewLabel());
    Branch(L2);
    PostLabel(L1);
    Block();
  }
  PostLabel(L2);
  MatchString("ENDIF");
}
Exemple #24
0
	//////////////////////////////////////////////////////////////////////////
	//
	// Class Logical
	// 
	Expr* Logical::Gen()
	{
		int f = NewLabel();
		int a = NewLabel();

		Temp* temp = new Temp( m_pType );
		Jumping( -1, f );

		char code[ 30 ];

		Emit( temp->ToString() + " = true" );
		sprintf_s( code, "goto L%d", a );
		Emit( code );
		EmitLabel( f );
		sprintf_s( code, "goto L%d", a );
		EmitLabel( a );

		return temp;
	}
void DoLoop() {
  char L[100];
  Match('p');
  strcpy(L, NewLabel());
  PostLabel(L);
  Block();
  Match('e');
  sprintf(tmp, "jmp %s", L);
  EmitLn(tmp);
}
/* Recognize and Translate an IF construct */
void DoIf()
{
    Next();
    char L1[MAX_BUF];
    char L2[MAX_BUF];
    sprintf(L1, NewLabel());
    sprintf(L2, L1);
    BoolExpression();
    BranchFalse(L1);
    Block();
    if (Token == 'l') {
        Next();
        sprintf(L2, NewLabel());
        Branch(L2);
        PostLabel(L1);
        Block();
    }
    PostLabel(L2);
    MatchString("ENDIF");
}
void DoLoop(void)
{
        char code[MAXMSG];
        char l1[MAXLBL];
        char l2[MAXLBL];

        Match('p');
        NewLabel();
        strncpy(l1, label, MAXLBL);
	NewLabel();
	strncpy(l2, label, MAXLBL); // exit point

	PostLabel(l1);
	Block(l2);
	Match('e');
        snprintf(code, MAXMSG, "jmp .%s", l1);
        EmitLn(code);
	printf("#ENDLOOP\n");	
        PostLabel(l2);
}
void DoRepeat() {
  char L[100];
  Match('r');
  strcpy(L, NewLabel());
  PostLabel(L);
  Block();
  Match('u');
  BoolExpression();
  sprintf(tmp, "jmp %s", L);
  EmitLn(tmp);
}
Exemple #29
0
void renewlab(Term t)
{
	List l;
	labl=0;
	labm=0;
	lablist(t);
	for(l=labl;l;l=ListTail(l))
		labm=AppendFirst(labm,NewLabel());
	chlabs(t);
	if(labl) {FreeAtomic(labl);FreeAtomic(labm);}
}
void DoDo()
{
    Match('d');
    char L1[MAX_BUF];
    char L2[MAX_BUF];
    strcpy(L1, NewLabel());
    strcpy(L2, NewLabel());
    Expression();
    EmitLn("subl %eax, $1");
    EmitLn("movl %eax, %ecx");
    PostLabel(L1);
    EmitLn("pushl %ecx");
    Block(L2);
    EmitLn("popl %ecx");
    sprintf(tmp, "loop %s", L1);
    EmitLn(tmp);
    EmitLn("pushl %ecx");
    PostLabel(L2);
    EmitLn("popl %ecx");
}