Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. //
  2. // Copyright 2012 Francisco Jerez
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a
  5. // copy of this software and associated documentation files (the "Software"),
  6. // to deal in the Software without restriction, including without limitation
  7. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. // and/or sell copies of the Software, and to permit persons to whom the
  9. // Software is furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  17. // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. // OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22.  
  23. #ifndef CLOVER_CORE_MODULE_HPP
  24. #define CLOVER_CORE_MODULE_HPP
  25.  
  26. #include <vector>
  27. #include <string>
  28.  
  29. namespace clover {
  30.    struct module {
  31.       typedef uint32_t resource_id;
  32.       typedef uint32_t size_t;
  33.  
  34.       struct section {
  35.          enum type {
  36.             text,
  37.             data_constant,
  38.             data_global,
  39.             data_local,
  40.             data_private
  41.          };
  42.  
  43.          section(resource_id id, enum type type, size_t size,
  44.                  const std::vector<char> &data) :
  45.                  id(id), type(type), size(size), data(data) { }
  46.          section() : id(0), type(text), size(0), data() { }
  47.  
  48.          resource_id id;
  49.          type type;
  50.          size_t size;
  51.          std::vector<char> data;
  52.       };
  53.  
  54.       struct argument {
  55.          enum type {
  56.             scalar,
  57.             constant,
  58.             global,
  59.             local,
  60.             image2d_rd,
  61.             image2d_wr,
  62.             image3d_rd,
  63.             image3d_wr,
  64.             sampler
  65.          };
  66.  
  67.          enum ext_type {
  68.             zero_ext,
  69.             sign_ext
  70.          };
  71.  
  72.          enum semantic {
  73.             general,
  74.             grid_dimension,
  75.             grid_offset
  76.          };
  77.  
  78.          argument(enum type type, size_t size,
  79.                   size_t target_size, size_t target_align,
  80.                   enum ext_type ext_type,
  81.                   enum semantic semantic = general) :
  82.             type(type), size(size),
  83.             target_size(target_size), target_align(target_align),
  84.             ext_type(ext_type), semantic(semantic) { }
  85.  
  86.          argument(enum type type, size_t size) :
  87.             type(type), size(size),
  88.             target_size(size), target_align(1),
  89.             ext_type(zero_ext), semantic(general) { }
  90.  
  91.          argument() : type(scalar), size(0),
  92.                       target_size(0), target_align(1),
  93.                       ext_type(zero_ext), semantic(general) { }
  94.  
  95.          type type;
  96.          size_t size;
  97.          size_t target_size;
  98.          size_t target_align;
  99.          ext_type ext_type;
  100.          semantic semantic;
  101.       };
  102.  
  103.       struct symbol {
  104.          symbol(const std::string &name, resource_id section,
  105.                 size_t offset, const std::vector<argument> &args) :
  106.                 name(name), section(section), offset(offset), args(args) { }
  107.          symbol() : name(), section(0), offset(0), args() { }
  108.  
  109.          std::string name;
  110.          resource_id section;
  111.          size_t offset;
  112.          std::vector<argument> args;
  113.       };
  114.  
  115.       void serialize(std::ostream &os) const;
  116.       static module deserialize(std::istream &is);
  117.       size_t size() const;
  118.  
  119.       std::vector<symbol> syms;
  120.       std::vector<section> secs;
  121.    };
  122. }
  123.  
  124. #endif
  125.