tgsitollvm.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  llvm

Functions

llvm::Module * tgsi_to_llvm (struct gallivm_ir *ir, const struct tgsi_token *tokens)
llvm::Module * tgsi_to_llvmir (struct gallivm_ir *ir, const struct tgsi_token *tokens)


Function Documentation

llvm::Module* tgsi_to_llvm ( struct gallivm_ir ir,
const struct tgsi_token tokens 
)

Definition at line 1035 of file tgsitollvm.cpp.

References args, assert, tgsi_full_token::FullDeclaration, tgsi_full_token::FullImmediate, tgsi_full_token::FullInstruction, tgsi_parse_context::FullToken, GALLIVM_VS, gallivm_ir::id, gallivm_ir::num_consts, Storage::numConsts(), stream, tgsi_default_full_declaration(), tgsi_default_full_instruction(), tgsi_parse_end_of_tokens(), tgsi_parse_free(), tgsi_parse_init(), tgsi_parse_token(), TGSI_TOKEN_TYPE_DECLARATION, TGSI_TOKEN_TYPE_IMMEDIATE, TGSI_TOKEN_TYPE_INSTRUCTION, tgsi_full_token::Token, translate_declaration(), translate_immediate(), translate_instruction(), tgsi_token::Type, and gallivm_ir::type.

01036 {
01037    llvm::Module *mod = new Module("shader");
01038    struct tgsi_parse_context parse;
01039    struct tgsi_full_instruction fi;
01040    struct tgsi_full_declaration fd;
01041    unsigned instno = 0;
01042    Function* shader = mod->getFunction("execute_shader");
01043    std::ostringstream stream;
01044    if (ir->type == GALLIVM_VS) {
01045       stream << "vs_shader";
01046    } else {
01047       stream << "fs_shader";
01048    }
01049    stream << ir->id;
01050    std::string func_name = stream.str();
01051    shader->setName(func_name.c_str());
01052 
01053    Function::arg_iterator args = shader->arg_begin();
01054    Value *ptr_INPUT = args++;
01055    ptr_INPUT->setName("input");
01056 
01057    BasicBlock *label_entry = BasicBlock::Create("entry", shader, 0);
01058 
01059    tgsi_parse_init(&parse, tokens);
01060 
01061    fi = tgsi_default_full_instruction();
01062    fd = tgsi_default_full_declaration();
01063    Storage storage(label_entry, ptr_INPUT);
01064    Instructions instr(mod, shader, label_entry, &storage);
01065    while(!tgsi_parse_end_of_tokens(&parse)) {
01066       tgsi_parse_token(&parse);
01067 
01068       switch (parse.FullToken.Token.Type) {
01069       case TGSI_TOKEN_TYPE_DECLARATION:
01070          translate_declaration(ir, mod, &storage,
01071                                &parse.FullToken.FullDeclaration,
01072                                &fd);
01073          break;
01074 
01075       case TGSI_TOKEN_TYPE_IMMEDIATE:
01076          translate_immediate(&storage,
01077                              &parse.FullToken.FullImmediate);
01078          break;
01079 
01080       case TGSI_TOKEN_TYPE_INSTRUCTION:
01081          translate_instruction(mod, &storage, &instr,
01082                                &parse.FullToken.FullInstruction,
01083                                &fi, instno);
01084          ++instno;
01085          break;
01086 
01087       default:
01088          assert(0);
01089       }
01090    }
01091 
01092    tgsi_parse_free(&parse);
01093 
01094    ir->num_consts = storage.numConsts();
01095    return mod;
01096 }

llvm::Module* tgsi_to_llvmir ( struct gallivm_ir ir,
const struct tgsi_token tokens 
)

Definition at line 1098 of file tgsitollvm.cpp.

References args, assert, StorageSoa::declareImmediates(), tgsi_full_token::FullDeclaration, tgsi_full_token::FullImmediate, tgsi_full_token::FullInstruction, tgsi_parse_context::FullToken, GALLIVM_VS, stream, tgsi_default_full_declaration(), tgsi_default_full_instruction(), tgsi_parse_end_of_tokens(), tgsi_parse_free(), tgsi_parse_init(), tgsi_parse_token(), TGSI_TOKEN_TYPE_DECLARATION, TGSI_TOKEN_TYPE_IMMEDIATE, TGSI_TOKEN_TYPE_INSTRUCTION, tgsi_full_token::Token, translate_declarationir(), translate_immediateir(), translate_instructionir(), tgsi_token::Type, gallivm_ir::type, and vertexShaderFunctionType().

01100 {
01101    llvm::Module *mod = new Module("shader");
01102    struct tgsi_parse_context parse;
01103    struct tgsi_full_instruction fi;
01104    struct tgsi_full_declaration fd;
01105    unsigned instno = 0;
01106    std::ostringstream stream;
01107    if (ir->type == GALLIVM_VS) {
01108       stream << "vs_shader";
01109    } else {
01110       stream << "fs_shader";
01111    }
01112    //stream << ir->id;
01113    std::string func_name = stream.str();
01114    Function *shader = llvm::cast<Function>(mod->getOrInsertFunction(
01115                                               func_name.c_str(),
01116                                               vertexShaderFunctionType()));
01117 
01118    Function::arg_iterator args = shader->arg_begin();
01119    Value *input = args++;
01120    input->setName("inputs");
01121    Value *output = args++;
01122    output->setName("outputs");
01123    Value *consts = args++;
01124    consts->setName("consts");
01125    Value *temps = args++;
01126    temps->setName("temps");
01127 
01128    BasicBlock *label_entry = BasicBlock::Create("entry", shader, 0);
01129 
01130    tgsi_parse_init(&parse, tokens);
01131 
01132    fi = tgsi_default_full_instruction();
01133    fd = tgsi_default_full_declaration();
01134 
01135    StorageSoa storage(label_entry, input, output, consts, temps);
01136    InstructionsSoa instr(mod, shader, label_entry, &storage);
01137 
01138    while(!tgsi_parse_end_of_tokens(&parse)) {
01139       tgsi_parse_token(&parse);
01140 
01141       switch (parse.FullToken.Token.Type) {
01142       case TGSI_TOKEN_TYPE_DECLARATION:
01143          translate_declarationir(ir, mod, &storage,
01144                                  &parse.FullToken.FullDeclaration,
01145                                  &fd);
01146          break;
01147 
01148       case TGSI_TOKEN_TYPE_IMMEDIATE:
01149          translate_immediateir(&storage,
01150                              &parse.FullToken.FullImmediate);
01151          break;
01152 
01153       case TGSI_TOKEN_TYPE_INSTRUCTION:
01154          storage.declareImmediates();
01155          translate_instructionir(mod, &storage, &instr,
01156                                  &parse.FullToken.FullInstruction,
01157                                  &fi, instno);
01158          ++instno;
01159          break;
01160 
01161       default:
01162          assert(0);
01163       }
01164    }
01165 
01166    tgsi_parse_free(&parse);
01167 
01168    return mod;
01169 }


Generated on Tue Sep 29 06:25:23 2009 for Gallium3D by  doxygen 1.5.4