mojoshader_assembler.c
changeset 578 6c8f73c845e7
parent 576 d7ec39b7abab
child 586 321a19a62989
equal deleted inserted replaced
577:bec531dd448e 578:6c8f73c845e7
  1512             parse_instruction_token(ctx, token);
  1512             parse_instruction_token(ctx, token);
  1513     } // if
  1513     } // if
  1514 } // parse_token
  1514 } // parse_token
  1515 
  1515 
  1516 
  1516 
  1517 static Context *build_context(const char *source, unsigned int sourcelen,
  1517 static Context *build_context(const char *filename,
       
  1518                               const char *source, unsigned int sourcelen,
  1518                               const MOJOSHADER_preprocessorDefine **defines,
  1519                               const MOJOSHADER_preprocessorDefine **defines,
  1519                               unsigned int define_count,
  1520                               unsigned int define_count,
  1520                               MOJOSHADER_includeOpen include_open,
  1521                               MOJOSHADER_includeOpen include_open,
  1521                               MOJOSHADER_includeClose include_close,
  1522                               MOJOSHADER_includeClose include_close,
  1522                               MOJOSHADER_malloc m, MOJOSHADER_free f, void *d)
  1523                               MOJOSHADER_malloc m, MOJOSHADER_free f, void *d)
  1535     memset(ctx, '\0', sizeof (Context));
  1536     memset(ctx, '\0', sizeof (Context));
  1536     ctx->malloc = m;
  1537     ctx->malloc = m;
  1537     ctx->free = f;
  1538     ctx->free = f;
  1538     ctx->malloc_data = d;
  1539     ctx->malloc_data = d;
  1539     ctx->parse_phase = MOJOSHADER_PARSEPHASE_NOTSTARTED;
  1540     ctx->parse_phase = MOJOSHADER_PARSEPHASE_NOTSTARTED;
  1540     ctx->preprocessor = preprocessor_start(NULL, source, sourcelen,
  1541     ctx->preprocessor = preprocessor_start(filename, source, sourcelen,
  1541                                            include_open, include_close,
  1542                                            include_open, include_close,
  1542                                            defines, define_count, m, f, d);
  1543                                            defines, define_count, m, f, d);
  1543 
  1544 
  1544     if (ctx->preprocessor == NULL)
  1545     if (ctx->preprocessor == NULL)
  1545     {
  1546     {
  1815 } // output_comments
  1816 } // output_comments
  1816 
  1817 
  1817 
  1818 
  1818 // API entry point...
  1819 // API entry point...
  1819 
  1820 
  1820 const MOJOSHADER_parseData *MOJOSHADER_assemble(const char *source,
  1821 const MOJOSHADER_parseData *MOJOSHADER_assemble(const char *filename,
  1821                              unsigned int sourcelen,
  1822                              const char *source, unsigned int sourcelen,
  1822                              const char **comments, unsigned int comment_count,
  1823                              const char **comments, unsigned int comment_count,
  1823                              const MOJOSHADER_symbol *symbols,
  1824                              const MOJOSHADER_symbol *symbols,
  1824                              unsigned int symbol_count,
  1825                              unsigned int symbol_count,
  1825                              const MOJOSHADER_preprocessorDefine **defines,
  1826                              const MOJOSHADER_preprocessorDefine **defines,
  1826                              unsigned int define_count,
  1827                              unsigned int define_count,
  1832     Context *ctx = NULL;
  1833     Context *ctx = NULL;
  1833 
  1834 
  1834     if ( ((m == NULL) && (f != NULL)) || ((m != NULL) && (f == NULL)) )
  1835     if ( ((m == NULL) && (f != NULL)) || ((m != NULL) && (f == NULL)) )
  1835         return &MOJOSHADER_out_of_mem_data;  // supply both or neither.
  1836         return &MOJOSHADER_out_of_mem_data;  // supply both or neither.
  1836 
  1837 
  1837     ctx = build_context(source, sourcelen, defines, define_count,
  1838     ctx = build_context(filename, source, sourcelen, defines, define_count,
  1838                         include_open, include_close, m, f, d);
  1839                         include_open, include_close, m, f, d);
  1839     if (ctx == NULL)
  1840     if (ctx == NULL)
  1840         return &MOJOSHADER_out_of_mem_data;
  1841         return &MOJOSHADER_out_of_mem_data;
  1841 
  1842 
  1842     // Version token always comes first.
  1843     // Version token always comes first.