Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Side by Side Diff: src/assembler_ia32.cpp

Issue 678533005: Subzero: Add basic ELFObjectWriter (text section, symtab, strtab, headers) (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: cleanup Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===- subzero/src/assembler_ia32.cpp - Assembler for x86-32 -------------===// 1 //===- subzero/src/assembler_ia32.cpp - Assembler for x86-32 -------------===//
2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 // 5 //
6 // Modified by the Subzero authors. 6 // Modified by the Subzero authors.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // The Subzero Code Generator 10 // The Subzero Code Generator
11 // 11 //
12 // This file is distributed under the University of Illinois Open Source 12 // This file is distributed under the University of Illinois Open Source
13 // License. See LICENSE.TXT for details. 13 // License. See LICENSE.TXT for details.
14 // 14 //
15 //===----------------------------------------------------------------------===// 15 //===----------------------------------------------------------------------===//
16 // 16 //
17 // This file implements the Assembler class for x86-32. 17 // This file implements the Assembler class for x86-32.
18 // 18 //
19 //===----------------------------------------------------------------------===// 19 //===----------------------------------------------------------------------===//
20 20
21 #include "assembler_ia32.h" 21 #include "assembler_ia32.h"
22 #include "IceCfg.h" 22 #include "IceCfg.h"
23 #include "IceMemoryRegion.h"
24 #include "IceOperand.h" 23 #include "IceOperand.h"
25 24
26 namespace Ice { 25 namespace Ice {
27 namespace x86 { 26 namespace x86 {
28 27
29 class DirectCallRelocation : public AssemblerFixup { 28 class DirectCallRelocation : public AssemblerFixup {
30 DirectCallRelocation(const DirectCallRelocation &) = delete; 29 DirectCallRelocation(const DirectCallRelocation &) = delete;
31 DirectCallRelocation &operator=(const DirectCallRelocation &) = delete; 30 DirectCallRelocation &operator=(const DirectCallRelocation &) = delete;
32 31
33 public: 32 public:
34 static DirectCallRelocation *create(Assembler *Asm, FixupKind Kind, 33 static DirectCallRelocation *create(Assembler *Asm, FixupKind Kind,
35 const ConstantRelocatable *Sym) { 34 const ConstantRelocatable *Sym) {
36 return new (Asm->Allocate<DirectCallRelocation>()) 35 return new (Asm->Allocate<DirectCallRelocation>())
37 DirectCallRelocation(Kind, Sym); 36 DirectCallRelocation(Kind, Sym);
38 } 37 }
39 38
40 void Process(const MemoryRegion &region, intptr_t position) override {
41 // Direct calls are relative to the following instruction on x86.
42 int32_t pointer = region.Load<int32_t>(position);
43 int32_t delta = region.start() + position + sizeof(int32_t);
44 region.Store<int32_t>(position, pointer - delta);
45 }
46
47 private: 39 private:
48 DirectCallRelocation(FixupKind Kind, const ConstantRelocatable *Sym) 40 DirectCallRelocation(FixupKind Kind, const ConstantRelocatable *Sym)
49 : AssemblerFixup(Kind, Sym) {} 41 : AssemblerFixup(Kind, Sym) {}
50 }; 42 };
51 43
52 Address Address::ofConstPool(GlobalContext *Ctx, Assembler *Asm, 44 Address Address::ofConstPool(GlobalContext *Ctx, Assembler *Asm,
53 const Constant *Imm) { 45 const Constant *Imm) {
54 // We should make this much lighter-weight. E.g., just record the const pool 46 // We should make this much lighter-weight. E.g., just record the const pool
55 // entry ID. 47 // entry ID.
56 std::string Buffer; 48 std::string Buffer;
(...skipping 14 matching lines...) Expand all
71 #ifndef NDEBUG 63 #ifndef NDEBUG
72 for (const Label *Label : CfgNodeLabels) { 64 for (const Label *Label : CfgNodeLabels) {
73 Label->FinalCheck(); 65 Label->FinalCheck();
74 } 66 }
75 for (const Label *Label : LocalLabels) { 67 for (const Label *Label : LocalLabels) {
76 Label->FinalCheck(); 68 Label->FinalCheck();
77 } 69 }
78 #endif 70 #endif
79 } 71 }
80 72
73 void AssemblerX86::alignFunction() {
74 intptr_t Pos = buffer_.GetPosition();
75 SizeT Align = 1 << getBundleAlignLog2Bytes();
76 intptr_t Mod = Pos & (Align - 1);
77 if (Mod == 0) {
78 return;
79 }
80 SizeT BytesNeeded = Align - Mod;
81 const SizeT HltSize = 1;
82 while (BytesNeeded > 0) {
83 hlt();
84 BytesNeeded -= HltSize;
85 }
86 assert((buffer_.GetPosition() & (Align - 1)) == 0);
87 }
88
81 Label *AssemblerX86::GetOrCreateLabel(SizeT Number, LabelVector &Labels) { 89 Label *AssemblerX86::GetOrCreateLabel(SizeT Number, LabelVector &Labels) {
82 Label *L = nullptr; 90 Label *L = nullptr;
83 if (Number == Labels.size()) { 91 if (Number == Labels.size()) {
84 L = new (this->Allocate<Label>()) Label(); 92 L = new (this->Allocate<Label>()) Label();
85 Labels.push_back(L); 93 Labels.push_back(L);
86 return L; 94 return L;
87 } 95 }
88 if (Number > Labels.size()) { 96 if (Number > Labels.size()) {
89 Labels.resize(Number + 1); 97 Labels.resize(Number + 1);
90 } 98 }
(...skipping 2430 matching lines...) Expand 10 before | Expand all | Expand 10 after
2521 assert(shifter == RegX8632::Encoded_Reg_ecx); 2529 assert(shifter == RegX8632::Encoded_Reg_ecx);
2522 (void)shifter; 2530 (void)shifter;
2523 if (Ty == IceType_i16) 2531 if (Ty == IceType_i16)
2524 EmitOperandSizeOverride(); 2532 EmitOperandSizeOverride();
2525 EmitUint8(isByteSizedArithType(Ty) ? 0xD2 : 0xD3); 2533 EmitUint8(isByteSizedArithType(Ty) ? 0xD2 : 0xD3);
2526 EmitOperand(rm, operand); 2534 EmitOperand(rm, operand);
2527 } 2535 }
2528 2536
2529 } // end of namespace x86 2537 } // end of namespace x86
2530 } // end of namespace Ice 2538 } // end of namespace Ice
OLDNEW
« src/IceMemoryRegion.h ('K') | « src/assembler_ia32.h ('k') | src/llvm2ice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698