OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2010 The Native Client Authors. All rights reserved. | |
3 * Use of this source code is governed by a BSD-style license that can be | |
4 * found in the LICENSE file. | |
5 */ | |
6 | |
7 /* ncdecode_st.h - Implements a (simple) hashtable used by the | |
8 * instruction table generator. | |
9 */ | |
10 | |
11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_DECODER_GENERATOR_NCDECODE_ST_H_ | |
12 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_DECODER_GENERATOR_NCDECODE_ST_H_ | |
13 | |
14 #ifndef NACL_TRUSTED_BUT_NOT_TCB | |
15 #error("This file is not meant for use in the TCB") | |
16 #endif | |
17 | |
18 #include "native_client/src/include/portability.h" | |
19 #include "native_client/src/trusted/validator/x86/decoder/generator/ncdecode_for
ms.h" | |
20 | |
21 struct NaClSymbolTable; | |
22 struct NaClStValue; | |
23 struct Gio; | |
24 | |
25 /* The set of possible values that can be put in a symbol table. */ | |
26 typedef enum { | |
27 nacl_byte, /* (unsigned) byte value. */ | |
28 nacl_text, /* char* value. */ | |
29 nacl_int, /* integer value. */ | |
30 nacl_defop, /* a NaClDefOperand function pointer. */ | |
31 } NaClStValueKind; | |
32 | |
33 /* Returns a printable name for the given kind. */ | |
34 const char* NaClStValueKindName(NaClStValueKind kind); | |
35 | |
36 /* Models the set of possible values that can appear in a symbol table. */ | |
37 typedef struct NaClStValue { | |
38 NaClStValueKind kind; /* descriminant of the kind of value. */ | |
39 union NaClStValueUnion { | |
40 /* kind == nacl_byte */ | |
41 uint8_t byte_value; | |
42 /* kind == nacl_int */ | |
43 int int_value; | |
44 /* kind == nacl_text */ | |
45 const char* text_value; | |
46 /* kind == nacl_defop */ | |
47 NaClDefOperand defop_value; | |
48 } value; | |
49 } NaClStValue; | |
50 | |
51 /* Copies the contents of the RHS to the LHS. Note: Does a shallow copy | |
52 * only (I.e. only copies the int / char* / pointer of the union. | |
53 */ | |
54 void NaClStValueAssign( | |
55 NaClStValue* lhs, | |
56 NaClStValue* rhs); | |
57 | |
58 /* Prints out the contents of a value to the given file. */ | |
59 void NaClStValuePrint(struct Gio* g, NaClStValue* value); | |
60 | |
61 /* Dynamically creates a symbol table, with the expected size, | |
62 * and the given calling context (NULL implies top-level). | |
63 * Must be destroyed with NaClSymbolTableDestroy. | |
64 */ | |
65 struct NaClSymbolTable* NaClSymbolTableCreate( | |
66 size_t capacity, | |
67 struct NaClSymbolTable* calling_context); | |
68 | |
69 /* Adds the name value pair into the given symbol table. Value | |
70 * must be non-NULL. | |
71 */ | |
72 void NaClSymbolTablePut( | |
73 const char* name, | |
74 struct NaClStValue* value, | |
75 struct NaClSymbolTable* st); | |
76 | |
77 void NaClSymbolTablePutByte(const char* name, | |
78 uint8_t byte, | |
79 struct NaClSymbolTable* st); | |
80 | |
81 void NaClSymbolTablePutText(const char* name, | |
82 const char* value, | |
83 struct NaClSymbolTable* st); | |
84 | |
85 void NaClSymbolTablePutInt(const char* name, | |
86 int value, | |
87 struct NaClSymbolTable* st); | |
88 | |
89 /* Returns the value associated with the name, or NULL if | |
90 * no such value exists (in the given symbol table, or any | |
91 * of its calling contexts). | |
92 */ | |
93 struct NaClStValue* NaClSymbolTableGet( | |
94 const char* name, | |
95 struct NaClSymbolTable* st); | |
96 | |
97 /* Print out the set of symbol bindings in a symbol table. */ | |
98 void NaClSymbolTablePrint(struct Gio* g, struct NaClSymbolTable* st); | |
99 | |
100 /* Destroys the given symbol table. */ | |
101 void NaClSymbolTableDestroy(struct NaClSymbolTable* st); | |
102 | |
103 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_DECODER_GENERATOR_NCDECODE_ST
_H_ */ | |
OLD | NEW |