summaryrefslogtreecommitdiff
path: root/miniany/cc.c
diff options
context:
space:
mode:
Diffstat (limited to 'miniany/cc.c')
-rw-r--r--miniany/cc.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/miniany/cc.c b/miniany/cc.c
index c814f3d..28d9f1c 100644
--- a/miniany/cc.c
+++ b/miniany/cc.c
@@ -1295,6 +1295,49 @@ void parseIf( struct Compiler *compiler )
free( label1 );
}
+/*
+ void parseIf( struct Compiler *compiler )
+{
+ struct Parser *parser;
+ struct ASTnode *node;
+ char *label1, *label2;
+
+ parser = compiler->parser;
+ parserExpect( parser, S_IF, "if" );
+ parserExpect( parser, S_LPAREN, "(" );
+ node = parseExpression( parser, 0 );
+ if( compiler->generator->debug ) {
+ putstring( "; if <cond> then" ); putnl( );
+ }
+ generateFromAST( compiler->generator, node, NOREG );
+ putstring( "cmp al, 0" ); putnl( );
+ label1 = genGetLabel( compiler, compiler->parser->global_scope );
+ putstring( "je " ); putstring( label1 ); putnl( );
+ genFreeAllRegs( compiler->generator );
+ parserExpect( parser, S_RPAREN, ")" );
+ parseStatementBlock( compiler );
+ if( parser->token == S_ELSE ) {
+ label2 = genGetLabel( compiler, compiler->parser->global_scope );
+ putstring( "jmp " ); putstring( label2 ); putnl( );
+ if( compiler->generator->debug ) {
+ putstring( "; else" ); putnl( );
+ }
+ putstring( label1 ); putchar( ':' ); putnl( );
+ compiler->parser->token = getToken( compiler->parser->scanner );
+ parseStatementBlock( compiler );
+ putstring( label2 ); putchar( ':' ); putnl( );
+ free( label2 );
+ } else {
+ putstring( label1 ); putchar( ':' ); putnl( );
+ }
+
+ if( compiler->generator->debug ) {
+ putstring( "; fi" ); putnl( );
+ }
+ free( label1 );
+}
+
+ */
void parseStatement( struct Compiler *compiler )
{
struct Parser *parser;