void compileFuncDecl(void) { Object* funcObj; Type* returnType; eat(KW_FUNCTION); eat(TK_IDENT); // TODO: Check if a function identifier is fresh in the block checkFreshIdent(currentToken->string); // create the function object funcObj = createFunctionObject(currentToken->string); // declare the function object declareObject(funcObj); // enter the function's block enterBlock(funcObj->funcAttrs->scope); // parse the function's parameters compileParams(); eat(SB_COLON); // get the funtion's return type returnType = compileBasicType(); funcObj->funcAttrs->returnType = returnType; eat(SB_SEMICOLON); compileBlock(); eat(SB_SEMICOLON); // exit the function block exitBlock(); }
void compileFuncDecl(void) { Object* funcObj; Type* returnType; eat(KW_FUNCTION); eat(TK_IDENT); checkFreshIdent(currentToken->string); funcObj = createFunctionObject(currentToken->string); declareObject(funcObj); enterBlock(funcObj->funcAttrs->scope); compileParams(); eat(SB_COLON); returnType = compileBasicType(); funcObj->funcAttrs->returnType = returnType; eat(SB_SEMICOLON); compileBlock(); eat(SB_SEMICOLON); exitBlock(); }
void initSymTab(void) { Object* param; symtab = (SymTab*) malloc(sizeof(SymTab)); symtab->globalObjectList = NULL; symtab->program = NULL; symtab->currentScope = NULL; readcFunction = createFunctionObject("READC"); declareObject(readcFunction); readcFunction->funcAttrs->returnType = makeCharType(); readiFunction = createFunctionObject("READI"); declareObject(readiFunction); readiFunction->funcAttrs->returnType = makeIntType(); writeiProcedure = createProcedureObject("WRITEI"); declareObject(writeiProcedure); enterBlock(writeiProcedure->procAttrs->scope); param = createParameterObject("i", PARAM_VALUE); param->paramAttrs->type = makeIntType(); declareObject(param); exitBlock(); writecProcedure = createProcedureObject("WRITEC"); declareObject(writecProcedure); enterBlock(writecProcedure->procAttrs->scope); param = createParameterObject("ch", PARAM_VALUE); param->paramAttrs->type = makeCharType(); declareObject(param); exitBlock(); writelnProcedure = createProcedureObject("WRITELN"); declareObject(writelnProcedure); intType = makeIntType(); charType = makeCharType(); }
void compileProgram(void) { // TODO: create, enter, and exit program block# Object * obj = NULL; eat(KW_PROGRAM); eat(TK_IDENT); obj = createProgramObject(currentToken->string); eat(SB_SEMICOLON); enterBlock(obj->progAttrs->scope); compileBlock(); exitBlock(); eat(SB_PERIOD); }
void compileProgram(void) { Object* program; eat(KW_PROGRAM); eat(TK_IDENT); program = createProgramObject(currentToken->string); enterBlock(program->progAttrs->scope); eat(SB_SEMICOLON); compileBlock(); eat(SB_PERIOD); exitBlock(); }
void compileProcDecl(void) { // TODO: create and declare a procedure object// Object* obj=NULL; eat(KW_PROCEDURE); eat(TK_IDENT); obj = createProcedureObject(currentToken->string); enterBlock(obj->procAttrs->scope); compileParams(); eat(SB_SEMICOLON); compileBlock(); eat(SB_SEMICOLON); exitBlock(); declareObject(obj); }
void RemoveBarrierPass::_removeBarrier( analysis::DataflowGraph::iterator block, unsigned int id ) { typedef analysis::DataflowGraph::RegisterSet RegisterSet; analysis::DataflowGraph::InstructionVector::const_iterator _instruction( block->instructions().begin() ); std::advance( _instruction, id ); analysis::DataflowGraph::iterator exitBlock( _dfg().end() ); std::advance( exitBlock, -1 ); ir::PTXInstruction& instruction = static_cast< ir::PTXInstruction& >( *_instruction->i ); bool isBarrier = instruction.opcode == ir::PTXInstruction::Bar; if( isBarrier ) { report( " Converting instruction " << instruction.toString() ); instruction.opcode = ir::PTXInstruction::Call; instruction.tailCall = true; instruction.branchTargetInstruction = -1; instruction.a = ir::PTXOperand( ir::PTXOperand::FunctionName, "_ZOcelotBarrierKernel"); instruction.d.addressMode = ir::PTXOperand::Invalid; report( " Converted to " << instruction.toString() ); } RegisterSet alive = block->alive( _instruction ); analysis::DataflowGraph::iterator bottom = _dfg().split( block, id + 1, false ); _addSpillCode( block, bottom, alive, isBarrier ); _addRestoreCode( bottom, alive ); _dfg().redirect( block, bottom, exitBlock ); if( !isBarrier && instruction.pg.condition != ir::PTXOperand::PT ) { _dfg().target( block, bottom, true ); } _addEntryPoint( bottom ); }
void compileProcDecl(void) { Object* procObj; eat(KW_PROCEDURE); eat(TK_IDENT); checkFreshIdent(currentToken->string); procObj = createProcedureObject(currentToken->string); declareObject(procObj); enterBlock(procObj->procAttrs->scope); compileParams(); eat(SB_SEMICOLON); compileBlock(); eat(SB_SEMICOLON); exitBlock(); }
void compileProgram(void) { Object* program; eat(KW_PROGRAM); eat(TK_IDENT); program = createProgramObject(currentToken->string); program->progAttrs->codeAddress = getCurrentCodeAddress(); enterBlock(program->progAttrs->scope); eat(SB_SEMICOLON); compileBlock(); eat(SB_PERIOD); // Halt the program genHL(); exitBlock(); }
void compileFuncDecl(void) { // TODO: create and declare a function object# Object* obj=NULL; eat(KW_FUNCTION); eat(TK_IDENT); obj = createFunctionObject(currentToken->string); enterBlock(obj->funcAttrs->scope); compileParams(); eat(SB_COLON); obj->funcAttrs->returnType = compileBasicType(); eat(SB_SEMICOLON); compileBlock(); eat(SB_SEMICOLON); exitBlock(); declareObject(obj); }
void compileProcDecl(void) { Object* procObj; eat(KW_PROCEDURE); eat(TK_IDENT); // TODO: Check if a procedure identifier is fresh in the block checkFreshIdent(currentToken->string); // create a procedure object procObj = createProcedureObject(currentToken->string); // declare the procedure object declareObject(procObj); // enter the procedure's block enterBlock(procObj->procAttrs->scope); // parse the procedure's parameters compileParams(); eat(SB_SEMICOLON); compileBlock(); eat(SB_SEMICOLON); // exit the block exitBlock(); }
int main() { Object* obj; initSymTab(); obj = createProgramObject("PRG"); enterBlock(obj->progAttrs->scope); obj = createConstantObject("c1"); obj->constAttrs->value = makeIntConstant(10); declareObject(obj); obj = createConstantObject("c2"); obj->constAttrs->value = makeCharConstant('a'); declareObject(obj); obj = createTypeObject("t1"); obj->typeAttrs->actualType = makeArrayType(10, makeIntType()); declareObject(obj); obj = createVariableObject("v1"); obj->varAttrs->type = makeIntType(); declareObject(obj); obj = createVariableObject("v2"); obj->varAttrs->type = makeArrayType(10, makeArrayType(10, makeIntType())); declareObject(obj); obj = createFunctionObject("f"); obj->funcAttrs->returnType = makeIntType(); declareObject(obj); enterBlock(obj->funcAttrs->scope); obj = createParameterObject("p1", PARAM_VALUE, symtab->currentScope->owner); obj->paramAttrs->type = makeIntType(); declareObject(obj); obj = createParameterObject("p2", PARAM_REFERENCE, symtab->currentScope->owner); obj->paramAttrs->type = makeCharType(); declareObject(obj); exitBlock(); obj = createProcedureObject("p"); declareObject(obj); enterBlock(obj->procAttrs->scope); obj = createParameterObject("v1", PARAM_VALUE, symtab->currentScope->owner); obj->paramAttrs->type = makeIntType(); declareObject(obj); obj = createConstantObject("c1"); obj->constAttrs->value = makeCharConstant('a'); declareObject(obj); obj = createConstantObject("c3"); obj->constAttrs->value = makeIntConstant(10); declareObject(obj); obj = createTypeObject("t1"); obj->typeAttrs->actualType = makeIntType(); declareObject(obj); obj = createTypeObject("t2"); obj->typeAttrs->actualType = makeArrayType(10, makeIntType()); declareObject(obj); obj = createVariableObject("v2"); obj->varAttrs->type = makeArrayType(10, makeIntType()); declareObject(obj); obj = createVariableObject("v3"); obj->varAttrs->type = makeCharType(); declareObject(obj); exitBlock(); exitBlock(); printObject(symtab->program, 0); cleanSymTab(); return 0; }