17cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines/*
27cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * Copyright 2012, The Android Open Source Project
37cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines *
47cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * Licensed under the Apache License, Version 2.0 (the "License");
57cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * you may not use this file except in compliance with the License.
67cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * You may obtain a copy of the License at
77cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines *
87cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines *     http://www.apache.org/licenses/LICENSE-2.0
97cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines *
107cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * Unless required by applicable law or agreed to in writing, software
117cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * distributed under the License is distributed on an "AS IS" BASIS,
127cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * See the License for the specific language governing permissions and
147cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * limitations under the License.
157cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines */
167cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines
177cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines// Define a generic interface to a file/memory region that contains
187cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines// a bitcode file, a wrapped bitcode file, or a data file to wrap.
197cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines
207cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines#ifndef LLVM_WRAP_WRAPPER_INPUT_H__
217cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines#define LLVM_WRAP_WRAPPER_INPUT_H__
227cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines
237cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines#include <stdint.h>
247cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines#include <sys/types.h>
257cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines
267cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines#include "support_macros.h"
277cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines
287cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines// The following is a generic interface to a file/memory region that contains
297cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines// a bitcode file, a wrapped bitcode file, or data file to wrap.
307cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hinesclass WrapperInput {
317cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines public:
327cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines  WrapperInput() {}
337cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines  virtual ~WrapperInput() {}
347cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines  // Tries to read the requested number of bytes into the buffer. Returns the
357cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines  // actual number of bytes read.
367cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines  virtual size_t Read(uint8_t* buffer, size_t wanted) = 0;
377cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines  // Returns true if at end of input. Note: May return false until
387cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines  // Read is called, and returns 0.
397cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines  virtual bool AtEof() = 0;
407cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines  // Returns the size of the input (in bytes).
417cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines  virtual off_t Size() = 0;
427cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines  // Moves to the given offset within the input region. Returns false
437cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines  // if unable to move to that position.
447cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines  virtual bool Seek(uint32_t pos) = 0;
457cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines private:
467cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines  DISALLOW_CLASS_COPY_AND_ASSIGN(WrapperInput);
477cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines};
487cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines
497cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines#endif  // LLVM_WRAP_WRAPPER_INPUT_H__
50